@endo/compartment-mapper 1.6.2 → 2.0.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/package.json +12 -16
- package/src/archive-lite.d.ts +7 -7
- package/src/archive-lite.d.ts.map +1 -1
- package/src/archive-lite.js +78 -27
- package/src/archive.d.ts.map +1 -1
- package/src/archive.js +7 -0
- package/src/bundle-lite.d.ts +3 -3
- package/src/bundle-lite.d.ts.map +1 -1
- package/src/bundle-lite.js +19 -24
- package/src/bundle.d.ts +3 -3
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +19 -24
- package/src/capture-lite.d.ts +2 -2
- package/src/capture-lite.d.ts.map +1 -1
- package/src/capture-lite.js +217 -25
- package/src/compartment-map.d.ts +9 -2
- package/src/compartment-map.d.ts.map +1 -1
- package/src/compartment-map.js +737 -254
- package/src/digest.d.ts +22 -2
- package/src/digest.d.ts.map +1 -1
- package/src/digest.js +179 -56
- package/src/generic-graph.d.ts +84 -0
- package/src/generic-graph.d.ts.map +1 -0
- package/src/generic-graph.js +356 -0
- package/src/guards.d.ts +18 -0
- package/src/guards.d.ts.map +1 -0
- package/src/guards.js +109 -0
- package/src/hooks.md +124 -0
- package/src/import-archive-lite.d.ts.map +1 -1
- package/src/import-archive-lite.js +15 -11
- package/src/import-archive.d.ts +5 -19
- package/src/import-archive.d.ts.map +1 -1
- package/src/import-archive.js +7 -27
- package/src/import-hook.d.ts +4 -3
- package/src/import-hook.d.ts.map +1 -1
- package/src/import-hook.js +156 -71
- package/src/import-lite.d.ts +6 -6
- package/src/import-lite.d.ts.map +1 -1
- package/src/import-lite.js +8 -5
- package/src/import.d.ts +3 -3
- package/src/import.d.ts.map +1 -1
- package/src/import.js +16 -6
- package/src/infer-exports.d.ts.map +1 -1
- package/src/infer-exports.js +16 -6
- package/src/json.d.ts +1 -1
- package/src/json.d.ts.map +1 -1
- package/src/json.js +10 -3
- package/src/link.d.ts +4 -3
- package/src/link.d.ts.map +1 -1
- package/src/link.js +70 -58
- package/src/node-modules.d.ts +5 -3
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +648 -245
- package/src/node-powers.d.ts +6 -5
- package/src/node-powers.d.ts.map +1 -1
- package/src/node-powers.js +11 -8
- package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
- package/src/parse-cjs-shared-export-wrapper.js +3 -1
- package/src/policy-format.d.ts +22 -5
- package/src/policy-format.d.ts.map +1 -1
- package/src/policy-format.js +342 -108
- package/src/policy.d.ts +13 -28
- package/src/policy.d.ts.map +1 -1
- package/src/policy.js +161 -106
- package/src/types/canonical-name.d.ts +97 -0
- package/src/types/canonical-name.d.ts.map +1 -0
- package/src/types/canonical-name.ts +151 -0
- package/src/types/compartment-map-schema.d.ts +114 -35
- package/src/types/compartment-map-schema.d.ts.map +1 -1
- package/src/types/compartment-map-schema.ts +202 -37
- package/src/types/external.d.ts +173 -29
- package/src/types/external.d.ts.map +1 -1
- package/src/types/external.ts +221 -27
- package/src/types/generic-graph.d.ts +17 -0
- package/src/types/generic-graph.d.ts.map +1 -0
- package/src/types/generic-graph.ts +17 -0
- package/src/types/internal.d.ts +24 -42
- package/src/types/internal.d.ts.map +1 -1
- package/src/types/internal.ts +52 -50
- package/src/types/node-modules.d.ts +101 -17
- package/src/types/node-modules.d.ts.map +1 -1
- package/src/types/node-modules.ts +142 -17
- package/src/types/policy-schema.d.ts +26 -11
- package/src/types/policy-schema.d.ts.map +1 -1
- package/src/types/policy-schema.ts +29 -16
- package/src/types/policy.d.ts +6 -2
- package/src/types/policy.d.ts.map +1 -1
- package/src/types/policy.ts +7 -2
- package/src/types/powers.d.ts +38 -11
- package/src/types/powers.d.ts.map +1 -1
- package/src/types/powers.ts +50 -17
- package/src/types/typescript.d.ts +28 -0
- package/src/types/typescript.d.ts.map +1 -1
- package/src/types/typescript.ts +37 -1
package/src/import-lite.js
CHANGED
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* @import {
|
|
24
|
-
* CompartmentMapDescriptor,
|
|
25
24
|
* SyncImportLocationOptions,
|
|
26
25
|
* ImportNowHookMaker,
|
|
27
26
|
* ReadNowPowers,
|
|
@@ -31,6 +30,7 @@
|
|
|
31
30
|
* ReadFn,
|
|
32
31
|
* ReadPowers,
|
|
33
32
|
* SomeObject,
|
|
33
|
+
* PackageCompartmentMapDescriptor,
|
|
34
34
|
* } from './types.js'
|
|
35
35
|
*/
|
|
36
36
|
|
|
@@ -73,7 +73,7 @@ const isSyncOptions = value => {
|
|
|
73
73
|
/**
|
|
74
74
|
* @overload
|
|
75
75
|
* @param {ReadNowPowers} readPowers
|
|
76
|
-
* @param {
|
|
76
|
+
* @param {PackageCompartmentMapDescriptor} compartmentMap
|
|
77
77
|
* @param {SyncImportLocationOptions} [opts]
|
|
78
78
|
* @returns {Promise<Application>}
|
|
79
79
|
*/
|
|
@@ -81,14 +81,14 @@ const isSyncOptions = value => {
|
|
|
81
81
|
/**
|
|
82
82
|
* @overload
|
|
83
83
|
* @param {ReadFn | ReadPowers} readPowers
|
|
84
|
-
* @param {
|
|
84
|
+
* @param {PackageCompartmentMapDescriptor} compartmentMap
|
|
85
85
|
* @param {ImportLocationOptions} [opts]
|
|
86
86
|
* @returns {Promise<Application>}
|
|
87
87
|
*/
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* @param {ReadFn|ReadPowers|ReadNowPowers} readPowers
|
|
91
|
-
* @param {
|
|
91
|
+
* @param {PackageCompartmentMapDescriptor} compartmentMap
|
|
92
92
|
* @param {ImportLocationOptions} [options]
|
|
93
93
|
* @returns {Promise<Application>}
|
|
94
94
|
*/
|
|
@@ -98,6 +98,7 @@ export const loadFromMap = async (readPowers, compartmentMap, options = {}) => {
|
|
|
98
98
|
searchSuffixes = undefined,
|
|
99
99
|
parserForLanguage: parserForLanguageOption = {},
|
|
100
100
|
Compartment: LoadCompartmentOption = Compartment,
|
|
101
|
+
moduleSourceHook,
|
|
101
102
|
} = options;
|
|
102
103
|
|
|
103
104
|
const parserForLanguage = freeze(
|
|
@@ -172,6 +173,7 @@ export const loadFromMap = async (readPowers, compartmentMap, options = {}) => {
|
|
|
172
173
|
entryCompartmentName,
|
|
173
174
|
entryModuleSpecifier,
|
|
174
175
|
importHook: compartmentExitModuleImportHook,
|
|
176
|
+
moduleSourceHook,
|
|
175
177
|
},
|
|
176
178
|
);
|
|
177
179
|
|
|
@@ -195,6 +197,7 @@ export const loadFromMap = async (readPowers, compartmentMap, options = {}) => {
|
|
|
195
197
|
compartmentDescriptors: compartmentMap.compartments,
|
|
196
198
|
searchSuffixes,
|
|
197
199
|
importNowHook: exitModuleImportNowHook,
|
|
200
|
+
moduleSourceHook,
|
|
198
201
|
},
|
|
199
202
|
);
|
|
200
203
|
({ compartment, pendingJobsPromise } = link(compartmentMap, {
|
|
@@ -235,7 +238,7 @@ export const loadFromMap = async (readPowers, compartmentMap, options = {}) => {
|
|
|
235
238
|
|
|
236
239
|
/**
|
|
237
240
|
* @param {ReadFn | ReadPowers} readPowers
|
|
238
|
-
* @param {
|
|
241
|
+
* @param {PackageCompartmentMapDescriptor} compartmentMap
|
|
239
242
|
* @param {ImportLocationOptions} [options]
|
|
240
243
|
* @returns {Promise<SomeObject>} the object of the imported modules exported
|
|
241
244
|
* names.
|
package/src/import.d.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* @overload
|
|
3
3
|
* @param {ReadNowPowers} readPowers
|
|
4
4
|
* @param {string} moduleLocation
|
|
5
|
-
* @param {
|
|
5
|
+
* @param {SyncLoadLocationOptions} options
|
|
6
6
|
* @returns {Promise<Application>}
|
|
7
7
|
*/
|
|
8
|
-
export function loadLocation(readPowers: ReadNowPowers, moduleLocation: string, options:
|
|
8
|
+
export function loadLocation(readPowers: ReadNowPowers, moduleLocation: string, options: SyncLoadLocationOptions): Promise<Application>;
|
|
9
9
|
/**
|
|
10
10
|
* @overload
|
|
11
11
|
* @param {ReadFn | ReadPowers} readPowers
|
|
@@ -37,7 +37,7 @@ export function importLocation(readPowers: ReadNowPowers, moduleLocation: string
|
|
|
37
37
|
*/
|
|
38
38
|
export function importLocation(readPowers: ReadPowers | ReadFn, moduleLocation: string, options?: ImportLocationOptions | undefined): Promise<SomeObject>;
|
|
39
39
|
import type { ReadNowPowers } from './types.js';
|
|
40
|
-
import type {
|
|
40
|
+
import type { SyncLoadLocationOptions } from './types.js';
|
|
41
41
|
import type { Application } from './types.js';
|
|
42
42
|
import type { ReadFn } from './types.js';
|
|
43
43
|
import type { ReadPowers } from './types.js';
|
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":";;;;;;;AAkDG,yCACQ,aAAa,kBACb,MAAM,WACN,uBAAuB,GACrB,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;AAGE,yCACQ,MAAM,GAAG,UAAU,kBACnB,MAAM,8CAEJ,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;;;;AAkEE,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;mCAxHS,YAAY;6CAAZ,YAAY;iCAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;yCAAZ,YAAY;+CAAZ,YAAY;gCAAZ,YAAY;2CAAZ,YAAY"}
|
package/src/import.js
CHANGED
|
@@ -18,26 +18,25 @@
|
|
|
18
18
|
* Application,
|
|
19
19
|
* SyncImportLocationOptions,
|
|
20
20
|
* ImportLocationOptions,
|
|
21
|
-
* SyncArchiveOptions,
|
|
22
21
|
* LoadLocationOptions,
|
|
23
22
|
* SomeObject,
|
|
24
23
|
* ReadNowPowers,
|
|
25
|
-
* ArchiveOptions,
|
|
26
24
|
* ReadFn,
|
|
27
25
|
* ReadPowers,
|
|
26
|
+
SyncLoadLocationOptions,
|
|
28
27
|
* } from './types.js'
|
|
29
28
|
*/
|
|
30
29
|
|
|
30
|
+
import { loadFromMap } from './import-lite.js';
|
|
31
31
|
import { defaultParserForLanguage } from './import-parsers.js';
|
|
32
32
|
import { mapNodeModules } from './node-modules.js';
|
|
33
|
-
import { loadFromMap } from './import-lite.js';
|
|
34
33
|
|
|
35
34
|
const { assign, create, freeze } = Object;
|
|
36
35
|
|
|
37
36
|
/**
|
|
38
37
|
* Add the default parserForLanguage option.
|
|
39
|
-
* @param {
|
|
40
|
-
* @returns {
|
|
38
|
+
* @param {LoadLocationOptions} [options]
|
|
39
|
+
* @returns {LoadLocationOptions}
|
|
41
40
|
*/
|
|
42
41
|
const assignParserForLanguage = (options = {}) => {
|
|
43
42
|
const { parserForLanguage: parserForLanguageOption, ...rest } = options;
|
|
@@ -52,7 +51,7 @@ const assignParserForLanguage = (options = {}) => {
|
|
|
52
51
|
* @overload
|
|
53
52
|
* @param {ReadNowPowers} readPowers
|
|
54
53
|
* @param {string} moduleLocation
|
|
55
|
-
* @param {
|
|
54
|
+
* @param {SyncLoadLocationOptions} options
|
|
56
55
|
* @returns {Promise<Application>}
|
|
57
56
|
*/
|
|
58
57
|
|
|
@@ -82,6 +81,7 @@ export const loadLocation = async (
|
|
|
82
81
|
commonDependencies,
|
|
83
82
|
policy,
|
|
84
83
|
parserForLanguage,
|
|
84
|
+
log,
|
|
85
85
|
languages,
|
|
86
86
|
languageForExtension,
|
|
87
87
|
commonjsLanguageForExtension,
|
|
@@ -89,6 +89,10 @@ export const loadLocation = async (
|
|
|
89
89
|
workspaceLanguageForExtension,
|
|
90
90
|
workspaceCommonjsLanguageForExtension,
|
|
91
91
|
workspaceModuleLanguageForExtension,
|
|
92
|
+
unknownCanonicalNameHook,
|
|
93
|
+
packageDataHook,
|
|
94
|
+
packageDependenciesHook,
|
|
95
|
+
moduleSourceHook,
|
|
92
96
|
...otherOptions
|
|
93
97
|
} = assignParserForLanguage(options);
|
|
94
98
|
// conditions are not present in SyncArchiveOptions
|
|
@@ -107,9 +111,15 @@ export const loadLocation = async (
|
|
|
107
111
|
workspaceCommonjsLanguageForExtension,
|
|
108
112
|
workspaceModuleLanguageForExtension,
|
|
109
113
|
languages,
|
|
114
|
+
log,
|
|
115
|
+
unknownCanonicalNameHook,
|
|
116
|
+
packageDataHook,
|
|
117
|
+
packageDependenciesHook,
|
|
110
118
|
});
|
|
111
119
|
return loadFromMap(readPowers, compartmentMap, {
|
|
112
120
|
parserForLanguage,
|
|
121
|
+
log,
|
|
122
|
+
moduleSourceHook,
|
|
113
123
|
...otherOptions,
|
|
114
124
|
});
|
|
115
125
|
};
|
|
@@ -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":"AAsIO,+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;uCA1NyD,YAAY;0CAAZ,YAAY;0BAC/C,yBAAyB"}
|
package/src/infer-exports.js
CHANGED
|
@@ -63,13 +63,15 @@ function* interpretBrowserField(name, browser, main = 'index.js') {
|
|
|
63
63
|
* @param {object} exports - the `exports` field from a package.json.
|
|
64
64
|
* @param {Set<string>} conditions - build conditions about the target environment
|
|
65
65
|
* for selecting relevant exports, e.g., "browser" or "node".
|
|
66
|
+
* @param {LanguageForExtension} types - an object to populate
|
|
67
|
+
* with any recognized module's type, if implied by a tag.
|
|
66
68
|
* @yields {[string, string]}
|
|
67
69
|
* @returns {Generator<[string, string]>}
|
|
68
70
|
*/
|
|
69
|
-
function* interpretExports(name, exports, conditions) {
|
|
71
|
+
function* interpretExports(name, exports, conditions, types) {
|
|
70
72
|
if (isArray(exports)) {
|
|
71
73
|
for (const section of exports) {
|
|
72
|
-
const results = [...interpretExports(name, section, conditions)];
|
|
74
|
+
const results = [...interpretExports(name, section, conditions, types)];
|
|
73
75
|
if (results.length > 0) {
|
|
74
76
|
yield* results;
|
|
75
77
|
break;
|
|
@@ -93,12 +95,20 @@ function* interpretExports(name, exports, conditions) {
|
|
|
93
95
|
continue; // or no-op
|
|
94
96
|
} else if (key.startsWith('./') || key === '.') {
|
|
95
97
|
if (name === '.') {
|
|
96
|
-
yield* interpretExports(key, value, conditions);
|
|
98
|
+
yield* interpretExports(key, value, conditions, types);
|
|
97
99
|
} else {
|
|
98
|
-
yield* interpretExports(join(name, key), value, conditions);
|
|
100
|
+
yield* interpretExports(join(name, key), value, conditions, types);
|
|
99
101
|
}
|
|
100
102
|
} else if (conditions.has(key)) {
|
|
101
|
-
|
|
103
|
+
if (types && key === 'import' && typeof value === 'string') {
|
|
104
|
+
// In this one case, the key "import" has carried a hint that the
|
|
105
|
+
// referenced module is an ECMASCript module, and that hint may be
|
|
106
|
+
// necessary to override whatever type might be inferred from the module
|
|
107
|
+
// specifier extension.
|
|
108
|
+
const spec = relativize(value);
|
|
109
|
+
types[spec] = 'mjs';
|
|
110
|
+
}
|
|
111
|
+
yield* interpretExports(name, value, conditions, types);
|
|
102
112
|
// Take only the first matching tag.
|
|
103
113
|
break;
|
|
104
114
|
}
|
|
@@ -141,7 +151,7 @@ export const inferExportsEntries = function* inferExportsEntries(
|
|
|
141
151
|
yield ['.', relativize(main)];
|
|
142
152
|
}
|
|
143
153
|
if (exports !== undefined) {
|
|
144
|
-
yield* interpretExports('.', exports, conditions);
|
|
154
|
+
yield* interpretExports('.', exports, conditions, types);
|
|
145
155
|
}
|
|
146
156
|
// TODO Otherwise, glob 'files' for all '.js', '.cjs', and '.mjs' entry
|
|
147
157
|
// modules, taking care to exclude node_modules.
|
package/src/json.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export function parseLocatedJson(source: string, location: string):
|
|
1
|
+
export function parseLocatedJson<T = any>(source: string, location: string): T;
|
|
2
2
|
//# sourceMappingURL=json.d.ts.map
|
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":"AAgBO,iCANO,CAAC,gBAEJ,MAAM,YACN,MAAM,GACJ,CAAC,CAWb"}
|
package/src/json.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Annotates JSON parse exceptions with the location of the source.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
|
-
* Parses JSON and, if necessary, throws exceptions that include the location
|
|
5
|
-
*
|
|
8
|
+
* Parses JSON and, if necessary, throws exceptions that include the location of
|
|
9
|
+
* the offending file.
|
|
6
10
|
*
|
|
11
|
+
* @template [T=any] The desired type of the parsed JSON. `unknown` is
|
|
12
|
+
* recommended; using the default is unsafe.
|
|
7
13
|
* @param {string} source
|
|
8
14
|
* @param {string} location
|
|
15
|
+
* @returns {T}
|
|
9
16
|
*/
|
|
10
17
|
export const parseLocatedJson = (source, location) => {
|
|
11
18
|
try {
|
package/src/link.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export function link({ entry, compartments: compartmentDescriptors }:
|
|
2
|
-
export function assemble(compartmentMap:
|
|
3
|
-
import type {
|
|
1
|
+
export function link({ entry, compartments: compartmentDescriptors }: PackageCompartmentMapDescriptor | FileCompartmentMapDescriptor, options: LinkOptions): LinkResult;
|
|
2
|
+
export function assemble(compartmentMap: PackageCompartmentMapDescriptor, options: LinkOptions): Compartment;
|
|
3
|
+
import type { PackageCompartmentMapDescriptor } from './types.js';
|
|
4
|
+
import type { FileCompartmentMapDescriptor } from './types.js';
|
|
4
5
|
import type { LinkOptions } from './types.js';
|
|
5
6
|
import type { LinkResult } from './types.js';
|
|
6
7
|
//# sourceMappingURL=link.d.ts.map
|
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":"AA+PO,sEAJI,+BAA+B,GAAC,4BAA4B,WAC5D,WAAW,GACT,UAAU,CAgLtB;AAOM,yCAJI,+BAA+B,WAC/B,WAAW,eAIqB;qDArZjC,YAAY;kDAAZ,YAAY;iCAAZ,YAAY;gCAAZ,YAAY"}
|
package/src/link.js
CHANGED
|
@@ -13,28 +13,38 @@
|
|
|
13
13
|
/**
|
|
14
14
|
* @import {ModuleMapHook} from 'ses'
|
|
15
15
|
* @import {
|
|
16
|
-
* CompartmentDescriptor,
|
|
17
|
-
* CompartmentMapDescriptor,
|
|
18
16
|
* ImportNowHookMaker,
|
|
19
17
|
* LinkOptions,
|
|
20
18
|
* LinkResult,
|
|
21
|
-
* ModuleDescriptor,
|
|
22
19
|
* ParseFn,
|
|
23
20
|
* AsyncParseFn,
|
|
24
21
|
* ParserForLanguage,
|
|
25
22
|
* ParserImplementation,
|
|
26
23
|
* ShouldDeferError,
|
|
24
|
+
* ScopeDescriptor,
|
|
25
|
+
* CompartmentModuleConfiguration,
|
|
26
|
+
* PackageCompartmentMapDescriptor,
|
|
27
|
+
* FileUrlString,
|
|
28
|
+
* PackageCompartmentDescriptor,
|
|
29
|
+
* FileCompartmentMapDescriptor,
|
|
30
|
+
* FileCompartmentDescriptor,
|
|
31
|
+
* FileModuleConfiguration,
|
|
32
|
+
* MakeModuleMapHookOptions,
|
|
27
33
|
* } from './types.js'
|
|
28
34
|
*/
|
|
29
35
|
|
|
30
36
|
import { makeMapParsers } from './map-parser.js';
|
|
31
37
|
import { resolve as resolveFallback } from './node-module-specifier.js';
|
|
32
38
|
import {
|
|
33
|
-
ATTENUATORS_COMPARTMENT,
|
|
34
39
|
attenuateGlobals,
|
|
35
|
-
|
|
40
|
+
enforcePolicyByModule,
|
|
36
41
|
makeDeferredAttenuatorsProvider,
|
|
37
42
|
} from './policy.js';
|
|
43
|
+
import { ATTENUATORS_COMPARTMENT } from './policy-format.js';
|
|
44
|
+
import {
|
|
45
|
+
isCompartmentModuleConfiguration,
|
|
46
|
+
isExitModuleConfiguration,
|
|
47
|
+
} from './guards.js';
|
|
38
48
|
|
|
39
49
|
const { assign, create, entries, freeze } = Object;
|
|
40
50
|
const { hasOwnProperty } = Object.prototype;
|
|
@@ -47,17 +57,17 @@ const { allSettled } = Promise;
|
|
|
47
57
|
*/
|
|
48
58
|
const promiseAllSettled = allSettled.bind(Promise);
|
|
49
59
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
// q, as in quote, for strings in error messages.
|
|
53
|
-
const q = JSON.stringify;
|
|
60
|
+
const DefaultCompartment = Compartment;
|
|
54
61
|
|
|
55
62
|
/**
|
|
63
|
+
* TODO: can we just use `Object.hasOwn` instead?
|
|
56
64
|
* @param {Record<string, unknown>} object
|
|
57
65
|
* @param {string} key
|
|
58
66
|
* @returns {boolean}
|
|
59
67
|
*/
|
|
60
68
|
const has = (object, key) => apply(hasOwnProperty, object, [key]);
|
|
69
|
+
// q, as in quote, for strings in error messages.
|
|
70
|
+
const { quote: q } = assert;
|
|
61
71
|
|
|
62
72
|
/**
|
|
63
73
|
* For a full, absolute module specifier like "dependency",
|
|
@@ -89,11 +99,11 @@ const trimModuleSpecifierPrefix = (moduleSpecifier, prefix) => {
|
|
|
89
99
|
* Any module specifier with an absolute prefix should be captured by
|
|
90
100
|
* the `moduleMap` or `moduleMapHook`.
|
|
91
101
|
*
|
|
92
|
-
* @param {
|
|
102
|
+
* @param {FileCompartmentDescriptor|PackageCompartmentDescriptor} compartmentDescriptor
|
|
93
103
|
* @param {Record<string, Compartment>} compartments
|
|
94
104
|
* @param {string} compartmentName
|
|
95
|
-
* @param {Record<string,
|
|
96
|
-
* @param {Record<string,
|
|
105
|
+
* @param {Record<string, FileModuleConfiguration|CompartmentModuleConfiguration>} moduleDescriptors
|
|
106
|
+
* @param {Record<string, ScopeDescriptor<FileUrlString>>} scopeDescriptors
|
|
97
107
|
* @returns {ModuleMapHook | undefined}
|
|
98
108
|
*/
|
|
99
109
|
const makeModuleMapHook = (
|
|
@@ -104,8 +114,7 @@ const makeModuleMapHook = (
|
|
|
104
114
|
scopeDescriptors,
|
|
105
115
|
) => {
|
|
106
116
|
/**
|
|
107
|
-
* @
|
|
108
|
-
* @returns {string | object | undefined}
|
|
117
|
+
* @type {ModuleMapHook}
|
|
109
118
|
*/
|
|
110
119
|
const moduleMapHook = moduleSpecifier => {
|
|
111
120
|
compartmentDescriptor.retained = true;
|
|
@@ -114,40 +123,42 @@ const makeModuleMapHook = (
|
|
|
114
123
|
if (moduleDescriptor !== undefined) {
|
|
115
124
|
moduleDescriptor.retained = true;
|
|
116
125
|
|
|
126
|
+
if (isExitModuleConfiguration(moduleDescriptor)) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
117
129
|
// "foreignCompartmentName" refers to the compartment which
|
|
118
130
|
// may differ from the current compartment
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
131
|
+
if (isCompartmentModuleConfiguration(moduleDescriptor)) {
|
|
132
|
+
const {
|
|
133
|
+
compartment: foreignCompartmentName = compartmentName,
|
|
134
|
+
module: foreignModuleSpecifier,
|
|
135
|
+
} = moduleDescriptor;
|
|
136
|
+
if (foreignModuleSpecifier !== undefined) {
|
|
137
|
+
// archive goes through foreignModuleSpecifier for local modules too
|
|
138
|
+
if (!moduleSpecifier.startsWith('./')) {
|
|
139
|
+
// This code path seems to only be reached on subsequent imports of the same specifier in the same compartment.
|
|
140
|
+
// The check should be redundant and is only left here out of abundance of caution.
|
|
141
|
+
enforcePolicyByModule(moduleSpecifier, compartmentDescriptor, {
|
|
142
|
+
exit: false,
|
|
143
|
+
errorHint:
|
|
144
|
+
'This check should not be reachable. If you see this error, please file an issue.',
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const foreignCompartment = compartments[foreignCompartmentName];
|
|
149
|
+
if (foreignCompartment === undefined) {
|
|
150
|
+
throw Error(
|
|
151
|
+
`Cannot import from missing compartment ${q(
|
|
152
|
+
foreignCompartmentName,
|
|
153
|
+
)}}`,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
// actual module descriptor
|
|
157
|
+
return {
|
|
158
|
+
compartment: foreignCompartment,
|
|
159
|
+
namespace: foreignModuleSpecifier,
|
|
160
|
+
};
|
|
146
161
|
}
|
|
147
|
-
return {
|
|
148
|
-
compartment: foreignCompartment,
|
|
149
|
-
namespace: foreignModuleSpecifier,
|
|
150
|
-
};
|
|
151
162
|
}
|
|
152
163
|
}
|
|
153
164
|
|
|
@@ -178,7 +189,7 @@ const makeModuleMapHook = (
|
|
|
178
189
|
);
|
|
179
190
|
}
|
|
180
191
|
|
|
181
|
-
|
|
192
|
+
enforcePolicyByModule(scopePrefix, compartmentDescriptor, {
|
|
182
193
|
exit: false,
|
|
183
194
|
errorHint: `Blocked in linking. ${q(
|
|
184
195
|
moduleSpecifier,
|
|
@@ -198,7 +209,9 @@ const makeModuleMapHook = (
|
|
|
198
209
|
retained: true,
|
|
199
210
|
compartment: foreignCompartmentName,
|
|
200
211
|
module: foreignModuleSpecifier,
|
|
212
|
+
__createdBy: 'link',
|
|
201
213
|
};
|
|
214
|
+
// actual module descriptor
|
|
202
215
|
return {
|
|
203
216
|
compartment: foreignCompartment,
|
|
204
217
|
namespace: foreignModuleSpecifier,
|
|
@@ -236,16 +249,10 @@ const impossibleImportNowHookMaker = () => {
|
|
|
236
249
|
* - Passes the given globals and external modules into the root compartment
|
|
237
250
|
* only.
|
|
238
251
|
*
|
|
239
|
-
* @param {
|
|
252
|
+
* @param {PackageCompartmentMapDescriptor|FileCompartmentMapDescriptor} compartmentMap
|
|
240
253
|
* @param {LinkOptions} options
|
|
241
254
|
* @returns {LinkResult} the root compartment of the compartment DAG
|
|
242
255
|
*/
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* @param {CompartmentMapDescriptor} compartmentMap
|
|
246
|
-
* @param {LinkOptions} options
|
|
247
|
-
* @returns {LinkResult}
|
|
248
|
-
*/
|
|
249
256
|
export const link = (
|
|
250
257
|
{ entry, compartments: compartmentDescriptors },
|
|
251
258
|
options,
|
|
@@ -262,7 +269,7 @@ export const link = (
|
|
|
262
269
|
__shimTransforms__ = [],
|
|
263
270
|
__native__ = false,
|
|
264
271
|
archiveOnly = false,
|
|
265
|
-
Compartment =
|
|
272
|
+
Compartment = DefaultCompartment,
|
|
266
273
|
} = options;
|
|
267
274
|
|
|
268
275
|
const { compartment: entryCompartmentName } = entry;
|
|
@@ -291,9 +298,14 @@ export const link = (
|
|
|
291
298
|
syncModuleTransforms,
|
|
292
299
|
});
|
|
293
300
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
301
|
+
const compartmentDescriptorEntries =
|
|
302
|
+
/** @type {[string, PackageCompartmentDescriptor|FileCompartmentDescriptor][]} */ (
|
|
303
|
+
entries(compartmentDescriptors)
|
|
304
|
+
);
|
|
305
|
+
for (const [
|
|
306
|
+
compartmentName,
|
|
307
|
+
compartmentDescriptor,
|
|
308
|
+
] of compartmentDescriptorEntries) {
|
|
297
309
|
const {
|
|
298
310
|
location,
|
|
299
311
|
name,
|
|
@@ -418,7 +430,7 @@ export const link = (
|
|
|
418
430
|
};
|
|
419
431
|
|
|
420
432
|
/**
|
|
421
|
-
* @param {
|
|
433
|
+
* @param {PackageCompartmentMapDescriptor} compartmentMap
|
|
422
434
|
* @param {LinkOptions} options
|
|
423
435
|
* @deprecated Use {@link link}.
|
|
424
436
|
*/
|
package/src/node-modules.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export function basename(location: string): string;
|
|
2
|
-
export function
|
|
3
|
-
export function mapNodeModules(readPowers: ReadFn | ReadPowers | MaybeReadPowers
|
|
2
|
+
export function compartmentMapForNodeModules_(readPowers: ReadFn | ReadPowers<FileUrlString> | MaybeReadPowers<FileUrlString>, entryPackageLocation: FileUrlString, conditionsOption: Set<string>, packageDescriptor: PackageDescriptor, entryModuleSpecifier: string, options?: CompartmentMapForNodeModulesOptions): Promise<PackageCompartmentMapDescriptor>;
|
|
3
|
+
export function mapNodeModules(readPowers: ReadFn | ReadPowers<FileUrlString> | MaybeReadPowers<FileUrlString>, moduleLocation: string, { tags, conditions, log, unknownCanonicalNameHook, packageDataHook, packageDependenciesHook, policy, ...otherOptions }?: MapNodeModulesOptions): Promise<PackageCompartmentMapDescriptor>;
|
|
4
|
+
export function compartmentMapForNodeModules(readPowers: ReadFn | ReadPowers<FileUrlString> | MaybeReadPowers<FileUrlString>, entryPackageLocation: FileUrlString, conditionsOption: Set<string>, packageDescriptor: PackageDescriptor, entryModuleSpecifier: string, options?: CompartmentMapForNodeModulesOptions): Promise<PackageCompartmentMapDescriptor>;
|
|
4
5
|
import type { ReadFn } from './types.js';
|
|
6
|
+
import type { FileUrlString } from './types.js';
|
|
5
7
|
import type { ReadPowers } from './types.js';
|
|
6
8
|
import type { MaybeReadPowers } from './types.js';
|
|
7
9
|
import type { PackageDescriptor } from './types.js';
|
|
8
10
|
import type { CompartmentMapForNodeModulesOptions } from './types.js';
|
|
9
|
-
import type {
|
|
11
|
+
import type { PackageCompartmentMapDescriptor } from './types.js';
|
|
10
12
|
import type { MapNodeModulesOptions } from './types.js';
|
|
11
13
|
//# sourceMappingURL=node-modules.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-modules.d.ts","sourceRoot":"","sources":["node-modules.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node-modules.d.ts","sourceRoot":"","sources":["node-modules.js"],"names":[],"mappings":"AA4LO,mCAHI,MAAM,GACJ,MAAM,CAYlB;AAqlCM,0DARI,MAAM,GAAG,WAAW,aAAa,CAAC,GAAG,gBAAgB,aAAa,CAAC,wBACnE,aAAa,oBACb,GAAG,CAAC,MAAM,CAAC,qBACX,iBAAiB,wBACjB,MAAM,YACN,mCAAmC,GACjC,OAAO,CAAC,+BAA+B,CAAC,CA0HpD;AAaM,2CALI,MAAM,GAAG,WAAW,aAAa,CAAC,GAAG,gBAAgB,aAAa,CAAC,kBACnE,MAAM,2HACN,qBAAqB,GACnB,OAAO,CAAC,+BAA+B,CAAC,CA6CpD;AAhLM,yDARI,MAAM,GAAG,WAAW,aAAa,CAAC,GAAG,gBAAgB,aAAa,CAAC,wBACnE,aAAa,oBACb,GAAG,CAAC,MAAM,CAAC,qBACX,iBAAiB,wBACjB,MAAM,YACN,mCAAmC,GACjC,OAAO,CAAC,+BAA+B,CAAC,CA0HpD;4BA51CS,YAAY;mCAAZ,YAAY;gCAAZ,YAAY;qCAAZ,YAAY;uCAAZ,YAAY;yDAAZ,YAAY;qDAAZ,YAAY;2CAAZ,YAAY"}
|