@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
@@ -0,0 +1,379 @@
1
+ /**
2
+ * @module External types of the compartment mapper.
3
+ */
4
+
5
+ /* eslint-disable no-use-before-define */
6
+
7
+ import type {
8
+ FinalStaticModuleType,
9
+ StaticModuleType,
10
+ ThirdPartyStaticModuleInterface,
11
+ Transform,
12
+ } from 'ses';
13
+ import type {
14
+ CompartmentMapDescriptor,
15
+ CompartmentDescriptor,
16
+ Language,
17
+ LanguageForExtension,
18
+ } from './compartment-map-schema.js';
19
+ import type { HashFn, ReadFn, ReadPowers } from './powers.js';
20
+
21
+ /**
22
+ * Set of options available in the context of code execution.
23
+ *
24
+ * May be used only as an intersection with other options types.
25
+ */
26
+ export type ExecuteOptions = Partial<{
27
+ globals: object;
28
+ transforms: Array<Transform>;
29
+ __shimTransforms__: Array<Transform>;
30
+ attenuations: Record<string, object>;
31
+ Compartment: typeof Compartment;
32
+ }> &
33
+ ModulesOption &
34
+ ExitModuleImportHookOption;
35
+
36
+ export type ParseArchiveOptions = Partial<{
37
+ expectedSha512: string;
38
+ computeSha512: HashFn;
39
+ computeSourceLocation: ComputeSourceLocationHook;
40
+ computeSourceMapLocation: ComputeSourceMapLocationHook;
41
+ }> &
42
+ ModulesOption &
43
+ CompartmentOption &
44
+ ParserForLanguageOption &
45
+ ExitModuleImportHookOption;
46
+
47
+ export type LoadArchiveOptions = ParseArchiveOptions;
48
+
49
+ export type MapNodeModulesOptions = MapNodeModulesOptionsOmitPolicy &
50
+ PolicyOption;
51
+ type MapNodeModulesOptionsOmitPolicy = Partial<{
52
+ /** @deprecated renamed `conditions` to be consistent with Node.js */
53
+ tags: Set<string>;
54
+ /**
55
+ * Conditions for package `"imports"` and `"exports"`.
56
+ * The `"development"` condition also implies that `devDependencies` of the
57
+ * entry package should be reachable.
58
+ * Common conditions include `"node"`, `"browser"`, `"require"`, `"import"`,
59
+ * and `"default"`.
60
+ * The conditions `"import"`, `"default"`, and `"endo"` need not be
61
+ * specified.
62
+ */
63
+ conditions: Set<string>;
64
+ /**
65
+ * @deprecated add `"development"` to the `conditions` Set option.
66
+ * Including `devDependencies` has been subsumed by implication
67
+ * of having the `"development"` condition.
68
+ */
69
+ dev: boolean;
70
+ /** Dependencies to make reachable from any package */
71
+ commonDependencies: Record<string, string>;
72
+ /** Maps extensions to languages for all packages, like `txt` to `text` */
73
+ languageForExtension: LanguageForExtension;
74
+ /** Maps additional extensions to languages for all type=module packages */
75
+ moduleLanguageForExtension: LanguageForExtension;
76
+ /** Maps additional extensions to languages for all type=commonjs packages (default) */
77
+ commonjsLanguageForExtension: LanguageForExtension;
78
+ /** Maps extensions to languages for packages not under node_modules */
79
+ workspaceLanguageForExtension: LanguageForExtension;
80
+ /**
81
+ * Maps additional extensions to languages for all type=module packages that
82
+ * are not under node_modules
83
+ */
84
+ workspaceModuleLanguageForExtension: LanguageForExtension;
85
+ /**
86
+ * Maps additional extensions to languages for all type=commonjs packages
87
+ * (default)
88
+ */
89
+ workspaceCommonjsLanguageForExtension: LanguageForExtension;
90
+ /**
91
+ * Accounts for languages not present as values in any of the extension to
92
+ * language mappings.
93
+ * For higher level functions like `importLocation`, these are inferred
94
+ * from the `parserForLanguage` option.
95
+ */
96
+ languages: Array<Language>;
97
+ }>;
98
+
99
+ /**
100
+ * @deprecated Use `mapNodeModules()`.
101
+ */
102
+ export type CompartmentMapForNodeModulesOptions = Omit<
103
+ MapNodeModulesOptions,
104
+ 'conditions' | 'tags'
105
+ >;
106
+
107
+ export type CaptureLiteOptions = ImportingOptions &
108
+ LinkingOptions &
109
+ PolicyOption;
110
+
111
+ export type ArchiveLiteOptions = SyncOrAsyncArchiveOptions &
112
+ ModuleTransformsOption &
113
+ ImportingOptions &
114
+ ExitModuleImportHookOption &
115
+ LinkingOptions;
116
+
117
+ export type SyncArchiveLiteOptions = SyncOrAsyncArchiveOptions &
118
+ SyncModuleTransformsOption &
119
+ SyncImportingOptions &
120
+ ExitModuleImportNowHookOption;
121
+
122
+ export type ArchiveOptions = Omit<MapNodeModulesOptions, 'language'> &
123
+ ArchiveLiteOptions;
124
+
125
+ export type SyncArchiveOptions = Omit<MapNodeModulesOptions, 'languages'> &
126
+ SyncArchiveLiteOptions;
127
+
128
+ /**
129
+ * Options for `loadLocation()`
130
+ */
131
+ export type LoadLocationOptions = ArchiveOptions & SyncArchiveOptions;
132
+
133
+ /**
134
+ * Options for `importLocation()` necessary (but not sufficient--see
135
+ * `ReadNowPowers`) for dynamic require support
136
+ */
137
+ export type SyncImportLocationOptions = SyncArchiveOptions & ExecuteOptions;
138
+
139
+ export type ImportLocationOptions = ArchiveOptions & ExecuteOptions;
140
+
141
+ // ////////////////////////////////////////////////////////////////////////////////
142
+ // Single Options
143
+
144
+ export type SearchSuffixesOption = {
145
+ /**
146
+ * Suffixes to search if the unmodified specifier is not found. Pass `[]` to
147
+ * emulate Node.js' strict behavior. The default handles Node.js' CommonJS
148
+ * behavior.
149
+ * Unlike Node.js, the Compartment Mapper lifts CommonJS up, more like a
150
+ * bundler, and does not attempt to vary the behavior of resolution depending
151
+ * on the language of the importing module.
152
+ */
153
+ searchSuffixes?: string[];
154
+ };
155
+
156
+ export type SourceMapHookOption = {
157
+ sourceMapHook?: SourceMapHook;
158
+ };
159
+
160
+ export type ModulesOption = {
161
+ modules?: Record<string, any>;
162
+ };
163
+
164
+ export type ExitModuleImportHookOption = {
165
+ importHook?: ExitModuleImportHook;
166
+ };
167
+
168
+ export type ExitModuleImportNowHookOption = {
169
+ importNowHook?: ExitModuleImportNowHook;
170
+ };
171
+
172
+ export type ParserForLanguageOption = {
173
+ parserForLanguage?: ParserForLanguage;
174
+ };
175
+
176
+ export type CompartmentOption = {
177
+ Compartment?: typeof Compartment;
178
+ };
179
+
180
+ export type ModuleTransformsOption = {
181
+ moduleTransforms?: ModuleTransforms;
182
+ };
183
+
184
+ export type SyncModuleTransformsOption = {
185
+ syncModuleTransforms?: SyncModuleTransforms;
186
+ };
187
+
188
+ export type PolicyOption = {
189
+ policy?: any;
190
+ };
191
+
192
+ export type LanguageForExtensionOption = {
193
+ languageForExtension?: LanguageForExtension;
194
+ };
195
+
196
+ // ////////////////////////////////////////////////////////////////////////////////
197
+ // Common option groups:
198
+
199
+ export type SyncOrAsyncArchiveOptions = Partial<{
200
+ captureSourceLocation: CaptureSourceLocationHook;
201
+ }> &
202
+ ParserForLanguageOption &
203
+ CompartmentOption &
204
+ PolicyOption;
205
+
206
+ type SyncOrAsyncImportingOptions = SearchSuffixesOption & SourceMapHookOption;
207
+
208
+ type ImportingOptions = ModulesOption &
209
+ SyncOrAsyncImportingOptions &
210
+ ExitModuleImportHookOption;
211
+
212
+ type SyncImportingOptions = ModulesOption &
213
+ SyncOrAsyncImportingOptions &
214
+ ExitModuleImportNowHookOption;
215
+
216
+ type LinkingOptions = ParserForLanguageOption &
217
+ CompartmentOption &
218
+ SyncModuleTransformsOption &
219
+ ModuleTransformsOption;
220
+
221
+ // ////////////////////////////////////////////////////////////////////////////////
222
+
223
+ /**
224
+ * The result of `captureFromMap`.
225
+ */
226
+ export type CaptureResult = {
227
+ captureCompartmentMap: CompartmentMapDescriptor;
228
+ captureSources: Sources;
229
+ compartmentRenames: Record<string, string>;
230
+ };
231
+
232
+ /**
233
+ * The compartment mapper can capture the Sources for all loaded modules
234
+ * for bundling, archiving, or analysis.
235
+ */
236
+ export type Sources = Record<string, CompartmentSources>;
237
+ export type CompartmentSources = Record<string, ModuleSource>;
238
+
239
+ // TODO unionize:
240
+ export type ModuleSource = Partial<{
241
+ /** module loading error deferred to later stage */
242
+ deferredError: string;
243
+ /** package-relative location */
244
+ location: string;
245
+ /** fully qualified location */
246
+ sourceLocation: string;
247
+ bytes: Uint8Array;
248
+ /** in lowercase base-16 (hexadecimal) */
249
+ sha512: string;
250
+ parser: Language;
251
+ /** indicates that this is a reference that exits the mapped compartments */
252
+ exit: string;
253
+ /** module for the module */
254
+ record: StaticModuleType;
255
+ }>;
256
+
257
+ export type SourceMapHook = (
258
+ sourceMap: string,
259
+ details: SourceMapHookDetails,
260
+ ) => void;
261
+ export type SourceMapHookDetails = {
262
+ compartment: string;
263
+ module: string;
264
+ location: string;
265
+ sha512: string;
266
+ };
267
+
268
+ export type ModuleTransforms = Record<string, ModuleTransform>;
269
+
270
+ export type SyncModuleTransforms = Record<string, SyncModuleTransform>;
271
+
272
+ export type ModuleTransform = (
273
+ ...args: ModuleTransformArguments
274
+ ) => Promise<ModuleTransformResult>;
275
+ export type SyncModuleTransform = (
276
+ ...args: ModuleTransformArguments
277
+ ) => ModuleTransformResult;
278
+
279
+ type ModuleTransformArguments = [
280
+ bytes: Uint8Array,
281
+ specifier: string,
282
+ moduleLocation: string,
283
+ packageLocation: string,
284
+ params: {
285
+ sourceMap?: string;
286
+ },
287
+ ];
288
+
289
+ type ModuleTransformResult = {
290
+ bytes: Uint8Array;
291
+ parser: Language;
292
+ sourceMap?: string;
293
+ };
294
+
295
+ export type ExitModuleImportHook = (
296
+ specifier: string,
297
+ packageLocation: string,
298
+ ) => Promise<ThirdPartyStaticModuleInterface | undefined>;
299
+
300
+ export type ExitModuleImportNowHook = (
301
+ specifier: string,
302
+ packageLocation: string,
303
+ ) => ThirdPartyStaticModuleInterface | undefined;
304
+
305
+ export type ComputeSourceLocationHook = (
306
+ compartmentName: string,
307
+ moduleSpecifier: string,
308
+ ) => string | undefined;
309
+
310
+ /**
311
+ * A hook for archiving that allows the caller to create a side-table or
312
+ * out-of-band reference for where the archive's sources originated,
313
+ * intended to assist debuggers.
314
+ * When making and importing an archive locally, `import-archive.js` can inject
315
+ * the original source location for compartment name and module specifier chosen
316
+ * by `archive.js.
317
+ */
318
+ export type CaptureSourceLocationHook = (
319
+ compartmentName: string,
320
+ moduleSpecifier: string,
321
+ sourceLocation: string,
322
+ ) => void;
323
+
324
+ export type ComputeSourceMapLocationDetails = {
325
+ compartment: string;
326
+ module: string;
327
+ location: string;
328
+ sha512: string;
329
+ };
330
+
331
+ export type ComputeSourceMapLocationHook = (
332
+ details: ComputeSourceMapLocationDetails,
333
+ ) => string;
334
+
335
+ export type ParserImplementation = {
336
+ /**
337
+ * Whether a heuristic is used by parser to detect imports.
338
+ * CommonJS uses a lexer to heuristically discover static require calls.
339
+ */
340
+ heuristicImports: boolean;
341
+ parse: ParseFn;
342
+ synchronous: boolean;
343
+ };
344
+
345
+ type ParseArguments = [
346
+ bytes: Uint8Array,
347
+ specifier: string,
348
+ moduleLocation: string,
349
+ packageLocation: string,
350
+ options?: Partial<{
351
+ sourceMap: string;
352
+ sourceMapHook: SourceMapHook;
353
+ sourceMapUrl: string;
354
+ readPowers: ReadFn | ReadPowers;
355
+ compartmentDescriptor: CompartmentDescriptor;
356
+ }>,
357
+ ];
358
+
359
+ /**
360
+ * Result of a {@link ParseFn} or {@link AsyncParseFn}
361
+ */
362
+ export type ParseResult = {
363
+ bytes: Uint8Array;
364
+ parser: Language;
365
+ record: FinalStaticModuleType;
366
+ sourceMap?: string;
367
+ };
368
+
369
+ export type AsyncParseFn = (...args: ParseArguments) => Promise<ParseResult>;
370
+
371
+ export type ParseFn = { isSyncParser?: true } & ((
372
+ ...args: ParseArguments
373
+ ) => ParseResult);
374
+
375
+ /**
376
+ * Mapping of `Language` to {@link ParserImplementation
377
+ * ParserImplementations}
378
+ */
379
+ export type ParserForLanguage = Record<Language | string, ParserImplementation>;
@@ -0,0 +1,161 @@
1
+ /**
2
+ * @module Internal types of the compartment mapper that need not be visible to
3
+ * consumers.
4
+ */
5
+ import type { ImportHook, ImportNowHook } from 'ses';
6
+ import type { CompartmentDescriptor, Language, LanguageForExtension, LanguageForModuleSpecifier, ModuleDescriptor } from './compartment-map-schema.js';
7
+ import type { HashFn, MaybeReadFn, MaybeReadNowFn, ReadFn, ReadPowers } from './powers.js';
8
+ import type { DeferredAttenuatorsProvider } from './policy.js';
9
+ import type { AsyncParseFn, CompartmentSources, ExecuteOptions, ExitModuleImportNowHook, ModuleTransforms, ParseFn, ParserForLanguage, SearchSuffixesOption, SourceMapHook, SourceMapHookOption, Sources, SyncModuleTransforms } from './external.js';
10
+ export type LinkOptions = {
11
+ resolve?: ResolveHook;
12
+ makeImportHook: ImportHookMaker;
13
+ makeImportNowHook?: ImportNowHookMaker;
14
+ parserForLanguage?: ParserForLanguage;
15
+ moduleTransforms?: ModuleTransforms;
16
+ syncModuleTransforms?: SyncModuleTransforms;
17
+ archiveOnly?: boolean;
18
+ } & ExecuteOptions;
19
+ export type LinkResult = {
20
+ compartment: Compartment;
21
+ compartments: Record<string, Compartment>;
22
+ attenuatorsCompartment: Compartment;
23
+ pendingJobsPromise: Promise<void>;
24
+ };
25
+ export type ResolveHook = (importSpecifier: string, referrerSpecifier: string) => string;
26
+ export type ShouldDeferError = (language: Language | undefined) => boolean;
27
+ export type MakeImportNowHookMakerOptions = Partial<{
28
+ sources: Sources;
29
+ compartmentDescriptors: Record<string, CompartmentDescriptor>;
30
+ computeSha512: HashFn;
31
+ exitModuleImportNowHook: ExitModuleImportNowHook;
32
+ }> & SearchSuffixesOption & SourceMapHookOption;
33
+ export type ImportHookMaker = (params: {
34
+ packageLocation: string;
35
+ packageName: string;
36
+ attenuators: DeferredAttenuatorsProvider;
37
+ parse: ParseFn | AsyncParseFn;
38
+ shouldDeferError: ShouldDeferError;
39
+ compartments: Record<string, Compartment>;
40
+ }) => ImportHook;
41
+ export type ImportNowHookMaker = (params: {
42
+ packageLocation: string;
43
+ packageName: string;
44
+ parse: ParseFn | AsyncParseFn;
45
+ compartments: Record<string, Compartment>;
46
+ attenuators?: never;
47
+ shouldDeferError?: never;
48
+ }) => ImportNowHook;
49
+ /**
50
+ * The value returned by `makeMapParsers()`
51
+ */
52
+ export type MapParsersFn<ParseT = AsyncParseFn | ParseFn> = (
53
+ /** Mapping from file extension to Language (like `js` to `mjs`). */
54
+ languageForExtension: LanguageForExtension,
55
+ /** Mapping from module specifier to Language. */
56
+ languageForModuleSpecifier: LanguageForModuleSpecifier) => ParseT;
57
+ /**
58
+ * As used in `import-hook.js`
59
+ */
60
+ export type ChooseModuleDescriptorParams = {
61
+ /** Module specifiers with each search suffix appended */
62
+ candidates: string[];
63
+ moduleSpecifier: string;
64
+ packageLocation: string;
65
+ /** Compartment descriptor from the compartment map */
66
+ compartmentDescriptor: CompartmentDescriptor;
67
+ /** All compartment descriptors from the compartment map */
68
+ compartmentDescriptors: Record<string, CompartmentDescriptor>;
69
+ /** All module descriptors in same compartment */
70
+ moduleDescriptors: Record<string, ModuleDescriptor>;
71
+ /** All compartments */
72
+ compartments: Record<string, Compartment>;
73
+ packageSources: CompartmentSources;
74
+ /** Function to compute SHA-512 hash */
75
+ computeSha512?: HashFn;
76
+ readPowers: ReadPowers | ReadFn;
77
+ sourceMapHook?: SourceMapHook;
78
+ /**
79
+ * Function returning a set of module names (scoped to the compartment) whose
80
+ * parser is not using heuristics to determine imports.
81
+ */
82
+ strictlyRequiredForCompartment: (compartmentName: string) => Set<string>;
83
+ };
84
+ type SyncChooseModuleDescriptorOperators = {
85
+ /**
86
+ * A function that reads a file, returning its binary contents _or_
87
+ * `undefined` if the file is not found
88
+ */
89
+ maybeRead: MaybeReadNowFn;
90
+ /**
91
+ * A function that parses the (defined) binary contents from `maybeRad` into
92
+ * a `ParseResult`
93
+ */
94
+ parse: ParseFn;
95
+ /** Should be omitted */
96
+ shouldDeferError?: never;
97
+ };
98
+ /**
99
+ * Operators for `chooseModuleDescriptor` representing asynchronous operation.
100
+ */
101
+ export type AsyncChooseModuleDescriptorOperators = {
102
+ /**
103
+ * A function that reads a file, resolving with its binary contents _or_
104
+ * `undefined` if the file is not found
105
+ */
106
+ maybeRead: MaybeReadFn;
107
+ /**
108
+ * A function that parses the (defined) binary contents from `maybeRead` into
109
+ * a `ParseResult`
110
+ */
111
+ parse: AsyncParseFn | ParseFn;
112
+ /**
113
+ * A function that returns `true` if the language returned by `parse` should
114
+ * defer errors.
115
+ */
116
+ shouldDeferError: (language: Language) => boolean;
117
+ };
118
+ /**
119
+ * Either synchronous or asynchronous operators for `chooseModuleDescriptor`.
120
+ */
121
+ export type ChooseModuleDescriptorOperators = AsyncChooseModuleDescriptorOperators | SyncChooseModuleDescriptorOperators;
122
+ /**
123
+ * The agglomeration of things that the `chooseModuleDescriptor` generator can
124
+ * yield.
125
+ *
126
+ * The generator does not necessarily yield _all_ of these; it depends on
127
+ * whether the operators are {@link AsyncChooseModuleDescriptorOperators} or
128
+ * {@link SyncChooseModuleDescriptorOperators}.
129
+ */
130
+ export type ChooseModuleDescriptorYieldables = ReturnType<ChooseModuleDescriptorOperators['maybeRead']> | ReturnType<ChooseModuleDescriptorOperators['parse']>;
131
+ /**
132
+ * Parameters for `findRedirect()`.
133
+ */
134
+ export type FindRedirectParams = {
135
+ compartmentDescriptor: CompartmentDescriptor;
136
+ compartmentDescriptors: Record<string, CompartmentDescriptor>;
137
+ compartments: Record<string, Compartment>;
138
+ absoluteModuleSpecifier: string;
139
+ /** Location of the compartment descriptor's package. */
140
+ packageLocation: string;
141
+ };
142
+ /**
143
+ * Options for `makeMapParsers()`
144
+ */
145
+ export type MakeMapParsersOptions = {
146
+ /** Mapping of language to `ParserImplementation` */
147
+ parserForLanguage: ParserForLanguage;
148
+ /**
149
+ * Async or sync module transforms.
150
+ * If non-empty, synchronous import (specifically dynamic `require` in
151
+ * CommonJS or `compartment.importNow`) are unsupported.
152
+ */
153
+ moduleTransforms?: ModuleTransforms;
154
+ /**
155
+ * Sync module transforms.
156
+ * Always supported.
157
+ */
158
+ syncModuleTransforms?: SyncModuleTransforms;
159
+ };
160
+ export {};
161
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK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