@endo/compartment-mapper 1.1.5 → 1.2.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 +17 -28
- package/archive-lite.d.ts +2 -0
- package/archive-lite.js +7 -0
- package/archive-parsers.d.ts +2 -0
- package/archive-parsers.js +1 -0
- package/capture-lite.d.ts +2 -0
- package/capture-lite.js +1 -0
- package/import-archive-lite.d.ts +2 -0
- package/import-archive-lite.js +5 -0
- package/import-archive-parsers.d.ts +2 -0
- package/import-archive-parsers.js +1 -0
- package/import-lite.d.ts +2 -0
- package/import-lite.js +1 -0
- package/import-parsers.d.ts +2 -0
- package/import-parsers.js +1 -0
- package/node-modules.d.ts +2 -0
- package/node-modules.js +1 -0
- package/package.json +23 -14
- package/src/archive-lite.d.ts +20 -0
- package/src/archive-lite.d.ts.map +1 -0
- package/src/archive-lite.js +495 -0
- package/src/archive-parsers.d.ts +11 -0
- package/src/archive-parsers.d.ts.map +1 -0
- package/src/archive-parsers.js +26 -0
- package/src/archive.d.ts +0 -6
- package/src/archive.d.ts.map +1 -1
- package/src/archive.js +94 -420
- package/src/bundle-cjs.d.ts +6 -17
- package/src/bundle-cjs.d.ts.map +1 -1
- package/src/bundle-cjs.js +11 -3
- package/src/bundle-json.d.ts +15 -0
- package/src/bundle-json.d.ts.map +1 -0
- package/src/bundle-json.js +24 -0
- package/src/bundle-mjs.d.ts +3 -19
- package/src/bundle-mjs.d.ts.map +1 -1
- package/src/bundle-mjs.js +6 -0
- package/src/bundle.d.ts +53 -10
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +118 -56
- package/src/capture-lite.d.ts +7 -0
- package/src/capture-lite.d.ts.map +1 -0
- package/src/capture-lite.js +324 -0
- package/src/compartment-map.d.ts +1 -1
- package/src/compartment-map.d.ts.map +1 -1
- package/src/compartment-map.js +18 -37
- package/src/extension.d.ts.map +1 -1
- package/src/extension.js +2 -0
- package/src/import-archive-lite.d.ts +26 -0
- package/src/import-archive-lite.d.ts.map +1 -0
- package/src/import-archive-lite.js +455 -0
- package/src/import-archive-parsers.d.ts +9 -0
- package/src/import-archive-parsers.d.ts.map +1 -0
- package/src/import-archive-parsers.js +24 -0
- package/src/import-archive.d.ts +12 -9
- package/src/import-archive.d.ts.map +1 -1
- package/src/import-archive.js +74 -406
- package/src/import-hook.d.ts.map +1 -1
- package/src/import-hook.js +10 -3
- package/src/import-lite.d.ts +9 -0
- package/src/import-lite.d.ts.map +1 -0
- package/src/import-lite.js +121 -0
- package/src/import-parsers.d.ts +9 -0
- package/src/import-parsers.d.ts.map +1 -0
- package/src/import-parsers.js +24 -0
- package/src/import.d.ts +1 -4
- package/src/import.d.ts.map +1 -1
- package/src/import.js +44 -97
- package/src/infer-exports.d.ts +4 -4
- package/src/infer-exports.d.ts.map +1 -1
- package/src/infer-exports.js +29 -20
- package/src/json.d.ts.map +1 -1
- package/src/json.js +1 -0
- package/src/link.d.ts +4 -4
- package/src/link.d.ts.map +1 -1
- package/src/link.js +62 -19
- package/src/node-module-specifier.d.ts.map +1 -1
- package/src/node-module-specifier.js +5 -0
- package/src/node-modules.d.ts +13 -2
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +127 -40
- package/src/node-powers.d.ts +4 -4
- package/src/node-powers.d.ts.map +1 -1
- package/src/node-powers.js +10 -0
- package/src/parse-archive-cjs.d.ts +2 -2
- package/src/parse-archive-cjs.d.ts.map +1 -1
- package/src/parse-archive-cjs.js +4 -0
- package/src/parse-archive-mjs.d.ts +2 -2
- package/src/parse-archive-mjs.d.ts.map +1 -1
- package/src/parse-archive-mjs.js +5 -2
- package/src/parse-bytes.d.ts +2 -2
- package/src/parse-bytes.d.ts.map +1 -1
- package/src/parse-bytes.js +4 -0
- package/src/parse-cjs-shared-export-wrapper.d.ts +2 -2
- package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
- package/src/parse-cjs-shared-export-wrapper.js +16 -1
- package/src/parse-cjs.d.ts +2 -2
- package/src/parse-cjs.d.ts.map +1 -1
- package/src/parse-cjs.js +4 -0
- package/src/parse-json.d.ts +2 -2
- package/src/parse-json.d.ts.map +1 -1
- package/src/parse-json.js +2 -0
- package/src/parse-mjs.d.ts +2 -2
- package/src/parse-mjs.d.ts.map +1 -1
- package/src/parse-mjs.js +4 -2
- package/src/parse-pre-cjs.d.ts +2 -2
- package/src/parse-pre-cjs.d.ts.map +1 -1
- package/src/parse-pre-cjs.js +6 -0
- package/src/parse-pre-mjs.d.ts +2 -2
- package/src/parse-pre-mjs.d.ts.map +1 -1
- package/src/parse-pre-mjs.js +6 -0
- package/src/parse-text.d.ts +2 -2
- package/src/parse-text.d.ts.map +1 -1
- package/src/parse-text.js +5 -0
- package/src/policy-format.d.ts +8 -6
- package/src/policy-format.d.ts.map +1 -1
- package/src/policy-format.js +12 -3
- package/src/policy.d.ts +9 -9
- package/src/policy.d.ts.map +1 -1
- package/src/policy.js +3 -0
- package/src/powers.d.ts +1 -1
- package/src/powers.d.ts.map +1 -1
- package/src/powers.js +7 -0
- package/src/search.d.ts +4 -2
- package/src/search.d.ts.map +1 -1
- package/src/search.js +22 -16
- package/src/types.d.ts +121 -15
- package/src/types.d.ts.map +1 -1
- package/src/types.js +161 -19
- package/src/url.d.ts.map +1 -1
- package/src/url.js +5 -0
package/src/bundle-mjs.d.ts
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
export const runtime: "function observeImports(map, importName, importIndex) {\n for (const [name, observers] of map.get(importName)) {\n const cell = cells[importIndex][name];\n if (cell === undefined) {\n throw new ReferenceError(`Cannot import name ${name}`);\n }\n for (const observer of observers) {\n cell.observe(observer);\n }\n }\n}\n";
|
|
2
|
-
declare
|
|
3
|
-
export { runtime };
|
|
4
|
-
export function getBundlerKit({ index, indexedImports, record: { __syncModuleProgram__, __fixedExportMap__, __liveExportMap__, __reexportMap__, reexports, }, }: {
|
|
5
|
-
index: any;
|
|
6
|
-
indexedImports: any;
|
|
7
|
-
record: {
|
|
8
|
-
__syncModuleProgram__: any;
|
|
9
|
-
__fixedExportMap__?: {} | undefined;
|
|
10
|
-
__liveExportMap__?: {} | undefined;
|
|
11
|
-
__reexportMap__?: {} | undefined;
|
|
12
|
-
reexports: any;
|
|
13
|
-
};
|
|
14
|
-
}): {
|
|
15
|
-
getFunctor: () => string;
|
|
16
|
-
getCells: () => string;
|
|
17
|
-
getReexportsWiring: () => any;
|
|
18
|
-
getFunctorCall: () => string;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
2
|
+
declare const _default: BundlerSupport<PrecompiledModuleSource>;
|
|
21
3
|
export default _default;
|
|
4
|
+
import type { PrecompiledModuleSource } from 'ses';
|
|
5
|
+
import type { BundlerSupport } from './bundle.js';
|
|
22
6
|
//# sourceMappingURL=bundle-mjs.d.ts.map
|
package/src/bundle-mjs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle-mjs.d.ts","sourceRoot":"","sources":["bundle-mjs.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bundle-mjs.d.ts","sourceRoot":"","sources":["bundle-mjs.js"],"names":[],"mappings":"AAsCA,oXAYE;wBAES,eAAe,uBAAuB,CAAC;;6CAlDP,KAAK;oCACd,aAAa"}
|
package/src/bundle-mjs.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/* Provides ESM support for `bundle.js`. */
|
|
2
|
+
|
|
3
|
+
/** @import {PrecompiledModuleSource} from 'ses' */
|
|
4
|
+
/** @import {BundlerSupport} from './bundle.js' */
|
|
5
|
+
|
|
1
6
|
/** quotes strings */
|
|
2
7
|
const q = JSON.stringify;
|
|
3
8
|
|
|
@@ -45,6 +50,7 @@ function observeImports(map, importName, importIndex) {
|
|
|
45
50
|
}
|
|
46
51
|
`;
|
|
47
52
|
|
|
53
|
+
/** @type {BundlerSupport<PrecompiledModuleSource>} */
|
|
48
54
|
export default {
|
|
49
55
|
runtime,
|
|
50
56
|
getBundlerKit({
|
package/src/bundle.d.ts
CHANGED
|
@@ -1,14 +1,57 @@
|
|
|
1
|
-
export function makeBundle(
|
|
2
|
-
moduleTransforms?: ModuleTransforms | undefined;
|
|
3
|
-
dev?: boolean | undefined;
|
|
4
|
-
tags?: Set<string> | undefined;
|
|
5
|
-
commonDependencies?: object;
|
|
6
|
-
searchSuffixes?: string[] | undefined;
|
|
7
|
-
sourceMapHook?: import("./types.js").SourceMapHook | undefined;
|
|
8
|
-
} | undefined): Promise<string>;
|
|
1
|
+
export function makeBundle(readPowers: ReadFn | ReadPowers | MaybeReadPowers, moduleLocation: string, options?: ArchiveOptions | undefined): Promise<string>;
|
|
9
2
|
export function writeBundle(write: WriteFn, read: ReadFn, bundleLocation: string, moduleLocation: string, options?: ArchiveOptions | undefined): Promise<void>;
|
|
3
|
+
export type BundlerKit = {
|
|
4
|
+
/**
|
|
5
|
+
* Produces a JavaScript string consisting of
|
|
6
|
+
* a function expression followed by a comma delimiter that will be evaluated in
|
|
7
|
+
* a lexical scope with no free variables except the globals.
|
|
8
|
+
* In the generated bundle runtime, the function will receive an environment
|
|
9
|
+
* record: a record mapping every name of the corresponding module's internal
|
|
10
|
+
* namespace to a "cell" it can use to get, set, or observe the linked
|
|
11
|
+
* variable.
|
|
12
|
+
*/
|
|
13
|
+
getFunctor: () => string;
|
|
14
|
+
/**
|
|
15
|
+
* Produces a JavaScript string consisting of
|
|
16
|
+
* a JavaScript object and a trailing comma.
|
|
17
|
+
* The string is evaluated in a lexical context with a `cell` maker, the `cells`
|
|
18
|
+
* array of every module's internal environment record.
|
|
19
|
+
*/
|
|
20
|
+
getCells: () => string;
|
|
21
|
+
/**
|
|
22
|
+
* Produces a JavaScript string may
|
|
23
|
+
* be a statement that calls this module's functor with the calling convention
|
|
24
|
+
* appropriate for its language, injecting whatever cells it needs to link to
|
|
25
|
+
* other module namespaces.
|
|
26
|
+
*/
|
|
27
|
+
getFunctorCall: () => string;
|
|
28
|
+
/**
|
|
29
|
+
* Produces a JavaScript string
|
|
30
|
+
* that may include statements that bind the cells reexported by this module.
|
|
31
|
+
*/
|
|
32
|
+
getReexportsWiring: () => string;
|
|
33
|
+
};
|
|
34
|
+
export type BundleModule<SpecificModuleSource extends unknown> = {
|
|
35
|
+
key: string;
|
|
36
|
+
compartmentName: string;
|
|
37
|
+
moduleSpecifier: string;
|
|
38
|
+
parser: string;
|
|
39
|
+
record: StaticModuleType & SpecificModuleSource;
|
|
40
|
+
resolvedImports: Record<string, string>;
|
|
41
|
+
indexedImports: Record<string, number>;
|
|
42
|
+
bytes: Uint8Array;
|
|
43
|
+
index: number;
|
|
44
|
+
bundlerKit: BundlerKit;
|
|
45
|
+
};
|
|
46
|
+
export type GetBundlerKit<SpecificModuleSource extends unknown> = (module: BundleModule<SpecificModuleSource>) => BundlerKit;
|
|
47
|
+
export type BundlerSupport<SpecificModuleSource extends unknown> = {
|
|
48
|
+
runtime: string;
|
|
49
|
+
getBundlerKit: GetBundlerKit<SpecificModuleSource>;
|
|
50
|
+
};
|
|
10
51
|
import type { ReadFn } from './types.js';
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
52
|
+
import type { ReadPowers } from './types.js';
|
|
53
|
+
import type { MaybeReadPowers } from './types.js';
|
|
13
54
|
import type { ArchiveOptions } from './types.js';
|
|
55
|
+
import type { WriteFn } from './types.js';
|
|
56
|
+
import type { StaticModuleType } from 'ses';
|
|
14
57
|
//# sourceMappingURL=bundle.d.ts.map
|
package/src/bundle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["bundle.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["bundle.js"],"names":[],"mappings":"AA4NO,uCALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM,yCAEJ,OAAO,CAAC,MAAM,CAAC,CA4K3B;AASM,mCANI,OAAO,QACP,MAAM,kBACN,MAAM,kBACN,MAAM,uDAahB;;;;;;;;;;;gBAxYa,MAAM,MAAM;;;;;;;cAOZ,MAAM,MAAM;;;;;;;oBAIZ,MAAM,MAAM;;;;;wBAIZ,MAAM,MAAM;;yBAKH,oBAAoB,SAA9B,OAAS;SAER,MAAM;qBACN,MAAM;qBACN,MAAM;YACN,MAAM;YACN,gBAAgB,GAAG,oBAAoB;qBACvC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;oBACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;WACtB,UAAU;WACV,MAAM;gBACN,UAAU;;0BAID,oBAAoB,SAA9B,OAAS,aAEX,YAAY,CAAC,oBAAoB,CAAC,KAChC,UAAU;2BAIA,oBAAoB,SAA9B,OAAS;aAER,MAAM;mBACN,aAAa,CAAC,oBAAoB,CAAC;;4BApDvB,YAAY;gCACR,YAAY;qCAHP,YAAY;oCAHb,YAAY;6BAQnB,YAAY;sCAVH,KAAK"}
|
package/src/bundle.js
CHANGED
|
@@ -1,47 +1,85 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
/* eslint no-shadow: 0 */
|
|
3
3
|
|
|
4
|
-
/** @import {
|
|
5
|
-
|
|
6
|
-
/** @import {
|
|
4
|
+
/** @import {StaticModuleType} from 'ses' */
|
|
5
|
+
|
|
6
|
+
/** @import {ArchiveOptions} from './types.js' */
|
|
7
7
|
/** @import {CompartmentDescriptor} from './types.js' */
|
|
8
8
|
/** @import {CompartmentSources} from './types.js' */
|
|
9
|
+
/** @import {MaybeReadPowers} from './types.js' */
|
|
10
|
+
/** @import {PrecompiledStaticModuleInterface} from 'ses' */
|
|
9
11
|
/** @import {ReadFn} from './types.js' */
|
|
10
|
-
/** @import {
|
|
12
|
+
/** @import {ReadPowers} from './types.js' */
|
|
11
13
|
/** @import {Sources} from './types.js' */
|
|
12
14
|
/** @import {WriteFn} from './types.js' */
|
|
13
|
-
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {object} BundlerKit
|
|
18
|
+
* @property {() => string} getFunctor Produces a JavaScript string consisting of
|
|
19
|
+
* a function expression followed by a comma delimiter that will be evaluated in
|
|
20
|
+
* a lexical scope with no free variables except the globals.
|
|
21
|
+
* In the generated bundle runtime, the function will receive an environment
|
|
22
|
+
* record: a record mapping every name of the corresponding module's internal
|
|
23
|
+
* namespace to a "cell" it can use to get, set, or observe the linked
|
|
24
|
+
* variable.
|
|
25
|
+
* @property {() => string} getCells Produces a JavaScript string consisting of
|
|
26
|
+
* a JavaScript object and a trailing comma.
|
|
27
|
+
* The string is evaluated in a lexical context with a `cell` maker, the `cells`
|
|
28
|
+
* array of every module's internal environment record.
|
|
29
|
+
* @property {() => string} getFunctorCall Produces a JavaScript string may
|
|
30
|
+
* be a statement that calls this module's functor with the calling convention
|
|
31
|
+
* appropriate for its language, injecting whatever cells it needs to link to
|
|
32
|
+
* other module namespaces.
|
|
33
|
+
* @property {() => string} getReexportsWiring Produces a JavaScript string
|
|
34
|
+
* that may include statements that bind the cells reexported by this module.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @template {unknown} SpecificModuleSource
|
|
39
|
+
* @typedef {object} BundleModule
|
|
40
|
+
* @property {string} key
|
|
41
|
+
* @property {string} compartmentName
|
|
42
|
+
* @property {string} moduleSpecifier
|
|
43
|
+
* @property {string} parser
|
|
44
|
+
* @property {StaticModuleType & SpecificModuleSource} record
|
|
45
|
+
* @property {Record<string, string>} resolvedImports
|
|
46
|
+
* @property {Record<string, number>} indexedImports
|
|
47
|
+
* @property {Uint8Array} bytes
|
|
48
|
+
* @property {number} index
|
|
49
|
+
* @property {BundlerKit} bundlerKit
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @template {unknown} SpecificModuleSource
|
|
54
|
+
* @callback GetBundlerKit
|
|
55
|
+
* @param {BundleModule<SpecificModuleSource>} module
|
|
56
|
+
* @returns {BundlerKit}
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @template {unknown} SpecificModuleSource
|
|
61
|
+
* @typedef {object} BundlerSupport
|
|
62
|
+
* @property {string} runtime
|
|
63
|
+
* @property {GetBundlerKit<SpecificModuleSource>} getBundlerKit
|
|
64
|
+
*/
|
|
14
65
|
|
|
15
66
|
import { resolve } from './node-module-specifier.js';
|
|
16
67
|
import { compartmentMapForNodeModules } from './node-modules.js';
|
|
17
68
|
import { search } from './search.js';
|
|
18
69
|
import { link } from './link.js';
|
|
70
|
+
import { unpackReadPowers } from './powers.js';
|
|
19
71
|
import { makeImportHookMaker } from './import-hook.js';
|
|
20
|
-
import
|
|
21
|
-
import parserText from './parse-text.js';
|
|
22
|
-
import parserBytes from './parse-bytes.js';
|
|
23
|
-
import parserArchiveCjs from './parse-archive-cjs.js';
|
|
24
|
-
import parserArchiveMjs from './parse-archive-mjs.js';
|
|
72
|
+
import { defaultParserForLanguage } from './archive-parsers.js';
|
|
25
73
|
import { parseLocatedJson } from './json.js';
|
|
26
74
|
|
|
27
75
|
import mjsSupport from './bundle-mjs.js';
|
|
28
76
|
import cjsSupport from './bundle-cjs.js';
|
|
77
|
+
import jsonSupport from './bundle-json.js';
|
|
29
78
|
|
|
30
79
|
const textEncoder = new TextEncoder();
|
|
31
80
|
|
|
32
81
|
const { quote: q } = assert;
|
|
33
82
|
|
|
34
|
-
/** @type {Record<string, ParserImplementation>} */
|
|
35
|
-
const parserForLanguage = {
|
|
36
|
-
mjs: parserArchiveMjs,
|
|
37
|
-
'pre-mjs-json': parserArchiveMjs,
|
|
38
|
-
cjs: parserArchiveCjs,
|
|
39
|
-
'pre-cjs-json': parserArchiveCjs,
|
|
40
|
-
json: parserJson,
|
|
41
|
-
text: parserText,
|
|
42
|
-
bytes: parserBytes,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
83
|
/**
|
|
46
84
|
* @param {Record<string, CompartmentDescriptor>} compartmentDescriptors
|
|
47
85
|
* @param {Record<string, CompartmentSources>} compartmentSources
|
|
@@ -54,8 +92,11 @@ const sortedModules = (
|
|
|
54
92
|
entryCompartmentName,
|
|
55
93
|
entryModuleSpecifier,
|
|
56
94
|
) => {
|
|
95
|
+
/** @type {BundleModule<unknown>[]} */
|
|
57
96
|
const modules = [];
|
|
97
|
+
/** @type {Map<string, string>} aliaes */
|
|
58
98
|
const aliases = new Map();
|
|
99
|
+
/** @type {Set<string>} seen */
|
|
59
100
|
const seen = new Set();
|
|
60
101
|
|
|
61
102
|
/**
|
|
@@ -71,7 +112,9 @@ const sortedModules = (
|
|
|
71
112
|
|
|
72
113
|
const source = compartmentSources[compartmentName][moduleSpecifier];
|
|
73
114
|
if (source !== undefined) {
|
|
74
|
-
const { record, parser, deferredError } = source;
|
|
115
|
+
const { record, parser, deferredError, bytes } = source;
|
|
116
|
+
assert(parser !== undefined);
|
|
117
|
+
assert(bytes !== undefined);
|
|
75
118
|
if (deferredError) {
|
|
76
119
|
throw Error(
|
|
77
120
|
`Cannot bundle: encountered deferredError ${deferredError}`,
|
|
@@ -99,6 +142,11 @@ const sortedModules = (
|
|
|
99
142
|
parser,
|
|
100
143
|
record,
|
|
101
144
|
resolvedImports,
|
|
145
|
+
bytes,
|
|
146
|
+
// @ts-expect-error
|
|
147
|
+
index: undefined,
|
|
148
|
+
// @ts-expect-error
|
|
149
|
+
bundlerKit: null,
|
|
102
150
|
});
|
|
103
151
|
|
|
104
152
|
return key;
|
|
@@ -132,61 +180,77 @@ const sortedModules = (
|
|
|
132
180
|
return { modules, aliases };
|
|
133
181
|
};
|
|
134
182
|
|
|
135
|
-
|
|
183
|
+
/** @type {Record<string, BundlerSupport<unknown>>} */
|
|
184
|
+
const bundlerSupportForLanguage = {
|
|
136
185
|
'pre-mjs-json': mjsSupport,
|
|
137
186
|
'pre-cjs-json': cjsSupport,
|
|
187
|
+
json: jsonSupport,
|
|
138
188
|
};
|
|
139
189
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
190
|
+
/** @param {string} language */
|
|
191
|
+
const getRuntime = language =>
|
|
192
|
+
bundlerSupportForLanguage[language]
|
|
193
|
+
? bundlerSupportForLanguage[language].runtime
|
|
194
|
+
: `/*unknown language:${language}*/`;
|
|
195
|
+
|
|
196
|
+
/** @param {BundleModule<unknown>} module */
|
|
197
|
+
const getBundlerKitForModule = module => {
|
|
198
|
+
const language = module.parser;
|
|
199
|
+
assert(language !== undefined);
|
|
200
|
+
if (bundlerSupportForLanguage[language] === undefined) {
|
|
201
|
+
const warning = `/*unknown language:${language}*/`;
|
|
150
202
|
// each item is a function to avoid creating more in-memory copies of the source text etc.
|
|
203
|
+
/** @type {BundlerKit} */
|
|
151
204
|
return {
|
|
152
|
-
getFunctor: () => `(()=>{${warning}})
|
|
153
|
-
getCells: `{${warning}}
|
|
154
|
-
getFunctorCall: warning,
|
|
205
|
+
getFunctor: () => `(()=>{${warning}}),`,
|
|
206
|
+
getCells: () => `{${warning}},`,
|
|
207
|
+
getFunctorCall: () => warning,
|
|
208
|
+
getReexportsWiring: () => '',
|
|
155
209
|
};
|
|
156
210
|
}
|
|
157
|
-
const { getBundlerKit } =
|
|
211
|
+
const { getBundlerKit } = bundlerSupportForLanguage[language];
|
|
158
212
|
return getBundlerKit(module);
|
|
159
|
-
}
|
|
213
|
+
};
|
|
160
214
|
|
|
161
215
|
/**
|
|
162
|
-
* @param {ReadFn}
|
|
216
|
+
* @param {ReadFn | ReadPowers | MaybeReadPowers} readPowers
|
|
163
217
|
* @param {string} moduleLocation
|
|
164
|
-
* @param {
|
|
165
|
-
* @param {ModuleTransforms} [options.moduleTransforms]
|
|
166
|
-
* @param {boolean} [options.dev]
|
|
167
|
-
* @param {Set<string>} [options.tags]
|
|
168
|
-
* @param {object} [options.commonDependencies]
|
|
169
|
-
* @param {Array<string>} [options.searchSuffixes]
|
|
170
|
-
* @param {import('./types.js').SourceMapHook} [options.sourceMapHook]
|
|
218
|
+
* @param {ArchiveOptions} [options]
|
|
171
219
|
* @returns {Promise<string>}
|
|
172
220
|
*/
|
|
173
|
-
export const makeBundle = async (
|
|
221
|
+
export const makeBundle = async (readPowers, moduleLocation, options) => {
|
|
222
|
+
const { read } = unpackReadPowers(readPowers);
|
|
223
|
+
|
|
174
224
|
const {
|
|
175
225
|
moduleTransforms,
|
|
176
226
|
dev,
|
|
177
227
|
tags: tagsOption,
|
|
228
|
+
conditions: conditionsOption = tagsOption,
|
|
178
229
|
searchSuffixes,
|
|
179
230
|
commonDependencies,
|
|
180
231
|
sourceMapHook = undefined,
|
|
232
|
+
parserForLanguage: parserForLanguageOption = {},
|
|
233
|
+
languageForExtension: languageForExtensionOption = {},
|
|
181
234
|
} = options || {};
|
|
182
|
-
const
|
|
235
|
+
const conditions = new Set(conditionsOption);
|
|
236
|
+
|
|
237
|
+
const parserForLanguage = Object.freeze(
|
|
238
|
+
Object.assign(
|
|
239
|
+
Object.create(null),
|
|
240
|
+
defaultParserForLanguage,
|
|
241
|
+
parserForLanguageOption,
|
|
242
|
+
),
|
|
243
|
+
);
|
|
244
|
+
const languageForExtension = Object.freeze(
|
|
245
|
+
Object.assign(Object.create(null), languageForExtensionOption),
|
|
246
|
+
);
|
|
183
247
|
|
|
184
248
|
const {
|
|
185
249
|
packageLocation,
|
|
186
250
|
packageDescriptorText,
|
|
187
251
|
packageDescriptorLocation,
|
|
188
252
|
moduleSpecifier,
|
|
189
|
-
} = await search(
|
|
253
|
+
} = await search(readPowers, moduleLocation);
|
|
190
254
|
|
|
191
255
|
const packageDescriptor = parseLocatedJson(
|
|
192
256
|
packageDescriptorText,
|
|
@@ -195,7 +259,7 @@ export const makeBundle = async (read, moduleLocation, options) => {
|
|
|
195
259
|
const compartmentMap = await compartmentMapForNodeModules(
|
|
196
260
|
read,
|
|
197
261
|
packageLocation,
|
|
198
|
-
|
|
262
|
+
conditions,
|
|
199
263
|
packageDescriptor,
|
|
200
264
|
moduleSpecifier,
|
|
201
265
|
{ dev, commonDependencies },
|
|
@@ -223,6 +287,7 @@ export const makeBundle = async (read, moduleLocation, options) => {
|
|
|
223
287
|
makeImportHook,
|
|
224
288
|
moduleTransforms,
|
|
225
289
|
parserForLanguage,
|
|
290
|
+
languageForExtension,
|
|
226
291
|
});
|
|
227
292
|
await compartment.load(entryModuleSpecifier);
|
|
228
293
|
|
|
@@ -271,10 +336,7 @@ export const makeBundle = async (read, moduleLocation, options) => {
|
|
|
271
336
|
|
|
272
337
|
const bundle = `\
|
|
273
338
|
'use strict';
|
|
274
|
-
(
|
|
275
|
-
const functors = [
|
|
276
|
-
${''.concat(...modules.map(m => m.bundlerKit.getFunctor()))}\
|
|
277
|
-
]; // functors end
|
|
339
|
+
(functors => {
|
|
278
340
|
|
|
279
341
|
const cell = (name, value = undefined) => {
|
|
280
342
|
const observers = [];
|
|
@@ -302,7 +364,7 @@ ${''.concat(...modules.map(m => m.bundlerKit.getCells()))}\
|
|
|
302
364
|
|
|
303
365
|
${''.concat(...modules.map(m => m.bundlerKit.getReexportsWiring()))}\
|
|
304
366
|
|
|
305
|
-
const namespaces = cells.map(cells => Object.freeze(Object.create(null, {
|
|
367
|
+
const namespaces = cells.map(cells => Object.freeze(Object.create(null, {
|
|
306
368
|
...cells,
|
|
307
369
|
// Make this appear like an ESM module namespace object.
|
|
308
370
|
[Symbol.toStringTag]: {
|
|
@@ -322,7 +384,7 @@ ${''.concat(...Array.from(parsersInUse).map(parser => getRuntime(parser)))}
|
|
|
322
384
|
${''.concat(...modules.map(m => m.bundlerKit.getFunctorCall()))}\
|
|
323
385
|
|
|
324
386
|
return cells[cells.length - 1]['*'].get();
|
|
325
|
-
})();
|
|
387
|
+
})([${''.concat(...modules.map(m => m.bundlerKit.getFunctor()))}]);
|
|
326
388
|
`;
|
|
327
389
|
|
|
328
390
|
return bundle;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function captureFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: CaptureOptions | undefined): Promise<CaptureResult>;
|
|
2
|
+
import type { ReadFn } from './types.js';
|
|
3
|
+
import type { ReadPowers } from './types.js';
|
|
4
|
+
import type { CompartmentMapDescriptor } from './types.js';
|
|
5
|
+
import type { CaptureOptions } from './types.js';
|
|
6
|
+
import type { CaptureResult } from './types.js';
|
|
7
|
+
//# sourceMappingURL=capture-lite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture-lite.d.ts","sourceRoot":"","sources":["capture-lite.js"],"names":[],"mappings":"AAkQO,uCALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,yCAEtB,OAAO,CAAC,aAAa,CAAC,CAmElC;4BAlSyB,YAAY;gCACR,YAAY;8CACE,YAAY;oCACtB,YAAY;mCAIb,YAAY"}
|