@endo/compartment-mapper 1.6.3 → 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.map +1 -1
- package/src/generic-graph.js +8 -3
- 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 +138 -69
- 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/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 +4 -3
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +482 -114
- 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 +168 -28
- package/src/types/external.d.ts.map +1 -1
- package/src/types/external.ts +215 -26
- package/src/types/internal.d.ts +23 -42
- package/src/types/internal.d.ts.map +1 -1
- package/src/types/internal.ts +51 -50
- package/src/types/node-modules.d.ts +71 -10
- package/src/types/node-modules.d.ts.map +1 -1
- package/src/types/node-modules.ts +107 -9
- 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/typescript.d.ts +28 -0
- package/src/types/typescript.d.ts.map +1 -1
- package/src/types/typescript.ts +37 -1
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,12 +1,13 @@
|
|
|
1
1
|
export function basename(location: string): string;
|
|
2
|
-
export function
|
|
3
|
-
export function mapNodeModules(readPowers: ReadFn | ReadPowers<FileUrlString> | MaybeReadPowers<FileUrlString>, moduleLocation: string, { tags, conditions, log, ...otherOptions }?: MapNodeModulesOptions): Promise<
|
|
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';
|
|
5
6
|
import type { FileUrlString } from './types.js';
|
|
6
7
|
import type { ReadPowers } from './types.js';
|
|
7
8
|
import type { MaybeReadPowers } from './types.js';
|
|
8
9
|
import type { PackageDescriptor } from './types.js';
|
|
9
10
|
import type { CompartmentMapForNodeModulesOptions } from './types.js';
|
|
10
|
-
import type {
|
|
11
|
+
import type { PackageCompartmentMapDescriptor } from './types.js';
|
|
11
12
|
import type { MapNodeModulesOptions } from './types.js';
|
|
12
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"}
|