@endo/compartment-mapper 1.5.0 → 1.6.1

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.
Files changed (143) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +278 -111
  3. package/SECURITY.md +2 -2
  4. package/bundle.d.ts +1 -1
  5. package/bundle.js +4 -1
  6. package/functor-lite.d.ts +3 -0
  7. package/functor-lite.d.ts.map +1 -0
  8. package/functor-lite.js +4 -0
  9. package/functor.d.ts +3 -0
  10. package/functor.d.ts.map +1 -0
  11. package/functor.js +4 -0
  12. package/index.d.ts +1 -1
  13. package/index.js +4 -1
  14. package/package.json +15 -11
  15. package/script-lite.d.ts +3 -0
  16. package/script-lite.d.ts.map +1 -0
  17. package/script-lite.js +4 -0
  18. package/script.d.ts +3 -0
  19. package/script.d.ts.map +1 -0
  20. package/script.js +4 -0
  21. package/src/archive-lite.d.ts +5 -5
  22. package/src/archive-lite.d.ts.map +1 -1
  23. package/src/archive-lite.js +1 -1
  24. package/src/archive.d.ts +5 -5
  25. package/src/archive.d.ts.map +1 -1
  26. package/src/archive.js +3 -1
  27. package/src/bundle-cjs.d.ts +12 -2
  28. package/src/bundle-cjs.d.ts.map +1 -1
  29. package/src/bundle-cjs.js +57 -28
  30. package/src/bundle-json.d.ts.map +1 -1
  31. package/src/bundle-json.js +2 -3
  32. package/src/bundle-lite.d.ts +91 -0
  33. package/src/bundle-lite.d.ts.map +1 -0
  34. package/src/bundle-lite.js +667 -0
  35. package/src/bundle-mjs.d.ts +13 -3
  36. package/src/bundle-mjs.d.ts.map +1 -1
  37. package/src/bundle-mjs.js +36 -19
  38. package/src/bundle.d.ts +48 -10
  39. package/src/bundle.d.ts.map +1 -1
  40. package/src/bundle.js +392 -126
  41. package/src/capture-lite.d.ts +1 -1
  42. package/src/capture-lite.d.ts.map +1 -1
  43. package/src/capture-lite.js +4 -2
  44. package/src/compartment-map.d.ts +1 -1
  45. package/src/compartment-map.d.ts.map +1 -1
  46. package/src/import-archive-lite.d.ts +2 -2
  47. package/src/import-archive-lite.d.ts.map +1 -1
  48. package/src/import-archive-lite.js +3 -1
  49. package/src/import-archive.d.ts +3 -3
  50. package/src/import-archive.d.ts.map +1 -1
  51. package/src/import-archive.js +3 -1
  52. package/src/import-hook.d.ts +3 -16
  53. package/src/import-hook.d.ts.map +1 -1
  54. package/src/import-hook.js +214 -116
  55. package/src/import-lite.d.ts +1 -1
  56. package/src/import-lite.d.ts.map +1 -1
  57. package/src/import-lite.js +7 -3
  58. package/src/import.d.ts.map +1 -1
  59. package/src/import.js +3 -1
  60. package/src/infer-exports.d.ts +5 -7
  61. package/src/infer-exports.d.ts.map +1 -1
  62. package/src/infer-exports.js +23 -8
  63. package/src/link.d.ts.map +1 -1
  64. package/src/link.js +4 -1
  65. package/src/map-parser.d.ts.map +1 -1
  66. package/src/map-parser.js +51 -5
  67. package/src/node-module-specifier.d.ts.map +1 -1
  68. package/src/node-module-specifier.js +3 -1
  69. package/src/node-modules.d.ts +4 -47
  70. package/src/node-modules.d.ts.map +1 -1
  71. package/src/node-modules.js +267 -148
  72. package/src/node-powers.d.ts +1 -1
  73. package/src/node-powers.d.ts.map +1 -1
  74. package/src/node-powers.js +3 -1
  75. package/src/parse-archive-cjs.d.ts +5 -1
  76. package/src/parse-archive-cjs.d.ts.map +1 -1
  77. package/src/parse-archive-cjs.js +11 -4
  78. package/src/parse-archive-mjs.d.ts +5 -1
  79. package/src/parse-archive-mjs.d.ts.map +1 -1
  80. package/src/parse-archive-mjs.js +3 -1
  81. package/src/parse-bytes.d.ts +5 -1
  82. package/src/parse-bytes.d.ts.map +1 -1
  83. package/src/parse-bytes.js +3 -1
  84. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  85. package/src/parse-cjs-shared-export-wrapper.js +5 -11
  86. package/src/parse-cjs.d.ts +5 -1
  87. package/src/parse-cjs.d.ts.map +1 -1
  88. package/src/parse-cjs.js +4 -2
  89. package/src/parse-json.d.ts +5 -2
  90. package/src/parse-json.d.ts.map +1 -1
  91. package/src/parse-mjs.d.ts +5 -1
  92. package/src/parse-mjs.d.ts.map +1 -1
  93. package/src/parse-mjs.js +2 -2
  94. package/src/parse-pre-cjs.d.ts +5 -1
  95. package/src/parse-pre-cjs.d.ts.map +1 -1
  96. package/src/parse-pre-cjs.js +3 -1
  97. package/src/parse-pre-mjs.d.ts +5 -1
  98. package/src/parse-pre-mjs.d.ts.map +1 -1
  99. package/src/parse-pre-mjs.js +3 -1
  100. package/src/parse-text.d.ts +5 -1
  101. package/src/parse-text.d.ts.map +1 -1
  102. package/src/parse-text.js +3 -1
  103. package/src/policy-format.d.ts +2 -1
  104. package/src/policy-format.d.ts.map +1 -1
  105. package/src/policy-format.js +5 -2
  106. package/src/policy.d.ts +2 -2
  107. package/src/policy.d.ts.map +1 -1
  108. package/src/policy.js +10 -11
  109. package/src/powers.d.ts +1 -1
  110. package/src/powers.d.ts.map +1 -1
  111. package/src/powers.js +3 -1
  112. package/src/search.d.ts +7 -12
  113. package/src/search.d.ts.map +1 -1
  114. package/src/search.js +32 -13
  115. package/src/types/compartment-map-schema.d.ts +8 -1
  116. package/src/types/compartment-map-schema.d.ts.map +1 -1
  117. package/src/types/compartment-map-schema.ts +8 -1
  118. package/src/types/external.d.ts +127 -17
  119. package/src/types/external.d.ts.map +1 -1
  120. package/src/types/external.ts +142 -17
  121. package/src/types/internal.d.ts +116 -29
  122. package/src/types/internal.d.ts.map +1 -1
  123. package/src/types/internal.ts +144 -31
  124. package/src/types/node-modules.d.ts +79 -0
  125. package/src/types/node-modules.d.ts.map +1 -0
  126. package/src/types/node-modules.ts +89 -0
  127. package/src/types/node-powers.d.ts +7 -5
  128. package/src/types/node-powers.d.ts.map +1 -1
  129. package/src/types/node-powers.ts +7 -5
  130. package/src/types/policy-schema.d.ts +3 -1
  131. package/src/types/policy-schema.d.ts.map +1 -1
  132. package/src/types/policy-schema.ts +3 -1
  133. package/src/types/policy.d.ts +3 -1
  134. package/src/types/policy.d.ts.map +1 -1
  135. package/src/types/policy.ts +3 -1
  136. package/src/types/powers.d.ts +5 -3
  137. package/src/types/powers.d.ts.map +1 -1
  138. package/src/types/powers.ts +5 -3
  139. package/src/types/typescript.d.ts +3 -1
  140. package/src/types/typescript.d.ts.map +1 -1
  141. package/src/types/typescript.ts +3 -1
  142. package/src/url.d.ts.map +1 -1
  143. package/src/url.js +3 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@endo/compartment-mapper",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
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"
@@ -56,23 +60,23 @@
56
60
  "test": "ava"
