feat(compartment-mapper): implement passing values in import.meta.url
MODIFY
packages/compartment-mapper/src/import-archive.js
packages/compartment-mapper/src/import-archive.js
@@ -151,7 +151,7 @@ const makeArchiveImportHookMaker = (
sourceLocation,
packageLocation,
);
- return record;
+ return { record, specifier: moduleSpecifier };
};
return importHook;
};

MODIFY
packages/compartment-mapper/src/import-hook.js
packages/compartment-mapper/src/import-hook.js
@@ -186,20 +186,18 @@ export const makeImportHookMaker = (
// Facilitate a redirect if the returned record has a different
// module specifier than the requested one.
- /** @type {StaticModuleType} */
- let record;
if (candidateSpecifier !== moduleSpecifier) {
modules[moduleSpecifier] = {
module: candidateSpecifier,
compartment: packageLocation,
};
- record = {
+ }
+ /** @type {StaticModuleType} */
+ const record = {
record: concreteRecord,
specifier: candidateSpecifier,
+ importMeta: { url: moduleLocation },
};
- } else {
- record = concreteRecord;
- }
let sha512;
if (computeSha512 !== undefined) {
@@ -214,7 +212,7 @@ export const makeImportHookMaker = (
sourceLocation: moduleLocation,
parser,
bytes: transformedBytes,
- record,
+ record: concreteRecord,
sha512,
};
if (!shouldDeferError(parser)) {

MODIFY
packages/compartment-mapper/test/app.agar
packages/compartment-mapper/test/app.agar
Binary files a/packages/compartment-mapper/test/app.agar and b/packages/compartment-mapper/test/app.agar differ

MODIFY
packages/compartment-mapper/test/fixtures-0/node_modules/app/main.js
packages/compartment-mapper/test/fixtures-0/node_modules/app/main.js
@@ -26,6 +26,8 @@ export { builtin } from 'builtin';
export const receivedGlobalProperty = globalProperty;
export const receivedGlobalLexical = globalLexical;
+export const importMetaUrl = import.meta.url;
+
if (!Object.isFrozen(globalThis)) {
throw new Error('The global object must be frozen in all compartments');
}

MODIFY
packages/compartment-mapper/test/test-main.js
packages/compartment-mapper/test/test-main.js
@@ -9,7 +9,10 @@ const fixture = new URL(
).toString();
const archiveFixture = new URL('app.agar', import.meta.url).toString();
-const assertFixture = (t, { namespace, globals, globalLexicals }) => {
+const assertFixture = (
+ t,
+ { namespace, globals, globalLexicals, testCategoryHint },
+) => {
const {
avery,
brooke,
@@ -22,8 +25,16 @@ const assertFixture = (t, { namespace, globals, globalLexicals }) => {
typemodule,
typemoduleImplied,
typeparsers,
+ importMetaUrl,
} = namespace;
+ if (testCategoryHint === 'Location') {
+ // matching any character where / or \ would be
+ t.regex(importMetaUrl, /fixtures-0.node_modules.app.main\.js$/);
+ } else {
+ t.is(importMetaUrl, undefined);
+ }
+
t.is(avery, 'Avery', 'exports avery');
t.is(brooke, 'Brooke', 'exports brooke');
t.is(clarke, 'Clarke', 'exports clarke');
@@ -59,7 +70,7 @@ const assertFixture = (t, { namespace, globals, globalLexicals }) => {
);
};
-const fixtureAssertionCount = 11;
+const fixtureAssertionCount = 12;
scaffold('fixture-0', test, fixture, assertFixture, fixtureAssertionCount);

MODIFY
packages/ses/index.d.ts
packages/ses/index.d.ts
@@ -67,6 +67,7 @@ export type FinalStaticModuleType =
export interface RedirectStaticModuleInterface {
record: FinalStaticModuleType;
specifier: string;
+ importMeta?: any;
}
export type StaticModuleType =

feat(compartment-mapper): implement passing values in import.meta.url