@endo/compartment-mapper 1.3.1 → 1.5.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 (154) hide show
  1. package/README.md +64 -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-all-parsers.d.ts +2 -0
  13. package/import-archive-all-parsers.d.ts.map +1 -0
  14. package/import-archive-all-parsers.js +1 -0
  15. package/import-archive-lite.d.ts +1 -0
  16. package/import-archive-lite.js +3 -0
  17. package/import-archive-parsers.d.ts +1 -0
  18. package/import-archive-parsers.js +3 -0
  19. package/import-archive.d.ts +1 -0
  20. package/import-archive.js +3 -0
  21. package/import-lite.d.ts +1 -0
  22. package/import-lite.js +3 -0
  23. package/import-parsers.d.ts +1 -0
  24. package/import-parsers.js +3 -0
  25. package/import.d.ts +1 -0
  26. package/import.js +3 -0
  27. package/index.d.ts +1 -0
  28. package/index.js +3 -1
  29. package/node-modules.d.ts +1 -0
  30. package/node-modules.js +3 -0
  31. package/node-powers.d.ts +1 -0
  32. package/node-powers.js +3 -0
  33. package/package.json +16 -15
  34. package/src/archive-lite.d.ts +8 -10
  35. package/src/archive-lite.d.ts.map +1 -1
  36. package/src/archive-lite.js +35 -209
  37. package/src/archive.d.ts.map +1 -1
  38. package/src/archive.js +140 -28
  39. package/src/bundle.d.ts.map +1 -1
  40. package/src/bundle.js +62 -16
  41. package/src/capture-lite.d.ts +2 -2
  42. package/src/capture-lite.d.ts.map +1 -1
  43. package/src/capture-lite.js +27 -201
  44. package/src/compartment-map.d.ts +2 -1
  45. package/src/compartment-map.d.ts.map +1 -1
  46. package/src/compartment-map.js +11 -3
  47. package/src/digest.d.ts +5 -0
  48. package/src/digest.d.ts.map +1 -0
  49. package/src/digest.js +235 -0
  50. package/src/extension.d.ts.map +1 -1
  51. package/src/extension.js +1 -3
  52. package/src/import-archive-all-parsers.d.ts +11 -0
  53. package/src/import-archive-all-parsers.d.ts.map +1 -0
  54. package/src/import-archive-all-parsers.js +29 -0
  55. package/src/import-archive-lite.d.ts +3 -19
  56. package/src/import-archive-lite.d.ts.map +1 -1
  57. package/src/import-archive-lite.js +47 -57
  58. package/src/import-archive-parsers.d.ts.map +1 -1
  59. package/src/import-archive-parsers.js +1 -0
  60. package/src/import-archive.d.ts +2 -2
  61. package/src/import-archive.d.ts.map +1 -1
  62. package/src/import-archive.js +15 -12
  63. package/src/import-hook.d.ts +2 -1
  64. package/src/import-hook.d.ts.map +1 -1
  65. package/src/import-hook.js +87 -76
  66. package/src/import-lite.d.ts.map +1 -1
  67. package/src/import-lite.js +26 -23
  68. package/src/import.d.ts.map +1 -1
  69. package/src/import.js +49 -23
  70. package/src/infer-exports.d.ts.map +1 -1
  71. package/src/infer-exports.js +2 -3
  72. package/src/json.d.ts.map +1 -1
  73. package/src/json.js +1 -2
  74. package/src/link.d.ts.map +1 -1
  75. package/src/link.js +14 -29
  76. package/src/map-parser.d.ts.map +1 -1
  77. package/src/map-parser.js +25 -17
  78. package/src/node-module-specifier.d.ts.map +1 -1
  79. package/src/node-module-specifier.js +2 -3
  80. package/src/node-modules.d.ts +10 -8
  81. package/src/node-modules.d.ts.map +1 -1
  82. package/src/node-modules.js +212 -97
  83. package/src/node-powers.d.ts +8 -8
  84. package/src/node-powers.d.ts.map +1 -1
  85. package/src/node-powers.js +29 -24
  86. package/src/parse-archive-cjs.d.ts +3 -2
  87. package/src/parse-archive-cjs.d.ts.map +1 -1
  88. package/src/parse-archive-cjs.js +5 -4
  89. package/src/parse-archive-mjs.d.ts +3 -2
  90. package/src/parse-archive-mjs.d.ts.map +1 -1
  91. package/src/parse-archive-mjs.js +7 -5
  92. package/src/parse-bytes.d.ts +3 -2
  93. package/src/parse-bytes.d.ts.map +1 -1
  94. package/src/parse-bytes.js +7 -5
  95. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  96. package/src/parse-cjs-shared-export-wrapper.js +7 -6
  97. package/src/parse-cjs.d.ts +3 -2
  98. package/src/parse-cjs.d.ts.map +1 -1
  99. package/src/parse-cjs.js +14 -5
  100. package/src/parse-json.d.ts.map +1 -1
  101. package/src/parse-json.js +6 -6
  102. package/src/parse-mjs.d.ts +3 -2
  103. package/src/parse-mjs.d.ts.map +1 -1
  104. package/src/parse-mjs.js +3 -3
  105. package/src/parse-pre-cjs.d.ts +3 -2
  106. package/src/parse-pre-cjs.d.ts.map +1 -1
  107. package/src/parse-pre-cjs.js +14 -4
  108. package/src/parse-pre-mjs.d.ts +3 -2
  109. package/src/parse-pre-mjs.d.ts.map +1 -1
  110. package/src/parse-pre-mjs.js +4 -3
  111. package/src/parse-text.d.ts +3 -2
  112. package/src/parse-text.d.ts.map +1 -1
  113. package/src/parse-text.js +6 -5
  114. package/src/policy-format.d.ts +1 -1
  115. package/src/policy-format.d.ts.map +1 -1
  116. package/src/policy-format.js +5 -7
  117. package/src/policy.d.ts.map +1 -1
  118. package/src/policy.js +15 -10
  119. package/src/powers.d.ts.map +1 -1
  120. package/src/powers.js +15 -12
  121. package/src/search.d.ts.map +1 -1
  122. package/src/search.js +10 -7
  123. package/src/types/compartment-map-schema.d.ts +98 -0
  124. package/src/types/compartment-map-schema.d.ts.map +1 -0
  125. package/src/types/compartment-map-schema.ts +116 -0
  126. package/src/types/external.d.ts +299 -0
  127. package/src/types/external.d.ts.map +1 -0
  128. package/src/types/external.ts +428 -0
  129. package/src/types/internal.d.ts +162 -0
  130. package/src/types/internal.d.ts.map +1 -0
  131. package/src/types/internal.ts +217 -0
  132. package/src/types/node-powers.d.ts +46 -0
  133. package/src/types/node-powers.d.ts.map +1 -0
  134. package/src/types/node-powers.ts +52 -0
  135. package/src/types/policy-schema.d.ts +81 -0
  136. package/src/types/policy-schema.d.ts.map +1 -0
  137. package/src/types/policy-schema.ts +131 -0
  138. package/src/types/policy.d.ts +20 -0
  139. package/src/types/policy.d.ts.map +1 -0
  140. package/src/types/policy.ts +42 -0
  141. package/src/types/powers.d.ts +83 -0
  142. package/src/types/powers.d.ts.map +1 -0
  143. package/src/types/powers.ts +120 -0
  144. package/src/types/typescript.d.ts +28 -0
  145. package/src/types/typescript.d.ts.map +1 -0
  146. package/src/types/typescript.ts +41 -0
  147. package/src/types-external.d.ts +14 -0
  148. package/src/types-external.js +2 -0
  149. package/src/types.d.ts +9 -787
  150. package/src/url.d.ts.map +1 -1
  151. package/src/url.js +2 -3
  152. package/src/types.d.ts.map +0 -1
  153. package/src/types.js +0 -995
  154. package/types.d.ts +0 -19
