Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! module: implement "exports" proposal for CommonJS
  • Loading branch information
hybrist committed Jul 23, 2019
commit 104af348170c79b9addb6ce33c026a2196cbd5f7
8 changes: 4 additions & 4 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,12 @@ function resolveExports(nmPath, request, absoluteRequest) {

const basePath = path.resolve(nmPath, name);
const pkgExports = readExports(basePath);
const baseURL = `${pathToFileURL(basePath)}/`;

if (pkgExports != null) {
const mappingKey = `.${expansion}`;
const mapping = pkgExports[mappingKey];
if (typeof mapping === 'string') {
return fileURLToPath(new URL(mapping, baseURL));
return fileURLToPath(new URL(mapping, `${pathToFileURL(basePath)}/`));
}
Comment thread
bmeck marked this conversation as resolved.

let dirMatch = '';
Expand All @@ -370,9 +369,10 @@ function resolveExports(nmPath, request, absoluteRequest) {
if (dirMatch !== '') {
const dirMapping = pkgExports[dirMatch];
const remainder = StringPrototype.slice(mappingKey, dirMatch.length);
const expectedPrefix = new URL(dirMapping, baseURL).href;
const expectedPrefix =
new URL(dirMapping, `${pathToFileURL(basePath)}/`);
const resolved = new URL(remainder, expectedPrefix).href;
if (StringPrototype.startsWith(resolved, expectedPrefix)) {
if (StringPrototype.startsWith(resolved, expectedPrefix.href)) {
return fileURLToPath(resolved);
}
}
Expand Down