@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
@@ -28,20 +28,22 @@
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
+ * ArchiveResult,
37
+ * ArchiveWriter,
38
+ * CaptureSourceLocationHook,
39
+ * CompartmentMapDescriptor,
40
+ * HashPowers,
41
+ * ReadFn,
42
+ * ReadPowers,
43
+ * Sources,
44
+ * WriteFn,
45
+ * } from './types.js'
46
+ */
45
47
 
46
48
  import { writeZip } from '@endo/zip';
47
49
  import { resolve } from './node-module-specifier.js';
@@ -51,12 +53,8 @@ import {
51
53
  makeImportHookMaker,
52
54
  } from './import-hook.js';
53
55
  import { unpackReadPowers } from './powers.js';
54
- import {
55
- assertCompartmentMap,
56
- stringCompare,
57
- pathCompare,
58
- } from './compartment-map.js';
59
56
  import { detectAttenuators } from './policy.js';
57
+ import { digestCompartmentMap } from './digest.js';
60
58
 
61
59
  const textEncoder = new TextEncoder();
62
60
 
@@ -69,157 +67,7 @@ const { assign, create, freeze } = Object;
69
67
  */
70
68
  const resolveLocation = (rel, abs) => new URL(rel, abs).toString();
71
69
 
72
- const { keys, entries, fromEntries } = Object;
73
-
74
- /**
75
- * We attempt to produce compartment maps that are consistent regardless of
76
- * whether the packages were originally laid out on disk for development or
77
- * production, and other trivia like the fully qualified path of a specific
78
- * installation.
79
- *
80
- * Naming compartments for the self-ascribed name and version of each Node.js
81
- * package is insufficient because they are not guaranteed to be unique.
82
- * Dependencies do not necessarilly come from the npm registry and may be
83
- * for example derived from fully qualified URL's or Github org and project
84
- * names.
85
- * Package managers are also not required to fully deduplicate the hard
86
- * copy of each package even when they are identical resources.
87
- * Duplication is undesirable, but we elect to defer that problem to solutions
88
- * in the package managers, as the alternative would be to consistently hash
89
- * the original sources of the packages themselves, which may not even be
90
- * available much less pristine for us.
91
- *
92
- * So, instead, we use the lexically least path of dependency names, delimited
93
- * by hashes.
94
- * The compartment maps generated by the ./node-modules.js tooling pre-compute
95
- * these traces for our use here.
96
- * We sort the compartments lexically on their self-ascribed name and version,
97
- * and use the lexically least dependency name path as a tie-breaker.
98
- * The dependency path is logical and orthogonal to the package manager's
99
- * actual installation location, so should be orthogonal to the vagaries of the
100
- * package manager's deduplication algorithm.
101
- *
102
- * @param {Record<string, CompartmentDescriptor>} compartments
103
- * @returns {Record<string, string>} map from old to new compartment names.
104
- */
105
- const renameCompartments = compartments => {
106
- /** @type {Record<string, string>} */
107
- const compartmentRenames = create(null);
108
- let index = 0;
109
- let prev = '';
110
-
111
- // The sort below combines two comparators to avoid depending on sort
112
- // stability, which became standard as recently as 2019.
113
- // If that date seems quaint, please accept my regards from the distant past.
114
- // We are very proud of you.
115
- const compartmentsByPath = Object.entries(compartments)
116
- .map(([name, compartment]) => ({
117
- name,
118
- path: compartment.path,
119
- label: compartment.label,
120
- }))
121
- .sort((a, b) => {
122
- if (a.label === b.label) {
123
- assert(a.path !== undefined && b.path !== undefined);
124
- return pathCompare(a.path, b.path);
125
- }
126
- return stringCompare(a.label, b.label);
127
- });
128
-
129
- for (const { name, label } of compartmentsByPath) {
130
- if (label === prev) {
131
- compartmentRenames[name] = `${label}-n${index}`;
132
- index += 1;
133
- } else {
134
- compartmentRenames[name] = label;
135
- prev = label;
136
- index = 1;
137
- }
138
- }
139
- return compartmentRenames;
140
- };
141
-
142
- /**
143
- * @param {Record<string, CompartmentDescriptor>} compartments
144
- * @param {Sources} sources
145
- * @param {Record<string, string>} compartmentRenames
146
- */
147
- const translateCompartmentMap = (compartments, sources, compartmentRenames) => {
148
- const result = create(null);
149
- for (const compartmentName of keys(compartmentRenames)) {
150
- const compartment = compartments[compartmentName];
151
- const { name, label, retained, policy } = compartment;
152
- if (retained) {
153
- // rename module compartments
154
- /** @type {Record<string, ModuleDescriptor>} */
155
- const modules = create(null);
156
- const compartmentModules = compartment.modules;
157
- if (compartment.modules) {
158
- 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;
167
- }
168
- }
169
- }
170
-
171
- // integrate sources into modules
172
- const compartmentSources = sources[compartmentName];
173
- if (compartmentSources) {
174
- for (const name of keys(compartmentSources).sort()) {
175
- const source = compartmentSources[name];
176
- const { location, parser, exit, sha512, deferredError } = source;
177
- if (location !== undefined) {
178
- modules[name] = {
179
- location,
180
- parser,
181
- sha512,
182
- };
183
- } else if (exit !== undefined) {
184
- modules[name] = {
185
- exit,
186
- };
187
- } else if (deferredError !== undefined) {
188
- modules[name] = {
189
- deferredError,
190
- };
191
- }
192
- }
193
- }
194
-
195
- result[compartmentRenames[compartmentName]] = {
196
- name,
197
- label,
198
- location: compartmentRenames[compartmentName],
199
- modules,
200
- policy,
201
- // `scopes`, `types`, and `parsers` are not necessary since every
202
- // loadable module is captured in `modules`.
203
- };
204
- }
205
- }
206
-
207
- return result;
208
- };
209
-
210
- /**
211
- * @param {Sources} sources
212
- * @param {Record<string, string>} compartmentRenames
213
- * @returns {Sources}
214
- */
215
- const renameSources = (sources, compartmentRenames) => {
216
- return fromEntries(
217
- entries(sources).map(([name, compartmentSources]) => [
218
- compartmentRenames[name],
219
- compartmentSources,
220
- ]),
221
- );
222
- };
70
+ const { keys } = Object;
223
71
 
