forked from jupyterlab/jupyterlab
/
ensure-max-old-space.ts
executable file
·32 lines (28 loc) · 1.12 KB
/
ensure-max-old-space.ts
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
#!/usr/bin/env node
/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/
/**
* This file is a temporary workaround to ensure that we can set
* max_old_space by default but allow others to override it.
*
* When node 10 support is dropped, we can remove this file as node 12
* should just grow as required.
*
* See: https://github.com/jupyterlab/jupyterlab/issues/7175
*
* @example
* node ensure-max-old-space.js real-cli.js arg1 arg2
*/
import { execFileSync } from 'child_process';
import * as which from 'which';
const MAX_OLD_SPACE = '--max_old_space_size=4096';
if (!process.env.NODE_OPTIONS) {
process.env.NODE_OPTIONS = MAX_OLD_SPACE;
} else if (!/--max[_\-]old[_\-]space[_\-]size/.test(process.env.NODE_OPTIONS)) {
process.env.NODE_OPTIONS += ` ${MAX_OLD_SPACE}`;
}
const program = which.sync(process.argv[2]);
const args = process.argv.slice(3);
execFileSync(program, args, { env: process.env, stdio: 'inherit' });