diff --git a/src/options.ts b/src/options.ts index 4f4e5c8f..8c55944a 100644 --- a/src/options.ts +++ b/src/options.ts @@ -26,6 +26,7 @@ export interface NexeOptions { cwd: string fs: boolean | string[] flags: string[] + nodeOptions: string[] configure: string[] vcBuild: string[] make: string[] @@ -60,6 +61,7 @@ export interface NexeOptions { const defaults = { flags: [], + nodeOptions: [], cwd: process.cwd(), fs: true, configure: [], @@ -85,6 +87,7 @@ const alias = { r: 'resource', p: 'python', f: 'flag', + e: 'nodeOption', c: 'configure', m: 'make', h: 'help', @@ -111,6 +114,7 @@ ${c.bold('nexe [options]')} -b --build -- build from source -p --python -- python3 (as python) executable path -f --flag -- *v8 flags to include during compilation + -e --node-option -- node option -c --configure -- *arguments to the configure step -m --make -- *arguments to the make/build step --patch -- module with middleware default export for adding a build patch @@ -242,6 +246,7 @@ function normalizeOptions(input?: Partial): NexeOptions { options.name = extractName(options) options.loglevel = extractLogLevel(options) options.flags = flatten(opts.flag, options.flags) + options.nodeOptions = flatten(opts['node-option'], options.nodeOptions) options.targets = flatten(opts.target, options.targets).map(getTarget) if (!options.targets.length) { options.targets.push(getTarget()) diff --git a/src/patches/index.ts b/src/patches/index.ts index 8697313e..cb7540b1 100644 --- a/src/patches/index.ts +++ b/src/patches/index.ts @@ -6,7 +6,8 @@ import flags from './flags' import ico from './ico' import rc from './node-rc' import snapshot from './snapshot' +import options from './options' -const patches = [gyp, bootNexe, buildFixes, cli, flags, ico, rc, snapshot] +const patches = [gyp, bootNexe, buildFixes, cli, flags, ico, rc, snapshot, options] export default patches diff --git a/src/patches/options.ts b/src/patches/options.ts new file mode 100644 index 00000000..cb7db0a3 --- /dev/null +++ b/src/patches/options.ts @@ -0,0 +1,25 @@ +import { NexeCompiler } from '../compiler'; + +export default async function options(compiler: NexeCompiler, next: () => Promise) { + const nodeOptions = compiler.options.nodeOptions; + if (!nodeOptions.length) { + return next(); + } + + const find = '#if !defined(NODE_WITHOUT_NODE_OPTIONS)'; + const code = `do { + std::string node_options = ${JSON.stringify(nodeOptions.join(' '))}; + std::vector env_argv = ParseNodeOptionsEnvVar(node_options, errors); + if (!errors->empty()) return 9; + env_argv.insert(env_argv.begin(), argv->at(0)); + const int exit_code = ProcessGlobalArgs(&env_argv, nullptr, errors, kAllowedInEnvironment); + if (exit_code != 0) return exit_code; + } while(0); + + ${find} + `; + + await compiler.replaceInFileAsync('src/node.cc', find, code); + + return next(); +}