224
72
  /**
225
73
  * @param {ArchiveWriter} archive
@@ -263,47 +111,29 @@ const captureSourceLocations = async (sources, captureSourceLocation) => {
263
111
  /**
264
112
  * @param {CompartmentMapDescriptor} compartmentMap
265
113
  * @param {Sources} sources
266
- * @returns {{archiveCompartmentMap: CompartmentMapDescriptor, archiveSources: Sources}}
114
+ * @returns {ArchiveResult}
267
115
  */
268
116
  export const makeArchiveCompartmentMap = (compartmentMap, sources) => {
269
117
  const {
270
- compartments,
271
- entry: { compartment: entryCompartmentName, module: entryModuleSpecifier },
272
- } = compartmentMap;
273
-
274
- const compartmentRenames = renameCompartments(compartments);
275
- const archiveCompartments = translateCompartmentMap(
276
- compartments,
277
- sources,
118
+ compartmentMap: archiveCompartmentMap,
119
+ sources: archiveSources,
120
+ oldToNewCompartmentNames,
121
+ newToOldCompartmentNames,
122
+ compartmentRenames,
123
+ } = digestCompartmentMap(compartmentMap, sources);
124
+ return {
125
+ archiveCompartmentMap,
126
+ archiveSources,
127
+ oldToNewCompartmentNames,
128
+ newToOldCompartmentNames,
278
129
  compartmentRenames,
279
- );
280
- const archiveEntryCompartmentName = compartmentRenames[entryCompartmentName];
281
- const archiveSources = renameSources(sources, compartmentRenames);
282
-
283
- const archiveCompartmentMap = {
284
- // TODO migrate tags to conditions
285
- // https://github.com/endojs/endo/issues/2388
286
- tags: [],
287
- entry: {
288
- compartment: archiveEntryCompartmentName,
289
- module: entryModuleSpecifier,
290
- },
291
- compartments: archiveCompartments,
292
130
  };
293
-
294
- // Cross-check:
295
- // We assert that we have constructed a valid compartment map, not because it
296
- // might not be, but to ensure that the assertCompartmentMap function can
297
- // accept all valid compartment maps.
298
- assertCompartmentMap(archiveCompartmentMap);
299
-
300
- return { archiveCompartmentMap, archiveSources };
301
131
  };
