@endo/compartment-mapper 1.6.0 → 1.6.1
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/LICENSE +1 -1
- package/SECURITY.md +2 -2
- package/package.json +11 -11
- package/src/archive-lite.d.ts +5 -5
- package/src/archive-lite.d.ts.map +1 -1
- package/src/archive.d.ts +5 -5
- package/src/archive.d.ts.map +1 -1
- package/src/archive.js +3 -1
- package/src/bundle-cjs.d.ts +12 -2
- package/src/bundle-cjs.d.ts.map +1 -1
- package/src/bundle-lite.d.ts +2 -2
- package/src/bundle-lite.d.ts.map +1 -1
- package/src/bundle-lite.js +0 -1
- package/src/bundle-mjs.d.ts +12 -2
- package/src/bundle-mjs.d.ts.map +1 -1
- package/src/bundle.d.ts +5 -5
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +1 -1
- package/src/capture-lite.d.ts +1 -1
- package/src/capture-lite.d.ts.map +1 -1
- package/src/capture-lite.js +3 -1
- package/src/compartment-map.d.ts +1 -1
- package/src/compartment-map.d.ts.map +1 -1
- package/src/import-archive-lite.d.ts +2 -2
- package/src/import-archive-lite.d.ts.map +1 -1
- package/src/import-archive-lite.js +3 -1
- package/src/import-archive.d.ts +3 -3
- package/src/import-archive.d.ts.map +1 -1
- package/src/import-archive.js +3 -1
- package/src/import-hook.d.ts.map +1 -1
- package/src/import-hook.js +204 -99
- package/src/import-lite.d.ts +1 -1
- package/src/import-lite.d.ts.map +1 -1
- package/src/import-lite.js +3 -1
- package/src/import.d.ts.map +1 -1
- package/src/import.js +3 -1
- package/src/infer-exports.d.ts +5 -7
- package/src/infer-exports.d.ts.map +1 -1
- package/src/infer-exports.js +23 -8
- package/src/link.d.ts.map +1 -1
- package/src/link.js +4 -1
- package/src/map-parser.d.ts.map +1 -1
- package/src/map-parser.js +51 -5
- package/src/node-module-specifier.d.ts.map +1 -1
- package/src/node-module-specifier.js +3 -1
- package/src/node-modules.d.ts +2 -2
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +150 -31
- package/src/node-powers.d.ts +1 -1
- package/src/node-powers.d.ts.map +1 -1
- package/src/node-powers.js +3 -1
- package/src/parse-archive-cjs.d.ts +5 -1
- package/src/parse-archive-cjs.d.ts.map +1 -1
- package/src/parse-archive-cjs.js +3 -1
- package/src/parse-archive-mjs.d.ts +5 -1
- package/src/parse-archive-mjs.d.ts.map +1 -1
- package/src/parse-archive-mjs.js +3 -1
- package/src/parse-bytes.d.ts +5 -1
- package/src/parse-bytes.d.ts.map +1 -1
- package/src/parse-bytes.js +3 -1
- package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
- package/src/parse-cjs-shared-export-wrapper.js +3 -1
- package/src/parse-cjs.d.ts +5 -1
- package/src/parse-cjs.d.ts.map +1 -1
- package/src/parse-cjs.js +3 -1
- package/src/parse-json.d.ts +5 -2
- package/src/parse-json.d.ts.map +1 -1
- package/src/parse-mjs.d.ts +5 -1
- package/src/parse-mjs.d.ts.map +1 -1
- package/src/parse-pre-cjs.d.ts +5 -1
- package/src/parse-pre-cjs.d.ts.map +1 -1
- package/src/parse-pre-cjs.js +3 -1
- package/src/parse-pre-mjs.d.ts +5 -1
- package/src/parse-pre-mjs.d.ts.map +1 -1
- package/src/parse-pre-mjs.js +3 -1
- package/src/parse-text.d.ts +5 -1
- package/src/parse-text.d.ts.map +1 -1
- package/src/parse-text.js +3 -1
- package/src/policy-format.d.ts +2 -1
- package/src/policy-format.d.ts.map +1 -1
- package/src/policy-format.js +5 -2
- package/src/policy.d.ts +2 -2
- package/src/policy.d.ts.map +1 -1
- package/src/policy.js +10 -8
- package/src/powers.d.ts +1 -1
- package/src/powers.d.ts.map +1 -1
- package/src/powers.js +3 -1
- package/src/search.d.ts +2 -1
- package/src/search.d.ts.map +1 -1
- package/src/search.js +3 -1
- package/src/types/compartment-map-schema.d.ts +3 -1
- package/src/types/compartment-map-schema.d.ts.map +1 -1
- package/src/types/compartment-map-schema.ts +3 -1
- package/src/types/external.d.ts +15 -9
- package/src/types/external.d.ts.map +1 -1
- package/src/types/external.ts +15 -9
- package/src/types/internal.d.ts +33 -18
- package/src/types/internal.d.ts.map +1 -1
- package/src/types/internal.ts +40 -20
- package/src/types/node-powers.d.ts +3 -1
- package/src/types/node-powers.d.ts.map +1 -1
- package/src/types/node-powers.ts +3 -1
- package/src/types/policy-schema.d.ts +3 -1
- package/src/types/policy-schema.d.ts.map +1 -1
- package/src/types/policy-schema.ts +3 -1
- package/src/types/policy.d.ts +3 -1
- package/src/types/policy.d.ts.map +1 -1
- package/src/types/policy.ts +3 -1
- package/src/types/powers.d.ts +3 -1
- package/src/types/powers.d.ts.map +1 -1
- package/src/types/powers.ts +3 -1
- package/src/types/typescript.d.ts +3 -1
- package/src/types/typescript.d.ts.map +1 -1
- package/src/types/typescript.ts +3 -1
- package/src/url.d.ts.map +1 -1
- package/src/url.js +3 -1
package/src/import-hook.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides the implementation of each compartment's `importHook` when
|
|
3
3
|
* using `import.js`, `import-lite.js`, `archive.js`, or `archive-lite.js`.
|
|
4
4
|
* However, `import-archive.js` and `import-archive-lite.js` use their own
|
|
5
5
|
* variant.
|
|
6
6
|
*
|
|
7
7
|
* For building archives, these import hooks create a table of all the modules
|
|
8
8
|
* in a "working set" of transitive dependencies.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -13,7 +15,8 @@
|
|
|
13
15
|
* ImportHook,
|
|
14
16
|
* ImportNowHook,
|
|
15
17
|
* RedirectStaticModuleInterface,
|
|
16
|
-
* StaticModuleType
|
|
18
|
+
* StaticModuleType,
|
|
19
|
+
* VirtualModuleSource
|
|
17
20
|
* } from 'ses'
|
|
18
21
|
* @import {
|
|
19
22
|
* CompartmentDescriptor,
|
|
@@ -22,7 +25,6 @@
|
|
|
22
25
|
* ChooseModuleDescriptorYieldables,
|
|
23
26
|
* ExitModuleImportHook,
|
|
24
27
|
* FindRedirectParams,
|
|
25
|
-
* HashFn,
|
|
26
28
|
* ImportHookMaker,
|
|
27
29
|
* ImportNowHookMaker,
|
|
28
30
|
* MakeImportHookMakerOptions,
|
|
@@ -31,9 +33,10 @@
|
|
|
31
33
|
* ParseResult,
|
|
32
34
|
* ReadFn,
|
|
33
35
|
* ReadPowers,
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
36
|
+
* ReadNowPowers,
|
|
37
|
+
* StrictlyRequiredFn,
|
|
38
|
+
* CompartmentSources,
|
|
39
|
+
* DeferErrorFn
|
|
37
40
|
* } from './types.js'
|
|
38
41
|
*/
|
|
39
42
|
|
|
@@ -93,6 +96,32 @@ const nodejsConventionSearchSuffixes = [
|
|
|
93
96
|
'/index.node',
|
|
94
97
|
];
|
|
95
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Returns `true` if `absoluteModuleSpecifier` is within the path `compartmentLocation`.
|
|
101
|
+
* @param {string} absoluteModudeSpecifier Absolute path to module specifier
|
|
102
|
+
* @param {string} compartmentLocation Absolute path to compartment location
|
|
103
|
+
* @returns {boolean}
|
|
104
|
+
*/
|
|
105
|
+
const isLocationWithinCompartment = (
|
|
106
|
+
absoluteModudeSpecifier,
|
|
107
|
+
compartmentLocation,
|
|
108
|
+
) => absoluteModudeSpecifier.startsWith(compartmentLocation);
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Computes the relative path to a module from its compartment location (including a leading `./`)
|
|
112
|
+
*
|
|
113
|
+
* @param {string} absoluteModuleSpecifier Absolute path (not URL) to a module specifier
|
|
114
|
+
* @param {string} compartmentLocation Absolute path to compartment location
|
|
115
|
+
* @returns {string} Redirect static module interface; the `specifier` prop of this value _must_ be a relative path with leading `./`
|
|
116
|
+
*/
|
|
117
|
+
const relativeSpecifier = (absoluteModuleSpecifier, compartmentLocation) => {
|
|
118
|
+
assert(
|
|
119
|
+
isLocationWithinCompartment(absoluteModuleSpecifier, compartmentLocation),
|
|
120
|
+
`Module specifier location "${absoluteModuleSpecifier}" does not start with compartment location "${compartmentLocation}"`,
|
|
121
|
+
);
|
|
122
|
+
return `./${absoluteModuleSpecifier.substring(compartmentLocation.length)}`;
|
|
123
|
+
};
|
|
124
|
+
|
|
96
125
|
/**
|
|
97
126
|
* Given a module specifier which is an absolute path, attempt to match it with
|
|
98
127
|
* an existing compartment; return a {@link RedirectStaticModuleInterface} if found.
|
|
@@ -106,12 +135,9 @@ const findRedirect = ({
|
|
|
106
135
|
compartmentDescriptors,
|
|
107
136
|
compartments,
|
|
108
137
|
absoluteModuleSpecifier,
|
|
109
|
-
packageLocation,
|
|
110
138
|
}) => {
|
|
111
|
-
const moduleSpecifierLocation = new URL(
|
|
112
|
-
|
|
113
|
-
packageLocation,
|
|
114
|
-
).href;
|
|
139
|
+
const moduleSpecifierLocation = new URL(absoluteModuleSpecifier, 'file:')
|
|
140
|
+
.href;
|
|
115
141
|
|
|
116
142
|
// a file:// URL string
|
|
117
143
|
let someLocation = new URL('./', moduleSpecifierLocation).href;
|
|
@@ -137,7 +163,7 @@ const findRedirect = ({
|
|
|
137
163
|
// is a dependency of the compartment descriptor
|
|
138
164
|
if (compartmentDescriptor.compartments.has(location)) {
|
|
139
165
|
return {
|
|
140
|
-
specifier:
|
|
166
|
+
specifier: relativeSpecifier(moduleSpecifierLocation, location),
|
|
141
167
|
compartment: compartments[location],
|
|
142
168
|
};
|
|
143
169
|
}
|
|
@@ -158,7 +184,7 @@ const findRedirect = ({
|
|
|
158
184
|
},
|
|
159
185
|
);
|
|
160
186
|
return {
|
|
161
|
-
specifier:
|
|
187
|
+
specifier: relativeSpecifier(moduleSpecifierLocation, location),
|
|
162
188
|
compartment: compartments[location],
|
|
163
189
|
};
|
|
164
190
|
}
|
|
@@ -402,6 +428,54 @@ function* chooseModuleDescriptor(
|
|
|
402
428
|
return undefined;
|
|
403
429
|
}
|
|
404
430
|
|
|
431
|
+
/**
|
|
432
|
+
* Creates a `deferError` function which decides whether to throw immediately or
|
|
433
|
+
* at execution time.
|
|
434
|
+
*
|
|
435
|
+
* @param {StrictlyRequiredFn} strictlyRequiredForCompartment
|
|
436
|
+
* @param {string} packageLocation
|
|
437
|
+
* @param {CompartmentSources} packageSources
|
|
438
|
+
* @returns {DeferErrorFn}
|
|
439
|
+
*/
|
|
440
|
+
const makeDeferError = (
|
|
441
|
+
strictlyRequiredForCompartment,
|
|
442
|
+
packageLocation,
|
|
443
|
+
packageSources,
|
|
444
|
+
) => {
|
|
445
|
+
/**
|
|
446
|
+
* @param {string} specifier
|
|
447
|
+
* @param {Error} error - error to throw on execute
|
|
448
|
+
* @returns {StaticModuleType}
|
|
449
|
+
*/
|
|
450
|
+
const deferError = (specifier, error) => {
|
|
451
|
+
// strictlyRequired is populated with imports declared by modules whose parser is not using heuristics to figure
|
|
452
|
+
// out imports. We're guaranteed they're reachable. If the same module is imported and required, it will not
|
|
453
|
+
// defer, because importing from esm makes it strictly required.
|
|
454
|
+
// Note that ultimately a situation may arise, with exit modules, where the module never reaches importHook but
|
|
455
|
+
// its imports do. In that case the notion of strictly required is no longer boolean, it's true,false,noidea.
|
|
456
|
+
if (strictlyRequiredForCompartment(packageLocation).has(specifier)) {
|
|
457
|
+
throw error;
|
|
458
|
+
}
|
|
459
|
+
// Return a place-holder that'd throw an error if executed
|
|
460
|
+
// This allows cjs parser to more eagerly find calls to require
|
|
461
|
+
// - if parser identified a require call that's a local function, execute will never be called
|
|
462
|
+
// - if actual required module is missing, the error will happen anyway - at execution time
|
|
463
|
+
const record = freeze({
|
|
464
|
+
imports: [],
|
|
465
|
+
exports: [],
|
|
466
|
+
execute: () => {
|
|
467
|
+
throw error;
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
packageSources[specifier] = {
|
|
471
|
+
deferredError: error.message,
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
return record;
|
|
475
|
+
};
|
|
476
|
+
return deferError;
|
|
477
|
+
};
|
|
478
|
+
|
|
405
479
|
/**
|
|
406
480
|
* @param {ReadFn|ReadPowers} readPowers
|
|
407
481
|
* @param {string} baseLocation
|
|
@@ -461,37 +535,11 @@ export const makeImportHookMaker = (
|
|
|
461
535
|
const { modules: moduleDescriptors = create(null) } = compartmentDescriptor;
|
|
462
536
|
compartmentDescriptor.modules = moduleDescriptors;
|
|
463
537
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const deferError = (specifier, error) => {
|
|
470
|
-
// strictlyRequired is populated with imports declared by modules whose parser is not using heuristics to figure
|
|
471
|
-
// out imports. We're guaranteed they're reachable. If the same module is imported and required, it will not
|
|
472
|
-
// defer, because importing from esm makes it strictly required.
|
|
473
|
-
// Note that ultimately a situation may arise, with exit modules, where the module never reaches importHook but
|
|
474
|
-
// its imports do. In that case the notion of strictly required is no longer boolean, it's true,false,noidea.
|
|
475
|
-
if (strictlyRequiredForCompartment(packageLocation).has(specifier)) {
|
|
476
|
-
throw error;
|
|
477
|
-
}
|
|
478
|
-
// Return a place-holder that'd throw an error if executed
|
|
479
|
-
// This allows cjs parser to more eagerly find calls to require
|
|
480
|
-
// - if parser identified a require call that's a local function, execute will never be called
|
|
481
|
-
// - if actual required module is missing, the error will happen anyway - at execution time
|
|
482
|
-
const record = freeze({
|
|
483
|
-
imports: [],
|
|
484
|
-
exports: [],
|
|
485
|
-
execute: () => {
|
|
486
|
-
throw error;
|
|
487
|
-
},
|
|
488
|
-
});
|
|
489
|
-
packageSources[specifier] = {
|
|
490
|
-
deferredError: error.message,
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
return record;
|
|
494
|
-
};
|
|
538
|
+
const deferError = makeDeferError(
|
|
539
|
+
strictlyRequiredForCompartment,
|
|
540
|
+
packageLocation,
|
|
541
|
+
packageSources,
|
|
542
|
+
);
|
|
495
543
|
|
|
496
544
|
/** @type {ImportHook} */
|
|
497
545
|
const importHook = async moduleSpecifier => {
|
|
@@ -639,7 +687,55 @@ export function makeImportNowHookMaker(
|
|
|
639
687
|
packageName: _packageName,
|
|
640
688
|
parse,
|
|
641
689
|
compartments,
|
|
690
|
+
shouldDeferError,
|
|
642
691
|
}) => {
|
|
692
|
+
const deferError = makeDeferError(
|
|
693
|
+
strictlyRequiredForCompartment,
|
|
694
|
+
packageLocation,
|
|
695
|
+
sources,
|
|
696
|
+
);
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Attempt to load the moduleSpecifier via an {@link ExitModuleImportNowHook}, if one exists.
|
|
700
|
+
*
|
|
701
|
+
* If it doesn't exist, then throw an exception.
|
|
702
|
+
* @param {string} moduleSpecifier
|
|
703
|
+
* @param {CompartmentDescriptor} compartmentDescriptor
|
|
704
|
+
* @returns {VirtualModuleSource}
|
|
705
|
+
*/
|
|
706
|
+
const importExitModuleOrFail = (moduleSpecifier, compartmentDescriptor) => {
|
|
707
|
+
if (exitModuleImportNowHook) {
|
|
708
|
+
// This hook is responsible for ensuring that the moduleSpecifier
|
|
709
|
+
// actually refers to an exit module.
|
|
710
|
+
const exitRecord = exitModuleImportNowHook(
|
|
711
|
+
moduleSpecifier,
|
|
712
|
+
packageLocation,
|
|
713
|
+
);
|
|
714
|
+
if (exitRecord) {
|
|
715
|
+
// It'd be nice to check the policy before importing it, but we can only throw a policy error if the
|
|
716
|
+
// hook returns something. Otherwise, we need to fall back to the 'cannot find' error below.
|
|
717
|
+
enforceModulePolicy(moduleSpecifier, compartmentDescriptor, {
|
|
718
|
+
exit: true,
|
|
719
|
+
errorHint: `Blocked in loading. ${q(
|
|
720
|
+
moduleSpecifier,
|
|
721
|
+
)} was not in the compartment map and an attempt was made to load it as a builtin`,
|
|
722
|
+
});
|
|
723
|
+
return exitRecord;
|
|
724
|
+
}
|
|
725
|
+
throw Error(
|
|
726
|
+
`Cannot find external module ${q(
|
|
727
|
+
moduleSpecifier,
|
|
728
|
+
)} in package at ${packageLocation}`,
|
|
729
|
+
);
|
|
730
|
+
} else {
|
|
731
|
+
throw Error(
|
|
732
|
+
`Cannot find external module ${q(
|
|
733
|
+
moduleSpecifier,
|
|
734
|
+
)} from package at ${packageLocation}; try providing an importNowHook`,
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
|
|
643
739
|
if (!('isSyncParser' in parse)) {
|
|
644
740
|
return function impossibleTransformImportNowHook() {
|
|
645
741
|
throw new Error(
|
|
@@ -684,70 +780,79 @@ export function makeImportNowHookMaker(
|
|
|
684
780
|
|
|
685
781
|
/** @type {ImportNowHook} */
|
|
686
782
|
const importNowHook = moduleSpecifier => {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
783
|
+
try {
|
|
784
|
+
// many dynamically-required specifiers will be absolute paths owing to use of `require.resolve()` and `path.resolve()`
|
|
785
|
+
if (isAbsolute(moduleSpecifier)) {
|
|
786
|
+
const record = findRedirect({
|
|
787
|
+
compartmentDescriptor,
|
|
788
|
+
compartmentDescriptors,
|
|
789
|
+
compartments,
|
|
790
|
+
absoluteModuleSpecifier: moduleSpecifier,
|
|
791
|
+
});
|
|
792
|
+
if (record) {
|
|
793
|
+
return record;
|
|
794
|
+
}
|
|
699
795
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
parse,
|
|
722
|
-
},
|
|
723
|
-
);
|
|
796
|
+
// if and only if the module specifier is within the compartment can we
|
|
797
|
+
// make it a relative specifier. the following conditional avoids a try/catch
|
|
798
|
+
// since `relativeSpecifier` will throw if this condition is not met
|
|
799
|
+
if (
|
|
800
|
+
isLocationWithinCompartment(
|
|
801
|
+
moduleSpecifier,
|
|
802
|
+
compartmentDescriptor.location,
|
|
803
|
+
)
|
|
804
|
+
) {
|
|
805
|
+
moduleSpecifier = relativeSpecifier(
|
|
806
|
+
moduleSpecifier,
|
|
807
|
+
compartmentDescriptor.location,
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
} else if (
|
|
811
|
+
moduleSpecifier !== '.' &&
|
|
812
|
+
!moduleSpecifier.startsWith('./')
|
|
813
|
+
) {
|
|
814
|
+
// could be a builtin, which means we should not bother bouncing on the trampoline to find it.
|
|
815
|
+
return importExitModuleOrFail(moduleSpecifier, compartmentDescriptor);
|
|
816
|
+
}
|
|
724
817
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
818
|
+
// we might have an absolute path here, but it might be within the compartment, so
|
|
819
|
+
// we will try to find it.
|
|
820
|
+
const candidates = nominateCandidates(moduleSpecifier, searchSuffixes);
|
|
728
821
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
822
|
+
const record = syncTrampoline(
|
|
823
|
+
chooseModuleDescriptor,
|
|
824
|
+
{
|
|
825
|
+
candidates,
|
|
826
|
+
compartmentDescriptor,
|
|
827
|
+
compartmentDescriptors,
|
|
828
|
+
compartments,
|
|
829
|
+
computeSha512,
|
|
830
|
+
moduleDescriptors,
|
|
831
|
+
moduleSpecifier,
|
|
832
|
+
packageLocation,
|
|
833
|
+
packageSources,
|
|
834
|
+
readPowers,
|
|
835
|
+
archiveOnly,
|
|
836
|
+
sourceMapHook,
|
|
837
|
+
strictlyRequiredForCompartment,
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
maybeRead: maybeReadNow,
|
|
841
|
+
parse,
|
|
842
|
+
shouldDeferError,
|
|
843
|
+
},
|
|
735
844
|
);
|
|
736
845
|
|
|
737
|
-
if (
|
|
738
|
-
|
|
846
|
+
if (record) {
|
|
847
|
+
return record;
|
|
739
848
|
}
|
|
740
849
|
|
|
741
|
-
|
|
850
|
+
// at this point, we haven't found the module by guessing, so we'll try the importer-of-last-resort
|
|
851
|
+
return importExitModuleOrFail(moduleSpecifier, compartmentDescriptor);
|
|
852
|
+
} catch (err) {
|
|
853
|
+
return deferError(moduleSpecifier, err);
|
|
742
854
|
}
|
|
743
|
-
|
|
744
|
-
throw new Error(
|
|
745
|
-
`Could not import module: ${q(
|
|
746
|
-
moduleSpecifier,
|
|
747
|
-
)}; try providing an importNowHook`,
|
|
748
|
-
);
|
|
749
855
|
};
|
|
750
|
-
|
|
751
856
|
return importNowHook;
|
|
752
857
|
};
|
|
753
858
|
return makeImportNowHook;
|
package/src/import-lite.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export function loadFromMap(readPowers: ReadNowPowers, compartmentMap: Compartme
|
|
|
14
14
|
* @returns {Promise<Application>}
|
|
15
15
|
*/
|
|
16
16
|
export function loadFromMap(readPowers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, opts?: ImportLocationOptions | undefined): Promise<Application>;
|
|
17
|
-
export function importFromMap(readPowers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ImportLocationOptions
|
|
17
|
+
export function importFromMap(readPowers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ImportLocationOptions): Promise<SomeObject>;
|
|
18
18
|
import type { ReadNowPowers } from './types.js';
|
|
19
19
|
import type { CompartmentMapDescriptor } from './types.js';
|
|
20
20
|
import type { SyncImportLocationOptions } from './types.js';
|
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":";;;;;;;AAyEG,wCACQ,aAAa,kBACb,wBAAwB,iDAEtB,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;AAGE,wCACQ,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,WAAW,CAAC,CAChC;AA4JM,0CANI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,YACxB,qBAAqB,GACnB,OAAO,CAAC,UAAU,CAAC,CAU/B;mCAxNS,YAAY;8CAAZ,YAAY;+CAAZ,YAAY;iCAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;2CAAZ,YAAY;gCAAZ,YAAY"}
|
package/src/import-lite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides functions for evaluating a module and its transitive
|
|
3
3
|
* dependencies given a partially completed compartment map.
|
|
4
4
|
* The compartment map needs to describe every reachable compartment, where to
|
|
5
5
|
* find modules in that compartment, and how to link modules between
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* The default `parserForLanguage` mapping is empty.
|
|
14
14
|
* You will need to provide the `defaultParserForLanguage` from
|
|
15
15
|
* `@endo/compartment-mapper/import-parsers.js` or similar.
|
|
16
|
+
*
|
|
17
|
+
* @module
|
|
16
18
|
*/
|
|
17
19
|
|
|
18
20
|
/* eslint no-shadow: "off" */
|
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":";;;;;;;AAmDG,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,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides functions for evaluating a module and its transitive
|
|
3
3
|
* dependencies given the URL of the entry module and assuming packages laid
|
|
4
4
|
* out according to the `node_modules` conventions.
|
|
5
5
|
*
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* The default `parserForLanguage` is `import-parsers.js`, which is suitable
|
|
11
11
|
* for most cases.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
/**
|
package/src/infer-exports.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
export function inferExportsEntries({ main, module, exports }:
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}, conditions: Set<string>, types: LanguageForExtension): Generator<string[], void, any>;
|
|
6
|
-
export function inferExports(descriptor: object, conditions: Set<string>, types: LanguageForExtension): Record<string, string>;
|
|
7
|
-
export function inferExportsAndAliases(descriptor: any, externalAliases: any, internalAliases: any, conditions: any, types: any): void;
|
|
1
|
+
export function inferExportsEntries({ main, module, exports }: PackageDescriptor, conditions: Set<string>, types: LanguageForExtension): Generator<string[], void, any>;
|
|
2
|
+
export function inferExports(descriptor: PackageDescriptor, conditions: Set<string>, types: LanguageForExtension): Record<string, string>;
|
|
3
|
+
export function inferExportsAndAliases(descriptor: PackageDescriptor, externalAliases: Node["externalAliases"], internalAliases: Node["internalAliases"], conditions: Set<string>, types: Record<string, string>): void;
|
|
4
|
+
import type { PackageDescriptor } from './types.js';
|
|
8
5
|
import type { LanguageForExtension } from './types.js';
|
|
6
|
+
import type { Node } from './types/node-modules.js';
|
|
9
7
|
//# sourceMappingURL=infer-exports.d.ts.map
|
|
@@ -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":"AA4HO,+DAPI,iBAAiB,cACjB,GAAG,CAAC,MAAM,CAAC,SAEX,oBAAoB,kCA2B9B;AAkBM,yCAPI,iBAAiB,cACjB,GAAG,CAAC,MAAM,CAAC,SAEX,oBAAoB,GAElB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAG8B;AAU1D,mDANI,iBAAiB,mBACjB,IAAI,CAAC,iBAAiB,CAAC,mBACvB,IAAI,CAAC,iBAAiB,CAAC,cACvB,GAAG,CAAC,MAAM,CAAC,SACX,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QA6ChC;uCAhNyD,YAAY;0CAAZ,YAAY;0BAC/C,yBAAyB"}
|
package/src/infer-exports.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides functions needed by `node-modules.js` for building
|
|
3
3
|
* inter-compartment linkage according to the specifications in a
|
|
4
4
|
* `package.json` as laid out in the `node_modules` convention.
|
|
5
5
|
* These functions implement the behavior for a package's `"main"`,
|
|
6
6
|
* `"browser"`, `"imports"`, and `"exports"` properties in a `package.json`.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* @import {LanguageForExtension, PackageDescriptor} from './types.js'
|
|
13
|
+
* @import {Node} from './types/node-modules.js'
|
|
14
|
+
*/
|
|
10
15
|
|
|
11
16
|
import { join, relativize } from './node-module-specifier.js';
|
|
12
17
|
|
|
@@ -81,7 +86,12 @@ function* interpretExports(name, exports, conditions) {
|
|
|
81
86
|
);
|
|
82
87
|
}
|
|
83
88
|
for (const [key, value] of entries(exports)) {
|
|
84
|
-
|
|
89
|
+
// "./" is explicitly an invalid key, but that doesn't
|
|
90
|
+
// stop people from trying to use it.
|
|
91
|
+
if (key === './') {
|
|
92
|
+
// eslint-disable-next-line no-continue
|
|
93
|
+
continue; // or no-op
|
|
94
|
+
} else if (key.startsWith('./') || key === '.') {
|
|
85
95
|
if (name === '.') {
|
|
86
96
|
yield* interpretExports(key, value, conditions);
|
|
87
97
|
} else {
|
|
@@ -105,10 +115,7 @@ function* interpretExports(name, exports, conditions) {
|
|
|
105
115
|
* There may be multiple pairs for a single `name`, but they will be yielded in
|
|
106
116
|
* ascending priority order, and the caller should use the last one that exists.
|
|
107
117
|
*
|
|
108
|
-
* @param {
|
|
109
|
-
* @param {string} packageDescriptor.main
|
|
110
|
-
* @param {string} [packageDescriptor.module]
|
|
111
|
-
* @param {object} [packageDescriptor.exports]
|
|
118
|
+
* @param {PackageDescriptor} packageDescriptor - the parsed body of a package.json file.
|
|
112
119
|
* @param {Set<string>} conditions - build conditions about the target environment
|
|
113
120
|
* for selecting relevant exports, e.g., "browser" or "node".
|
|
114
121
|
* @param {LanguageForExtension} types - an object to populate
|
|
@@ -149,7 +156,7 @@ export const inferExportsEntries = function* inferExportsEntries(
|
|
|
149
156
|
* The values are the corresponding module specifiers in the dependency
|
|
150
157
|
* package's module map, like `./index.js`.
|
|
151
158
|
*
|
|
152
|
-
* @param {
|
|
159
|
+
* @param {PackageDescriptor} descriptor - the parsed body of a package.json file.
|
|
153
160
|
* @param {Set<string>} conditions - build conditions about the target environment
|
|
154
161
|
* for selecting relevant exports, e.g., "browser" or "node".
|
|
155
162
|
* @param {LanguageForExtension} types - an object to populate
|
|
@@ -159,6 +166,14 @@ export const inferExportsEntries = function* inferExportsEntries(
|
|
|
159
166
|
export const inferExports = (descriptor, conditions, types) =>
|
|
160
167
|
fromEntries(inferExportsEntries(descriptor, conditions, types));
|
|
161
168
|
|
|
169
|
+
/**
|
|
170
|
+
*
|
|
171
|
+
* @param {PackageDescriptor} descriptor
|
|
172
|
+
* @param {Node['externalAliases']} externalAliases
|
|
173
|
+
* @param {Node['internalAliases']} internalAliases
|
|
174
|
+
* @param {Set<string>} conditions
|
|
175
|
+
* @param {Record<string, string>} types
|
|
176
|
+
*/
|
|
162
177
|
export const inferExportsAndAliases = (
|
|
163
178
|
descriptor,
|
|
164
179
|
externalAliases,
|
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":"AAwPO,sEAJI,wBAAwB,WACxB,WAAW,GACT,UAAU,CA2KtB;AAOM,yCAJI,wBAAwB,WACxB,WAAW,eAIqB;8CA/YjC,YAAY;iCAAZ,YAAY;gCAAZ,YAAY"}
|
package/src/link.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides the linking behavior shared by all Compartment Mapper
|
|
3
3
|
* workflows.
|
|
4
4
|
* This involves creating and configuring compartments according to the
|
|
5
5
|
* specifications in a compartment map, and is suitable for compartment maps
|
|
6
6
|
* that just outline the locations of compartments and their inter-linkage and
|
|
7
7
|
* also compartment maps that include every module descriptor in the transitive
|
|
8
8
|
* dependencies of their entry module.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -344,6 +346,7 @@ export const link = (
|
|
|
344
346
|
packageName: name,
|
|
345
347
|
parse,
|
|
346
348
|
compartments,
|
|
349
|
+
shouldDeferError,
|
|
347
350
|
});
|
|
348
351
|
|
|
349
352
|
const moduleMapHook = makeModuleMapHook(
|
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":"AA2VO,+FAHI,qBAAqB,GACnB,YAAY,CA+CxB;2CAnXS,YAAY;kCAAZ,YAAY"}
|
package/src/map-parser.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Exports {@link makeMapParsers}, which creates a function which matches a
|
|
3
3
|
* module to a parser based on reasons.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
8
|
/**
|
|
@@ -46,6 +48,48 @@ const has = (object, key) => apply(hasOwnProperty, object, [key]);
|
|
|
46
48
|
*/
|
|
47
49
|
const extensionImpliesLanguage = extension => extension !== 'js';
|
|
48
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Produces a `parser` that parses the content of a module according to the
|
|
53
|
+
* corresponding module language, given the extension of the module specifier
|
|
54
|
+
* and the configuration of the containing compartment. We do not yet support
|
|
55
|
+
* import assertions and we do not have a mechanism for validating the MIME type
|
|
56
|
+
* of the module content against the language implied by the extension or file
|
|
57
|
+
* name.
|
|
58
|
+
*
|
|
59
|
+
* @overload
|
|
60
|
+
* @param {true} preferSynchronous
|
|
61
|
+
* @param {Record<string, string>} languageForExtension - maps a file extension
|
|
62
|
+
* to the corresponding language.
|
|
63
|
+
* @param {Record<string, string>} languageForModuleSpecifier - In a rare case,
|
|
64
|
+
* the type of a module is implied by package.json and should not be inferred
|
|
65
|
+
* from its extension.
|
|
66
|
+
* @param {ParserForLanguage} parserForLanguage
|
|
67
|
+
* @param {ModuleTransforms} moduleTransforms
|
|
68
|
+
* @param {SyncModuleTransforms} syncModuleTransforms
|
|
69
|
+
* @returns {ParseFn}
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Produces a `parser` that parses the content of a module according to the
|
|
74
|
+
* corresponding module language, given the extension of the module specifier
|
|
75
|
+
* and the configuration of the containing compartment. We do not yet support
|
|
76
|
+
* import assertions and we do not have a mechanism for validating the MIME type
|
|
77
|
+
* of the module content against the language implied by the extension or file
|
|
78
|
+
* name.
|
|
79
|
+
*
|
|
80
|
+
* @overload
|
|
81
|
+
* @param {false} preferSynchronous
|
|
82
|
+
* @param {Record<string, string>} languageForExtension - maps a file extension
|
|
83
|
+
* to the corresponding language.
|
|
84
|
+
* @param {Record<string, string>} languageForModuleSpecifier - In a rare case,
|
|
85
|
+
* the type of a module is implied by package.json and should not be inferred
|
|
86
|
+
* from its extension.
|
|
87
|
+
* @param {ParserForLanguage} parserForLanguage
|
|
88
|
+
* @param {ModuleTransforms} moduleTransforms
|
|
89
|
+
* @param {SyncModuleTransforms} syncModuleTransforms
|
|
90
|
+
* @returns {AsyncParseFn}
|
|
91
|
+
*/
|
|
92
|
+
|
|
49
93
|
/**
|
|
50
94
|
* Produces a `parser` that parses the content of a module according to the
|
|
51
95
|
* corresponding module language, given the extension of the module specifier
|
|
@@ -259,10 +303,12 @@ function mapParsers(
|
|
|
259
303
|
languageForExtension,
|
|
260
304
|
languageForModuleSpecifier,
|
|
261
305
|
parserForLanguage,
|
|
262
|
-
moduleTransforms
|
|
263
|
-
syncModuleTransforms
|
|
264
|
-
preferSynchronous
|
|
306
|
+
moduleTransforms,
|
|
307
|
+
syncModuleTransforms,
|
|
308
|
+
preferSynchronous,
|
|
265
309
|
) {
|
|
310
|
+
moduleTransforms = moduleTransforms || {};
|
|
311
|
+
syncModuleTransforms = syncModuleTransforms || {};
|
|
266
312
|
const languageForExtensionEntries = [];
|
|
267
313
|
const problems = [];
|
|
268
314
|
for (const [extension, language] of entries(languageForExtension)) {
|
|
@@ -276,7 +322,7 @@ function mapParsers(
|
|
|
276
322
|
throw Error(`No parser available for language: ${problems.join(', ')}`);
|
|
277
323
|
}
|
|
278
324
|
return makeExtensionParser(
|
|
279
|
-
preferSynchronous,
|
|
325
|
+
/** @type {any} */ (preferSynchronous),
|
|
280
326
|
fromEntries(languageForExtensionEntries),
|
|
281
327
|
languageForModuleSpecifier,
|
|
282
328
|
parserForLanguage,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-module-specifier.d.ts","sourceRoot":"","sources":["node-module-specifier.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node-module-specifier.d.ts","sourceRoot":"","sources":["node-module-specifier.js"],"names":[],"mappings":"AA0DO,8BAJI,MAAM,YACN,MAAM,GACJ,MAAM,CAiClB;AAeM,2BAJI,MAAM,QACN,MAAM,GACJ,MAAM,CA6BlB;AAaM,iCALI,MAAM,GAEJ,MAAM,CAclB"}
|