From 7f3e248ed1b789bfa92f885158ab6e60063159c5 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Mon, 20 Nov 2023 13:36:05 +0000 Subject: [PATCH] Add NODE_OPTIONS env var to npm install part of #194 --- lib/launcher.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/launcher.js b/lib/launcher.js index 3066a24..dee4282 100644 --- a/lib/launcher.js +++ b/lib/launcher.js @@ -219,10 +219,15 @@ class Launcher { fs.writeFileSync(pkgFilePath, JSON.stringify(pkg, null, 2)) const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm' return new Promise((resolve, reject) => { + const env = {} + if (this.settings.stack.memory) { + const memLimit = Math.round(this.settings.stack.memory * 0.75) + env.NODE_OPTIONS = `--max-old-space=${memLimit}` + } const child = childProcess.spawn( npmCommand, ['install', '--omit=dev', '--no-audit', '--no-update-notifier', '--no-fund'], - { windowsHide: true, cwd: path.join(this.settings.rootDir, this.settings.userDir) }) + { windowsHide: true, cwd: path.join(this.settings.rootDir, this.settings.userDir), env }) child.stdout.on('data', (data) => { this.logBuffer.add({ level: 'system', msg: '[npm] ' + data }) })