@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/bundle.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
// @ts-check
|
|
2
1
|
/* eslint no-shadow: 0 */
|
|
3
2
|
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @import {
|
|
5
|
+
* StaticModuleType,
|
|
6
|
+
* PrecompiledStaticModuleInterface
|
|
7
|
+
* } from 'ses'
|
|
8
|
+
* @import {
|
|
9
|
+
* ArchiveOptions,
|
|
10
|
+
* CompartmentDescriptor,
|
|
11
|
+
* CompartmentSources,
|
|
12
|
+
* MaybeReadPowers,
|
|
13
|
+
* ReadFn,
|
|
14
|
+
* ReadPowers,
|
|
15
|
+
* Sources,
|
|
16
|
+
* WriteFn,
|
|
17
|
+
* } from './types.js'
|
|
18
|
+
*/
|
|
15
19
|
|
|
16
20
|
/**
|
|
17
21
|
* @typedef {object} BundlerKit
|
|
@@ -113,8 +117,14 @@ const sortedModules = (
|
|
|
113
117
|
const source = compartmentSources[compartmentName][moduleSpecifier];
|
|
114
118
|
if (source !== undefined) {
|
|
115
119
|
const { record, parser, deferredError, bytes } = source;
|
|
116
|
-
assert(
|
|
117
|
-
|
|
120
|
+
assert(
|
|
121
|
+
bytes !== undefined,
|
|
122
|
+
`No bytes for ${moduleSpecifier} in ${compartmentName}`,
|
|
123
|
+
);
|
|
124
|
+
assert(
|
|
125
|
+
parser !== undefined,
|
|
126
|
+
`No parser for ${moduleSpecifier} in ${compartmentName}`,
|
|
127
|
+
);
|
|
118
128
|
if (deferredError) {
|
|
119
129
|
throw Error(
|
|
120
130
|
`Cannot bundle: encountered deferredError ${deferredError}`,
|
|
@@ -231,6 +241,13 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
|
|
|
231
241
|
sourceMapHook = undefined,
|
|
232
242
|
parserForLanguage: parserForLanguageOption = {},
|
|
233
243
|
languageForExtension: languageForExtensionOption = {},
|
|
244
|
+
commonjsLanguageForExtension: commonjsLanguageForExtensionOption = {},
|
|
245
|
+
moduleLanguageForExtension: moduleLanguageForExtensionOption = {},
|
|
246
|
+
workspaceLanguageForExtension: workspaceLanguageForExtensionOption = {},
|
|
247
|
+
workspaceCommonjsLanguageForExtension:
|
|
248
|
+
workspaceCommonjsLanguageForExtensionOption = {},
|
|
249
|
+
workspaceModuleLanguageForExtension:
|
|
250
|
+
workspaceModuleLanguageForExtensionOption = {},
|
|
234
251
|
} = options || {};
|
|
235
252
|
const conditions = new Set(conditionsOption);
|
|
236
253
|
|
|
@@ -244,6 +261,27 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
|
|
|
244
261
|
const languageForExtension = Object.freeze(
|
|
245
262
|
Object.assign(Object.create(null), languageForExtensionOption),
|
|
246
263
|
);
|
|
264
|
+
const commonjsLanguageForExtension = Object.freeze(
|
|
265
|
+
Object.assign(Object.create(null), commonjsLanguageForExtensionOption),
|
|
266
|
+
);
|
|
267
|
+
const moduleLanguageForExtension = Object.freeze(
|
|
268
|
+
Object.assign(Object.create(null), moduleLanguageForExtensionOption),
|
|
269
|
+
);
|
|
270
|
+
const workspaceLanguageForExtension = Object.freeze(
|
|
271
|
+
Object.assign(Object.create(null), workspaceLanguageForExtensionOption),
|
|
272
|
+
);
|
|
273
|
+
const workspaceCommonjsLanguageForExtension = Object.freeze(
|
|
274
|
+
Object.assign(
|
|
275
|
+
Object.create(null),
|
|
276
|
+
workspaceCommonjsLanguageForExtensionOption,
|
|
277
|
+
),
|
|
278
|
+
);
|
|
279
|
+
const workspaceModuleLanguageForExtension = Object.freeze(
|
|
280
|
+
Object.assign(
|
|
281
|
+
Object.create(null),
|
|
282
|
+
workspaceModuleLanguageForExtensionOption,
|
|
283
|
+
),
|
|
284
|
+
);
|
|
247
285
|
|
|
248
286
|
const {
|
|
249
287
|
packageLocation,
|
|
@@ -262,7 +300,16 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
|
|
|
262
300
|
conditions,
|
|
263
301
|
packageDescriptor,
|
|
264
302
|
moduleSpecifier,
|
|
265
|
-
{
|
|
303
|
+
{
|
|
304
|
+
dev,
|
|
305
|
+
commonDependencies,
|
|
306
|
+
languageForExtension,
|
|
307
|
+
commonjsLanguageForExtension,
|
|
308
|
+
moduleLanguageForExtension,
|
|
309
|
+
workspaceLanguageForExtension,
|
|
310
|
+
workspaceCommonjsLanguageForExtension,
|
|
311
|
+
workspaceModuleLanguageForExtension,
|
|
312
|
+
},
|
|
266
313
|
);
|
|
267
314
|
|
|
268
315
|
const {
|
|
@@ -287,7 +334,6 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
|
|
|
287
334
|
makeImportHook,
|
|
288
335
|
moduleTransforms,
|
|
289
336
|
parserForLanguage,
|
|
290
|
-
languageForExtension,
|
|
291
337
|
});
|
|
292
338
|
await compartment.load(entryModuleSpecifier);
|
|
293
339
|
|
package/src/capture-lite.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export function captureFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?:
|
|
1
|
+
export function captureFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: CaptureLiteOptions | undefined): Promise<CaptureResult>;
|
|
2
2
|
import type { ReadFn } from './types.js';
|
|
3
3
|
import type { ReadPowers } from './types.js';
|
|
4
4
|
import type { CompartmentMapDescriptor } from './types.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { CaptureLiteOptions } from './types.js';
|
|
6
6
|
import type { CaptureResult } from './types.js';
|
|
7
7
|
//# sourceMappingURL=capture-lite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture-lite.d.ts","sourceRoot":"","sources":["capture-lite.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"capture-lite.d.ts","sourceRoot":"","sources":["capture-lite.js"],"names":[],"mappings":"AAoFO,uCALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,aAAa,CAAC,CAmElC;4BA9GS,YAAY;gCAAZ,YAAY;8CAAZ,YAAY;wCAAZ,YAAY;mCAAZ,YAAY"}
|
package/src/capture-lite.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @module
|
|
2
3
|
* This module provides {@link captureFromMap}, which only "captures" the
|
|
3
4
|
* compartment map descriptors and sources from a partially completed
|
|
4
5
|
* compartment map--_without_ creating an archive. The resulting compartment map
|
|
@@ -24,27 +25,21 @@
|
|
|
24
25
|
* contain original sources, so to import the archive with
|
|
25
26
|
* `src/import-archive-lite.js`, you will need to provide the archive parsers
|
|
26
27
|
* and entrain a runtime dependency on Babel.
|
|
27
|
-
*
|
|
28
|
-
* @module
|
|
29
28
|
*/
|
|
30
29
|
|
|
31
|
-
// @ts-check
|
|
32
30
|
/* eslint no-shadow: 0 */
|
|
33
31
|
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
/**
|
|
33
|
+
* @import {
|
|
34
|
+
* CaptureLiteOptions,
|
|
35
|
+
* CaptureResult,
|
|
36
|
+
* CompartmentMapDescriptor,
|
|
37
|
+
* ReadFn,
|
|
38
|
+
* ReadPowers,
|
|
39
|
+
* Sources,
|
|
40
|
+
* } from './types.js'
|
|
41
|
+
*/
|
|
42
42
|
|
|
43
|
-
import {
|
|
44
|
-
assertCompartmentMap,
|
|
45
|
-
pathCompare,
|
|
46
|
-
stringCompare,
|
|
47
|
-
} from './compartment-map.js';
|
|
48
43
|
import {
|
|
49
44
|
exitModuleImportHookMaker,
|
|
50
45
|
makeImportHookMaker,
|
|
@@ -53,158 +48,11 @@ import { link } from './link.js';
|
|
|
53
48
|
import { resolve } from './node-module-specifier.js';
|
|
54
49
|
import { detectAttenuators } from './policy.js';
|
|
55
50
|
import { unpackReadPowers } from './powers.js';
|
|
51
|
+
import { digestCompartmentMap } from './digest.js';
|
|
56
52
|
|
|
57
|
-
const { freeze, assign, create
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* We attempt to produce compartment maps that are consistent regardless of
|
|
61
|
-
* whether the packages were originally laid out on disk for development or
|
|
62
|
-
* production, and other trivia like the fully qualified path of a specific
|
|
63
|
-
* installation.
|
|
64
|
-
*
|
|
65
|
-
* Naming compartments for the self-ascribed name and version of each Node.js
|
|
66
|
-
* package is insufficient because they are not guaranteed to be unique.
|
|
67
|
-
* Dependencies do not necessarilly come from the npm registry and may be
|
|
68
|
-
* for example derived from fully qualified URL's or Github org and project
|
|
69
|
-
* names.
|
|
70
|
-
* Package managers are also not required to fully deduplicate the hard
|
|
71
|
-
* copy of each package even when they are identical resources.
|
|
72
|
-
* Duplication is undesirable, but we elect to defer that problem to solutions
|
|
73
|
-
* in the package managers, as the alternative would be to consistently hash
|
|
74
|
-
* the original sources of the packages themselves, which may not even be
|
|
75
|
-
* available much less pristine for us.
|
|
76
|
-
*
|
|
77
|
-
* So, instead, we use the lexically least path of dependency names, delimited
|
|
78
|
-
* by hashes.
|
|
79
|
-
* The compartment maps generated by the ./node-modules.js tooling pre-compute
|
|
80
|
-
* these traces for our use here.
|
|
81
|
-
* We sort the compartments lexically on their self-ascribed name and version,
|
|
82
|
-
* and use the lexically least dependency name path as a tie-breaker.
|
|
83
|
-
* The dependency path is logical and orthogonal to the package manager's
|
|
84
|
-
* actual installation location, so should be orthogonal to the vagaries of the
|
|
85
|
-
* package manager's deduplication algorithm.
|
|
86
|
-
*
|
|
87
|
-
* @param {Record<string, CompartmentDescriptor>} compartments
|
|
88
|
-
* @returns {Record<string, string>} map from old to new compartment names.
|
|
89
|
-
*/
|
|
90
|
-
const renameCompartments = compartments => {
|
|
91
|
-
/** @type {Record<string, string>} */
|
|
92
|
-
const compartmentRenames = create(null);
|
|
93
|
-
let index = 0;
|
|
94
|
-
let prev = '';
|
|
95
|
-
|
|
96
|
-
// The sort below combines two comparators to avoid depending on sort
|
|
97
|
-
// stability, which became standard as recently as 2019.
|
|
98
|
-
// If that date seems quaint, please accept my regards from the distant past.
|
|
99
|
-
// We are very proud of you.
|
|
100
|
-
const compartmentsByPath = Object.entries(compartments)
|
|
101
|
-
.map(([name, compartment]) => ({
|
|
102
|
-
name,
|
|
103
|
-
path: compartment.path,
|
|
104
|
-
label: compartment.label,
|
|
105
|
-
}))
|
|
106
|
-
.sort((a, b) => {
|
|
107
|
-
if (a.label === b.label) {
|
|
108
|
-
assert(a.path !== undefined && b.path !== undefined);
|
|
109
|
-
return pathCompare(a.path, b.path);
|
|
110
|
-
}
|
|
111
|
-
return stringCompare(a.label, b.label);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
for (const { name, label } of compartmentsByPath) {
|
|
115
|
-
if (label === prev) {
|
|
116
|
-
compartmentRenames[name] = `${label}-n${index}`;
|
|
117
|
-
index += 1;
|
|
118
|
-
} else {
|
|
119
|
-
compartmentRenames[name] = label;
|
|
120
|
-
prev = label;
|
|
121
|
-
index = 1;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return compartmentRenames;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @param {Record<string, CompartmentDescriptor>} compartments
|
|
129
|
-
* @param {Sources} sources
|
|
130
|
-
* @param {Record<string, string>} compartmentRenames
|
|
131
|
-
*/
|
|
132
|
-
const translateCompartmentMap = (compartments, sources, compartmentRenames) => {
|
|
133
|
-
const result = create(null);
|
|
134
|
-
for (const compartmentName of keys(compartmentRenames)) {
|
|
135
|
-
const compartment = compartments[compartmentName];
|
|
136
|
-
const { name, label, retained, policy } = compartment;
|
|
137
|
-
if (retained) {
|
|
138
|
-
// rename module compartments
|
|
139
|
-
/** @type {Record<string, ModuleDescriptor>} */
|
|
140
|
-
const modules = create(null);
|
|
141
|
-
const compartmentModules = compartment.modules;
|
|
142
|
-
if (compartment.modules) {
|
|
143
|
-
for (const name of keys(compartmentModules).sort()) {
|
|
144
|
-
const module = compartmentModules[name];
|
|
145
|
-
if (module.compartment !== undefined) {
|
|
146
|
-
modules[name] = {
|
|
147
|
-
...module,
|
|
148
|
-
compartment: compartmentRenames[module.compartment],
|
|
149
|
-
};
|
|
150
|
-
} else {
|
|
151
|
-
modules[name] = module;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// integrate sources into modules
|
|
157
|
-
const compartmentSources = sources[compartmentName];
|
|
158
|
-
if (compartmentSources) {
|
|
159
|
-
for (const name of keys(compartmentSources).sort()) {
|
|
160
|
-
const source = compartmentSources[name];
|
|
161
|
-
const { location, parser, exit, sha512, deferredError } = source;
|
|
162
|
-
if (location !== undefined) {
|
|
163
|
-
modules[name] = {
|
|
164
|
-
location,
|
|
165
|
-
parser,
|
|
166
|
-
sha512,
|
|
167
|
-
};
|
|
168
|
-
} else if (exit !== undefined) {
|
|
169
|
-
modules[name] = {
|
|
170
|
-
exit,
|
|
171
|
-
};
|
|
172
|
-
} else if (deferredError !== undefined) {
|
|
173
|
-
modules[name] = {
|
|
174
|
-
deferredError,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
53
|
+
const { freeze, assign, create } = Object;
|
|
179
54
|
|
|
180
|
-
|
|
181
|
-
name,
|
|
182
|
-
label,
|
|
183
|
-
location: compartmentRenames[compartmentName],
|
|
184
|
-
modules,
|
|
185
|
-
policy,
|
|
186
|
-
// `scopes`, `types`, and `parsers` are not necessary since every
|
|
187
|
-
// loadable module is captured in `modules`.
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return result;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* @param {Sources} sources
|
|
197
|
-
* @param {Record<string, string>} compartmentRenames
|
|
198
|
-
* @returns {Sources}
|
|
199
|
-
*/
|
|
200
|
-
const renameSources = (sources, compartmentRenames) => {
|
|
201
|
-
return fromEntries(
|
|
202
|
-
entries(sources).map(([name, compartmentSources]) => [
|
|
203
|
-
compartmentRenames[name],
|
|
204
|
-
compartmentSources,
|
|
205
|
-
]),
|
|
206
|
-
);
|
|
207
|
-
};
|
|
55
|
+
const defaultCompartment = Compartment;
|
|
208
56
|
|
|
209
57
|
/**
|
|
210
58
|
* @param {CompartmentMapDescriptor} compartmentMap
|
|
@@ -213,67 +61,43 @@ const renameSources = (sources, compartmentRenames) => {
|
|
|
213
61
|
*/
|
|
214
62
|
const captureCompartmentMap = (compartmentMap, sources) => {
|
|
215
63
|
const {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const compartmentRenames = renameCompartments(compartments);
|
|
221
|
-
const captureCompartments = translateCompartmentMap(
|
|
222
|
-
compartments,
|
|
223
|
-
sources,
|
|
64
|
+
compartmentMap: captureCompartmentMap,
|
|
65
|
+
sources: captureSources,
|
|
66
|
+
newToOldCompartmentNames,
|
|
224
67
|
compartmentRenames,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const captureSources = renameSources(sources, compartmentRenames);
|
|
228
|
-
|
|
229
|
-
const captureCompartmentMap = {
|
|
230
|
-
// TODO graceful migration from tags to conditions
|
|
231
|
-
// https://github.com/endojs/endo/issues/2388
|
|
232
|
-
tags: [],
|
|
233
|
-
entry: {
|
|
234
|
-
compartment: captureEntryCompartmentName,
|
|
235
|
-
module: entryModuleSpecifier,
|
|
236
|
-
},
|
|
237
|
-
compartments: captureCompartments,
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
// Cross-check:
|
|
241
|
-
// We assert that we have constructed a valid compartment map, not because it
|
|
242
|
-
// might not be, but to ensure that the assertCompartmentMap function can
|
|
243
|
-
// accept all valid compartment maps.
|
|
244
|
-
assertCompartmentMap(captureCompartmentMap);
|
|
245
|
-
|
|
68
|
+
oldToNewCompartmentNames,
|
|
69
|
+
} = digestCompartmentMap(compartmentMap, sources);
|
|
246
70
|
return {
|
|
247
71
|
captureCompartmentMap,
|
|
248
72
|
captureSources,
|
|
249
73
|
compartmentRenames,
|
|
74
|
+
newToOldCompartmentNames,
|
|
75
|
+
oldToNewCompartmentNames,
|
|
250
76
|
};
|
|
251
77
|
};
|
|
252
78
|
|
|
253
79
|
/**
|
|
254
80
|
* @param {ReadFn | ReadPowers} powers
|
|
255
81
|
* @param {CompartmentMapDescriptor} compartmentMap
|
|
256
|
-
* @param {
|
|
82
|
+
* @param {CaptureLiteOptions} [options]
|
|
257
83
|
* @returns {Promise<CaptureResult>}
|
|
258
84
|
*/
|
|
259
85
|
export const captureFromMap = async (powers, compartmentMap, options = {}) => {
|
|
260
86
|
const {
|
|
261
87
|
moduleTransforms,
|
|
88
|
+
syncModuleTransforms,
|
|
262
89
|
modules: exitModules = {},
|
|
263
90
|
searchSuffixes = undefined,
|
|
264
91
|
importHook: exitModuleImportHook = undefined,
|
|
265
92
|
policy = undefined,
|
|
266
93
|
sourceMapHook = undefined,
|
|
267
94
|
parserForLanguage: parserForLanguageOption = {},
|
|
268
|
-
|
|
95
|
+
Compartment = defaultCompartment,
|
|
269
96
|
} = options;
|
|
270
97
|
|
|
271
98
|
const parserForLanguage = freeze(
|
|
272
99
|
assign(create(null), parserForLanguageOption),
|
|
273
100
|
);
|
|
274
|
-
const languageForExtension = freeze(
|
|
275
|
-
assign(create(null), languageForExtensionOption),
|
|
276
|
-
);
|
|
277
101
|
|
|
278
102
|
const { read, computeSha512 } = unpackReadPowers(powers);
|
|
279
103
|
|
|
@@ -288,6 +112,7 @@ export const captureFromMap = async (powers, compartmentMap, options = {}) => {
|
|
|
288
112
|
const consolidatedExitModuleImportHook = exitModuleImportHookMaker({
|
|
289
113
|
modules: exitModules,
|
|
290
114
|
exitModuleImportHook,
|
|
115
|
+
entryCompartmentName,
|
|
291
116
|
});
|
|
292
117
|
|
|
293
118
|
const makeImportHook = makeImportHookMaker(read, entryCompartmentName, {
|
|
@@ -306,9 +131,10 @@ export const captureFromMap = async (powers, compartmentMap, options = {}) => {
|
|
|
306
131
|
resolve,
|
|
307
132
|
makeImportHook,
|
|
308
133
|
moduleTransforms,
|
|
134
|
+
syncModuleTransforms,
|
|
309
135
|
parserForLanguage,
|
|
310
|
-
languageForExtension,
|
|
311
136
|
archiveOnly: true,
|
|
137
|
+
Compartment,
|
|
312
138
|
});
|
|
313
139
|
await compartment.load(entryModuleSpecifier);
|
|
314
140
|
if (policy) {
|
package/src/compartment-map.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @type {(a: string, b: string) => number} */
|
|
2
2
|
export const stringCompare: (a: string, b: string) => number;
|
|
3
3
|
export function pathCompare(a: Array<string> | undefined, b: Array<string> | undefined): number;
|
|
4
|
-
export function assertCompartmentMap(allegedCompartmentMap: unknown, url?: string | undefined): asserts allegedCompartmentMap is
|
|
4
|
+
export function assertCompartmentMap(allegedCompartmentMap: unknown, url?: string | undefined): asserts allegedCompartmentMap is CompartmentMapDescriptor;
|
|
5
|
+
import type { CompartmentMapDescriptor } from './types.js';
|
|
5
6
|
//# sourceMappingURL=compartment-map.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compartment-map.d.ts","sourceRoot":"","sources":["compartment-map.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compartment-map.d.ts","sourceRoot":"","sources":["compartment-map.js"],"names":[],"mappings":"AAYA,+CAA+C;AAE/C,4BAFW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAE2B;AAc/D,+BAHI,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,KACzB,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,UAqCnC;AA8ZM,4DALI,OAAO,6BAEL,QAAQ,qBAAqB,IAAI,wBAAwB,CA+BrE;8CArf2C,YAAY"}
|
package/src/compartment-map.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* Validates a compartment map against its schema. */
|
|
2
2
|
|
|
3
|
-
// @ts-check
|
|
4
3
|
import { assertPackagePolicy } from './policy-format.js';
|
|
5
4
|
|
|
5
|
+
/** @import {CompartmentMapDescriptor} from './types.js' */
|
|
6
|
+
|
|
6
7
|
// TODO convert to the new `||` assert style.
|
|
7
8
|
// Deferred because this file pervasively uses simple template strings rather than
|
|
8
9
|
// template strings tagged with `assert.details` (aka `X`), and uses
|
|
@@ -107,7 +108,7 @@ const assertConditions = (conditions, url) => {
|
|
|
107
108
|
* @param {string} url
|
|
108
109
|
*/
|
|
109
110
|
const assertCompartmentModule = (allegedModule, path, url) => {
|
|
110
|
-
const { compartment, module, ...extra } = allegedModule;
|
|
111
|
+
const { compartment, module, retained, ...extra } = allegedModule;
|
|
111
112
|
assertEmptyObject(
|
|
112
113
|
extra,
|
|
113
114
|
`${path} must not have extra properties, got ${q({
|
|
@@ -125,6 +126,13 @@ const assertCompartmentModule = (allegedModule, path, url) => {
|
|
|
125
126
|
'string',
|
|
126
127
|
`${path}.module must be a string, got ${q(module)} in ${q(url)}`,
|
|
127
128
|
);
|
|
129
|
+
if (retained !== undefined) {
|
|
130
|
+
assert.typeof(
|
|
131
|
+
retained,
|
|
132
|
+
'boolean',
|
|
133
|
+
`${path}.retained must be a boolean, got ${q(retained)} in ${q(url)}`,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
128
136
|
};
|
|
129
137
|
|
|
130
138
|
/**
|
|
@@ -464,7 +472,7 @@ const assertEntry = (allegedEntry, url) => {
|
|
|
464
472
|
/**
|
|
465
473
|
* @param {unknown} allegedCompartmentMap
|
|
466
474
|
* @param {string} [url]
|
|
467
|
-
* @returns {asserts allegedCompartmentMap is
|
|
475
|
+
* @returns {asserts allegedCompartmentMap is CompartmentMapDescriptor}
|
|
468
476
|
*/
|
|
469
477
|
|
|
470
478
|
export const assertCompartmentMap = (
|
package/src/digest.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function digestCompartmentMap(compartmentMap: CompartmentMapDescriptor, sources: Sources): DigestResult;
|
|
2
|
+
import type { CompartmentMapDescriptor } from './types.js';
|
|
3
|
+
import type { Sources } from './types.js';
|
|
4
|
+
import type { DigestResult } from './types.js';
|
|
5
|
+
//# sourceMappingURL=digest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["digest.js"],"names":[],"mappings":"AAwLO,qDAJI,wBAAwB,WACxB,OAAO,GACL,YAAY,CAoDxB;8CA3NS,YAAY;6BAAZ,YAAY;kCAAZ,YAAY"}
|