package/src/bundle.js CHANGED
@@ -1,17 +1,21 @@
1
- // @ts-check
2
1
  /* eslint no-shadow: 0 */
3
2
 
4
- /** @import {StaticModuleType} from 'ses' */
5
-
6
- /** @import {ArchiveOptions} from './types.js' */
7
- /** @import {CompartmentDescriptor} from './types.js' */
8
- /** @import {CompartmentSources} from './types.js' */
9
- /** @import {MaybeReadPowers} from './types.js' */
10
- /** @import {PrecompiledStaticModuleInterface} from 'ses' */
11
- /** @import {ReadFn} from './types.js' */
12
- /** @import {ReadPowers} from './types.js' */
13
- /** @import {Sources} from './types.js' */
14
- /** @import {WriteFn} from './types.js' */
3
+ /**
4
+ * @import {
5
+ * StaticModuleType,
6
+ * PrecompiledStaticModuleInterface
7
+ * } from 'ses'
8
+ * @import {
9
+ * ArchiveOptions,
10
+ * CompartmentDescriptor,
11
+ * CompartmentSources,
12
+ * MaybeReadPowers,
13
+ * ReadFn,
14
+ * ReadPowers,
15
+ * Sources,
16
+ * WriteFn,
17
+ * } from './types.js'
18
+ */
15
19
 
