@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-cjs-shared-export-wrapper.d.ts","sourceRoot":"","sources":["parse-cjs-shared-export-wrapper.js"],"names":[],"mappings":"AA0CO,2CAPI,UAAU,GAAG,MAAM,GAAG,SAAS,YAC/B,MAAM,GACJ;IACR,QAAQ,EAAC,MAAM,GAAC,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAC,IAAI,CAAA;CACrB,CAgCH;AAmBM,uGAZJ;IAAmB,uBAAuB,EAAlC,MAAM;IACU,WAAW,EAA3B,WAAW;IACgB,eAAe,EAA1C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACX,QAAQ,EAAnB,MAAM;IAC8B,UAAU,EAA9C,MAAM,GAAG,UAAU,GAAG,SAAS;CACvC,GAAU;IACR,MAAM,EAAE;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC;IACzB,aAAa,EAAE,GAAG,CAAC;IACnB,YAAY,WAAW;IACvB,OAAO,WAAW;CACnB,
|
|
1
|
+
{"version":3,"file":"parse-cjs-shared-export-wrapper.d.ts","sourceRoot":"","sources":["parse-cjs-shared-export-wrapper.js"],"names":[],"mappings":"AA0CO,2CAPI,UAAU,GAAG,MAAM,GAAG,SAAS,YAC/B,MAAM,GACJ;IACR,QAAQ,EAAC,MAAM,GAAC,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAC,IAAI,CAAA;CACrB,CAgCH;AAmBM,uGAZJ;IAAmB,uBAAuB,EAAlC,MAAM;IACU,WAAW,EAA3B,WAAW;IACgB,eAAe,EAA1C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACX,QAAQ,EAAnB,MAAM;IAC8B,UAAU,EAA9C,MAAM,GAAG,UAAU,GAAG,SAAS;CACvC,GAAU;IACR,MAAM,EAAE;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC;IACzB,aAAa,EAAE,GAAG,CAAC;IACnB,YAAY,WAAW;IACvB,OAAO,WAAW;CACnB,CAiJH;gCAlOqC,YAAY;4BAAZ,YAAY"}
|
|
@@ -219,7 +219,9 @@ export const wrap = ({
|
|
|
219
219
|
}
|
|
220
220
|
} else {
|
|
221
221
|
for (const prop of redefined) {
|
|
222
|
-
|
|
222
|
+
if (prop !== 'default') {
|
|
223
|
+
moduleEnvironmentRecord[prop] = moduleEnvironmentRecord.default[prop];
|
|
224
|
+
}
|
|
223
225
|
}
|
|
224
226
|
}
|
|
225
227
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export function assertMatchingWildcardCount(pattern: string, replacement: string): void;
|
|
2
|
+
export function makeMultiSubpathReplacer(mapping: PatternDescriptor[] | SubpathMapping): SubpathReplacer;
|
|
3
|
+
import type { PatternDescriptor } from './types/pattern-replacement.js';
|
|
4
|
+
import type { SubpathMapping } from './types/pattern-replacement.js';
|
|
5
|
+
import type { SubpathReplacer } from './types/pattern-replacement.js';
|
|
6
|
+
//# sourceMappingURL=pattern-replacement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pattern-replacement.d.ts","sourceRoot":"","sources":["pattern-replacement.js"],"names":[],"mappings":"AA6BO,qDAJI,MAAM,eACN,MAAM,QAWhB;AAwFM,kDAHI,iBAAiB,EAAE,GAAG,cAAc,GAClC,eAAe,CA0E3B;uCAtLS,gCAAgC;oCAAhC,gCAAgC;qCAAhC,gCAAgC"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides pattern matching for Node.js-style subpath exports and imports.
|
|
3
|
+
* Patterns use `*` as a wildcard that matches any string, including across
|
|
4
|
+
* `/` path separators, matching Node.js semantics.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @import {
|
|
11
|
+
* SubpathReplacer,
|
|
12
|
+
* SubpathReplacerResult,
|
|
13
|
+
* SubpathMapping,
|
|
14
|
+
* PatternDescriptor,
|
|
15
|
+
* ResolvedPattern,
|
|
16
|
+
* } from './types/pattern-replacement.js'
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const { entries } = Object;
|
|
20
|
+
const { isArray } = Array;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Validates that the pattern and replacement have the same number of wildcards.
|
|
24
|
+
* Node.js restricts subpath patterns to exactly one `*` on each side.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} pattern - Source pattern
|
|
27
|
+
* @param {string} replacement - Target pattern
|
|
28
|
+
* @throws {Error} If wildcard counts don't match
|
|
29
|
+
*/
|
|
30
|
+
export const assertMatchingWildcardCount = (pattern, replacement) => {
|
|
31
|
+
const patternCount = (pattern.match(/\*/g) || []).length;
|
|
32
|
+
const replacementCount = (replacement.match(/\*/g) || []).length;
|
|
33
|
+
if (patternCount !== replacementCount) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Wildcard count mismatch: "${pattern}" has ${patternCount}, "${replacement}" has ${replacementCount}`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Compare two pattern keys using Node.js's PATTERN_KEY_COMPARE ordering.
|
|
42
|
+
* This prefers the longest prefix before `*`, then the longest full key.
|
|
43
|
+
* For example, `./foo/*.js` outranks `./foo/*`.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} a
|
|
46
|
+
* @param {string} b
|
|
47
|
+
* @returns {number}
|
|
48
|
+
*/
|
|
49
|
+
const patternKeyCompare = (a, b) => {
|
|
50
|
+
const aBaseLength = a.indexOf('*') + 1;
|
|
51
|
+
const bBaseLength = b.indexOf('*') + 1;
|
|
52
|
+
if (aBaseLength > bBaseLength) {
|
|
53
|
+
return -1;
|
|
54
|
+
}
|
|
55
|
+
if (bBaseLength > aBaseLength) {
|
|
56
|
+
return 1;
|
|
57
|
+
}
|
|
58
|
+
if (a.length > b.length) {
|
|
59
|
+
return -1;
|
|
60
|
+
}
|
|
61
|
+
if (b.length > a.length) {
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
return 0;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Classifies a pattern/replacement pair as exact or wildcard and adds it
|
|
69
|
+
* to the appropriate collection.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} pattern
|
|
72
|
+
* @param {string | null} replacement
|
|
73
|
+
* @param {string | undefined} compartment
|
|
74
|
+
* @param {Map<string, { replacement: string | null, compartment?: string }>} exactEntries
|
|
75
|
+
* @param {ResolvedPattern[]} wildcardEntries
|
|
76
|
+
*/
|
|
77
|
+
const classifyPatternEntry = (
|
|
78
|
+
pattern,
|
|
79
|
+
replacement,
|
|
80
|
+
compartment,
|
|
81
|
+
exactEntries,
|
|
82
|
+
wildcardEntries,
|
|
83
|
+
) => {
|
|
84
|
+
if (replacement !== null) {
|
|
85
|
+
assertMatchingWildcardCount(pattern, replacement);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const wildcardIndex = pattern.indexOf('*');
|
|
89
|
+
if (wildcardIndex === -1) {
|
|
90
|
+
exactEntries.set(pattern, { replacement, compartment });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const prefix = pattern.slice(0, wildcardIndex);
|
|
95
|
+
const suffix = pattern.slice(wildcardIndex + 1);
|
|
96
|
+
let replacementPrefix = null;
|
|
97
|
+
let replacementSuffix = null;
|
|
98
|
+
if (replacement !== null) {
|
|
99
|
+
const replacementWildcardIndex = replacement.indexOf('*');
|
|
100
|
+
replacementPrefix = replacement.slice(0, replacementWildcardIndex);
|
|
101
|
+
replacementSuffix = replacement.slice(replacementWildcardIndex + 1);
|
|
102
|
+
}
|
|
103
|
+
wildcardEntries.push({
|
|
104
|
+
pattern,
|
|
105
|
+
prefix,
|
|
106
|
+
suffix,
|
|
107
|
+
replacementPrefix,
|
|
108
|
+
replacementSuffix,
|
|
109
|
+
compartment,
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Creates a multi-pattern replacer for Node.js-style subpath patterns.
|
|
115
|
+
*
|
|
116
|
+
* Patterns are matched by specificity: the pattern with the longest matching
|
|
117
|
+
* prefix before the `*` wins. Exact entries (no `*`) take precedence over
|
|
118
|
+
* all wildcard patterns.
|
|
119
|
+
*
|
|
120
|
+
* The `*` wildcard matches any substring, including substrings that contain
|
|
121
|
+
* `/`, matching Node.js semantics.
|
|
122
|
+
*
|
|
123
|
+
* @param {PatternDescriptor[] | SubpathMapping} mapping - Pattern to replacement mapping
|
|
124
|
+
* @returns {SubpathReplacer} Function that matches a specifier and returns the replacement
|
|
125
|
+
*/
|
|
126
|
+
export const makeMultiSubpathReplacer = mapping => {
|
|
127
|
+
/** @type {Map<string, { replacement: string | null, compartment?: string }>} */
|
|
128
|
+
const exactEntries = new Map();
|
|
129
|
+
/** @type {ResolvedPattern[]} */
|
|
130
|
+
const wildcardEntries = [];
|
|
131
|
+
|
|
132
|
+
/** @type {Array<[string, string | null, string | undefined]>} */
|
|
133
|
+
let normalizedEntries;
|
|
134
|
+
if (isArray(mapping)) {
|
|
135
|
+
normalizedEntries = /** @type {typeof normalizedEntries} */ (
|
|
136
|
+
mapping.map(entry => {
|
|
137
|
+
if (isArray(entry)) {
|
|
138
|
+
// [pattern, replacement] tuple
|
|
139
|
+
return [entry[0], entry[1], undefined];
|
|
140
|
+
}
|
|
141
|
+
// PatternDescriptor { from, to, compartment? }
|
|
142
|
+
return [entry.from, entry.to, entry.compartment];
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
normalizedEntries = /** @type {typeof normalizedEntries} */ (
|
|
147
|
+
entries(mapping).map(([pattern, replacement]) => [
|
|
148
|
+
pattern,
|
|
149
|
+
replacement,
|
|
150
|
+
undefined,
|
|
151
|
+
])
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
for (const [pattern, replacement, compartment] of normalizedEntries) {
|
|
156
|
+
classifyPatternEntry(
|
|
157
|
+
pattern,
|
|
158
|
+
replacement,
|
|
159
|
+
compartment,
|
|
160
|
+
exactEntries,
|
|
161
|
+
wildcardEntries,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Match Node.js PATTERN_KEY_COMPARE semantics for subpath pattern
|
|
166
|
+
// precedence: longest prefix before `*`, then longest full pattern key.
|
|
167
|
+
wildcardEntries.sort((a, b) => patternKeyCompare(a.pattern, b.pattern));
|
|
168
|
+
|
|
169
|
+
return specifier => {
|
|
170
|
+
// Exact entries take precedence
|
|
171
|
+
const exact = exactEntries.get(specifier);
|
|
172
|
+
if (exact) {
|
|
173
|
+
return { result: exact.replacement, compartment: exact.compartment };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Try wildcard patterns in specificity order
|
|
177
|
+
for (const entry of wildcardEntries) {
|
|
178
|
+
if (
|
|
179
|
+
specifier.startsWith(entry.prefix) &&
|
|
180
|
+
specifier.endsWith(entry.suffix) &&
|
|
181
|
+
specifier.length >= entry.prefix.length + entry.suffix.length
|
|
182
|
+
) {
|
|
183
|
+
// Null replacement means this path is explicitly excluded.
|
|
184
|
+
if (entry.replacementPrefix === null) {
|
|
185
|
+
return { result: null, compartment: entry.compartment };
|
|
186
|
+
}
|
|
187
|
+
const captured = specifier.slice(
|
|
188
|
+
entry.prefix.length,
|
|
189
|
+
specifier.length - entry.suffix.length,
|
|
190
|
+
);
|
|
191
|
+
const result = `${entry.replacementPrefix}${captured}${entry.replacementSuffix}`;
|
|
192
|
+
return { result, compartment: entry.compartment };
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return null;
|
|
197
|
+
};
|
|
198
|
+
};
|
package/src/policy-format.d.ts
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Const string to identify the internal attenuators compartment
|
|
3
|
+
*/
|
|
4
|
+
export const ATTENUATORS_COMPARTMENT: "<ATTENUATORS>";
|
|
5
|
+
export const ENTRY_COMPARTMENT: "$root$";
|
|
6
|
+
export function generateCanonicalName({ isEntry, name, path }: PackageNamingKit): string;
|
|
1
7
|
export const WILDCARD_POLICY_VALUE: "any";
|
|
2
|
-
export function policyLookupHelper(packagePolicy:
|
|
3
|
-
export function isAllowingEverything(policyValue: unknown): policyValue is
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
export function policyLookupHelper(packagePolicy: PackagePolicy, field: PolicyEnforcementField, canonicalName: string): boolean | AttenuationDefinition;
|
|
9
|
+
export function isAllowingEverything(policyValue: unknown): policyValue is WildcardPolicy;
|
|
10
|
+
/**
|
|
11
|
+
* Type guard for `AttenuationDefinition`
|
|
12
|
+
*/
|
|
13
|
+
export const isAttenuationDefinition: (value: unknown) => value is FullAttenuationDefinition | ImplicitAttenuationDefinition;
|
|
14
|
+
export function getAttenuatorFromDefinition(attenuationDefinition: AttenuationDefinition): UnifiedAttenuationDefinition;
|
|
15
|
+
export function assertPackagePolicy(allegedPackagePolicy: unknown, keypath: string, url?: string): asserts allegedPackagePolicy is SomePackagePolicy | undefined;
|
|
7
16
|
export function assertPolicy(allegedPolicy: unknown): asserts allegedPolicy is (SomePolicy | undefined);
|
|
17
|
+
import type { PackageNamingKit } from './types.js';
|
|
18
|
+
import type { PackagePolicy } from './types.js';
|
|
19
|
+
import type { PolicyEnforcementField } from './types.js';
|
|
20
|
+
import type { AttenuationDefinition } from './types.js';
|
|
21
|
+
import type { WildcardPolicy } from './types.js';
|
|
22
|
+
import type { FullAttenuationDefinition } from './types.js';
|
|
23
|
+
import type { ImplicitAttenuationDefinition } from './types.js';
|
|
24
|
+
import type { UnifiedAttenuationDefinition } from './types.js';
|
|
8
25
|
import type { SomePackagePolicy } from './types.js';
|
|
9
26
|
import type { SomePolicy } from './types.js';
|
|
10
27
|
//# sourceMappingURL=policy-format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy-format.d.ts","sourceRoot":"","sources":["policy-format.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"policy-format.d.ts","sourceRoot":"","sources":["policy-format.js"],"names":[],"mappings":"AA8BA;;GAEG;AACH,sCAAuC,eAAe,CAAC;AAEvD,gCAAiC,QAAQ,CAAC;AAmBnC,+DAJI,gBAAgB,GACd,MAAM,CAWlB;AAED,oCAAqC,KAAK,CAAC;AAqEpC,kDALI,aAAa,SACb,sBAAsB,iBACtB,MAAM,GACJ,OAAO,GAAG,qBAAqB,CA2B3C;AAQM,kDAHI,OAAO,GACL,WAAW,IAAI,cAAc,CAGH;AA6EvC;;GAEG;AACH,6HAGG;AAQI,mEAHI,qBAAqB,GACnB,4BAA4B,CAwBxC;AAqGM,0DALI,OAAO,WACP,MAAM,QACN,MAAM,GACJ,QAAQ,oBAAoB,IAAI,iBAAiB,GAAC,SAAS,CA0DvE;AAUM,4CAHI,OAAO,GACL,QAAQ,aAAa,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC,CAiC7D;sCAvcQ,YAAY;mCAAZ,YAAY;4CAAZ,YAAY;2CAAZ,YAAY;oCAAZ,YAAY;+CAAZ,YAAY;mDAAZ,YAAY;kDAAZ,YAAY;uCAAZ,YAAY;gCAAZ,YAAY"}
|