From 133d1919faba2964fdc339464ac16b019585d8ea Mon Sep 17 00:00:00 2001 From: bruce-one Date: Fri, 2 Feb 2018 09:29:49 +1100 Subject: [PATCH] feat: allow setting NODE_OPTIONS. (#448) --- README.md | 4 +++- src/patches/disable-node-cli.ts | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 937693e..9bc0a5d 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,9 @@ compile({ - #### `clean: boolean` - If included, nexe will remove temporary files for the accompanying configuration and exit - #### `enableNodeCli: boolean` - - Enable the original Node CLI (will prevent application cli from working) + - Enable the original Node CLI (will prevent application cli from working). + - Node CLI arguments passed via the [NODE_OPTIONS](https://nodejs.org/api/cli.html#cli_node_options_options) environment + variable will still be processed. NODE_OPTIONS support can be disabled with the `--without-node-options` configure flag. - default: `false` - #### `fakeArgv: boolean` - fake the entry point file name (`process.argv[1]`). If nexe was used with stdin this will be `'[stdin]'`. diff --git a/src/patches/disable-node-cli.ts b/src/patches/disable-node-cli.ts index 7964d02..3d5b4f5 100644 --- a/src/patches/disable-node-cli.ts +++ b/src/patches/disable-node-cli.ts @@ -5,8 +5,16 @@ export default async function disableNodeCli(compiler: NexeCompiler, next: () => return next() } - const nodeccMarker = "argv[index][0] == '-'" + const nodeccMarker = 'argv[index][0] ==' + + await compiler.replaceInFileAsync( + 'src/node.cc', + `${nodeccMarker} '-'`, + // allow NODE_OPTIONS, introduced in 8.0 + parseInt(compiler.target.version.split('.')[0]) >= 8 + ? `(${nodeccMarker} is_env ? '-' : ']')` + : `(${nodeccMarker} ']')` + ) - await compiler.replaceInFileAsync('src/node.cc', nodeccMarker, nodeccMarker.replace('-', ']')) return next() }