@endo/compartment-mapper 1.4.0 → 1.6.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 +292 -111
- package/bundle.d.ts +1 -1
- package/bundle.js +4 -1
- package/functor-lite.d.ts +3 -0
- package/functor-lite.d.ts.map +1 -0
- package/functor-lite.js +4 -0
- package/functor.d.ts +3 -0
- package/functor.d.ts.map +1 -0
- package/functor.js +4 -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/index.d.ts +1 -1
- package/index.js +4 -1
- package/package.json +14 -5
- package/script-lite.d.ts +3 -0
- package/script-lite.d.ts.map +1 -0
- package/script-lite.js +4 -0
- package/script.d.ts +3 -0
- package/script.d.ts.map +1 -0
- package/script.js +4 -0
- package/src/archive-lite.d.ts +2 -4
- package/src/archive-lite.d.ts.map +1 -1
- package/src/archive-lite.js +16 -192
- package/src/archive.d.ts.map +1 -1
- package/src/archive.js +8 -0
- package/src/bundle-cjs.d.ts +1 -1
- package/src/bundle-cjs.d.ts.map +1 -1
- package/src/bundle-cjs.js +57 -28
- package/src/bundle-json.d.ts.map +1 -1
- package/src/bundle-json.js +2 -3
- package/src/bundle-lite.d.ts +91 -0
- package/src/bundle-lite.d.ts.map +1 -0
- package/src/bundle-lite.js +668 -0
- package/src/bundle-mjs.d.ts +2 -2
- package/src/bundle-mjs.d.ts.map +1 -1
- package/src/bundle-mjs.js +36 -19
- package/src/bundle.d.ts +48 -10
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +399 -127
- package/src/capture-lite.d.ts.map +1 -1
- package/src/capture-lite.js +10 -188
- package/src/digest.d.ts +5 -0
- package/src/digest.d.ts.map +1 -0
- package/src/digest.js +235 -0
- 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.map +1 -1
- package/src/import-archive-lite.js +4 -0
- package/src/import-hook.d.ts +3 -16
- package/src/import-hook.d.ts.map +1 -1
- package/src/import-hook.js +11 -18
- package/src/import-lite.d.ts.map +1 -1
- package/src/import-lite.js +7 -2
- package/src/import.d.ts.map +1 -1
- package/src/import.js +2 -0
- package/src/link.d.ts.map +1 -1
- package/src/link.js +2 -0
- package/src/map-parser.d.ts.map +1 -1
- package/src/map-parser.js +4 -1
- package/src/node-modules.d.ts +4 -47
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +157 -131
- package/src/parse-archive-cjs.d.ts.map +1 -1
- package/src/parse-archive-cjs.js +8 -3
- package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
- package/src/parse-cjs-shared-export-wrapper.js +2 -10
- package/src/parse-cjs.js +1 -1
- package/src/parse-mjs.js +2 -2
- package/src/policy.d.ts.map +1 -1
- package/src/policy.js +4 -7
- package/src/search.d.ts +6 -12
- package/src/search.d.ts.map +1 -1
- package/src/search.js +29 -12
- package/src/types/compartment-map-schema.d.ts +5 -0
- package/src/types/compartment-map-schema.d.ts.map +1 -1
- package/src/types/compartment-map-schema.ts +5 -0
- package/src/types/external.d.ts +159 -12
- package/src/types/external.d.ts.map +1 -1
- package/src/types/external.ts +180 -12
- package/src/types/internal.d.ts +86 -13
- package/src/types/internal.d.ts.map +1 -1
- package/src/types/internal.ts +107 -13
- package/src/types/node-modules.d.ts +79 -0
- package/src/types/node-modules.d.ts.map +1 -0
- package/src/types/node-modules.ts +89 -0
- package/src/types/node-powers.d.ts +4 -4
- package/src/types/node-powers.d.ts.map +1 -1
- package/src/types/node-powers.ts +4 -4
- package/src/types/powers.d.ts +2 -2
- package/src/types/powers.d.ts.map +1 -1
- package/src/types/powers.ts +2 -2
|
@@ -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
|
@@ -33,20 +33,13 @@
|
|
|
33
33
|
* @import {
|
|
34
34
|
* CaptureLiteOptions,
|
|
35
35
|
* CaptureResult,
|
|
36
|
-
* CompartmentDescriptor,
|
|
37
36
|
* CompartmentMapDescriptor,
|
|
38
|
-
* ModuleDescriptor,
|
|
39
37
|
* ReadFn,
|
|
40
38
|
* ReadPowers,
|
|
41
39
|
* Sources,
|
|
42
40
|
* } from './types.js'
|
|
43
41
|
*/
|
|
44
42
|
|
|
45
|
-
import {
|
|
46
|
-
assertCompartmentMap,
|
|
47
|
-
pathCompare,
|
|
48
|
-
stringCompare,
|
|
49
|
-
} from './compartment-map.js';
|
|
50
43
|
import {
|
|
51
44
|
exitModuleImportHookMaker,
|
|
52
45
|
makeImportHookMaker,
|
|
@@ -55,161 +48,12 @@ import { link } from './link.js';
|
|
|
55
48
|
import { resolve } from './node-module-specifier.js';
|
|
56
49
|
import { detectAttenuators } from './policy.js';
|
|
57
50
|
import { unpackReadPowers } from './powers.js';
|
|
51
|
+
import { digestCompartmentMap } from './digest.js';
|
|
58
52
|
|
|
59
|
-
const { freeze, assign, create
|
|
53
|
+
const { freeze, assign, create } = Object;
|
|
60
54
|
|
|
61
55
|
const defaultCompartment = Compartment;
|
|
62
56
|
|
|
63
|
-
/**
|
|
64
|
-
* We attempt to produce compartment maps that are consistent regardless of
|
|
65
|
-
* whether the packages were originally laid out on disk for development or
|
|
66
|
-
* production, and other trivia like the fully qualified path of a specific
|
|
67
|
-
* installation.
|
|
68
|
-
*
|
|
69
|
-
* Naming compartments for the self-ascribed name and version of each Node.js
|
|
70
|
-
* package is insufficient because they are not guaranteed to be unique.
|
|
71
|
-
* Dependencies do not necessarilly come from the npm registry and may be
|
|
72
|
-
* for example derived from fully qualified URL's or Github org and project
|
|
73
|
-
* names.
|
|
74
|
-
* Package managers are also not required to fully deduplicate the hard
|
|
75
|
-
* copy of each package even when they are identical resources.
|
|
76
|
-
* Duplication is undesirable, but we elect to defer that problem to solutions
|
|
77
|
-
* in the package managers, as the alternative would be to consistently hash
|
|
78
|
-
* the original sources of the packages themselves, which may not even be
|
|
79
|
-
* available much less pristine for us.
|
|
80
|
-
*
|
|
81
|
-
* So, instead, we use the lexically least path of dependency names, delimited
|
|
82
|
-
* by hashes.
|
|
83
|
-
* The compartment maps generated by the ./node-modules.js tooling pre-compute
|
|
84
|
-
* these traces for our use here.
|
|
85
|
-
* We sort the compartments lexically on their self-ascribed name and version,
|
|
86
|
-
* and use the lexically least dependency name path as a tie-breaker.
|
|
87
|
-
* The dependency path is logical and orthogonal to the package manager's
|
|
88
|
-
* actual installation location, so should be orthogonal to the vagaries of the
|
|
89
|
-
* package manager's deduplication algorithm.
|
|
90
|
-
*
|
|
91
|
-
* @param {Record<string, CompartmentDescriptor>} compartments
|
|
92
|
-
* @returns {Record<string, string>} map from old to new compartment names.
|
|
93
|
-
*/
|
|
94
|
-
const renameCompartments = compartments => {
|
|
95
|
-
/** @type {Record<string, string>} */
|
|
96
|
-
const compartmentRenames = create(null);
|
|
97
|
-
let index = 0;
|
|
98
|
-
let prev = '';
|
|
99
|
-
|
|
100
|
-
// The sort below combines two comparators to avoid depending on sort
|
|
101
|
-
// stability, which became standard as recently as 2019.
|
|
102
|
-
// If that date seems quaint, please accept my regards from the distant past.
|
|
103
|
-
// We are very proud of you.
|
|
104
|
-
const compartmentsByPath = Object.entries(compartments)
|
|
105
|
-
.map(([name, compartment]) => ({
|
|
106
|
-
name,
|
|
107
|
-
path: compartment.path,
|
|
108
|
-
label: compartment.label,
|
|
109
|
-
}))
|
|
110
|
-
.sort((a, b) => {
|
|
111
|
-
if (a.label === b.label) {
|
|
112
|
-
assert(a.path !== undefined && b.path !== undefined);
|
|
113
|
-
return pathCompare(a.path, b.path);
|
|
114
|
-
}
|
|
115
|
-
return stringCompare(a.label, b.label);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
for (const { name, label } of compartmentsByPath) {
|
|
119
|
-
if (label === prev) {
|
|
120
|
-
compartmentRenames[name] = `${label}-n${index}`;
|
|
121
|
-
index += 1;
|
|
122
|
-
} else {
|
|
123
|
-
compartmentRenames[name] = label;
|
|
124
|
-
prev = label;
|
|
125
|
-
index = 1;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return compartmentRenames;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @param {Record<string, CompartmentDescriptor>} compartments
|
|
133
|
-
* @param {Sources} sources
|
|
134
|
-
* @param {Record<string, string>} compartmentRenames
|
|
135
|
-
*/
|
|
136
|
-
const translateCompartmentMap = (compartments, sources, compartmentRenames) => {
|
|
137
|
-
const result = create(null);
|
|
138
|
-
for (const compartmentName of keys(compartmentRenames)) {
|
|
139
|
-
const compartment = compartments[compartmentName];
|
|
140
|
-
const { name, label, retained, policy } = compartment;
|
|
141
|
-
if (retained) {
|
|
142
|
-
// rename module compartments
|
|
143
|
-
/** @type {Record<string, ModuleDescriptor>} */
|
|
144
|
-
const modules = create(null);
|
|
145
|
-
const compartmentModules = compartment.modules;
|
|
146
|
-
if (compartment.modules) {
|
|
147
|
-
for (const name of keys(compartmentModules).sort()) {
|
|
148
|
-
const module = compartmentModules[name];
|
|
149
|
-
if (module.compartment !== undefined) {
|
|
150
|
-
modules[name] = {
|
|
151
|
-
...module,
|
|
152
|
-
compartment: compartmentRenames[module.compartment],
|
|
153
|
-
};
|
|
154
|
-
} else {
|
|
155
|
-
modules[name] = module;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// integrate sources into modules
|
|
161
|
-
const compartmentSources = sources[compartmentName];
|
|
162
|
-
if (compartmentSources) {
|
|
163
|
-
for (const name of keys(compartmentSources).sort()) {
|
|
164
|
-
const source = compartmentSources[name];
|
|
165
|
-
const { location, parser, exit, sha512, deferredError } = source;
|
|
166
|
-
if (location !== undefined) {
|
|
167
|
-
modules[name] = {
|
|
168
|
-
location,
|
|
169
|
-
parser,
|
|
170
|
-
sha512,
|
|
171
|
-
};
|
|
172
|
-
} else if (exit !== undefined) {
|
|
173
|
-
modules[name] = {
|
|
174
|
-
exit,
|
|
175
|
-
};
|
|
176
|
-
} else if (deferredError !== undefined) {
|
|
177
|
-
modules[name] = {
|
|
178
|
-
deferredError,
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
result[compartmentRenames[compartmentName]] = {
|
|
185
|
-
name,
|
|
186
|
-
label,
|
|
187
|
-
location: compartmentRenames[compartmentName],
|
|
188
|
-
modules,
|
|
189
|
-
policy,
|
|
190
|
-
// `scopes`, `types`, and `parsers` are not necessary since every
|
|
191
|
-
// loadable module is captured in `modules`.
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return result;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* @param {Sources} sources
|
|
201
|
-
* @param {Record<string, string>} compartmentRenames
|
|
202
|
-
* @returns {Sources}
|
|
203
|
-
*/
|
|
204
|
-
const renameSources = (sources, compartmentRenames) => {
|
|
205
|
-
return fromEntries(
|
|
206
|
-
entries(sources).map(([name, compartmentSources]) => [
|
|
207
|
-
compartmentRenames[name],
|
|
208
|
-
compartmentSources,
|
|
209
|
-
]),
|
|
210
|
-
);
|
|
211
|
-
};
|
|
212
|
-
|
|
213
57
|
/**
|
|
214
58
|
* @param {CompartmentMapDescriptor} compartmentMap
|
|
215
59
|
* @param {Sources} sources
|
|
@@ -217,40 +61,18 @@ const renameSources = (sources, compartmentRenames) => {
|
|
|
217
61
|
*/
|
|
218
62
|
const captureCompartmentMap = (compartmentMap, sources) => {
|
|
219
63
|
const {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const compartmentRenames = renameCompartments(compartments);
|
|
225
|
-
const captureCompartments = translateCompartmentMap(
|
|
226
|
-
compartments,
|
|
227
|
-
sources,
|
|
64
|
+
compartmentMap: captureCompartmentMap,
|
|
65
|
+
sources: captureSources,
|
|
66
|
+
newToOldCompartmentNames,
|
|
228
67
|
compartmentRenames,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const captureSources = renameSources(sources, compartmentRenames);
|
|
232
|
-
|
|
233
|
-
const captureCompartmentMap = {
|
|
234
|
-
// TODO graceful migration from tags to conditions
|
|
235
|
-
// https://github.com/endojs/endo/issues/2388
|
|
236
|
-
tags: [],
|
|
237
|
-
entry: {
|
|
238
|
-
compartment: captureEntryCompartmentName,
|
|
239
|
-
module: entryModuleSpecifier,
|
|
240
|
-
},
|
|
241
|
-
compartments: captureCompartments,
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
// Cross-check:
|
|
245
|
-
// We assert that we have constructed a valid compartment map, not because it
|
|
246
|
-
// might not be, but to ensure that the assertCompartmentMap function can
|
|
247
|
-
// accept all valid compartment maps.
|
|
248
|
-
assertCompartmentMap(captureCompartmentMap);
|
|
249
|
-
|
|
68
|
+
oldToNewCompartmentNames,
|
|
69
|
+
} = digestCompartmentMap(compartmentMap, sources);
|
|
250
70
|
return {
|
|
251
71
|
captureCompartmentMap,
|
|
252
72
|
captureSources,
|
|
253
73
|
compartmentRenames,
|
|
74
|
+
newToOldCompartmentNames,
|
|
75
|
+
oldToNewCompartmentNames,
|
|
254
76
|
};
|
|
255
77
|
};
|
|
256
78
|
|
|
@@ -301,7 +123,7 @@ export const captureFromMap = async (powers, compartmentMap, options = {}) => {
|
|
|
301
123
|
searchSuffixes,
|
|
302
124
|
entryCompartmentName,
|
|
303
125
|
entryModuleSpecifier,
|
|
304
|
-
|
|
126
|
+
importHook: consolidatedExitModuleImportHook,
|
|
305
127
|
sourceMapHook,
|
|
306
128
|
});
|
|
307
129
|
// Induce importHook to record all the necessary modules to import the given module specifier.
|
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"}
|
package/src/digest.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/* eslint-disable no-shadow */
|
|
2
|
+
/**
|
|
3
|
+
* Provides {@link digestCompartmentMap} which creates a digest of a compartment
|
|
4
|
+
* map suitable for archival or further inspection.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @import {
|
|
11
|
+
* CompartmentDescriptor,
|
|
12
|
+
* CompartmentMapDescriptor,
|
|
13
|
+
* DigestResult,
|
|
14
|
+
* ModuleDescriptor,
|
|
15
|
+
* Sources,
|
|
16
|
+
* } from './types.js'
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
assertCompartmentMap,
|
|
21
|
+
pathCompare,
|
|
22
|
+
stringCompare,
|
|
23
|
+
} from './compartment-map.js';
|
|
24
|
+
|
|
25
|
+
const { create, fromEntries, entries, keys } = Object;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* We attempt to produce compartment maps that are consistent regardless of
|
|
29
|
+
* whether the packages were originally laid out on disk for development or
|
|
30
|
+
* production, and other trivia like the fully qualified path of a specific
|
|
31
|
+
* installation.
|
|
32
|
+
*
|
|
33
|
+
* Naming compartments for the self-ascribed name and version of each Node.js
|
|
34
|
+
* package is insufficient because they are not guaranteed to be unique.
|
|
35
|
+
* Dependencies do not necessarilly come from the npm registry and may be
|
|
36
|
+
* for example derived from fully qualified URL's or Github org and project
|
|
37
|
+
* names.
|
|
38
|
+
* Package managers are also not required to fully deduplicate the hard
|
|
39
|
+
* copy of each package even when they are identical resources.
|
|
40
|
+
* Duplication is undesirable, but we elect to defer that problem to solutions
|
|
41
|
+
* in the package managers, as the alternative would be to consistently hash
|
|
42
|
+
* the original sources of the packages themselves, which may not even be
|
|
43
|
+
* available much less pristine for us.
|
|
44
|
+
*
|
|
45
|
+
* So, instead, we use the lexically least path of dependency names, delimited
|
|
46
|
+
* by hashes.
|
|
47
|
+
* The compartment maps generated by the ./node-modules.js tooling pre-compute
|
|
48
|
+
* these traces for our use here.
|
|
49
|
+
* We sort the compartments lexically on their self-ascribed name and version,
|
|
50
|
+
* and use the lexically least dependency name path as a tie-breaker.
|
|
51
|
+
* The dependency path is logical and orthogonal to the package manager's
|
|
52
|
+
* actual installation location, so should be orthogonal to the vagaries of the
|
|
53
|
+
* package manager's deduplication algorithm.
|
|
54
|
+
*
|
|
55
|
+
* @param {Record<string, CompartmentDescriptor>} compartments
|
|
56
|
+
* @returns {Record<string, string>} map from old to new compartment names.
|
|
57
|
+
*/
|
|
58
|
+
const renameCompartments = compartments => {
|
|
59
|
+
/** @type {Record<string, string>} */
|
|
60
|
+
const compartmentRenames = create(null);
|
|
61
|
+
let index = 0;
|
|
62
|
+
let prev = '';
|
|
63
|
+
|
|
64
|
+
// The sort below combines two comparators to avoid depending on sort
|
|
65
|
+
// stability, which became standard as recently as 2019.
|
|
66
|
+
// If that date seems quaint, please accept my regards from the distant past.
|
|
67
|
+
// We are very proud of you.
|
|
68
|
+
const compartmentsByPath = Object.entries(compartments)
|
|
69
|
+
.map(([name, compartment]) => ({
|
|
70
|
+
name,
|
|
71
|
+
path: compartment.path,
|
|
72
|
+
label: compartment.label,
|
|
73
|
+
}))
|
|
74
|
+
.sort((a, b) => {
|
|
75
|
+
if (a.label === b.label) {
|
|
76
|
+
assert(a.path !== undefined && b.path !== undefined);
|
|
77
|
+
return pathCompare(a.path, b.path);
|
|
78
|
+
}
|
|
79
|
+
return stringCompare(a.label, b.label);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
for (const { name, label } of compartmentsByPath) {
|
|
83
|
+
if (label === prev) {
|
|
84
|
+
compartmentRenames[name] = `${label}-n${index}`;
|
|
85
|
+
index += 1;
|
|
86
|
+
} else {
|
|
87
|
+
compartmentRenames[name] = label;
|
|
88
|
+
prev = label;
|
|
89
|
+
index = 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return compartmentRenames;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @param {Record<string, CompartmentDescriptor>} compartments
|
|
97
|
+
* @param {Sources} sources
|
|
98
|
+
* @param {Record<string, string>} compartmentRenames
|
|
99
|
+
*/
|
|
100
|
+
const translateCompartmentMap = (compartments, sources, compartmentRenames) => {
|
|
101
|
+
const result = create(null);
|
|
102
|
+
for (const compartmentName of keys(compartmentRenames)) {
|
|
103
|
+
const compartment = compartments[compartmentName];
|
|
104
|
+
const { name, label, retained: compartmentRetained, policy } = compartment;
|
|
105
|
+
if (compartmentRetained) {
|
|
106
|
+
// rename module compartments
|
|
107
|
+
/** @type {Record<string, ModuleDescriptor>} */
|
|
108
|
+
const modules = create(null);
|
|
109
|
+
const compartmentModules = compartment.modules;
|
|
110
|
+
if (compartment.modules) {
|
|
111
|
+
for (const name of keys(compartmentModules).sort()) {
|
|
112
|
+
const { retained: moduleRetained, ...retainedModule } =
|
|
113
|
+
compartmentModules[name];
|
|
114
|
+
if (moduleRetained) {
|
|
115
|
+
if (retainedModule.compartment !== undefined) {
|
|
116
|
+
modules[name] = {
|
|
117
|
+
...retainedModule,
|
|
118
|
+
compartment: compartmentRenames[retainedModule.compartment],
|
|
119
|
+
};
|
|
120
|
+
} else {
|
|
121
|
+
modules[name] = retainedModule;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// integrate sources into modules
|
|
128
|
+
const compartmentSources = sources[compartmentName];
|
|
129
|
+
if (compartmentSources) {
|
|
130
|
+
for (const name of keys(compartmentSources).sort()) {
|
|
131
|
+
const source = compartmentSources[name];
|
|
132
|
+
const { location, parser, exit, sha512, deferredError } = source;
|
|
133
|
+
if (location !== undefined) {
|
|
134
|
+
modules[name] = {
|
|
135
|
+
location,
|
|
136
|
+
parser,
|
|
137
|
+
sha512,
|
|
138
|
+
};
|
|
139
|
+
} else if (exit !== undefined) {
|
|
140
|
+
modules[name] = {
|
|
141
|
+
exit,
|
|
142
|
+
};
|
|
143
|
+
} else if (deferredError !== undefined) {
|
|
144
|
+
modules[name] = {
|
|
145
|
+
deferredError,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
result[compartmentRenames[compartmentName]] = {
|
|
152
|
+
name,
|
|
153
|
+
label,
|
|
154
|
+
location: compartmentRenames[compartmentName],
|
|
155
|
+
modules,
|
|
156
|
+
policy,
|
|
157
|
+
// `scopes`, `types`, and `parsers` are not necessary since every
|
|
158
|
+
// loadable module is captured in `modules`.
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return result;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @param {Sources} sources
|
|
168
|
+
* @param {Record<string, string>} compartmentRenames
|
|
169
|
+
* @returns {Sources}
|
|
170
|
+
*/
|
|
171
|
+
const renameSources = (sources, compartmentRenames) => {
|
|
172
|
+
return fromEntries(
|
|
173
|
+
entries(sources).map(([name, compartmentSources]) => [
|
|
174
|
+
compartmentRenames[name],
|
|
175
|
+
compartmentSources,
|
|
176
|
+
]),
|
|
177
|
+
);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @param {CompartmentMapDescriptor} compartmentMap
|
|
182
|
+
* @param {Sources} sources
|
|
183
|
+
* @returns {DigestResult}
|
|
184
|
+
*/
|
|
185
|
+
export const digestCompartmentMap = (compartmentMap, sources) => {
|
|
186
|
+
const {
|
|
187
|
+
compartments,
|
|
188
|
+
entry: { compartment: entryCompartmentName, module: entryModuleSpecifier },
|
|
189
|
+
} = compartmentMap;
|
|
190
|
+
|
|
191
|
+
const oldToNewCompartmentNames = renameCompartments(compartments);
|
|
192
|
+
const digestCompartments = translateCompartmentMap(
|
|
193
|
+
compartments,
|
|
194
|
+
sources,
|
|
195
|
+
oldToNewCompartmentNames,
|
|
196
|
+
);
|
|
197
|
+
const digestEntryCompartmentName =
|
|
198
|
+
oldToNewCompartmentNames[entryCompartmentName];
|
|
199
|
+
const digestSources = renameSources(sources, oldToNewCompartmentNames);
|
|
200
|
+
|
|
201
|
+
const digestCompartmentMap = {
|
|
202
|
+
// TODO graceful migration from tags to conditions
|
|
203
|
+
// https://github.com/endojs/endo/issues/2388
|
|
204
|
+
tags: [],
|
|
205
|
+
entry: {
|
|
206
|
+
compartment: digestEntryCompartmentName,
|
|
207
|
+
module: entryModuleSpecifier,
|
|
208
|
+
},
|
|
209
|
+
compartments: digestCompartments,
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// Cross-check:
|
|
213
|
+
// We assert that we have constructed a valid compartment map, not because it
|
|
214
|
+
// might not be, but to ensure that the assertCompartmentMap function can
|
|
215
|
+
// accept all valid compartment maps.
|
|
216
|
+
assertCompartmentMap(digestCompartmentMap);
|
|
217
|
+
|
|
218
|
+
const newToOldCompartmentNames = fromEntries(
|
|
219
|
+
entries(oldToNewCompartmentNames).map(([oldName, newName]) => [
|
|
220
|
+
newName,
|
|
221
|
+
oldName,
|
|
222
|
+
]),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
/** @type {DigestResult} */
|
|
226
|
+
const digestResult = {
|
|
227
|
+
compartmentMap: digestCompartmentMap,
|
|
228
|
+
sources: digestSources,
|
|
229
|
+
oldToNewCompartmentNames,
|
|
230
|
+
newToOldCompartmentNames,
|
|
231
|
+
compartmentRenames: newToOldCompartmentNames,
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
return digestResult;
|
|
235
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** @satisfies {Readonly<ParserForLanguage>} */
|
|
2
|
+
export const defaultParserForLanguage: Readonly<{
|
|
3
|
+
readonly 'pre-cjs-json': import("./types.js").ParserImplementation;
|
|
4
|
+
readonly 'pre-mjs-json': import("./types.js").ParserImplementation;
|
|
5
|
+
readonly cjs: import("./types.js").ParserImplementation;
|
|
6
|
+
readonly mjs: import("./types.js").ParserImplementation;
|
|
7
|
+
readonly json: import("./types.js").ParserImplementation;
|
|
8
|
+
readonly text: import("./types.js").ParserImplementation;
|
|
9
|
+
readonly bytes: import("./types.js").ParserImplementation;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=import-archive-all-parsers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-archive-all-parsers.d.ts","sourceRoot":"","sources":["import-archive-all-parsers.js"],"names":[],"mappings":"AAiBA,+CAA+C;AAC/C;;;;;;;;GAUE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* Provides a set of default language behaviors (parsers) suitable for
|
|
2
|
+
* evaluating archives (zip files with a `compartment-map.json` and a file for
|
|
3
|
+
* each module) with pre-compiled _or_ original ESM and CommonJS.
|
|
4
|
+
*
|
|
5
|
+
* This module does not entrain a dependency on Babel on XS, but does on other
|
|
6
|
+
* platforms like Node.js.
|
|
7
|
+
*/
|
|
8
|
+
/** @import {ParserForLanguage} from './types.js' */
|
|
9
|
+
|
|
10
|
+
import parserPreCjs from './parse-pre-cjs.js';
|
|
11
|
+
import parserJson from './parse-json.js';
|
|
12
|
+
import parserText from './parse-text.js';
|
|
13
|
+
import parserBytes from './parse-bytes.js';
|
|
14
|
+
import parserPreMjs from './parse-pre-mjs.js';
|
|
15
|
+
import parserMjs from './parse-mjs.js';
|
|
16
|
+
import parserCjs from './parse-cjs.js';
|
|
17
|
+
|
|
18
|
+
/** @satisfies {Readonly<ParserForLanguage>} */
|
|
19
|
+
export const defaultParserForLanguage = Object.freeze(
|
|
20
|
+
/** @type {const} */ ({
|
|
21
|
+
'pre-cjs-json': parserPreCjs,
|
|
22
|
+
'pre-mjs-json': parserPreMjs,
|
|
23
|
+
cjs: parserCjs,
|
|
24
|
+
mjs: parserMjs,
|
|
25
|
+
json: parserJson,
|
|
26
|
+
text: parserText,
|
|
27
|
+
bytes: parserBytes,
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-archive-lite.d.ts","sourceRoot":"","sources":["import-archive-lite.js"],"names":[],"mappings":"AAoPO,2CALI,UAAU,oFAGR,OAAO,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"import-archive-lite.d.ts","sourceRoot":"","sources":["import-archive-lite.js"],"names":[],"mappings":"AAoPO,2CALI,UAAU,oFAGR,OAAO,CAAC,WAAW,CAAC,CAiKhC;AAQM,wCALI,MAAM,GAAG,UAAU,mBACnB,MAAM,8CAEJ,OAAO,CAAC,WAAW,CAAC,CAwBhC;AAQM,0CALI,MAAM,GAAG,UAAU,mBACnB,MAAM,WACN,kBAAkB,GAChB,OAAO,CAAC,UAAU,CAAC,CAK/B;yCAxZS,YAAY;iCAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;wCAAZ,YAAY;gCAAZ,YAAY"}
|
|
@@ -257,6 +257,7 @@ export const parseArchive = async (
|
|
|
257
257
|
modules = undefined,
|
|
258
258
|
importHook: exitModuleImportHook = undefined,
|
|
259
259
|
parserForLanguage: parserForLanguageOption = {},
|
|
260
|
+
__native__ = false,
|
|
260
261
|
} = options;
|
|
261
262
|
|
|
262
263
|
const parserForLanguage = freeze(
|
|
@@ -343,6 +344,7 @@ export const parseArchive = async (
|
|
|
343
344
|
}),
|
|
344
345
|
),
|
|
345
346
|
Compartment: CompartmentParseOption,
|
|
347
|
+
__native__,
|
|
346
348
|
});
|
|
347
349
|
|
|
348
350
|
await pendingJobsPromise;
|
|
@@ -362,6 +364,7 @@ export const parseArchive = async (
|
|
|
362
364
|
transforms,
|
|
363
365
|
__shimTransforms__,
|
|
364
366
|
Compartment: CompartmentOption = CompartmentParseOption,
|
|
367
|
+
__native__,
|
|
365
368
|
importHook: exitModuleImportHook,
|
|
366
369
|
} = options || {};
|
|
367
370
|
|
|
@@ -388,6 +391,7 @@ export const parseArchive = async (
|
|
|
388
391
|
transforms,
|
|
389
392
|
__shimTransforms__,
|
|
390
393
|
Compartment: CompartmentOption,
|
|
394
|
+
__native__,
|
|
391
395
|
});
|
|
392
396
|
|
|
393
397
|
await pendingJobsPromise;
|
package/src/import-hook.d.ts
CHANGED
|
@@ -6,32 +6,19 @@
|
|
|
6
6
|
* @param {MakeImportNowHookMakerOptions} options
|
|
7
7
|
* @returns {ImportNowHookMaker}
|
|
8
8
|
*/
|
|
9
|
-
export function makeImportNowHookMaker(readPowers: ReadNowPowers, baseLocation: string, { sources, compartmentDescriptors, computeSha512, searchSuffixes, sourceMapHook, exitModuleImportNowHook, }: MakeImportNowHookMakerOptions): ImportNowHookMaker;
|
|
9
|
+
export function makeImportNowHookMaker(readPowers: ReadNowPowers, baseLocation: string, { sources, compartmentDescriptors, computeSha512, searchSuffixes, archiveOnly, sourceMapHook, importNowHook: exitModuleImportNowHook, }: MakeImportNowHookMakerOptions): ImportNowHookMaker;
|
|
10
10
|
export function exitModuleImportHookMaker({ modules, exitModuleImportHook, entryCompartmentName, }: {
|
|
11
11
|
modules?: Record<string, any> | undefined;
|
|
12
12
|
exitModuleImportHook?: ExitModuleImportHook | undefined;
|
|
13
13
|
entryCompartmentName: string;
|
|
14
14
|
}): ExitModuleImportHook | undefined;
|
|
15
|
-
export function makeImportHookMaker(readPowers: ReadFn | ReadPowers, baseLocation: string, { sources, compartmentDescriptors, archiveOnly, computeSha512, searchSuffixes, sourceMapHook, entryCompartmentName, entryModuleSpecifier, exitModuleImportHook, }:
|
|
16
|
-
sources?: Sources | undefined;
|
|
17
|
-
compartmentDescriptors?: Record<string, CompartmentDescriptor> | undefined;
|
|
18
|
-
archiveOnly?: boolean | undefined;
|
|
19
|
-
computeSha512?: HashFn | undefined;
|
|
20
|
-
searchSuffixes?: string[] | undefined;
|
|
21
|
-
entryCompartmentName: string;
|
|
22
|
-
entryModuleSpecifier: string;
|
|
23
|
-
exitModuleImportHook?: ExitModuleImportHook | undefined;
|
|
24
|
-
sourceMapHook?: SourceMapHook | undefined;
|
|
25
|
-
}): ImportHookMaker;
|
|
15
|
+
export function makeImportHookMaker(readPowers: ReadFn | ReadPowers, baseLocation: string, { sources, compartmentDescriptors, archiveOnly, computeSha512, searchSuffixes, sourceMapHook, entryCompartmentName, entryModuleSpecifier, importHook: exitModuleImportHook, }: MakeImportHookMakerOptions): ImportHookMaker;
|
|
26
16
|
import type { ReadNowPowers } from './types.js';
|
|
27
17
|
import type { MakeImportNowHookMakerOptions } from './types.js';
|
|
28
18
|
import type { ImportNowHookMaker } from './types.js';
|
|
29
19
|
import type { ExitModuleImportHook } from './types.js';
|
|
30
20
|
import type { ReadFn } from './types.js';
|
|
31
21
|
import type { ReadPowers } from './types.js';
|
|
32
|
-
import type {
|
|
33
|
-
import type { CompartmentDescriptor } from './types.js';
|
|
34
|
-
import type { HashFn } from './types.js';
|
|
35
|
-
import type { SourceMapHook } from './types.js';
|
|
22
|
+
import type { MakeImportHookMakerOptions } from './types.js';
|
|
36
23
|
import type { ImportHookMaker } from './types.js';
|
|
37
24
|
//# sourceMappingURL=import-hook.d.ts.map
|
package/src/import-hook.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-hook.d.ts","sourceRoot":"","sources":["import-hook.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"import-hook.d.ts","sourceRoot":"","sources":["import-hook.js"],"names":[],"mappings":"AAklBA;;;;;;;GAOG;AACH,mDALW,aAAa,gBACb,MAAM,2IACN,6BAA6B,GAC3B,kBAAkB,CAyJ9B;AApjBM,oGALJ;IAAqC,OAAO;IACN,oBAAoB;IACnC,oBAAoB,EAAnC,MAAM;CACd,GAAU,oBAAoB,GAAC,SAAS,CA8B1C;AAiMM,gDALI,MAAM,GAAC,UAAU,gBACjB,MAAM,iLACN,0BAA0B,GACxB,eAAe,CAwL3B;mCA5iBS,YAAY;mDAAZ,YAAY;wCAAZ,YAAY;0CAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;gDAAZ,YAAY;qCAAZ,YAAY"}
|