@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.
- package/README.md +64 -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-all-parsers.d.ts +2 -0
- package/import-archive-all-parsers.d.ts.map +1 -0
- package/import-archive-all-parsers.js +1 -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 +16 -15
- package/src/archive-lite.d.ts +8 -10
- package/src/archive-lite.d.ts.map +1 -1
- package/src/archive-lite.js +35 -209
- package/src/archive.d.ts.map +1 -1
- package/src/archive.js +140 -28
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +62 -16
- package/src/capture-lite.d.ts +2 -2
- package/src/capture-lite.d.ts.map +1 -1
- package/src/capture-lite.js +27 -201
- package/src/compartment-map.d.ts +2 -1
- package/src/compartment-map.d.ts.map +1 -1
- package/src/compartment-map.js +11 -3
- package/src/digest.d.ts +5 -0
- package/src/digest.d.ts.map +1 -0
- package/src/digest.js +235 -0
- package/src/extension.d.ts.map +1 -1
- package/src/extension.js +1 -3
- package/src/import-archive-all-parsers.d.ts +11 -0
- package/src/import-archive-all-parsers.d.ts.map +1 -0
- package/src/import-archive-all-parsers.js +29 -0
- 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 +47 -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 +26 -23
- package/src/import.d.ts.map +1 -1
- package/src/import.js +49 -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 +14 -29
- package/src/map-parser.d.ts.map +1 -1
- package/src/map-parser.js +25 -17
- package/src/node-module-specifier.d.ts.map +1 -1
- package/src/node-module-specifier.js +2 -3
- package/src/node-modules.d.ts +10 -8
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +212 -97
- 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 +299 -0
- package/src/types/external.d.ts.map +1 -0
- package/src/types/external.ts +428 -0
- package/src/types/internal.d.ts +162 -0
- package/src/types/internal.d.ts.map +1 -0
- package/src/types/internal.ts +217 -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/import-hook.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides the implementation of each compartment's `importHook` when
|
|
3
|
+
* using `import.js`, `import-lite.js`, `archive.js`, or `archive-lite.js`.
|
|
4
|
+
* However, `import-archive.js` and `import-archive-lite.js` use their own
|
|
5
|
+
* variant.
|
|
4
6
|
*
|
|
5
7
|
* For building archives, these import hooks create a table of all the modules
|
|
6
8
|
* in a "working set" of transitive dependencies.
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
|
-
// @ts-check
|
|
10
11
|
/**
|
|
11
12
|
* @import {
|
|
12
13
|
* ImportHook,
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
* @import {
|
|
18
19
|
* CompartmentDescriptor,
|
|
19
20
|
* ChooseModuleDescriptorOperators,
|
|
20
|
-
*
|
|
21
|
+
* ChooseModuleDescriptorParams,
|
|
21
22
|
* ChooseModuleDescriptorYieldables,
|
|
22
23
|
* ExitModuleImportHook,
|
|
23
24
|
* FindRedirectParams,
|
|
@@ -180,13 +181,15 @@ const findRedirect = ({
|
|
|
180
181
|
|
|
181
182
|
/**
|
|
182
183
|
* @param {object} params
|
|
183
|
-
* @param {Record<string, any
|
|
184
|
+
* @param {Record<string, any>} [params.modules]
|
|
184
185
|
* @param {ExitModuleImportHook} [params.exitModuleImportHook]
|
|
186
|
+
* @param {string} params.entryCompartmentName
|
|
185
187
|
* @returns {ExitModuleImportHook|undefined}
|
|
186
188
|
*/
|
|
187
189
|
export const exitModuleImportHookMaker = ({
|
|
188
190
|
modules = undefined,
|
|
189
191
|
exitModuleImportHook = undefined,
|
|
192
|
+
entryCompartmentName,
|
|
190
193
|
}) => {
|
|
191
194
|
if (!modules && !exitModuleImportHook) {
|
|
192
195
|
return undefined;
|
|
@@ -204,7 +207,10 @@ export const exitModuleImportHookMaker = ({
|
|
|
204
207
|
});
|
|
205
208
|
}
|
|
206
209
|
if (exitModuleImportHook) {
|
|
207
|
-
|
|
210
|
+
// The entryCompartmentName is a file URL when constructing an archive or
|
|
211
|
+
// importing from a file system, but is merely a zip archive root
|
|
212
|
+
// directory name when importing from an archive.
|
|
213
|
+
return exitModuleImportHook(specifier, entryCompartmentName);
|
|
208
214
|
}
|
|
209
215
|
return undefined;
|
|
210
216
|
};
|
|
@@ -243,7 +249,7 @@ const nominateCandidates = (moduleSpecifier, searchSuffixes) => {
|
|
|
243
249
|
*
|
|
244
250
|
* @template {ChooseModuleDescriptorOperators} Operators Type of operators (sync
|
|
245
251
|
* or async)
|
|
246
|
-
* @param {
|
|
252
|
+
* @param {ChooseModuleDescriptorParams} options Options/context
|
|
247
253
|
* @param {Operators} operators Operators
|
|
248
254
|
* @returns {Generator<ChooseModuleDescriptorYieldables,
|
|
249
255
|
* StaticModuleType|undefined, Awaited<ChooseModuleDescriptorYieldables>>}
|
|
@@ -269,6 +275,7 @@ function* chooseModuleDescriptor(
|
|
|
269
275
|
for (const candidateSpecifier of candidates) {
|
|
270
276
|
const candidateModuleDescriptor = moduleDescriptors[candidateSpecifier];
|
|
271
277
|
if (candidateModuleDescriptor !== undefined) {
|
|
278
|
+
candidateModuleDescriptor.retained = true;
|
|
272
279
|
const { compartment: candidateCompartmentName = packageLocation } =
|
|
273
280
|
candidateModuleDescriptor;
|
|
274
281
|
const candidateCompartment = compartments[candidateCompartmentName];
|
|
@@ -339,6 +346,7 @@ function* chooseModuleDescriptor(
|
|
|
339
346
|
// module specifier than the requested one.
|
|
340
347
|
if (candidateSpecifier !== moduleSpecifier) {
|
|
341
348
|
moduleDescriptors[moduleSpecifier] = {
|
|
349
|
+
retained: true,
|
|
342
350
|
module: candidateSpecifier,
|
|
343
351
|
compartment: packageLocation,
|
|
344
352
|
};
|
|
@@ -502,89 +510,91 @@ export const makeImportHookMaker = (
|
|
|
502
510
|
// for lint rule
|
|
503
511
|
await null;
|
|
504
512
|
|
|
505
|
-
//
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
enforceModulePolicy(moduleSpecifier, compartmentDescriptor, {
|
|
518
|
-
exit: true,
|
|
519
|
-
errorHint: `Blocked in loading. ${q(
|
|
520
|
-
moduleSpecifier,
|
|
521
|
-
)} was not in the compartment map and an attempt was made to load it as a builtin`,
|
|
522
|
-
});
|
|
523
|
-
if (archiveOnly) {
|
|
524
|
-
// Return a place-holder.
|
|
525
|
-
// Archived compartments are not executed.
|
|
526
|
-
return freeze({ imports: [], exports: [], execute() {} });
|
|
527
|
-
}
|
|
528
|
-
// note it's not being marked as exit in sources
|
|
529
|
-
// it could get marked and the second pass, when the archive is being executed, would have the data
|
|
530
|
-
// to enforce which exits can be dynamically imported
|
|
531
|
-
const attenuatedRecord = await attenuateModuleHook(
|
|
513
|
+
// All importHook errors must be deferred if coming from loading dependencies
|
|
514
|
+
// identified by a parser that discovers imports heuristically.
|
|
515
|
+
try {
|
|
516
|
+
// per-module:
|
|
517
|
+
|
|
518
|
+
// In Node.js, an absolute specifier always indicates a built-in or
|
|
519
|
+
// third-party dependency.
|
|
520
|
+
// The `moduleMapHook` captures all third-party dependencies, unless
|
|
521
|
+
// we allow importing any exit.
|
|
522
|
+
if (moduleSpecifier !== '.' && !moduleSpecifier.startsWith('./')) {
|
|
523
|
+
if (exitModuleImportHook) {
|
|
524
|
+
const record = await exitModuleImportHook(
|
|
532
525
|
moduleSpecifier,
|
|
533
|
-
|
|
534
|
-
compartmentDescriptor.policy,
|
|
535
|
-
attenuators,
|
|
526
|
+
packageLocation,
|
|
536
527
|
);
|
|
537
|
-
|
|
528
|
+
if (record) {
|
|
529
|
+
// It'd be nice to check the policy before importing it, but we can only throw a policy error if the
|
|
530
|
+
// hook returns something. Otherwise, we need to fall back to the 'cannot find' error below.
|
|
531
|
+
enforceModulePolicy(moduleSpecifier, compartmentDescriptor, {
|
|
532
|
+
exit: true,
|
|
533
|
+
errorHint: `Blocked in loading. ${q(
|
|
534
|
+
moduleSpecifier,
|
|
535
|
+
)} was not in the compartment map and an attempt was made to load it as a builtin`,
|
|
536
|
+
});
|
|
537
|
+
if (archiveOnly) {
|
|
538
|
+
// Return a place-holder.
|
|
539
|
+
// Archived compartments are not executed.
|
|
540
|
+
return freeze({ imports: [], exports: [], execute() {} });
|
|
541
|
+
}
|
|
542
|
+
// note it's not being marked as exit in sources
|
|
543
|
+
// it could get marked and the second pass, when the archive is being executed, would have the data
|
|
544
|
+
// to enforce which exits can be dynamically imported
|
|
545
|
+
const attenuatedRecord = await attenuateModuleHook(
|
|
546
|
+
moduleSpecifier,
|
|
547
|
+
record,
|
|
548
|
+
compartmentDescriptor.policy,
|
|
549
|
+
attenuators,
|
|
550
|
+
);
|
|
551
|
+
return attenuatedRecord;
|
|
552
|
+
}
|
|
538
553
|
}
|
|
539
|
-
|
|
540
|
-
return deferError(
|
|
541
|
-
moduleSpecifier,
|
|
542
|
-
Error(
|
|
554
|
+
throw Error(
|
|
543
555
|
`Cannot find external module ${q(
|
|
544
556
|
moduleSpecifier,
|
|
545
557
|
)} in package ${packageLocation}`,
|
|
546
|
-
)
|
|
547
|
-
|
|
548
|
-
}
|
|
558
|
+
);
|
|
559
|
+
}
|
|
549
560
|
|
|
550
|
-
|
|
561
|
+
const { maybeRead } = unpackReadPowers(readPowers);
|
|
551
562
|
|
|
552
|
-
|
|
563
|
+
const candidates = nominateCandidates(moduleSpecifier, searchSuffixes);
|
|
553
564
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
565
|
+
const record = await asyncTrampoline(
|
|
566
|
+
chooseModuleDescriptor,
|
|
567
|
+
{
|
|
568
|
+
candidates,
|
|
569
|
+
compartmentDescriptor,
|
|
570
|
+
compartmentDescriptors,
|
|
571
|
+
compartments,
|
|
572
|
+
computeSha512,
|
|
573
|
+
moduleDescriptors,
|
|
574
|
+
moduleSpecifier,
|
|
575
|
+
packageLocation,
|
|
576
|
+
packageSources,
|
|
577
|
+
readPowers,
|
|
578
|
+
sourceMapHook,
|
|
579
|
+
strictlyRequiredForCompartment,
|
|
580
|
+
},
|
|
581
|
+
{ maybeRead, parse, shouldDeferError },
|
|
582
|
+
);
|
|
572
583
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
584
|
+
if (record) {
|
|
585
|
+
return record;
|
|
586
|
+
}
|
|
576
587
|
|
|
577
|
-
|
|
578
|
-
moduleSpecifier,
|
|
579
|
-
// TODO offer breadcrumbs in the error message, or how to construct breadcrumbs with another tool.
|
|
580
|
-
Error(
|
|
588
|
+
throw Error(
|
|
581
589
|
`Cannot find file for internal module ${q(
|
|
582
590
|
moduleSpecifier,
|
|
583
591
|
)} (with candidates ${candidates
|
|
584
592
|
.map(x => q(x))
|
|
585
593
|
.join(', ')}) in package ${packageLocation}`,
|
|
586
|
-
)
|
|
587
|
-
)
|
|
594
|
+
);
|
|
595
|
+
} catch (error) {
|
|
596
|
+
return deferError(moduleSpecifier, error);
|
|
597
|
+
}
|
|
588
598
|
};
|
|
589
599
|
return importHook;
|
|
590
600
|
};
|
|
@@ -724,7 +734,8 @@ export function makeImportNowHookMaker(
|
|
|
724
734
|
}
|
|
725
735
|
|
|
726
736
|
if (exitModuleImportNowHook) {
|
|
727
|
-
//
|
|
737
|
+
// This hook is responsible for ensuring that the moduleSpecifier
|
|
738
|
+
// actually refers to an exit module.
|
|
728
739
|
const exitRecord = exitModuleImportNowHook(
|
|
729
740
|
moduleSpecifier,
|
|
730
741
|
packageLocation,
|
package/src/import-lite.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-lite.d.ts","sourceRoot":"","sources":["import-lite.js"],"names":[],"mappings":";;;;;;;
|
|
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"}
|
package/src/import-lite.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides functions for evaluating a module and its transitive
|
|
3
|
+
* dependencies given a partially completed compartment map.
|
|
3
4
|
* The compartment map needs to describe every reachable compartment, where to
|
|
4
5
|
* find modules in that compartment, and how to link modules between
|
|
5
6
|
* compartments, but does not need to capture a module descriptor for every
|
|
@@ -14,19 +15,22 @@
|
|
|
14
15
|
* `@endo/compartment-mapper/import-parsers.js` or similar.
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
|
-
// @ts-check
|
|
18
18
|
/* eslint no-shadow: "off" */
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @import {
|
|
22
|
+
* CompartmentMapDescriptor,
|
|
23
|
+
* SyncImportLocationOptions,
|
|
24
|
+
* ImportNowHookMaker,
|
|
25
|
+
* ReadNowPowers,
|
|
26
|
+
* Application,
|
|
27
|
+
* ImportLocationOptions,
|
|
28
|
+
* ExecuteFn,
|
|
29
|
+
* ReadFn,
|
|
30
|
+
* ReadPowers,
|
|
31
|
+
* SomeObject,
|
|
32
|
+
* } from './types.js'
|
|
33
|
+
*/
|
|
30
34
|
|
|
31
35
|
import { link } from './link.js';
|
|
32
36
|
import {
|
|
@@ -91,15 +95,12 @@ export const loadFromMap = async (readPowers, compartmentMap, options = {}) => {
|
|
|
91
95
|
const {
|
|
92
96
|
searchSuffixes = undefined,
|
|
93
97
|
parserForLanguage: parserForLanguageOption = {},
|
|
94
|
-
|
|
98
|
+
Compartment: LoadCompartmentOption = Compartment,
|
|
95
99
|
} = options;
|
|
96
100
|
|
|
97
101
|
const parserForLanguage = freeze(
|
|
98
102
|
assign(create(null), parserForLanguageOption),
|
|
99
103
|
);
|
|
100
|
-
const languageForExtension = freeze(
|
|
101
|
-
assign(create(null), languageForExtensionOption),
|
|
102
|
-
);
|
|
103
104
|
|
|
104
105
|
/**
|
|
105
106
|
* Object containing options and read powers that fulfills all requirements
|
|
@@ -150,12 +151,14 @@ export const loadFromMap = async (readPowers, compartmentMap, options = {}) => {
|
|
|
150
151
|
modules,
|
|
151
152
|
transforms,
|
|
152
153
|
__shimTransforms__,
|
|
153
|
-
Compartment,
|
|
154
|
+
Compartment: CompartmentOption = LoadCompartmentOption,
|
|
155
|
+
__native__,
|
|
154
156
|
importHook: exitModuleImportHook,
|
|
155
157
|
} = options;
|
|
156
158
|
const compartmentExitModuleImportHook = exitModuleImportHookMaker({
|
|
157
159
|
modules,
|
|
158
160
|
exitModuleImportHook,
|
|
161
|
+
entryCompartmentName,
|
|
159
162
|
});
|
|
160
163
|
const makeImportHook = makeImportHookMaker(
|
|
161
164
|
readPowers,
|
|
@@ -194,12 +197,12 @@ export const loadFromMap = async (readPowers, compartmentMap, options = {}) => {
|
|
|
194
197
|
makeImportHook,
|
|
195
198
|
makeImportNowHook,
|
|
196
199
|
parserForLanguage,
|
|
197
|
-
languageForExtension,
|
|
198
200
|
globals,
|
|
199
201
|
transforms,
|
|
200
202
|
syncModuleTransforms,
|
|
201
203
|
__shimTransforms__,
|
|
202
|
-
Compartment,
|
|
204
|
+
Compartment: CompartmentOption,
|
|
205
|
+
__native__,
|
|
203
206
|
}));
|
|
204
207
|
} else {
|
|
205
208
|
// sync module transforms are allowed, because they are "compatible"
|
|
@@ -208,13 +211,13 @@ export const loadFromMap = async (readPowers, compartmentMap, options = {}) => {
|
|
|
208
211
|
({ compartment, pendingJobsPromise } = link(compartmentMap, {
|
|
209
212
|
makeImportHook,
|
|
210
213
|
parserForLanguage,
|
|
211
|
-
languageForExtension,
|
|
212
214
|
globals,
|
|
213
215
|
transforms,
|
|
214
216
|
moduleTransforms,
|
|
215
217
|
syncModuleTransforms,
|
|
216
218
|
__shimTransforms__,
|
|
217
|
-
Compartment,
|
|
219
|
+
Compartment: CompartmentOption,
|
|
220
|
+
__native__,
|
|
218
221
|
}));
|
|
219
222
|
}
|
|
220
223
|
|
package/src/import.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["import.js"],"names":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["import.js"],"names":[],"mappings":";;;;;;;AAiDG,yCACQ,aAAa,kBACb,MAAM,WACN,kBAAkB,GAChB,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;AAGE,yCACQ,MAAM,GAAG,UAAU,kBACnB,MAAM,8CAEJ,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;;;;AAuDE,2CACQ,aAAa,kBACb,MAAM,WACN,yBAAyB,GACvB,OAAO,CAAC,UAAU,CAAC,CAE/B;;;;;;;;;;;AAKE,2CACQ,UAAU,GAAC,MAAM,kBACjB,MAAM,gDAEJ,OAAO,CAAC,UAAU,CAAC,CAE/B;mCA7GS,YAAY;wCAAZ,YAAY;iCAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;yCAAZ,YAAY;+CAAZ,YAAY;gCAAZ,YAAY;2CAAZ,YAAY"}
|
package/src/import.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides functions for evaluating a module and its transitive
|
|
3
|
+
* dependencies given the URL of the entry module and assuming packages laid
|
|
4
|
+
* out according to the `node_modules` conventions.
|
|
4
5
|
*
|
|
5
6
|
* To import modules according to any other convention, use `import-lite.js`
|
|
6
7
|
* and provide a compartment map with a custom analog to `mapNodeModules` from
|
|
@@ -10,7 +11,20 @@
|
|
|
10
11
|
* for most cases.
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @import {
|
|
16
|
+
* Application,
|
|
17
|
+
* SyncImportLocationOptions,
|
|
18
|
+
* ImportLocationOptions,
|
|
19
|
+
* SyncArchiveOptions,
|
|
20
|
+
* LoadLocationOptions,
|
|
21
|
+
* SomeObject,
|
|
22
|
+
* ReadNowPowers,
|
|
23
|
+
* ArchiveOptions,
|
|
24
|
+
* ReadFn,
|
|
25
|
+
* ReadPowers,
|
|
26
|
+
* } from './types.js'
|
|
27
|
+
*/
|
|
14
28
|
|
|
15
29
|
import { defaultParserForLanguage } from './import-parsers.js';
|
|
16
30
|
import { mapNodeModules } from './node-modules.js';
|
|
@@ -18,17 +32,6 @@ import { loadFromMap } from './import-lite.js';
|
|
|
18
32
|
|
|
19
33
|
const { assign, create, freeze } = Object;
|
|
20
34
|
|
|
21
|
-
/** @import {Application} from './types.js' */
|
|
22
|
-
/** @import {ImportLocationOptions} from './types.js' */
|
|
23
|
-
/** @import {SyncArchiveOptions} from './types.js' */
|
|
24
|
-
/** @import {LoadLocationOptions} from './types.js' */
|
|
25
|
-
/** @import {SyncImportLocationOptions} from './types.js' */
|
|
26
|
-
/** @import {SomeObject} from './types.js' */
|
|
27
|
-
/** @import {ReadNowPowers} from './types.js' */
|
|
28
|
-
/** @import {ArchiveOptions} from './types.js' */
|
|
29
|
-
/** @import {ReadFn} from './types.js' */
|
|
30
|
-
/** @import {ReadPowers} from './types.js' */
|
|
31
|
-
|
|
32
35
|
/**
|
|
33
36
|
* Add the default parserForLanguage option.
|
|
34
37
|
* @param {ArchiveOptions} [options]
|
|
@@ -39,7 +42,8 @@ const assignParserForLanguage = (options = {}) => {
|
|
|
39
42
|
const parserForLanguage = freeze(
|
|
40
43
|
assign(create(null), defaultParserForLanguage, parserForLanguageOption),
|
|
41
44
|
);
|
|
42
|
-
|
|
45
|
+
const languages = Object.keys(parserForLanguage);
|
|
46
|
+
return { ...rest, parserForLanguage, languages };
|
|
43
47
|
};
|
|
44
48
|
|
|
45
49
|
/**
|
|
@@ -69,21 +73,43 @@ export const loadLocation = async (
|
|
|
69
73
|
moduleLocation,
|
|
70
74
|
options = {},
|
|
71
75
|
) => {
|
|
72
|
-
const {
|
|
76
|
+
const {
|
|
77
|
+
dev,
|
|
78
|
+
tags,
|
|
79
|
+
strict,
|
|
80
|
+
commonDependencies,
|
|
81
|
+
policy,
|
|
82
|
+
parserForLanguage,
|
|
83
|
+
languages,
|
|
84
|
+
languageForExtension,
|
|
85
|
+
commonjsLanguageForExtension,
|
|
86
|
+
moduleLanguageForExtension,
|
|
87
|
+
workspaceLanguageForExtension,
|
|
88
|
+
workspaceCommonjsLanguageForExtension,
|
|
89
|
+
workspaceModuleLanguageForExtension,
|
|
90
|
+
...otherOptions
|
|
91
|
+
} = assignParserForLanguage(options);
|
|
73
92
|
// conditions are not present in SyncArchiveOptions
|
|
74
93
|
const conditions =
|
|
75
94
|
'conditions' in options ? options.conditions || tags : tags;
|
|
76
95
|
const compartmentMap = await mapNodeModules(readPowers, moduleLocation, {
|
|
77
96
|
dev,
|
|
97
|
+
strict,
|
|
78
98
|
conditions,
|
|
79
99
|
commonDependencies,
|
|
80
100
|
policy,
|
|
101
|
+
languageForExtension,
|
|
102
|
+
commonjsLanguageForExtension,
|
|
103
|
+
moduleLanguageForExtension,
|
|
104
|
+
workspaceLanguageForExtension,
|
|
105
|
+
workspaceCommonjsLanguageForExtension,
|
|
106
|
+
workspaceModuleLanguageForExtension,
|
|
107
|
+
languages,
|
|
108
|
+
});
|
|
109
|
+
return loadFromMap(readPowers, compartmentMap, {
|
|
110
|
+
parserForLanguage,
|
|
111
|
+
...otherOptions,
|
|
81
112
|
});
|
|
82
|
-
return loadFromMap(
|
|
83
|
-
readPowers,
|
|
84
|
-
compartmentMap,
|
|
85
|
-
assignParserForLanguage(options),
|
|
86
|
-
);
|
|
87
113
|
};
|
|
88
114
|
|
|
89
115
|
/**
|
|
@@ -111,7 +137,7 @@ export const loadLocation = async (
|
|
|
111
137
|
/**
|
|
112
138
|
* @param {ReadPowers|ReadFn|ReadNowPowers} readPowers
|
|
113
139
|
* @param {string} moduleLocation
|
|
114
|
-
* @param {ImportLocationOptions} [options]
|
|
140
|
+
* @param {ImportLocationOptions|SyncImportLocationOptions} [options]
|
|
115
141
|
* @returns {Promise<SomeObject>} the object of the imported modules exported
|
|
116
142
|
* names.
|
|
117
143
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infer-exports.d.ts","sourceRoot":"","sources":["infer-exports.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"infer-exports.d.ts","sourceRoot":"","sources":["infer-exports.js"],"names":[],"mappings":"AAqHO,+DATJ;IAAkC,IAAI,EAA9B,MAAM;IACqB,MAAM;IACN,OAAO,GAAlC,MAAM;CACd,cAAQ,GAAG,CAAC,MAAM,CAAC,SAEX,oBAAoB,kCA2B9B;AAkBM,yCAPI,MAAM,cACN,GAAG,CAAC,MAAM,CAAC,SAEX,oBAAoB,GAElB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAG8B;AAE1D,uIA2CN;0CApMuC,YAAY"}
|
package/src/infer-exports.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides functions needed by `node-modules.js` for building
|
|
2
3
|
* inter-compartment linkage according to the specifications in a
|
|
3
4
|
* `package.json` as laid out in the `node_modules` convention.
|
|
4
5
|
* These functions implement the behavior for a package's `"main"`,
|
|
5
6
|
* `"browser"`, `"imports"`, and `"exports"` properties in a `package.json`.
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
|
-
// @ts-check
|
|
9
|
-
|
|
10
9
|
/** @import {LanguageForExtension} from './types.js' */
|
|
11
10
|
|
|
12
11
|
import { join, relativize } from './node-module-specifier.js';
|
package/src/json.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["json.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["json.js"],"names":[],"mappings":"AASO,yCAHI,MAAM,YACN,MAAM,OAWhB"}
|
package/src/json.js
CHANGED
package/src/link.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["link.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["link.js"],"names":[],"mappings":"AAsPO,sEAJI,wBAAwB,WACxB,WAAW,GACT,UAAU,CA0KtB;AAOM,yCAJI,wBAAwB,WACxB,WAAW,eAIqB;8CA9YjC,YAAY;iCAAZ,YAAY;gCAAZ,YAAY"}
|
package/src/link.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides the linking behavior shared by all Compartment Mapper
|
|
3
|
+
* workflows.
|
|
2
4
|
* This involves creating and configuring compartments according to the
|
|
3
5
|
* specifications in a compartment map, and is suitable for compartment maps
|
|
4
6
|
* that just outline the locations of compartments and their inter-linkage and
|
|
@@ -6,26 +8,22 @@
|
|
|
6
8
|
* dependencies of their entry module.
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
|
-
// @ts-check
|
|
10
|
-
|
|
11
|
-
/** @import {ModuleMapHook} from 'ses' */
|
|
12
11
|
/**
|
|
12
|
+
* @import {ModuleMapHook} from 'ses'
|
|
13
13
|
* @import {
|
|
14
14
|
* CompartmentDescriptor,
|
|
15
15
|
* CompartmentMapDescriptor,
|
|
16
16
|
* ImportNowHookMaker,
|
|
17
|
-
* LanguageForExtension,
|
|
18
17
|
* LinkOptions,
|
|
19
18
|
* LinkResult,
|
|
20
19
|
* ModuleDescriptor,
|
|
21
20
|
* ParseFn,
|
|
22
|
-
*
|
|
21
|
+
* AsyncParseFn,
|
|
23
22
|
* ParserForLanguage,
|
|
24
23
|
* ParserImplementation,
|
|
25
24
|
* ShouldDeferError,
|
|
26
25
|
* } from './types.js'
|
|
27
26
|
*/
|
|
28
|
-
/** @import {ERef} from '@endo/eventual-send' */
|
|
29
27
|
|
|
30
28
|
import { makeMapParsers } from './map-parser.js';
|
|
31
29
|
import { resolve as resolveFallback } from './node-module-specifier.js';
|
|
@@ -43,7 +41,7 @@ const { allSettled } = Promise;
|
|
|
43
41
|
|
|
44
42
|
/**
|
|
45
43
|
* @template T
|
|
46
|
-
* @type {(iterable: Iterable<
|
|
44
|
+
* @type {(iterable: Iterable<Promise<T>>) => Promise<Array<PromiseSettledResult<T>>>}
|
|
47
45
|
*/
|
|
48
46
|
const promiseAllSettled = allSettled.bind(Promise);
|
|
49
47
|
|
|
@@ -112,6 +110,8 @@ const makeModuleMapHook = (
|
|
|
112
110
|
|
|
113
111
|
const moduleDescriptor = moduleDescriptors[moduleSpecifier];
|
|
114
112
|
if (moduleDescriptor !== undefined) {
|
|
113
|
+
moduleDescriptor.retained = true;
|
|
114
|
+
|
|
115
115
|
// "foreignCompartmentName" refers to the compartment which
|
|
116
116
|
// may differ from the current compartment
|
|
117
117
|
const {
|
|
@@ -193,6 +193,7 @@ const makeModuleMapHook = (
|
|
|
193
193
|
// a moduleMapHook when we assemble compartments from the resulting
|
|
194
194
|
// archive.
|
|
195
195
|
moduleDescriptors[moduleSpecifier] = {
|
|
196
|
+
retained: true,
|
|
196
197
|
compartment: foreignCompartmentName,
|
|
197
198
|
module: foreignModuleSpecifier,
|
|
198
199
|
};
|
|
@@ -252,12 +253,12 @@ export const link = (
|
|
|
252
253
|
makeImportHook,
|
|
253
254
|
makeImportNowHook = impossibleImportNowHookMaker,
|
|
254
255
|
parserForLanguage: parserForLanguageOption = {},
|
|
255
|
-
languageForExtension: languageForExtensionOption = {},
|
|
256
256
|
globals = {},
|
|
257
257
|
transforms = [],
|
|
258
258
|
moduleTransforms,
|
|
259
259
|
syncModuleTransforms,
|
|
260
260
|
__shimTransforms__ = [],
|
|
261
|
+
__native__ = false,
|
|
261
262
|
archiveOnly = false,
|
|
262
263
|
Compartment = defaultCompartment,
|
|
263
264
|
} = options;
|
|
@@ -277,10 +278,6 @@ export const link = (
|
|
|
277
278
|
|
|
278
279
|
const pendingJobs = [];
|
|
279
280
|
|
|
280
|
-
/** @type {LanguageForExtension} */
|
|
281
|
-
const defaultLanguageForExtension = freeze(
|
|
282
|
-
assign(create(null), languageForExtensionOption),
|
|
283
|
-
);
|
|
284
281
|
/** @type {ParserForLanguage} */
|
|
285
282
|
const parserForLanguage = freeze(
|
|
286
283
|
assign(create(null), parserForLanguageOption),
|
|
@@ -298,8 +295,8 @@ export const link = (
|
|
|
298
295
|
const {
|
|
299
296
|
location,
|
|
300
297
|
name,
|
|
301
|
-
parsers:
|
|
302
|
-
types:
|
|
298
|
+
parsers: languageForExtension = {},
|
|
299
|
+
types: languageForModuleSpecifier = {},
|
|
303
300
|
} = compartmentDescriptor;
|
|
304
301
|
|
|
305
302
|
// this is for retaining the correct type inference about these values
|
|
@@ -312,22 +309,9 @@ export const link = (
|
|
|
312
309
|
// The `moduleMapHook` writes back to the compartment map.
|
|
313
310
|
compartmentDescriptor.modules = modules;
|
|
314
311
|
|
|
315
|
-
/** @type {Record<string, string>} */
|
|
316
|
-
const languageForModuleSpecifier = freeze(
|
|
317
|
-
assign(create(null), languageForModuleSpecifierOverrides),
|
|
318
|
-
);
|
|
319
|
-
/** @type {LanguageForExtension} */
|
|
320
|
-
const languageForExtension = freeze(
|
|
321
|
-
assign(
|
|
322
|
-
create(null),
|
|
323
|
-
defaultLanguageForExtension,
|
|
324
|
-
languageForExtensionOverrides,
|
|
325
|
-
),
|
|
326
|
-
);
|
|
327
|
-
|
|
328
312
|
// TS is kind of dumb about this, so we can use a type assertion to avoid a
|
|
329
313
|
// pointless ternary.
|
|
330
|
-
const parse = /** @type {ParseFn|
|
|
314
|
+
const parse = /** @type {ParseFn|AsyncParseFn} */ (
|
|
331
315
|
mapParsers(languageForExtension, languageForModuleSpecifier)
|
|
332
316
|
);
|
|
333
317
|
|
|
@@ -379,6 +363,7 @@ export const link = (
|
|
|
379
363
|
transforms,
|
|
380
364
|
__shimTransforms__,
|
|
381
365
|
__options__: true,
|
|
366
|
+
__native__,
|
|
382
367
|
});
|
|
383
368
|
|
|
384
369
|
if (!archiveOnly) {
|
package/src/map-parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-parser.d.ts","sourceRoot":"","sources":["map-parser.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"map-parser.d.ts","sourceRoot":"","sources":["map-parser.js"],"names":[],"mappings":"AA6SO,+FAHI,qBAAqB,GACnB,YAAY,CA+CxB;2CAvUS,YAAY;kCAAZ,YAAY"}
|