Skip to content

Commit 42e9ebc

Browse files
fix(ext/node): align module.builtinModules / getBuiltinModule with Node (#33404)
Co-authored-by: Nathan Whitaker <nathan@deno.com>
1 parent 44b0e04 commit 42e9ebc

2 files changed

Lines changed: 42 additions & 6 deletions

File tree

ext/node/polyfills/01_require.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ const {
5454
RegExpPrototypeTest,
5555
SafeArrayIterator,
5656
SafeMap,
57+
SafeSet,
5758
SafeWeakMap,
59+
SetPrototypeHas,
5860
String,
5961
StringPrototypeCharCodeAt,
6062
StringPrototypeEndsWith,
@@ -275,7 +277,7 @@ function setupBuiltinModules() {
275277
timers,
276278
"timers/promises": timersPromises,
277279
tls,
278-
traceEvents,
280+
trace_events: traceEvents,
279281
tty,
280282
url,
281283
util,
@@ -286,9 +288,27 @@ function setupBuiltinModules() {
286288
worker_threads: workerThreads,
287289
zlib,
288290
};
291+
// Match Node's schemelessBlockList: these modules can only be imported
292+
// via the `node:` scheme (see lib/internal/bootstrap/realm.js), so they
293+
// appear in `builtinModules` as `node:<name>` rather than `<name>`.
294+
const schemelessBlockList = new SafeSet([
295+
"sea",
296+
"sqlite",
297+
"test",
298+
"test/reporters",
299+
]);
289300
for (const [name, moduleExports] of ObjectEntries(nodeModules)) {
290301
nativeModuleExports[name] = moduleExports;
291-
ArrayPrototypePush(builtinModules, name);
302+
// `internal/*` modules are only exposed under --expose-internals, so
303+
// they aren't part of the public builtinModules list.
304+
if (StringPrototypeStartsWith(name, "internal/")) {
305+
continue;
306+
}
307+
if (SetPrototypeHas(schemelessBlockList, name)) {
308+
ArrayPrototypePush(builtinModules, `node:${name}`);
309+
} else {
310+
ArrayPrototypePush(builtinModules, name);
311+
}
292312
}
293313
}
294314
setupBuiltinModules();
@@ -1372,6 +1392,9 @@ function isBuiltin(moduleName) {
13721392
}
13731393

13741394
function getBuiltinModule(id) {
1395+
if (typeof id !== "string") {
1396+
throw new internalErrors.ERR_INVALID_ARG_TYPE("id", "string", id);
1397+
}
13751398
if (!isBuiltin(id)) {
13761399
return undefined;
13771400
}

tests/node_compat/config.jsonc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,7 @@
19941994
"parallel/test-process-exit-recursive.js": {},
19951995
"parallel/test-process-exit.js": {},
19961996
"parallel/test-process-features.js": {},
1997+
"parallel/test-process-get-builtin.mjs": {},
19971998
"parallel/test-process-getgroups.js": {},
19981999
"parallel/test-process-hrtime-bigint.js": {},
19992000
"parallel/test-process-hrtime.js": {},
@@ -2558,13 +2559,25 @@
25582559
"parallel/test-tls-transport-destroy-after-own-gc.js": {},
25592560
"parallel/test-tls-wrap-econnreset-pipe.js": { "windows": false },
25602561
"parallel/test-tls-zero-clear-in.js": {},
2561-
"parallel/test-trace-events-api.js": {},
2562-
"parallel/test-trace-events-async-hooks-dynamic.js": {},
2563-
"parallel/test-trace-events-async-hooks-worker.js": {},
2562+
"parallel/test-trace-events-api.js": {
2563+
"ignore": true,
2564+
"reason": "Deno's node:trace_events polyfill is a stub (createTracing returns an object without .enable/.disable, getEnabledCategories returns \"\" instead of undefined). These tests were silently skipping via try/catch(require('trace_events')) until that lookup was fixed."
2565+
},
2566+
"parallel/test-trace-events-async-hooks-dynamic.js": {
2567+
"ignore": true,
2568+
"reason": "Deno's node:trace_events polyfill is a stub (createTracing returns an object without .enable/.disable, getEnabledCategories returns \"\" instead of undefined). These tests were silently skipping via try/catch(require('trace_events')) until that lookup was fixed."
2569+
},
2570+
"parallel/test-trace-events-async-hooks-worker.js": {
2571+
"ignore": true,
2572+
"reason": "Deno's node:trace_events polyfill is a stub (createTracing returns an object without .enable/.disable, getEnabledCategories returns \"\" instead of undefined). These tests were silently skipping via try/catch(require('trace_events')) until that lookup was fixed."
2573+
},
25642574
"parallel/test-trace-events-dynamic-enable-workers-disabled.js": {},
25652575
// TODO(bartlomieju): disabled during work on `node:inspector`, this test didn't actualy run before
25662576
// "parallel/test-trace-events-dynamic-enable.js": {},
2567-
"parallel/test-trace-events-get-category-enabled-buffer.js": {},
2577+
"parallel/test-trace-events-get-category-enabled-buffer.js": {
2578+
"ignore": true,
2579+
"reason": "Deno's node:trace_events polyfill is a stub (createTracing returns an object without .enable/.disable, getEnabledCategories returns \"\" instead of undefined). These tests were silently skipping via try/catch(require('trace_events')) until that lookup was fixed."
2580+
},
25682581
"parallel/test-tty-stdin-end.js": {},
25692582
"parallel/test-tty-stdin-pipe.js": {},
25702583
"parallel/test-ttywrap-invalid-fd.js": {},

0 commit comments

Comments
 (0)