@endo/compartment-mapper 1.3.1 → 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 -3
  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
@@ -1,6 +1,7 @@
1
- /* Provides functions for constructing a compartment map that has a compartment
2
- * descriptor corresponding to every reachable package from an entry module and
3
- * how to create links between them.
1
+ /**
2
+ * @module Provides functions for constructing a compartment map that has a
3
+ * compartment descriptor corresponding to every reachable package from an
4
+ * entry module and how to create links between them.
4
5
  * The resulting compartment map does not describe individual modules but does
5
6
  * capture every usable route between packages including those generalized by
6
7
  * wildcard expansion.
@@ -8,23 +9,27 @@
8
9
  * for transitive dependencies.
9
10
  */
10
11
 
11
- // @ts-check
12
12
  /* eslint no-shadow: 0 */
13
13
 
14
- /** @import {CanonicalFn} from './types.js' */
15
- /** @import {CompartmentMapForNodeModulesOptions} from './types.js' */
16
- /** @import {SomePolicy} from './types.js' */
17
- /** @import {CompartmentDescriptor} from './types.js' */
18
- /** @import {CompartmentMapDescriptor} from './types.js' */
19
- /** @import {Language} from './types.js' */
20
- /** @import {LanguageForExtension} from './types.js' */
21
- /** @import {MaybeReadFn} from './types.js' */
22
- /** @import {MaybeReadPowers} from './types.js' */
23
- /** @import {ModuleDescriptor} from './types.js' */
24
- /** @import {ReadFn} from './types.js' */
25
- /** @import {ReadPowers} from './types.js' */
26
- /** @import {ScopeDescriptor} from './types.js' */
27
- /** @import {SomePackagePolicy} from './types.js' */
14
+ /**
15
+ * @import {
16
+ * CanonicalFn,
17
+ * CompartmentDescriptor,
18
+ * CompartmentMapDescriptor,
19
+ * CompartmentMapForNodeModulesOptions,
20
+ * Language,
21
+ * LanguageForExtension,
22
+ * MapNodeModulesOptions,
23
+ * MaybeReadFn,
24
+ * MaybeReadPowers,
25
+ * ModuleDescriptor,
26
+ * ReadFn,
27
+ * ReadPowers,
28
+ * ScopeDescriptor,
29
+ * SomePackagePolicy,
30
+ * SomePolicy,
31
+ * } from './types.js'
32
+ */
28
33
 
29
34
  /**
30
35
  * The graph is an intermediate object model that the functions of this module
@@ -52,6 +57,15 @@
52
57
  * modules.
53
58
  */
54
59
 
60
+ /**
61
+ * @typedef {object} LanguageOptions
62
+ * @property {LanguageForExtension} commonjsLanguageForExtension
63
+ * @property {LanguageForExtension} moduleLanguageForExtension
64
+ * @property {LanguageForExtension} workspaceCommonjsLanguageForExtension
65
+ * @property {LanguageForExtension} workspaceModuleLanguageForExtension
66
+ * @property {Set<string>} languages
67
+ */
68
+
55
69
  /**
56
70
  * @typedef {Record<string, {spec: string, alias: string}>} CommonDependencyDescriptors
57
71
  */
@@ -184,83 +198,83 @@ const findPackage = async (readDescriptor, canonical, directory, name) => {
184
198
  }
185
199
  };
186
200
 
