refactor(compartment-mapper)!: Import options bags and thread transforms
All spellings of `import` previously took globals and modules as positional arguments.
MODIFY
packages/compartment-mapper/NEWS.md
packages/compartment-mapper/NEWS.md
@@ -2,7 +2,7 @@ User-visible changes to the compartment mapper:
## Next release
-* No changes yet.
+* Threads transforms through to underlying compartments.
## Release 0.1.0 (2020-09-21)

MODIFY
packages/compartment-mapper/README.md
packages/compartment-mapper/README.md
@@ -33,8 +33,10 @@ const read = async location =>
const { namespace } = await importLocation(
read,
moduleLocation,
+ {
endowments,
modules
+ }
);
```
@@ -57,7 +59,7 @@ The `importLocation` function uses `loadLocation`.
Using `loadLocation` directly allows for deferred execution or multiple runs
with different endowments or modules in the same process.
Calling `loadLocation` returns an `Application` object with an
-`import(endowments?, modules?)` method.
+`import({ endowments?, modules? })` method.
Use `writeArchive` to capture an application in an archival format.
Archives are `zip` files with a `compartment-map.json` manifest file.
@@ -100,8 +102,10 @@ const read = async location =>
const { namespace } = await importArchive(
read,
archiveLocation,
+ {
endowments,
modules
+ }
);
```
@@ -110,7 +114,7 @@ Use `loadArchive` to defer execution or run multiple times with varying
endowments.
Use `parseArchive` to construct a runner from the bytes of an archive.
The `loadArchive` and `parseArchive` functions return an `Application`
-object with an `import(endowments?, modules?)` method.
+object with an `import({ endowments?, modules? })` method.
# Package Descriptors

MODIFY
packages/compartment-mapper/src/assemble.js
packages/compartment-mapper/src/assemble.js
@@ -130,6 +130,7 @@ export const assemble = (
{
makeImportHook,
endowments = {},
+ transforms = [],
modules: exitModules = {},
Compartment = defaultCompartment
}
@@ -168,6 +169,7 @@ export const assemble = (
resolveHook,
importHook,
moduleMapHook,
+ transforms,
name: location
});

MODIFY
packages/compartment-mapper/src/import-archive.js
packages/compartment-mapper/src/import-archive.js
@@ -38,7 +38,8 @@ export const parseArchive = async (archiveBytes, archiveLocation) => {
const compartmentMapText = decoder.decode(compartmentMapBytes);
const compartmentMap = json.parse(compartmentMapText, "compartment-map.json");
- const execute = (endowments, modules) => {
+ const execute = options => {
+ const { endowments, modules, transforms } = options;
const {
compartments,
entry: { module: moduleSpecifier }
@@ -47,7 +48,8 @@ export const parseArchive = async (archiveBytes, archiveLocation) => {
const compartment = assemble(compartmentMap, {
makeImportHook,
endowments,
- modules
+ modules,
+ transforms
});
return compartment.import(moduleSpecifier);
};
@@ -60,12 +62,7 @@ export const loadArchive = async (read, archiveLocation) => {
return parseArchive(archiveBytes, archiveLocation);
};
-export const importArchive = async (
- read,
- archiveLocation,
- endowments,
- modules
-) => {
+export const importArchive = async (read, archiveLocation, options) => {
const archive = await loadArchive(read, archiveLocation);
- return archive.import(endowments, modules);
+ return archive.import(options);
};

MODIFY
packages/compartment-mapper/src/import.js
packages/compartment-mapper/src/import.js
@@ -25,12 +25,14 @@ export const loadLocation = async (read, moduleLocation) => {
packageDescriptor
);
- const execute = async (endowments = {}, modules = {}) => {
+ const execute = async (options = {}) => {
+ const { endowments, modules, transforms } = options;
const makeImportHook = makeImportHookMaker(read, packageLocation);
const compartment = assemble(compartmentMap, {
makeImportHook,
endowments,
- modules
+ modules,
+ transforms
});
return compartment.import(moduleSpecifier);
};
@@ -38,12 +40,7 @@ export const loadLocation = async (read, moduleLocation) => {
return { import: execute };
};
-export const importLocation = async (
- read,
- moduleLocation,
- endowments,
- modules
-) => {
+export const importLocation = async (read, moduleLocation, options = {}) => {
const application = await loadLocation(read, moduleLocation);
- return application.import(endowments, modules);
+ return application.import(options);
};

MODIFY
packages/compartment-mapper/test/main.test.js
packages/compartment-mapper/test/main.test.js
@@ -77,7 +77,7 @@ let modules;
test("create builtin", async t => {
const utility = await loadLocation(read, builtinLocation);
- const { namespace } = await utility.import(endowments);
+ const { namespace } = await utility.import({ endowments });
// We pass the builtin module into the module map.
modules = {
builtin: namespace
@@ -89,19 +89,17 @@ test("loadLocation", async t => {
t.plan(fixtureAssertionCount);
const application = await loadLocation(read, fixture);
- const { namespace } = await application.import(endowments, modules);
+ const { namespace } = await application.import({ endowments, modules });
assertFixture(t, namespace);
});
test("importLocation", async t => {
t.plan(fixtureAssertionCount);
- const { namespace } = await importLocation(
- read,
- fixture,
+ const { namespace } = await importLocation(read, fixture, {
endowments,
modules
- );
+ });
assertFixture(t, namespace);
});
@@ -110,7 +108,7 @@ test("makeArchive / parseArchive", async t => {
const archive = await makeArchive(read, fixture);
const application = await parseArchive(archive);
- const { namespace } = await application.import(endowments, modules);
+ const { namespace } = await application.import({ endowments, modules });
assertFixture(t, namespace);
});
@@ -130,7 +128,7 @@ test("writeArchive / loadArchive", async t => {
await writeArchive(fakeWrite, read, "app.agar", fixture);
const application = await loadArchive(fakeRead, "app.agar");
- const { namespace } = await application.import(endowments, modules);
+ const { namespace } = await application.import({ endowments, modules });
assertFixture(t, namespace);
});
@@ -149,11 +147,9 @@ test("writeArchive / importArchive", async t => {
};
await writeArchive(fakeWrite, read, "app.agar", fixture);
- const { namespace } = await importArchive(
- fakeRead,
- "app.agar",
+ const { namespace } = await importArchive(fakeRead, "app.agar", {
endowments,
modules
- );
+ });
assertFixture(t, namespace);
});

refactor(compartment-mapper)!: Import options bags and thread transforms

All spellings of `import` previously took globals and modules as positional arguments.