@endo/compartment-mapper 1.3.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +64 -27
  2. package/archive-lite.d.ts +1 -0
  3. package/archive-lite.js +3 -0
  4. package/archive-parsers.d.ts +1 -0
  5. package/archive-parsers.js +3 -0
  6. package/archive.d.ts +1 -0
  7. package/archive.js +3 -0
  8. package/bundle.d.ts +1 -0
  9. package/bundle.js +3 -0
  10. package/capture-lite.d.ts +1 -0
  11. package/capture-lite.js +3 -0
  12. package/import-archive-all-parsers.d.ts +2 -0
  13. package/import-archive-all-parsers.d.ts.map +1 -0
  14. package/import-archive-all-parsers.js +1 -0
  15. package/import-archive-lite.d.ts +1 -0
  16. package/import-archive-lite.js +3 -0
  17. package/import-archive-parsers.d.ts +1 -0
  18. package/import-archive-parsers.js +3 -0
  19. package/import-archive.d.ts +1 -0
  20. package/import-archive.js +3 -0
  21. package/import-lite.d.ts +1 -0
  22. package/import-lite.js +3 -0
  23. package/import-parsers.d.ts +1 -0
  24. package/import-parsers.js +3 -0
  25. package/import.d.ts +1 -0
  26. package/import.js +3 -0
  27. package/index.d.ts +1 -0
  28. package/index.js +3 -1
  29. package/node-modules.d.ts +1 -0
  30. package/node-modules.js +3 -0
  31. package/node-powers.d.ts +1 -0
  32. package/node-powers.js +3 -0
  33. package/package.json +16 -15
  34. package/src/archive-lite.d.ts +8 -10
  35. package/src/archive-lite.d.ts.map +1 -1
  36. package/src/archive-lite.js +35 -209
  37. package/src/archive.d.ts.map +1 -1
  38. package/src/archive.js +140 -28
  39. package/src/bundle.d.ts.map +1 -1
  40. package/src/bundle.js +62 -16
  41. package/src/capture-lite.d.ts +2 -2
  42. package/src/capture-lite.d.ts.map +1 -1
  43. package/src/capture-lite.js +27 -201
  44. package/src/compartment-map.d.ts +2 -1
  45. package/src/compartment-map.d.ts.map +1 -1
  46. package/src/compartment-map.js +11 -3
  47. package/src/digest.d.ts +5 -0
  48. package/src/digest.d.ts.map +1 -0
  49. package/src/digest.js +235 -0
  50. package/src/extension.d.ts.map +1 -1
  51. package/src/extension.js +1 -3
  52. package/src/import-archive-all-parsers.d.ts +11 -0
  53. package/src/import-archive-all-parsers.d.ts.map +1 -0
  54. package/src/import-archive-all-parsers.js +29 -0
  55. package/src/import-archive-lite.d.ts +3 -19
  56. package/src/import-archive-lite.d.ts.map +1 -1
  57. package/src/import-archive-lite.js +47 -57
  58. package/src/import-archive-parsers.d.ts.map +1 -1
  59. package/src/import-archive-parsers.js +1 -0
  60. package/src/import-archive.d.ts +2 -2
  61. package/src/import-archive.d.ts.map +1 -1
  62. package/src/import-archive.js +15 -12
  63. package/src/import-hook.d.ts +2 -1
  64. package/src/import-hook.d.ts.map +1 -1
  65. package/src/import-hook.js +87 -76
  66. package/src/import-lite.d.ts.map +1 -1
  67. package/src/import-lite.js +26 -23
  68. package/src/import.d.ts.map +1 -1
  69. package/src/import.js +49 -23
  70. package/src/infer-exports.d.ts.map +1 -1
  71. package/src/infer-exports.js +2 -3
  72. package/src/json.d.ts.map +1 -1
  73. package/src/json.js +1 -2
  74. package/src/link.d.ts.map +1 -1
  75. package/src/link.js +14 -29
  76. package/src/map-parser.d.ts.map +1 -1
  77. package/src/map-parser.js +25 -17
  78. package/src/node-module-specifier.d.ts.map +1 -1
  79. package/src/node-module-specifier.js +2 -3
  80. package/src/node-modules.d.ts +10 -8
  81. package/src/node-modules.d.ts.map +1 -1
  82. package/src/node-modules.js +212 -97
  83. package/src/node-powers.d.ts +8 -8
  84. package/src/node-powers.d.ts.map +1 -1
  85. package/src/node-powers.js +29 -24
  86. package/src/parse-archive-cjs.d.ts +3 -2
  87. package/src/parse-archive-cjs.d.ts.map +1 -1
  88. package/src/parse-archive-cjs.js +5 -4
  89. package/src/parse-archive-mjs.d.ts +3 -2
  90. package/src/parse-archive-mjs.d.ts.map +1 -1
  91. package/src/parse-archive-mjs.js +7 -5
  92. package/src/parse-bytes.d.ts +3 -2
  93. package/src/parse-bytes.d.ts.map +1 -1
  94. package/src/parse-bytes.js +7 -5
  95. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  96. package/src/parse-cjs-shared-export-wrapper.js +7 -6
  97. package/src/parse-cjs.d.ts +3 -2
  98. package/src/parse-cjs.d.ts.map +1 -1
  99. package/src/parse-cjs.js +14 -5
  100. package/src/parse-json.d.ts.map +1 -1
  101. package/src/parse-json.js +6 -6
  102. package/src/parse-mjs.d.ts +3 -2
  103. package/src/parse-mjs.d.ts.map +1 -1
  104. package/src/parse-mjs.js +3 -3
  105. package/src/parse-pre-cjs.d.ts +3 -2
  106. package/src/parse-pre-cjs.d.ts.map +1 -1
  107. package/src/parse-pre-cjs.js +14 -4
  108. package/src/parse-pre-mjs.d.ts +3 -2
  109. package/src/parse-pre-mjs.d.ts.map +1 -1
  110. package/src/parse-pre-mjs.js +4 -3
  111. package/src/parse-text.d.ts +3 -2
  112. package/src/parse-text.d.ts.map +1 -1
  113. package/src/parse-text.js +6 -5
  114. package/src/policy-format.d.ts +1 -1
  115. package/src/policy-format.d.ts.map +1 -1
  116. package/src/policy-format.js +5 -7
  117. package/src/policy.d.ts.map +1 -1
  118. package/src/policy.js +15 -10
  119. package/src/powers.d.ts.map +1 -1
  120. package/src/powers.js +15 -12
  121. package/src/search.d.ts.map +1 -1
  122. package/src/search.js +10 -7
  123. package/src/types/compartment-map-schema.d.ts +98 -0
  124. package/src/types/compartment-map-schema.d.ts.map +1 -0
  125. package/src/types/compartment-map-schema.ts +116 -0
  126. package/src/types/external.d.ts +299 -0
  127. package/src/types/external.d.ts.map +1 -0
  128. package/src/types/external.ts +428 -0
  129. package/src/types/internal.d.ts +162 -0
  130. package/src/types/internal.d.ts.map +1 -0
  131. package/src/types/internal.ts +217 -0
  132. package/src/types/node-powers.d.ts +46 -0
  133. package/src/types/node-powers.d.ts.map +1 -0
  134. package/src/types/node-powers.ts +52 -0
  135. package/src/types/policy-schema.d.ts +81 -0
  136. package/src/types/policy-schema.d.ts.map +1 -0
  137. package/src/types/policy-schema.ts +131 -0
  138. package/src/types/policy.d.ts +20 -0
  139. package/src/types/policy.d.ts.map +1 -0
  140. package/src/types/policy.ts +42 -0
  141. package/src/types/powers.d.ts +83 -0
  142. package/src/types/powers.d.ts.map +1 -0
  143. package/src/types/powers.ts +120 -0
  144. package/src/types/typescript.d.ts +28 -0
  145. package/src/types/typescript.d.ts.map +1 -0
  146. package/src/types/typescript.ts +41 -0
  147. package/src/types-external.d.ts +14 -0
  148. package/src/types-external.js +2 -0
  149. package/src/types.d.ts +9 -787
  150. package/src/url.d.ts.map +1 -1
  151. package/src/url.js +2 -3
  152. package/src/types.d.ts.map +0 -1
  153. package/src/types.js +0 -995
  154. package/types.d.ts +0 -19