187
- const defaultLanguages = /** @type {const} */ ([
188
- 'mjs',
189
- 'cjs',
190
- 'json',
191
- 'text',
192
- 'bytes',
193
- ]);
194
- const defaultUncontroversialParsers = /** @type {const} */ ({
195
- cjs: 'cjs',
201
+ const defaultLanguageForExtension = /** @type {const} */ ({
196
202
  mjs: 'mjs',
203
+ cjs: 'cjs',
197
204
  json: 'json',
198
205
  text: 'text',
199
206
  bytes: 'bytes',
200
207
  });
201
- const defaultCommonParsers = /** @type {const} */ ({
208
+ const defaultCommonjsLanguageForExtension = /** @type {const} */ ({
202
209
  js: 'cjs',
203
- ...defaultUncontroversialParsers,
204
210
  });
205
- const defaultModuleParsers = /** @type {const} */ ({
211
+ const defaultModuleLanguageForExtension = /** @type {const} */ ({
206
212
  js: 'mjs',
207
- ...defaultUncontroversialParsers,
208
213
  });
209
214
 
210
215
  /**
211
216
  * @param {object} descriptor
212
217
  * @param {string} location
213
- * @param {object} [options]
214
- * @param {readonly string[]|string[]} [options.languages]
215
- * @param {Record<string, string>} [options.uncontroversialParsers]
216
- * @param {Record<string, string>} [options.commonParsers]
217
- * @param {Record<string, string>} [options.moduleParsers]
218
+ * @param {LanguageOptions} languageOptions
218
219
  * @returns {Record<string, string>}
219
220
  */
220
- const inferParsers = (
221
- descriptor,
222
- location,
223
- {
224
- languages = defaultLanguages,
225
- uncontroversialParsers = defaultUncontroversialParsers,
226
- commonParsers = defaultCommonParsers,
227
- moduleParsers = defaultModuleParsers,
228
- } = {},
229
- ) => {
230
- const { type, module, parsers } = descriptor;
231
- let additionalParsers = Object.create(null);
232
- if (parsers !== undefined) {
233
- if (typeof parsers !== 'object') {
234
- throw Error(
235
- `Cannot interpret parser map ${JSON.stringify(
236
- parsers,
237
- )} of package at ${location}, must be an object mapping file extensions to corresponding languages (mjs for ECMAScript modules, cjs for CommonJS modules, or json for JSON modules`,
238
- );
239
- }
240
- const invalidLanguages = values(parsers).filter(
241
- language => !languages.includes(language),
221
+ const inferParsers = (descriptor, location, languageOptions) => {
222
+ let { moduleLanguageForExtension, commonjsLanguageForExtension } =
223
+ languageOptions;
224
+ const {
225
+ languages,
226
+ workspaceModuleLanguageForExtension,
227
+ workspaceCommonjsLanguageForExtension,
228
+ } = languageOptions;
229
+
230
+ // Select languageForExtension options based on whether they are physically
231
+ // under node_modules, indicating that they have not been built for npm,
232
+ // so any languages that compile to JavaScript may need additional parsers.
233
+ if (!location.includes('/node_modules/')) {
234
+ moduleLanguageForExtension = workspaceModuleLanguageForExtension;
235
+ commonjsLanguageForExtension = workspaceCommonjsLanguageForExtension;
236
+ }
237
+
238
+ const {
239
+ type,
240
+ module,
241
+ parsers: packageLanguageForExtension = {},
242
+ } = descriptor;
243
+
244
+ // Validate package-local "parsers"
245
+ if (
246
+ typeof packageLanguageForExtension !== 'object' ||
247
+ packageLanguageForExtension === null
248
+ ) {
249
+ throw Error(
250
+ `Cannot interpret parser map ${JSON.stringify(
251
+ packageLanguageForExtension,
252
+ )} of package at ${location}, must be an object mapping file extensions to corresponding languages (for example, mjs for ECMAScript modules, cjs for CommonJS modules, or json for JSON modules`,
242
253
  );
243
- if (invalidLanguages.length > 0) {
244
- throw Error(
245
- `Cannot interpret parser map language values ${JSON.stringify(
246
- invalidLanguages,
247
- )} of package at ${location}, must be an object mapping file extensions to corresponding languages (mjs for ECMAScript modules, cjs for CommonJS modules, or json for JSON modules`,
248
- );
249
- }
250
- additionalParsers = { ...uncontroversialParsers, ...parsers };
251
254
  }
255
+ const invalidLanguages = values(packageLanguageForExtension).filter(
256
+ language => !languages.has(language),
257
+ );
258
+ if (invalidLanguages.length > 0) {
259
+ throw Error(
260
+ `Cannot interpret parser map language values ${JSON.stringify(
261
+ invalidLanguages,
262
+ )} of package at ${location}, must be an object mapping file extensions to corresponding languages (for example, mjs for ECMAScript modules, cjs for CommonJS modules, or json for JSON modules`,
263
+ );
264
+ }
265
+
252
266
  if (type === 'module' || module !== undefined) {
253
- return { ...moduleParsers, ...additionalParsers };
267
+ return { ...moduleLanguageForExtension, ...packageLanguageForExtension };
254
268
  }
255
269
  if (type === 'commonjs') {
256
- return { ...commonParsers, ...additionalParsers };
270
+ return { ...commonjsLanguageForExtension, ...packageLanguageForExtension };
257
271
  }
258
272
  if (type !== undefined) {
259
273
  throw Error(
260
274
  `Cannot infer parser map for package of type ${type} at ${location}`,
261
275
  );
262
276
  }
263
- return { ...commonParsers, ...additionalParsers };
277
+ return { ...commonjsLanguageForExtension, ...packageLanguageForExtension };
264
278
  };
265
279
 
266
280
  /**
@@ -281,6 +295,7 @@ const inferParsers = (
281
295
  * @param {Set<string>} conditions
282
296
  * @param {boolean | undefined} dev
283
297
  * @param {CommonDependencyDescriptors} commonDependencyDescriptors
298
+ * @param {LanguageOptions} languageOptions
284
299
  * @param {Map<string, Array<string>>} preferredPackageLogicalPathMap
285
300
  * @param {Array<string>} logicalPath
286
301
  * @returns {Promise<undefined>}
@@ -294,6 +309,7 @@ const graphPackage = async (
294
309
  conditions,
295
310
  dev,
296
311
  commonDependencyDescriptors,
312
+ languageOptions,
297
313
  preferredPackageLogicalPathMap = new Map(),
298
314
  logicalPath = [],
299
315
  ) => {
@@ -363,6 +379,7 @@ const graphPackage = async (
363
379
  name,
364
380
  conditions,
365
381
  preferredPackageLogicalPathMap,
382
+ languageOptions,
366
383
  childLogicalPath,
367
384
  optional,
368
385
  commonDependencyDescriptors,
@@ -394,6 +411,12 @@ const graphPackage = async (
394
411
  types,
395
412
  );
396
413
 
414
+ const parsers = inferParsers(
415
+ packageDescriptor,
416
+ packageLocation,
417
+ languageOptions,
418
+ );
419
+
397
420
  Object.assign(result, {
398
421
  name,
399
422
  path: logicalPath,
@@ -403,7 +426,7 @@ const graphPackage = async (
403
426
  internalAliases,
404
427
  dependencyLocations,
405
428
  types,
406
- parsers: inferParsers(packageDescriptor, packageLocation),
429
+ parsers,
407
430
  });
408
431
 
409
432
  await Promise.all(
@@ -457,6 +480,7 @@ const graphPackage = async (
457
480
  * @param {string} name - name of the package of interest.
458
481
  * @param {Set<string>} conditions
459
482
  * @param {Map<string, Array<string>>} preferredPackageLogicalPathMap
483
+ * @param {LanguageOptions} languageOptions
460
484
  * @param {Array<string>} [childLogicalPath]
461
485
  * @param {boolean} [optional] - whether the dependency is optional
462
486
  * @param {object} [commonDependencyDescriptors] - dependencies to be added to all packages
@@ -470,6 +494,7 @@ const gatherDependency = async (
470
494
  name,
471
495
  conditions,
472
496
  preferredPackageLogicalPathMap,
497
+ languageOptions,
473
498
  childLogicalPath = [],
474
499
  optional = false,
475
500
  commonDependencyDescriptors = undefined,
@@ -506,6 +531,7 @@ const gatherDependency = async (
506
531
  conditions,
507
532
  false,
508
533
  commonDependencyDescriptors,
534
+ languageOptions,
509
535
  preferredPackageLogicalPathMap,
510
536
  childLogicalPath,
511
537
  );
@@ -528,7 +554,8 @@ const gatherDependency = async (
528
554
  * package.json, which was already read when searching for the package.json.
529
555
  * @param {boolean|undefined} dev - whether to use devDependencies from this package (and
530
556
  * only this package).
531
- * @param {Record<string,string>} [commonDependencies] - dependencies to be added to all packages
557
+ * @param {Record<string,string>} commonDependencies - dependencies to be added to all packages
558
+ * @param {LanguageOptions} languageOptions
532
559
  */
533
560
  const graphPackages = async (
534
561
  maybeRead,
@@ -537,7 +564,8 @@ const graphPackages = async (
537
564
  conditions,
538
565
  mainPackageDescriptor,
539
566
  dev,
540
- commonDependencies = {},
567
+ commonDependencies,
568
+ languageOptions,
541
569
  ) => {
542
570
  const memo = create(null);
543
571
  /**
@@ -594,6 +622,7 @@ const graphPackages = async (
594
622
  conditions,
595
623
  dev,
596
624
  commonDependencyDescriptors,
625
+ languageOptions,
597
626
  );
598
627
  return graph;
599
628
  };
@@ -749,6 +778,74 @@ const translateGraph = (
749
778
  };
750
779
  };
751
780
 
781
+ /**
782
+ * @param {Pick<MapNodeModulesOptions,
783
+ * 'languageForExtension' |
784
+ * 'moduleLanguageForExtension' |
785
+ * 'commonjsLanguageForExtension' |
786
+ * 'workspaceLanguageForExtension' |
787
+ * 'workspaceModuleLanguageForExtension' |
788
+ * 'workspaceCommonjsLanguageForExtension' |
789
+ * 'languages'
790
+ * >} options
791
+ */
792
+ const makeLanguageOptions = ({
793
+ languageForExtension: additionalLanguageForExtension = {},
794
+ moduleLanguageForExtension: additionalModuleLanguageForExtension = {},
795
+ commonjsLanguageForExtension: additionalCommonjsLanguageForExtension = {},
796
+ workspaceLanguageForExtension: additionalWorkspaceLanguageForExtension = {},
797
+ workspaceModuleLanguageForExtension:
798
+ additionalWorkspaceModuleLanguageForExtension = {},
799
+ workspaceCommonjsLanguageForExtension:
800
+ additionalWorkspaceCommonjsLanguageForExtension = {},
801
+ languages: additionalLanguages = [],
802
+ }) => {
803
+ const commonjsLanguageForExtension = {
804
+ ...defaultLanguageForExtension,
805
+ ...additionalLanguageForExtension,
806
+ ...defaultCommonjsLanguageForExtension,
807
+ ...additionalCommonjsLanguageForExtension,
808
+ };
809
+ const moduleLanguageForExtension = {
810
+ ...defaultLanguageForExtension,
811
+ ...additionalLanguageForExtension,
812
+ ...defaultModuleLanguageForExtension,
813
+ ...additionalModuleLanguageForExtension,
814
+ };
815
+ const workspaceCommonjsLanguageForExtension = {
816
+ ...defaultLanguageForExtension,
817
+ ...additionalLanguageForExtension,
818
+ ...defaultCommonjsLanguageForExtension,
819
+ ...additionalCommonjsLanguageForExtension,
820
+ ...additionalWorkspaceLanguageForExtension,
821
+ ...additionalWorkspaceCommonjsLanguageForExtension,
822
+ };
823
+ const workspaceModuleLanguageForExtension = {
824
+ ...defaultLanguageForExtension,
825
+ ...additionalLanguageForExtension,
826
+ ...defaultModuleLanguageForExtension,
827
+ ...additionalModuleLanguageForExtension,
828
+ ...additionalWorkspaceLanguageForExtension,
829
+ ...additionalWorkspaceModuleLanguageForExtension,
830
+ };
831
+
832
+ const languages = new Set([
833
+ ...Object.values(moduleLanguageForExtension),
834
+ ...Object.values(commonjsLanguageForExtension),
835
+ ...Object.values(workspaceModuleLanguageForExtension),
836
+ ...Object.values(workspaceCommonjsLanguageForExtension),
837
+ ...additionalLanguages,
838
+ ]);
839
+
840
+ return {
841
+ languages,
842
+ commonjsLanguageForExtension,
843
+ moduleLanguageForExtension,
844
+ workspaceCommonjsLanguageForExtension,
845
+ workspaceModuleLanguageForExtension,
846
+ };
847
+ };
848
+
752
849
  /**
753
850
  * @param {ReadFn | ReadPowers | MaybeReadPowers} readPowers
754
851
  * @param {string} packageLocation
@@ -766,8 +863,10 @@ export const compartmentMapForNodeModules = async (
766
863
  moduleSpecifier,
767
864
  options = {},
768
865
  ) => {
769
- const { dev = undefined, commonDependencies, policy } = options;
866
+ const { dev = undefined, commonDependencies = {}, policy } = options;
770
867
  const { maybeRead, canonical } = unpackReadPowers(readPowers);
868
+ const languageOptions = makeLanguageOptions(options);
869
+
771
870
  const graph = await graphPackages(
772
871
  maybeRead,
773
872
  canonical,
@@ -776,6 +875,7 @@ export const compartmentMapForNodeModules = async (
776
875
  packageDescriptor,
777
876
  dev,
778
877
  commonDependencies,
878
+ languageOptions,
779
879
  );
780
880
 
781
881
  if (policy) {
@@ -808,12 +908,7 @@ export const compartmentMapForNodeModules = async (
808
908
  /**
809
909
  * @param {ReadFn | ReadPowers | MaybeReadPowers} readPowers
810
910
  * @param {string} moduleLocation
811
- * @param {object} [options]
812
- * @param {Set<string>} [options.tags] deprecated in favor of `conditions`
813
- * @param {Set<string>} [options.conditions]
814
- * @param {boolean} [options.dev]
815
- * @param {object} [options.commonDependencies]
816
- * @param {object} [options.policy]
911
+ * @param {MapNodeModulesOptions} [options]
817
912
  * @returns {Promise<CompartmentMapDescriptor>}
818
913
  */
819
914
  export const mapNodeModules = async (
@@ -821,13 +916,7 @@ export const mapNodeModules = async (
821
916
  moduleLocation,
822
917
  options = {},
823
918
  ) => {
824
- const {
825
- tags = new Set(),
826
- conditions = tags,
827
- dev = undefined,
828
- commonDependencies,
829
- policy,
830
- } = options;
919
+ const { tags = new Set(), conditions = tags, ...otherOptions } = options;
831
920
 
832
921
  const {
833
922
  packageLocation,
@@ -847,6 +936,6 @@ export const mapNodeModules = async (
847
936
  conditions,
848
937
  packageDescriptor,
849
938
  moduleSpecifier,
850
- { dev, commonDependencies, policy },
939
+ otherOptions,
851
940
  );
852
941
  };
@@ -39,12 +39,12 @@ export function makeWritePowers({ fs, url }: {
39
39
  };
40
40
  export function makeNodeReadPowers(fs: FsInterface, crypto?: CryptoInterface | undefined): ReadPowers;
41
41
  export function makeNodeWritePowers(fs: FsInterface): WritePowers;
42
- import type { FsInterface } from './types.js';
43
- import type { UrlInterface } from './types.js';
44
- import type { CryptoInterface } from './types.js';
45
- import type { PathInterface } from './types.js';
46
- import type { MaybeReadPowers } from './types.js';
47
- import type { ReadNowPowers } from './types.js';
48
- import type { ReadPowers } from './types.js';
49
- import type { WritePowers } from './types.js';
42
+ import type { FsInterface } from './types/node-powers.js';
43
+ import type { UrlInterface } from './types/node-powers.js';
44
+ import type { CryptoInterface } from './types/node-powers.js';
45
+ import type { PathInterface } from './types/node-powers.js';
46
+ import type { MaybeReadPowers } from './types/powers.js';
47
+ import type { ReadNowPowers } from './types/powers.js';
48
+ import type { ReadPowers } from './types/powers.js';
49
+ import type { WritePowers } from './types/powers.js';
50
50
  //# sourceMappingURL=node-powers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-powers.d.ts","sourceRoot":"","sources":["node-powers.js"],"names":[],"mappings":"AAqLO,8DANJ;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;IACA,MAAM;IACR,IAAI;CACjC,GAAU,eAAe,GAAG,aAAa,CAoC3C;AAlKD;;;;;;;;;;;GAWG;AACH,2DANG;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;IACA,MAAM;IACR,IAAI;CACjC,GAAU,eAAe,CA0G3B;AAgDD;;;;;;;;GAQG;AACH,6CAHG;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;CAAC;sBAOtB,MAAM,QACN,UAAU;EAYtB;AA2BM,uCALI,WAAW,yCAET,UAAU,CAKtB;AAWM,wCAJI,WAAW,GACT,WAAW,CAKvB;iCAjR8B,YAAY;kCAWX,YAAY;qCAbT,YAAY;mCAOd,YAAY;qCADV,YAAY;mCAMd,YAAY;gCAFf,YAAY;iCAIX,YAAY"}
1
+ {"version":3,"file":"node-powers.d.ts","sourceRoot":"","sources":["node-powers.js"],"names":[],"mappings":"AA0LO,8DANJ;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;IACA,MAAM;IACR,IAAI;CACjC,GAAU,eAAe,GAAG,aAAa,CAoC3C;AAlKD;;;;;;;;;;;GAWG;AACH,2DANG;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;IACA,MAAM;IACR,IAAI;CACjC,GAAU,eAAe,CA0G3B;AAgDD;;;;;;;;GAQG;AACH,6CAHG;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;CAAC;sBAOtB,MAAM,QACN,UAAU;EAYtB;AA2BM,uCALI,WAAW,yCAET,UAAU,CAKtB;AAWM,wCAJI,WAAW,GACT,WAAW,CAKvB;iCApRS,wBAAwB;kCAAxB,wBAAwB;qCAAxB,wBAAwB;mCAAxB,wBAAwB;qCAexB,mBAAmB;mCAAnB,mBAAmB;gCAAnB,mBAAmB;iCAAnB,mBAAmB"}
@@ -1,30 +1,35 @@
1
- /* Provides adapters for Compartment Mapper I/O to the corresponding Node.js
2
- * implementations of those behaviors.
1
+ /**
2
+ * @module Provides adapters for Compartment Mapper I/O to the corresponding
3
+ * Node.js implementations of those behaviors.
3
4
  *
4
5
  * The Compartment Mapper generalizes its I/O interface to allow for a wide
5
6
  * variety of I/O providers, but especially for reading and writing from
6
7
  * virtualized file systems like zip files.
7
8
  */
8
9
 
9
- // @ts-check
10
-
11
- /** @import {CanonicalFn} from './types.js' */
12
- /** @import {CryptoInterface} from './types.js' */
13
- /** @import {FileURLToPathFn} from './types.js' */
14
- /** @import {FsInterface} from './types.js' */
15
- /** @import {HashFn} from './types.js' */
16
- /** @import {IsAbsoluteFn} from './types.js' */
17
- /** @import {MaybeReadFn} from './types.js' */
18
- /** @import {MaybeReadPowers} from './types.js' */
19
- /** @import {PathInterface} from './types.js' */
20
- /** @import {PathToFileURLFn} from './types.js' */
21
- /** @import {ReadFn} from './types.js' */
22
- /** @import {ReadPowers} from './types.js' */
23
- /** @import {RequireResolveFn} from './types.js' */
24
- /** @import {ReadNowPowers} from './types.js' */
25
- /** @import {UrlInterface} from './types.js' */
26
- /** @import {WritePowers} from './types.js' */
27
- /** @import {MaybeReadNowFn} from './types.js' */
10
+ /**
11
+ * @import {
12
+ * CryptoInterface,
13
+ * FsInterface,
14
+ * PathInterface,
15
+ * UrlInterface,
16
+ * } from './types/node-powers.js'
17
+ * @import {
18
+ * CanonicalFn,
19
+ * FileURLToPathFn,
20
+ * HashFn,
21
+ * IsAbsoluteFn,
22
+ * MaybeReadFn,
23
+ * MaybeReadNowFn,
24
+ * MaybeReadPowers,
25
+ * PathToFileURLFn,
26
+ * ReadFn,
27
+ * ReadNowPowers,
28
+ * ReadPowers,
29
+ * RequireResolveFn,
30
+ * WritePowers,
31
+ * } from './types/powers.js'
32
+ */
28
33
 
29
34
  import { createRequire } from 'module';
30
35
 
@@ -43,7 +48,7 @@ const fakeFileURLToPath = location => {
43
48
  * @type {PathToFileURLFn} path
44
49
  */
45
50
  const fakePathToFileURL = path => {
46
- return new URL(path, 'file://').toString();
51
+ return new URL(path, 'file://');
47
52
  };
48
53
 
49
54
  /**
@@ -138,10 +143,10 @@ const makeReadPowersSloppy = ({
138
143
  const realPath = await fs.promises.realpath(
139
144
  fileURLToPath(location).replace(/\/$/, ''),
140
145
  );
141
- return `${pathToFileURL(realPath)}/`;
146
+ return `${pathToFileURL(realPath).href}/`;
142
147
  } else {
143
148
  const realPath = await fs.promises.realpath(fileURLToPath(location));
144
- return pathToFileURL(realPath).toString();
149
+ return pathToFileURL(realPath).href;
145
150
  }
146
151
  } catch {
147
152
  return location;
@@ -1,5 +1,6 @@
1
- /** @type {import('./types.js').ParseFn} */
2
- export const parseArchiveCjs: import("./types.js").ParseFn;
1
+ /** @type {ParseFn} */
2
+ export const parseArchiveCjs: ParseFn;
3
3
  declare const _default: import("./types.js").ParserImplementation;
4
4
  export default _default;
5
+ import type { ParseFn } from './types.js';
5
6
  //# sourceMappingURL=parse-archive-cjs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-archive-cjs.d.ts","sourceRoot":"","sources":["parse-archive-cjs.js"],"names":[],"mappings":"AAiBA,2CAA2C;AAC3C,8BADW,OAAO,YAAY,EAAE,OAAO,CA6CrC;wBAES,OAAO,YAAY,EAAE,oBAAoB"}
1
+ {"version":3,"file":"parse-archive-cjs.d.ts","sourceRoot":"","sources":["parse-archive-cjs.js"],"names":[],"mappings":"AAkBA,sBAAsB;AACtB,8BADW,OAAO,CA6ChB;wBAES,OAAO,YAAY,EAAE,oBAAoB;;6BA5DzB,YAAY"}
@@ -1,8 +1,9 @@
1
- /* Provides language behavior for analyzing, pre-compiling, and storing
1
+ /**
2
+ * @module Provides language behavior for analyzing, pre-compiling, and storing
2
3
  * CommonJS modules for an archive.
3
4
  */
4
5
 
5
- // @ts-check
6
+ /** @import {ParseFn} from './types.js' */
6
7
 
7
8
  import { analyzeCommonJS } from '@endo/cjs-module-analyzer';
8
9
 
@@ -15,10 +16,10 @@ const freeze = Object.freeze;
15
16
  const noopExecute = () => {};
16
17
  freeze(noopExecute);
17
18
 
18
- /** @type {import('./types.js').ParseFn} */
19
+ /** @type {ParseFn} */
19
20
  export const parseArchiveCjs = (
20
21
  bytes,
21
- specifier,
22
+ _specifier,
22
23
  location,
23
24
  _packageLocation,
24
25
  ) => {
@@ -1,5 +1,6 @@
1
- /** @type {import('./types.js').ParseFn} */
2
- export const parseArchiveMjs: import("./types.js").ParseFn;
1
+ /** @type {ParseFn} */
2
+ export const parseArchiveMjs: ParseFn;
3
3
  declare const _default: import("./types.js").ParserImplementation;
4
4
  export default _default;
5
+ import type { ParseFn } from './types.js';
5
6
  //# sourceMappingURL=parse-archive-mjs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-archive-mjs.d.ts","sourceRoot":"","sources":["parse-archive-mjs.js"],"names":[],"mappings":"AAUA,2CAA2C;AAC3C,8BADW,OAAO,YAAY,EAAE,OAAO,CAqBrC;wBAES,OAAO,YAAY,EAAE,oBAAoB"}
1
+ {"version":3,"file":"parse-archive-mjs.d.ts","sourceRoot":"","sources":["parse-archive-mjs.js"],"names":[],"mappings":"AAYA,sBAAsB;AACtB,8BADW,OAAO,CAqBhB;wBAES,OAAO,YAAY,EAAE,oBAAoB;;6BA9BzB,YAAY"}
@@ -1,19 +1,21 @@
1
- /* Provides language behavior for analyzing, pre-compiling, and storing ESM
1
+ /**
2
+ * @module Provides language behavior for analyzing, pre-compiling, and storing ESM
2
3
  * modules for an archive.
3
4
  */
4
- // @ts-check
5
+
6
+ /** @import {ParseFn} from './types.js' */
5
7
 
6
8
  import { ModuleSource } from '@endo/module-source';
7
9
 
8
10
  const textEncoder = new TextEncoder();
9
11
  const textDecoder = new TextDecoder();
10
12
 
11
- /** @type {import('./types.js').ParseFn} */
13
+ /** @type {ParseFn} */
12
14
  export const parseArchiveMjs = (
13
15
  bytes,
14
- specifier,
16
+ _specifier,
15
17
  sourceUrl,
16
- packageLocation,
18
+ _packageLocation,
17
19
  options = {},
18
20
  ) => {
19
21
  const { sourceMap, sourceMapHook } = options;
@@ -1,5 +1,6 @@
1
- /** @type {import('./types.js').ParseFn} */
2
- export const parseBytes: import("./types.js").ParseFn;
1
+ /** @type {ParseFn} */
2
+ export const parseBytes: ParseFn;
3
3
  declare const _default: import("./types.js").ParserImplementation;
4
4
  export default _default;
5
+ import type { ParseFn } from './types.js';
5
6
  //# sourceMappingURL=parse-bytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-bytes.d.ts","sourceRoot":"","sources":["parse-bytes.js"],"names":[],"mappings":"AAcA,2CAA2C;AAC3C,yBADW,OAAO,YAAY,EAAE,OAAO,CA0BrC;wBAES,OAAO,YAAY,EAAE,oBAAoB"}
1
+ {"version":3,"file":"parse-bytes.d.ts","sourceRoot":"","sources":["parse-bytes.js"],"names":[],"mappings":"AAgBA,sBAAsB;AACtB,yBADW,OAAO,CA0BhB;wBAES,OAAO,YAAY,EAAE,oBAAoB;;6BAtCzB,YAAY"}
@@ -1,18 +1,20 @@
1
- /* Provides rudimentary support for treating an arbitrary file as a module that
2
- * exports the bytes of that file.
1
+ /**
2
+ * @module Provides rudimentary support for treating an arbitrary file as a
3
+ * module that exports the bytes of that file.
3
4
  */
4
5
 
5
- // @ts-check
6
+ /** @import {Harden} from 'ses' */
7
+ /** @import {ParseFn} from './types.js' */
6
8
 
7
9
  /**
8
10
  * TypeScript cannot be relied upon to deal with the nuances of Readonly, so we
9
11
  * borrow the pass-through type definition of harden here.
10
12
  *
11
- * @type {import('ses').Harden}
13
+ * @type {Harden}
12
14
  */
13
15
  const freeze = Object.freeze;
14
16
 
15
- /** @type {import('./types.js').ParseFn} */
17
+ /** @type {ParseFn} */
16
18
  export const parseBytes = (bytes, _specifier, _location, _packageLocation) => {
17
19
  // Snapshot ArrayBuffer
18
20
  const buffer = new ArrayBuffer(bytes.length);
@@ -1 +1 @@
1
- {"version":3,"file":"parse-cjs-shared-export-wrapper.d.ts","sourceRoot":"","sources":["parse-cjs-shared-export-wrapper.js"],"names":[],"mappings":"AAuCO,2CAPI,UAAU,GAAG,MAAM,GAAG,SAAS,YAC/B,MAAM,GACJ;IACR,QAAQ,EAAC,MAAM,GAAC,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAC,IAAI,CAAA;CACrB,CAgCH;AAmBM,uGAZJ;IAAmB,uBAAuB,EAAlC,MAAM;IACU,WAAW,EAA3B,WAAW;IACgB,eAAe,EAA1C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACX,QAAQ,EAAnB,MAAM;IAC8B,UAAU,EAA9C,MAAM,GAAG,UAAU,GAAG,SAAS;CACvC,GAAU;IACR,MAAM,EAAE;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC;IACzB,aAAa,EAAE,GAAG,CAAC;IACnB,YAAY,WAAW;IACvB,OAAO,WAAW;CACnB,CAmIH;gCA/M6B,YAAY;4BADhB,YAAY"}
1
+ {"version":3,"file":"parse-cjs-shared-export-wrapper.d.ts","sourceRoot":"","sources":["parse-cjs-shared-export-wrapper.js"],"names":[],"mappings":"AAwCO,2CAPI,UAAU,GAAG,MAAM,GAAG,SAAS,YAC/B,MAAM,GACJ;IACR,QAAQ,EAAC,MAAM,GAAC,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAC,IAAI,CAAA;CACrB,CAgCH;AAmBM,uGAZJ;IAAmB,uBAAuB,EAAlC,MAAM;IACU,WAAW,EAA3B,WAAW;IACgB,eAAe,EAA1C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACX,QAAQ,EAAnB,MAAM;IAC8B,UAAU,EAA9C,MAAM,GAAG,UAAU,GAAG,SAAS;CACvC,GAAU;IACR,MAAM,EAAE;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC;IACzB,aAAa,EAAE,GAAG,CAAC;IACnB,YAAY,WAAW;IACvB,OAAO,WAAW;CACnB,CAmIH;gCApNqC,YAAY;4BAAZ,YAAY"}