@endo/compartment-mapper 1.5.0 → 1.6.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 (71) hide show
  1. package/README.md +278 -111
  2. package/bundle.d.ts +1 -1
  3. package/bundle.js +4 -1
  4. package/functor-lite.d.ts +3 -0
  5. package/functor-lite.d.ts.map +1 -0
  6. package/functor-lite.js +4 -0
  7. package/functor.d.ts +3 -0
  8. package/functor.d.ts.map +1 -0
  9. package/functor.js +4 -0
  10. package/index.d.ts +1 -1
  11. package/index.js +4 -1
  12. package/package.json +8 -4
  13. package/script-lite.d.ts +3 -0
  14. package/script-lite.d.ts.map +1 -0
  15. package/script-lite.js +4 -0
  16. package/script.d.ts +3 -0
  17. package/script.d.ts.map +1 -0
  18. package/script.js +4 -0
  19. package/src/archive-lite.js +1 -1
  20. package/src/bundle-cjs.d.ts +1 -1
  21. package/src/bundle-cjs.d.ts.map +1 -1
  22. package/src/bundle-cjs.js +57 -28
  23. package/src/bundle-json.d.ts.map +1 -1
  24. package/src/bundle-json.js +2 -3
  25. package/src/bundle-lite.d.ts +91 -0
  26. package/src/bundle-lite.d.ts.map +1 -0
  27. package/src/bundle-lite.js +668 -0
  28. package/src/bundle-mjs.d.ts +2 -2
  29. package/src/bundle-mjs.d.ts.map +1 -1
  30. package/src/bundle-mjs.js +36 -19
  31. package/src/bundle.d.ts +48 -10
  32. package/src/bundle.d.ts.map +1 -1
  33. package/src/bundle.js +391 -125
  34. package/src/capture-lite.js +1 -1
  35. package/src/import-hook.d.ts +3 -16
  36. package/src/import-hook.d.ts.map +1 -1
  37. package/src/import-hook.js +11 -18
  38. package/src/import-lite.d.ts.map +1 -1
  39. package/src/import-lite.js +4 -2
  40. package/src/node-modules.d.ts +4 -47
  41. package/src/node-modules.d.ts.map +1 -1
  42. package/src/node-modules.js +121 -121
  43. package/src/parse-archive-cjs.d.ts.map +1 -1
  44. package/src/parse-archive-cjs.js +8 -3
  45. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  46. package/src/parse-cjs-shared-export-wrapper.js +2 -10
  47. package/src/parse-cjs.js +1 -1
  48. package/src/parse-mjs.js +2 -2
  49. package/src/policy.d.ts.map +1 -1
  50. package/src/policy.js +4 -7
  51. package/src/search.d.ts +6 -12
  52. package/src/search.d.ts.map +1 -1
  53. package/src/search.js +29 -12
  54. package/src/types/compartment-map-schema.d.ts +5 -0
  55. package/src/types/compartment-map-schema.d.ts.map +1 -1
  56. package/src/types/compartment-map-schema.ts +5 -0
  57. package/src/types/external.d.ts +112 -8
  58. package/src/types/external.d.ts.map +1 -1
  59. package/src/types/external.ts +127 -8
  60. package/src/types/internal.d.ts +85 -13
  61. package/src/types/internal.d.ts.map +1 -1
  62. package/src/types/internal.ts +106 -13
  63. package/src/types/node-modules.d.ts +79 -0
  64. package/src/types/node-modules.d.ts.map +1 -0
  65. package/src/types/node-modules.ts +89 -0
  66. package/src/types/node-powers.d.ts +4 -4
  67. package/src/types/node-powers.d.ts.map +1 -1
  68. package/src/types/node-powers.ts +4 -4
  69. package/src/types/powers.d.ts +2 -2
  70. package/src/types/powers.d.ts.map +1 -1
  71. package/src/types/powers.ts +2 -2
@@ -123,7 +123,7 @@ export const captureFromMap = async (powers, compartmentMap, options = {}) => {
123
123
  searchSuffixes,
124
124
  entryCompartmentName,
125
125
  entryModuleSpecifier,
126
- exitModuleImportHook: consolidatedExitModuleImportHook,
126
+ importHook: consolidatedExitModuleImportHook,
127
127
  sourceMapHook,
128
128
  });
129
129
  // Induce importHook to record all the necessary modules to import the given module specifier.
@@ -6,32 +6,19 @@
6
6
  * @param {MakeImportNowHookMakerOptions} options