57
61
  },
58
62
  "dependencies": {
59
- "@endo/cjs-module-analyzer": "^1.0.9",
60
- "@endo/module-source": "^1.2.0",
61
- "@endo/trampoline": "^1.0.3",
62
- "@endo/zip": "^1.0.9",
63
- "ses": "^1.11.0"
63
+ "@endo/cjs-module-analyzer": "^1.0.10",
64
+ "@endo/module-source": "^1.3.1",
65
+ "@endo/trampoline": "^1.0.4",
66
+ "@endo/zip": "^1.0.10",
67
+ "ses": "^1.13.0"
64
68
  },
65
69
  "devDependencies": {
66
70
  "ava": "^6.1.3",
67
71
  "babel-eslint": "^10.1.0",
68
72
  "c8": "^7.14.0",
69
- "eslint": "^8.57.0",
73
+ "eslint": "^8.57.1",
70
74
  "eslint-config-airbnb-base": "^15.0.0",
71
75
  "eslint-config-prettier": "^9.1.0",
72
76
  "eslint-plugin-eslint-comments": "^3.2.0",
73
- "eslint-plugin-import": "^2.29.1",
74
- "prettier": "^3.3.3",
75
- "typescript": "~5.6.3"
77
+ "eslint-plugin-import": "^2.31.0",
78
+ "prettier": "^3.5.3",
79
+ "typescript": "~5.8.3"
76
80
  },
