Skip to content

Commit

Permalink
fix(compartment-mapper): Fix "module" property in package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Mar 11, 2022
1 parent 38464e0 commit 68395a2
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 28 deletions.
7 changes: 7 additions & 0 deletions packages/compartment-mapper/NEWS.md
@@ -1,5 +1,12 @@
User-visible changes to the compartment mapper:

# Next release

- Fixes treatment of packages with a `"module"` property in their
`package.json`: When the compartment mapper encounters such a package, every
module in that package with `.js` extension including the referenced module
will be treated an ESM, as if it had the `.mjs` extension.

# v0.7.0 (2022-03-01)

- *BREAKING:* Archive integrity checks now occur when the archive is loaded
Expand Down
16 changes: 7 additions & 9 deletions packages/compartment-mapper/src/infer-exports.js
Expand Up @@ -81,20 +81,18 @@ export const inferExportsEntries = function* inferExportsEntries(
) {
// From lowest to highest precedence, such that later entries override former
// entries.
if (main !== undefined) {
yield [name, relativize(main)];
}
if (module !== undefined && tags.has('import')) {
// In this one case, the key "module" has carried a hint that the
// referenced module is an ECMASCript module, and that hint is necessary to
// override whatever type might be inferred from the module specifier
// extension.
// referenced module is an ECMASCript module, and that hint may be
// necessary to override whatever type might be inferred from the module
// specifier extension.
const spec = relativize(module);
types[spec] = 'mjs';
yield [name, spec];
}
if (browser !== undefined && tags.has('browser')) {
yield [name, relativize(module)];
} else if (browser !== undefined && tags.has('browser')) {
yield* interpretBrowserExports(name, browser);
} else if (main !== undefined) {
yield [name, relativize(main)];
}
if (exports !== undefined) {
yield* interpretExports(name, exports, tags);
Expand Down
4 changes: 2 additions & 2 deletions packages/compartment-mapper/src/node-modules.js
Expand Up @@ -165,7 +165,7 @@ const moduleParsers = { js: 'mjs', ...uncontroversialParsers };
* @returns {Record<string, string>}
*/
const inferParsers = (descriptor, location) => {
const { type, parsers } = descriptor;
const { type, module, parsers } = descriptor;
if (parsers !== undefined) {
if (typeof parsers !== 'object') {
throw new Error(
Expand All @@ -186,7 +186,7 @@ const inferParsers = (descriptor, location) => {
}
return { ...uncontroversialParsers, ...parsers };
}
if (type === 'module') {
if (type === 'module' || module !== undefined) {
return moduleParsers;
}
if (type === 'commonjs') {
Expand Down
Binary file modified packages/compartment-mapper/test/app.agar
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions packages/compartment-mapper/test/test-main.js
Expand Up @@ -20,7 +20,7 @@ const assertFixture = (t, { namespace, globals, globalLexicals }) => {
receivedGlobalLexical,
typecommon,
typemodule,
typehybrid,
typemoduleImplied,
typeparsers,
} = namespace;

Expand Down Expand Up @@ -52,7 +52,11 @@ const assertFixture = (t, { namespace, globals, globalLexicals }) => {
[42, 42, 42, 42],
'parsers-specifying package carries exports',
);
t.is(typehybrid, 42, 'type=module and module= package carries exports');
t.deepEqual(
typemoduleImplied,
[42, 42, 42, 42],
'module= package carries exports',
);
};

const fixtureAssertionCount = 11;
Expand Down

0 comments on commit 68395a2

Please sign in to comment.