Skip to content

Commit

Permalink
module: require.resolve.paths returns null with node schema
Browse files Browse the repository at this point in the history
require.resolve.paths should returns null with builtin module.
when builtin module without `node:` schema, `paths` returns null.
But, it don't return null when builtin module with `node:` schema.

Fixes: nodejs#45001
  • Loading branch information
fossamagna committed Oct 24, 2022
1 parent 89c4e1f commit 96f14e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,13 @@ if (isWindows) {
}

Module._resolveLookupPaths = function(request, parent) {
if (BuiltinModule.canBeRequiredByUsers(request) &&
BuiltinModule.canBeRequiredWithoutScheme(request)) {
if ((
StringPrototypeStartsWith(request, 'node:') &&
BuiltinModule.canBeRequiredByUsers(StringPrototypeSlice(request, 5))
) || (
BuiltinModule.canBeRequiredByUsers(request) &&
BuiltinModule.canBeRequiredWithoutScheme(request)
)) {
debug('looking for %j in []', request);
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-require-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ require(fixtures.path('resolve-paths', 'default', 'verify-paths.js'));
assert.strictEqual(require.resolve.paths(mod), null);
});

builtinModules.forEach((mod) => {
assert.strictEqual(require.resolve.paths(`node:${mod}`), null);
});

// node_modules.
const resolvedPaths = require.resolve.paths('eslint');
assert.strictEqual(Array.isArray(resolvedPaths), true);
Expand Down

0 comments on commit 96f14e2

Please sign in to comment.