77
81
  "files": [
78
82
  "./*.d.ts",
@@ -114,5 +118,5 @@
114
118
  "typeCoverage": {
115
119
  "atLeast": 86.14
116
120
  },
117
- "gitHead": "e0683e0bfdbfc84351af332c9e78813d7b67ef89"
121
+ "gitHead": "571b7803cf10df7cb4fa9d70e4d53a0b53767fa8"
118
122
  }
@@ -0,0 +1,3 @@
1
+ export * from "./src/types-external.js";
2
+ export { makeScriptFromMap } from "./src/bundle-lite.js";
3
+ //# sourceMappingURL=script-lite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-lite.d.ts","sourceRoot":"","sources":["script-lite.js"],"names":[],"mappings":""}
package/script-lite.js ADDED
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
4
+ export { makeScriptFromMap } from './src/bundle-lite.js';
package/script.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./src/types-external.js";
2
+ export { makeScript } from "./src/bundle.js";
3
+ //# sourceMappingURL=script.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["script.js"],"names":[],"mappings":""}
package/script.js ADDED
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
4
+ export { makeScript } from './src/bundle.js';
@@ -1,12 +1,12 @@
1
1
  export function makeArchiveCompartmentMap(compartmentMap: CompartmentMapDescriptor, sources: Sources): ArchiveResult;
2
- export function makeAndHashArchiveFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<{
2
+ export function makeAndHashArchiveFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions): Promise<{
3
3
  bytes: Uint8Array;
4
4
  sha512?: string;
5
5
  }>;
6
- export function makeArchiveFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<Uint8Array>;
7
- export function mapFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<Uint8Array>;
8
- export function hashFromMap(powers: HashPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<string>;
9
- export function writeArchiveFromMap(write: WriteFn, readPowers: ReadFn | ReadPowers, archiveLocation: string, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<void>;
6
+ export function makeArchiveFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions): Promise<Uint8Array>;
7
+ export function mapFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions): Promise<Uint8Array>;
8
+ export function hashFromMap(powers: HashPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions): Promise<string>;
9
+ export function writeArchiveFromMap(write: WriteFn, readPowers: ReadFn | ReadPowers, archiveLocation: string, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions): Promise<void>;
10
10
  import type { CompartmentMapDescriptor } from './types.js';
11
11
  import type { Sources } from './types.js';
12
12
  import type { ArchiveResult } from './types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"archive-lite.d.ts","sourceRoot":"","sources":["archive-lite.js"],"names":[],"mappings":"AAmHO,0DAJI,wBAAwB,WACxB,OAAO,GACL,aAAa,CAiBzB;AAyGM,kDALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAC,CA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7 +176,7 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
176
176
  searchSuffixes,
177
177
  entryCompartmentName,
178
178
  entryModuleSpecifier,
179
- exitModuleImportHook: consolidatedExitModuleImportHook,
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/archive.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export function makeAndHashArchive(powers: ReadFn | ReadPowers, moduleLocation: string, options?: ArchiveOptions | undefined): Promise<{
1
+ export function makeAndHashArchive(powers: ReadFn | ReadPowers, moduleLocation: string, options?: ArchiveOptions): Promise<{
2
2
  bytes: Uint8Array;
3
3
  sha512?: string;
4
4
  }>;
5
- export function makeArchive(powers: ReadFn | ReadPowers, moduleLocation: string, options?: ArchiveOptions | undefined): Promise<Uint8Array>;
6
- export function mapLocation(powers: ReadFn | ReadPowers, moduleLocation: string, options?: ArchiveOptions | undefined): Promise<Uint8Array>;
7
- export function hashLocation(powers: HashPowers, moduleLocation: string, options?: ArchiveOptions | undefined): Promise<string>;
8
- export function writeArchive(write: WriteFn, readPowers: ReadFn | ReadPowers, archiveLocation: string, moduleLocation: string, options?: ArchiveOptions | undefined): Promise<void>;
5
+ export function makeArchive(powers: ReadFn | ReadPowers, moduleLocation: string, options?: ArchiveOptions): Promise<Uint8Array>;
6
+ export function mapLocation(powers: ReadFn | ReadPowers, moduleLocation: string, options?: ArchiveOptions): Promise<Uint8Array>;
7
+ export function hashLocation(powers: HashPowers, moduleLocation: string, options?: ArchiveOptions): Promise<string>;
8
+ export function writeArchive(write: WriteFn, readPowers: ReadFn | ReadPowers, archiveLocation: string, moduleLocation: string, options?: ArchiveOptions): Promise<void>;
9
9
  import type { ReadFn } from './types.js';
10
10
  import type { ReadPowers } from './types.js';
11
11
  import type { ArchiveOptions } from './types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["archive.js"],"names":[],"mappings":"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
- * @module Provides mechanisms for creating archives (zip files with a
2
+ * Provides mechanisms for creating archives (zip files with a
3
3
  * `compartmeent-map.json` and a file for every static dependency of an entry
4
4
  * module).
5
5
  *
@@ -13,6 +13,8 @@
13
13
  * See `archive-lite.js` for a variation that does not depend on Babel
14
14
  * for cases like XS native Compartments where pre-compilation is not
15
15
  * necessary or where the dependency on Babel can be dererred to runtime.
16
+ *
17
+ * @module
16
18
  */
17
19
 
18
20
  /**
@@ -1,8 +1,18 @@
1
- declare const _default: BundlerSupport<CjsModuleSource>;
1
+ declare const _default: {
2
+ runtime: string;
3
+ getBundlerKit({ index, indexedImports, moduleSpecifier, sourceDirname, record: { cjsFunctor, exports: exportsList }, }: import("./bundle-lite.js").BundleModule<CjsModuleSource>, { useEvaluate }: {
4
+ useEvaluate?: boolean | undefined;
5
+ sourceUrlPrefix?: string | undefined;
6
+ }): {
7
+ getFunctor: () => string;
8
+ getCells: () => string;
9
+ getReexportsWiring: () => string;
10
+ getFunctorCall: () => string;
11
+ };
12
+ };
2
13
  export default _default;
3
14
  export type CjsModuleSource = VirtualModuleSource & {
4
15
  cjsFunctor: string;
5
16
  };
6
- import type { BundlerSupport } from './bundle.js';
7
17
  import type { VirtualModuleSource } from 'ses';
8
18
  //# sourceMappingURL=bundle-cjs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bundle-cjs.d.ts","sourceRoot":"","sources":["bundle-cjs.js"],"names":[],"mappings":"wBA4DW,eAAe,eAAe,CAAC;;8BAvD5B,mBAAmB,GAAG;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC;oCAFtB,aAAa;yCADR,KAAK"}
1
+ {"version":3,"file":"bundle-cjs.d.ts","sourceRoot":"","sources":["bundle-cjs.js"],"names":[],"mappings":";;;;;;;;;;;;;8BAKc,mBAAmB,GAAG;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC;yCAHjB,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(num) {
26
+ function wrapCjsFunctor(index, functor) {
25
27
  /* eslint-disable no-undef */
26
28
  return ({ imports = {} }) => {
27
- const moduleCells = cells[num];
28
- const cModule = Object.freeze(
29
- Object.defineProperty({}, 'exports', moduleCells.default),
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
- functors[num](Object.freeze(requireImpl), cModule.exports, cModule);
35
+ functor(freeze(requireImpl), cModule.exports, cModule);
34
36
  // Update all named cells from module.exports.
35
- Object.keys(moduleCells)
36
- .filter(k => k !== 'default' && k !== '*')
37
- .map(k => moduleCells[k].set(cModule.exports[k]));
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
- Object.keys(cModule.exports)
40
- .filter(k => k !== 'default' && k !== '*')
41
- .filter(k => moduleCells[k] === undefined)
42
- .map(k => (moduleCells[k] = cell(k, cModule.exports[k])));
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 = Object.create(null, {
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
- Object.keys(moduleCells)
54
- .filter(k => k !== '*')
55
- .map(k => Object.defineProperty(starExports, k, moduleCells[k]));
56
- moduleCells['*'].set(Object.freeze(starExports));
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
- index,
66
- indexedImports,
67
- record: { cjsFunctor, exports: exportsList = {} },
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
- // === functors[${index}] ===
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
- wrapCjsFunctor(${index})({imports: ${importsMap}});
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
  };
@@ -1 +1 @@
1
- {"version":3,"file":"bundle-json.d.ts","sourceRoot":"","sources":["bundle-json.js"],"names":[],"mappings":";;IAME;;;;;;;;;MAgBC"}
1
+ {"version":3,"file":"bundle-json.d.ts","sourceRoot":"","sources":["bundle-json.js"],"names":[],"mappings":";;IAME;;;;;;;;;MAeC"}
@@ -9,15 +9,14 @@ export default {
9
9
  const json = JSON.stringify(JSON.parse(textDecoder.decode(bytes)));
10
10
  return {
11
11
  getFunctor: () => `\
12
- // === functors[${index}] ===
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
- functors[${index}](cells[${index}].default.set);
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): Promise<string>;
2
+ export function makeScriptFromMap(readPowers: ReadFn | ReadPowers | MaybeReadPowers, compartmentMap: CompartmentMapDescriptor, options?: BundleOptions): 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":"AA2TO,+CALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,wBAAwB,YACxB,aAAa,GACX,OAAO,CAAC,MAAM,CAAC,CAgV3B;AAQM,8CALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,wBAAwB,YACxB,aAAa,GACX,OAAO,CAAC,MAAM,CAAC,CAW3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA9mBa,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"}