@endo/compartment-mapper 1.3.0 → 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.
- package/README.md +50 -27
- package/archive-lite.d.ts +1 -0
- package/archive-lite.js +3 -0
- package/archive-parsers.d.ts +1 -0
- package/archive-parsers.js +3 -0
- package/archive.d.ts +1 -0
- package/archive.js +3 -0
- package/bundle.d.ts +1 -0
- package/bundle.js +3 -0
- package/capture-lite.d.ts +1 -0
- package/capture-lite.js +3 -0
- package/import-archive-lite.d.ts +1 -0
- package/import-archive-lite.js +3 -0
- package/import-archive-parsers.d.ts +1 -0
- package/import-archive-parsers.js +3 -0
- package/import-archive.d.ts +1 -0
- package/import-archive.js +3 -0
- package/import-lite.d.ts +1 -0
- package/import-lite.js +3 -0
- package/import-parsers.d.ts +1 -0
- package/import-parsers.js +3 -0
- package/import.d.ts +1 -0
- package/import.js +3 -0
- package/index.d.ts +1 -0
- package/index.js +3 -1
- package/node-modules.d.ts +1 -0
- package/node-modules.js +3 -0
- package/node-powers.d.ts +1 -0
- package/node-powers.js +3 -0
- package/package.json +10 -14
- package/src/archive-lite.d.ts +6 -6
- package/src/archive-lite.d.ts.map +1 -1
- package/src/archive-lite.js +35 -33
- package/src/archive.d.ts.map +1 -1
- package/src/archive.js +132 -28
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +54 -14
- package/src/capture-lite.d.ts +2 -2
- package/src/capture-lite.d.ts.map +1 -1
- package/src/capture-lite.js +21 -17
- package/src/compartment-map.d.ts +2 -1
- package/src/compartment-map.d.ts.map +1 -1
- package/src/compartment-map.js +11 -5
- package/src/extension.d.ts.map +1 -1
- package/src/extension.js +1 -3
- package/src/import-archive-lite.d.ts +3 -19
- package/src/import-archive-lite.d.ts.map +1 -1
- package/src/import-archive-lite.js +43 -57
- package/src/import-archive-parsers.d.ts.map +1 -1
- package/src/import-archive-parsers.js +1 -0
- package/src/import-archive.d.ts +2 -2
- package/src/import-archive.d.ts.map +1 -1
- package/src/import-archive.js +15 -12
- package/src/import-hook.d.ts +2 -1
- package/src/import-hook.d.ts.map +1 -1
- package/src/import-hook.js +87 -76
- package/src/import-lite.d.ts.map +1 -1
- package/src/import-lite.js +23 -23
- package/src/import.d.ts.map +1 -1
- package/src/import.js +47 -23
- package/src/infer-exports.d.ts.map +1 -1
- package/src/infer-exports.js +2 -3
- package/src/json.d.ts.map +1 -1
- package/src/json.js +1 -2
- package/src/link.d.ts.map +1 -1
- package/src/link.js +12 -29
- package/src/map-parser.d.ts.map +1 -1
- package/src/map-parser.js +21 -16
- package/src/node-module-specifier.d.ts.map +1 -1
- package/src/node-module-specifier.js +2 -3
- package/src/node-modules.d.ts +9 -7
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +176 -87
- package/src/node-powers.d.ts +8 -8
- package/src/node-powers.d.ts.map +1 -1
- package/src/node-powers.js +29 -24
- package/src/parse-archive-cjs.d.ts +3 -2
- package/src/parse-archive-cjs.d.ts.map +1 -1
- package/src/parse-archive-cjs.js +5 -4
- package/src/parse-archive-mjs.d.ts +3 -2
- package/src/parse-archive-mjs.d.ts.map +1 -1
- package/src/parse-archive-mjs.js +7 -5
- package/src/parse-bytes.d.ts +3 -2
- package/src/parse-bytes.d.ts.map +1 -1
- package/src/parse-bytes.js +7 -5
- package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
- package/src/parse-cjs-shared-export-wrapper.js +7 -6
- package/src/parse-cjs.d.ts +3 -2
- package/src/parse-cjs.d.ts.map +1 -1
- package/src/parse-cjs.js +14 -5
- package/src/parse-json.d.ts.map +1 -1
- package/src/parse-json.js +6 -6
- package/src/parse-mjs.d.ts +3 -2
- package/src/parse-mjs.d.ts.map +1 -1
- package/src/parse-mjs.js +3 -3
- package/src/parse-pre-cjs.d.ts +3 -2
- package/src/parse-pre-cjs.d.ts.map +1 -1
- package/src/parse-pre-cjs.js +14 -4
- package/src/parse-pre-mjs.d.ts +3 -2
- package/src/parse-pre-mjs.d.ts.map +1 -1
- package/src/parse-pre-mjs.js +4 -3
- package/src/parse-text.d.ts +3 -2
- package/src/parse-text.d.ts.map +1 -1
- package/src/parse-text.js +6 -5
- package/src/policy-format.d.ts +1 -1
- package/src/policy-format.d.ts.map +1 -1
- package/src/policy-format.js +5 -7
- package/src/policy.d.ts.map +1 -1
- package/src/policy.js +15 -10
- package/src/powers.d.ts.map +1 -1
- package/src/powers.js +15 -12
- package/src/search.d.ts.map +1 -1
- package/src/search.js +10 -7
- package/src/types/compartment-map-schema.d.ts +98 -0
- package/src/types/compartment-map-schema.d.ts.map +1 -0
- package/src/types/compartment-map-schema.ts +116 -0
- package/src/types/external.d.ts +256 -0
- package/src/types/external.d.ts.map +1 -0
- package/src/types/external.ts +379 -0
- package/src/types/internal.d.ts +161 -0
- package/src/types/internal.d.ts.map +1 -0
- package/src/types/internal.ts +216 -0
- package/src/types/node-powers.d.ts +46 -0
- package/src/types/node-powers.d.ts.map +1 -0
- package/src/types/node-powers.ts +52 -0
- package/src/types/policy-schema.d.ts +81 -0
- package/src/types/policy-schema.d.ts.map +1 -0
- package/src/types/policy-schema.ts +131 -0
- package/src/types/policy.d.ts +20 -0
- package/src/types/policy.d.ts.map +1 -0
- package/src/types/policy.ts +42 -0
- package/src/types/powers.d.ts +83 -0
- package/src/types/powers.d.ts.map +1 -0
- package/src/types/powers.ts +120 -0
- package/src/types/typescript.d.ts +28 -0
- package/src/types/typescript.d.ts.map +1 -0
- package/src/types/typescript.ts +41 -0
- package/src/types-external.d.ts +14 -0
- package/src/types-external.js +2 -0
- package/src/types.d.ts +9 -787
- package/src/url.d.ts.map +1 -1
- package/src/url.js +2 -3
- package/src/types.d.ts.map +0 -1
- package/src/types.js +0 -995
- package/types.d.ts +0 -19
package/src/node-modules.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
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
|
|
208
|
+
const defaultCommonjsLanguageForExtension = /** @type {const} */ ({
|
|
202
209
|
js: 'cjs',
|
|
203
|
-
...defaultUncontroversialParsers,
|
|
204
210
|
});
|
|
205
|
-
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 {
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
{
|
|
224
|
-
languages
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
221
|
+
const inferParsers = (descriptor, location, languageOptions) => {
|
|
222
|
+
let { moduleLanguageForExtension, commonjsLanguageForExtension } =
|
|
223
|
+
languageOptions;
|
|
224
|
+
const {
|
|
225
|
+
languages,
|
|
226
|
+
workspaceModuleLanguageForExtension,
|
|
227
|
+
workspaceCommonjsLanguageForExtension,
|
|
228
|
+
} = languageOptions;
|
|
229
|
+
|
|
230
|
+
// Select languageForExtension options based on whether they are physically
|
|
231
|
+
// under node_modules, indicating that they have not been built for npm,
|
|
232
|
+
// so any languages that compile to JavaScript may need additional parsers.
|
|
233
|
+
if (!location.includes('/node_modules/')) {
|
|
234
|
+
moduleLanguageForExtension = workspaceModuleLanguageForExtension;
|
|
235
|
+
commonjsLanguageForExtension = workspaceCommonjsLanguageForExtension;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const {
|
|
239
|
+
type,
|
|
240
|
+
module,
|
|
241
|
+
parsers: packageLanguageForExtension = {},
|
|
242
|
+
} = descriptor;
|
|
243
|
+
|
|
244
|
+
// Validate package-local "parsers"
|
|
245
|
+
if (
|
|
246
|
+
typeof packageLanguageForExtension !== 'object' ||
|
|
247
|
+
packageLanguageForExtension === null
|
|
248
|
+
) {
|
|
249
|
+
throw Error(
|
|
250
|
+
`Cannot interpret parser map ${JSON.stringify(
|
|
251
|
+
packageLanguageForExtension,
|
|
252
|
+
)} of package at ${location}, must be an object mapping file extensions to corresponding languages (for example, mjs for ECMAScript modules, cjs for CommonJS modules, or json for JSON modules`,
|
|
242
253
|
);
|
|
243
|
-
if (invalidLanguages.length > 0) {
|
|
244
|
-
throw Error(
|
|
245
|
-
`Cannot interpret parser map language values ${JSON.stringify(
|
|
246
|
-
invalidLanguages,
|
|
247
|
-
)} of package at ${location}, must be an object mapping file extensions to corresponding languages (mjs for ECMAScript modules, cjs for CommonJS modules, or json for JSON modules`,
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
additionalParsers = { ...uncontroversialParsers, ...parsers };
|
|
251
254
|
}
|
|
255
|
+
const invalidLanguages = values(packageLanguageForExtension).filter(
|
|
256
|
+
language => !languages.has(language),
|
|
257
|
+
);
|
|
258
|
+
if (invalidLanguages.length > 0) {
|
|
259
|
+
throw Error(
|
|
260
|
+
`Cannot interpret parser map language values ${JSON.stringify(
|
|
261
|
+
invalidLanguages,
|
|
262
|
+
)} of package at ${location}, must be an object mapping file extensions to corresponding languages (for example, mjs for ECMAScript modules, cjs for CommonJS modules, or json for JSON modules`,
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
252
266
|
if (type === 'module' || module !== undefined) {
|
|
253
|
-
return { ...
|
|
267
|
+
return { ...moduleLanguageForExtension, ...packageLanguageForExtension };
|
|
254
268
|
}
|
|
255
269
|
if (type === 'commonjs') {
|
|
256
|
-
return { ...
|
|
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 { ...
|
|
277
|
+
return { ...commonjsLanguageForExtension, ...packageLanguageForExtension };
|
|
264
278
|
};
|
|
265
279
|
|
|
266
280
|
/**
|
|
@@ -281,6 +295,7 @@ const inferParsers = (
|
|
|
281
295
|
* @param {Set<string>} conditions
|
|
282
296
|
* @param {boolean | undefined} dev
|
|
283
297
|
* @param {CommonDependencyDescriptors} commonDependencyDescriptors
|
|
298
|
+
* @param {LanguageOptions} languageOptions
|
|
284
299
|
* @param {Map<string, Array<string>>} preferredPackageLogicalPathMap
|
|
285
300
|
* @param {Array<string>} logicalPath
|
|
286
301
|
* @returns {Promise<undefined>}
|
|
@@ -294,6 +309,7 @@ const graphPackage = async (
|
|
|
294
309
|
conditions,
|
|
295
310
|
dev,
|
|
296
311
|
commonDependencyDescriptors,
|
|
312
|
+
languageOptions,
|
|
297
313
|
preferredPackageLogicalPathMap = new Map(),
|
|
298
314
|
logicalPath = [],
|
|
299
315
|
) => {
|
|
@@ -363,6 +379,7 @@ const graphPackage = async (
|
|
|
363
379
|
name,
|
|
364
380
|
conditions,
|
|
365
381
|
preferredPackageLogicalPathMap,
|
|
382
|
+
languageOptions,
|
|
366
383
|
childLogicalPath,
|
|
367
384
|
optional,
|
|
368
385
|
commonDependencyDescriptors,
|
|
@@ -394,6 +411,12 @@ const graphPackage = async (
|
|
|
394
411
|
types,
|
|
395
412
|
);
|
|
396
413
|
|
|
414
|
+
const parsers = inferParsers(
|
|
415
|
+
packageDescriptor,
|
|
416
|
+
packageLocation,
|
|
417
|
+
languageOptions,
|
|
418
|
+
);
|
|
419
|
+
|
|
397
420
|
Object.assign(result, {
|
|
398
421
|
name,
|
|
399
422
|
path: logicalPath,
|
|
@@ -403,7 +426,7 @@ const graphPackage = async (
|
|
|
403
426
|
internalAliases,
|
|
404
427
|
dependencyLocations,
|
|
405
428
|
types,
|
|
406
|
-
parsers
|
|
429
|
+
parsers,
|
|
407
430
|
});
|
|
408
431
|
|
|
409
432
|
await Promise.all(
|
|
@@ -457,6 +480,7 @@ const graphPackage = async (
|
|
|
457
480
|
* @param {string} name - name of the package of interest.
|
|
458
481
|
* @param {Set<string>} conditions
|
|
459
482
|
* @param {Map<string, Array<string>>} preferredPackageLogicalPathMap
|
|
483
|
+
* @param {LanguageOptions} languageOptions
|
|
460
484
|
* @param {Array<string>} [childLogicalPath]
|
|
461
485
|
* @param {boolean} [optional] - whether the dependency is optional
|
|
462
486
|
* @param {object} [commonDependencyDescriptors] - dependencies to be added to all packages
|
|
@@ -470,6 +494,7 @@ const gatherDependency = async (
|
|
|
470
494
|
name,
|
|
471
495
|
conditions,
|
|
472
496
|
preferredPackageLogicalPathMap,
|
|
497
|
+
languageOptions,
|
|
473
498
|
childLogicalPath = [],
|
|
474
499
|
optional = false,
|
|
475
500
|
commonDependencyDescriptors = undefined,
|
|
@@ -506,6 +531,7 @@ const gatherDependency = async (
|
|
|
506
531
|
conditions,
|
|
507
532
|
false,
|
|
508
533
|
commonDependencyDescriptors,
|
|
534
|
+
languageOptions,
|
|
509
535
|
preferredPackageLogicalPathMap,
|
|
510
536
|
childLogicalPath,
|
|
511
537
|
);
|
|
@@ -528,7 +554,8 @@ const gatherDependency = async (
|
|
|
528
554
|
* package.json, which was already read when searching for the package.json.
|
|
529
555
|
* @param {boolean|undefined} dev - whether to use devDependencies from this package (and
|
|
530
556
|
* only this package).
|
|
531
|
-
* @param {Record<string,string>}
|
|
557
|
+
* @param {Record<string,string>} commonDependencies - dependencies to be added to all packages
|
|
558
|
+
* @param {LanguageOptions} languageOptions
|
|
532
559
|
*/
|
|
533
560
|
const graphPackages = async (
|
|
534
561
|
maybeRead,
|
|
@@ -537,7 +564,8 @@ const graphPackages = async (
|
|
|
537
564
|
conditions,
|
|
538
565
|
mainPackageDescriptor,
|
|
539
566
|
dev,
|
|
540
|
-
commonDependencies
|
|
567
|
+
commonDependencies,
|
|
568
|
+
languageOptions,
|
|
541
569
|
) => {
|
|
542
570
|
const memo = create(null);
|
|
543
571
|
/**
|
|
@@ -594,6 +622,7 @@ const graphPackages = async (
|
|
|
594
622
|
conditions,
|
|
595
623
|
dev,
|
|
596
624
|
commonDependencyDescriptors,
|
|
625
|
+
languageOptions,
|
|
597
626
|
);
|
|
598
627
|
return graph;
|
|
599
628
|
};
|
|
@@ -749,6 +778,74 @@ const translateGraph = (
|
|
|
749
778
|
};
|
|
750
779
|
};
|
|
751
780
|
|
|
781
|
+
/**
|
|
782
|
+
* @param {Pick<MapNodeModulesOptions,
|
|
783
|
+
* 'languageForExtension' |
|
|
784
|
+
* 'moduleLanguageForExtension' |
|
|
785
|
+
* 'commonjsLanguageForExtension' |
|
|
786
|
+
* 'workspaceLanguageForExtension' |
|
|
787
|
+
* 'workspaceModuleLanguageForExtension' |
|
|
788
|
+
* 'workspaceCommonjsLanguageForExtension' |
|
|
789
|
+
* 'languages'
|
|
790
|
+
* >} options
|
|
791
|
+
*/
|
|
792
|
+
const makeLanguageOptions = ({
|
|
793
|
+
languageForExtension: additionalLanguageForExtension = {},
|
|
794
|
+
moduleLanguageForExtension: additionalModuleLanguageForExtension = {},
|
|
795
|
+
commonjsLanguageForExtension: additionalCommonjsLanguageForExtension = {},
|
|
796
|
+
workspaceLanguageForExtension: additionalWorkspaceLanguageForExtension = {},
|
|
797
|
+
workspaceModuleLanguageForExtension:
|
|
798
|
+
additionalWorkspaceModuleLanguageForExtension = {},
|
|
799
|
+
workspaceCommonjsLanguageForExtension:
|
|
800
|
+
additionalWorkspaceCommonjsLanguageForExtension = {},
|
|
801
|
+
languages: additionalLanguages = [],
|
|
802
|
+
}) => {
|
|
803
|
+
const commonjsLanguageForExtension = {
|
|
804
|
+
...defaultLanguageForExtension,
|
|
805
|
+
...additionalLanguageForExtension,
|
|
806
|
+
...defaultCommonjsLanguageForExtension,
|
|
807
|
+
...additionalCommonjsLanguageForExtension,
|
|
808
|
+
};
|
|
809
|
+
const moduleLanguageForExtension = {
|
|
810
|
+
...defaultLanguageForExtension,
|
|
811
|
+
...additionalLanguageForExtension,
|
|
812
|
+
...defaultModuleLanguageForExtension,
|
|
813
|
+
...additionalModuleLanguageForExtension,
|
|
814
|
+
};
|
|
815
|
+
const workspaceCommonjsLanguageForExtension = {
|
|
816
|
+
...defaultLanguageForExtension,
|
|
817
|
+
...additionalLanguageForExtension,
|
|
818
|
+
...defaultCommonjsLanguageForExtension,
|
|
819
|
+
...additionalCommonjsLanguageForExtension,
|
|
820
|
+
...additionalWorkspaceLanguageForExtension,
|
|
821
|
+
...additionalWorkspaceCommonjsLanguageForExtension,
|
|
822
|
+
};
|
|
823
|
+
const workspaceModuleLanguageForExtension = {
|
|
824
|
+
...defaultLanguageForExtension,
|
|
825
|
+
...additionalLanguageForExtension,
|
|
826
|
+
...defaultModuleLanguageForExtension,
|
|
827
|
+
...additionalModuleLanguageForExtension,
|
|
828
|
+
...additionalWorkspaceLanguageForExtension,
|
|
829
|
+
...additionalWorkspaceModuleLanguageForExtension,
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
const languages = new Set([
|
|
833
|
+
...Object.values(moduleLanguageForExtension),
|
|
834
|
+
...Object.values(commonjsLanguageForExtension),
|
|
835
|
+
...Object.values(workspaceModuleLanguageForExtension),
|
|
836
|
+
...Object.values(workspaceCommonjsLanguageForExtension),
|
|
837
|
+
...additionalLanguages,
|
|
838
|
+
]);
|
|
839
|
+
|
|
840
|
+
return {
|
|
841
|
+
languages,
|
|
842
|
+
commonjsLanguageForExtension,
|
|
843
|
+
moduleLanguageForExtension,
|
|
844
|
+
workspaceCommonjsLanguageForExtension,
|
|
845
|
+
workspaceModuleLanguageForExtension,
|
|
846
|
+
};
|
|
847
|
+
};
|
|
848
|
+
|
|
752
849
|
/**
|
|
753
850
|
* @param {ReadFn | ReadPowers | MaybeReadPowers} readPowers
|
|
754
851
|
* @param {string} packageLocation
|
|
@@ -766,8 +863,10 @@ export const compartmentMapForNodeModules = async (
|
|
|
766
863
|
moduleSpecifier,
|
|
767
864
|
options = {},
|
|
768
865
|
) => {
|
|
769
|
-
const { dev = undefined, commonDependencies, policy } = options;
|
|
866
|
+
const { dev = undefined, commonDependencies = {}, policy } = options;
|
|
770
867
|
const { maybeRead, canonical } = unpackReadPowers(readPowers);
|
|
868
|
+
const languageOptions = makeLanguageOptions(options);
|
|
869
|
+
|
|
771
870
|
const graph = await graphPackages(
|
|
772
871
|
maybeRead,
|
|
773
872
|
canonical,
|
|
@@ -776,6 +875,7 @@ export const compartmentMapForNodeModules = async (
|
|
|
776
875
|
packageDescriptor,
|
|
777
876
|
dev,
|
|
778
877
|
commonDependencies,
|
|
878
|
+
languageOptions,
|
|
779
879
|
);
|
|
780
880
|
|
|
781
881
|
if (policy) {
|
|
@@ -808,12 +908,7 @@ export const compartmentMapForNodeModules = async (
|
|
|
808
908
|
/**
|
|
809
909
|
* @param {ReadFn | ReadPowers | MaybeReadPowers} readPowers
|
|
810
910
|
* @param {string} moduleLocation
|
|
811
|
-
* @param {
|
|
812
|
-
* @param {Set<string>} [options.tags] deprecated in favor of `conditions`
|
|
813
|
-
* @param {Set<string>} [options.conditions]
|
|
814
|
-
* @param {boolean} [options.dev]
|
|
815
|
-
* @param {object} [options.commonDependencies]
|
|
816
|
-
* @param {object} [options.policy]
|
|
911
|
+
* @param {MapNodeModulesOptions} [options]
|
|
817
912
|
* @returns {Promise<CompartmentMapDescriptor>}
|
|
818
913
|
*/
|
|
819
914
|
export const mapNodeModules = async (
|
|
@@ -821,13 +916,7 @@ export const mapNodeModules = async (
|
|
|
821
916
|
moduleLocation,
|
|
822
917
|
options = {},
|
|
823
918
|
) => {
|
|
824
|
-
const {
|
|
825
|
-
tags = new Set(),
|
|
826
|
-
conditions = tags,
|
|
827
|
-
dev = undefined,
|
|
828
|
-
commonDependencies,
|
|
829
|
-
policy,
|
|
830
|
-
} = options;
|
|
919
|
+
const { tags = new Set(), conditions = tags, ...otherOptions } = options;
|
|
831
920
|
|
|
832
921
|
const {
|
|
833
922
|
packageLocation,
|
|
@@ -847,6 +936,6 @@ export const mapNodeModules = async (
|
|
|
847
936
|
conditions,
|
|
848
937
|
packageDescriptor,
|
|
849
938
|
moduleSpecifier,
|
|
850
|
-
|
|
939
|
+
otherOptions,
|
|
851
940
|
);
|
|
852
941
|
};
|
package/src/node-powers.d.ts
CHANGED
|
@@ -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
|
package/src/node-powers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-powers.d.ts","sourceRoot":"","sources":["node-powers.js"],"names":[],"mappings":"
|
|
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"}
|
package/src/node-powers.js
CHANGED
|
@@ -1,30 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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://')
|
|
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).
|
|
149
|
+
return pathToFileURL(realPath).href;
|
|
145
150
|
}
|
|
146
151
|
} catch {
|
|
147
152
|
return location;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/** @type {
|
|
2
|
-
export const parseArchiveCjs:
|
|
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":"
|
|
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"}
|
package/src/parse-archive-cjs.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides language behavior for analyzing, pre-compiling, and storing
|
|
2
3
|
* CommonJS modules for an archive.
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
|
-
|
|
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 {
|
|
19
|
+
/** @type {ParseFn} */
|
|
19
20
|
export const parseArchiveCjs = (
|
|
20
21
|
bytes,
|
|
21
|
-
|
|
22
|
+
_specifier,
|
|
22
23
|
location,
|
|
23
24
|
_packageLocation,
|
|
24
25
|
) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/** @type {
|
|
2
|
-
export const parseArchiveMjs:
|
|
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":"
|
|
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"}
|
package/src/parse-archive-mjs.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides language behavior for analyzing, pre-compiling, and storing ESM
|
|
2
3
|
* modules for an archive.
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
/** @import {ParseFn} from './types.js' */
|
|
5
7
|
|
|
6
8
|
import { ModuleSource } from '@endo/module-source';
|
|
7
9
|
|
|
8
10
|
const textEncoder = new TextEncoder();
|
|
9
11
|
const textDecoder = new TextDecoder();
|
|
10
12
|
|
|
11
|
-
/** @type {
|
|
13
|
+
/** @type {ParseFn} */
|
|
12
14
|
export const parseArchiveMjs = (
|
|
13
15
|
bytes,
|
|
14
|
-
|
|
16
|
+
_specifier,
|
|
15
17
|
sourceUrl,
|
|
16
|
-
|
|
18
|
+
_packageLocation,
|
|
17
19
|
options = {},
|
|
18
20
|
) => {
|
|
19
21
|
const { sourceMap, sourceMapHook } = options;
|
package/src/parse-bytes.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/** @type {
|
|
2
|
-
export const parseBytes:
|
|
1
|
+
/** @type {ParseFn} */
|
|
2
|
+
export const parseBytes: ParseFn;
|
|
3
3
|
declare const _default: import("./types.js").ParserImplementation;
|
|
4
4
|
export default _default;
|
|
5
|
+
import type { ParseFn } from './types.js';
|
|
5
6
|
//# sourceMappingURL=parse-bytes.d.ts.map
|
package/src/parse-bytes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-bytes.d.ts","sourceRoot":"","sources":["parse-bytes.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-bytes.d.ts","sourceRoot":"","sources":["parse-bytes.js"],"names":[],"mappings":"AAgBA,sBAAsB;AACtB,yBADW,OAAO,CA0BhB;wBAES,OAAO,YAAY,EAAE,oBAAoB;;6BAtCzB,YAAY"}
|
package/src/parse-bytes.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides rudimentary support for treating an arbitrary file as a
|
|
3
|
+
* module that exports the bytes of that file.
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
/** @import {Harden} from 'ses' */
|
|
7
|
+
/** @import {ParseFn} from './types.js' */
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* TypeScript cannot be relied upon to deal with the nuances of Readonly, so we
|
|
9
11
|
* borrow the pass-through type definition of harden here.
|
|
10
12
|
*
|
|
11
|
-
* @type {
|
|
13
|
+
* @type {Harden}
|
|
12
14
|
*/
|
|
13
15
|
const freeze = Object.freeze;
|
|
14
16
|
|
|
15
|
-
/** @type {
|
|
17
|
+
/** @type {ParseFn} */
|
|
16
18
|
export const parseBytes = (bytes, _specifier, _location, _packageLocation) => {
|
|
17
19
|
// Snapshot ArrayBuffer
|
|
18
20
|
const buffer = new ArrayBuffer(bytes.length);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-cjs-shared-export-wrapper.d.ts","sourceRoot":"","sources":["parse-cjs-shared-export-wrapper.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-cjs-shared-export-wrapper.d.ts","sourceRoot":"","sources":["parse-cjs-shared-export-wrapper.js"],"names":[],"mappings":"AAwCO,2CAPI,UAAU,GAAG,MAAM,GAAG,SAAS,YAC/B,MAAM,GACJ;IACR,QAAQ,EAAC,MAAM,GAAC,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAC,IAAI,CAAA;CACrB,CAgCH;AAmBM,uGAZJ;IAAmB,uBAAuB,EAAlC,MAAM;IACU,WAAW,EAA3B,WAAW;IACgB,eAAe,EAA1C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACX,QAAQ,EAAnB,MAAM;IAC8B,UAAU,EAA9C,MAAM,GAAG,UAAU,GAAG,SAAS;CACvC,GAAU;IACR,MAAM,EAAE;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC;IACzB,aAAa,EAAE,GAAG,CAAC;IACnB,YAAY,WAAW;IACvB,OAAO,WAAW;CACnB,CAmIH;gCApNqC,YAAY;4BAAZ,YAAY"}
|