feat(compartment-mapper): allow alternate searchSuffixes
MODIFY
packages/compartment-mapper/src/archive.js
packages/compartment-mapper/src/archive.js
@@ -254,6 +254,7 @@ const digestLocation = async (powers, moduleLocation, options) => {
dev = false,
tags = new Set(),
captureSourceLocation = undefined,
+ searchSuffixes = undefined,
} = options || {};
const { read, computeSha512 } = unpackReadPowers(powers);
const {
@@ -295,6 +296,7 @@ const digestLocation = async (powers, moduleLocation, options) => {
compartments,
exitModules,
computeSha512,
+ searchSuffixes,
);
// Induce importHook to record all the necessary modules to import the given module specifier.

MODIFY
packages/compartment-mapper/src/bundle.js
packages/compartment-mapper/src/bundle.js
@@ -146,10 +146,16 @@ const sortedModules = (
* @param {ModuleTransforms} [options.moduleTransforms]
* @param {boolean} [options.dev]
* @param {Set<string>} [options.tags]
+ * @param {Array<string>} [options.searchSuffixes]
* @returns {Promise<string>}
*/
export const makeBundle = async (read, moduleLocation, options) => {
- const { moduleTransforms, dev, tags: tagsOption } = options || {};
+ const {
+ moduleTransforms,
+ dev,
+ tags: tagsOption,
+ searchSuffixes,
+ } = options || {};
const tags = new Set(tagsOption);
const {
@@ -184,6 +190,9 @@ export const makeBundle = async (read, moduleLocation, options) => {
packageLocation,
sources,
compartments,
+ undefined,
+ undefined,
+ searchSuffixes,
);
// Induce importHook to record all the necessary modules to import the given module specifier.

MODIFY
packages/compartment-mapper/src/import.js
packages/compartment-mapper/src/import.js
@@ -41,6 +41,7 @@ export const loadLocation = async (readPowers, moduleLocation, options) => {
moduleTransforms = {},
dev = false,
tags = new Set(),
+ searchSuffixes = undefined,
} = options || {};
const { read } = unpackReadPowers(readPowers);
@@ -74,6 +75,9 @@ export const loadLocation = async (readPowers, moduleLocation, options) => {
packageLocation,
undefined,
compartmentMap.compartments,
+ undefined,
+ undefined,
+ searchSuffixes,
);
const { compartment } = link(compartmentMap, {
makeImportHook,

MODIFY
packages/compartment-mapper/src/types.js
packages/compartment-mapper/src/types.js
@@ -311,4 +311,5 @@ export {};
* @property {boolean} [dev]
* @property {Set<string>} [tags]
* @property {CaptureSourceLocationHook} [captureSourceLocation]
+ * @property {Array<string>} [searchSuffixes]
*/

ADD
packages/compartment-mapper/test/fixtures-0/node_modules/candidates-custom/index.js
+export { fourthPrime } from './util';

ADD
packages/compartment-mapper/test/fixtures-0/node_modules/candidates-custom/package.json
+{
+ "name": "canidates-custom",
+ "version": "1.0.0",
+ "description": "uses imports that requires custom canidates",
+ "type": "module",
+ "scripts": {
+ "preinstall": "echo DO NOT INSTALL TEST FIXTURES; exit -1"
+ }
+}

ADD
packages/compartment-mapper/test/fixtures-0/node_modules/candidates-custom/util.abc.js
+export const fourthPrime = 7;
\ No newline at end of file

MODIFY
packages/compartment-mapper/test/scaffold.js
packages/compartment-mapper/test/scaffold.js
@@ -58,6 +58,7 @@ export function scaffold(
shouldFailBeforeArchiveOperations = false,
knownFailure = false,
tags = undefined,
+ searchSuffixes = undefined,
} = {},
) {
// wrapping each time allows for convenient use of test.only
@@ -91,6 +92,7 @@ export function scaffold(
const application = await loadLocation(readPowers, fixture, {
dev: true,
tags,
+ searchSuffixes,
});
const { namespace } = await application.import({
globals,
@@ -110,6 +112,7 @@ export function scaffold(
Compartment,
dev: true,
tags,
+ searchSuffixes,
});
return namespace;
});
@@ -122,6 +125,7 @@ export function scaffold(
modules,
dev: true,
tags,
+ searchSuffixes,
});
const application = await parseArchive(archive, '<unknown>', {
modules: Object.fromEntries(
@@ -153,6 +157,7 @@ export function scaffold(
modules,
dev: true,
tags,
+ searchSuffixes,
});
const prefixArchive = new Uint8Array(archive.length + 10);
prefixArchive.set(archive, 10);
@@ -189,6 +194,7 @@ export function scaffold(
modules: { builtin: true },
dev: true,
tags,
+ searchSuffixes,
});
const application = await loadArchive(fakeRead, 'app.agar', {
modules,
@@ -221,6 +227,7 @@ export function scaffold(
modules,
dev: true,
tags,
+ searchSuffixes,
});
const { namespace } = await importArchive(fakeRead, 'app.agar', {
globals,
@@ -240,12 +247,14 @@ export function scaffold(
Compartment,
dev: true,
tags,
+ searchSuffixes,
});
const archiveBytes = await makeArchive(readPowers, fixture, {
modules,
dev: true,
tags,
+ searchSuffixes,
});
const { computeSha512 } = readPowers;
@@ -272,12 +281,14 @@ export function scaffold(
modules,
dev: true,
tags,
+ searchSuffixes,
});
const archive = await makeArchive(readPowers, fixture, {
modules,
dev: true,
tags,
+ searchSuffixes,
});
const reader = new ZipReader(archive);

MODIFY
packages/compartment-mapper/test/test-main.js
packages/compartment-mapper/test/test-main.js
@@ -239,3 +239,19 @@ scaffold(
},
2,
);
+
+scaffold(
+ 'overwrite searchSuffixes',
+ test,
+ new URL(
+ 'fixtures-0/node_modules/candidates-custom/index.js',
+ import.meta.url,
+ ).toString(),
+ (t, { namespace: { fourthPrime } }) => {
+ t.is(fourthPrime, 7);
+ },
+ 1,
+ {
+ searchSuffixes: ['.abc.js'],
+ },
+);

feat(compartment-mapper): allow alternate searchSuffixes