@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
@@ -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`,
253
+ );
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`,
242
263
  );
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
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,8 @@ const inferParsers = (
281
295
  * @param {Set<string>} conditions
282
296
  * @param {boolean | undefined} dev
283
297
  * @param {CommonDependencyDescriptors} commonDependencyDescriptors
298
+ * @param {LanguageOptions} languageOptions
299
+ * @param {boolean} strict
284
300
  * @param {Map<string, Array<string>>} preferredPackageLogicalPathMap
285
301
  * @param {Array<string>} logicalPath
286
302
  * @returns {Promise<undefined>}
@@ -294,6 +310,8 @@ const graphPackage = async (
294
310
  conditions,
295
311
  dev,
296
312
  commonDependencyDescriptors,
313
+ languageOptions,
314
+ strict,
297
315
  preferredPackageLogicalPathMap = new Map(),
298
316
  logicalPath = [],
299
317
  ) => {
@@ -328,14 +346,18 @@ const graphPackage = async (
328
346
  devDependencies = {},
329
347
  } = packageDescriptor;
330
348
  const allDependencies = {};
331
- assign(allDependencies, commonDependencyDescriptors);
332
- for (const [name, { spec }] of Object.entries(commonDependencyDescriptors)) {
333
- allDependencies[name] = spec;
349
+ for (const [name, descriptor] of Object.entries(
350
+ commonDependencyDescriptors,
351
+ )) {
352
+ if (Object(descriptor) === descriptor) {
353
+ const { spec } = descriptor;
354
+ allDependencies[name] = spec;
355
+ }
334
356
  }
335
357
  assign(allDependencies, dependencies);
336
358
  assign(allDependencies, peerDependencies);
337
- for (const [name, { optional }] of Object.entries(peerDependenciesMeta)) {
338
- if (optional) {
359
+ for (const [name, meta] of Object.entries(peerDependenciesMeta)) {
360
+ if (Object(meta) === meta && meta.optional) {
339
361
  optionals.add(name);
340
362
  }
341
363
  }
@@ -344,7 +366,7 @@ const graphPackage = async (
344
366
  for (const name of Object.keys(optionalDependencies)) {
345
367
  optionals.add(name);
346
368
  }
347
- if (dev !== undefined && dev !== null ? dev : conditions.has('development')) {
369
+ if (dev) {
348
370
  assign(allDependencies, devDependencies);
349
371
  }
350
372
 
@@ -363,6 +385,8 @@ const graphPackage = async (
363
385
  name,
364
386
  conditions,
365
387
  preferredPackageLogicalPathMap,
388
+ languageOptions,
389
+ strict,
366
390
  childLogicalPath,
367
391
  optional,
368
392
  commonDependencyDescriptors,
@@ -394,6 +418,12 @@ const graphPackage = async (
394
418
  types,
395
419
  );
396
420
 
421
+ const parsers = inferParsers(
422
+ packageDescriptor,
423
+ packageLocation,
424
+ languageOptions,
425
+ );
426
+
397
427
  Object.assign(result, {
398
428
  name,
399
429
  path: logicalPath,
@@ -403,7 +433,7 @@ const graphPackage = async (
403
433
  internalAliases,
404
434
  dependencyLocations,
405
435
  types,
406
- parsers: inferParsers(packageDescriptor, packageLocation),
436
+ parsers,
407
437
  });
408
438
 
409
439
  await Promise.all(
@@ -457,6 +487,8 @@ const graphPackage = async (
457
487
  * @param {string} name - name of the package of interest.
458
488
  * @param {Set<string>} conditions
459
489
  * @param {Map<string, Array<string>>} preferredPackageLogicalPathMap
490
+ * @param {LanguageOptions} languageOptions
491
+ * @param {boolean} strict
460
492
  * @param {Array<string>} [childLogicalPath]
461
493
  * @param {boolean} [optional] - whether the dependency is optional
462
494
  * @param {object} [commonDependencyDescriptors] - dependencies to be added to all packages
@@ -470,6 +502,8 @@ const gatherDependency = async (
470
502
  name,
471
503
  conditions,
472
504
  preferredPackageLogicalPathMap,
505
+ languageOptions,
506
+ strict,
473
507
  childLogicalPath = [],
474
508
  optional = false,
475
509
  commonDependencyDescriptors = undefined,
@@ -482,7 +516,7 @@ const gatherDependency = async (
482
516
  );
483
517
  if (dependency === undefined) {
484
518
  // allow the dependency to be missing if optional
485
- if (optional) {
519
+ if (optional || !strict) {
486
520
  return;
487
521
  }
488
522
  throw Error(`Cannot find dependency ${name} for ${packageLocation}`);
@@ -506,6 +540,8 @@ const gatherDependency = async (
506
540
  conditions,
507
541
  false,
508
542
  commonDependencyDescriptors,
543
+ languageOptions,
544
+ strict,
509
545
  preferredPackageLogicalPathMap,
510
546
  childLogicalPath,
511
547
  );
@@ -528,7 +564,9 @@ const gatherDependency = async (
528
564
  * package.json, which was already read when searching for the package.json.
529
565
  * @param {boolean|undefined} dev - whether to use devDependencies from this package (and
530
566
  * only this package).
531
- * @param {Record<string,string>} [commonDependencies] - dependencies to be added to all packages
567
+ * @param {Record<string,string>} commonDependencies - dependencies to be added to all packages
568
+ * @param {LanguageOptions} languageOptions
569
+ * @param {boolean} strict
532
570
  */
533
571
  const graphPackages = async (
534
572
  maybeRead,
@@ -537,7 +575,9 @@ const graphPackages = async (
537
575
  conditions,
538
576
  mainPackageDescriptor,
539
577
  dev,
540
- commonDependencies = {},
578
+ commonDependencies,
579
+ languageOptions,
580
+ strict,
541
581
  ) => {
542
582
  const memo = create(null);
543
583
  /**
@@ -594,6 +634,8 @@ const graphPackages = async (
594
634
  conditions,
595
635
  dev,
596
636
  commonDependencyDescriptors,
637
+ languageOptions,
638
+ strict,
597
639
  );
598
640
  return graph;
599
641
  };
@@ -749,10 +791,78 @@ const translateGraph = (
749
791
  };
750
792
  };
751
793
 
794
+ /**
795
+ * @param {Pick<MapNodeModulesOptions,
796
+ * 'languageForExtension' |
797
+ * 'moduleLanguageForExtension' |
798
+ * 'commonjsLanguageForExtension' |
799
+ * 'workspaceLanguageForExtension' |
800
+ * 'workspaceModuleLanguageForExtension' |
801
+ * 'workspaceCommonjsLanguageForExtension' |
802
+ * 'languages'
803
+ * >} options
804
+ */
805
+ const makeLanguageOptions = ({
806
+ languageForExtension: additionalLanguageForExtension = {},
807
+ moduleLanguageForExtension: additionalModuleLanguageForExtension = {},
808
+ commonjsLanguageForExtension: additionalCommonjsLanguageForExtension = {},
809
+ workspaceLanguageForExtension: additionalWorkspaceLanguageForExtension = {},
810
+ workspaceModuleLanguageForExtension:
811
+ additionalWorkspaceModuleLanguageForExtension = {},
812
+ workspaceCommonjsLanguageForExtension:
813
+ additionalWorkspaceCommonjsLanguageForExtension = {},
814
+ languages: additionalLanguages = [],
815
+ }) => {
816
+ const commonjsLanguageForExtension = {
817
+ ...defaultLanguageForExtension,
818
+ ...additionalLanguageForExtension,
819
+ ...defaultCommonjsLanguageForExtension,
820
+ ...additionalCommonjsLanguageForExtension,
821
+ };
822
+ const moduleLanguageForExtension = {
823
+ ...defaultLanguageForExtension,
824
+ ...additionalLanguageForExtension,
825
+ ...defaultModuleLanguageForExtension,
826
+ ...additionalModuleLanguageForExtension,
827
+ };
828
+ const workspaceCommonjsLanguageForExtension = {
829
+ ...defaultLanguageForExtension,
830
+ ...additionalLanguageForExtension,
831
+ ...defaultCommonjsLanguageForExtension,
832
+ ...additionalCommonjsLanguageForExtension,
833
+ ...additionalWorkspaceLanguageForExtension,
834
+ ...additionalWorkspaceCommonjsLanguageForExtension,
835
+ };
836
+ const workspaceModuleLanguageForExtension = {
837
+ ...defaultLanguageForExtension,
838
+ ...additionalLanguageForExtension,
839
+ ...defaultModuleLanguageForExtension,
840
+ ...additionalModuleLanguageForExtension,
841
+ ...additionalWorkspaceLanguageForExtension,
842
+ ...additionalWorkspaceModuleLanguageForExtension,
843
+ };
844
+
845
+ const languages = new Set([
846
+ ...Object.values(moduleLanguageForExtension),
847
+ ...Object.values(commonjsLanguageForExtension),
848
+ ...Object.values(workspaceModuleLanguageForExtension),
849
+ ...Object.values(workspaceCommonjsLanguageForExtension),
850
+ ...additionalLanguages,
851
+ ]);
852
+
853
+ return {
854
+ languages,
855
+ commonjsLanguageForExtension,
856
+ moduleLanguageForExtension,
857
+ workspaceCommonjsLanguageForExtension,
858
+ workspaceModuleLanguageForExtension,
859
+ };
860
+ };
861
+
752
862
  /**
753
863
  * @param {ReadFn | ReadPowers | MaybeReadPowers} readPowers
754
864
  * @param {string} packageLocation
755
- * @param {Set<string>} conditions
865
+ * @param {Set<string>} conditionsOption
756
866
  * @param {object} packageDescriptor
757
867
  * @param {string} moduleSpecifier
758
868
  * @param {CompartmentMapForNodeModulesOptions} [options]
@@ -761,21 +871,37 @@ const translateGraph = (
761
871
  export const compartmentMapForNodeModules = async (
762
872
  readPowers,
763
873
  packageLocation,
764
- conditions,
874
+ conditionsOption,
765
875
  packageDescriptor,
766
876
  moduleSpecifier,
767
877
  options = {},
768
878
  ) => {
769
- const { dev = undefined, commonDependencies, policy } = options;
879
+ const {
880
+ dev = false,
881
+ commonDependencies = {},
882
+ policy,
883
+ strict = false,
884
+ } = options;
770
885
  const { maybeRead, canonical } = unpackReadPowers(readPowers);
886
+ const languageOptions = makeLanguageOptions(options);
887
+
888
+ const conditions = new Set(conditionsOption || []);
889
+
890
+ // dev is only set for the entry package, and implied by the development
891
+ // condition.
892
+ // The dev option is deprecated in favor of using conditions, since that
893
+ // covers more intentional behaviors of the development mode.
894
+
771
895
  const graph = await graphPackages(
772
896
  maybeRead,
773
897
  canonical,
774
898
  packageLocation,
775
899
  conditions,
776
900
  packageDescriptor,
777
- dev,
901
+ dev || (conditions && conditions.has('development')),
778
902
  commonDependencies,
903
+ languageOptions,
904
+ strict,
779
905
  );
780
906
 
781
907
  if (policy) {
@@ -808,12 +934,7 @@ export const compartmentMapForNodeModules = async (
808
934
  /**
809
935
  * @param {ReadFn | ReadPowers | MaybeReadPowers} readPowers
810
936
  * @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]
937
+ * @param {MapNodeModulesOptions} [options]
817
938
  * @returns {Promise<CompartmentMapDescriptor>}
818
939
  */
819
940
  export const mapNodeModules = async (
@@ -821,13 +942,7 @@ export const mapNodeModules = async (
821
942
  moduleLocation,
822
943
  options = {},
823
944
  ) => {
824
- const {
825
- tags = new Set(),
826
- conditions = tags,
827
- dev = undefined,
828
- commonDependencies,
829
- policy,
830
- } = options;
945
+ const { tags = new Set(), conditions = tags, ...otherOptions } = options;
831
946
 
832
947
  const {
833
948
  packageLocation,
@@ -847,6 +962,6 @@ export const mapNodeModules = async (
847
962
  conditions,
848
963
  packageDescriptor,
849
964
  moduleSpecifier,
850
- { dev, commonDependencies, policy },
965
+ otherOptions,
851
966
  );
852
967
  };
@@ -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"}