@esmx/core 3.0.0-rc.66 → 3.0.0-rc.70

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/dist/core.mjs CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  parsePackConfig
15
15
  } from "./pack-config.mjs";
16
16
  import { createCache } from "./utils/cache.mjs";
17
- import { getImportMap } from "./utils/import-map.mjs";
17
+ import { createImportMap } from "./utils/import-map.mjs";
18
18
  import { resolvePath } from "./utils/resolve-path.mjs";
19
19
  import { getImportPreloadInfo as getStaticImportPaths } from "./utils/static-import-lexer.mjs";
20
20
  export var COMMAND = /* @__PURE__ */ ((COMMAND2) => {
@@ -677,7 +677,7 @@ export class Esmx {
677
677
  let json = {};
678
678
  switch (env) {
679
679
  case "client": {
680
- json = getImportMap({
680
+ json = createImportMap({
681
681
  manifests,
682
682
  getScope(name, scope) {
683
683
  return `/${name}${scope}`;
@@ -689,7 +689,7 @@ export class Esmx {
689
689
  break;
690
690
  }
691
691
  case "server":
692
- json = getImportMap({
692
+ json = createImportMap({
693
693
  manifests,
694
694
  getScope: (name, scope) => {
695
695
  const linkPath = moduleConfig.links[name].server;
@@ -14,21 +14,22 @@ export interface GetImportMapOptions {
14
14
  getScope: (name: string, scope: string) => string;
15
15
  getFile: (name: string, file: string) => string;
16
16
  }
17
- export declare function buildImportsMap(manifests: readonly ImportMapManifest[], getFile: (name: string, file: string) => string): SpecifierMap;
18
- export declare function buildScopesMap(imports: SpecifierMap, manifests: readonly ImportMapManifest[], getScope: (name: string, scope: string) => string): ScopesMap;
17
+ export declare function createImportsMap(manifests: readonly ImportMapManifest[], getFile: (name: string, file: string) => string): SpecifierMap;
18
+ export declare function createScopesMap(imports: SpecifierMap, manifests: readonly ImportMapManifest[], getScope: (name: string, scope: string) => string): ScopesMap;
19
19
  /**
20
- * Fixes Chrome's nested scope resolution bug in import maps.
20
+ * Fixes the nested scope resolution issue in import maps across all browsers.
21
21
  *
22
- * Chrome has a bug where nested scopes in import maps are not resolved correctly.
22
+ * Import Maps have a cross-browser issue where nested scopes are not resolved correctly.
23
23
  * For example, when you have both "/shared-modules/" and "/shared-modules/vue2/" scopes,
24
- * Chrome fails to properly apply the more specific nested scope.
24
+ * browsers fail to properly apply the more specific nested scope.
25
25
  *
26
- * This function works around the bug by:
26
+ * This function works around the issue by:
27
27
  * 1. Sorting scopes by path depth (shallow paths first, deeper paths last)
28
28
  * 2. Manually applying scopes to matching imports in the correct order
29
+ * 3. Converting pattern-based scopes to concrete path scopes
29
30
  *
30
31
  * @example
31
- * Problematic import map that fails in Chrome:
32
+ * Problematic import map that fails in browsers:
32
33
  * ```json
33
34
  * {
34
35
  * "scopes": {
@@ -45,5 +46,5 @@ export declare function buildScopesMap(imports: SpecifierMap, manifests: readonl
45
46
  * @see https://github.com/guybedford/es-module-shims/issues/529
46
47
  * @see https://issues.chromium.org/issues/453147451
47
48
  */
48
- export declare function fixNestedScopesResolution(importMap: Required<ImportMap>): Required<ImportMap>;
49
- export declare function getImportMap({ manifests, getFile, getScope }: GetImportMapOptions): Required<ImportMap>;
49
+ export declare function fixImportMapNestedScopes(importMap: Required<ImportMap>): Required<ImportMap>;
50
+ export declare function createImportMap({ manifests, getFile, getScope }: GetImportMapOptions): Required<ImportMap>;
@@ -1,5 +1,5 @@
1
1
  import { pathWithoutIndex } from "./path-without-index.mjs";
2
- export function buildImportsMap(manifests, getFile) {
2
+ export function createImportsMap(manifests, getFile) {
3
3
  const imports = {};
4
4
  manifests.forEach((manifest) => {
5
5
  Object.entries(manifest.exports).forEach(([, exportItem]) => {
@@ -10,7 +10,7 @@ export function buildImportsMap(manifests, getFile) {
10
10
  pathWithoutIndex(imports);
11
11
  return imports;
12
12
  }
13
- export function buildScopesMap(imports, manifests, getScope) {
13
+ export function createScopesMap(imports, manifests, getScope) {
14
14
  const scopes = {};
15
15
  manifests.forEach((manifest) => {
16
16
  if (!manifest.scopes) {
@@ -30,7 +30,7 @@ export function buildScopesMap(imports, manifests, getScope) {
30
30
  });
31
31
  return scopes;
32
32
  }
33
- export function fixNestedScopesResolution(importMap) {
33
+ export function fixImportMapNestedScopes(importMap) {
34
34
  Object.entries(importMap.scopes).sort(([pathA], [pathB]) => {
35
35
  const depthA = pathA.split("/").length;
36
36
  const depthB = pathB.split("/").length;
@@ -48,13 +48,13 @@ export function fixNestedScopesResolution(importMap) {
48
48
  });
49
49
  return importMap;
50
50
  }
51
- export function getImportMap({
51
+ export function createImportMap({
52
52
  manifests,
53
53
  getFile,
54
54
  getScope
55
55
  }) {
56
- const imports = buildImportsMap(manifests, getFile);
57
- const scopes = buildScopesMap(imports, manifests, getScope);
56
+ const imports = createImportsMap(manifests, getFile);
57
+ const scopes = createScopesMap(imports, manifests, getScope);
58
58
  return {
59
59
  imports,
60
60
  scopes
@@ -1,13 +1,13 @@
1
1
  import { assert, describe, test } from "vitest";
2
2
  import {
3
- buildImportsMap,
4
- buildScopesMap,
5
- fixNestedScopesResolution,
6
- getImportMap
3
+ createImportMap,
4
+ createImportsMap,
5
+ createScopesMap,
6
+ fixImportMapNestedScopes
7
7
  } from "./import-map.mjs";
8
- describe("buildImportsMap", () => {
8
+ describe("createImportsMap", () => {
9
9
  test("should return empty object for empty manifests", () => {
10
- const result = buildImportsMap([], (name, file) => `${name}/${file}`);
10
+ const result = createImportsMap([], (name, file) => `${name}/${file}`);
11
11
  assert.deepEqual(result, {});
12
12
  });
13
13
  test("should process all exports including package exports", () => {
@@ -31,7 +31,7 @@ describe("buildImportsMap", () => {
31
31
  scopes: {}
32
32
  }
33
33
  ];
34
- const result = buildImportsMap(
34
+ const result = createImportsMap(
35
35
  manifests,
36
36
  (name, file) => `${name}/${file}`
37
37
  );
@@ -55,7 +55,7 @@ describe("buildImportsMap", () => {
55
55
  scopes: {}
56
56
  }
57
57
  ];
58
- const result = buildImportsMap(
58
+ const result = createImportsMap(
59
59
  manifests,
60
60
  (name, file) => `${name}/${file}`
61
61
  );
@@ -84,7 +84,7 @@ describe("buildImportsMap", () => {
84
84
  scopes: {}
85
85
  }
86
86
  ];
87
- const result = buildImportsMap(
87
+ const result = createImportsMap(
88
88
  manifests,
89
89
  (name, file) => `${name}/${file}`
90
90
  );
@@ -100,7 +100,7 @@ describe("buildImportsMap", () => {
100
100
  scopes: {}
101
101
  }
102
102
  ];
103
- const result = buildImportsMap(
103
+ const result = createImportsMap(
104
104
  manifests,
105
105
  (name, file) => `${name}/${file}`
106
106
  );
@@ -121,7 +121,7 @@ describe("buildImportsMap", () => {
121
121
  scopes: {}
122
122
  }
123
123
  ];
124
- const result = buildImportsMap(
124
+ const result = createImportsMap(
125
125
  manifests,
126
126
  (name, file) => `${name}/${file}`
127
127
  );
@@ -157,7 +157,7 @@ describe("buildImportsMap", () => {
157
157
  scopes: {}
158
158
  }
159
159
  ];
160
- const result = buildImportsMap(
160
+ const result = createImportsMap(
161
161
  manifests,
162
162
  (name, file) => `${name}/${file}`
163
163
  );
@@ -181,7 +181,7 @@ describe("buildImportsMap", () => {
181
181
  scopes: {}
182
182
  }
183
183
  ];
184
- const result = buildImportsMap(
184
+ const result = createImportsMap(
185
185
  manifests,
186
186
  (name, file) => `${name}/${file}`
187
187
  );
@@ -191,7 +191,7 @@ describe("buildImportsMap", () => {
191
191
  });
192
192
  });
193
193
  });
194
- describe("fixNestedScopesResolution", () => {
194
+ describe("fixImportMapNestedScopes", () => {
195
195
  test("should return unchanged import map for empty scopes", () => {
196
196
  const importMap = {
197
197
  imports: {
@@ -199,7 +199,7 @@ describe("fixNestedScopesResolution", () => {
199
199
  },
200
200
  scopes: {}
201
201
  };
202
- const result = fixNestedScopesResolution(importMap);
202
+ const result = fixImportMapNestedScopes(importMap);
203
203
  assert.deepEqual(result, importMap);
204
204
  });
205
205
  test("should return unchanged import map for shallow scopes only", () => {
@@ -213,7 +213,7 @@ describe("fixNestedScopesResolution", () => {
213
213
  }
214
214
  }
215
215
  };
216
- const result = fixNestedScopesResolution(importMap);
216
+ const result = fixImportMapNestedScopes(importMap);
217
217
  assert.deepEqual(result, importMap);
218
218
  });
219
219
  test("should create file-level scopes for nested scopes", () => {
@@ -255,7 +255,7 @@ describe("fixNestedScopesResolution", () => {
255
255
  }
256
256
  }
257
257
  };
258
- const result = fixNestedScopesResolution(importMap);
258
+ const result = fixImportMapNestedScopes(importMap);
259
259
  assert.deepEqual(result, expected);
260
260
  });
261
261
  test("should handle multiple nested scopes correctly", () => {
@@ -305,7 +305,7 @@ describe("fixNestedScopesResolution", () => {
305
305
  }
306
306
  }
307
307
  };
308
- const result = fixNestedScopesResolution(importMap);
308
+ const result = fixImportMapNestedScopes(importMap);
309
309
  assert.deepEqual(result, expected);
310
310
  });
311
311
  test("should handle deeply nested scopes", () => {
@@ -334,7 +334,7 @@ describe("fixNestedScopesResolution", () => {
334
334
  }
335
335
  }
336
336
  };
337
- const result = fixNestedScopesResolution(importMap);
337
+ const result = fixImportMapNestedScopes(importMap);
338
338
  assert.deepEqual(result, expected);
339
339
  });
340
340
  test("should not create file-level scopes for imports not matching nested scope", () => {
@@ -358,7 +358,7 @@ describe("fixNestedScopesResolution", () => {
358
358
  }
359
359
  }
360
360
  };
361
- const result = fixNestedScopesResolution(importMap);
361
+ const result = fixImportMapNestedScopes(importMap);
362
362
  assert.deepEqual(result, expected);
363
363
  });
364
364
  test("should handle empty imports", () => {
@@ -374,7 +374,7 @@ describe("fixNestedScopesResolution", () => {
374
374
  imports: {},
375
375
  scopes: {}
376
376
  };
377
- const result = fixNestedScopesResolution(importMap);
377
+ const result = fixImportMapNestedScopes(importMap);
378
378
  assert.deepEqual(result, expected);
379
379
  });
380
380
  test("should preserve original import map structure", () => {
@@ -390,7 +390,7 @@ describe("fixNestedScopesResolution", () => {
390
390
  }
391
391
  }
392
392
  };
393
- const result = fixNestedScopesResolution(importMap);
393
+ const result = fixImportMapNestedScopes(importMap);
394
394
  assert.deepEqual(result.imports, importMap.imports);
395
395
  assert.deepEqual(
396
396
  result.scopes["/shared-modules/vue2/"],
@@ -454,7 +454,7 @@ describe("fixNestedScopesResolution", () => {
454
454
  }
455
455
  }
456
456
  };
457
- const result = fixNestedScopesResolution(importMap);
457
+ const result = fixImportMapNestedScopes(importMap);
458
458
  assert.deepEqual(result, expected);
459
459
  });
460
460
  test("should handle priority with overlapping nested scopes", () => {
@@ -500,7 +500,7 @@ describe("fixNestedScopesResolution", () => {
500
500
  }
501
501
  }
502
502
  };
503
- const result = fixNestedScopesResolution(importMap);
503
+ const result = fixImportMapNestedScopes(importMap);
504
504
  assert.deepEqual(result, expected);
505
505
  });
506
506
  test("should handle very deeply nested scope priority scenarios", () => {
@@ -552,7 +552,7 @@ describe("fixNestedScopesResolution", () => {
552
552
  }
553
553
  }
554
554
  };
555
- const result = fixNestedScopesResolution(importMap);
555
+ const result = fixImportMapNestedScopes(importMap);
556
556
  assert.deepEqual(result, expected);
557
557
  });
558
558
  test("should ensure different directory levels have distinct values for proper testing", () => {
@@ -586,7 +586,7 @@ describe("fixNestedScopesResolution", () => {
586
586
  }
587
587
  }
588
588
  };
589
- const result = fixNestedScopesResolution(importMap);
589
+ const result = fixImportMapNestedScopes(importMap);
590
590
  assert.deepEqual(result, expected);
591
591
  assert.equal(
592
592
  result.scopes["/shared-modules/level1/level2.e5f6g7h8.final.mjs"].vue,
@@ -608,11 +608,11 @@ describe("fixNestedScopesResolution", () => {
608
608
  }
609
609
  }
610
610
  };
611
- const result = fixNestedScopesResolution(importMap);
611
+ const result = fixImportMapNestedScopes(importMap);
612
612
  assert.deepEqual(result.imports, importMap.imports);
613
613
  assert.isUndefined(result.scopes["/shared/modules/vue2/"]);
614
614
  assert.doesNotThrow(() => {
615
- fixNestedScopesResolution(importMap);
615
+ fixImportMapNestedScopes(importMap);
616
616
  });
617
617
  });
618
618
  describe("scope path processing logic", () => {
@@ -651,7 +651,7 @@ describe("fixNestedScopesResolution", () => {
651
651
  }
652
652
  }
653
653
  };
654
- const result = fixNestedScopesResolution(importMap);
654
+ const result = fixImportMapNestedScopes(importMap);
655
655
  assert.deepEqual(result, expected);
656
656
  });
657
657
  test("should handle scope paths with any depth", () => {
@@ -671,7 +671,7 @@ describe("fixNestedScopesResolution", () => {
671
671
  },
672
672
  scopes: {}
673
673
  };
674
- const result = fixNestedScopesResolution(importMap);
674
+ const result = fixImportMapNestedScopes(importMap);
675
675
  assert.deepEqual(result, expected);
676
676
  });
677
677
  test("should handle very deep nested scope paths", () => {
@@ -691,7 +691,7 @@ describe("fixNestedScopesResolution", () => {
691
691
  },
692
692
  scopes: {}
693
693
  };
694
- const result = fixNestedScopesResolution(importMap);
694
+ const result = fixImportMapNestedScopes(importMap);
695
695
  assert.deepEqual(result, expected);
696
696
  });
697
697
  test("should create file-level scopes for all scope paths", () => {
@@ -723,7 +723,7 @@ describe("fixNestedScopesResolution", () => {
723
723
  }
724
724
  }
725
725
  };
726
- const result = fixNestedScopesResolution(importMap);
726
+ const result = fixImportMapNestedScopes(importMap);
727
727
  assert.deepEqual(result, expected);
728
728
  });
729
729
  test("should process multiple scope paths in correct order by depth", () => {
@@ -757,16 +757,16 @@ describe("fixNestedScopesResolution", () => {
757
757
  }
758
758
  }
759
759
  };
760
- const result = fixNestedScopesResolution(importMap);
760
+ const result = fixImportMapNestedScopes(importMap);
761
761
  assert.deepEqual(result, expected);
762
762
  });
763
763
  });
764
764
  });
765
- describe("buildScopesMap", () => {
765
+ describe("createScopesMap", () => {
766
766
  test("should return empty object for empty manifests", () => {
767
767
  const imports = {};
768
768
  const manifests = [];
769
- const result = buildScopesMap(
769
+ const result = createScopesMap(
770
770
  imports,
771
771
  manifests,
772
772
  (name, scope) => `${name}/${scope}`
@@ -791,7 +791,7 @@ describe("buildScopesMap", () => {
791
791
  scopes: {}
792
792
  }
793
793
  ];
794
- const result = buildScopesMap(
794
+ const result = createScopesMap(
795
795
  imports,
796
796
  manifests,
797
797
  (name, scope) => `${name}/${scope}`
@@ -828,7 +828,7 @@ describe("buildScopesMap", () => {
828
828
  }
829
829
  }
830
830
  ];
831
- const result = buildScopesMap(
831
+ const result = createScopesMap(
832
832
  imports,
833
833
  manifests,
834
834
  (name, scope) => `${name}/${scope}`
@@ -863,7 +863,7 @@ describe("buildScopesMap", () => {
863
863
  }
864
864
  }
865
865
  ];
866
- const result = buildScopesMap(
866
+ const result = createScopesMap(
867
867
  imports,
868
868
  manifests,
869
869
  (name, scope) => `${name}/${scope}`
@@ -898,7 +898,7 @@ describe("buildScopesMap", () => {
898
898
  }
899
899
  }
900
900
  ];
901
- const result = buildScopesMap(
901
+ const result = createScopesMap(
902
902
  imports,
903
903
  manifests,
904
904
  (name, scope) => `${name}/${scope}`
@@ -939,7 +939,7 @@ describe("buildScopesMap", () => {
939
939
  }
940
940
  }
941
941
  ];
942
- const result = buildScopesMap(
942
+ const result = createScopesMap(
943
943
  imports,
944
944
  manifests,
945
945
  (name, scope) => `${name}/${scope}`
@@ -972,7 +972,7 @@ describe("buildScopesMap", () => {
972
972
  }
973
973
  }
974
974
  ];
975
- const result = buildScopesMap(
975
+ const result = createScopesMap(
976
976
  imports,
977
977
  manifests,
978
978
  (name, scope) => `${name}/${scope}`
@@ -1015,7 +1015,7 @@ describe("buildScopesMap", () => {
1015
1015
  }
1016
1016
  }
1017
1017
  ];
1018
- const result = buildScopesMap(
1018
+ const result = createScopesMap(
1019
1019
  imports,
1020
1020
  manifests,
1021
1021
  (name, scope) => `${name}/${scope}`
@@ -1068,7 +1068,7 @@ describe("buildScopesMap", () => {
1068
1068
  }
1069
1069
  }
1070
1070
  ];
1071
- const result = buildScopesMap(
1071
+ const result = createScopesMap(
1072
1072
  imports,
1073
1073
  manifests,
1074
1074
  (name, scope) => `${name}/${scope}`
@@ -1102,7 +1102,7 @@ describe("buildScopesMap", () => {
1102
1102
  }
1103
1103
  }
1104
1104
  ];
1105
- const result = buildScopesMap(
1105
+ const result = createScopesMap(
1106
1106
  imports,
1107
1107
  manifests,
1108
1108
  (name, scope) => `${name}/${scope}`
@@ -1129,7 +1129,7 @@ describe("buildScopesMap", () => {
1129
1129
  scopes: void 0
1130
1130
  }
1131
1131
  ];
1132
- const result = buildScopesMap(
1132
+ const result = createScopesMap(
1133
1133
  imports,
1134
1134
  manifests,
1135
1135
  (name, scope) => `${name}/${scope}`
@@ -1137,14 +1137,14 @@ describe("buildScopesMap", () => {
1137
1137
  assert.deepEqual(result, {});
1138
1138
  });
1139
1139
  });
1140
- describe("getImportMap", () => {
1140
+ describe("createImportMap", () => {
1141
1141
  test("should return empty import map for empty manifests", () => {
1142
1142
  const options = {
1143
1143
  manifests: [],
1144
1144
  getFile: (name, file) => `${name}/${file}`,
1145
1145
  getScope: (name, scope) => `${name}/${scope}`
1146
1146
  };
1147
- const result = getImportMap(options);
1147
+ const result = createImportMap(options);
1148
1148
  assert.deepEqual(result, {
1149
1149
  imports: {},
1150
1150
  scopes: {}
@@ -1180,7 +1180,7 @@ describe("getImportMap", () => {
1180
1180
  getFile: (name, file) => `${name}/${file}`,
1181
1181
  getScope: (name, scope) => `${name}/${scope}`
1182
1182
  };
1183
- const result = getImportMap(options);
1183
+ const result = createImportMap(options);
1184
1184
  assert.deepEqual(result, {
1185
1185
  imports: {
1186
1186
  "test-module/component": "test-module/component.js",
@@ -1233,7 +1233,7 @@ describe("getImportMap", () => {
1233
1233
  getFile: (name, file) => `${name}/${file}`,
1234
1234
  getScope: (name, scope) => `${name}/${scope}`
1235
1235
  };
1236
- const result = getImportMap(options);
1236
+ const result = createImportMap(options);
1237
1237
  assert.deepEqual(result, {
1238
1238
  imports: {
1239
1239
  "module-a/utils": "module-a/utils.js",
@@ -1268,7 +1268,7 @@ describe("getImportMap", () => {
1268
1268
  getFile: (name, file) => `${name}/${file}`,
1269
1269
  getScope: (name, scope) => `${name}/${scope}`
1270
1270
  };
1271
- const result = getImportMap(options);
1271
+ const result = createImportMap(options);
1272
1272
  assert.deepEqual(result, {
1273
1273
  imports: {
1274
1274
  "test-module/component": "test-module/component.js"
@@ -1292,7 +1292,7 @@ describe("getImportMap", () => {
1292
1292
  getFile: (name, file) => `${name}/${file}`,
1293
1293
  getScope: (name, scope) => `${name}/${scope}`
1294
1294
  };
1295
- const result = getImportMap(options);
1295
+ const result = createImportMap(options);
1296
1296
  assert.deepEqual(result, {
1297
1297
  imports: {},
1298
1298
  scopes: {
@@ -1325,7 +1325,7 @@ describe("getImportMap", () => {
1325
1325
  getFile: (name, file) => `/custom/path/${name}/${file}`,
1326
1326
  getScope: (name, scope) => `custom-scope-${name}-${scope}`
1327
1327
  };
1328
- const result = getImportMap(options);
1328
+ const result = createImportMap(options);
1329
1329
  assert.deepEqual(result, {
1330
1330
  imports: {
1331
1331
  "test-module/component": "/custom/path/test-module/component.js"
@@ -1356,7 +1356,7 @@ describe("getImportMap", () => {
1356
1356
  getFile: (name, file) => `${name}/${file}`,
1357
1357
  getScope: (name, scope) => `${name}/${scope}`
1358
1358
  };
1359
- const result = getImportMap(options);
1359
+ const result = createImportMap(options);
1360
1360
  assert.deepEqual(result, {
1361
1361
  imports: {
1362
1362
  "test-module/component": "test-module/component.js"
@@ -1388,7 +1388,7 @@ describe("getImportMap", () => {
1388
1388
  getFile: (name, file) => `${name}/${file}`,
1389
1389
  getScope: (name, scope) => `${name}/${scope}`
1390
1390
  };
1391
- const result = getImportMap(options);
1391
+ const result = createImportMap(options);
1392
1392
  assert.deepEqual(result, {
1393
1393
  imports: {
1394
1394
  "test-module/component": "test-module/component.js"
@@ -1424,7 +1424,7 @@ describe("getImportMap", () => {
1424
1424
  getFile: (name, file) => `${name}/${file}`,
1425
1425
  getScope: (name, scope) => `${name}/${scope}`
1426
1426
  };
1427
- const result = getImportMap(options);
1427
+ const result = createImportMap(options);
1428
1428
  assert.deepEqual(result, {
1429
1429
  imports: {
1430
1430
  "test-module/src/index": "test-module/src/index.js",
package/package.json CHANGED
@@ -59,7 +59,7 @@
59
59
  "build": "unbuild"
60
60
  },
61
61
  "dependencies": {
62
- "@esmx/import": "3.0.0-rc.66",
62
+ "@esmx/import": "3.0.0-rc.70",
63
63
  "@types/serialize-javascript": "^5.0.4",
64
64
  "es-module-lexer": "^1.7.0",
65
65
  "find": "^0.3.0",
@@ -77,7 +77,7 @@
77
77
  "unbuild": "3.6.0",
78
78
  "vitest": "3.2.4"
79
79
  },
80
- "version": "3.0.0-rc.66",
80
+ "version": "3.0.0-rc.70",
81
81
  "type": "module",
82
82
  "private": false,
83
83
  "exports": {
@@ -100,5 +100,5 @@
100
100
  "template",
101
101
  "public"
102
102
  ],
103
- "gitHead": "07815a4becd617c4c3fc58f5fd853d8ad4bd4caf"
103
+ "gitHead": "9aa452ae73e450d285e4ddbd35a4ac8b53427d95"
104
104
  }
package/src/core.ts CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  import type { ImportmapMode } from './render-context';
23
23
  import type { RenderContext, RenderContextOptions } from './render-context';
24
24
  import { type CacheHandle, createCache } from './utils/cache';
25
- import { getImportMap } from './utils/import-map';
25
+ import { createImportMap } from './utils/import-map';
26
26
  import type { Middleware } from './utils/middleware';
27
27
  import { type ProjectPath, resolvePath } from './utils/resolve-path';
28
28
  import { getImportPreloadInfo as getStaticImportPaths } from './utils/static-import-lexer';
@@ -854,7 +854,7 @@ export class Esmx {
854
854
  let json: ImportMap = {};
855
855
  switch (env) {
856
856
  case 'client': {
857
- json = getImportMap({
857
+ json = createImportMap({
858
858
  manifests,
859
859
  getScope(name, scope) {
860
860
  return `/${name}${scope}`;
@@ -866,7 +866,7 @@ export class Esmx {
866
866
  break;
867
867
  }
868
868
  case 'server':
869
- json = getImportMap({
869
+ json = createImportMap({
870
870
  manifests,
871
871
  getScope: (name: string, scope: string) => {
872
872
  const linkPath = moduleConfig.links[name].server;
@@ -1,15 +1,15 @@
1
1
  import { assert, describe, test } from 'vitest';
2
2
  import {
3
- buildImportsMap,
4
- buildScopesMap,
5
- fixNestedScopesResolution,
6
- getImportMap
3
+ createImportMap,
4
+ createImportsMap,
5
+ createScopesMap,
6
+ fixImportMapNestedScopes
7
7
  } from './import-map';
8
8
  import type { GetImportMapOptions, ImportMapManifest } from './import-map';
9
9
 
10
- describe('buildImportsMap', () => {
10
+ describe('createImportsMap', () => {
11
11
  test('should return empty object for empty manifests', () => {
12
- const result = buildImportsMap([], (name, file) => `${name}/${file}`);
12
+ const result = createImportsMap([], (name, file) => `${name}/${file}`);
13
13
  assert.deepEqual(result, {});
14
14
  });
15
15
 
@@ -35,7 +35,7 @@ describe('buildImportsMap', () => {
35
35
  }
36
36
  ];
37
37
 
38
- const result = buildImportsMap(
38
+ const result = createImportsMap(
39
39
  manifests,
40
40
  (name, file) => `${name}/${file}`
41
41
  );
@@ -62,7 +62,7 @@ describe('buildImportsMap', () => {
62
62
  }
63
63
  ];
64
64
 
65
- const result = buildImportsMap(
65
+ const result = createImportsMap(
66
66
  manifests,
67
67
  (name, file) => `${name}/${file}`
68
68
  );
@@ -94,7 +94,7 @@ describe('buildImportsMap', () => {
94
94
  }
95
95
  ];
96
96
 
97
- const result = buildImportsMap(
97
+ const result = createImportsMap(
98
98
  manifests,
99
99
  (name, file) => `${name}/${file}`
100
100
  );
@@ -113,7 +113,7 @@ describe('buildImportsMap', () => {
113
113
  }
114
114
  ];
115
115
 
116
- const result = buildImportsMap(
116
+ const result = createImportsMap(
117
117
  manifests,
118
118
  (name, file) => `${name}/${file}`
119
119
  );
@@ -137,7 +137,7 @@ describe('buildImportsMap', () => {
137
137
  }
138
138
  ];
139
139
 
140
- const result = buildImportsMap(
140
+ const result = createImportsMap(
141
141
  manifests,
142
142
  (name, file) => `${name}/${file}`
143
143
  );
@@ -177,7 +177,7 @@ describe('buildImportsMap', () => {
177
177
  }
178
178
  ];
179
179
 
180
- const result = buildImportsMap(
180
+ const result = createImportsMap(
181
181
  manifests,
182
182
  (name, file) => `${name}/${file}`
183
183
  );
@@ -204,7 +204,7 @@ describe('buildImportsMap', () => {
204
204
  }
205
205
  ];
206
206
 
207
- const result = buildImportsMap(
207
+ const result = createImportsMap(
208
208
  manifests,
209
209
  (name, file) => `${name}/${file}`
210
210
  );
@@ -218,7 +218,7 @@ describe('buildImportsMap', () => {
218
218
  });
219
219
  });
220
220
 
221
- describe('fixNestedScopesResolution', () => {
221
+ describe('fixImportMapNestedScopes', () => {
222
222
  test('should return unchanged import map for empty scopes', () => {
223
223
  const importMap = {
224
224
  imports: {
@@ -227,7 +227,7 @@ describe('fixNestedScopesResolution', () => {
227
227
  scopes: {}
228
228
  };
229
229
 
230
- const result = fixNestedScopesResolution(importMap);
230
+ const result = fixImportMapNestedScopes(importMap);
231
231
  assert.deepEqual(result, importMap);
232
232
  });
233
233
 
@@ -243,7 +243,7 @@ describe('fixNestedScopesResolution', () => {
243
243
  }
244
244
  };
245
245
 
246
- const result = fixNestedScopesResolution(importMap);
246
+ const result = fixImportMapNestedScopes(importMap);
247
247
  assert.deepEqual(result, importMap);
248
248
  });
249
249
 
@@ -294,7 +294,7 @@ describe('fixNestedScopesResolution', () => {
294
294
  }
295
295
  };
296
296
 
297
- const result = fixNestedScopesResolution(importMap);
297
+ const result = fixImportMapNestedScopes(importMap);
298
298
  assert.deepEqual(result, expected);
299
299
  });
300
300
 
@@ -355,7 +355,7 @@ describe('fixNestedScopesResolution', () => {
355
355
  }
356
356
  };
357
357
 
358
- const result = fixNestedScopesResolution(importMap);
358
+ const result = fixImportMapNestedScopes(importMap);
359
359
  assert.deepEqual(result, expected);
360
360
  });
361
361
 
@@ -391,7 +391,7 @@ describe('fixNestedScopesResolution', () => {
391
391
  }
392
392
  };
393
393
 
394
- const result = fixNestedScopesResolution(importMap);
394
+ const result = fixImportMapNestedScopes(importMap);
395
395
  assert.deepEqual(result, expected);
396
396
  });
397
397
 
@@ -420,7 +420,7 @@ describe('fixNestedScopesResolution', () => {
420
420
  }
421
421
  };
422
422
 
423
- const result = fixNestedScopesResolution(importMap);
423
+ const result = fixImportMapNestedScopes(importMap);
424
424
  assert.deepEqual(result, expected);
425
425
  });
426
426
 
@@ -439,7 +439,7 @@ describe('fixNestedScopesResolution', () => {
439
439
  scopes: {}
440
440
  };
441
441
 
442
- const result = fixNestedScopesResolution(importMap);
442
+ const result = fixImportMapNestedScopes(importMap);
443
443
  assert.deepEqual(result, expected);
444
444
  });
445
445
 
@@ -460,7 +460,7 @@ describe('fixNestedScopesResolution', () => {
460
460
  }
461
461
  };
462
462
 
463
- const result = fixNestedScopesResolution(importMap);
463
+ const result = fixImportMapNestedScopes(importMap);
464
464
 
465
465
  assert.deepEqual(result.imports, importMap.imports);
466
466
  assert.deepEqual(
@@ -543,7 +543,7 @@ describe('fixNestedScopesResolution', () => {
543
543
  }
544
544
  };
545
545
 
546
- const result = fixNestedScopesResolution(importMap);
546
+ const result = fixImportMapNestedScopes(importMap);
547
547
  assert.deepEqual(result, expected);
548
548
  });
549
549
 
@@ -607,7 +607,7 @@ describe('fixNestedScopesResolution', () => {
607
607
  }
608
608
  };
609
609
 
610
- const result = fixNestedScopesResolution(importMap);
610
+ const result = fixImportMapNestedScopes(importMap);
611
611
  assert.deepEqual(result, expected);
612
612
  });
613
613
 
@@ -674,7 +674,7 @@ describe('fixNestedScopesResolution', () => {
674
674
  }
675
675
  };
676
676
 
677
- const result = fixNestedScopesResolution(importMap);
677
+ const result = fixImportMapNestedScopes(importMap);
678
678
  assert.deepEqual(result, expected);
679
679
  });
680
680
 
@@ -717,7 +717,7 @@ describe('fixNestedScopesResolution', () => {
717
717
  }
718
718
  };
719
719
 
720
- const result = fixNestedScopesResolution(importMap);
720
+ const result = fixImportMapNestedScopes(importMap);
721
721
  assert.deepEqual(result, expected);
722
722
 
723
723
  assert.equal(
@@ -746,11 +746,11 @@ describe('fixNestedScopesResolution', () => {
746
746
  }
747
747
  };
748
748
 
749
- const result = fixNestedScopesResolution(importMap);
749
+ const result = fixImportMapNestedScopes(importMap);
750
750
  assert.deepEqual(result.imports, importMap.imports);
751
751
  assert.isUndefined(result.scopes['/shared/modules/vue2/']);
752
752
  assert.doesNotThrow(() => {
753
- fixNestedScopesResolution(importMap);
753
+ fixImportMapNestedScopes(importMap);
754
754
  });
755
755
  });
756
756
 
@@ -794,7 +794,7 @@ describe('fixNestedScopesResolution', () => {
794
794
  }
795
795
  };
796
796
 
797
- const result = fixNestedScopesResolution(importMap);
797
+ const result = fixImportMapNestedScopes(importMap);
798
798
  assert.deepEqual(result, expected);
799
799
  });
800
800
 
@@ -817,7 +817,7 @@ describe('fixNestedScopesResolution', () => {
817
817
  scopes: {}
818
818
  };
819
819
 
820
- const result = fixNestedScopesResolution(importMap);
820
+ const result = fixImportMapNestedScopes(importMap);
821
821
  assert.deepEqual(result, expected);
822
822
  });
823
823
 
@@ -840,7 +840,7 @@ describe('fixNestedScopesResolution', () => {
840
840
  scopes: {}
841
841
  };
842
842
 
843
- const result = fixNestedScopesResolution(importMap);
843
+ const result = fixImportMapNestedScopes(importMap);
844
844
  assert.deepEqual(result, expected);
845
845
  });
846
846
 
@@ -875,7 +875,7 @@ describe('fixNestedScopesResolution', () => {
875
875
  }
876
876
  };
877
877
 
878
- const result = fixNestedScopesResolution(importMap);
878
+ const result = fixImportMapNestedScopes(importMap);
879
879
  assert.deepEqual(result, expected);
880
880
  });
881
881
 
@@ -919,17 +919,17 @@ describe('fixNestedScopesResolution', () => {
919
919
  }
920
920
  };
921
921
 
922
- const result = fixNestedScopesResolution(importMap);
922
+ const result = fixImportMapNestedScopes(importMap);
923
923
  assert.deepEqual(result, expected);
924
924
  });
925
925
  });
926
926
  });
927
927
 
928
- describe('buildScopesMap', () => {
928
+ describe('createScopesMap', () => {
929
929
  test('should return empty object for empty manifests', () => {
930
930
  const imports = {};
931
931
  const manifests: ImportMapManifest[] = [];
932
- const result = buildScopesMap(
932
+ const result = createScopesMap(
933
933
  imports,
934
934
  manifests,
935
935
  (name, scope) => `${name}/${scope}`
@@ -955,7 +955,7 @@ describe('buildScopesMap', () => {
955
955
  scopes: {}
956
956
  }
957
957
  ];
958
- const result = buildScopesMap(
958
+ const result = createScopesMap(
959
959
  imports,
960
960
  manifests,
961
961
  (name, scope) => `${name}/${scope}`
@@ -993,7 +993,7 @@ describe('buildScopesMap', () => {
993
993
  }
994
994
  }
995
995
  ];
996
- const result = buildScopesMap(
996
+ const result = createScopesMap(
997
997
  imports,
998
998
  manifests,
999
999
  (name, scope) => `${name}/${scope}`
@@ -1029,7 +1029,7 @@ describe('buildScopesMap', () => {
1029
1029
  }
1030
1030
  }
1031
1031
  ];
1032
- const result = buildScopesMap(
1032
+ const result = createScopesMap(
1033
1033
  imports,
1034
1034
  manifests,
1035
1035
  (name, scope) => `${name}/${scope}`
@@ -1065,7 +1065,7 @@ describe('buildScopesMap', () => {
1065
1065
  }
1066
1066
  }
1067
1067
  ];
1068
- const result = buildScopesMap(
1068
+ const result = createScopesMap(
1069
1069
  imports,
1070
1070
  manifests,
1071
1071
  (name, scope) => `${name}/${scope}`
@@ -1107,7 +1107,7 @@ describe('buildScopesMap', () => {
1107
1107
  }
1108
1108
  }
1109
1109
  ];
1110
- const result = buildScopesMap(
1110
+ const result = createScopesMap(
1111
1111
  imports,
1112
1112
  manifests,
1113
1113
  (name, scope) => `${name}/${scope}`
@@ -1141,7 +1141,7 @@ describe('buildScopesMap', () => {
1141
1141
  }
1142
1142
  }
1143
1143
  ];
1144
- const result = buildScopesMap(
1144
+ const result = createScopesMap(
1145
1145
  imports,
1146
1146
  manifests,
1147
1147
  (name, scope) => `${name}/${scope}`
@@ -1185,7 +1185,7 @@ describe('buildScopesMap', () => {
1185
1185
  }
1186
1186
  }
1187
1187
  ];
1188
- const result = buildScopesMap(
1188
+ const result = createScopesMap(
1189
1189
  imports,
1190
1190
  manifests,
1191
1191
  (name, scope) => `${name}/${scope}`
@@ -1239,7 +1239,7 @@ describe('buildScopesMap', () => {
1239
1239
  }
1240
1240
  }
1241
1241
  ];
1242
- const result = buildScopesMap(
1242
+ const result = createScopesMap(
1243
1243
  imports,
1244
1244
  manifests,
1245
1245
  (name, scope) => `${name}/${scope}`
@@ -1274,7 +1274,7 @@ describe('buildScopesMap', () => {
1274
1274
  }
1275
1275
  }
1276
1276
  ];
1277
- const result = buildScopesMap(
1277
+ const result = createScopesMap(
1278
1278
  imports,
1279
1279
  manifests,
1280
1280
  (name, scope) => `${name}/${scope}`
@@ -1302,7 +1302,7 @@ describe('buildScopesMap', () => {
1302
1302
  scopes: undefined as any
1303
1303
  }
1304
1304
  ];
1305
- const result = buildScopesMap(
1305
+ const result = createScopesMap(
1306
1306
  imports,
1307
1307
  manifests,
1308
1308
  (name, scope) => `${name}/${scope}`
@@ -1311,14 +1311,14 @@ describe('buildScopesMap', () => {
1311
1311
  });
1312
1312
  });
1313
1313
 
1314
- describe('getImportMap', () => {
1314
+ describe('createImportMap', () => {
1315
1315
  test('should return empty import map for empty manifests', () => {
1316
1316
  const options: GetImportMapOptions = {
1317
1317
  manifests: [],
1318
1318
  getFile: (name, file) => `${name}/${file}`,
1319
1319
  getScope: (name, scope) => `${name}/${scope}`
1320
1320
  };
1321
- const result = getImportMap(options);
1321
+ const result = createImportMap(options);
1322
1322
  assert.deepEqual(result, {
1323
1323
  imports: {},
1324
1324
  scopes: {}
@@ -1355,7 +1355,7 @@ describe('getImportMap', () => {
1355
1355
  getFile: (name, file) => `${name}/${file}`,
1356
1356
  getScope: (name, scope) => `${name}/${scope}`
1357
1357
  };
1358
- const result = getImportMap(options);
1358
+ const result = createImportMap(options);
1359
1359
  assert.deepEqual(result, {
1360
1360
  imports: {
1361
1361
  'test-module/component': 'test-module/component.js',
@@ -1409,7 +1409,7 @@ describe('getImportMap', () => {
1409
1409
  getFile: (name, file) => `${name}/${file}`,
1410
1410
  getScope: (name, scope) => `${name}/${scope}`
1411
1411
  };
1412
- const result = getImportMap(options);
1412
+ const result = createImportMap(options);
1413
1413
  assert.deepEqual(result, {
1414
1414
  imports: {
1415
1415
  'module-a/utils': 'module-a/utils.js',
@@ -1445,7 +1445,7 @@ describe('getImportMap', () => {
1445
1445
  getFile: (name, file) => `${name}/${file}`,
1446
1446
  getScope: (name, scope) => `${name}/${scope}`
1447
1447
  };
1448
- const result = getImportMap(options);
1448
+ const result = createImportMap(options);
1449
1449
  assert.deepEqual(result, {
1450
1450
  imports: {
1451
1451
  'test-module/component': 'test-module/component.js'
@@ -1470,7 +1470,7 @@ describe('getImportMap', () => {
1470
1470
  getFile: (name, file) => `${name}/${file}`,
1471
1471
  getScope: (name, scope) => `${name}/${scope}`
1472
1472
  };
1473
- const result = getImportMap(options);
1473
+ const result = createImportMap(options);
1474
1474
  assert.deepEqual(result, {
1475
1475
  imports: {},
1476
1476
  scopes: {
@@ -1504,7 +1504,7 @@ describe('getImportMap', () => {
1504
1504
  getFile: (name, file) => `/custom/path/${name}/${file}`,
1505
1505
  getScope: (name, scope) => `custom-scope-${name}-${scope}`
1506
1506
  };
1507
- const result = getImportMap(options);
1507
+ const result = createImportMap(options);
1508
1508
  assert.deepEqual(result, {
1509
1509
  imports: {
1510
1510
  'test-module/component': '/custom/path/test-module/component.js'
@@ -1536,7 +1536,7 @@ describe('getImportMap', () => {
1536
1536
  getFile: (name, file) => `${name}/${file}`,
1537
1537
  getScope: (name, scope) => `${name}/${scope}`
1538
1538
  };
1539
- const result = getImportMap(options);
1539
+ const result = createImportMap(options);
1540
1540
  assert.deepEqual(result, {
1541
1541
  imports: {
1542
1542
  'test-module/component': 'test-module/component.js'
@@ -1569,7 +1569,7 @@ describe('getImportMap', () => {
1569
1569
  getFile: (name, file) => `${name}/${file}`,
1570
1570
  getScope: (name, scope) => `${name}/${scope}`
1571
1571
  };
1572
- const result = getImportMap(options);
1572
+ const result = createImportMap(options);
1573
1573
  assert.deepEqual(result, {
1574
1574
  imports: {
1575
1575
  'test-module/component': 'test-module/component.js'
@@ -1606,7 +1606,7 @@ describe('getImportMap', () => {
1606
1606
  getFile: (name, file) => `${name}/${file}`,
1607
1607
  getScope: (name, scope) => `${name}/${scope}`
1608
1608
  };
1609
- const result = getImportMap(options);
1609
+ const result = createImportMap(options);
1610
1610
  assert.deepEqual(result, {
1611
1611
  imports: {
1612
1612
  'test-module/src/index': 'test-module/src/index.js',
@@ -22,7 +22,7 @@ export interface GetImportMapOptions {
22
22
  getFile: (name: string, file: string) => string;
23
23
  }
24
24
 
25
- export function buildImportsMap(
25
+ export function createImportsMap(
26
26
  manifests: readonly ImportMapManifest[],
27
27
  getFile: (name: string, file: string) => string
28
28
  ): SpecifierMap {
@@ -40,7 +40,7 @@ export function buildImportsMap(
40
40
  return imports;
41
41
  }
42
42
 
43
- export function buildScopesMap(
43
+ export function createScopesMap(
44
44
  imports: SpecifierMap,
45
45
  manifests: readonly ImportMapManifest[],
46
46
  getScope: (name: string, scope: string) => string
@@ -73,18 +73,19 @@ export function buildScopesMap(
73
73
  return scopes;
74
74
  }
75
75
  /**
76
- * Fixes Chrome's nested scope resolution bug in import maps.
76
+ * Fixes the nested scope resolution issue in import maps across all browsers.
77
77
  *
78
- * Chrome has a bug where nested scopes in import maps are not resolved correctly.
78
+ * Import Maps have a cross-browser issue where nested scopes are not resolved correctly.
79
79
  * For example, when you have both "/shared-modules/" and "/shared-modules/vue2/" scopes,
80
- * Chrome fails to properly apply the more specific nested scope.
80
+ * browsers fail to properly apply the more specific nested scope.
81
81
  *
82
- * This function works around the bug by:
82
+ * This function works around the issue by:
83
83
  * 1. Sorting scopes by path depth (shallow paths first, deeper paths last)
84
84
  * 2. Manually applying scopes to matching imports in the correct order
85
+ * 3. Converting pattern-based scopes to concrete path scopes
85
86
  *
86
87
  * @example
87
- * Problematic import map that fails in Chrome:
88
+ * Problematic import map that fails in browsers:
88
89
  * ```json
89
90
  * {
90
91
  * "scopes": {
@@ -101,7 +102,7 @@ export function buildScopesMap(
101
102
  * @see https://github.com/guybedford/es-module-shims/issues/529
102
103
  * @see https://issues.chromium.org/issues/453147451
103
104
  */
104
- export function fixNestedScopesResolution(
105
+ export function fixImportMapNestedScopes(
105
106
  importMap: Required<ImportMap>
106
107
  ): Required<ImportMap> {
107
108
  Object.entries(importMap.scopes)
@@ -125,14 +126,14 @@ export function fixNestedScopesResolution(
125
126
  return importMap;
126
127
  }
127
128
 
128
- export function getImportMap({
129
+ export function createImportMap({
129
130
  manifests,
130
131
  getFile,
131
132
  getScope
132
133
  }: GetImportMapOptions): Required<ImportMap> {
133
- const imports = buildImportsMap(manifests, getFile);
134
+ const imports = createImportsMap(manifests, getFile);
134
135
 
135
- const scopes = buildScopesMap(imports, manifests, getScope);
136
+ const scopes = createScopesMap(imports, manifests, getScope);
136
137
  return {
137
138
  imports,
138
139
  scopes