@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.
Files changed (95) hide show
  1. package/package.json +24 -14
  2. package/src/archive-lite.d.ts +7 -7
  3. package/src/archive-lite.d.ts.map +1 -1
  4. package/src/archive-lite.js +81 -30
  5. package/src/archive.d.ts.map +1 -1
  6. package/src/archive.js +7 -0
  7. package/src/bundle-lite.d.ts +3 -3
  8. package/src/bundle-lite.d.ts.map +1 -1
  9. package/src/bundle-lite.js +19 -24
  10. package/src/bundle.d.ts +3 -3
  11. package/src/bundle.d.ts.map +1 -1
  12. package/src/bundle.js +19 -24
  13. package/src/capture-lite.d.ts +2 -2
  14. package/src/capture-lite.d.ts.map +1 -1
  15. package/src/capture-lite.js +243 -25
  16. package/src/compartment-map.d.ts +9 -2
  17. package/src/compartment-map.d.ts.map +1 -1
  18. package/src/compartment-map.js +738 -254
  19. package/src/digest.d.ts +22 -2
  20. package/src/digest.d.ts.map +1 -1
  21. package/src/digest.js +180 -57
  22. package/src/generic-graph.d.ts +7 -25
  23. package/src/generic-graph.d.ts.map +1 -1
  24. package/src/generic-graph.js +83 -108
  25. package/src/guards.d.ts +18 -0
  26. package/src/guards.d.ts.map +1 -0
  27. package/src/guards.js +109 -0
  28. package/src/hooks.md +124 -0
  29. package/src/import-archive-lite.d.ts.map +1 -1
  30. package/src/import-archive-lite.js +15 -11
  31. package/src/import-archive.d.ts +5 -19
  32. package/src/import-archive.d.ts.map +1 -1
  33. package/src/import-archive.js +7 -27
  34. package/src/import-hook.d.ts +4 -3
  35. package/src/import-hook.d.ts.map +1 -1
  36. package/src/import-hook.js +140 -70
  37. package/src/import-lite.d.ts +6 -6
  38. package/src/import-lite.d.ts.map +1 -1
  39. package/src/import-lite.js +8 -5
  40. package/src/import.d.ts +3 -3
  41. package/src/import.d.ts.map +1 -1
  42. package/src/import.js +16 -6
  43. package/src/infer-exports.d.ts +4 -2
  44. package/src/infer-exports.d.ts.map +1 -1
  45. package/src/infer-exports.js +172 -23
  46. package/src/link.d.ts +4 -3
  47. package/src/link.d.ts.map +1 -1
  48. package/src/link.js +122 -52
  49. package/src/node-modules.d.ts +4 -3
  50. package/src/node-modules.d.ts.map +1 -1
  51. package/src/node-modules.js +513 -151
  52. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  53. package/src/parse-cjs-shared-export-wrapper.js +3 -1
  54. package/src/pattern-replacement.d.ts +6 -0
  55. package/src/pattern-replacement.d.ts.map +1 -0
  56. package/src/pattern-replacement.js +198 -0
  57. package/src/policy-format.d.ts +22 -5
  58. package/src/policy-format.d.ts.map +1 -1
  59. package/src/policy-format.js +342 -108
  60. package/src/policy.d.ts +13 -28
  61. package/src/policy.d.ts.map +1 -1
  62. package/src/policy.js +161 -106
  63. package/src/types/canonical-name.d.ts +97 -0
  64. package/src/types/canonical-name.d.ts.map +1 -0
  65. package/src/types/canonical-name.ts +151 -0
  66. package/src/types/compartment-map-schema.d.ts +121 -35
  67. package/src/types/compartment-map-schema.d.ts.map +1 -1
  68. package/src/types/compartment-map-schema.ts +211 -37
  69. package/src/types/external.d.ts +240 -76
  70. package/src/types/external.d.ts.map +1 -1
  71. package/src/types/external.ts +305 -74
  72. package/src/types/generic-graph.d.ts +8 -2
  73. package/src/types/generic-graph.d.ts.map +1 -1
  74. package/src/types/generic-graph.ts +7 -2
  75. package/src/types/internal.d.ts +31 -50
  76. package/src/types/internal.d.ts.map +1 -1
  77. package/src/types/internal.ts +60 -58
  78. package/src/types/node-modules.d.ts +112 -14
  79. package/src/types/node-modules.d.ts.map +1 -1
  80. package/src/types/node-modules.ts +152 -13
  81. package/src/types/pattern-replacement.d.ts +62 -0
  82. package/src/types/pattern-replacement.d.ts.map +1 -0
  83. package/src/types/pattern-replacement.ts +70 -0
  84. package/src/types/policy-schema.d.ts +26 -11
  85. package/src/types/policy-schema.d.ts.map +1 -1
  86. package/src/types/policy-schema.ts +29 -16
  87. package/src/types/policy.d.ts +6 -2
  88. package/src/types/policy.d.ts.map +1 -1
  89. package/src/types/policy.ts +7 -2
  90. package/src/types/powers.d.ts +11 -9
  91. package/src/types/powers.d.ts.map +1 -1
  92. package/src/types/powers.ts +11 -10
  93. package/src/types/typescript.d.ts +28 -0
  94. package/src/types/typescript.d.ts.map +1 -1
  95. 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 {SyncArchiveOptions} options
