@endo/compartment-mapper 1.3.1 → 1.4.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 +50 -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-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 +10 -14
- package/src/archive-lite.d.ts +6 -6
- package/src/archive-lite.d.ts.map +1 -1
- package/src/archive-lite.js +35 -33
- package/src/archive.d.ts.map +1 -1
- package/src/archive.js +132 -28
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +54 -14
- package/src/capture-lite.d.ts +2 -2
- package/src/capture-lite.d.ts.map +1 -1
- package/src/capture-lite.js +21 -17
- 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/extension.d.ts.map +1 -1
- package/src/extension.js +1 -3
- 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 +43 -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 +23 -23
- package/src/import.d.ts.map +1 -1
- package/src/import.js +47 -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 +12 -29
- package/src/map-parser.d.ts.map +1 -1
- package/src/map-parser.js +21 -16
- package/src/node-module-specifier.d.ts.map +1 -1
- package/src/node-module-specifier.js +2 -3
- package/src/node-modules.d.ts +9 -7
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +176 -87
- 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 +256 -0
- package/src/types/external.d.ts.map +1 -0
- package/src/types/external.ts +379 -0
- package/src/types/internal.d.ts +161 -0
- package/src/types/internal.d.ts.map +1 -0
- package/src/types/internal.ts +216 -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
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides functions for evaluating the modules in an archive (a zip
|
|
2
3
|
* file with a `compartment-map.json` and a file for each module it contains.)
|
|
3
4
|
*
|
|
4
5
|
* These functions do not have a bias for any particular mapping, so you will
|
|
@@ -11,26 +12,30 @@
|
|
|
11
12
|
* `@endo/compartment-mapper/archive-parsers.js`.
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
|
-
// @ts-check
|
|
15
15
|
/* eslint no-shadow: "off" */
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @import {
|
|
19
|
+
* ImportHook,
|
|
20
|
+
* StaticModuleType,
|
|
21
|
+
* } from 'ses';
|
|
22
|
+
* @import {
|
|
23
|
+
* Application,
|
|
24
|
+
* CompartmentDescriptor,
|
|
25
|
+
* ComputeSourceLocationHook,
|
|
26
|
+
* ComputeSourceMapLocationHook,
|
|
27
|
+
* ExecuteFn,
|
|
28
|
+
* ExitModuleImportHook,
|
|
29
|
+
* HashFn,
|
|
30
|
+
* ImportHookMaker,
|
|
31
|
+
* LoadArchiveOptions,
|
|
32
|
+
* ParseArchiveOptions,
|
|
33
|
+
* ParserForLanguage,
|
|
34
|
+
* ReadFn,
|
|
35
|
+
* ReadPowers,
|
|
36
|
+
* SomeObject,
|
|
37
|
+
* } from './types.js'
|
|
38
|
+
*/
|
|
34
39
|
|
|
35
40
|
import { ZipReader } from '@endo/zip';
|
|
36
41
|
import { link } from './link.js';
|
|
@@ -41,8 +46,6 @@ import { assertCompartmentMap } from './compartment-map.js';
|
|
|
41
46
|
import { exitModuleImportHookMaker } from './import-hook.js';
|
|
42
47
|
import { attenuateModuleHook, enforceModulePolicy } from './policy.js';
|
|
43
48
|
|
|
44
|
-
const DefaultCompartment = Compartment;
|
|
45
|
-
|
|
46
49
|
const { Fail, quote: q } = assert;
|
|
47
50
|
|
|
48
51
|
const textDecoder = new TextDecoder();
|
|
@@ -119,7 +122,10 @@ const makeArchiveImportHookMaker = (
|
|
|
119
122
|
moduleSpecifier,
|
|
120
123
|
)} was not in the archive and an attempt was made to load it as a builtin`,
|
|
121
124
|
});
|
|
122
|
-
const record = await exitModuleImportHook(
|
|
125
|
+
const record = await exitModuleImportHook(
|
|
126
|
+
moduleSpecifier,
|
|
127
|
+
packageLocation,
|
|
128
|
+
);
|
|
123
129
|
if (record) {
|
|
124
130
|
// note it's not being marked as exit in sources
|
|
125
131
|
// it could get marked and the second pass, when the archive is being executed, would have the data
|
|
@@ -230,24 +236,10 @@ const makeArchiveImportHookMaker = (
|
|
|
230
236
|
return makeImportHook;
|
|
231
237
|
};
|
|
232
238
|
|
|
233
|
-
// Have to give it a name to capture the external meaning of Compartment
|
|
234
|
-
// Otherwise @param {typeof Compartment} takes the Compartment to mean
|
|
235
|
-
// the const variable defined within the function.
|
|
236
|
-
/** @typedef {typeof Compartment} CompartmentConstructor */
|
|
237
|
-
|
|
238
239
|
/**
|
|
239
240
|
* @param {Uint8Array} archiveBytes
|
|
240
241
|
* @param {string} [archiveLocation]
|
|
241
|
-
* @param {
|
|
242
|
-
* @param {string} [options.expectedSha512]
|
|
243
|
-
* @param {HashFn} [options.computeSha512]
|
|
244
|
-
* @param {Record<string, unknown>} [options.modules]
|
|
245
|
-
* @param {ExitModuleImportHook} [options.importHook]
|
|
246
|
-
* @param {CompartmentConstructor} [options.Compartment]
|
|
247
|
-
* @param {ComputeSourceLocationHook} [options.computeSourceLocation]
|
|
248
|
-
* @param {ComputeSourceMapLocationHook} [options.computeSourceMapLocation]
|
|
249
|
-
* @param {ParserForLanguage} [options.parserForLanguage]
|
|
250
|
-
* @param {LanguageForExtension} [options.languageForExtension]
|
|
242
|
+
* @param {ParseArchiveOptions} [options]
|
|
251
243
|
* @returns {Promise<Application>}
|
|
252
244
|
*/
|
|
253
245
|
export const parseArchive = async (
|
|
@@ -261,24 +253,15 @@ export const parseArchive = async (
|
|
|
261
253
|
expectedSha512 = undefined,
|
|
262
254
|
computeSourceLocation = undefined,
|
|
263
255
|
computeSourceMapLocation = undefined,
|
|
264
|
-
Compartment =
|
|
256
|
+
Compartment: CompartmentParseOption = Compartment,
|
|
265
257
|
modules = undefined,
|
|
266
258
|
importHook: exitModuleImportHook = undefined,
|
|
267
259
|
parserForLanguage: parserForLanguageOption = {},
|
|
268
|
-
languageForExtension: languageForExtensionOption = {},
|
|
269
260
|
} = options;
|
|
270
261
|
|
|
271
262
|
const parserForLanguage = freeze(
|
|
272
263
|
assign(create(null), parserForLanguageOption),
|
|
273
264
|
);
|
|
274
|
-
const languageForExtension = freeze(
|
|
275
|
-
assign(create(null), languageForExtensionOption),
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
const compartmentExitModuleImportHook = exitModuleImportHookMaker({
|
|
279
|
-
modules,
|
|
280
|
-
exitModuleImportHook,
|
|
281
|
-
});
|
|
282
265
|
|
|
283
266
|
const archive = new ZipReader(archiveBytes, { name: archiveLocation });
|
|
284
267
|
|
|
@@ -324,9 +307,15 @@ export const parseArchive = async (
|
|
|
324
307
|
|
|
325
308
|
const {
|
|
326
309
|
compartments,
|
|
327
|
-
entry: { module:
|
|
310
|
+
entry: { module: entryModuleSpecifier, compartment: entryCompartmentName },
|
|
328
311
|
} = compartmentMap;
|
|
329
312
|
|
|
313
|
+
const compartmentExitModuleImportHook = exitModuleImportHookMaker({
|
|
314
|
+
modules,
|
|
315
|
+
exitModuleImportHook,
|
|
316
|
+
entryCompartmentName,
|
|
317
|
+
});
|
|
318
|
+
|
|
330
319
|
// Archive integrity checks: ensure every module is pre-loaded so its hash
|
|
331
320
|
// gets checked, and ensure that every file in the archive is used, and
|
|
332
321
|
// therefore checked.
|
|
@@ -348,18 +337,17 @@ export const parseArchive = async (
|
|
|
348
337
|
const { compartment, pendingJobsPromise } = link(compartmentMap, {
|
|
349
338
|
makeImportHook,
|
|
350
339
|
parserForLanguage,
|
|
351
|
-
languageForExtension,
|
|
352
340
|
modules: Object.fromEntries(
|
|
353
341
|
Object.keys(modules || {}).map(specifier => {
|
|
354
342
|
return [specifier, { namespace: {} }];
|
|
355
343
|
}),
|
|
356
344
|
),
|
|
357
|
-
Compartment,
|
|
345
|
+
Compartment: CompartmentParseOption,
|
|
358
346
|
});
|
|
359
347
|
|
|
360
348
|
await pendingJobsPromise;
|
|
361
349
|
|
|
362
|
-
await compartment.load(
|
|
350
|
+
await compartment.load(entryModuleSpecifier);
|
|
363
351
|
unseen.size === 0 ||
|
|
364
352
|
Fail`Archive contains extraneous files: ${q([...unseen])} in ${q(
|
|
365
353
|
archiveLocation,
|
|
@@ -373,13 +361,14 @@ export const parseArchive = async (
|
|
|
373
361
|
modules,
|
|
374
362
|
transforms,
|
|
375
363
|
__shimTransforms__,
|
|
376
|
-
Compartment,
|
|
364
|
+
Compartment: CompartmentOption = CompartmentParseOption,
|
|
377
365
|
importHook: exitModuleImportHook,
|
|
378
366
|
} = options || {};
|
|
379
367
|
|
|
380
368
|
const compartmentExitModuleImportHook = exitModuleImportHookMaker({
|
|
381
369
|
modules,
|
|
382
370
|
exitModuleImportHook,
|
|
371
|
+
entryCompartmentName,
|
|
383
372
|
});
|
|
384
373
|
const makeImportHook = makeArchiveImportHookMaker(
|
|
385
374
|
get,
|
|
@@ -394,18 +383,17 @@ export const parseArchive = async (
|
|
|
394
383
|
const { compartment, pendingJobsPromise } = link(compartmentMap, {
|
|
395
384
|
makeImportHook,
|
|
396
385
|
parserForLanguage,
|
|
397
|
-
languageForExtension,
|
|
398
386
|
globals,
|
|
399
387
|
modules,
|
|
400
388
|
transforms,
|
|
401
389
|
__shimTransforms__,
|
|
402
|
-
Compartment,
|
|
390
|
+
Compartment: CompartmentOption,
|
|
403
391
|
});
|
|
404
392
|
|
|
405
393
|
await pendingJobsPromise;
|
|
406
394
|
|
|
407
395
|
// eslint-disable-next-line dot-notation
|
|
408
|
-
return compartment['import'](
|
|
396
|
+
return compartment['import'](entryModuleSpecifier);
|
|
409
397
|
};
|
|
410
398
|
|
|
411
399
|
return { import: execute, sha512 };
|
|
@@ -429,7 +417,6 @@ export const loadArchive = async (
|
|
|
429
417
|
modules,
|
|
430
418
|
computeSourceMapLocation,
|
|
431
419
|
parserForLanguage,
|
|
432
|
-
languageForExtension,
|
|
433
420
|
} = options;
|
|
434
421
|
const archiveBytes = await read(archiveLocation);
|
|
435
422
|
return parseArchive(archiveBytes, archiveLocation, {
|
|
@@ -439,7 +426,6 @@ export const loadArchive = async (
|
|
|
439
426
|
modules,
|
|
440
427
|
computeSourceMapLocation,
|
|
441
428
|
parserForLanguage,
|
|
442
|
-
languageForExtension,
|
|
443
429
|
});
|
|
444
430
|
};
|
|
445
431
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-archive-parsers.d.ts","sourceRoot":"","sources":["import-archive-parsers.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"import-archive-parsers.d.ts","sourceRoot":"","sources":["import-archive-parsers.js"],"names":[],"mappings":"AAeA,+CAA+C;AAC/C;;;;;;GAQE"}
|
package/src/import-archive.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function parseArchive(archiveBytes: Uint8Array, archiveLocation?: string | undefined, options?: Options | undefined): Promise<Application>;
|
|
2
|
-
export function loadArchive(readPowers: import("@endo/zip").ReadFn | ReadPowers, archiveLocation: string, options?:
|
|
2
|
+
export function loadArchive(readPowers: import("@endo/zip").ReadFn | ReadPowers, archiveLocation: string, options?: import("./types.js").ParseArchiveOptions | undefined): Promise<Application>;
|
|
3
3
|
export function importArchive(readPowers: import("@endo/zip").ReadFn | ReadPowers, archiveLocation: string, options: ExecuteOptions & LoadArchiveOptions): Promise<object>;
|
|
4
4
|
export type CompartmentConstructor = typeof Compartment;
|
|
5
5
|
export type Options = {
|
|
@@ -14,8 +14,8 @@ export type Options = {
|
|
|
14
14
|
};
|
|
15
15
|
import type { Application } from './types.js';
|
|
16
16
|
import type { ReadPowers } from './types.js';
|
|
17
|
-
import type { LoadArchiveOptions } from './types.js';
|
|
18
17
|
import type { ExecuteOptions } from './types.js';
|
|
18
|
+
import type { LoadArchiveOptions } from './types.js';
|
|
19
19
|
import type { HashFn } from './types.js';
|
|
20
20
|
import type { ExitModuleImportHook } from './types.js';
|
|
21
21
|
import type { ComputeSourceLocationHook } from './types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-archive.d.ts","sourceRoot":"","sources":["import-archive.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"import-archive.d.ts","sourceRoot":"","sources":["import-archive.js"],"names":[],"mappings":"AA6EO,2CALI,UAAU,wEAGR,OAAO,CAAC,WAAW,CAAC,CAW9B;AAQI,wCALI,OAAO,WAAW,EAAE,MAAM,GAAG,UAAU,mBACvC,MAAM,mEAEJ,OAAO,CAAC,WAAW,CAAC,CAO9B;AAQI,0CALI,OAAO,WAAW,EAAE,MAAM,GAAG,UAAU,mBACvC,MAAM,WACN,cAAc,GAAG,kBAAkB,GACjC,OAAO,CAAC,MAAM,CAAC,CAOzB;qCArEW,OAAO,WAAW;;;;;;;;;;;iCAhBtB,YAAY;gCAAZ,YAAY;oCAAZ,YAAY;wCAAZ,YAAY;4BAAZ,YAAY;0CAAZ,YAAY;+CAAZ,YAAY;kDAAZ,YAAY;uCAAZ,YAAY"}
|
package/src/import-archive.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides functions for evaluating modules in an archive (a zip file
|
|
2
3
|
* with a `compartment-map.json` and a file for a module and each of its
|
|
3
4
|
* transitive dependencies.)
|
|
4
5
|
*
|
|
@@ -13,7 +14,19 @@
|
|
|
13
14
|
* dependency on Babel.
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @import {
|
|
19
|
+
* Application,
|
|
20
|
+
* ComputeSourceLocationHook,
|
|
21
|
+
* ComputeSourceMapLocationHook,
|
|
22
|
+
* ExecuteOptions,
|
|
23
|
+
* ExitModuleImportHook,
|
|
24
|
+
* HashFn,
|
|
25
|
+
* LoadArchiveOptions,
|
|
26
|
+
* ReadPowers,
|
|
27
|
+
* ParserForLanguage,
|
|
28
|
+
* } from './types.js'
|
|
29
|
+
*/
|
|
17
30
|
|
|
18
31
|
import { defaultParserForLanguage } from './import-archive-parsers.js';
|
|
19
32
|
import {
|
|
@@ -24,16 +37,6 @@ import {
|
|
|
24
37
|
|
|
25
38
|
const { assign, create, freeze } = Object;
|
|
26
39
|
|
|
27
|
-
/** @import {Application} from './types.js' */
|
|
28
|
-
/** @import {ComputeSourceLocationHook} from './types.js' */
|
|
29
|
-
/** @import {ComputeSourceMapLocationHook} from './types.js' */
|
|
30
|
-
/** @import {ExecuteOptions} from './types.js' */
|
|
31
|
-
/** @import {ExitModuleImportHook} from './types.js' */
|
|
32
|
-
/** @import {HashFn} from './types.js' */
|
|
33
|
-
/** @import {LoadArchiveOptions} from './types.js' */
|
|
34
|
-
/** @import {ReadPowers} from './types.js' */
|
|
35
|
-
/** @import {ParserForLanguage} from './types.js' */
|
|
36
|
-
|
|
37
40
|
// Must give the type of Compartment a name to capture the external meaning of
|
|
38
41
|
// Compartment Otherwise @param {typeof Compartment} takes the Compartment to
|
|
39
42
|
// mean the const variable defined within the function.
|
package/src/import-hook.d.ts
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* @returns {ImportNowHookMaker}
|
|
8
8
|
*/
|
|
9
9
|
export function makeImportNowHookMaker(readPowers: ReadNowPowers, baseLocation: string, { sources, compartmentDescriptors, computeSha512, searchSuffixes, sourceMapHook, exitModuleImportNowHook, }: MakeImportNowHookMakerOptions): ImportNowHookMaker;
|
|
10
|
-
export function exitModuleImportHookMaker({ modules, exitModuleImportHook, }: {
|
|
10
|
+
export function exitModuleImportHookMaker({ modules, exitModuleImportHook, entryCompartmentName, }: {
|
|
11
11
|
modules?: Record<string, any> | undefined;
|
|
12
12
|
exitModuleImportHook?: ExitModuleImportHook | undefined;
|
|
13
|
+
entryCompartmentName: string;
|
|
13
14
|
}): ExitModuleImportHook | undefined;
|
|
14
15
|
export function makeImportHookMaker(readPowers: ReadFn | ReadPowers, baseLocation: string, { sources, compartmentDescriptors, archiveOnly, computeSha512, searchSuffixes, sourceMapHook, entryCompartmentName, entryModuleSpecifier, exitModuleImportHook, }: {
|
|
15
16
|
sources?: Sources | undefined;
|
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":"AA2lBA;;;;;;;GAOG;AACH,mDALW,aAAa,gBACb,MAAM,+GACN,6BAA6B,GAC3B,kBAAkB,CAuJ9B;AA5jBM,oGALJ;IAAqC,OAAO;IACN,oBAAoB;IACnC,oBAAoB,EAAnC,MAAM;CACd,GAAU,oBAAoB,GAAC,SAAS,CA8B1C;AA4MM,gDApBI,MAAM,GAAC,UAAU,gBACjB,MAAM,qKAEd;IAA0B,OAAO;IACuB,sBAAsB;IACpD,WAAW;IACZ,aAAa;IACN,cAAc;IAOtB,oBAAoB,EAApC,MAAM;IACU,oBAAoB,EAApC,MAAM;IACyB,oBAAoB;IAC3B,aAAa;CAC7C,GAAU,eAAe,CAuL3B;mCAtjBS,YAAY;mDAAZ,YAAY;wCAAZ,YAAY;0CAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;6BAAZ,YAAY;2CAAZ,YAAY;4BAAZ,YAAY;mCAAZ,YAAY;qCAAZ,YAAY"}
|
package/src/import-hook.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides the implementation of each compartment's `importHook` when
|
|
3
|
+
* using `import.js`, `import-lite.js`, `archive.js`, or `archive-lite.js`.
|
|
4
|
+
* However, `import-archive.js` and `import-archive-lite.js` use their own
|
|
5
|
+
* variant.
|
|
4
6
|
*
|
|
5
7
|
* For building archives, these import hooks create a table of all the modules
|
|
6
8
|
* in a "working set" of transitive dependencies.
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
|
-
// @ts-check
|
|
10
11
|
/**
|
|
11
12
|
* @import {
|
|
12
13
|
* ImportHook,
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
* @import {
|
|
18
19
|
* CompartmentDescriptor,
|
|
19
20
|
* ChooseModuleDescriptorOperators,
|
|
20
|
-
*
|
|
21
|
+
* ChooseModuleDescriptorParams,
|
|
21
22
|
* ChooseModuleDescriptorYieldables,
|
|
22
23
|
* ExitModuleImportHook,
|
|
23
24
|
* FindRedirectParams,
|
|
@@ -180,13 +181,15 @@ const findRedirect = ({
|
|
|
180
181
|
|
|
181
182
|
/**
|
|
182
183
|
* @param {object} params
|
|
183
|
-
* @param {Record<string, any
|
|
184
|
+
* @param {Record<string, any>} [params.modules]
|
|
184
185
|
* @param {ExitModuleImportHook} [params.exitModuleImportHook]
|
|
186
|
+
* @param {string} params.entryCompartmentName
|
|
185
187
|
* @returns {ExitModuleImportHook|undefined}
|
|
186
188
|
*/
|
|
187
189
|
export const exitModuleImportHookMaker = ({
|
|
188
190
|
modules = undefined,
|
|
189
191
|
exitModuleImportHook = undefined,
|
|
192
|
+
entryCompartmentName,
|
|
190
193
|
}) => {
|
|
191
194
|
if (!modules && !exitModuleImportHook) {
|
|
192
195
|
return undefined;
|
|
@@ -204,7 +207,10 @@ export const exitModuleImportHookMaker = ({
|
|
|
204
207
|
});
|
|
205
208
|
}
|
|
206
209
|
if (exitModuleImportHook) {
|
|
207
|
-
|
|
210
|
+
// The entryCompartmentName is a file URL when constructing an archive or
|
|
211
|
+
// importing from a file system, but is merely a zip archive root
|
|
212
|
+
// directory name when importing from an archive.
|
|
213
|
+
return exitModuleImportHook(specifier, entryCompartmentName);
|
|
208
214
|
}
|
|
209
215
|
return undefined;
|
|
210
216
|
};
|
|
@@ -243,7 +249,7 @@ const nominateCandidates = (moduleSpecifier, searchSuffixes) => {
|
|
|
243
249
|
*
|
|
244
250
|
* @template {ChooseModuleDescriptorOperators} Operators Type of operators (sync
|
|
245
251
|
* or async)
|
|
246
|
-
* @param {
|
|
252
|
+
* @param {ChooseModuleDescriptorParams} options Options/context
|
|
247
253
|
* @param {Operators} operators Operators
|
|
248
254
|
* @returns {Generator<ChooseModuleDescriptorYieldables,
|
|
249
255
|
* StaticModuleType|undefined, Awaited<ChooseModuleDescriptorYieldables>>}
|
|
@@ -269,6 +275,7 @@ function* chooseModuleDescriptor(
|
|
|
269
275
|
for (const candidateSpecifier of candidates) {
|
|
270
276
|
const candidateModuleDescriptor = moduleDescriptors[candidateSpecifier];
|
|
271
277
|
if (candidateModuleDescriptor !== undefined) {
|
|
278
|
+
candidateModuleDescriptor.retained = true;
|
|
272
279
|
const { compartment: candidateCompartmentName = packageLocation } =
|
|
273
280
|
candidateModuleDescriptor;
|
|
274
281
|
const candidateCompartment = compartments[candidateCompartmentName];
|
|
@@ -339,6 +346,7 @@ function* chooseModuleDescriptor(
|
|
|
339
346
|
// module specifier than the requested one.
|
|
340
347
|
if (candidateSpecifier !== moduleSpecifier) {
|
|
341
348
|
moduleDescriptors[moduleSpecifier] = {
|
|
349
|
+
retained: true,
|
|
342
350
|
module: candidateSpecifier,
|
|
343
351
|
compartment: packageLocation,
|
|
344
352
|
};
|
|
@@ -502,89 +510,91 @@ export const makeImportHookMaker = (
|
|
|
502
510
|
// for lint rule
|
|
503
511
|
await null;
|
|
504
512
|
|
|
505
|
-
//
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
enforceModulePolicy(moduleSpecifier, compartmentDescriptor, {
|
|
518
|
-
exit: true,
|
|
519
|
-
errorHint: `Blocked in loading. ${q(
|
|
520
|
-
moduleSpecifier,
|
|
521
|
-
)} was not in the compartment map and an attempt was made to load it as a builtin`,
|
|
522
|
-
});
|
|
523
|
-
if (archiveOnly) {
|
|
524
|
-
// Return a place-holder.
|
|
525
|
-
// Archived compartments are not executed.
|
|
526
|
-
return freeze({ imports: [], exports: [], execute() {} });
|
|
527
|
-
}
|
|
528
|
-
// note it's not being marked as exit in sources
|
|
529
|
-
// it could get marked and the second pass, when the archive is being executed, would have the data
|
|
530
|
-
// to enforce which exits can be dynamically imported
|
|
531
|
-
const attenuatedRecord = await attenuateModuleHook(
|
|
513
|
+
// All importHook errors must be deferred if coming from loading dependencies
|
|
514
|
+
// identified by a parser that discovers imports heuristically.
|
|
515
|
+
try {
|
|
516
|
+
// per-module:
|
|
517
|
+
|
|
518
|
+
// In Node.js, an absolute specifier always indicates a built-in or
|
|
519
|
+
// third-party dependency.
|
|
520
|
+
// The `moduleMapHook` captures all third-party dependencies, unless
|
|
521
|
+
// we allow importing any exit.
|
|
522
|
+
if (moduleSpecifier !== '.' && !moduleSpecifier.startsWith('./')) {
|
|
523
|
+
if (exitModuleImportHook) {
|
|
524
|
+
const record = await exitModuleImportHook(
|
|
532
525
|
moduleSpecifier,
|
|
533
|
-
|
|
534
|
-
compartmentDescriptor.policy,
|
|
535
|
-
attenuators,
|
|
526
|
+
packageLocation,
|
|
536
527
|
);
|
|
537
|
-
|
|
528
|
+
if (record) {
|
|
529
|
+
// It'd be nice to check the policy before importing it, but we can only throw a policy error if the
|
|
530
|
+
// hook returns something. Otherwise, we need to fall back to the 'cannot find' error below.
|
|
531
|
+
enforceModulePolicy(moduleSpecifier, compartmentDescriptor, {
|
|
532
|
+
exit: true,
|
|
533
|
+
errorHint: `Blocked in loading. ${q(
|
|
534
|
+
moduleSpecifier,
|
|
535
|
+
)} was not in the compartment map and an attempt was made to load it as a builtin`,
|
|
536
|
+
});
|
|
537
|
+
if (archiveOnly) {
|
|
538
|
+
// Return a place-holder.
|
|
539
|
+
// Archived compartments are not executed.
|
|
540
|
+
return freeze({ imports: [], exports: [], execute() {} });
|
|
541
|
+
}
|
|
542
|
+
// note it's not being marked as exit in sources
|
|
543
|
+
// it could get marked and the second pass, when the archive is being executed, would have the data
|
|
544
|
+
// to enforce which exits can be dynamically imported
|
|
545
|
+
const attenuatedRecord = await attenuateModuleHook(
|
|
546
|
+
moduleSpecifier,
|
|
547
|
+
record,
|
|
548
|
+
compartmentDescriptor.policy,
|
|
549
|
+
attenuators,
|
|
550
|
+
);
|
|
551
|
+
return attenuatedRecord;
|
|
552
|
+
}
|
|
538
553
|
}
|
|
539
|
-
|
|
540
|
-
return deferError(
|
|
541
|
-
moduleSpecifier,
|
|
542
|
-
Error(
|
|
554
|
+
throw Error(
|
|
543
555
|
`Cannot find external module ${q(
|
|
544
556
|
moduleSpecifier,
|
|
545
557
|
)} in package ${packageLocation}`,
|
|
546
|
-
)
|
|
547
|
-
|
|
548
|
-
}
|
|
558
|
+
);
|
|
559
|
+
}
|
|
549
560
|
|
|
550
|
-
|
|
561
|
+
const { maybeRead } = unpackReadPowers(readPowers);
|
|
551
562
|
|
|
552
|
-
|
|
563
|
+
const candidates = nominateCandidates(moduleSpecifier, searchSuffixes);
|
|
553
564
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
565
|
+
const record = await asyncTrampoline(
|
|
566
|
+
chooseModuleDescriptor,
|
|
567
|
+
{
|
|
568
|
+
candidates,
|
|
569
|
+
compartmentDescriptor,
|
|
570
|
+
compartmentDescriptors,
|
|
571
|
+
compartments,
|
|
572
|
+
computeSha512,
|
|
573
|
+
moduleDescriptors,
|
|
574
|
+
moduleSpecifier,
|
|
575
|
+
packageLocation,
|
|
576
|
+
packageSources,
|
|
577
|
+
readPowers,
|
|
578
|
+
sourceMapHook,
|
|
579
|
+
strictlyRequiredForCompartment,
|
|
580
|
+
},
|
|
581
|
+
{ maybeRead, parse, shouldDeferError },
|
|
582
|
+
);
|
|
572
583
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
584
|
+
if (record) {
|
|
585
|
+
return record;
|
|
586
|
+
}
|
|
576
587
|
|
|
577
|
-
|
|
578
|
-
moduleSpecifier,
|
|
579
|
-
// TODO offer breadcrumbs in the error message, or how to construct breadcrumbs with another tool.
|
|
580
|
-
Error(
|
|
588
|
+
throw Error(
|
|
581
589
|
`Cannot find file for internal module ${q(
|
|
582
590
|
moduleSpecifier,
|
|
583
591
|
)} (with candidates ${candidates
|
|
584
592
|
.map(x => q(x))
|
|
585
593
|
.join(', ')}) in package ${packageLocation}`,
|
|
586
|
-
)
|
|
587
|
-
)
|
|
594
|
+
);
|
|
595
|
+
} catch (error) {
|
|
596
|
+
return deferError(moduleSpecifier, error);
|
|
597
|
+
}
|
|
588
598
|
};
|
|
589
599
|
return importHook;
|
|
590
600
|
};
|
|
@@ -724,7 +734,8 @@ export function makeImportNowHookMaker(
|
|
|
724
734
|
}
|
|
725
735
|
|
|
726
736
|
if (exitModuleImportNowHook) {
|
|
727
|
-
//
|
|
737
|
+
// This hook is responsible for ensuring that the moduleSpecifier
|
|
738
|
+
// actually refers to an exit module.
|
|
728
739
|
const exitRecord = exitModuleImportNowHook(
|
|
729
740
|
moduleSpecifier,
|
|
730
741
|
packageLocation,
|
package/src/import-lite.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-lite.d.ts","sourceRoot":"","sources":["import-lite.js"],"names":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"import-lite.d.ts","sourceRoot":"","sources":["import-lite.js"],"names":[],"mappings":";;;;;;;AAuEG,wCACQ,aAAa,kBACb,wBAAwB,iDAEtB,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;AAGE,wCACQ,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,WAAW,CAAC,CAChC;AAuJM,0CANI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,gDAEtB,OAAO,CAAC,UAAU,CAAC,CAU/B;mCAnNS,YAAY;8CAAZ,YAAY;+CAAZ,YAAY;iCAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;2CAAZ,YAAY;gCAAZ,YAAY"}
|