Skip to content

Commit 663450d

Browse files
authored
feat(compartment-mapper): Bundle the unarchiver (merge #1356)
2 parents 342afa8 + f67827b commit 663450d

File tree

9 files changed

+57
-2
lines changed

9 files changed

+57
-2
lines changed

packages/compartment-mapper/NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ User-visible changes to the compartment mapper:
22

33
# Next release
44

5+
- Bundles now evaluate to their entrypoint module's namespace object.
56
- Removes support for `globalLexicals`.
67

78
# 0.7.7 (2022-06-28)

packages/compartment-mapper/src/bundle.js

+2
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ ${importsCellSetter(__fixedExportMap__, index)}\
337337
`,
338338
),
339339
)}\
340+
341+
return cells[cells.length - 1]['*'].get();
340342
})();
341343
`;
342344

packages/compartment-mapper/src/import-archive.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ export const parseArchive = async (
304304
__shimTransforms__,
305305
Compartment,
306306
});
307-
return compartment.import(moduleSpecifier);
307+
// eslint-disable-next-line dot-notation
308+
return compartment['import'](moduleSpecifier);
308309
};
309310

310311
return { import: execute, sha512 };

packages/compartment-mapper/test/fixtures-0/node_modules/bundle-dep/index.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compartment-mapper/test/fixtures-0/node_modules/bundle-dep/package.json

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compartment-mapper/test/fixtures-0/node_modules/bundle/main.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compartment-mapper/test/fixtures-0/node_modules/bundle/package.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compartment-mapper/test/test-bundle.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const fixture = new URL(
1313
const { read } = makeReadPowers({ fs, url });
1414

1515
const expectedLog = [
16+
'dependency',
1617
'foo',
1718
{
1819
c: 'sea',

packages/compartment-mapper/test/test-main.js

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'ses';
22
import test from 'ava';
3-
import { loadLocation, importArchive } from '../index.js';
3+
import { loadLocation, importArchive, makeBundle } from '../index.js';
44
import { scaffold, readPowers, setup } from './scaffold.js';
55

66
const fixture = new URL(
@@ -83,6 +83,42 @@ with the current test fixture.`);
8383
assertFixture(t, { namespace, globals });
8484
});
8585

86+
test('makeBundle / importArchive', async t => {
87+
t.plan(fixtureAssertionCount);
88+
89+
const archiverLocation = new URL(
90+
'../src/import-archive.js',
91+
import.meta.url,
92+
).toString();
93+
94+
const archiverBundle = await makeBundle(readPowers.read, archiverLocation);
95+
const archiverCompartment = new Compartment({
96+
TextEncoder,
97+
TextDecoder,
98+
URL,
99+
assert,
100+
});
101+
const evasiveArchiverBundle = archiverBundle
102+
.replace(/(?<!\.)\bimport\b(?![:"'])/g, 'IMPORT')
103+
.replace(/\beval\b/g, 'EVAL');
104+
const { importArchive: bundledImportArchive } = archiverCompartment.evaluate(
105+
evasiveArchiverBundle,
106+
);
107+
108+
const { globals, modules } = await setup();
109+
110+
const { namespace } = await bundledImportArchive(
111+
readPowers.read,
112+
archiveFixture,
113+
{
114+
globals,
115+
modules,
116+
Compartment,
117+
},
118+
);
119+
assertFixture(t, { namespace, globals });
120+
});
121+
86122
test('no dev dependencies', async t => {
87123
const { globals, modules } = await setup();
88124

0 commit comments

Comments
 (0)