@endo/compartment-mapper 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +278 -111
- package/bundle.d.ts +1 -1
- package/bundle.js +4 -1
- package/functor-lite.d.ts +3 -0
- package/functor-lite.d.ts.map +1 -0
- package/functor-lite.js +4 -0
- package/functor.d.ts +3 -0
- package/functor.d.ts.map +1 -0
- package/functor.js +4 -0
- package/index.d.ts +1 -1
- package/index.js +4 -1
- package/package.json +8 -4
- package/script-lite.d.ts +3 -0
- package/script-lite.d.ts.map +1 -0
- package/script-lite.js +4 -0
- package/script.d.ts +3 -0
- package/script.d.ts.map +1 -0
- package/script.js +4 -0
- package/src/archive-lite.js +1 -1
- package/src/bundle-cjs.d.ts +1 -1
- package/src/bundle-cjs.d.ts.map +1 -1
- package/src/bundle-cjs.js +57 -28
- package/src/bundle-json.d.ts.map +1 -1
- package/src/bundle-json.js +2 -3
- package/src/bundle-lite.d.ts +91 -0
- package/src/bundle-lite.d.ts.map +1 -0
- package/src/bundle-lite.js +668 -0
- package/src/bundle-mjs.d.ts +2 -2
- package/src/bundle-mjs.d.ts.map +1 -1
- package/src/bundle-mjs.js +36 -19
- package/src/bundle.d.ts +48 -10
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +391 -125
- package/src/capture-lite.js +1 -1
- package/src/import-hook.d.ts +3 -16
- package/src/import-hook.d.ts.map +1 -1
- package/src/import-hook.js +11 -18
- package/src/import-lite.d.ts.map +1 -1
- package/src/import-lite.js +4 -2
- package/src/node-modules.d.ts +4 -47
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +121 -121
- package/src/parse-archive-cjs.d.ts.map +1 -1
- package/src/parse-archive-cjs.js +8 -3
- package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
- package/src/parse-cjs-shared-export-wrapper.js +2 -10
- package/src/parse-cjs.js +1 -1
- package/src/parse-mjs.js +2 -2
- package/src/policy.d.ts.map +1 -1
- package/src/policy.js +4 -7
- package/src/search.d.ts +6 -12
- package/src/search.d.ts.map +1 -1
- package/src/search.js +29 -12
- package/src/types/compartment-map-schema.d.ts +5 -0
- package/src/types/compartment-map-schema.d.ts.map +1 -1
- package/src/types/compartment-map-schema.ts +5 -0
- package/src/types/external.d.ts +112 -8
- package/src/types/external.d.ts.map +1 -1
- package/src/types/external.ts +127 -8
- package/src/types/internal.d.ts +85 -13
- package/src/types/internal.d.ts.map +1 -1
- package/src/types/internal.ts +106 -13
- package/src/types/node-modules.d.ts +79 -0
- package/src/types/node-modules.d.ts.map +1 -0
- package/src/types/node-modules.ts +89 -0
- package/src/types/node-powers.d.ts +4 -4
- package/src/types/node-powers.d.ts.map +1 -1
- package/src/types/node-powers.ts +4 -4
- package/src/types/powers.d.ts +2 -2
- package/src/types/powers.d.ts.map +1 -1
- package/src/types/powers.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@endo/compartment-mapper",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "The compartment mapper assembles Node applications in a sandbox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -39,6 +39,10 @@
|
|
|
39
39
|
},
|
|
40
40
|
"./import-archive-all-parsers.js": "./import-archive-all-parsers.js",
|
|
41
41
|
"./bundle.js": "./bundle.js",
|
|
42
|
+
"./functor.js": "./functor.js",
|
|
43
|
+
"./functor-lite.js": "./functor-lite.js",
|
|
44
|
+
"./script.js": "./script.js",
|
|
45
|
+
"./script-lite.js": "./script-lite.js",
|
|
42
46
|
"./node-powers.js": "./node-powers.js",
|
|
43
47
|
"./node-modules.js": "./node-modules.js",
|
|
44
48
|
"./package.json": "./package.json"
|
|
@@ -57,10 +61,10 @@
|
|
|
57
61
|
},
|
|
58
62
|
"dependencies": {
|
|
59
63
|
"@endo/cjs-module-analyzer": "^1.0.9",
|
|
60
|
-
"@endo/module-source": "^1.
|
|
64
|
+
"@endo/module-source": "^1.3.0",
|
|
61
65
|
"@endo/trampoline": "^1.0.3",
|
|
62
66
|
"@endo/zip": "^1.0.9",
|
|
63
|
-
"ses": "^1.
|
|
67
|
+
"ses": "^1.12.0"
|
|
64
68
|
},
|
|
65
69
|
"devDependencies": {
|
|
66
70
|
"ava": "^6.1.3",
|
|
@@ -114,5 +118,5 @@
|
|
|
114
118
|
"typeCoverage": {
|
|
115
119
|
"atLeast": 86.14
|
|
116
120
|
},
|
|
117
|
-
"gitHead": "
|
|
121
|
+
"gitHead": "9b6784831d37db948cdd61f6da1f3489e8f97906"
|
|
118
122
|
}
|
package/script-lite.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-lite.d.ts","sourceRoot":"","sources":["script-lite.js"],"names":[],"mappings":""}
|
package/script-lite.js
ADDED
package/script.d.ts
ADDED
package/script.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.d.ts","sourceRoot":"","sources":["script.js"],"names":[],"mappings":""}
|
package/script.js
ADDED
package/src/archive-lite.js
CHANGED
|
@@ -176,7 +176,7 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
|
|
|
176
176
|
searchSuffixes,
|
|
177
177
|
entryCompartmentName,
|
|
178
178
|
entryModuleSpecifier,
|
|
179
|
-
|
|
179
|
+
importHook: consolidatedExitModuleImportHook,
|
|
180
180
|
sourceMapHook,
|
|
181
181
|
});
|
|
182
182
|
// Induce importHook to record all the necessary modules to import the given module specifier.
|
package/src/bundle-cjs.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export default _default;
|
|
|
3
3
|
export type CjsModuleSource = VirtualModuleSource & {
|
|
4
4
|
cjsFunctor: string;
|
|
5
5
|
};
|
|
6
|
-
import type { BundlerSupport } from './bundle.js';
|
|
6
|
+
import type { BundlerSupport } from './bundle-lite.js';
|
|
7
7
|
import type { VirtualModuleSource } from 'ses';
|
|
8
8
|
//# sourceMappingURL=bundle-cjs.d.ts.map
|
package/src/bundle-cjs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle-cjs.d.ts","sourceRoot":"","sources":["bundle-cjs.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bundle-cjs.d.ts","sourceRoot":"","sources":["bundle-cjs.js"],"names":[],"mappings":"wBAyEW,eAAe,eAAe,CAAC;;8BApE5B,mBAAmB,GAAG;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC;oCAFtB,kBAAkB;yCADb,KAAK"}
|
package/src/bundle-cjs.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/* Provides CommonJS support for `bundle.js`. */
|
|
2
2
|
|
|
3
3
|
/** @import {VirtualModuleSource} from 'ses' */
|
|
4
|
-
/** @import {BundlerSupport} from './bundle.js' */
|
|
4
|
+
/** @import {BundlerSupport} from './bundle-lite.js' */
|
|
5
5
|
|
|
6
6
|
/** @typedef {VirtualModuleSource & {cjsFunctor: string}} CjsModuleSource */
|
|
7
7
|
|
|
8
|
+
import { join } from './node-module-specifier.js';
|
|
9
|
+
|
|
8
10
|
/** quotes strings */
|
|
9
11
|
const q = JSON.stringify;
|
|
10
12
|
|
|
@@ -21,27 +23,34 @@ const exportsCellRecord = exportsList =>
|
|
|
21
23
|
|
|
22
24
|
// This function is serialized and references variables from its destination scope.
|
|
23
25
|
const runtime = `\
|
|
24
|
-
function wrapCjsFunctor(
|
|
26
|
+
function wrapCjsFunctor(index, functor) {
|
|
25
27
|
/* eslint-disable no-undef */
|
|
26
28
|
return ({ imports = {} }) => {
|
|
27
|
-
const moduleCells = cells[
|
|
28
|
-
const cModule =
|
|
29
|
-
|
|
29
|
+
const moduleCells = cells[index];
|
|
30
|
+
const cModule = freeze(
|
|
31
|
+
defineProperty({}, 'exports', moduleCells.default),
|
|
30
32
|
);
|
|
31
33
|
// TODO: specifier not found handling
|
|
32
34
|
const requireImpl = specifier => cells[imports[specifier]].default.get();
|
|
33
|
-
|
|
35
|
+
functor(freeze(requireImpl), cModule.exports, cModule);
|
|
34
36
|
// Update all named cells from module.exports.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
const names = keys(moduleCells);
|
|
38
|
+
for (let i = 0; i < names.length; i += 1) {
|
|
39
|
+
const name = names[i];
|
|
40
|
+
if (name !== 'default' && name !== '*') {
|
|
41
|
+
moduleCells[name].set(cModule.exports[name]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
38
44
|
// Add new named cells from module.exports.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
const exportNames = keys(cModule.exports);
|
|
46
|
+
for (let i = 0; i < exportNames.length; i += 1) {
|
|
47
|
+
const name = exportNames[i];
|
|
48
|
+
if (name !== 'default' && name !== '*' && moduleCells[name] === undefined) {
|
|
49
|
+
moduleCells[name] = cell(name, cModule.exports[name]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
43
52
|
// Update the star cell from all cells.
|
|
44
|
-
const starExports =
|
|
53
|
+
const starExports = create(null, {
|
|
45
54
|
// Make this appear like an ESM module namespace object.
|
|
46
55
|
[Symbol.toStringTag]: {
|
|
47
56
|
value: 'Module',
|
|
@@ -50,10 +59,14 @@ function wrapCjsFunctor(num) {
|
|
|
50
59
|
configurable: false,
|
|
51
60
|
},
|
|
52
61
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
const allNames = keys(moduleCells);
|
|
63
|
+
for (let i = 0; i < allNames.length; i += 1) {
|
|
64
|
+
const name = allNames[i];
|
|
65
|
+
if (name !== '*') {
|
|
66
|
+
defineProperty(starExports, name, moduleCells[name]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
moduleCells['*'].set(freeze(starExports));
|
|
57
70
|
};
|
|
58
71
|
/* eslint-enable no-undef */
|
|
59
72
|
}`;
|
|
@@ -61,17 +74,27 @@ function wrapCjsFunctor(num) {
|
|
|
61
74
|
/** @type {BundlerSupport<CjsModuleSource>} */
|
|
62
75
|
export default {
|
|
63
76
|
runtime,
|
|
64
|
-
getBundlerKit(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
getBundlerKit(
|
|
78
|
+
{
|
|
79
|
+
index,
|
|
80
|
+
indexedImports,
|
|
81
|
+
moduleSpecifier,
|
|
82
|
+
sourceDirname,
|
|
83
|
+
record: { cjsFunctor, exports: exportsList = {} },
|
|
84
|
+
},
|
|
85
|
+
{ useEvaluate = false },
|
|
86
|
+
) {
|
|
69
87
|
const importsMap = JSON.stringify(indexedImports);
|
|
70
88
|
|
|
89
|
+
let functor = cjsFunctor;
|
|
90
|
+
if (useEvaluate) {
|
|
91
|
+
const sourceUrl = join(sourceDirname, moduleSpecifier);
|
|
92
|
+
functor = JSON.stringify([functor, sourceUrl]);
|
|
93
|
+
}
|
|
94
|
+
|
|
71
95
|
return {
|
|
72
96
|
getFunctor: () => `\
|
|
73
|
-
|
|
74
|
-
${cjsFunctor},
|
|
97
|
+
${functor},
|
|
75
98
|
`,
|
|
76
99
|
getCells: () => `\
|
|
77
100
|
{
|
|
@@ -79,9 +102,15 @@ ${exportsCellRecord(exportsList)}\
|
|
|
79
102
|
},
|
|
80
103
|
`,
|
|
81
104
|
getReexportsWiring: () => '',
|
|
82
|
-
getFunctorCall: () =>
|
|
83
|
-
|
|
84
|
-
|
|
105
|
+
getFunctorCall: () => {
|
|
106
|
+
let functorExpression = `functors[${index}]`;
|
|
107
|
+
if (useEvaluate) {
|
|
108
|
+
functorExpression = `evaluateSource(...${functorExpression})`;
|
|
109
|
+
}
|
|
110
|
+
return `\
|
|
111
|
+
wrapCjsFunctor(${index}, ${functorExpression})({imports: ${importsMap}});
|
|
112
|
+
`;
|
|
113
|
+
},
|
|
85
114
|
};
|
|
86
115
|
},
|
|
87
116
|
};
|
package/src/bundle-json.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle-json.d.ts","sourceRoot":"","sources":["bundle-json.js"],"names":[],"mappings":";;IAME;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"bundle-json.d.ts","sourceRoot":"","sources":["bundle-json.js"],"names":[],"mappings":";;IAME;;;;;;;;;MAeC"}
|
package/src/bundle-json.js
CHANGED
|
@@ -9,15 +9,14 @@ export default {
|
|
|
9
9
|
const json = JSON.stringify(JSON.parse(textDecoder.decode(bytes)));
|
|
10
10
|
return {
|
|
11
11
|
getFunctor: () => `\
|
|
12
|
-
|
|
13
|
-
(set) => set(${json}),
|
|
12
|
+
${json},
|
|
14
13
|
`,
|
|
15
14
|
getCells: () => `\
|
|
16
15
|
{ default: cell('default') },
|
|
17
16
|
`,
|
|
18
17
|
getReexportsWiring: () => '',
|
|
19
18
|
getFunctorCall: () => `\
|
|
20
|
-
|
|
19
|
+
cells[${index}].default.set(functors[${index}]);
|
|
21
20
|
`,
|
|
22
21
|
};
|
|
23
22
|
},
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export function makeFunctorFromMap(readPowers: ReadFn | ReadPowers | MaybeReadPowers, compartmentMap: CompartmentMapDescriptor, options?: BundleOptions | undefined): Promise<string>;
|
|
2
|
+
export function makeScriptFromMap(readPowers: ReadFn | ReadPowers | MaybeReadPowers, compartmentMap: CompartmentMapDescriptor, options?: BundleOptions | undefined): Promise<string>;
|
|
3
|
+
/**
|
|
4
|
+
* The bundler kit defines a language-specific behavior for injecting a module
|
|
5
|
+
* into a bundle.
|
|
6
|
+
* Each module must allocate cells for its imports and exports, link those cells
|
|
7
|
+
* to the cells of dependencies, and provide both the linker and evaluation behavior
|
|
8
|
+
* for the module.
|
|
9
|
+
* The linker behavior gets injected in a lexical scope with the linker runtime
|
|
10
|
+
* and has access to the cells of all modules, whereas the evaluation behavior
|
|
11
|
+
* gets injected in the generated script's top level lexical scope, so has
|
|
12
|
+
* no accidental visibility into the linkage runtime.
|
|
13
|
+
*
|
|
14
|
+
* For example, JSON modules produce a single "default" cell ("getCells"):
|
|
15
|
+
*
|
|
16
|
+
* { default: cell('default') },
|
|
17
|
+
*
|
|
18
|
+
* Then, the JSON gets injected verbatim for the evaluation behavior ("getFunctor").
|
|
19
|
+
* The linker simply sets the cell to the value.
|
|
20
|
+
*
|
|
21
|
+
* functors[0]['default'].set(modules[0]);
|
|
22
|
+
*
|
|
23
|
+
* For an ECMAScript or CommonJS module, the evaluation behavior is a function
|
|
24
|
+
* that the linker runtime can call to inject it with the cells it needs by
|
|
25
|
+
* the names it sees for them.
|
|
26
|
+
*/
|
|
27
|
+
export type BundlerKit = {
|
|
28
|
+
/**
|
|
29
|
+
* Produces a JavaScript string consisting of
|
|
30
|
+
* a function expression followed by a comma delimiter that will be evaluated in
|
|
31
|
+
* a lexical scope with no free variables except the globals.
|
|
32
|
+
* In the generated bundle runtime, the function will receive an environment
|
|
33
|
+
* record: a record mapping every name of the corresponding module's internal
|
|
34
|
+
* namespace to a "cell" it can use to get, set, or observe the linked
|
|
35
|
+
* variable.
|
|
36
|
+
*/
|
|
37
|
+
getFunctor: () => string;
|
|
38
|
+
/**
|
|
39
|
+
* Produces a JavaScript string consisting of
|
|
40
|
+
* a JavaScript object and a trailing comma.
|
|
41
|
+
* The string is evaluated in the linker runtime's lexical context.
|
|
42
|
+
*/
|
|
43
|
+
getCells: () => string;
|
|
44
|
+
/**
|
|
45
|
+
* Produces a JavaScript string,
|
|
46
|
+
* a statement that effects the module's evaluation behavior using the cells
|
|
47
|
+
* it imports and exports and the evaluated "functor".
|
|
48
|
+
*/
|
|
49
|
+
getFunctorCall: () => string;
|
|
50
|
+
/**
|
|
51
|
+
* Produces a JavaScript string
|
|
52
|
+
* that may include statements that bind the cells reexported by this module.
|
|
53
|
+
*/
|
|
54
|
+
getReexportsWiring: () => string;
|
|
55
|
+
};
|
|
56
|
+
export type BundleModule<SpecificModuleSource extends unknown> = {
|
|
57
|
+
key: string;
|
|
58
|
+
exit: string;
|
|
59
|
+
compartmentName: string;
|
|
60
|
+
moduleSpecifier: string;
|
|
61
|
+
sourceDirname: string;
|
|
62
|
+
parser: string;
|
|
63
|
+
record: StaticModuleType & SpecificModuleSource;
|
|
64
|
+
resolvedImports: Record<string, string>;
|
|
65
|
+
indexedImports: Record<string, number>;
|
|
66
|
+
bytes: Uint8Array;
|
|
67
|
+
index: number;
|
|
68
|
+
bundlerKit: BundlerKit;
|
|
69
|
+
};
|
|
70
|
+
export type BundleExit = {
|
|
71
|
+
exit: string;
|
|
72
|
+
index: number;
|
|
73
|
+
bundlerKit: BundlerKit;
|
|
74
|
+
indexedImports: Record<string, number>;
|
|
75
|
+
resolvedImports: Record<string, string>;
|
|
76
|
+
};
|
|
77
|
+
export type GetBundlerKit<SpecificModuleSource extends unknown> = (module: BundleModule<SpecificModuleSource>, params: {
|
|
78
|
+
useEvaluate?: boolean | undefined;
|
|
79
|
+
sourceUrlPrefix?: string | undefined;
|
|
80
|
+
}) => BundlerKit;
|
|
81
|
+
export type BundlerSupport<SpecificModuleSource extends unknown> = {
|
|
82
|
+
runtime: string;
|
|
83
|
+
getBundlerKit: GetBundlerKit<SpecificModuleSource>;
|
|
84
|
+
};
|
|
85
|
+
import type { ReadFn } from './types.js';
|
|
86
|
+
import type { ReadPowers } from './types.js';
|
|
87
|
+
import type { MaybeReadPowers } from './types.js';
|
|
88
|
+
import type { CompartmentMapDescriptor } from './types.js';
|
|
89
|
+
import type { BundleOptions } from './types.js';
|
|
90
|
+
import type { StaticModuleType } from 'ses';
|
|
91
|
+
//# sourceMappingURL=bundle-lite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-lite.d.ts","sourceRoot":"","sources":["bundle-lite.js"],"names":[],"mappings":"AA4TO,+CALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,wBAAwB,wCAEtB,OAAO,CAAC,MAAM,CAAC,CAgV3B;AAQM,8CALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,wBAAwB,wCAEtB,OAAO,CAAC,MAAM,CAAC,CAW3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA/mBa,MAAM,MAAM;;;;;;cAOZ,MAAM,MAAM;;;;;;oBAGZ,MAAM,MAAM;;;;;wBAGZ,MAAM,MAAM;;yBAKH,oBAAoB,SAA9B,OAAS;SAER,MAAM;UACN,MAAM;qBACN,MAAM;qBACN,MAAM;mBACN,MAAM;YACN,MAAM;YACN,gBAAgB,GAAG,oBAAoB;qBACvC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;oBACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;WACtB,UAAU;WACV,MAAM;gBACN,UAAU;;;UAKV,MAAM;WACN,MAAM;gBACN,UAAU;oBACV,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;qBACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;0BAIb,oBAAoB,SAA9B,OAAS,aAEX,YAAY,CAAC,oBAAoB,CAAC,UAE1C;IAAyB,WAAW;IACZ,eAAe;CACvC,KAAU,UAAU;2BAIA,oBAAoB,SAA9B,OAAS;aAER,MAAM;mBACN,aAAa,CAAC,oBAAoB,CAAC;;4BArFvC,YAAY;gCAAZ,YAAY;qCAAZ,YAAY;8CAAZ,YAAY;mCAAZ,YAAY;sCAVZ,KAAK"}
|