Skip to content

Commit a84209d

Browse files
committed
fixup! module: fix sync resolve hooks for require with node: prefixes
1 parent bac0a34 commit a84209d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,9 +1170,9 @@ function getDefaultLoad(url, filename) {
11701170
* @param {string} id The module ID (without the node: prefix)
11711171
* @param {string} url The module URL (with the node: prefix)
11721172
* @param {string} format Format from resolution.
1173-
* @returns {{builtinExports?: any, resultFromHook?: any}} If there are no load hooks or the load hooks do not
1174-
* override the format of the builtin, load and return the exports of the builtin module.
1175-
* Otherwise, return the loadResult for the caller to continue loading.
1173+
* @returns {{builtinExports: any, resultFromHook: undefined|ModuleLoadResult}} If there are no load
1174+
* hooks or the load hooks do not override the format of the builtin, load and return the exports
1175+
* of the builtin module. Otherwise, return the loadResult for the caller to continue loading.
11761176
*/
11771177
function loadBuiltinWithHooks(id, url, format) {
11781178
let resultFromHook;
@@ -1184,14 +1184,15 @@ function loadBuiltinWithHooks(id, url, format) {
11841184
getCjsConditionsArray(), getDefaultLoad(url, id), validateLoadStrict);
11851185
if (resultFromHook.format && resultFromHook.format !== 'builtin') {
11861186
debug('loadBuiltinWithHooks overriding module', id, url, resultFromHook);
1187-
return { resultFromHook }; // Format has been overridden, return result for the caller to continue loading.
1187+
// Format has been overridden, return result for the caller to continue loading.
1188+
return { builtinExports: undefined, resultFromHook };
11881189
}
11891190
}
11901191

11911192
// No hooks or the hooks have not overridden the format. Load it as a builtin module and return the
11921193
// exports.
11931194
const mod = loadBuiltinModule(id);
1194-
return { builtinExports: mod.exports };
1195+
return { builtinExports: mod.exports, resultFromHook: undefined };
11951196
}
11961197

11971198
/**

test/module-hooks/test-module-hooks-resolve-load-builtin-redirect.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
const common = require('../common');
55
const assert = require('assert');
66
const { registerHooks } = require('module');
7-
const fixtures = require('../common/fixtures');
87

98
// Pick a builtin that's unlikely to be loaded already - like zlib or dns.
109
assert(!process.moduleLoadList.includes('NativeModule zlib'));

0 commit comments

Comments
 (0)