16
20
  /**
17
21
  * @typedef {object} BundlerKit
@@ -113,8 +117,14 @@ const sortedModules = (
113
117
  const source = compartmentSources[compartmentName][moduleSpecifier];
114
118
  if (source !== undefined) {
115
119
  const { record, parser, deferredError, bytes } = source;
116
- assert(parser !== undefined);
117
- assert(bytes !== undefined);
120
+ assert(
121
+ bytes !== undefined,
122
+ `No bytes for ${moduleSpecifier} in ${compartmentName}`,
123
+ );
124
+ assert(
125
+ parser !== undefined,
126
+ `No parser for ${moduleSpecifier} in ${compartmentName}`,
127
+ );
118
128
  if (deferredError) {
119
129
  throw Error(
120
130
  `Cannot bundle: encountered deferredError ${deferredError}`,
@@ -231,6 +241,13 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
231
241
  sourceMapHook = undefined,
232
242
  parserForLanguage: parserForLanguageOption = {},
233
243
  languageForExtension: languageForExtensionOption = {},
244
+ commonjsLanguageForExtension: commonjsLanguageForExtensionOption = {},
245
+ moduleLanguageForExtension: moduleLanguageForExtensionOption = {},
246
+ workspaceLanguageForExtension: workspaceLanguageForExtensionOption = {},
247
+ workspaceCommonjsLanguageForExtension:
248
+ workspaceCommonjsLanguageForExtensionOption = {},
249
+ workspaceModuleLanguageForExtension:
250
+ workspaceModuleLanguageForExtensionOption = {},
234
251
  } = options || {};
235
252
  const conditions = new Set(conditionsOption);
236
253
 
@@ -244,6 +261,27 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
244
261
  const languageForExtension = Object.freeze(
245
262
  Object.assign(Object.create(null), languageForExtensionOption),
246
263
  );
264
+ const commonjsLanguageForExtension = Object.freeze(
265
+ Object.assign(Object.create(null), commonjsLanguageForExtensionOption),
266
+ );
267
+ const moduleLanguageForExtension = Object.freeze(
268
+ Object.assign(Object.create(null), moduleLanguageForExtensionOption),
269
+ );
270
+ const workspaceLanguageForExtension = Object.freeze(
271
+ Object.assign(Object.create(null), workspaceLanguageForExtensionOption),
272
+ );
273
+ const workspaceCommonjsLanguageForExtension = Object.freeze(
274
+ Object.assign(
275
+ Object.create(null),
276
+ workspaceCommonjsLanguageForExtensionOption,
277
+ ),
278
+ );
279
+ const workspaceModuleLanguageForExtension = Object.freeze(
280
+ Object.assign(
281
+ Object.create(null),
282
+ workspaceModuleLanguageForExtensionOption,
283
+ ),
284
+ );
247
285
 
248
286
  const {
249
287
  packageLocation,
@@ -262,7 +300,16 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
262
300
  conditions,
263
301
  packageDescriptor,
264
302
  moduleSpecifier,
265
- { dev, commonDependencies },
303
+ {
304
+ dev,
305
+ commonDependencies,
306
+ languageForExtension,
307
+ commonjsLanguageForExtension,
308
+ moduleLanguageForExtension,
309
+ workspaceLanguageForExtension,
310
+ workspaceCommonjsLanguageForExtension,
311
+ workspaceModuleLanguageForExtension,
312
+ },
266
313
  );
267
314
 
268
315
  const {
@@ -287,7 +334,6 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
287
334
  makeImportHook,
288
335
  moduleTransforms,
289
336
  parserForLanguage,
290
- languageForExtension,
291
337
  });
292
338
  await compartment.load(entryModuleSpecifier);
293
339
 
@@ -1,7 +1,7 @@
1
- export function captureFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: CaptureOptions | undefined): Promise<CaptureResult>;
1
+ export function captureFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: CaptureLiteOptions | undefined): Promise<CaptureResult>;
2
2
  import type { ReadFn } from './types.js';
3
3
  import type { ReadPowers } from './types.js';
4
4
  import type { CompartmentMapDescriptor } from './types.js';
5
- import type { CaptureOptions } from './types.js';
5
+ import type { CaptureLiteOptions } from './types.js';
6
6
  import type { CaptureResult } from './types.js';
7
7
  //# sourceMappingURL=capture-lite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"capture-lite.d.ts","sourceRoot":"","sources":["capture-lite.js"],"names":[],"mappings":"AAkQO,uCALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,yCAEtB,OAAO,CAAC,aAAa,CAAC,CAmElC;4BAlSyB,YAAY;gCACR,YAAY;8CACE,YAAY;oCACtB,YAAY;mCAIb,YAAY"}
1
+ {"version":3,"file":"capture-lite.d.ts","sourceRoot":"","sources":["capture-lite.js"],"names":[],"mappings":"AAoFO,uCALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,aAAa,CAAC,CAmElC;4BA9GS,YAAY;gCAAZ,YAAY;8CAAZ,YAAY;wCAAZ,YAAY;mCAAZ,YAAY"}
@@ -1,4 +1,5 @@
1
1
  /**
2
+ * @module
2
3
  * This module provides {@link captureFromMap}, which only "captures" the
3
4
  * compartment map descriptors and sources from a partially completed
4
5
  * compartment map--_without_ creating an archive. The resulting compartment map
@@ -24,27 +25,21 @@
24
25
  * contain original sources, so to import the archive with
25
26
  * `src/import-archive-lite.js`, you will need to provide the archive parsers
26
27
  * and entrain a runtime dependency on Babel.
27
- *
28
- * @module
29
28
  */
