/
spawn.js
32 lines (27 loc) · 1.17 KB
/
spawn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const { spawnSync } = require('child_process');
const args = process.argv.slice(2);
const maxMemory = process.env.MAX_USED_MEMORY || '3000';
const maxSemiSpaceSize = process.env.MAX_SEMI_SPACE_SIZE || '128';
const defaultArgs = [
`--max_old_space_size=${maxMemory}`,
`--max_semi_space_size=${maxSemiSpaceSize}`,
];
const paramsIndex = args.findIndex((x) => !x.startsWith('-'));
const nodeArgs = paramsIndex > 0 ? args.slice(0, paramsIndex) : [];
module.exports = function spawn(executePath) {
const { status, signal } = spawnSync(
'node',
defaultArgs
.concat(nodeArgs)
.concat(require.resolve(executePath))
.concat(args.slice(paramsIndex > 0 ? paramsIndex : 0)),
// this is the first place where we can pass env which will be used by webpack
// about watchpack issue - https://github.com/webpack/watchpack/issues/222, https://github.com/vercel/next.js/pull/51826
{ stdio: 'inherit', env: { ...process.env, WATCHPACK_WATCHER_LIMIT: '20' } }
);
if (signal) {
throw new Error(`Process was exited with signal "${signal}"
It's unexpected, please check available/used memory and cpu while running last command`);
}
process.exit(status);
};