7
7
  * @returns {ImportNowHookMaker}
8
8
  */
9
- export function makeImportNowHookMaker(readPowers: ReadNowPowers, baseLocation: string, { sources, compartmentDescriptors, computeSha512, searchSuffixes, sourceMapHook, exitModuleImportNowHook, }: MakeImportNowHookMakerOptions): ImportNowHookMaker;
9
+ export function makeImportNowHookMaker(readPowers: ReadNowPowers, baseLocation: string, { sources, compartmentDescriptors, computeSha512, searchSuffixes, archiveOnly, sourceMapHook, importNowHook: exitModuleImportNowHook, }: MakeImportNowHookMakerOptions): ImportNowHookMaker;
10
10
  export function exitModuleImportHookMaker({ modules, exitModuleImportHook, entryCompartmentName, }: {
11
11
  modules?: Record<string, any> | undefined;
12
12
  exitModuleImportHook?: ExitModuleImportHook | undefined;
13
13
  entryCompartmentName: string;
14
14
  }): ExitModuleImportHook | undefined;
15
- export function makeImportHookMaker(readPowers: ReadFn | ReadPowers, baseLocation: string, { sources, compartmentDescriptors, archiveOnly, computeSha512, searchSuffixes, sourceMapHook, entryCompartmentName, entryModuleSpecifier, exitModuleImportHook, }: {
16
- sources?: Sources | undefined;
17
- compartmentDescriptors?: Record<string, CompartmentDescriptor> | undefined;
18
- archiveOnly?: boolean | undefined;
19
- computeSha512?: HashFn | undefined;
20
- searchSuffixes?: string[] | undefined;
21
- entryCompartmentName: string;
22
- entryModuleSpecifier: string;
23
- exitModuleImportHook?: ExitModuleImportHook | undefined;
24
- sourceMapHook?: SourceMapHook | undefined;
25
- }): ImportHookMaker;
15
+ export function makeImportHookMaker(readPowers: ReadFn | ReadPowers, baseLocation: string, { sources, compartmentDescriptors, archiveOnly, computeSha512, searchSuffixes, sourceMapHook, entryCompartmentName, entryModuleSpecifier, importHook: exitModuleImportHook, }: MakeImportHookMakerOptions): ImportHookMaker;
26
16
  import type { ReadNowPowers } from './types.js';
27
17
  import type { MakeImportNowHookMakerOptions } from './types.js';
28
18
  import type { ImportNowHookMaker } from './types.js';
29
19
  import type { ExitModuleImportHook } from './types.js';
30
20
  import type { ReadFn } from './types.js';
31
21
  import type { ReadPowers } from './types.js';
32
- import type { Sources } from './types.js';
33
- import type { CompartmentDescriptor } from './types.js';
34
- import type { HashFn } from './types.js';
35
- import type { SourceMapHook } from './types.js';
22
+ import type { MakeImportHookMakerOptions } from './types.js';
36
23
  import type { ImportHookMaker } from './types.js';
37
24
  //# sourceMappingURL=import-hook.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"import-hook.d.ts","sourceRoot":"","sources":["import-hook.js"],"names":[],"mappings":"AA2lBA;;;;;;;GAOG;AACH,mDALW,aAAa,gBACb,MAAM,+GACN,6BAA6B,GAC3B,kBAAkB,CAuJ9B;AA5jBM,oGALJ;IAAqC,OAAO;IACN,oBAAoB;IACnC,oBAAoB,EAAnC,MAAM;CACd,GAAU,oBAAoB,GAAC,SAAS,CA8B1C;AA4MM,gDApBI,MAAM,GAAC,UAAU,gBACjB,MAAM,qKAEd;IAA0B,OAAO;IACuB,sBAAsB;IACpD,WAAW;IACZ,aAAa;IACN,cAAc;IAOtB,oBAAoB,EAApC,MAAM;IACU,oBAAoB,EAApC,MAAM;IACyB,oBAAoB;IAC3B,aAAa;CAC7C,GAAU,eAAe,CAuL3B;mCAtjBS,YAAY;mDAAZ,YAAY;wCAAZ,YAAY;0CAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;6BAAZ,YAAY;2CAAZ,YAAY;4BAAZ,YAAY;mCAAZ,YAAY;qCAAZ,YAAY"}
