Skip to content

Commit

Permalink
modules: enable subpath imports in REPL
Browse files Browse the repository at this point in the history
fix: #43410
  • Loading branch information
rayw000 committed Jun 16, 2022
1 parent 6975dd1 commit c58e2a6
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,8 @@ Module._resolveFilename = function(request, parent, isMain, options) {
paths = Module._resolveLookupPaths(request, parent);
}

if (parent?.filename) {
if (request[0] === '#') {
if (request[0] === '#') {
if (parent?.filename) {
const pkg = readPackageScope(parent.filename) || {};
if (pkg.data?.imports != null) {
try {
Expand All @@ -915,6 +915,20 @@ Module._resolveFilename = function(request, parent, isMain, options) {
throw e;
}
}
} else if (parent.id === '<repl>') {
// Also enable package imports in REPL
const curloc = process.cwd() + path.sep;
try {
return finalizeEsmResolution(
packageImportsResolve(
request, pathToFileURL(curloc),
cjsConditions),
curloc, curloc);
} catch (e) {
if (e.code === 'ERR_MODULE_NOT_FOUND')
throw createEsmNotFoundErr(request);
throw e;
}
}
}

Expand Down

0 comments on commit c58e2a6

Please sign in to comment.