Skip to content

Commit ca33f03

Browse files
authored
feat: allow JSON in BOXEDNODE_{CONFIGURE,MAKE}_ARGS (#27)
In mongosh, we introduced `NODE_JS_CONFIGURE_ARGS` (not remembering that boxednode already provides this capability). We should just use a single consistent env var throughout the build process. This adds JSON array support for these environment variables for cases in which the list items themselves contain commas, and, as a drive-by fix, avoids mutating the input options argument.
1 parent 6b16b02 commit ca33f03

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

.github/workflows/nodejs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
with:
1919
check-latest: true
2020
node-version: ${{ matrix.node-version }}
21+
- name: Install [email protected]
22+
run: npm install -g [email protected]
2123
- name: Install Dependencies
2224
run: npm install
2325
- name: Test
@@ -40,6 +42,8 @@ jobs:
4042
with:
4143
check-latest: true
4244
node-version: ${{ matrix.node-version }}
45+
- name: Install [email protected]
46+
run: npm install -g [email protected]
4347
- name: Install Dependencies
4448
run: npm install
4549
- name: Sharded tests

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"gen-esm-wrapper": "^1.1.0",
5353
"mocha": "^8.1.3",
5454
"nyc": "^15.1.0",
55-
"ts-node": "^9.0.0",
55+
"ts-node": "^10.8.1",
5656
"typescript": "^4.0.3",
5757
"weak-napi": "2.0.2"
5858
},

src/index.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,21 +336,32 @@ async function compileJSFileAsBinaryImpl (options: CompilationOptions, logger: L
336336
}
337337
}
338338

339-
export async function compileJSFileAsBinary (options: CompilationOptions): Promise<void> {
339+
// Allow specifying arguments to make/configure/vcbuild through env vars,
340+
// either as a comma-separated list or as a JSON array
341+
function parseEnvVarArgList (value: string | undefined): string[] {
342+
if (!value) return [];
343+
try {
344+
return JSON.parse(value);
345+
} catch {
346+
return value.split(',');
347+
}
348+
}
349+
350+
export async function compileJSFileAsBinary (options: Readonly<CompilationOptions>): Promise<void> {
340351
const logger = options.logger || new LoggerImpl();
341352

342-
options.configureArgs = options.configureArgs || [];
343-
if (process.env.BOXEDNODE_CONFIGURE_ARGS) {
344-
options.configureArgs.push(...process.env.BOXEDNODE_CONFIGURE_ARGS.split(','));
345-
}
353+
const configureArgs = [...(options.configureArgs || [])];
354+
configureArgs.push(...parseEnvVarArgList(process.env.BOXEDNODE_CONFIGURE_ARGS));
346355

347-
options.makeArgs = options.makeArgs || [];
348-
if (process.env.BOXEDNODE_MAKE_ARGS) {
349-
options.makeArgs.push(...process.env.BOXEDNODE_MAKE_ARGS.split(','));
350-
}
356+
const makeArgs = [...(options.makeArgs || [])];
357+
makeArgs.push(...parseEnvVarArgList(process.env.BOXEDNODE_MAKE_ARGS));
351358

352359
try {
353-
await compileJSFileAsBinaryImpl(options, logger);
360+
await compileJSFileAsBinaryImpl({
361+
...options,
362+
configureArgs,
363+
makeArgs
364+
}, logger);
354365
} catch (err) {
355366
logger.stepFailed(err);
356367
throw err;

0 commit comments

Comments
 (0)