1
+ {"version":3,"file":"import-hook.d.ts","sourceRoot":"","sources":["import-hook.js"],"names":[],"mappings":"AAklBA;;;;;;;GAOG;AACH,mDALW,aAAa,gBACb,MAAM,2IACN,6BAA6B,GAC3B,kBAAkB,CAyJ9B;AApjBM,oGALJ;IAAqC,OAAO;IACN,oBAAoB;IACnC,oBAAoB,EAAnC,MAAM;CACd,GAAU,oBAAoB,GAAC,SAAS,CA8B1C;AAiMM,gDALI,MAAM,GAAC,UAAU,gBACjB,MAAM,iLACN,0BAA0B,GACxB,eAAe,CAwL3B;mCA5iBS,YAAY;mDAAZ,YAAY;wCAAZ,YAAY;0CAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;gDAAZ,YAAY;qCAAZ,YAAY"}
@@ -25,6 +25,7 @@
25
25
  * HashFn,
26
26
  * ImportHookMaker,
27
27
  * ImportNowHookMaker,
28
+ * MakeImportHookMakerOptions,
28
29
  * MakeImportNowHookMakerOptions,
29
30
  * ModuleDescriptor,
30
31
  * ParseResult,
@@ -267,11 +268,13 @@ function* chooseModuleDescriptor(
267
268
  packageLocation,
268
269
  packageSources,
269
270
  readPowers,
271
+ archiveOnly,
270
272
  sourceMapHook,
271
273
  strictlyRequiredForCompartment,
272
274
  },
273
275
  { maybeRead, parse, shouldDeferError = () => false },