302
132
 
303
133
  /**
304
134
  * @param {ReadFn | ReadPowers} powers
305
135
  * @param {CompartmentMapDescriptor} compartmentMap
306
- * @param {ArchiveOptions} [options]
136
+ * @param {ArchiveLiteOptions} [options]
307
137
  * @returns {Promise<{sources: Sources, compartmentMapBytes: Uint8Array, sha512?: string}>}
308
138
  */
309
139
  const digestFromMap = async (powers, compartmentMap, options = {}) => {
@@ -316,15 +146,11 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
316
146
  policy = undefined,
317
147
  sourceMapHook = undefined,
318
148
  parserForLanguage: parserForLanguageOption = {},
319
- languageForExtension: languageForExtensionOption = {},
320
149
  } = options;
321
150
 
322
151
  const parserForLanguage = freeze(
323
152
  assign(create(null), parserForLanguageOption),
324
153
  );
325
- const languageForExtension = freeze(
326
- assign(create(null), languageForExtensionOption),
327
- );
328
154
 
329
155
  const { read, computeSha512 } = unpackReadPowers(powers);
330
156
 
@@ -339,6 +165,7 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
339
165
  const consolidatedExitModuleImportHook = exitModuleImportHookMaker({
340
166
  modules: exitModules,
341
167
  exitModuleImportHook,
168
+ entryCompartmentName,
342
169
  });
343
170
 
344
171
  const makeImportHook = makeImportHookMaker(read, entryCompartmentName, {
@@ -358,7 +185,6 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
358
185
  makeImportHook,
359
186
  moduleTransforms,
360
187
  parserForLanguage,
361
- languageForExtension,
362
188
  archiveOnly: true,
363
189
  });
364
190
  await compartment.load(entryModuleSpecifier);
@@ -404,7 +230,7 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
404
230
  /**
405
231
  * @param {ReadFn | ReadPowers} powers
406
232
  * @param {CompartmentMapDescriptor} compartmentMap
407
- * @param {ArchiveOptions} [options]
233
+ * @param {ArchiveLiteOptions} [options]
408
234
  * @returns {Promise<{bytes: Uint8Array, sha512?: string}>}
409
235
  */