30
29
 
31
- // @ts-check
32
30
  /* eslint no-shadow: 0 */
33
31
 
34
- /** @import {ReadFn} from './types.js' */
35
- /** @import {ReadPowers} from './types.js' */
36
- /** @import {CompartmentMapDescriptor} from './types.js' */
37
- /** @import {CaptureOptions} from './types.js' */
38
- /** @import {Sources} from './types.js' */
39
- /** @import {CompartmentDescriptor} from './types.js' */
40
- /** @import {ModuleDescriptor} from './types.js' */
41
- /** @import {CaptureResult} from './types.js' */
32
+ /**
33
+ * @import {
34
+ * CaptureLiteOptions,
35
+ * CaptureResult,
36
+ * CompartmentMapDescriptor,
37
+ * ReadFn,
38
+ * ReadPowers,
39
+ * Sources,
40
+ * } from './types.js'
41
+ */
42
42
 
43
- import {
44
- assertCompartmentMap,
45
- pathCompare,
46
- stringCompare,
47
- } from './compartment-map.js';
48
43
  import {
49
44
  exitModuleImportHookMaker,
50
45
  makeImportHookMaker,
@@ -53,158 +48,11 @@ import { link } from './link.js';
53
48
  import { resolve } from './node-module-specifier.js';
54
49
  import { detectAttenuators } from './policy.js';
55
50
  import { unpackReadPowers } from './powers.js';
51
+ import { digestCompartmentMap } from './digest.js';
56
52
 
57
- const { freeze, assign, create, fromEntries, entries, keys } = Object;
58
-
59
- /**
60
- * We attempt to produce compartment maps that are consistent regardless of
61
- * whether the packages were originally laid out on disk for development or
62
- * production, and other trivia like the fully qualified path of a specific
63
- * installation.
64
- *
65
- * Naming compartments for the self-ascribed name and version of each Node.js
66
- * package is insufficient because they are not guaranteed to be unique.
67
- * Dependencies do not necessarilly come from the npm registry and may be
68
- * for example derived from fully qualified URL's or Github org and project
69
- * names.
70
- * Package managers are also not required to fully deduplicate the hard
71
- * copy of each package even when they are identical resources.
72
- * Duplication is undesirable, but we elect to defer that problem to solutions
73
- * in the package managers, as the alternative would be to consistently hash
74
- * the original sources of the packages themselves, which may not even be
75
- * available much less pristine for us.
76
- *
77
- * So, instead, we use the lexically least path of dependency names, delimited
78
- * by hashes.
79
- * The compartment maps generated by the ./node-modules.js tooling pre-compute
80
- * these traces for our use here.
81
- * We sort the compartments lexically on their self-ascribed name and version,
82
- * and use the lexically least dependency name path as a tie-breaker.
83
- * The dependency path is logical and orthogonal to the package manager's
84
- * actual installation location, so should be orthogonal to the vagaries of the
85
- * package manager's deduplication algorithm.
86
- *
87
- * @param {Record<string, CompartmentDescriptor>} compartments
88
- * @returns {Record<string, string>} map from old to new compartment names.
89
- */
90
- const renameCompartments = compartments => {
91
- /** @type {Record<string, string>} */
92
- const compartmentRenames = create(null);
93
- let index = 0;
94
- let prev = '';
95
-
96
- // The sort below combines two comparators to avoid depending on sort
97
- // stability, which became standard as recently as 2019.
98
- // If that date seems quaint, please accept my regards from the distant past.
99
- // We are very proud of you.
100
- const compartmentsByPath = Object.entries(compartments)
101
- .map(([name, compartment]) => ({
102
- name,
103
- path: compartment.path,
104
- label: compartment.label,
105
- }))
106
- .sort((a, b) => {
107
- if (a.label === b.label) {
108
- assert(a.path !== undefined && b.path !== undefined);
109
- return pathCompare(a.path, b.path);
110
- }
111
- return stringCompare(a.label, b.label);
112
- });
113
-
114
- for (const { name, label } of compartmentsByPath) {
115
- if (label === prev) {
116
- compartmentRenames[name] = `${label}-n${index}`;
117
- index += 1;
118
- } else {
119
- compartmentRenames[name] = label;
120
- prev = label;
121
- index = 1;
122
- }
123
- }
124
- return compartmentRenames;
125
- };
126
-
127
- /**
128
- * @param {Record<string, CompartmentDescriptor>} compartments
129
- * @param {Sources} sources
130
- * @param {Record<string, string>} compartmentRenames
131
- */
132
- const translateCompartmentMap = (compartments, sources, compartmentRenames) => {
133
- const result = create(null);
134
- for (const compartmentName of keys(compartmentRenames)) {
135
- const compartment = compartments[compartmentName];
136
- const { name, label, retained, policy } = compartment;
137
- if (retained) {
138
- // rename module compartments
139
- /** @type {Record<string, ModuleDescriptor>} */
140
- const modules = create(null);
141
- const compartmentModules = compartment.modules;
142
- if (compartment.modules) {
143
- for (const name of keys(compartmentModules).sort()) {
144
- const module = compartmentModules[name];
145
- if (module.compartment !== undefined) {
146
- modules[name] = {
147
- ...module,
148
- compartment: compartmentRenames[module.compartment],
149
- };
150
- } else {
151
- modules[name] = module;
152
- }
153
- }
154
- }
155
-
156
- // integrate sources into modules
157
- const compartmentSources = sources[compartmentName];
158
- if (compartmentSources) {
159
- for (const name of keys(compartmentSources).sort()) {
160
- const source = compartmentSources[name];
161
- const { location, parser, exit, sha512, deferredError } = source;
162
- if (location !== undefined) {
163
- modules[name] = {
164
- location,
165
- parser,
166
- sha512,
167
- };
168
- } else if (exit !== undefined) {
169
- modules[name] = {
170
- exit,
171
- };
172
- } else if (deferredError !== undefined) {
173
- modules[name] = {
174
- deferredError,
175
- };
176
- }
177
- }
178
- }
53
+ const { freeze, assign, create } = Object;
179
54
 
180
- result[compartmentRenames[compartmentName]] = {
181
- name,
182
- label,
183
- location: compartmentRenames[compartmentName],
184
- modules,
185
- policy,
186
- // `scopes`, `types`, and `parsers` are not necessary since every
187
- // loadable module is captured in `modules`.
188
- };
189
- }
190
- }
191
-
192
- return result;
193
- };
194
-
195
- /**
196
- * @param {Sources} sources
197
- * @param {Record<string, string>} compartmentRenames
198
- * @returns {Sources}
199
- */
200
- const renameSources = (sources, compartmentRenames) => {
201
- return fromEntries(
202
- entries(sources).map(([name, compartmentSources]) => [
203
- compartmentRenames[name],
204
- compartmentSources,
205
- ]),
206
- );
207
- };
55
+ const defaultCompartment = Compartment;
208
56
 
209
57
  /**
210
58
  * @param {CompartmentMapDescriptor} compartmentMap
@@ -213,67 +61,43 @@ const renameSources = (sources, compartmentRenames) => {
213
61
  */
214
62
  const captureCompartmentMap = (compartmentMap, sources) => {
215
63
  const {
216
- compartments,
217
- entry: { compartment: entryCompartmentName, module: entryModuleSpecifier },
218
- } = compartmentMap;
219
-
220
- const compartmentRenames = renameCompartments(compartments);
221
- const captureCompartments = translateCompartmentMap(
222
- compartments,
223
- sources,
64
+ compartmentMap: captureCompartmentMap,
65
+ sources: captureSources,
66
+ newToOldCompartmentNames,
224
67
  compartmentRenames,
225
- );
226
- const captureEntryCompartmentName = compartmentRenames[entryCompartmentName];
227
- const captureSources = renameSources(sources, compartmentRenames);
228
-
229
- const captureCompartmentMap = {
230
- // TODO graceful migration from tags to conditions
231
- // https://github.com/endojs/endo/issues/2388
232
- tags: [],
233
- entry: {
234
- compartment: captureEntryCompartmentName,
235
- module: entryModuleSpecifier,
236
- },
237
- compartments: captureCompartments,
238
- };
239
-
240
- // Cross-check:
241
- // We assert that we have constructed a valid compartment map, not because it
242
- // might not be, but to ensure that the assertCompartmentMap function can
243
- // accept all valid compartment maps.
244
- assertCompartmentMap(captureCompartmentMap);
245
-
68
+ oldToNewCompartmentNames,
69
+ } = digestCompartmentMap(compartmentMap, sources);
246
70
  return {
247
71
  captureCompartmentMap,
248
72
  captureSources,
249
73
  compartmentRenames,
74
+ newToOldCompartmentNames,
75
+ oldToNewCompartmentNames,
250
76
  };
251
77
  };
