@endo/compartment-mapper 1.6.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +24 -14
- package/src/archive-lite.d.ts +7 -7
- package/src/archive-lite.d.ts.map +1 -1
- package/src/archive-lite.js +81 -30
- package/src/archive.d.ts.map +1 -1
- package/src/archive.js +7 -0
- package/src/bundle-lite.d.ts +3 -3
- package/src/bundle-lite.d.ts.map +1 -1
- package/src/bundle-lite.js +19 -24
- package/src/bundle.d.ts +3 -3
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +19 -24
- package/src/capture-lite.d.ts +2 -2
- package/src/capture-lite.d.ts.map +1 -1
- package/src/capture-lite.js +243 -25
- package/src/compartment-map.d.ts +9 -2
- package/src/compartment-map.d.ts.map +1 -1
- package/src/compartment-map.js +738 -254
- package/src/digest.d.ts +22 -2
- package/src/digest.d.ts.map +1 -1
- package/src/digest.js +180 -57
- package/src/generic-graph.d.ts +7 -25
- package/src/generic-graph.d.ts.map +1 -1
- package/src/generic-graph.js +83 -108
- package/src/guards.d.ts +18 -0
- package/src/guards.d.ts.map +1 -0
- package/src/guards.js +109 -0
- package/src/hooks.md +124 -0
- package/src/import-archive-lite.d.ts.map +1 -1
- package/src/import-archive-lite.js +15 -11
- package/src/import-archive.d.ts +5 -19
- package/src/import-archive.d.ts.map +1 -1
- package/src/import-archive.js +7 -27
- package/src/import-hook.d.ts +4 -3
- package/src/import-hook.d.ts.map +1 -1
- package/src/import-hook.js +140 -70
- package/src/import-lite.d.ts +6 -6
- package/src/import-lite.d.ts.map +1 -1
- package/src/import-lite.js +8 -5
- package/src/import.d.ts +3 -3
- package/src/import.d.ts.map +1 -1
- package/src/import.js +16 -6
- package/src/infer-exports.d.ts +4 -2
- package/src/infer-exports.d.ts.map +1 -1
- package/src/infer-exports.js +172 -23
- package/src/link.d.ts +4 -3
- package/src/link.d.ts.map +1 -1
- package/src/link.js +122 -52
- package/src/node-modules.d.ts +4 -3
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +513 -151
- package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
- package/src/parse-cjs-shared-export-wrapper.js +3 -1
- package/src/pattern-replacement.d.ts +6 -0
- package/src/pattern-replacement.d.ts.map +1 -0
- package/src/pattern-replacement.js +198 -0
- package/src/policy-format.d.ts +22 -5
- package/src/policy-format.d.ts.map +1 -1
- package/src/policy-format.js +342 -108
- package/src/policy.d.ts +13 -28
- package/src/policy.d.ts.map +1 -1
- package/src/policy.js +161 -106
- package/src/types/canonical-name.d.ts +97 -0
- package/src/types/canonical-name.d.ts.map +1 -0
- package/src/types/canonical-name.ts +151 -0
- package/src/types/compartment-map-schema.d.ts +121 -35
- package/src/types/compartment-map-schema.d.ts.map +1 -1
- package/src/types/compartment-map-schema.ts +211 -37
- package/src/types/external.d.ts +240 -76
- package/src/types/external.d.ts.map +1 -1
- package/src/types/external.ts +305 -74
- package/src/types/generic-graph.d.ts +8 -2
- package/src/types/generic-graph.d.ts.map +1 -1
- package/src/types/generic-graph.ts +7 -2
- package/src/types/internal.d.ts +31 -50
- package/src/types/internal.d.ts.map +1 -1
- package/src/types/internal.ts +60 -58
- package/src/types/node-modules.d.ts +112 -14
- package/src/types/node-modules.d.ts.map +1 -1
- package/src/types/node-modules.ts +152 -13
- package/src/types/pattern-replacement.d.ts +62 -0
- package/src/types/pattern-replacement.d.ts.map +1 -0
- package/src/types/pattern-replacement.ts +70 -0
- package/src/types/policy-schema.d.ts +26 -11
- package/src/types/policy-schema.d.ts.map +1 -1
- package/src/types/policy-schema.ts +29 -16
- package/src/types/policy.d.ts +6 -2
- package/src/types/policy.d.ts.map +1 -1
- package/src/types/policy.ts +7 -2
- package/src/types/powers.d.ts +11 -9
- package/src/types/powers.d.ts.map +1 -1
- package/src/types/powers.ts +11 -10
- package/src/types/typescript.d.ts +28 -0
- package/src/types/typescript.d.ts.map +1 -1
- package/src/types/typescript.ts +37 -1
package/src/import.d.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* @overload
|
|
3
3
|
* @param {ReadNowPowers} readPowers
|
|
4
4
|
* @param {string} moduleLocation
|
|
5
|
-
* @param {
|
|
5
|
+
* @param {SyncLoadLocationOptions} options
|
|
6
6
|
* @returns {Promise<Application>}
|
|
7
7
|
*/
|
|
8
|
-
export function loadLocation(readPowers: ReadNowPowers, moduleLocation: string, options:
|
|
8
|
+
export function loadLocation(readPowers: ReadNowPowers, moduleLocation: string, options: SyncLoadLocationOptions): Promise<Application>;
|
|
9
9
|
/**
|
|
10
10
|
* @overload
|
|
11
11
|
* @param {ReadFn | ReadPowers} readPowers
|
|
@@ -37,7 +37,7 @@ export function importLocation(readPowers: ReadNowPowers, moduleLocation: string
|
|
|
37
37
|
*/
|
|
38
38
|
export function importLocation(readPowers: ReadPowers | ReadFn, moduleLocation: string, options?: ImportLocationOptions | undefined): Promise<SomeObject>;
|
|
39
39
|
import type { ReadNowPowers } from './types.js';
|
|
40
|
-
import type {
|
|
40
|
+
import type { SyncLoadLocationOptions } from './types.js';
|
|
41
41
|
import type { Application } from './types.js';
|
|
42
42
|
import type { ReadFn } from './types.js';
|
|
43
43
|
import type { ReadPowers } from './types.js';
|
package/src/import.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["import.js"],"names":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["import.js"],"names":[],"mappings":";;;;;;;AAkDG,yCACQ,aAAa,kBACb,MAAM,WACN,uBAAuB,GACrB,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;AAGE,yCACQ,MAAM,GAAG,UAAU,kBACnB,MAAM,8CAEJ,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;;;;AAkEE,2CACQ,aAAa,kBACb,MAAM,WACN,yBAAyB,GACvB,OAAO,CAAC,UAAU,CAAC,CAE/B;;;;;;;;;;;AAKE,2CACQ,UAAU,GAAC,MAAM,kBACjB,MAAM,gDAEJ,OAAO,CAAC,UAAU,CAAC,CAE/B;mCAxHS,YAAY;6CAAZ,YAAY;iCAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;yCAAZ,YAAY;+CAAZ,YAAY;gCAAZ,YAAY;2CAAZ,YAAY"}
|
package/src/import.js
CHANGED
|
@@ -18,26 +18,25 @@
|
|
|
18
18
|
* Application,
|
|
19
19
|
* SyncImportLocationOptions,
|
|
20
20
|
* ImportLocationOptions,
|
|
21
|
-
* SyncArchiveOptions,
|
|
22
21
|
* LoadLocationOptions,
|
|
23
22
|
* SomeObject,
|
|
24
23
|
* ReadNowPowers,
|
|
25
|
-
* ArchiveOptions,
|
|
26
24
|
* ReadFn,
|
|
27
25
|
* ReadPowers,
|
|
26
|
+
SyncLoadLocationOptions,
|
|
28
27
|
* } from './types.js'
|
|
29
28
|
*/
|
|
30
29
|
|
|
30
|
+
import { loadFromMap } from './import-lite.js';
|
|
31
31
|
import { defaultParserForLanguage } from './import-parsers.js';
|
|
32
32
|
import { mapNodeModules } from './node-modules.js';
|
|
33
|
-
import { loadFromMap } from './import-lite.js';
|
|
34
33
|
|
|
35
34
|
const { assign, create, freeze } = Object;
|
|
36
35
|
|
|
37
36
|
/**
|
|
38
37
|
* Add the default parserForLanguage option.
|
|
39
|
-
* @param {
|
|
40
|
-
* @returns {
|
|
38
|
+
* @param {LoadLocationOptions} [options]
|
|
39
|
+
* @returns {LoadLocationOptions}
|
|
41
40
|
*/
|
|
42
41
|
const assignParserForLanguage = (options = {}) => {
|
|
43
42
|
const { parserForLanguage: parserForLanguageOption, ...rest } = options;
|
|
@@ -52,7 +51,7 @@ const assignParserForLanguage = (options = {}) => {
|
|
|
52
51
|
* @overload
|
|
53
52
|
* @param {ReadNowPowers} readPowers
|
|
54
53
|
* @param {string} moduleLocation
|
|
55
|
-
* @param {
|
|
54
|
+
* @param {SyncLoadLocationOptions} options
|
|
56
55
|
* @returns {Promise<Application>}
|
|
57
56
|
*/
|
|
58
57
|
|
|
@@ -82,6 +81,7 @@ export const loadLocation = async (
|
|
|
82
81
|
commonDependencies,
|
|
83
82
|
policy,
|
|
84
83
|
parserForLanguage,
|
|
84
|
+
log,
|
|
85
85
|
languages,
|
|
86
86
|
languageForExtension,
|
|
87
87
|
commonjsLanguageForExtension,
|
|
@@ -89,6 +89,10 @@ export const loadLocation = async (
|
|
|
89
89
|
workspaceLanguageForExtension,
|
|
90
90
|
workspaceCommonjsLanguageForExtension,
|
|
91
91
|
workspaceModuleLanguageForExtension,
|
|
92
|
+
unknownCanonicalNameHook,
|
|
93
|
+
packageDataHook,
|
|
94
|
+
packageDependenciesHook,
|
|
95
|
+
moduleSourceHook,
|
|
92
96
|
...otherOptions
|
|
93
97
|
} = assignParserForLanguage(options);
|
|
94
98
|
// conditions are not present in SyncArchiveOptions
|
|
@@ -107,9 +111,15 @@ export const loadLocation = async (
|
|
|
107
111
|
workspaceCommonjsLanguageForExtension,
|
|
108
112
|
workspaceModuleLanguageForExtension,
|
|
109
113
|
languages,
|
|
114
|
+
log,
|
|
115
|
+
unknownCanonicalNameHook,
|
|
116
|
+
packageDataHook,
|
|
117
|
+
packageDependenciesHook,
|
|
110
118
|
});
|
|
111
119
|
return loadFromMap(readPowers, compartmentMap, {
|
|
112
120
|
parserForLanguage,
|
|
121
|
+
log,
|
|
122
|
+
moduleSourceHook,
|
|
113
123
|
...otherOptions,
|
|
114
124
|
});
|
|
115
125
|
};
|
package/src/infer-exports.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export function inferExportsEntries({ main, module, exports }: PackageDescriptor, conditions: Set<string>, types: LanguageForExtension): Generator<string[], void, any>;
|
|
1
|
+
export function inferExportsEntries({ main, module, exports }: PackageDescriptor, conditions: Set<string>, types: LanguageForExtension): Generator<string[] | [string, string | null], void, any>;
|
|
2
2
|
export function inferExports(descriptor: PackageDescriptor, conditions: Set<string>, types: LanguageForExtension): Record<string, string>;
|
|
3
|
-
export function
|
|
3
|
+
export function inferExportsAliasesAndPatterns(descriptor: PackageDescriptor, externalAliases: Node["externalAliases"], internalAliases: Node["internalAliases"], patterns: PatternDescriptor[], conditions: Set<string>, types: Record<string, string>, log: LogFn): void;
|
|
4
4
|
import type { PackageDescriptor } from './types.js';
|
|
5
5
|
import type { LanguageForExtension } from './types.js';
|
|
6
6
|
import type { Node } from './types/node-modules.js';
|
|
7
|
+
import type { PatternDescriptor } from './types/pattern-replacement.js';
|
|
8
|
+
import type { LogFn } from './types/external.js';
|
|
7
9
|
//# sourceMappingURL=infer-exports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infer-exports.d.ts","sourceRoot":"","sources":["infer-exports.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"infer-exports.d.ts","sourceRoot":"","sources":["infer-exports.js"],"names":[],"mappings":"AAyLO,+DAPI,iBAAiB,cACjB,GAAG,CAAC,MAAM,CAAC,SAEX,oBAAoB,4DA2B9B;AAkBM,yCAPI,iBAAiB,cACjB,GAAG,CAAC,MAAM,CAAC,SAEX,oBAAoB,GAElB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAG8B;AAyD1D,2DARI,iBAAiB,mBACjB,IAAI,CAAC,iBAAiB,CAAC,mBACvB,IAAI,CAAC,iBAAiB,CAAC,YACvB,iBAAiB,EAAE,cACnB,GAAG,CAAC,MAAM,CAAC,SACX,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OACtB,KAAK,QAsFf;uCArWyD,YAAY;0CAAZ,YAAY;0BAE7B,yBAAyB;uCAC9B,gCAAgC;2BAF5C,qBAAqB"}
|
package/src/infer-exports.js
CHANGED
|
@@ -10,12 +10,14 @@
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @import {LanguageForExtension, PackageDescriptor} from './types.js'
|
|
13
|
-
* @import {
|
|
13
|
+
* @import {LogFn} from './types/external.js'
|
|
14
|
+
* @import {Exports, Imports, Node} from './types/node-modules.js'
|
|
15
|
+
* @import {PatternDescriptor} from './types/pattern-replacement.js'
|
|
14
16
|
*/
|
|
15
17
|
|
|
16
|
-
import {
|
|
18
|
+
import { relativize } from './node-module-specifier.js';
|
|
17
19
|
|
|
18
|
-
const { entries, fromEntries
|
|
20
|
+
const { entries, fromEntries } = Object;
|
|
19
21
|
const { isArray } = Array;
|
|
20
22
|
|
|
21
23
|
/**
|
|
@@ -60,16 +62,23 @@ function* interpretBrowserField(name, browser, main = 'index.js') {
|
|
|
60
62
|
|
|
61
63
|
/**
|
|
62
64
|
* @param {string} name - the name of the referrer package.
|
|
63
|
-
* @param {
|
|
65
|
+
* @param {Exports} exports - the `exports` field from a package.json.
|
|
64
66
|
* @param {Set<string>} conditions - build conditions about the target environment
|
|
65
67
|
* for selecting relevant exports, e.g., "browser" or "node".
|
|
66
|
-
* @
|
|
67
|
-
*
|
|
68
|
+
* @param {LanguageForExtension} types - an object to populate
|
|
69
|
+
* with any recognized module's type, if implied by a tag.
|
|
70
|
+
* @yields {[string, string | null]}
|
|
71
|
+
* @returns {Generator<[string, string | null]>}
|
|
68
72
|
*/
|
|
69
|
-
function* interpretExports(name, exports, conditions) {
|
|
73
|
+
function* interpretExports(name, exports, conditions, types) {
|
|
74
|
+
// Null targets are exclusions (Node.js semantics).
|
|
75
|
+
if (exports === null) {
|
|
76
|
+
yield [name, null];
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
70
79
|
if (isArray(exports)) {
|
|
71
80
|
for (const section of exports) {
|
|
72
|
-
const results = [...interpretExports(name, section, conditions)];
|
|
81
|
+
const results = [...interpretExports(name, section, conditions, types)];
|
|
73
82
|
if (results.length > 0) {
|
|
74
83
|
yield* results;
|
|
75
84
|
break;
|
|
@@ -92,19 +101,71 @@ function* interpretExports(name, exports, conditions) {
|
|
|
92
101
|
// eslint-disable-next-line no-continue
|
|
93
102
|
continue; // or no-op
|
|
94
103
|
} else if (key.startsWith('./') || key === '.') {
|
|
95
|
-
|
|
96
|
-
yield* interpretExports(key, value, conditions);
|
|
97
|
-
} else {
|
|
98
|
-
yield* interpretExports(join(name, key), value, conditions);
|
|
99
|
-
}
|
|
104
|
+
yield* interpretExports(key, value, conditions, types);
|
|
100
105
|
} else if (conditions.has(key)) {
|
|
101
|
-
|
|
106
|
+
if (types && key === 'import' && typeof value === 'string') {
|
|
107
|
+
// In this one case, the key "import" has carried a hint that the
|
|
108
|
+
// referenced module is an ECMASCript module, and that hint may be
|
|
109
|
+
// necessary to override whatever type might be inferred from the module
|
|
110
|
+
// specifier extension.
|
|
111
|
+
const spec = relativize(value);
|
|
112
|
+
types[spec] = 'mjs';
|
|
113
|
+
}
|
|
114
|
+
yield* interpretExports(name, value, conditions, types);
|
|
102
115
|
// Take only the first matching tag.
|
|
103
116
|
break;
|
|
104
117
|
}
|
|
105
118
|
}
|
|
106
119
|
}
|
|
107
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Interprets the `imports` field from a package.json file.
|
|
123
|
+
* The imports field provides self-referencing subpath patterns that
|
|
124
|
+
* can be used to create private internal mappings.
|
|
125
|
+
*
|
|
126
|
+
* @param {Imports} imports - the `imports` field from a package.json.
|
|
127
|
+
* @param {Set<string>} conditions - build conditions about the target environment
|
|
128
|
+
* @param {LogFn} log
|
|
129
|
+
* @yields {[string, string | null]}
|
|
130
|
+
* @returns {Generator<[string, string | null]>}
|
|
131
|
+
*/
|
|
132
|
+
function* interpretImports(imports, conditions, log) {
|
|
133
|
+
if (Object(imports) !== imports || Array.isArray(imports)) {
|
|
134
|
+
throw Error(
|
|
135
|
+
`Cannot interpret package.json imports property, must be object, got ${imports}`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
for (const [key, value] of entries(imports)) {
|
|
139
|
+
// imports keys must start with '#'
|
|
140
|
+
if (!key.startsWith('#')) {
|
|
141
|
+
log(`Ignoring invalid imports key "${key}": must start with "#"`);
|
|
142
|
+
// eslint-disable-next-line no-continue
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (value === null) {
|
|
146
|
+
// Null targets are exclusions (Node.js semantics).
|
|
147
|
+
yield [key, null];
|
|
148
|
+
} else if (typeof value === 'string') {
|
|
149
|
+
yield [key, relativize(value)];
|
|
150
|
+
} else if (Object(value) === value && !isArray(value)) {
|
|
151
|
+
// Handle conditional imports
|
|
152
|
+
for (const [condition, target] of entries(value)) {
|
|
153
|
+
if (conditions.has(condition)) {
|
|
154
|
+
if (target === null) {
|
|
155
|
+
yield [key, null];
|
|
156
|
+
} else if (typeof target === 'string') {
|
|
157
|
+
yield [key, relativize(target)];
|
|
158
|
+
}
|
|
159
|
+
// Take only the first matching condition
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
log(`Ignoring unsupported imports value for "${key}": ${typeof value}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
108
169
|
/**
|
|
109
170
|
* Given an unpacked `package.json`, generate a series of `[name, target]`
|
|
110
171
|
* pairs to represent what this package exports. `name` is what the
|
|
@@ -120,7 +181,7 @@ function* interpretExports(name, exports, conditions) {
|
|
|
120
181
|
* for selecting relevant exports, e.g., "browser" or "node".
|
|
121
182
|
* @param {LanguageForExtension} types - an object to populate
|
|
122
183
|
* with any recognized module's type, if implied by a tag.
|
|
123
|
-
* @yields {[string, string]}
|
|
184
|
+
* @yields {[string, string | null]}
|
|
124
185
|
*/
|
|
125
186
|
export const inferExportsEntries = function* inferExportsEntries(
|
|
126
187
|
{ main, module, exports },
|
|
@@ -141,7 +202,7 @@ export const inferExportsEntries = function* inferExportsEntries(
|
|
|
141
202
|
yield ['.', relativize(main)];
|
|
142
203
|
}
|
|
143
204
|
if (exports !== undefined) {
|
|
144
|
-
yield* interpretExports('.', exports, conditions);
|
|
205
|
+
yield* interpretExports('.', exports, conditions, types);
|
|
145
206
|
}
|
|
146
207
|
// TODO Otherwise, glob 'files' for all '.js', '.cjs', and '.mjs' entry
|
|
147
208
|
// modules, taking care to exclude node_modules.
|
|
@@ -167,27 +228,115 @@ export const inferExports = (descriptor, conditions, types) =>
|
|
|
167
228
|
fromEntries(inferExportsEntries(descriptor, conditions, types));
|
|
168
229
|
|
|
169
230
|
/**
|
|
231
|
+
* Determines if a key or value contains a wildcard pattern.
|
|
232
|
+
*
|
|
233
|
+
* @param {string} key
|
|
234
|
+
* @param {string | null} value
|
|
235
|
+
* @returns {boolean}
|
|
236
|
+
*/
|
|
237
|
+
const hasWildcard = (key, value) =>
|
|
238
|
+
key.includes('*') || (value?.includes('*') ?? false);
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Returns the number of `*` characters in a string.
|
|
242
|
+
*
|
|
243
|
+
* @param {string} str
|
|
244
|
+
* @returns {number}
|
|
245
|
+
*/
|
|
246
|
+
const countWildcards = str => (str.match(/\*/g) || []).length;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Validates a wildcard pattern entry and logs warnings for invalid patterns.
|
|
250
|
+
* Returns true if the pattern is valid and should be used.
|
|
251
|
+
*
|
|
252
|
+
* @param {string} key
|
|
253
|
+
* @param {string} value
|
|
254
|
+
* @param {LogFn} log
|
|
255
|
+
* @returns {boolean}
|
|
256
|
+
*/
|
|
257
|
+
const validateWildcardPattern = (key, value, log) => {
|
|
258
|
+
const keyCount = countWildcards(key);
|
|
259
|
+
const valueCount = countWildcards(value);
|
|
260
|
+
if (keyCount > 1 || valueCount > 1) {
|
|
261
|
+
log(`Ignoring pattern with multiple wildcards "${key}": "${value}"`);
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
if (keyCount !== valueCount) {
|
|
265
|
+
log(
|
|
266
|
+
`Ignoring pattern with mismatched wildcard count "${key}" (${keyCount}) vs "${value}" (${valueCount})`,
|
|
267
|
+
);
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
return true;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Infers exports, internal aliases, and wildcard patterns from a package descriptor.
|
|
275
|
+
* Extracts wildcard patterns from the `exports` and `imports` fields.
|
|
170
276
|
*
|
|
171
277
|
* @param {PackageDescriptor} descriptor
|
|
172
278
|
* @param {Node['externalAliases']} externalAliases
|
|
173
279
|
* @param {Node['internalAliases']} internalAliases
|
|
280
|
+
* @param {PatternDescriptor[]} patterns - array to populate with wildcard patterns
|
|
174
281
|
* @param {Set<string>} conditions
|
|
175
282
|
* @param {Record<string, string>} types
|
|
283
|
+
* @param {LogFn} log
|
|
176
284
|
*/
|
|
177
|
-
export const
|
|
285
|
+
export const inferExportsAliasesAndPatterns = (
|
|
178
286
|
descriptor,
|
|
179
287
|
externalAliases,
|
|
180
288
|
internalAliases,
|
|
289
|
+
patterns,
|
|
181
290
|
conditions,
|
|
182
291
|
types,
|
|
292
|
+
log,
|
|
183
293
|
) => {
|
|
184
|
-
const { name, type, main, module, exports, browser } = descriptor;
|
|
294
|
+
const { name, type, main, module, exports, imports, browser } = descriptor;
|
|
185
295
|
|
|
186
|
-
//
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
296
|
+
// Process exports field - separate wildcards from concrete exports.
|
|
297
|
+
for (const [key, value] of inferExportsEntries(
|
|
298
|
+
descriptor,
|
|
299
|
+
conditions,
|
|
300
|
+
types,
|
|
301
|
+
)) {
|
|
302
|
+
if (value === null) {
|
|
303
|
+
// Null targets are exclusions.
|
|
304
|
+
// Only wildcard null targets need to be stored as patterns;
|
|
305
|
+
// concrete null targets are excluded by omission from aliases.
|
|
306
|
+
if (key.includes('*')) {
|
|
307
|
+
patterns.push({ from: key, to: null });
|
|
308
|
+
}
|
|
309
|
+
// eslint-disable-next-line no-continue
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (hasWildcard(key, value)) {
|
|
313
|
+
if (validateWildcardPattern(key, value, log)) {
|
|
314
|
+
patterns.push({ from: key, to: value });
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
externalAliases[key] = value;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Process imports field (package self-referencing).
|
|
322
|
+
if (imports !== undefined) {
|
|
323
|
+
for (const [key, value] of interpretImports(imports, conditions, log)) {
|
|
324
|
+
if (value === null) {
|
|
325
|
+
if (key.includes('*')) {
|
|
326
|
+
patterns.push({ from: key, to: null });
|
|
327
|
+
}
|
|
328
|
+
// eslint-disable-next-line no-continue
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (hasWildcard(key, value)) {
|
|
332
|
+
if (validateWildcardPattern(key, value, log)) {
|
|
333
|
+
patterns.push({ from: key, to: value });
|
|
334
|
+
}
|
|
335
|
+
} else {
|
|
336
|
+
internalAliases[key] = value;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
191
340
|
|
|
192
341
|
// expose default module as package root
|
|
193
342
|
// may be overwritten by browser field
|
package/src/link.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export function link({ entry, compartments: compartmentDescriptors }:
|
|
2
|
-
export function assemble(compartmentMap:
|
|
3
|
-
import type {
|
|
1
|
+
export function link({ entry, compartments: compartmentDescriptors }: PackageCompartmentMapDescriptor | FileCompartmentMapDescriptor, options: LinkOptions): LinkResult;
|
|
2
|
+
export function assemble(compartmentMap: PackageCompartmentMapDescriptor, options: LinkOptions): Compartment;
|
|
3
|
+
import type { PackageCompartmentMapDescriptor } from './types.js';
|
|
4
|
+
import type { FileCompartmentMapDescriptor } from './types.js';
|
|
4
5
|
import type { LinkOptions } from './types.js';
|
|
5
6
|
import type { LinkResult } from './types.js';
|
|
6
7
|
//# sourceMappingURL=link.d.ts.map
|
package/src/link.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["link.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["link.js"],"names":[],"mappings":"AAyTO,sEAJI,+BAA+B,GAAC,4BAA4B,WAC5D,WAAW,GACT,UAAU,CAgLtB;AAOM,yCAJI,+BAA+B,WAC/B,WAAW,eAIqB;qDAhdjC,YAAY;kDAAZ,YAAY;iCAAZ,YAAY;gCAAZ,YAAY"}
|