Skip to content

Commit 918bb1d

Browse files
committed
loader: enforce path normalization before lookup
1 parent 120c2a4 commit 918bb1d

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

lib/internal/modules/package_map.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ class PackageMap {
140140
* @returns {string|null}
141141
*/
142142
#getKeyForPath(filePath) {
143+
filePath = pathResolve(filePath);
144+
143145
const cached = this.#pathToKeyCache.get(filePath);
144146
if (cached !== undefined) { return cached; }
145147

test/parallel/test-require-package-map.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ describe('CJS: --experimental-package-map', { concurrency: !process.env.TEST_PAR
7979
assert.match(stdout, /dep-b using dep-a-value/);
8080
assert.strictEqual(status, 0, stderr);
8181
});
82+
83+
it('resolves from createRequire() paths with mixed separators', {
84+
skip: !common.isWindows && 'mixed path separators only need normalization on Windows',
85+
}, () => {
86+
const { status, stdout, stderr } = spawnSync(process.execPath, [
87+
'--no-warnings',
88+
'--experimental-package-map', packageMapPath,
89+
'-e',
90+
`const { createRequire } = require('node:module'); const req = createRequire(process.cwd() + '/index.js'); const dep = req('dep-a'); console.log(dep.default);`,
91+
], {
92+
cwd: fixtures.path('package-map/root'),
93+
encoding: 'utf8',
94+
});
95+
96+
assert.strictEqual(stderr, '');
97+
assert.match(stdout, /dep-a-value/);
98+
assert.strictEqual(status, 0, stderr);
99+
});
82100
});
83101

84102
describe('resolution boundaries', () => {

0 commit comments

Comments
 (0)