@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/src/bundle-mjs.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* Provides ESM support for `bundle.js`. */
|
|
2
2
|
|
|
3
3
|
/** @import {PrecompiledModuleSource} from 'ses' */
|
|
4
|
-
/** @import {BundlerSupport} from './bundle.js' */
|
|
4
|
+
/** @import {BundlerSupport} from './bundle-lite.js' */
|
|
5
|
+
|
|
6
|
+
import { join } from './node-module-specifier.js';
|
|
5
7
|
|
|
6
8
|
/** quotes strings */
|
|
7
9
|
const q = JSON.stringify;
|
|
@@ -41,7 +43,7 @@ function observeImports(map, importName, importIndex) {
|
|
|
41
43
|
for (const [name, observers] of map.get(importName)) {
|
|
42
44
|
const cell = cells[importIndex][name];
|
|
43
45
|
if (cell === undefined) {
|
|
44
|
-
throw new ReferenceError(\`Cannot import name \${name}\`);
|
|
46
|
+
throw new ReferenceError(\`Cannot import name \${name} (has \${Object.getOwnPropertyNames(cells[importIndex]).join(', ')})\`);
|
|
45
47
|
}
|
|
46
48
|
for (const observer of observers) {
|
|
47
49
|
cell.observe(observer);
|
|
@@ -53,21 +55,30 @@ function observeImports(map, importName, importIndex) {
|
|
|
53
55
|
/** @type {BundlerSupport<PrecompiledModuleSource>} */
|
|
54
56
|
export default {
|
|
55
57
|
runtime,
|
|
56
|
-
getBundlerKit(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
getBundlerKit(
|
|
59
|
+
{
|
|
60
|
+
index,
|
|
61
|
+
indexedImports,
|
|
62
|
+
moduleSpecifier,
|
|
63
|
+
sourceDirname,
|
|
64
|
+
record: {
|
|
65
|
+
__syncModuleProgram__,
|
|
66
|
+
__fixedExportMap__ = {},
|
|
67
|
+
__liveExportMap__ = {},
|
|
68
|
+
__reexportMap__ = {},
|
|
69
|
+
reexports,
|
|
70
|
+
},
|
|
65
71
|
},
|
|
66
|
-
|
|
72
|
+
{ useEvaluate = false },
|
|
73
|
+
) {
|
|
74
|
+
let functor = __syncModuleProgram__;
|
|
75
|
+
if (useEvaluate) {
|
|
76
|
+
const sourceUrl = join(sourceDirname, moduleSpecifier);
|
|
77
|
+
functor = JSON.stringify([functor, sourceUrl]);
|
|
78
|
+
}
|
|
67
79
|
return {
|
|
68
80
|
getFunctor: () => `\
|
|
69
|
-
|
|
70
|
-
${__syncModuleProgram__},
|
|
81
|
+
${functor},
|
|
71
82
|
`,
|
|
72
83
|
getCells: () => `\
|
|
73
84
|
{
|
|
@@ -79,14 +90,14 @@ ${exportsCellRecord(__fixedExportMap__)}${exportsCellRecord(
|
|
|
79
90
|
getReexportsWiring: () => {
|
|
80
91
|
const mappings = reexports.map(
|
|
81
92
|
importSpecifier => `\
|
|
82
|
-
|
|
93
|
+
defineProperties(cells[${index}], getOwnPropertyDescriptors(cells[${indexedImports[importSpecifier]}]));
|
|
83
94
|
`,
|
|
84
95
|
);
|
|
85
96
|
// Create references for export name as newname
|
|
86
97
|
const namedReexportsToProcess = Object.entries(__reexportMap__);
|
|
87
98
|
if (namedReexportsToProcess.length > 0) {
|
|
88
99
|
mappings.push(`
|
|
89
|
-
|
|
100
|
+
defineProperties(cells[${index}], {${namedReexportsToProcess.map(
|
|
90
101
|
([specifier, renames]) => {
|
|
91
102
|
return renames.map(
|
|
92
103
|
([localName, exportedName]) =>
|
|
@@ -100,8 +111,13 @@ ${exportsCellRecord(__fixedExportMap__)}${exportsCellRecord(
|
|
|
100
111
|
}
|
|
101
112
|
return mappings.join('');
|
|
102
113
|
},
|
|
103
|
-
getFunctorCall: () =>
|
|
104
|
-
|
|
114
|
+
getFunctorCall: () => {
|
|
115
|
+
let functorExpression = `functors[${index}]`;
|
|
116
|
+
if (useEvaluate) {
|
|
117
|
+
functorExpression = `evaluateSource(...${functorExpression})`;
|
|
118
|
+
}
|
|
119
|
+
return `\
|
|
120
|
+
${functorExpression}({
|
|
105
121
|
imports(entries) {
|
|
106
122
|
const map = new Map(entries);
|
|
107
123
|
${''.concat(
|
|
@@ -120,7 +136,8 @@ ${importsCellSetter(__fixedExportMap__, index)}\
|
|
|
120
136
|
},
|
|
121
137
|
importMeta: {},
|
|
122
138
|
});
|
|
123
|
-
|
|
139
|
+
`;
|
|
140
|
+
},
|
|
124
141
|
};
|
|
125
142
|
},
|
|
126
143
|
};
|
package/src/bundle.d.ts
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
|
-
export function
|
|
2
|
-
export function
|
|
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
|
+
export function makeFunctor(readPowers: ReadFn | ReadPowers | MaybeReadPowers, moduleLocation: string, options?: BundleOptions | undefined): Promise<string>;
|
|
4
|
+
export function makeScript(readPowers: ReadFn | ReadPowers | MaybeReadPowers, moduleLocation: string, options?: BundleOptions | undefined): Promise<string>;
|
|
5
|
+
export function writeScript(write: WriteFn, read: ReadFn, bundleLocation: string, moduleLocation: string, options?: BundleOptions | undefined): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* The bundler kit defines a language-specific behavior for injecting a module
|
|
8
|
+
* into a bundle.
|
|
9
|
+
* Each module must allocate cells for its imports and exports, link those cells
|
|
10
|
+
* to the cells of dependencies, and provide both the linker and evaluation behavior
|
|
11
|
+
* for the module.
|
|
12
|
+
* The linker behavior gets injected in a lexical scope with the linker runtime
|
|
13
|
+
* and has access to the cells of all modules, whereas the evaluation behavior
|
|
14
|
+
* gets injected in the generated script's top level lexical scope, so has
|
|
15
|
+
* no accidental visibility into the linkage runtime.
|
|
16
|
+
*
|
|
17
|
+
* For example, JSON modules produce a single "default" cell ("getCells"):
|
|
18
|
+
*
|
|
19
|
+
* { default: cell('default') },
|
|
20
|
+
*
|
|
21
|
+
* Then, the JSON gets injected verbatim for the evaluation behavior ("getFunctor").
|
|
22
|
+
* The linker simply sets the cell to the value.
|
|
23
|
+
*
|
|
24
|
+
* functors[0]['default'].set(modules[0]);
|
|
25
|
+
*
|
|
26
|
+
* For an ECMAScript or CommonJS module, the evaluation behavior is a function
|
|
27
|
+
* that the linker runtime can call to inject it with the cells it needs by
|
|
28
|
+
* the names it sees for them.
|
|
29
|
+
*/
|
|
3
30
|
export type BundlerKit = {
|
|
4
31
|
/**
|
|
5
32
|
* Produces a JavaScript string consisting of
|
|
@@ -14,15 +41,13 @@ export type BundlerKit = {
|
|
|
14
41
|
/**
|
|
15
42
|
* Produces a JavaScript string consisting of
|
|
16
43
|
* a JavaScript object and a trailing comma.
|
|
17
|
-
* The string is evaluated in
|
|
18
|
-
* array of every module's internal environment record.
|
|
44
|
+
* The string is evaluated in the linker runtime's lexical context.
|
|
19
45
|
*/
|
|
20
46
|
getCells: () => string;
|
|
21
47
|
/**
|
|
22
|
-
* Produces a JavaScript string
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* other module namespaces.
|
|
48
|
+
* Produces a JavaScript string,
|
|
49
|
+
* a statement that effects the module's evaluation behavior using the cells
|
|
50
|
+
* it imports and exports and the evaluated "functor".
|
|
26
51
|
*/
|
|
27
52
|
getFunctorCall: () => string;
|
|
28
53
|
/**
|
|
@@ -33,8 +58,10 @@ export type BundlerKit = {
|
|
|
33
58
|
};
|
|
34
59
|
export type BundleModule<SpecificModuleSource extends unknown> = {
|
|
35
60
|
key: string;
|
|
61
|
+
exit: string;
|
|
36
62
|
compartmentName: string;
|
|
37
63
|
moduleSpecifier: string;
|
|
64
|
+
sourceDirname: string;
|
|
38
65
|
parser: string;
|
|
39
66
|
record: StaticModuleType & SpecificModuleSource;
|
|
40
67
|
resolvedImports: Record<string, string>;
|
|
@@ -43,7 +70,17 @@ export type BundleModule<SpecificModuleSource extends unknown> = {
|
|
|
43
70
|
index: number;
|
|
44
71
|
bundlerKit: BundlerKit;
|
|
45
72
|
};
|
|
46
|
-
export type
|
|
73
|
+
export type BundleExit = {
|
|
74
|
+
exit: string;
|
|
75
|
+
index: number;
|
|
76
|
+
bundlerKit: BundlerKit;
|
|
77
|
+
indexedImports: Record<string, number>;
|
|
78
|
+
resolvedImports: Record<string, string>;
|
|
79
|
+
};
|
|
80
|
+
export type GetBundlerKit<SpecificModuleSource extends unknown> = (module: BundleModule<SpecificModuleSource>, params: {
|
|
81
|
+
useEvaluate?: boolean | undefined;
|
|
82
|
+
sourceUrlPrefix?: string | undefined;
|
|
83
|
+
}) => BundlerKit;
|
|
47
84
|
export type BundlerSupport<SpecificModuleSource extends unknown> = {
|
|
48
85
|
runtime: string;
|
|
49
86
|
getBundlerKit: GetBundlerKit<SpecificModuleSource>;
|
|
@@ -51,7 +88,8 @@ export type BundlerSupport<SpecificModuleSource extends unknown> = {
|
|
|
51
88
|
import type { ReadFn } from './types.js';
|
|
52
89
|
import type { ReadPowers } from './types.js';
|
|
53
90
|
import type { MaybeReadPowers } from './types.js';
|
|
54
|
-
import type {
|
|
91
|
+
import type { CompartmentMapDescriptor } from './types.js';
|
|
92
|
+
import type { BundleOptions } from './types.js';
|
|
55
93
|
import type { WriteFn } from './types.js';
|
|
56
94
|
import type { StaticModuleType } from 'ses';
|
|
57
95
|
//# sourceMappingURL=bundle.d.ts.map
|
package/src/bundle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["bundle.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["bundle.js"],"names":[],"mappings":"AAgUO,+CALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,wBAAwB,wCAEtB,OAAO,CAAC,MAAM,CAAC,CAiV3B;AAQM,8CALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,wBAAwB,wCAEtB,OAAO,CAAC,MAAM,CAAC,CAW3B;AAQM,wCALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM,wCAEJ,OAAO,CAAC,MAAM,CAAC,CAS3B;AAQM,uCALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM,wCAEJ,OAAO,CAAC,MAAM,CAAC,CAS3B;AASM,mCANI,OAAO,QACP,MAAM,kBACN,MAAM,kBACN,MAAM,sDAahB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBApqBa,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;6BAAZ,YAAY;sCAXZ,KAAK"}
|