252
78
 
253
79
  /**
254
80
  * @param {ReadFn | ReadPowers} powers
255
81
  * @param {CompartmentMapDescriptor} compartmentMap
256
- * @param {CaptureOptions} [options]
82
+ * @param {CaptureLiteOptions} [options]
257
83
  * @returns {Promise<CaptureResult>}
258
84
  */
259
85
  export const captureFromMap = async (powers, compartmentMap, options = {}) => {
260
86
  const {
261
87
  moduleTransforms,
88
+ syncModuleTransforms,
262
89
  modules: exitModules = {},
263
90
  searchSuffixes = undefined,
264
91
  importHook: exitModuleImportHook = undefined,
265
92
  policy = undefined,
266
93
  sourceMapHook = undefined,
267
94
  parserForLanguage: parserForLanguageOption = {},
268
- languageForExtension: languageForExtensionOption = {},
95
+ Compartment = defaultCompartment,
269
96
  } = options;
270
97
 
271
98
  const parserForLanguage = freeze(
272
99
  assign(create(null), parserForLanguageOption),
273
100
  );
274
- const languageForExtension = freeze(
275
- assign(create(null), languageForExtensionOption),
276
- );
277
101
 
278
102
  const { read, computeSha512 } = unpackReadPowers(powers);
279
103
 
@@ -288,6 +112,7 @@ export const captureFromMap = async (powers, compartmentMap, options = {}) => {
288
112
  const consolidatedExitModuleImportHook = exitModuleImportHookMaker({
289
113
  modules: exitModules,
290
114
  exitModuleImportHook,
115
+ entryCompartmentName,
291
116
  });
292
117
 
293
118
  const makeImportHook = makeImportHookMaker(read, entryCompartmentName, {
@@ -306,9 +131,10 @@ export const captureFromMap = async (powers, compartmentMap, options = {}) => {
306
131
  resolve,
307
132
  makeImportHook,
308
133
  moduleTransforms,
134
+ syncModuleTransforms,
309
135
  parserForLanguage,
310
- languageForExtension,
311
136
  archiveOnly: true,
137
+ Compartment,
312
138
  });
313
139
  await compartment.load(entryModuleSpecifier);
314
140
  if (policy) {
@@ -1,5 +1,6 @@
1
1
  /** @type {(a: string, b: string) => number} */
2
2
  export const stringCompare: (a: string, b: string) => number;
3
3
  export function pathCompare(a: Array<string> | undefined, b: Array<string> | undefined): number;
4
- export function assertCompartmentMap(allegedCompartmentMap: unknown, url?: string | undefined): asserts allegedCompartmentMap is import("./types.js").CompartmentMapDescriptor;
4
+ export function assertCompartmentMap(allegedCompartmentMap: unknown, url?: string | undefined): asserts allegedCompartmentMap is CompartmentMapDescriptor;
5
+ import type { CompartmentMapDescriptor } from './types.js';
5
6
  //# sourceMappingURL=compartment-map.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compartment-map.d.ts","sourceRoot":"","sources":["compartment-map.js"],"names":[],"mappings":"AAWA,+CAA+C;AAE/C,4BAFW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAE2B;AAc/D,+BAHI,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,KACzB,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,UAqCnC;AAuZM,4DALI,OAAO,6BAEL,QAAQ,qBAAqB,IAAI,OAAO,YAAY,EAAE,wBAAwB,CA+B1F"}
1
+ {"version":3,"file":"compartment-map.d.ts","sourceRoot":"","sources":["compartment-map.js"],"names":[],"mappings":"AAYA,+CAA+C;AAE/C,4BAFW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAE2B;AAc/D,+BAHI,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,KACzB,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,UAqCnC;AA8ZM,4DALI,OAAO,6BAEL,QAAQ,qBAAqB,IAAI,wBAAwB,CA+BrE;8CArf2C,YAAY"}
@@ -1,8 +1,9 @@
1
1
  /* Validates a compartment map against its schema. */
2
2
 
3
- // @ts-check
4
3
  import { assertPackagePolicy } from './policy-format.js';
5
4
 
5
+ /** @import {CompartmentMapDescriptor} from './types.js' */
6
+
6
7
  // TODO convert to the new `||` assert style.
7
8
  // Deferred because this file pervasively uses simple template strings rather than
8
9
  // template strings tagged with `assert.details` (aka `X`), and uses
@@ -107,7 +108,7 @@ const assertConditions = (conditions, url) => {
107
108
  * @param {string} url
108
109
  */
109
110
  const assertCompartmentModule = (allegedModule, path, url) => {
110
- const { compartment, module, ...extra } = allegedModule;
111
+ const { compartment, module, retained, ...extra } = allegedModule;
111
112
  assertEmptyObject(
112
113
  extra,
113
114
  `${path} must not have extra properties, got ${q({
@@ -125,6 +126,13 @@ const assertCompartmentModule = (allegedModule, path, url) => {
125
126
  'string',
126
127
  `${path}.module must be a string, got ${q(module)} in ${q(url)}`,
127
128
  );
129
+ if (retained !== undefined) {
130
+ assert.typeof(
131
+ retained,
132
+ 'boolean',
133
+ `${path}.retained must be a boolean, got ${q(retained)} in ${q(url)}`,
134
+ );
135
+ }
128
136
  };
129
137
 
130
138
  /**
@@ -464,7 +472,7 @@ const assertEntry = (allegedEntry, url) => {
464
472
  /**
465
473
  * @param {unknown} allegedCompartmentMap
466
474
  * @param {string} [url]
467
- * @returns {asserts allegedCompartmentMap is import('./types.js').CompartmentMapDescriptor}
475
+ * @returns {asserts allegedCompartmentMap is CompartmentMapDescriptor}
468
476
  */
469
477
 
470
478
  export const assertCompartmentMap = (
@@ -0,0 +1,5 @@
1
+ export function digestCompartmentMap(compartmentMap: CompartmentMapDescriptor, sources: Sources): DigestResult;
2
+ import type { CompartmentMapDescriptor } from './types.js';
3
+ import type { Sources } from './types.js';
4
+ import type { DigestResult } from './types.js';
5
+ //# sourceMappingURL=digest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["digest.js"],"names":[],"mappings":"AAwLO,qDAJI,wBAAwB,WACxB,OAAO,GACL,YAAY,CAoDxB;8CA3NS,YAAY;6BAAZ,YAAY;kCAAZ,YAAY"}