package/src/map-parser.js CHANGED
@@ -1,15 +1,8 @@
1
1
  /**
2
- * Exports {@link makeMapParsers}, which creates a function which matches a
2
+ * @module Exports {@link makeMapParsers}, which creates a function which matches a
3
3
  * module to a parser based on reasons.
4
- *
5
- * @module
6
4
  */
7
5
 
8
- // @ts-check
9
-
10
- import { syncTrampoline, asyncTrampoline } from '@endo/trampoline';
11
- import { parseExtension } from './extension.js';
12
-
13
6
  /**
14
7
  * @import {
15
8
  * LanguageForExtension,
@@ -19,14 +12,20 @@ import { parseExtension } from './extension.js';
19
12
  * ModuleTransform,
20
13
  * ModuleTransforms,
21
14
  * ParseFn,
22
- * ParseFnAsync,
15
+ * AsyncParseFn,
23
16
  * ParseResult,
24
17
  * ParserForLanguage,
25
18
  * SyncModuleTransform,
26
19
  * SyncModuleTransforms
27
20
  * } from './types.js';
21
+ * @import {
22
+ * EReturn
23
+ * } from '@endo/eventual-send';
28
24
  */
29
25
 
26
+ import { syncTrampoline, asyncTrampoline } from '@endo/trampoline';
27
+ import { parseExtension } from './extension.js';
28
+
30
29
  const { entries, fromEntries, keys, hasOwnProperty, values } = Object;