274
276
  ) {
277
+ const { sourceDirname } = compartmentDescriptor;
275
278
  for (const candidateSpecifier of candidates) {
276
279
  const candidateModuleDescriptor = moduleDescriptors[candidateSpecifier];
277
280
  if (candidateModuleDescriptor !== undefined) {
@@ -327,6 +330,7 @@ function* chooseModuleDescriptor(
327
330
  packageLocation,
328
331
  {
329
332
  readPowers,
333
+ archiveOnly,
330
334
  sourceMapHook:
331
335
  sourceMapHook &&
332
336
  (nextSourceMapObject => {
@@ -378,6 +382,7 @@ function* chooseModuleDescriptor(
378
382
  packageSources[candidateSpecifier] = {
379
383
  location: packageRelativeLocation,
380
384
  sourceLocation: moduleLocation,
385
+ sourceDirname,
381
386
  parser,
382
387
  bytes: transformedBytes,
383
388
  record: concreteRecord,
@@ -400,22 +405,7 @@ function* chooseModuleDescriptor(
400
405
  /**
401
406
  * @param {ReadFn|ReadPowers} readPowers
402
407
  * @param {string} baseLocation
403
- * @param {object} options
404
- * @param {Sources} [options.sources]
405
- * @param {Record<string, CompartmentDescriptor>} [options.compartmentDescriptors]
406
- * @param {boolean} [options.archiveOnly]
407
- * @param {HashFn} [options.computeSha512]
408
- * @param {Array<string>} [options.searchSuffixes] - Suffixes to search if the
409
- * unmodified specifier is not found.
410
- * Pass [] to emulate Node.js' strict behavior.
411
- * The default handles Node.js' CommonJS behavior.
412
- * Unlike Node.js, the Compartment Mapper lifts CommonJS up, more like a
413
- * bundler, and does not attempt to vary the behavior of resolution depending
414
- * on the language of the importing module.
415
- * @param {string} options.entryCompartmentName
416
- * @param {string} options.entryModuleSpecifier
417
- * @param {ExitModuleImportHook} [options.exitModuleImportHook]
418
- * @param {SourceMapHook} [options.sourceMapHook]
408
+ * @param {MakeImportHookMakerOptions} options
419
409
  * @returns {ImportHookMaker}
420
410
  */
421
411
  export const makeImportHookMaker = (
@@ -430,7 +420,7 @@ export const makeImportHookMaker = (
430
420
  sourceMapHook = undefined,
431
421
  entryCompartmentName,
432
422
  entryModuleSpecifier,
433
- exitModuleImportHook = undefined,
423
+ importHook: exitModuleImportHook = undefined,
434
424
  },
435
425
  ) => {
436
426
  // Set of specifiers for modules (scoped to compartment) whose parser is not
@@ -575,6 +565,7 @@ export const makeImportHookMaker = (
575
565
  packageLocation,
576
566
  packageSources,
577
567
  readPowers,
568
+ archiveOnly,
578
569
  sourceMapHook,
579
570
  strictlyRequiredForCompartment,
580
571
  },
@@ -617,8 +608,9 @@ export function makeImportNowHookMaker(
617
608
  compartmentDescriptors = create(null),
618
609
  computeSha512 = undefined,
619
610
  searchSuffixes = nodejsConventionSearchSuffixes,
611
+ archiveOnly = false,
620
612
  sourceMapHook = undefined,
621
- exitModuleImportNowHook,
613
+ importNowHook: exitModuleImportNowHook = undefined,
622
614
  },
623
615
  ) {
624
616
  // Set of specifiers for modules (scoped to compartment) whose parser is not
@@ -720,6 +712,7 @@ export function makeImportNowHookMaker(
720
712
  packageLocation,
721
713
  packageSources,
722
714
  readPowers,
715
+ archiveOnly,
723
716
  sourceMapHook,
724
717
  strictlyRequiredForCompartment,
725
718
  },
@@ -1 +1 @@
1
- {"version":3,"file":"import-lite.d.ts","sourceRoot":"","sources":["import-lite.js"],"names":[],"mappings":";;;;;;;AAuEG,wCACQ,aAAa,kBACb,wBAAwB,iDAEtB,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;AAGE,wCACQ,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,WAAW,CAAC,CAChC;AA0JM,0CANI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,gDAEtB,OAAO,CAAC,UAAU,CAAC,CAU/B;mCAtNS,YAAY;8CAAZ,YAAY;+CAAZ,YAAY;iCAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;2CAAZ,YAAY;gCAAZ,YAAY"}
1
+ {"version":3,"file":"import-lite.d.ts","sourceRoot":"","sources":["import-lite.js"],"names":[],"mappings":";;;;;;;AAuEG,wCACQ,aAAa,kBACb,wBAAwB,iDAEtB,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;AAGE,wCACQ,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,WAAW,CAAC,CAChC;AA4JM,0CANI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,gDAEtB,OAAO,CAAC,UAAU,CAAC,CAU/B;mCAxNS,YAAY;8CAAZ,YAAY;+CAAZ,YAAY;iCAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;2CAAZ,YAAY;gCAAZ,YAAY"}
@@ -169,7 +169,7 @@ export const loadFromMap = async (readPowers, compartmentMap, options = {}) => {
169
169
  archiveOnly: false,
170
170
  entryCompartmentName,
171
171
  entryModuleSpecifier,
172
- exitModuleImportHook: compartmentExitModuleImportHook,
172
+ importHook: compartmentExitModuleImportHook,
173
173
  },
174
174
  );
175
175
 
@@ -188,9 +188,11 @@ export const loadFromMap = async (readPowers, compartmentMap, options = {}) => {
188
188
  /** @type {ReadNowPowers} */ (readPowers),
189
189
  entryCompartmentName,
190
190
  {
191
+ entryCompartmentName,
192
+ entryModuleSpecifier,
191
193
  compartmentDescriptors: compartmentMap.compartments,
192
194
  searchSuffixes,
193
- exitModuleImportNowHook,
195
+ importNowHook: exitModuleImportNowHook,
194
196
  },
195
197
  );
196
198
  ({ compartment, pendingJobsPromise } = link(compartmentMap, {
@@ -1,54 +1,11 @@
1
- export function compartmentMapForNodeModules(readPowers: ReadFn | ReadPowers | MaybeReadPowers, packageLocation: string, conditionsOption: Set<string>, packageDescriptor: object, moduleSpecifier: string, options?: CompartmentMapForNodeModulesOptions | undefined): Promise<CompartmentMapDescriptor>;
2
- export function mapNodeModules(readPowers: ReadFn | ReadPowers | MaybeReadPowers, moduleLocation: string, options?: MapNodeModulesOptions | undefined): Promise<CompartmentMapDescriptor>;
3
- /**
4
- * The graph is an intermediate object model that the functions of this module
5
- * build by exploring the `node_modules` tree dropped by tools like npm and
6
- * consumed by tools like Node.js.
7
- * This gets translated finally into a compartment map.
8
- */
9
- export type Graph = Record<string, Node>;
10
- export type Node = {
11
- label: string;
12
- name: string;
13
- path: Array<string>;
14
- logicalPath: Array<string>;
15
- explicitExports: boolean;
16
- internalAliases: Record<string, string>;
17
- externalAliases: Record<string, string>;
18
- /**
19
- * - from module name to
20
- * location in storage.
21
- */
22
- dependencyLocations: Record<string, string>;
23
- /**
24
- * - the parser for
25
- * modules based on their extension.
26
- */
27
- parsers: LanguageForExtension;
28
- /**
29
- * - the parser for specific
30
- * modules.
31
- */
32
- types: Record<string, Language>;
33
- };
34
- export type LanguageOptions = {
35
- commonjsLanguageForExtension: LanguageForExtension;
36
- moduleLanguageForExtension: LanguageForExtension;
37
- workspaceCommonjsLanguageForExtension: LanguageForExtension;
38
- workspaceModuleLanguageForExtension: LanguageForExtension;
39
- languages: Set<string>;
40
- };
41
- export type CommonDependencyDescriptors = Record<string, {
42
- spec: string;
43
- alias: string;
44
- }>;
45
- export type ReadDescriptorFn = (packageLocation: string) => Promise<object>;
1
+ export function basename(location: string): string;
2
+ export function compartmentMapForNodeModules(readPowers: ReadFn | ReadPowers | MaybeReadPowers, packageLocation: string, conditionsOption: Set<string>, packageDescriptor: PackageDescriptor, moduleSpecifier: string, options?: CompartmentMapForNodeModulesOptions | undefined): Promise<CompartmentMapDescriptor>;
3
+ export function mapNodeModules(readPowers: ReadFn | ReadPowers | MaybeReadPowers, moduleLocation: string, { tags, conditions, log, ...otherOptions }?: MapNodeModulesOptions | undefined): Promise<CompartmentMapDescriptor>;
46
4
  import type { ReadFn } from './types.js';
47
5
  import type { ReadPowers } from './types.js';
48
6
  import type { MaybeReadPowers } from './types.js';
7
+ import type { PackageDescriptor } from './types.js';
49
8
  import type { CompartmentMapForNodeModulesOptions } from './types.js';
50
9
  import type { CompartmentMapDescriptor } from './types.js';
51
10
  import type { MapNodeModulesOptions } from './types.js';
52
- import type { LanguageForExtension } from './types.js';
53
- import type { Language } from './types.js';
54
11
  //# sourceMappingURL=node-modules.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-modules.d.ts","sourceRoot":"","sources":["node-modules.js"],"names":[],"mappings":"AAs2BO,yDARI,MAAM,GAAG,UAAU,GAAG,eAAe,mBACrC,MAAM,oBACN,GAAG,CAAC,MAAM,CAAC,qBACX,MAAM,mBACN,MAAM,8DAEJ,OAAO,CAAC,wBAAwB,CAAC,CA+D7C;AAQM,2CALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM,gDAEJ,OAAO,CAAC,wBAAwB,CAAC,CA6B7C;;;;;;;oBA/5BY,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;;WAKnB,MAAM;UACN,MAAM;UACN,KAAK,CAAC,MAAM,CAAC;iBACb,KAAK,CAAC,MAAM,CAAC;qBACb,OAAO;qBACP,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;qBACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;;;yBACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;;;aAEtB,oBAAoB;;;;;WAEpB,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC;;;kCAMxB,oBAAoB;gCACpB,oBAAoB;2CACpB,oBAAoB;yCACpB,oBAAoB;eACpB,GAAG,CAAC,MAAM,CAAC;;0CAIZ,MAAM,CAAC,MAAM,EAAE;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC;iDA+E/C,MAAM,KACJ,OAAO,CAAC,MAAM,CAAC;4BAvHlB,YAAY;gCAAZ,YAAY;qCAAZ,YAAY;yDAAZ,YAAY;8CAAZ,YAAY;2CAAZ,YAAY;0CAAZ,YAAY;8BAAZ,YAAY"}
1
+ {"version":3,"file":"node-modules.d.ts","sourceRoot":"","sources":["node-modules.js"],"names":[],"mappings":"AAiFO,mCAHI,MAAM,GACJ,MAAM,CAYlB;AAuwBM,yDATI,MAAM,GAAG,UAAU,GAAG,eAAe,mBACrC,MAAM,oBACN,GAAG,CAAC,MAAM,CAAC,qBACX,iBAAiB,mBACjB,MAAM,8DAEJ,OAAO,CAAC,wBAAwB,CAAC,CAkE7C;AAaM,2CALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM,mFAEJ,OAAO,CAAC,wBAAwB,CAAC,CA0B7C;4BAz6BS,YAAY;gCAAZ,YAAY;qCAAZ,YAAY;uCAAZ,YAAY;yDAAZ,YAAY;8CAAZ,YAAY;2CAAZ,YAAY"}