410
236
  export const makeAndHashArchiveFromMap = async (
@@ -429,7 +255,7 @@ export const makeAndHashArchiveFromMap = async (
429
255
  /**
430
256
  * @param {ReadFn | ReadPowers} powers
431
257
  * @param {CompartmentMapDescriptor} compartmentMap
432
- * @param {ArchiveOptions} [options]
258
+ * @param {ArchiveLiteOptions} [options]
433
259
  * @returns {Promise<Uint8Array>}
434
260
  */
435
261
  export const makeArchiveFromMap = async (powers, compartmentMap, options) => {
@@ -444,7 +270,7 @@ export const makeArchiveFromMap = async (powers, compartmentMap, options) => {
444
270
  /**
445
271
  * @param {ReadFn | ReadPowers} powers
446
272
  * @param {CompartmentMapDescriptor} compartmentMap
447
- * @param {ArchiveOptions} [options]
273
+ * @param {ArchiveLiteOptions} [options]
448
274
  * @returns {Promise<Uint8Array>}
449
275
  */
450
276
  export const mapFromMap = async (powers, compartmentMap, options) => {
@@ -459,7 +285,7 @@ export const mapFromMap = async (powers, compartmentMap, options) => {
459
285
  /**
460
286
  * @param {HashPowers} powers
461
287
  * @param {CompartmentMapDescriptor} compartmentMap
462
- * @param {ArchiveOptions} [options]
288
+ * @param {ArchiveLiteOptions} [options]
463
289
  * @returns {Promise<string>}
464
290
  */
465
291
  export const hashFromMap = async (powers, compartmentMap, options) => {
@@ -477,7 +303,7 @@ export const hashFromMap = async (powers, compartmentMap, options) => {
477
303
  * @param {ReadFn | ReadPowers} readPowers
478
304
  * @param {string} archiveLocation
479
305
  * @param {CompartmentMapDescriptor} compartmentMap
480
- * @param {ArchiveOptions} [options]
306
+ * @param {ArchiveLiteOptions} [options]
481
307
  */
482
308
  export const writeArchiveFromMap = async (
483
309
  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,CAwC/B;AAQM,oCALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC,UAAU,CAAC,CAyC/B;AAQM,qCALI,UAAU,kBACV,MAAM,yCAEJ,OAAO,CAAC,MAAM,CAAC,CAyC3B;AASM,oCANI,OAAO,cACP,MAAM,GAAG,UAAU,mBACnB,MAAM,kBACN,MAAM,uDAgDhB;4BApPS,YAAY;gCAAZ,YAAY;oCAAZ,YAAY;gCAAZ,YAAY;6BAAZ,YAAY"}
package/src/archive.js CHANGED
@@ -1,4 +1,5 @@
1
- /* Provides mechanisms for creating archives (zip files with a
1
+ /**
2
+ * @module Provides mechanisms for creating archives (zip files with a
2
3
  * `compartmeent-map.json` and a file for every static dependency of an entry
3
4
  * module).
4
5
  *
@@ -13,7 +14,16 @@
13
14
  * for cases like XS native Compartments where pre-compilation is not
14
15
  * necessary or where the dependency on Babel can be dererred to runtime.
15
16
  */
16
- // @ts-check
17
+
18
+ /**
19
+ * @import {
20
+ * ArchiveOptions,
21
+ * ReadFn,
22
+ * ReadPowers,
23
+ * HashPowers,
24
+ * WriteFn,
25
+ * } from './types.js'
26
+ */
17
27
 
18
28
  import { defaultParserForLanguage } from './archive-parsers.js';
19
29
  import { mapNodeModules } from './node-modules.js';
@@ -27,12 +37,6 @@ import {
27
37
 
28
38
  const { assign, create, freeze } = Object;
29
39
 
30
- /** @import {ArchiveOptions} from './types.js' */
31
- /** @import {ReadFn} from './types.js' */
32
- /** @import {ReadPowers} from './types.js' */
33
- /** @import {HashPowers} from './types.js' */
34
- /** @import {WriteFn} from './types.js' */
35
-
36
40
  /**
37
41
  * Add the default parserForLanguage option.
38
42
  * @param {ArchiveOptions} [options]
@@ -43,7 +47,8 @@ const assignParserForLanguage = (options = {}) => {
43
47
  const parserForLanguage = freeze(
44
48
  assign(create(null), defaultParserForLanguage, parserForLanguageOption),
45
49
  );
46
- return { ...rest, parserForLanguage };
50
+ const languages = Object.keys(parserForLanguage);
51
+ return { ...rest, parserForLanguage, languages };
47
52
  };
48
53
 
49
54
  /**
@@ -57,12 +62,16 @@ export const makeAndHashArchive = async (
57
62
  moduleLocation,
58
63
  options = {},
59
64
  ) => {
60
- const compartmentMap = await mapNodeModules(powers, moduleLocation, options);
61
- return makeAndHashArchiveFromMap(
62
- powers,
63
- compartmentMap,
64
- assignParserForLanguage(options),
65
- );
65
+ const { parserForLanguage, languages, ...otherOptions } =
66
+ assignParserForLanguage(options);
67
+ const compartmentMap = await mapNodeModules(powers, moduleLocation, {
68
+ languages,
69
+ ...otherOptions,
70
+ });
71
+ return makeAndHashArchiveFromMap(powers, compartmentMap, {
72
+ parserForLanguage,
73
+ ...otherOptions,
74
+ });
66
75
  };
67
76
 
68
77
  /**
@@ -72,20 +81,43 @@ export const makeAndHashArchive = async (
72
81
  * @returns {Promise<Uint8Array>}
73
82
  */
74
83
  export const makeArchive = async (powers, moduleLocation, options = {}) => {
75
- const { dev, tags, conditions = tags, commonDependencies, policy } = options;
76
-
84
+ const {
85
+ dev,
86
+ tags,
87
+ conditions = tags,
88
+ strict = false,
89
+ commonDependencies,
90
+ policy,
91
+ languageForExtension,
92
+ commonjsLanguageForExtension,
93
+ moduleLanguageForExtension,
94
+ workspaceLanguageForExtension,
95
+ workspaceCommonjsLanguageForExtension,
96
+ workspaceModuleLanguageForExtension,
97
+ parserForLanguage,
98
+ languages,
99
+ ...otherOptions
100
+ } = assignParserForLanguage(options);
77
101
  const compartmentMap = await mapNodeModules(powers, moduleLocation, {
78
102
  dev,
103
+ strict,
79
104
  conditions,
80
105
  commonDependencies,
81
106
  policy,
107
+ languageForExtension,
108
+ commonjsLanguageForExtension,
109
+ moduleLanguageForExtension,
110
+ workspaceLanguageForExtension,
111
+ workspaceCommonjsLanguageForExtension,
112
+ workspaceModuleLanguageForExtension,
113
+ languages,
82
114
  });
83
115
 
84
- return makeArchiveFromMap(
85
- powers,
86
- compartmentMap,
87
- assignParserForLanguage(options),
88
- );
116
+ return makeArchiveFromMap(powers, compartmentMap, {
117
+ parserForLanguage,
118
+ policy,
119
+ ...otherOptions,
120
+ });
89
121
  };
90
122
 
91
123
  /**
@@ -95,16 +127,44 @@ export const makeArchive = async (powers, moduleLocation, options = {}) => {
95
127
  * @returns {Promise<Uint8Array>}
96
128
  */
97
129
  export const mapLocation = async (powers, moduleLocation, options = {}) => {
98
- const { dev, tags, conditions = tags, commonDependencies, policy } = options;
130
+ const {
131
+ dev,
132
+ tags,
133
+ conditions = tags,
134
+ strict = false,
135
+ commonDependencies,
136
+ policy,
137
+ parserForLanguage,
138
+ languages,
139
+ languageForExtension,
140
+ commonjsLanguageForExtension,
141
+ moduleLanguageForExtension,
142
+ workspaceLanguageForExtension,
143
+ workspaceCommonjsLanguageForExtension,
144
+ workspaceModuleLanguageForExtension,
145
+ ...otherOptions
146
+ } = assignParserForLanguage(options);
99
147
 
100
148
  const compartmentMap = await mapNodeModules(powers, moduleLocation, {
101
149
  dev,
150
+ strict,
102
151
  conditions,
103
152
  commonDependencies,
104
153
  policy,
154
+ languages,
155
+ languageForExtension,
156
+ commonjsLanguageForExtension,
157
+ moduleLanguageForExtension,
158
+ workspaceLanguageForExtension,
159
+ workspaceCommonjsLanguageForExtension,
160
+ workspaceModuleLanguageForExtension,
105
161
  });
106
162
 
107
- return mapFromMap(powers, compartmentMap, assignParserForLanguage(options));
163
+ return mapFromMap(powers, compartmentMap, {
164
+ parserForLanguage,
165
+ policy,
166
+ ...otherOptions,
167
+ });
108
168
  };
109
169
 
110
170
  /**
@@ -114,16 +174,44 @@ export const mapLocation = async (powers, moduleLocation, options = {}) => {
114
174
  * @returns {Promise<string>}
115
175
  */
116
176
  export const hashLocation = async (powers, moduleLocation, options = {}) => {
117
- const { dev, tags, conditions = tags, commonDependencies, policy } = options;
177
+ const {
178
+ dev,
179
+ tags,
180
+ conditions = tags,
181
+ strict = false,
182
+ commonDependencies,
183
+ policy,
184
+ parserForLanguage,
185
+ languages,
186
+ languageForExtension,
187
+ commonjsLanguageForExtension,
188
+ moduleLanguageForExtension,
189
+ workspaceLanguageForExtension,
190
+ workspaceCommonjsLanguageForExtension,
191
+ workspaceModuleLanguageForExtension,
192
+ ...otherOptions
193
+ } = assignParserForLanguage(options);
118
194
 
119
195
  const compartmentMap = await mapNodeModules(powers, moduleLocation, {
120
196
  dev,
197
+ strict,
121
198
  conditions,
122
199
  commonDependencies,
123
200
  policy,
201
+ languages,
202
+ languageForExtension,
203
+ commonjsLanguageForExtension,
204
+ moduleLanguageForExtension,
205
+ workspaceLanguageForExtension,
206
+ workspaceCommonjsLanguageForExtension,
207
+ workspaceModuleLanguageForExtension,
124
208
  });
125
209
 
126
- return hashFromMap(powers, compartmentMap, assignParserForLanguage(options));
210
+ return hashFromMap(powers, compartmentMap, {
211
+ parserForLanguage,
212
+ policy,
213
+ ...otherOptions,
214
+ });
127
215
  };
128
216
 
129
217
  /**
@@ -140,18 +228,42 @@ export const writeArchive = async (
140
228
  moduleLocation,
141
229
  options = {},
142
230
  ) => {
143
- const { dev, tags, conditions = tags, commonDependencies, policy } = options;
231
+ const {
232
+ dev,
233
+ tags,
234
+ conditions = tags,
235
+ strict = false,
236
+ commonDependencies,
237
+ policy,
238
+ parserForLanguage,
239
+ languages,
240
+ languageForExtension,
241
+ commonjsLanguageForExtension,
242
+ moduleLanguageForExtension,
243
+ workspaceLanguageForExtension,
244
+ workspaceCommonjsLanguageForExtension,
245
+ workspaceModuleLanguageForExtension,
246
+ ...otherOptions
247
+ } = assignParserForLanguage(options);
144
248
  const compartmentMap = await mapNodeModules(readPowers, moduleLocation, {
145
249
  dev,
250
+ strict,
146
251
  conditions,
147
252
  commonDependencies,
148
253
  policy,
254
+ languageForExtension,
255
+ commonjsLanguageForExtension,
256
+ moduleLanguageForExtension,
257
+ workspaceLanguageForExtension,
258
+ workspaceCommonjsLanguageForExtension,
259
+ workspaceModuleLanguageForExtension,
260
+ languages,
149
261
  });
150
262
  return writeArchiveFromMap(
151
263
  write,
152
264
  readPowers,
153
265
  archiveLocation,
154
266
  compartmentMap,
155
- assignParserForLanguage(options),
267
+ { policy, parserForLanguage, ...otherOptions },
156
268
  );
157
269
  };
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["bundle.js"],"names":[],"mappings":"AA4NO,uCALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM,yCAEJ,OAAO,CAAC,MAAM,CAAC,CA4K3B;AASM,mCANI,OAAO,QACP,MAAM,kBACN,MAAM,kBACN,MAAM,uDAahB;;;;;;;;;;;gBAxYa,MAAM,MAAM;;;;;;;cAOZ,MAAM,MAAM;;;;;;;oBAIZ,MAAM,MAAM;;;;;wBAIZ,MAAM,MAAM;;yBAKH,oBAAoB,SAA9B,OAAS;SAER,MAAM;qBACN,MAAM;qBACN,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;;0BAID,oBAAoB,SAA9B,OAAS,aAEX,YAAY,CAAC,oBAAoB,CAAC,KAChC,UAAU;2BAIA,oBAAoB,SAA9B,OAAS;aAER,MAAM;mBACN,aAAa,CAAC,oBAAoB,CAAC;;4BApDvB,YAAY;gCACR,YAAY;qCAHP,YAAY;oCAHb,YAAY;6BAQnB,YAAY;sCAVH,KAAK"}
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["bundle.js"],"names":[],"mappings":"AAsOO,uCALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM,yCAEJ,OAAO,CAAC,MAAM,CAAC,CAgN3B;AASM,mCANI,OAAO,QACP,MAAM,kBACN,MAAM,kBACN,MAAM,uDAahB;;;;;;;;;;;gBAlba,MAAM,MAAM;;;;;;;cAOZ,MAAM,MAAM;;;;;;;oBAIZ,MAAM,MAAM;;;;;wBAIZ,MAAM,MAAM;;yBAKH,oBAAoB,SAA9B,OAAS;SAER,MAAM;qBACN,MAAM;qBACN,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;;0BAID,oBAAoB,SAA9B,OAAS,aAEX,YAAY,CAAC,oBAAoB,CAAC,KAChC,UAAU;2BAIA,oBAAoB,SAA9B,OAAS;aAER,MAAM;mBACN,aAAa,CAAC,oBAAoB,CAAC;;4BAlDvC,YAAY;gCAAZ,YAAY;qCAAZ,YAAY;oCAAZ,YAAY;6BAAZ,YAAY;sCAVZ,KAAK"}