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: #45001
PR-URL: #45147
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
fossamagna authored and ruyadorno committed Nov 21, 2022
1 parent 0d1b1c5 commit 6fdd202
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 @@ -751,8 +751,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 6fdd202

Please sign in to comment.