| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 12a591a commit 3ad4d37
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -904,20 +904,19 @@ Module._resolveFilename = function(request, parent, isMain, options) { | |||
| 904 | 904 | paths = Module._resolveLookupPaths(request, parent); | |
| 905 | 905 | } | |
| 906 | 906 | ||
| 907 | - if (parent?.filename) { | ||
| 908 | - if (request[0] === '#') { | ||
| 909 | - const pkg = readPackageScope(parent.filename) || {}; | ||
| 910 | - if (pkg.data?.imports != null) { | ||
| 911 | - try { | ||
| 912 | - return finalizeEsmResolution( | ||
| 913 | - packageImportsResolve(request, pathToFileURL(parent.filename), | ||
| 914 | - cjsConditions), parent.filename, | ||
| 915 | - pkg.path); | ||
| 916 | - } catch (e) { | ||
| 917 | - if (e.code === 'ERR_MODULE_NOT_FOUND') | ||
| 918 | - throw createEsmNotFoundErr(request); | ||
| 919 | - throw e; | ||
| 920 | - } | ||
| 907 | + if (request[0] === '#' && (parent?.filename || parent?.id === '<repl>')) { | ||
| 908 | + const parentPath = parent?.filename ?? process.cwd() + path.sep; | ||
| 909 | + const pkg = readPackageScope(parentPath) || {}; | ||
| 910 | + if (pkg.data?.imports != null) { | ||
| 911 | + try { | ||
| 912 | + return finalizeEsmResolution( | ||
| 913 | + packageImportsResolve(request, pathToFileURL(parentPath), | ||
| 914 | + cjsConditions), parentPath, | ||
| 915 | + pkg.path); | ||
| 916 | + } catch (e) { | ||
| 917 | + if (e.code === 'ERR_MODULE_NOT_FOUND') | ||
| 918 | + throw createEsmNotFoundErr(request); | ||
| 919 | + throw e; | ||
| 921 | 920 | } | |
| 922 | 921 | } | |
| 923 | 922 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const { mustCall } = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const fixtures = require('../common/fixtures'); | ||
| 5 | + const { spawn } = require('child_process'); | ||
| 6 | + | ||
| 7 | + const child = spawn(process.execPath, [ | ||
| 8 | + '--interactive', | ||
| 9 | + ], { | ||
| 10 | + cwd: fixtures.path('es-modules', 'pkgimports'), | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + child.stdin.end( | ||
| 14 | + 'try{require("#test");await import("#test")}catch{process.exit(-1)}' | ||
| 15 | + ); | ||
| 16 | + | ||
| 17 | + child.on('exit', mustCall((code) => { | ||
| 18 | + assert.strictEqual(code, 0); | ||
| 19 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments