@endo/compartment-mapper 1.3.0 → 1.4.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.
Files changed (145) hide show
  1. package/README.md +50 -27
  2. package/archive-lite.d.ts +1 -0
  3. package/archive-lite.js +3 -0
  4. package/archive-parsers.d.ts +1 -0
  5. package/archive-parsers.js +3 -0
  6. package/archive.d.ts +1 -0
  7. package/archive.js +3 -0
  8. package/bundle.d.ts +1 -0
  9. package/bundle.js +3 -0
  10. package/capture-lite.d.ts +1 -0
  11. package/capture-lite.js +3 -0
  12. package/import-archive-lite.d.ts +1 -0
  13. package/import-archive-lite.js +3 -0
  14. package/import-archive-parsers.d.ts +1 -0
  15. package/import-archive-parsers.js +3 -0
  16. package/import-archive.d.ts +1 -0
  17. package/import-archive.js +3 -0
  18. package/import-lite.d.ts +1 -0
  19. package/import-lite.js +3 -0
  20. package/import-parsers.d.ts +1 -0
  21. package/import-parsers.js +3 -0
  22. package/import.d.ts +1 -0
  23. package/import.js +3 -0
  24. package/index.d.ts +1 -0
  25. package/index.js +3 -1
  26. package/node-modules.d.ts +1 -0
  27. package/node-modules.js +3 -0
  28. package/node-powers.d.ts +1 -0
  29. package/node-powers.js +3 -0
  30. package/package.json +10 -14
  31. package/src/archive-lite.d.ts +6 -6
  32. package/src/archive-lite.d.ts.map +1 -1
  33. package/src/archive-lite.js +35 -33
  34. package/src/archive.d.ts.map +1 -1
  35. package/src/archive.js +132 -28
  36. package/src/bundle.d.ts.map +1 -1
  37. package/src/bundle.js +54 -14
  38. package/src/capture-lite.d.ts +2 -2
  39. package/src/capture-lite.d.ts.map +1 -1
  40. package/src/capture-lite.js +21 -17
  41. package/src/compartment-map.d.ts +2 -1
  42. package/src/compartment-map.d.ts.map +1 -1
  43. package/src/compartment-map.js +11 -5
  44. package/src/extension.d.ts.map +1 -1
  45. package/src/extension.js +1 -3
  46. package/src/import-archive-lite.d.ts +3 -19
  47. package/src/import-archive-lite.d.ts.map +1 -1
  48. package/src/import-archive-lite.js +43 -57
  49. package/src/import-archive-parsers.d.ts.map +1 -1
  50. package/src/import-archive-parsers.js +1 -0
  51. package/src/import-archive.d.ts +2 -2
  52. package/src/import-archive.d.ts.map +1 -1
  53. package/src/import-archive.js +15 -12
  54. package/src/import-hook.d.ts +2 -1
  55. package/src/import-hook.d.ts.map +1 -1
  56. package/src/import-hook.js +87 -76
  57. package/src/import-lite.d.ts.map +1 -1
  58. package/src/import-lite.js +23 -23
  59. package/src/import.d.ts.map +1 -1
  60. package/src/import.js +47 -23
  61. package/src/infer-exports.d.ts.map +1 -1
  62. package/src/infer-exports.js +2 -3
  63. package/src/json.d.ts.map +1 -1
  64. package/src/json.js +1 -2
  65. package/src/link.d.ts.map +1 -1
  66. package/src/link.js +12 -29
  67. package/src/map-parser.d.ts.map +1 -1
  68. package/src/map-parser.js +21 -16
  69. package/src/node-module-specifier.d.ts.map +1 -1
  70. package/src/node-module-specifier.js +2 -3
  71. package/src/node-modules.d.ts +9 -7
  72. package/src/node-modules.d.ts.map +1 -1
  73. package/src/node-modules.js +176 -87
  74. package/src/node-powers.d.ts +8 -8
  75. package/src/node-powers.d.ts.map +1 -1
  76. package/src/node-powers.js +29 -24
  77. package/src/parse-archive-cjs.d.ts +3 -2
  78. package/src/parse-archive-cjs.d.ts.map +1 -1
  79. package/src/parse-archive-cjs.js +5 -4
  80. package/src/parse-archive-mjs.d.ts +3 -2
  81. package/src/parse-archive-mjs.d.ts.map +1 -1
  82. package/src/parse-archive-mjs.js +7 -5
  83. package/src/parse-bytes.d.ts +3 -2
  84. package/src/parse-bytes.d.ts.map +1 -1
  85. package/src/parse-bytes.js +7 -5
  86. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  87. package/src/parse-cjs-shared-export-wrapper.js +7 -6
  88. package/src/parse-cjs.d.ts +3 -2
  89. package/src/parse-cjs.d.ts.map +1 -1
  90. package/src/parse-cjs.js +14 -5
  91. package/src/parse-json.d.ts.map +1 -1
  92. package/src/parse-json.js +6 -6
  93. package/src/parse-mjs.d.ts +3 -2
  94. package/src/parse-mjs.d.ts.map +1 -1
  95. package/src/parse-mjs.js +3 -3
  96. package/src/parse-pre-cjs.d.ts +3 -2
  97. package/src/parse-pre-cjs.d.ts.map +1 -1
  98. package/src/parse-pre-cjs.js +14 -4
  99. package/src/parse-pre-mjs.d.ts +3 -2
  100. package/src/parse-pre-mjs.d.ts.map +1 -1
  101. package/src/parse-pre-mjs.js +4 -3
  102. package/src/parse-text.d.ts +3 -2
  103. package/src/parse-text.d.ts.map +1 -1
  104. package/src/parse-text.js +6 -5
  105. package/src/policy-format.d.ts +1 -1
  106. package/src/policy-format.d.ts.map +1 -1
  107. package/src/policy-format.js +5 -7
  108. package/src/policy.d.ts.map +1 -1
  109. package/src/policy.js +15 -10
  110. package/src/powers.d.ts.map +1 -1
  111. package/src/powers.js +15 -12
  112. package/src/search.d.ts.map +1 -1
  113. package/src/search.js +10 -7
  114. package/src/types/compartment-map-schema.d.ts +98 -0
  115. package/src/types/compartment-map-schema.d.ts.map +1 -0
  116. package/src/types/compartment-map-schema.ts +116 -0
  117. package/src/types/external.d.ts +256 -0
  118. package/src/types/external.d.ts.map +1 -0
  119. package/src/types/external.ts +379 -0
  120. package/src/types/internal.d.ts +161 -0
  121. package/src/types/internal.d.ts.map +1 -0
  122. package/src/types/internal.ts +216 -0
  123. package/src/types/node-powers.d.ts +46 -0
  124. package/src/types/node-powers.d.ts.map +1 -0
  125. package/src/types/node-powers.ts +52 -0
  126. package/src/types/policy-schema.d.ts +81 -0
  127. package/src/types/policy-schema.d.ts.map +1 -0
  128. package/src/types/policy-schema.ts +131 -0
  129. package/src/types/policy.d.ts +20 -0
  130. package/src/types/policy.d.ts.map +1 -0
  131. package/src/types/policy.ts +42 -0
  132. package/src/types/powers.d.ts +83 -0
  133. package/src/types/powers.d.ts.map +1 -0
  134. package/src/types/powers.ts +120 -0
  135. package/src/types/typescript.d.ts +28 -0
  136. package/src/types/typescript.d.ts.map +1 -0
  137. package/src/types/typescript.ts +41 -0
  138. package/src/types-external.d.ts +14 -0
  139. package/src/types-external.js +2 -0
  140. package/src/types.d.ts +9 -787
  141. package/src/url.d.ts.map +1 -1
  142. package/src/url.js +2 -3
  143. package/src/types.d.ts.map +0 -1
  144. package/src/types.js +0 -995
  145. package/types.d.ts +0 -19
package/README.md CHANGED
@@ -204,6 +204,8 @@ does not exist, to the `index.js` file in the directory with the same name.
204
204
  > `fetch` global, in conjunction with usable values for `import.meta.url` in
205
205
  > ECMAScript modules or `__dirname` and `__filename` in CommonJS modules.
206
206
 
207
+ ## Language Extensions
208
+
207
209
  Officially beginning with Node.js 14, Node.js treats `.mjs` files as ECMAScript
208
210
  modules and `.cjs` files as CommonJS modules.
209
211
  The `.js` extension indicates a CommonJS module by default, to maintain
@@ -211,30 +213,6 @@ backward compatibility.
211
213
  However, packages that have a `type` property that explicitly says `module`
212
214
  will treat a `.js` file as an ECMAScript module.
213
215
 
214
- This unforunately conflicts with packages written to work with the ECMAScript
215
- module system emulator in the `esm` package on npm, which allows every file
216
- with the `js` extension to be an ECMAScript module that presents itself to
217
- Node.js as a CommonJS module.
218
- To overcome such obstacles, the compartment mapper will accept a non-standard
219
- `parsers` property in `package.json` that maps file extensions, specifically
220
- `js` to the corresponding language name, one of `mjs` for ECMAScript modules,
221
- `cjs` for CommonJS modules, and `json` for JSON modules.
222
- All other language names are reserved and the defaults for files with the
223
- extensions `cjs`, `mjs`, `json`, `text`, and `bytes` default to the language of
224
- the same name unless overridden.
225
- JSON modules export a default object resulting from the conventional JSON.parse
226
- of the module's UTF-8 encoded bytes.
227
- Text modules export a default string from the module's UTF-8 encoded bytes.
228
- Bytes modules export a default ArrayBuffer capturing the module's bytes.
229
- If compartment mapper sees `parsers`, it ignores `type`, so these can
230
- contradict where using the `esm` emulator requires.
231
-
232
- ```json
233
- {
234
- "parsers": {"js": "mjs"}
235
- }
236
- ```
237
-
238
216
  Many Node.js applications using CommonJS modules expect to be able to `require`
