Skip to content

Commit

Permalink
feat(compartment-mapper): implement passing values in import.meta.url
Browse files Browse the repository at this point in the history
  • Loading branch information
naugtur committed Jun 28, 2022
1 parent 149492d commit d6294f6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/compartment-mapper/src/import-archive.js
Expand Up @@ -151,7 +151,7 @@ const makeArchiveImportHookMaker = (
sourceLocation,
packageLocation,
);
return record;
return { record, specifier: moduleSpecifier };
};
return importHook;
};
Expand Down
16 changes: 7 additions & 9 deletions packages/compartment-mapper/src/import-hook.js
Expand Up @@ -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 = {
record: concreteRecord,
specifier: candidateSpecifier,
};
} else {
record = concreteRecord;
}
/** @type {StaticModuleType} */
const record = {
record: concreteRecord,
specifier: candidateSpecifier,
importMeta: { url: moduleLocation },
};

let sha512;
if (computeSha512 !== undefined) {
Expand All @@ -214,7 +212,7 @@ export const makeImportHookMaker = (
sourceLocation: moduleLocation,
parser,
bytes: transformedBytes,
record,
record: concreteRecord,
sha512,
};
if (!shouldDeferError(parser)) {
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.

15 changes: 13 additions & 2 deletions packages/compartment-mapper/test/test-main.js
Expand Up @@ -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,
Expand All @@ -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');
Expand Down Expand Up @@ -59,7 +70,7 @@ const assertFixture = (t, { namespace, globals, globalLexicals }) => {
);
};

const fixtureAssertionCount = 11;
const fixtureAssertionCount = 12;

scaffold('fixture-0', test, fixture, assertFixture, fixtureAssertionCount);

Expand Down
1 change: 1 addition & 0 deletions packages/ses/index.d.ts
Expand Up @@ -67,6 +67,7 @@ export type FinalStaticModuleType =
export interface RedirectStaticModuleInterface {
record: FinalStaticModuleType;
specifier: string;
importMeta?: any;
}

export type StaticModuleType =
Expand Down

0 comments on commit d6294f6

Please sign in to comment.