fix(compartment-mapper): handle package default module via externalAliases
MODIFY
packages/compartment-mapper/src/import-hook.js
packages/compartment-mapper/src/import-hook.js
@@ -145,9 +145,7 @@ export const makeImportHookMaker = (
// Collate candidate locations for the moduleSpecifier per Node.js
// conventions.
const candidates = [];
- if (moduleSpecifier === '.') {
- candidates.push('./index.js');
- } else {
+ if (moduleSpecifier !== '.') {
candidates.push(moduleSpecifier);
candidates.push(`${moduleSpecifier}.js`, `${moduleSpecifier}/index.js`);
}

MODIFY
packages/compartment-mapper/src/infer-exports.js
packages/compartment-mapper/src/infer-exports.js
@@ -157,12 +157,23 @@ export const inferExportsAndAliases = (
tags,
types,
) => {
+ const { name, main, module, exports, browser } = descriptor;
+
+ // collect externalAliases from exports and main/module
assign(
externalAliases,
fromEntries(inferExportsEntries(descriptor, tags, types)),
);
+
+ // expose default module as package root
+ // may be overwritten by browser field
+ // see https://github.com/endojs/endo/issues/1363
+ if (module === undefined && exports === undefined) {
+ const defaultModule = main !== undefined ? relativize(main) : './index.js';
+ externalAliases['.'] = defaultModule;
+ }
+
// if present, allow "browser" field to populate moduleMap
- const { name, main, browser } = descriptor;
if (tags.has('browser') && browser !== undefined) {
for (const [specifier, target] of interpretBrowserField(
name,

fix(compartment-mapper): handle package default module via externalAliases