Skip to content

Commit 248921b

Browse files
joyeecheungtargos
authored andcommitted
lib: delay access to CLI option to pre-execution
CLI options should not be added through the config binding, instead they are already available in the JS land via `require('internal/options')`. Also CLI options in principle should be processed in pre-execution instead of bootstrap scripts. PR-URL: #30778 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 8d0217b commit 248921b

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

lib/internal/bootstrap/loaders.js

-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ function NativeModule(id) {
160160
this.loaded = false;
161161
this.loading = false;
162162
this.canBeRequiredByUsers = !id.startsWith('internal/');
163-
164-
if (id === 'wasi')
165-
this.canBeRequiredByUsers = !!internalBinding('config').experimentalWasi;
166163
}
167164

168165
// To be called during pre-execution when --expose-internals is on.

lib/internal/bootstrap/pre_execution.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function prepareMainThreadExecution(expandArgv1 = false) {
6262
initializeClusterIPC();
6363

6464
initializeDeprecations();
65+
initializeWASI();
6566
initializeCJSLoader();
6667
initializeESMLoader();
6768

@@ -400,6 +401,14 @@ function initializePolicy() {
400401
}
401402
}
402403

404+
function initializeWASI() {
405+
if (getOptionValue('--experimental-wasi-unstable-preview0')) {
406+
const { NativeModule } = require('internal/bootstrap/loaders');
407+
const mod = NativeModule.map.get('wasi');
408+
mod.canBeRequiredByUsers = true;
409+
}
410+
}
411+
403412
function initializeCJSLoader() {
404413
const CJSLoader = require('internal/modules/cjs/loader');
405414
CJSLoader.Module._initPaths();
@@ -466,5 +475,6 @@ module.exports = {
466475
setupTraceCategoryState,
467476
setupInspectorHooks,
468477
initializeReport,
469-
initializeCJSLoader
478+
initializeCJSLoader,
479+
initializeWASI
470480
};

lib/internal/main/worker_thread.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
setupWarningHandler,
1515
setupDebugEnv,
1616
initializeDeprecations,
17+
initializeWASI,
1718
initializeCJSLoader,
1819
initializeESMLoader,
1920
initializeFrozenIntrinsics,
@@ -109,6 +110,7 @@ port.on('message', (message) => {
109110
require('internal/process/policy').setup(manifestSrc, manifestURL);
110111
}
111112
initializeDeprecations();
113+
initializeWASI();
112114
initializeCJSLoader();
113115
initializeESMLoader();
114116

src/node_config.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ using v8::Number;
1515
using v8::Object;
1616
using v8::Value;
1717

18-
// The config binding is used to provide an internal view of compile or runtime
18+
// The config binding is used to provide an internal view of compile time
1919
// config options that are required internally by lib/*.js code. This is an
2020
// alternative to dropping additional properties onto the process object as
2121
// has been the practice previously in node.cc.
2222

23+
// Command line arguments are already accessible in the JS land via
24+
// require('internal/options').getOptionValue('--some-option'). Do not add them
25+
// here.
2326
static void Initialize(Local<Object> target,
2427
Local<Value> unused,
2528
Local<Context> context,
@@ -84,9 +87,6 @@ static void Initialize(Local<Object> target,
8487

8588
READONLY_PROPERTY(target, "hasCachedBuiltins",
8689
v8::Boolean::New(isolate, native_module::has_code_cache));
87-
88-
if (env->options()->experimental_wasi)
89-
READONLY_TRUE_PROPERTY(target, "experimentalWasi");
9090
} // InitConfig
9191

9292
} // namespace node

0 commit comments

Comments
 (0)