239
217
  a JSON file like `package.json`.
240
218
  The compartment mapper supports loading JSON modules from any type of module.
@@ -252,9 +230,54 @@ As of Node.js 14, Node does not support loading ECMAScript modules from
252
230
  CommonJS modules, so using this feature may limit compatibility with the
253
231
  Node.js platform.
254
232
 
255
- > TODO A future version may introduce language plugins, so a package may state
256
- > that files with a particular extension are either parsed or linked with
257
- > another module.
233
+ The compartment mapper supports language plugins.
234
+ The languages supported by default are:
235
+
236
+ - `mjs` for ECMAScript modules,
237
+ - `cjs` for CommonJS modules,
238
+ - `json` for JSON modules,
239
+ - `text` for UTF-8 encoded text files,
240
+ - `bytes` for any file, exporting a `Uint8Array` as `default`,
241
+ - `pre-mjs-json` for pre-compiled ECMAScript modules captured as JSON in
242
+ archives, and
243
+ - `pre-cjs-json` for pre-compiled CommonJS modules captured as JSON in
244
+ archives.
245
+
246
+ The compartment mapper accepts extensions to this set of languages with
247
+ the `parserForLanguage` option supported by many functions.
248
+ See `src/types/external.ts` for the type and expected behavior for
249
+ parsers.
250
+
251
+ These language identifiers are keys for the `moduleTransforms` and
252
+ `syncModuleTransforms` options, which may map each language to a transform
253
+ function.
254
+ The language identifiers are also the values for a `languageForExtension`,
255
+ `moduleLanguageForExtension`, and `commonjsLanguageForExtension` options to
256
+ configure additional extension-to-language mappings for a module and its
257
+ transitive dependencies.
258
+
259
+ For any package that has `type` set to `"module"` in its `package.json`,
260
+ `moduleLangaugeForExtension` will precede `languageForExtension`.
261
+ Packages with `type` set to `"commonjs"` or simply not set,
262
+ `commonjsLanguageForExtension` will precede `languageForExtension`.
263
+ This provides an hook for mapping TypeScript's `.ts` to either `.cts` or
264
+ `.mts`.
265
+
266
+ The analogous `workspaceLanguageForExtension`,
267
+ `workspaceCommonjsLanguageForExtension`, and
268
+ `workspaceModuleLanguageForExtension` options apply more specifically for
269
+ packages that are not under a `node_modules` directory, indicating that they
270
+ are in the set of linked workspaces and have not been built or published to
271
+ npm.
272
+
273
+ In the scope any given package, the `parsers` property in `package.json` may
274
+ override the extension-to-language mapping.
275
+
276
+ ```json
277
+ {
278
+ "parsers": { "png": "bytes" }
279
+ }
280
+ ```
258
281
 