31
30
  const { apply } = Reflect;
32
31
  // q, as in quote, for strings in error messages.
@@ -64,7 +63,7 @@ const extensionImpliesLanguage = extension => extension !== 'js';
64
63
  * @param {ParserForLanguage} parserForLanguage
65
64
  * @param {ModuleTransforms} moduleTransforms
66
65
  * @param {SyncModuleTransforms} syncModuleTransforms
67
- * @returns {ParseFnAsync|ParseFn}
66
+ * @returns {AsyncParseFn|ParseFn}
68
67
  */
69
68
  const makeExtensionParser = (
70
69
  preferSynchronous,
@@ -78,14 +77,15 @@ const makeExtensionParser = (
78
77
  let transforms;
79
78
 
80
79
  /**
81
- * Function returning a generator which executes a parser for a module in either sync or async context.
80
+ * Function returning a generator which executes a parser for a module in
81
+ * either sync or async context.
82
82
  *
83
83
  * @param {Uint8Array} bytes
84
84
  * @param {string} specifier
85
85
  * @param {string} location
86
86
  * @param {string} packageLocation
87
87
  * @param {*} options
88
- * @returns {Generator<ReturnType<ModuleTransform>|ReturnType<SyncModuleTransform>, ParseResult, Awaited<ReturnType<ModuleTransform>|ReturnType<SyncModuleTransform>>>}
88
+ * @returns {Generator<ReturnType<ModuleTransform>|ReturnType<SyncModuleTransform>, ParseResult, EReturn<ModuleTransform|SyncModuleTransform>>}
89
89
  */
90
90
  function* getParserGenerator(
91
91
  bytes,
@@ -104,6 +104,14 @@ const makeExtensionParser = (
104
104
  ) {
105
105
  language = languageForModuleSpecifier[specifier];
106
106
  } else {
107
+ // We should revisit this design decision:
108
+ // Defaulting the language to the extension conflates those namespaces.
109
+ // So, a transform keyed by extension can be used to coerce a language
110
+ // (e.g., .mts to mjs) as a shorthand for configuring a parser for that
111
+ // extension that pre-processes the file before handing off to the
112
+ // parser.
113
+ // But, this forces us to support the case of using weird language
114
+ // names like pre-mjs-json as valid, unconfigured extensions.
107
115
  language = languageForExtension[extension] || extension;
108
116
  }
109
117
 
@@ -169,7 +177,7 @@ const makeExtensionParser = (
169
177
  syncParser.isSyncParser = true;
170
178
 
171
179
  /**
172
- * @type {ParseFnAsync}
180
+ * @type {AsyncParseFn}
173
181
  */
174
182
  const asyncParser = async (
175
183
  bytes,
@@ -190,7 +198,7 @@ const makeExtensionParser = (
190
198
 
191
199
  // Unfortunately, typescript was not smart enough to figure out the return
192
200
  // type depending on a boolean in arguments, so it has to be
193
- // ParseFnAsync|ParseFn
201
+ // AsyncParseFn|ParseFn
194
202
  if (preferSynchronous) {
195
203
  transforms = syncModuleTransforms;
196
204
  return syncParser;
@@ -233,7 +241,7 @@ const makeExtensionParser = (
233
241
  * @param {ModuleTransforms} [moduleTransforms]
234
242
  * @param {SyncModuleTransforms} [syncModuleTransforms]
235
243
  * @param {false} [preferSynchronous]
236
- * @returns {ParseFnAsync}
244
+ * @returns {AsyncParseFn}
237
245
  */
238
246
 
239
247
  /**
@@ -245,7 +253,7 @@ const makeExtensionParser = (
245
253
  * @param {ModuleTransforms} [moduleTransforms]
246
254
  * @param {SyncModuleTransforms} [syncModuleTransforms]
247
255
  * @param {boolean} [preferSynchronous] If `true`, will create a `ParseFn`
248
- * @returns {ParseFnAsync|ParseFn}
256
+ * @returns {AsyncParseFn|ParseFn}
249
257
  */
250
258
  function mapParsers(
251
259
  languageForExtension,
@@ -300,7 +308,7 @@ export const makeMapParsers = ({
300
308
  * Async `mapParsers()` function; returned when a non-synchronous parser is
301
309
  * present _or_ when `moduleTransforms` is non-empty.
302
310
  *
303
- * @type {MapParsersFn<ParseFnAsync>}
311
+ * @type {MapParsersFn<AsyncParseFn>}
304
312
  */
305
313
  const asyncParseFn = (languageForExtension, languageForModuleSpecifier) =>
306
314
  mapParsers(
@@ -1 +1 @@
1
- {"version":3,"file":"node-module-specifier.d.ts","sourceRoot":"","sources":["node-module-specifier.js"],"names":[],"mappings":"AAyDO,8BAJI,MAAM,YACN,MAAM,GACJ,MAAM,CAiClB;AAeM,2BAJI,MAAM,QACN,MAAM,GACJ,MAAM,CA6BlB;AAaM,iCALI,MAAM,GAEJ,MAAM,CAclB"}
1
+ {"version":3,"file":"node-module-specifier.d.ts","sourceRoot":"","sources":["node-module-specifier.js"],"names":[],"mappings":"AAwDO,8BAJI,MAAM,YACN,MAAM,GACJ,MAAM,CAiClB;AAeM,2BAJI,MAAM,QACN,MAAM,GACJ,MAAM,CA6BlB;AAaM,iCALI,MAAM,GAEJ,MAAM,CAclB"}
@@ -1,10 +1,9 @@
1
- /* Provides functions for interacting with Node.js module specifiers in
1
+ /**
2
+ * @module Provides functions for interacting with Node.js module specifiers in
2
3
  * their canonical form.
3
4
  * This is a kind of path math that is platform-agnostic.
4
5
  */
5
6
 
6
- // @ts-check
7
-
8
7
  // q, as in quote, for error messages.
9
8
  const q = JSON.stringify;
10
9
 
@@ -1,11 +1,5 @@
1
- export function compartmentMapForNodeModules(readPowers: ReadFn | ReadPowers | MaybeReadPowers, packageLocation: string, conditions: Set<string>, packageDescriptor: object, moduleSpecifier: string, options?: CompartmentMapForNodeModulesOptions | undefined): Promise<CompartmentMapDescriptor>;
2
- export function mapNodeModules(readPowers: ReadFn | ReadPowers | MaybeReadPowers, moduleLocation: string, options?: {
3
- tags?: Set<string> | undefined;
4
- conditions?: Set<string> | undefined;
5
- dev?: boolean | undefined;
6
- commonDependencies?: object;
7
- policy?: object;
8
- } | undefined): Promise<CompartmentMapDescriptor>;
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>;
9
3
  /**
10
4
  * The graph is an intermediate object model that the functions of this module
11
5
  * build by exploring the `node_modules` tree dropped by tools like npm and
@@ -37,6 +31,13 @@ export type Node = {
37
31
  */
38
32
  types: Record<string, Language>;
39
33
  };
34
+ export type LanguageOptions = {
35
+ commonjsLanguageForExtension: LanguageForExtension;
36
+ moduleLanguageForExtension: LanguageForExtension;
37
+ workspaceCommonjsLanguageForExtension: LanguageForExtension;
38
+ workspaceModuleLanguageForExtension: LanguageForExtension;
39
+ languages: Set<string>;
40
+ };
40
41
  export type CommonDependencyDescriptors = Record<string, {
41
42
  spec: string;
42
43
  alias: string;
@@ -47,6 +48,7 @@ import type { ReadPowers } from './types.js';
47
48
  import type { MaybeReadPowers } from './types.js';
48
49
  import type { CompartmentMapForNodeModulesOptions } from './types.js';
49
50
  import type { CompartmentMapDescriptor } from './types.js';
51
+ import type { MapNodeModulesOptions } from './types.js';
50
52
  import type { LanguageForExtension } from './types.js';
51
53
  import type { Language } from './types.js';
52
54
  //# sourceMappingURL=node-modules.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-modules.d.ts","sourceRoot":"","sources":["node-modules.js"],"names":[],"mappings":"AAwvBO,yDARI,MAAM,GAAG,UAAU,GAAG,eAAe,mBACrC,MAAM,cACN,GAAG,CAAC,MAAM,CAAC,qBACX,MAAM,mBACN,MAAM,8DAEJ,OAAO,CAAC,wBAAwB,CAAC,CA+C7C;AAaM,2CAVI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM;;;;yBAKN,MAAM;aACN,MAAM;gBACJ,OAAO,CAAC,wBAAwB,CAAC,CAmC7C;;;;;;;oBAjzBY,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;;0CAKzB,MAAM,CAAC,MAAM,EAAE;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC;iDA+E/C,MAAM,KACJ,OAAO,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