Skip to content

Commit 992f9eb

Browse files
aduh95targos
andauthored
fix(v8): fix spawning of subprocesses (#726)
Co-authored-by: Michaël Zasso <[email protected]>
1 parent 8672c88 commit 992f9eb

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

components/git/v8.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import path from 'node:path';
2+
import { Readable } from 'node:stream';
23

34
import logSymbols from 'log-symbols';
45

56
import { minor, major, backport } from '../../lib/update-v8/index.js';
67
import { defaultBaseDir } from '../../lib/update-v8/constants.js';
78
import { checkCwd } from '../../lib/update-v8/common.js';
8-
import { runAsync } from '../../lib/run.js';
9+
import { forceRunAsync, runAsync } from '../../lib/run.js';
910

1011
export const command = 'v8 [major|minor|backport]';
1112
export const describe = 'Update or patch the V8 engine';
@@ -83,13 +84,16 @@ export function handler(argv) {
8384
return runAsync('git', args, {
8485
spawnArgs: {
8586
cwd: options.nodeDir,
86-
...input && { input }
87+
stdio: input ? [Readable.from(input), 'ignore', 'ignore'] : 'ignore'
8788
}
8889
});
8990
};
9091

9192
options.execGitV8 = function execGitV8(...args) {
92-
return runAsync('git', args, { captureStdout: true, spawnArgs: { cwd: options.v8Dir } });
93+
return forceRunAsync('git', args, {
94+
captureStdout: true,
95+
spawnArgs: { cwd: options.v8Dir, stdio: ['ignore', 'pipe', 'ignore'] }
96+
});
9397
};
9498

9599
Promise.resolve()

lib/update-v8/majorUpdate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function cloneLocalV8() {
8989
title: 'Clone branch to deps/v8',
9090
task: (ctx) =>
9191
runAsync('git', ['clone', '-b', ctx.branch, ctx.v8Dir, 'deps/v8'], {
92-
spawnArgs: { cwd: ctx.nodeDir }
92+
spawnArgs: { cwd: ctx.nodeDir, stdio: 'ignore' }
9393
})
9494
};
9595
}
@@ -107,7 +107,7 @@ function addDepsV8() {
107107
// Add all V8 files with --force before updating DEPS. We have to do this
108108
// because some files are checked in by V8 despite .gitignore rules.
109109
task: (ctx) => runAsync('git', ['add', '--force', 'deps/v8'], {
110-
spawnArgs: { cwd: ctx.nodeDir }
110+
spawnArgs: { cwd: ctx.nodeDir, stdio: 'ignore' }
111111
})
112112
};
113113
}
@@ -166,6 +166,6 @@ async function fetchFromGit(cwd, repo, commit) {
166166
await removeDirectory(path.join(cwd, '.git'));
167167

168168
function exec(...options) {
169-
return runAsync('git', options, { spawnArgs: { cwd } });
169+
return runAsync('git', options, { spawnArgs: { cwd, stdio: 'ignore' } });
170170
}
171171
}

lib/update-v8/minorUpdate.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { spawn } from 'node:child_process';
12
import path from 'node:path';
23
import { promises as fs } from 'node:fs';
34

@@ -35,7 +36,7 @@ function getLatestV8Version() {
3536
captureStdout: true,
3637
spawnArgs: {
3738
cwd: ctx.v8Dir,
38-
encoding: 'utf8'
39+
stdio: ['ignore', 'pipe', 'ignore']
3940
}
4041
});
4142
const tags = filterAndSortTags(result);
@@ -66,23 +67,29 @@ function doMinorUpdate() {
6667
}
6768

6869
async function applyPatch(ctx, latestStr) {
69-
const diff = await runAsync(
70+
const diff = spawn(
7071
'git',
7172
['format-patch', '--stdout', `${ctx.currentVersion}...${latestStr}`],
72-
{ captureStdout: true, spawnArgs: { cwd: ctx.v8Dir, encoding: 'utf8' } }
73+
{ cwd: ctx.v8Dir, stdio: ['ignore', 'pipe', 'ignore'] }
7374
);
7475
try {
7576
await runAsync('git', ['apply', '--directory', 'deps/v8'], {
7677
spawnArgs: {
7778
cwd: ctx.nodeDir,
78-
input: diff
79+
stdio: [diff.stdout, 'ignore', 'ignore']
7980
}
8081
});
8182
} catch (e) {
8283
const file = path.join(ctx.nodeDir, `${latestStr}.diff`);
8384
await fs.writeFile(file, diff);
8485
throw new Error(`Could not apply patch.\n${e}\nDiff was stored in ${file}`);
8586
}
87+
if (diff.exitCode !== 0) {
88+
const err = new Error(`git format-patch failed: ${diff.exitCode}`);
89+
err.code = diff.exitCode;
90+
err.messageOnly = true;
91+
throw err;
92+
}
8693
}
8794

8895
function filterAndSortTags(tags) {

lib/update-v8/updateV8Clone.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ function fetchOrigin() {
2424
title: 'Fetch V8',
2525
task: async(ctx, task) => {
2626
try {
27-
await runAsync('git', ['fetch', 'origin'], { spawnArgs: { cwd: ctx.v8Dir } });
27+
await runAsync('git', ['fetch', 'origin'], {
28+
spawnArgs: { cwd: ctx.v8Dir, stdio: 'ignore' }
29+
});
2830
} catch (e) {
2931
if (e.code === 'ENOENT') {
3032
ctx.shouldClone = true;
@@ -42,7 +44,9 @@ function createClone() {
4244
title: 'Clone V8',
4345
task: async(ctx) => {
4446
await fs.mkdir(ctx.baseDir, { recursive: true });
45-
await runAsync('git', ['clone', v8Git], { spawnArgs: { cwd: ctx.baseDir } });
47+
await runAsync('git', ['clone', v8Git], {
48+
spawnArgs: { cwd: ctx.baseDir, stdio: 'ignore' }
49+
});
4650
},
4751
enabled: (ctx) => ctx.shouldClone
4852
};

0 commit comments

Comments
 (0)