5
+ * @param {SyncLoadLocationOptions} options
6
6
  * @returns {Promise<Application>}
7
7
  */
8
- export function loadLocation(readPowers: ReadNowPowers, moduleLocation: string, options: SyncArchiveOptions): Promise<Application>;
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 { SyncArchiveOptions } from './types.js';
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';
@@ -1 +1 @@
1
- {"version":3,"file":"import.d.ts","sourceRoot":"","sources":["import.js"],"names":[],"mappings":";;;;;;;AAmDG,yCACQ,aAAa,kBACb,MAAM,WACN,kBAAkB,GAChB,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;AAGE,yCACQ,MAAM,GAAG,UAAU,kBACnB,MAAM,8CAEJ,OAAO,CAAC,WAAW,CAAC,CAChC;;;;;;;;;;;AAuDE,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;mCA7GS,YAAY;wCAAZ,YAAY;iCAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;yCAAZ,YAAY;+CAAZ,YAAY;gCAAZ,YAAY;2CAAZ,YAAY"}
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 {ArchiveOptions} [options]
40
- * @returns {ArchiveOptions}
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 {SyncArchiveOptions} options
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
  };
@@ -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 inferExportsAndAliases(descriptor: PackageDescriptor, externalAliases: Node["externalAliases"], internalAliases: Node["internalAliases"], conditions: Set<string>, types: Record<string, string>): void;
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":"AA4HO,+DAPI,iBAAiB,cACjB,GAAG,CAAC,MAAM,CAAC,SAEX,oBAAoB,kCA2B9B;AAkBM,yCAPI,iBAAiB,cACjB,GAAG,CAAC,MAAM,CAAC,SAEX,oBAAoB,GAElB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAG8B;AAU1D,mDANI,iBAAiB,mBACjB,IAAI,CAAC,iBAAiB,CAAC,mBACvB,IAAI,CAAC,iBAAiB,CAAC,cACvB,GAAG,CAAC,MAAM,CAAC,SACX,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QA6ChC;uCAhNyD,YAAY;0CAAZ,YAAY;0BAC/C,yBAAyB"}
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"}
@@ -10,12 +10,14 @@
10
10
 
11
11
  /**
12
12
  * @import {LanguageForExtension, PackageDescriptor} from './types.js'
13
- * @import {Node} from './types/node-modules.js'
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 { join, relativize } from './node-module-specifier.js';
18
+ import { relativize } from './node-module-specifier.js';
17
19
 
18
- const { entries, fromEntries, assign } = Object;
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 {object} exports - the `exports` field from a package.json.
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
- * @yields {[string, string]}
67
- * @returns {Generator<[string, string]>}
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
- if (name === '.') {
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
- yield* interpretExports(name, value, conditions);
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 inferExportsAndAliases = (
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
- // collect externalAliases from exports and main/module
187
- assign(
188
- externalAliases,
189
- fromEntries(inferExportsEntries(descriptor, conditions, types)),
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 }: CompartmentMapDescriptor, options: LinkOptions): LinkResult;
2
- export function assemble(compartmentMap: CompartmentMapDescriptor, options: LinkOptions): Compartment;
3
- import type { CompartmentMapDescriptor } from './types.js';
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":"AAwPO,sEAJI,wBAAwB,WACxB,WAAW,GACT,UAAU,CA2KtB;AAOM,yCAJI,wBAAwB,WACxB,WAAW,eAIqB;8CA/YjC,YAAY;iCAAZ,YAAY;gCAAZ,YAAY"}
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"}