259
282
  > TODO
260
283
  >
package/archive-lite.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { makeArchiveFromMap, makeAndHashArchiveFromMap, writeArchiveFromMap, mapFromMap, hashFromMap } from "./src/archive-lite.js";
2
3
  //# sourceMappingURL=archive-lite.d.ts.map
package/archive-lite.js CHANGED
@@ -1,3 +1,6 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export {
2
5
  makeArchiveFromMap,
3
6
  makeAndHashArchiveFromMap,
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { defaultParserForLanguage } from "./src/archive-parsers.js";
2
3
  //# sourceMappingURL=archive-parsers.d.ts.map
@@ -1 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export { defaultParserForLanguage } from './src/archive-parsers.js';
package/archive.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { makeArchive, makeAndHashArchive, writeArchive, mapLocation, hashLocation } from "./src/archive.js";
2
3
  //# sourceMappingURL=archive.d.ts.map
package/archive.js CHANGED
@@ -1,3 +1,6 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export {
2
5
  makeArchive,
3
6
  makeAndHashArchive,
package/bundle.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { makeBundle, writeBundle } from "./src/bundle.js";
2
3
  //# sourceMappingURL=bundle.d.ts.map
package/bundle.js CHANGED
@@ -1 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export { makeBundle, writeBundle } from './src/bundle.js';
package/capture-lite.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { captureFromMap } from "./src/capture-lite.js";
2
3
  //# sourceMappingURL=capture-lite.d.ts.map
package/capture-lite.js CHANGED
@@ -1 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export { captureFromMap } from './src/capture-lite.js';
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { parseArchive, loadArchive, importArchive } from "./src/import-archive-lite.js";
2
3
  //# sourceMappingURL=import-archive-lite.d.ts.map
@@ -1,3 +1,6 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export {
2
5
  parseArchive,
3
6
  loadArchive,
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { defaultParserForLanguage } from "./src/import-archive-parsers.js";
2
3
  //# sourceMappingURL=import-archive-parsers.d.ts.map
@@ -1 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export { defaultParserForLanguage } from './src/import-archive-parsers.js';
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { parseArchive, loadArchive, importArchive } from "./src/import-archive.js";
2
3
  //# sourceMappingURL=import-archive.d.ts.map
package/import-archive.js CHANGED
@@ -1,3 +1,6 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export {
2
5
  parseArchive,
3
6
  loadArchive,
package/import-lite.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { loadFromMap, importFromMap } from "./src/import-lite.js";
2
3
  //# sourceMappingURL=import-lite.d.ts.map
package/import-lite.js CHANGED
@@ -1 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export { loadFromMap, importFromMap } from './src/import-lite.js';
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { defaultParserForLanguage } from "./src/import-parsers.js";
2
3
  //# sourceMappingURL=import-parsers.d.ts.map
package/import-parsers.js CHANGED
@@ -1 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export { defaultParserForLanguage } from './src/import-parsers.js';
package/import.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { loadLocation, importLocation } from "./src/import.js";
2
3
  //# sourceMappingURL=import.d.ts.map
package/import.js CHANGED
@@ -1 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export { loadLocation, importLocation } from './src/import.js';
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./src/types-external.js";
1
2
  export { search } from "./src/search.js";
2
3
  export { compartmentMapForNodeModules } from "./src/node-modules.js";
3
4
  export { loadLocation, importLocation } from "./src/import.js";
package/index.js CHANGED
@@ -1,4 +1,6 @@
1
- // @ts-check
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
2
4
  export { loadLocation, importLocation } from './src/import.js';
3
5
  export {
4
6
  makeArchive,
package/node-modules.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { mapNodeModules } from "./src/node-modules.js";
2
3
  //# sourceMappingURL=node-modules.d.ts.map
package/node-modules.js CHANGED
@@ -1 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export { mapNodeModules } from './src/node-modules.js';
package/node-powers.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "./src/types-external.js";
1
2
  export { makeReadPowers, makeWritePowers, makeReadNowPowers, makeNodeReadPowers, makeNodeWritePowers } from "./src/node-powers.js";
2
3
  //# sourceMappingURL=node-powers.d.ts.map
package/node-powers.js CHANGED
@@ -1,3 +1,6 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
1
4
  export {
2
5
  makeReadPowers,
3
6
  makeWritePowers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@endo/compartment-mapper",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "The compartment mapper assembles Node applications in a sandbox",
5
5
  "keywords": [
6
6
  "node",
@@ -21,12 +21,8 @@
21
21
  },
22
22
  "type": "module",
23
23
  "main": "./index.js",
24
- "types": "./types.d.ts",
25
24
  "exports": {
26
- ".": {
27
- "types": "./types.d.ts",
28
- "default": "./index.js"
29
- },
25
+ ".": "./index.js",
30
26
  "./import.js": "./import.js",
31
27
  "./import-lite.js": "./import-lite.js",
32
28
  "./import-parsers.js": "./import-parsers.js",
@@ -55,11 +51,11 @@
55
51
  "test": "ava"
56
52
  },
57
53
  "dependencies": {
58
- "@endo/cjs-module-analyzer": "^1.0.8",
59
- "@endo/module-source": "^1.1.0",
60
- "@endo/trampoline": "^1.0.2",
61
- "@endo/zip": "^1.0.8",
62
- "ses": "^1.9.0"
54
+ "@endo/cjs-module-analyzer": "^1.0.9",
55
+ "@endo/module-source": "^1.1.2",
56
+ "@endo/trampoline": "^1.0.3",
57
+ "@endo/zip": "^1.0.9",
58
+ "ses": "^1.10.0"
63
59
  },
64
60
  "devDependencies": {
65
61
  "ava": "^6.1.3",
@@ -70,8 +66,8 @@
70
66
  "eslint-config-prettier": "^9.1.0",
71
67
  "eslint-plugin-eslint-comments": "^3.2.0",
72
68
  "eslint-plugin-import": "^2.29.1",
73
- "prettier": "^3.2.5",
74
- "typescript": "~5.6.2"
69
+ "prettier": "^3.3.3",
70
+ "typescript": "~5.6.3"
75
71
  },
76
72
  "files": [
77
73
  "./*.d.ts",
@@ -113,5 +109,5 @@
113
109
  "typeCoverage": {
114
110
  "atLeast": 86.14
115
111
  },
116
- "gitHead": "bbf20fae6726f7d26456714b8852572787d34e05"
112
+ "gitHead": "5486ed1f238104716b6a8321b977fbc508ef80e1"
117
113
  }
@@ -2,19 +2,19 @@ export function makeArchiveCompartmentMap(compartmentMap: CompartmentMapDescript
2
2
  archiveCompartmentMap: CompartmentMapDescriptor;
3
3
  archiveSources: Sources;
4
4
  };
5
- export function makeAndHashArchiveFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveOptions | undefined): Promise<{
5
+ export function makeAndHashArchiveFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<{
6
6
  bytes: Uint8Array;
7
7
  sha512?: string;
8
8
  }>;
9
- export function makeArchiveFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveOptions | undefined): Promise<Uint8Array>;
10
- export function mapFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveOptions | undefined): Promise<Uint8Array>;
11
- export function hashFromMap(powers: HashPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveOptions | undefined): Promise<string>;
12
- export function writeArchiveFromMap(write: WriteFn, readPowers: ReadFn | ReadPowers, archiveLocation: string, compartmentMap: CompartmentMapDescriptor, options?: ArchiveOptions | undefined): Promise<void>;
9
+ export function makeArchiveFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<Uint8Array>;
10
+ export function mapFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<Uint8Array>;
11
+ export function hashFromMap(powers: HashPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<string>;
12
+ export function writeArchiveFromMap(write: WriteFn, readPowers: ReadFn | ReadPowers, archiveLocation: string, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<void>;
13
13
  import type { CompartmentMapDescriptor } from './types.js';
14
14
  import type { Sources } from './types.js';
15
15
  import type { ReadFn } from './types.js';
16
16
  import type { ReadPowers } from './types.js';
17
- import type { ArchiveOptions } from './types.js';
17
+ import type { ArchiveLiteOptions } from './types.js';
18
18
  import type { HashPowers } from './types.js';
19
19
  import type { WriteFn } from './types.js';
20
20
  //# sourceMappingURL=archive-lite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"archive-lite.d.ts","sourceRoot":"","sources":["archive-lite.js"],"names":[],"mappings":"AA2QO,0DAJI,wBAAwB,WACxB,OAAO,GACL;IAAC,qBAAqB,EAAE,wBAAwB,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAC,CAmCtF;AA6GM,kDALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,yCAEtB,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC,CAmBzD;AAQM,2CALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,yCAEtB,OAAO,CAAC,UAAU,CAAC,CAS/B;AAQM,mCALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,yCAEtB,OAAO,CAAC,UAAU,CAAC,CAS/B;AAQM,oCALI,UAAU,kBACV,wBAAwB,yCAEtB,OAAO,CAAC,MAAM,CAAC,CAU3B;AASM,2CANI,OAAO,cACP,MAAM,GAAG,UAAU,mBACnB,MAAM,kBACN,wBAAwB,uDAgBlC;8CA1c2C,YAAY;6BAM7B,YAAY;4BAJb,YAAY;gCAER,YAAY;oCAPR,YAAY;gCAQhB,YAAY;6BAEf,YAAY"}
1
+ {"version":3,"file":"archive-lite.d.ts","sourceRoot":"","sources":["archive-lite.js"],"names":[],"mappings":"AAiRO,0DAJI,wBAAwB,WACxB,OAAO,GACL;IAAC,qBAAqB,EAAE,wBAAwB,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAC,CAmCtF;AAyGM,kDALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC,CAmBzD;AAQM,2CALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,UAAU,CAAC,CAS/B;AAQM,mCALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,UAAU,CAAC,CAS/B;AAQM,oCALI,UAAU,kBACV,wBAAwB,6CAEtB,OAAO,CAAC,MAAM,CAAC,CAU3B;AASM,2CANI,OAAO,cACP,MAAM,GAAG,UAAU,mBACnB,MAAM,kBACN,wBAAwB,2DAgBlC;8CAncS,YAAY;6BAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;wCAAZ,YAAY;gCAAZ,YAAY;6BAAZ,YAAY"}
@@ -28,20 +28,23 @@
28
28
  * web platform makes further progress on virtual module loaers.
29
29
  */
30
30
 
31
- // @ts-check
32
31
  /* eslint no-shadow: 0 */
33
32
 
34
- /** @import {ArchiveOptions} from './types.js' */
35
- /** @import {ArchiveWriter} from './types.js' */
36
- /** @import {CompartmentDescriptor} from './types.js' */
37
- /** @import {CompartmentMapDescriptor} from './types.js' */
38
- /** @import {ModuleDescriptor} from './types.js' */
39
- /** @import {ReadFn} from './types.js' */
40
- /** @import {CaptureSourceLocationHook} from './types.js' */
41
- /** @import {ReadPowers} from './types.js' */
42
- /** @import {HashPowers} from './types.js' */
43
- /** @import {Sources} from './types.js' */
44
- /** @import {WriteFn} from './types.js' */
33
+ /**
34
+ * @import {
35
+ * ArchiveLiteOptions,
36
+ * ArchiveWriter,
37
+ * CaptureSourceLocationHook,
38
+ * CompartmentDescriptor,
39
+ * CompartmentMapDescriptor,
40
+ * HashPowers,
41
+ * ModuleDescriptor,
42
+ * ReadFn,
43
+ * ReadPowers,
44
+ * Sources,
45
+ * WriteFn,
46
+ * } from './types.js'
47
+ */
45
48
 
46
49
  import { writeZip } from '@endo/zip';
47
50
  import { resolve } from './node-module-specifier.js';
@@ -148,22 +151,25 @@ const translateCompartmentMap = (compartments, sources, compartmentRenames) => {
148
151
  const result = create(null);
149
152
  for (const compartmentName of keys(compartmentRenames)) {
150
153
  const compartment = compartments[compartmentName];
151
- const { name, label, retained, policy } = compartment;
152
- if (retained) {
154
+ const { name, label, retained: compartmentRetained, policy } = compartment;
155
+ if (compartmentRetained) {
153
156
  // rename module compartments
154
157
  /** @type {Record<string, ModuleDescriptor>} */
155
158
  const modules = create(null);
156
159
  const compartmentModules = compartment.modules;
157
160
  if (compartment.modules) {
158
161
  for (const name of keys(compartmentModules).sort()) {
159
- const module = compartmentModules[name];
160
- if (module.compartment !== undefined) {
161
- modules[name] = {
162
- ...module,
163
- compartment: compartmentRenames[module.compartment],
164
- };
165
- } else {
166
- modules[name] = module;
162
+ const { retained: moduleRetained, ...retainedModule } =
163
+ compartmentModules[name];
164
+ if (moduleRetained) {
165
+ if (retainedModule.compartment !== undefined) {
166
+ modules[name] = {
167
+ ...retainedModule,
168
+ compartment: compartmentRenames[retainedModule.compartment],
169
+ };
170
+ } else {
171
+ modules[name] = retainedModule;
172
+ }
167
173
  }
168
174
  }
169
175
  }
@@ -303,7 +309,7 @@ export const makeArchiveCompartmentMap = (compartmentMap, sources) => {
303
309
  /**
304
310
  * @param {ReadFn | ReadPowers} powers
305
311
  * @param {CompartmentMapDescriptor} compartmentMap
306
- * @param {ArchiveOptions} [options]
312
+ * @param {ArchiveLiteOptions} [options]
307
313
  * @returns {Promise<{sources: Sources, compartmentMapBytes: Uint8Array, sha512?: string}>}
308
314
  */
309
315
  const digestFromMap = async (powers, compartmentMap, options = {}) => {
@@ -316,15 +322,11 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
316
322
  policy = undefined,
317
323
  sourceMapHook = undefined,
318
324
  parserForLanguage: parserForLanguageOption = {},
319
- languageForExtension: languageForExtensionOption = {},
320
325
  } = options;
321
326
 
322
327
  const parserForLanguage = freeze(
323
328
  assign(create(null), parserForLanguageOption),
324
329
  );
325
- const languageForExtension = freeze(
326
- assign(create(null), languageForExtensionOption),
327
- );
328
330
 
329
331
  const { read, computeSha512 } = unpackReadPowers(powers);
330
332
 
@@ -339,6 +341,7 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
339
341
  const consolidatedExitModuleImportHook = exitModuleImportHookMaker({
340
342
  modules: exitModules,
341
343
  exitModuleImportHook,
344
+ entryCompartmentName,
342
345
  });
343
346
 
344
347
  const makeImportHook = makeImportHookMaker(read, entryCompartmentName, {
@@ -358,7 +361,6 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
358
361
  makeImportHook,
359
362
  moduleTransforms,
360
363
  parserForLanguage,
361
- languageForExtension,
362
364
  archiveOnly: true,
363
365
  });
364
366
  await compartment.load(entryModuleSpecifier);
@@ -404,7 +406,7 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
404
406
  /**
405
407
  * @param {ReadFn | ReadPowers} powers
406
408
  * @param {CompartmentMapDescriptor} compartmentMap
407
- * @param {ArchiveOptions} [options]
409
+ * @param {ArchiveLiteOptions} [options]
408
410
  * @returns {Promise<{bytes: Uint8Array, sha512?: string}>}
409
411
  */
410
412
  export const makeAndHashArchiveFromMap = async (
@@ -429,7 +431,7 @@ export const makeAndHashArchiveFromMap = async (
429
431
  /**
430
432
  * @param {ReadFn | ReadPowers} powers
431
433
  * @param {CompartmentMapDescriptor} compartmentMap
432
- * @param {ArchiveOptions} [options]
434
+ * @param {ArchiveLiteOptions} [options]
433
435
  * @returns {Promise<Uint8Array>}
434
436
  */
435
437
  export const makeArchiveFromMap = async (powers, compartmentMap, options) => {
@@ -444,7 +446,7 @@ export const makeArchiveFromMap = async (powers, compartmentMap, options) => {
444
446
  /**
445
447
  * @param {ReadFn | ReadPowers} powers
446
448
  * @param {CompartmentMapDescriptor} compartmentMap
447
- * @param {ArchiveOptions} [options]
449
+ * @param {ArchiveLiteOptions} [options]
448
450
  * @returns {Promise<Uint8Array>}
449
451
  */
450
452
  export const mapFromMap = async (powers, compartmentMap, options) => {
@@ -459,7 +461,7 @@ export const mapFromMap = async (powers, compartmentMap, options) => {
459
461
  /**
460
462
  * @param {HashPowers} powers
461
463
  * @param {CompartmentMapDescriptor} compartmentMap
462
- * @param {ArchiveOptions} [options]
464
+ * @param {ArchiveLiteOptions} [options]
463
465
  * @returns {Promise<string>}
464
466
  */
465
467
  export const hashFromMap = async (powers, compartmentMap, options) => {
@@ -477,7 +479,7 @@ export const hashFromMap = async (powers, compartmentMap, options) => {
477
479
  * @param {ReadFn | ReadPowers} readPowers
478
480
  * @param {string} archiveLocation
479
481
  * @param {CompartmentMapDescriptor} compartmentMap
480
- * @param {ArchiveOptions} [options]
482
+ * @param {ArchiveLiteOptions} [options]
481
483
  */
482
484
  export const writeArchiveFromMap = async (
483
485
  write,
@@ -1 +1 @@
1
- {"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["archive.js"],"names":[],"mappings":"AAsDO,2CALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC,CAazD;AAQM,oCALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC,UAAU,CAAC,CAiB/B;AAQM,oCALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC,UAAU,CAAC,CAa/B;AAQM,qCALI,UAAU,kBACV,MAAM,yCAEJ,OAAO,CAAC,MAAM,CAAC,CAa3B;AASM,oCANI,OAAO,cACP,MAAM,GAAG,UAAU,mBACnB,MAAM,kBACN,MAAM,uDAwBhB;4BA9HyB,YAAY;gCACR,YAAY;oCAFR,YAAY;gCAGhB,YAAY;6BACf,YAAY"}
1
+ {"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["archive.js"],"names":[],"mappings":"AA2DO,2CALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC,CAiBzD;AAQM,oCALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC,UAAU,CAAC,CAsC/B;AAQM,oCALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC,UAAU,CAAC,CAuC/B;AAQM,qCALI,UAAU,kBACV,MAAM,yCAEJ,OAAO,CAAC,MAAM,CAAC,CAuC3B;AASM,oCANI,OAAO,cACP,MAAM,GAAG,UAAU,mBACnB,MAAM,kBACN,MAAM,uDA8ChB;4BA5OS,YAAY;gCAAZ,YAAY;oCAAZ,YAAY;gCAAZ,YAAY;6BAAZ,YAAY"}