Skip to content

Commit 909a870

Browse files
committed
wasi: require CLI flag to require() wasi module
This commit ensures that the WASI module cannot be require()'ed without a CLI flag while the module is still experimental. This fixes a regression from nodejs#30778.
1 parent ba29e27 commit 909a870

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/internal/bootstrap/pre_execution.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,10 @@ function initializePolicy() {
401401
}
402402

403403
function initializeWASI() {
404-
if (getOptionValue('--experimental-wasi-unstable-preview0')) {
405-
const { NativeModule } = require('internal/bootstrap/loaders');
406-
const mod = NativeModule.map.get('wasi');
407-
mod.canBeRequiredByUsers = true;
408-
}
404+
const { NativeModule } = require('internal/bootstrap/loaders');
405+
const mod = NativeModule.map.get('wasi');
406+
mod.canBeRequiredByUsers =
407+
getOptionValue('--experimental-wasi-unstable-preview0');
409408
}
410409

411410
function initializeCJSLoader() {

test/wasi/test-wasi-require-flag.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
// This test verifies that the WASI module cannot be require()'ed without a
3+
// CLI flag while it is still experimental.
4+
require('../common');
5+
const assert = require('assert');
6+
7+
assert.throws(() => {
8+
require('wasi');
9+
}, /^Error: Cannot find module 'wasi'/);

0 commit comments

Comments
 (0)