@esmx/core 3.0.0-rc.63 → 3.0.0-rc.64

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.
@@ -5,10 +5,6 @@ export interface ManifestJson {
5
5
  * Module name
6
6
  */
7
7
  name: string;
8
- /**
9
- * Import mappings
10
- */
11
- imports: Record<string, string>;
12
8
  /**
13
9
  * Scope-specific import mappings
14
10
  * Type: Record<scope name, import mappings within that scope>
@@ -55,7 +55,13 @@ export function getEnvironmentScopes(environment, scopes = {}) {
55
55
  export function getEnvironments(config, env, moduleName) {
56
56
  const imports = getEnvironmentImports(env, config.imports);
57
57
  const exports = getEnvironmentExports(config, env);
58
- const scopes = getEnvironmentScopes(env, config.scopes);
58
+ const scopes = getEnvironmentScopes(env, {
59
+ ...config.scopes,
60
+ "": {
61
+ ...config.scopes?.[""],
62
+ ...imports
63
+ }
64
+ });
59
65
  addPackageExportsToScopes(exports, scopes, moduleName);
60
66
  return {
61
67
  imports,
@@ -283,6 +283,30 @@ describe("Module Config Parser", () => {
283
283
  expect(emptyScope.existing).toBe("existing-value");
284
284
  expect(emptyScope.lodash).toBe("test-module/lodash");
285
285
  });
286
+ it("should verify the specific scopes merging logic with imports", () => {
287
+ const config = {
288
+ imports: {
289
+ react: "react",
290
+ vue: "vue"
291
+ },
292
+ scopes: {
293
+ utils: {
294
+ lodash: "lodash"
295
+ },
296
+ "": {
297
+ existing: "existing-value"
298
+ }
299
+ }
300
+ };
301
+ const result = getEnvironments(config, "client", "test-module");
302
+ expect(result.scopes[""]).toBeDefined();
303
+ expect(result.scopes[""].existing).toBe("existing-value");
304
+ expect(result.scopes[""].react).toBe("react");
305
+ expect(result.scopes[""].vue).toBe("vue");
306
+ expect(result.scopes.utils.lodash).toBe("lodash");
307
+ expect(result.imports.react).toBe("react");
308
+ expect(result.imports.vue).toBe("vue");
309
+ });
286
310
  });
287
311
  describe("addPackageExportsToScopes", () => {
288
312
  it("should create scopes for pkg exports", () => {
@@ -1,7 +1,6 @@
1
1
  import type { ImportMap, ScopesMap, SpecifierMap } from '@esmx/import';
2
2
  export interface ImportMapManifest {
3
3
  name: string;
4
- imports: Record<string, string>;
5
4
  exports: Record<string, {
6
5
  name: string;
7
6
  file: string;
@@ -7,12 +7,6 @@ export function buildImportsMap(manifests, getFile) {
7
7
  imports[exportItem.identifier] = file;
8
8
  });
9
9
  });
10
- manifests.forEach((manifest) => {
11
- Object.entries(manifest.imports).forEach(([name, identifier]) => {
12
- const fullName = `${manifest.name}/${name}`;
13
- imports[fullName] = imports[identifier] ?? identifier;
14
- });
15
- });
16
10
  pathWithoutIndex(imports);
17
11
  return imports;
18
12
  }
@@ -14,7 +14,6 @@ describe("buildImportsMap", () => {
14
14
  const manifests = [
15
15
  {
16
16
  name: "test-module",
17
- imports: {},
18
17
  exports: {
19
18
  component: {
20
19
  name: "component",
@@ -41,65 +40,10 @@ describe("buildImportsMap", () => {
41
40
  "test-module/vue": "test-module/vue.js"
42
41
  });
43
42
  });
44
- test("should handle user imports with existing identifiers", () => {
45
- const manifests = [
46
- {
47
- name: "test-module",
48
- imports: {
49
- "custom-name": "test-module/component"
50
- },
51
- exports: {
52
- component: {
53
- name: "component",
54
- pkg: false,
55
- file: "component.js",
56
- identifier: "test-module/component"
57
- }
58
- },
59
- scopes: {}
60
- }
61
- ];
62
- const result = buildImportsMap(
63
- manifests,
64
- (name, file) => `${name}/${file}`
65
- );
66
- assert.deepEqual(result, {
67
- "test-module/component": "test-module/component.js",
68
- "test-module/custom-name": "test-module/component.js"
69
- });
70
- });
71
- test("should handle user imports with non existing identifiers", () => {
72
- const manifests = [
73
- {
74
- name: "test-module",
75
- imports: {
76
- external: "https://cdn.com/lib.js"
77
- },
78
- exports: {
79
- component: {
80
- name: "component",
81
- pkg: false,
82
- file: "component.js",
83
- identifier: "test-module/component"
84
- }
85
- },
86
- scopes: {}
87
- }
88
- ];
89
- const result = buildImportsMap(
90
- manifests,
91
- (name, file) => `${name}/${file}`
92
- );
93
- assert.deepEqual(result, {
94
- "test-module/component": "test-module/component.js",
95
- "test-module/external": "https://cdn.com/lib.js"
96
- });
97
- });
98
43
  test("should create aliases for index suffixes", () => {
99
44
  const manifests = [
100
45
  {
101
46
  name: "test-module",
102
- imports: {},
103
47
  exports: {
104
48
  "src/index": {
105
49
  name: "src/index",
@@ -124,7 +68,6 @@ describe("buildImportsMap", () => {
124
68
  const manifests = [
125
69
  {
126
70
  name: "module-a",
127
- imports: {},
128
71
  exports: {
129
72
  utils: {
130
73
  name: "utils",
@@ -137,9 +80,6 @@ describe("buildImportsMap", () => {
137
80
  },
138
81
  {
139
82
  name: "module-b",
140
- imports: {
141
- shared: "module-a/utils"
142
- },
143
83
  exports: {},
144
84
  scopes: {}
145
85
  }
@@ -149,82 +89,13 @@ describe("buildImportsMap", () => {
149
89
  (name, file) => `${name}/${file}`
150
90
  );
151
91
  assert.deepEqual(result, {
152
- "module-a/utils": "module-a/utils.js",
153
- "module-b/shared": "module-a/utils.js"
154
- });
155
- });
156
- test("should prioritize user imports", () => {
157
- const manifests = [
158
- {
159
- name: "test-module",
160
- imports: {
161
- react: "preact",
162
- vue: "./custom/vue.js"
163
- },
164
- exports: {
165
- react: {
166
- name: "react",
167
- pkg: false,
168
- file: "react.js",
169
- identifier: "test-module/react"
170
- },
171
- vue: {
172
- name: "vue",
173
- pkg: false,
174
- file: "vue.js",
175
- identifier: "test-module/vue"
176
- }
177
- },
178
- scopes: {}
179
- }
180
- ];
181
- const result = buildImportsMap(
182
- manifests,
183
- (name, file) => `${name}/${file}`
184
- );
185
- assert.deepEqual(result, {
186
- "test-module/react": "preact",
187
- "test-module/vue": "./custom/vue.js"
188
- });
189
- });
190
- test("should handle mixed user import types", () => {
191
- const manifests = [
192
- {
193
- name: "test-module",
194
- imports: {
195
- "url-import": "https://example.com/lib.js",
196
- "relative-import": "./local/file.js",
197
- "identifier-import": "test-module/component"
198
- },
199
- exports: {
200
- component: {
201
- name: "component",
202
- pkg: false,
203
- file: "component.js",
204
- identifier: "test-module/component"
205
- }
206
- },
207
- scopes: {}
208
- }
209
- ];
210
- const result = buildImportsMap(
211
- manifests,
212
- (name, file) => `${name}/${file}`
213
- );
214
- assert.deepEqual(result, {
215
- "test-module/component": "test-module/component.js",
216
- "test-module/url-import": "https://example.com/lib.js",
217
- "test-module/relative-import": "./local/file.js",
218
- "test-module/identifier-import": "test-module/component.js"
92
+ "module-a/utils": "module-a/utils.js"
219
93
  });
220
94
  });
221
95
  test("should handle empty exports", () => {
222
96
  const manifests = [
223
97
  {
224
98
  name: "test-module",
225
- imports: {
226
- external: "https://cdn.com/lib.js"
227
- },
228
99
  exports: {},
229
100
  scopes: {}
230
101
  }
@@ -233,39 +104,12 @@ describe("buildImportsMap", () => {
233
104
  manifests,
234
105
  (name, file) => `${name}/${file}`
235
106
  );
236
- assert.deepEqual(result, {
237
- "test-module/external": "https://cdn.com/lib.js"
238
- });
239
- });
240
- test("should handle empty imports", () => {
241
- const manifests = [
242
- {
243
- name: "test-module",
244
- imports: {},
245
- exports: {
246
- component: {
247
- name: "component",
248
- pkg: false,
249
- file: "component.js",
250
- identifier: "test-module/component"
251
- }
252
- },
253
- scopes: {}
254
- }
255
- ];
256
- const result = buildImportsMap(
257
- manifests,
258
- (name, file) => `${name}/${file}`
259
- );
260
- assert.deepEqual(result, {
261
- "test-module/component": "test-module/component.js"
262
- });
107
+ assert.deepEqual(result, {});
263
108
  });
264
109
  test("should handle duplicate alias creation", () => {
265
110
  const manifests = [
266
111
  {
267
112
  name: "test-module",
268
- imports: {},
269
113
  exports: {
270
114
  "src/components/index": {
271
115
  name: "src/components/index",
@@ -286,77 +130,10 @@ describe("buildImportsMap", () => {
286
130
  "test-module/src/components": "test-module/src/components/index.js"
287
131
  });
288
132
  });
289
- test("should handle cross-module references", () => {
290
- const manifests = [
291
- {
292
- name: "module-a",
293
- imports: {},
294
- exports: {
295
- utils: {
296
- name: "utils",
297
- pkg: false,
298
- file: "utils.js",
299
- identifier: "module-a/utils"
300
- }
301
- },
302
- scopes: {}
303
- },
304
- {
305
- name: "module-b",
306
- imports: {
307
- shared: "module-a/utils"
308
- },
309
- exports: {},
310
- scopes: {}
311
- }
312
- ];
313
- const result = buildImportsMap(
314
- manifests,
315
- (name, file) => `${name}/${file}`
316
- );
317
- assert.deepEqual(result, {
318
- "module-a/utils": "module-a/utils.js",
319
- "module-b/shared": "module-a/utils.js"
320
- });
321
- });
322
- test("should handle cross-module non-existent references", () => {
323
- const manifests = [
324
- {
325
- name: "module-a",
326
- imports: {},
327
- exports: {
328
- utils: {
329
- name: "utils",
330
- pkg: false,
331
- file: "utils.js",
332
- identifier: "module-a/utils"
333
- }
334
- },
335
- scopes: {}
336
- },
337
- {
338
- name: "module-b",
339
- imports: {
340
- external: "module-a/non-existent"
341
- },
342
- exports: {},
343
- scopes: {}
344
- }
345
- ];
346
- const result = buildImportsMap(
347
- manifests,
348
- (name, file) => `${name}/${file}`
349
- );
350
- assert.deepEqual(result, {
351
- "module-a/utils": "module-a/utils.js",
352
- "module-b/external": "module-a/non-existent"
353
- });
354
- });
355
133
  test("should handle identifier conflicts across modules", () => {
356
134
  const manifests = [
357
135
  {
358
136
  name: "module-a",
359
- imports: {},
360
137
  exports: {
361
138
  utils: {
362
139
  name: "utils",
@@ -369,7 +146,6 @@ describe("buildImportsMap", () => {
369
146
  },
370
147
  {
371
148
  name: "module-b",
372
- imports: {},
373
149
  exports: {
374
150
  utils: {
375
151
  name: "utils",
@@ -390,39 +166,10 @@ describe("buildImportsMap", () => {
390
166
  "module-b/utils": "module-b/utils-b.js"
391
167
  });
392
168
  });
393
- test("should handle user imports referencing aliased identifiers", () => {
394
- const manifests = [
395
- {
396
- name: "test-module",
397
- imports: {
398
- "alias-test": "test-module/src/index"
399
- },
400
- exports: {
401
- "src/index": {
402
- name: "src/index",
403
- pkg: false,
404
- file: "src/index.js",
405
- identifier: "test-module/src/index"
406
- }
407
- },
408
- scopes: {}
409
- }
410
- ];
411
- const result = buildImportsMap(
412
- manifests,
413
- (name, file) => `${name}/${file}`
414
- );
415
- assert.deepEqual(result, {
416
- "test-module/src/index": "test-module/src/index.js",
417
- "test-module/src": "test-module/src/index.js",
418
- "test-module/alias-test": "test-module/src/index.js"
419
- });
420
- });
421
169
  test("should handle nested index aliases", () => {
422
170
  const manifests = [
423
171
  {
424
172
  name: "test-module",
425
- imports: {},
426
173
  exports: {
427
174
  "src/components/utils/index": {
428
175
  name: "src/components/utils/index",
@@ -1033,7 +780,6 @@ describe("buildScopesMap", () => {
1033
780
  const manifests = [
1034
781
  {
1035
782
  name: "test-module",
1036
- imports: {},
1037
783
  exports: {
1038
784
  component: {
1039
785
  name: "component",
@@ -1060,7 +806,6 @@ describe("buildScopesMap", () => {
1060
806
  const manifests = [
1061
807
  {
1062
808
  name: "test-module",
1063
- imports: {},
1064
809
  exports: {
1065
810
  component: {
1066
811
  name: "component",
@@ -1102,7 +847,6 @@ describe("buildScopesMap", () => {
1102
847
  const manifests = [
1103
848
  {
1104
849
  name: "test-module",
1105
- imports: {},
1106
850
  exports: {
1107
851
  component: {
1108
852
  name: "component",
@@ -1138,7 +882,6 @@ describe("buildScopesMap", () => {
1138
882
  const manifests = [
1139
883
  {
1140
884
  name: "test-module",
1141
- imports: {},
1142
885
  exports: {
1143
886
  component: {
1144
887
  name: "component",
@@ -1175,7 +918,6 @@ describe("buildScopesMap", () => {
1175
918
  const manifests = [
1176
919
  {
1177
920
  name: "test-module",
1178
- imports: {},
1179
921
  exports: {
1180
922
  node_modules: {
1181
923
  name: "node_modules",
@@ -1215,7 +957,6 @@ describe("buildScopesMap", () => {
1215
957
  const manifests = [
1216
958
  {
1217
959
  name: "test-module",
1218
- imports: {},
1219
960
  exports: {
1220
961
  component: {
1221
962
  name: "component",
@@ -1250,7 +991,6 @@ describe("buildScopesMap", () => {
1250
991
  const manifests = [
1251
992
  {
1252
993
  name: "test-module",
1253
- imports: {},
1254
994
  exports: {
1255
995
  component: {
1256
996
  name: "component",
@@ -1297,7 +1037,6 @@ describe("buildScopesMap", () => {
1297
1037
  const manifests = [
1298
1038
  {
1299
1039
  name: "module-a",
1300
- imports: {},
1301
1040
  exports: {
1302
1041
  component: {
1303
1042
  name: "component",
@@ -1314,7 +1053,6 @@ describe("buildScopesMap", () => {
1314
1053
  },
1315
1054
  {
1316
1055
  name: "module-b",
1317
- imports: {},
1318
1056
  exports: {
1319
1057
  utils: {
1320
1058
  name: "utils",
@@ -1351,7 +1089,6 @@ describe("buildScopesMap", () => {
1351
1089
  const manifests = [
1352
1090
  {
1353
1091
  name: "test-module",
1354
- imports: {},
1355
1092
  exports: {
1356
1093
  component: {
1357
1094
  name: "component",
@@ -1381,7 +1118,6 @@ describe("buildScopesMap", () => {
1381
1118
  const manifests = [
1382
1119
  {
1383
1120
  name: "test-module",
1384
- imports: {},
1385
1121
  exports: {
1386
1122
  component: {
1387
1123
  name: "component",
@@ -1414,14 +1150,11 @@ describe("getImportMap", () => {
1414
1150
  scopes: {}
1415
1151
  });
1416
1152
  });
1417
- test("should build complete import map with imports and scopes", () => {
1153
+ test("should build complete import map with exports and scopes", () => {
1418
1154
  const options = {
1419
1155
  manifests: [
1420
1156
  {
1421
1157
  name: "test-module",
1422
- imports: {
1423
- "custom-react": "test-module/component"
1424
- },
1425
1158
  exports: {
1426
1159
  component: {
1427
1160
  name: "component",
@@ -1451,8 +1184,7 @@ describe("getImportMap", () => {
1451
1184
  assert.deepEqual(result, {
1452
1185
  imports: {
1453
1186
  "test-module/component": "test-module/component.js",
1454
- "test-module/utils": "test-module/utils.js",
1455
- "test-module/custom-react": "test-module/component.js"
1187
+ "test-module/utils": "test-module/utils.js"
1456
1188
  },
1457
1189
  scopes: {
1458
1190
  "test-module//node_modules": {
@@ -1467,7 +1199,6 @@ describe("getImportMap", () => {
1467
1199
  manifests: [
1468
1200
  {
1469
1201
  name: "module-a",
1470
- imports: {},
1471
1202
  exports: {
1472
1203
  utils: {
1473
1204
  name: "utils",
@@ -1484,9 +1215,6 @@ describe("getImportMap", () => {
1484
1215
  },
1485
1216
  {
1486
1217
  name: "module-b",
1487
- imports: {
1488
- shared: "module-a/utils"
1489
- },
1490
1218
  exports: {
1491
1219
  component: {
1492
1220
  name: "component",
@@ -1509,8 +1237,7 @@ describe("getImportMap", () => {
1509
1237
  assert.deepEqual(result, {
1510
1238
  imports: {
1511
1239
  "module-a/utils": "module-a/utils.js",
1512
- "module-b/component": "module-b/component.js",
1513
- "module-b/shared": "module-a/utils.js"
1240
+ "module-b/component": "module-b/component.js"
1514
1241
  },
1515
1242
  scopes: {
1516
1243
  "module-a//node_modules": {
@@ -1527,7 +1254,6 @@ describe("getImportMap", () => {
1527
1254
  manifests: [
1528
1255
  {
1529
1256
  name: "test-module",
1530
- imports: {},
1531
1257
  exports: {
1532
1258
  component: {
1533
1259
  name: "component",
@@ -1550,35 +1276,11 @@ describe("getImportMap", () => {
1550
1276
  scopes: {}
1551
1277
  });
1552
1278
  });
1553
- test("should handle manifests with only imports", () => {
1554
- const options = {
1555
- manifests: [
1556
- {
1557
- name: "test-module",
1558
- imports: {
1559
- external: "https://cdn.com/lib.js"
1560
- },
1561
- exports: {},
1562
- scopes: {}
1563
- }
1564
- ],
1565
- getFile: (name, file) => `${name}/${file}`,
1566
- getScope: (name, scope) => `${name}/${scope}`
1567
- };
1568
- const result = getImportMap(options);
1569
- assert.deepEqual(result, {
1570
- imports: {
1571
- "test-module/external": "https://cdn.com/lib.js"
1572
- },
1573
- scopes: {}
1574
- });
1575
- });
1576
1279
  test("should handle manifests with only scopes", () => {
1577
1280
  const options = {
1578
1281
  manifests: [
1579
1282
  {
1580
1283
  name: "test-module",
1581
- imports: {},
1582
1284
  exports: {},
1583
1285
  scopes: {
1584
1286
  node_modules: {
@@ -1605,7 +1307,6 @@ describe("getImportMap", () => {
1605
1307
  manifests: [
1606
1308
  {
1607
1309
  name: "test-module",
1608
- imports: {},
1609
1310
  exports: {
1610
1311
  component: {
1611
1312
  name: "component",
@@ -1641,7 +1342,6 @@ describe("getImportMap", () => {
1641
1342
  manifests: [
1642
1343
  {
1643
1344
  name: "test-module",
1644
- imports: {},
1645
1345
  exports: {
1646
1346
  component: {
1647
1347
  name: "component",
@@ -1669,10 +1369,6 @@ describe("getImportMap", () => {
1669
1369
  manifests: [
1670
1370
  {
1671
1371
  name: "test-module",
1672
- imports: {
1673
- "external-react": "https://cdn.com/react.js",
1674
- "local-alias": "test-module/component"
1675
- },
1676
1372
  exports: {
1677
1373
  component: {
1678
1374
  name: "component",
@@ -1695,9 +1391,7 @@ describe("getImportMap", () => {
1695
1391
  const result = getImportMap(options);
1696
1392
  assert.deepEqual(result, {
1697
1393
  imports: {
1698
- "test-module/component": "test-module/component.js",
1699
- "test-module/external-react": "https://cdn.com/react.js",
1700
- "test-module/local-alias": "test-module/component.js"
1394
+ "test-module/component": "test-module/component.js"
1701
1395
  },
1702
1396
  scopes: {
1703
1397
  "test-module//node_modules": {
@@ -1712,7 +1406,6 @@ describe("getImportMap", () => {
1712
1406
  manifests: [
1713
1407
  {
1714
1408
  name: "test-module",
1715
- imports: {},
1716
1409
  exports: {
1717
1410
  "src/index": {
1718
1411
  name: "src/index",
package/package.json CHANGED
@@ -59,7 +59,7 @@
59
59
  "build": "unbuild"
60
60
  },
61
61
  "dependencies": {
62
- "@esmx/import": "3.0.0-rc.63",
62
+ "@esmx/import": "3.0.0-rc.64",
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.63",
80
+ "version": "3.0.0-rc.64",
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": "18a524ff1b7f9c6ea60d8bb57ad314329febc58c"
103
+ "gitHead": "8c103750d1e623fa4fa23b6ed9149f39e4a9bd58"
104
104
  }
@@ -9,10 +9,6 @@ export interface ManifestJson {
9
9
  * Module name
10
10
  */
11
11
  name: string;
12
- /**
13
- * Import mappings
14
- */
15
- imports: Record<string, string>;
16
12
  /**
17
13
  * Scope-specific import mappings
18
14
  * Type: Record<scope name, import mappings within that scope>
@@ -313,6 +313,37 @@ describe('Module Config Parser', () => {
313
313
  expect(emptyScope.existing).toBe('existing-value');
314
314
  expect(emptyScope.lodash).toBe('test-module/lodash');
315
315
  });
316
+
317
+ it('should verify the specific scopes merging logic with imports', () => {
318
+ const config: ModuleConfig = {
319
+ imports: {
320
+ react: 'react',
321
+ vue: 'vue'
322
+ },
323
+ scopes: {
324
+ utils: {
325
+ lodash: 'lodash'
326
+ },
327
+ '': {
328
+ existing: 'existing-value'
329
+ }
330
+ }
331
+ };
332
+ const result = getEnvironments(config, 'client', 'test-module');
333
+
334
+ // 验证核心逻辑:imports 被合并到空字符串 scope 中
335
+ expect(result.scopes['']).toBeDefined();
336
+ expect(result.scopes[''].existing).toBe('existing-value'); // 保留现有内容
337
+ expect(result.scopes[''].react).toBe('react'); // 合并 imports
338
+ expect(result.scopes[''].vue).toBe('vue'); // 合并 imports
339
+
340
+ // 验证其他 scopes 不受影响
341
+ expect(result.scopes.utils.lodash).toBe('lodash');
342
+
343
+ // 验证 result.imports 也包含相同的 imports
344
+ expect(result.imports.react).toBe('react');
345
+ expect(result.imports.vue).toBe('vue');
346
+ });
316
347
  });
317
348
 
318
349
  describe('addPackageExportsToScopes', () => {
@@ -145,7 +145,13 @@ export function getEnvironments(
145
145
  ): ParsedModuleConfigEnvironment {
146
146
  const imports = getEnvironmentImports(env, config.imports);
147
147
  const exports = getEnvironmentExports(config, env);
148
- const scopes = getEnvironmentScopes(env, config.scopes);
148
+ const scopes = getEnvironmentScopes(env, {
149
+ ...config.scopes,
150
+ '': {
151
+ ...config.scopes?.[''],
152
+ ...imports
153
+ }
154
+ });
149
155
  addPackageExportsToScopes(exports, scopes, moduleName);
150
156
  return {
151
157
  imports,
@@ -17,7 +17,6 @@ describe('buildImportsMap', () => {
17
17
  const manifests: ImportMapManifest[] = [
18
18
  {
19
19
  name: 'test-module',
20
- imports: {},
21
20
  exports: {
22
21
  component: {
23
22
  name: 'component',
@@ -47,71 +46,10 @@ describe('buildImportsMap', () => {
47
46
  });
48
47
  });
49
48
 
50
- test('should handle user imports with existing identifiers', () => {
51
- const manifests: ImportMapManifest[] = [
52
- {
53
- name: 'test-module',
54
- imports: {
55
- 'custom-name': 'test-module/component'
56
- },
57
- exports: {
58
- component: {
59
- name: 'component',
60
- pkg: false,
61
- file: 'component.js',
62
- identifier: 'test-module/component'
63
- }
64
- },
65
- scopes: {}
66
- }
67
- ];
68
-
69
- const result = buildImportsMap(
70
- manifests,
71
- (name, file) => `${name}/${file}`
72
- );
73
-
74
- assert.deepEqual(result, {
75
- 'test-module/component': 'test-module/component.js',
76
- 'test-module/custom-name': 'test-module/component.js'
77
- });
78
- });
79
-
80
- test('should handle user imports with non existing identifiers', () => {
81
- const manifests: ImportMapManifest[] = [
82
- {
83
- name: 'test-module',
84
- imports: {
85
- external: 'https://cdn.com/lib.js'
86
- },
87
- exports: {
88
- component: {
89
- name: 'component',
90
- pkg: false,
91
- file: 'component.js',
92
- identifier: 'test-module/component'
93
- }
94
- },
95
- scopes: {}
96
- }
97
- ];
98
-
99
- const result = buildImportsMap(
100
- manifests,
101
- (name, file) => `${name}/${file}`
102
- );
103
-
104
- assert.deepEqual(result, {
105
- 'test-module/component': 'test-module/component.js',
106
- 'test-module/external': 'https://cdn.com/lib.js'
107
- });
108
- });
109
-
110
49
  test('should create aliases for index suffixes', () => {
111
50
  const manifests: ImportMapManifest[] = [
112
51
  {
113
52
  name: 'test-module',
114
- imports: {},
115
53
  exports: {
116
54
  'src/index': {
117
55
  name: 'src/index',
@@ -139,7 +77,6 @@ describe('buildImportsMap', () => {
139
77
  const manifests: ImportMapManifest[] = [
140
78
  {
141
79
  name: 'module-a',
142
- imports: {},
143
80
  exports: {
144
81
  utils: {
145
82
  name: 'utils',
@@ -152,9 +89,6 @@ describe('buildImportsMap', () => {
152
89
  },
153
90
  {
154
91
  name: 'module-b',
155
- imports: {
156
- shared: 'module-a/utils'
157
- },
158
92
  exports: {},
159
93
  scopes: {}
160
94
  }
@@ -166,79 +100,7 @@ describe('buildImportsMap', () => {
166
100
  );
167
101
 
168
102
  assert.deepEqual(result, {
169
- 'module-a/utils': 'module-a/utils.js',
170
- 'module-b/shared': 'module-a/utils.js'
171
- });
172
- });
173
-
174
- test('should prioritize user imports', () => {
175
- const manifests: ImportMapManifest[] = [
176
- {
177
- name: 'test-module',
178
- imports: {
179
- react: 'preact',
180
- vue: './custom/vue.js'
181
- },
182
- exports: {
183
- react: {
184
- name: 'react',
185
- pkg: false,
186
- file: 'react.js',
187
- identifier: 'test-module/react'
188
- },
189
- vue: {
190
- name: 'vue',
191
- pkg: false,
192
- file: 'vue.js',
193
- identifier: 'test-module/vue'
194
- }
195
- },
196
- scopes: {}
197
- }
198
- ];
199
-
200
- const result = buildImportsMap(
201
- manifests,
202
- (name, file) => `${name}/${file}`
203
- );
204
-
205
- assert.deepEqual(result, {
206
- 'test-module/react': 'preact',
207
- 'test-module/vue': './custom/vue.js'
208
- });
209
- });
210
-
211
- test('should handle mixed user import types', () => {
212
- const manifests: ImportMapManifest[] = [
213
- {
214
- name: 'test-module',
215
- imports: {
216
- 'url-import': 'https://example.com/lib.js',
217
- 'relative-import': './local/file.js',
218
- 'identifier-import': 'test-module/component'
219
- },
220
- exports: {
221
- component: {
222
- name: 'component',
223
- pkg: false,
224
- file: 'component.js',
225
- identifier: 'test-module/component'
226
- }
227
- },
228
- scopes: {}
229
- }
230
- ];
231
-
232
- const result = buildImportsMap(
233
- manifests,
234
- (name, file) => `${name}/${file}`
235
- );
236
-
237
- assert.deepEqual(result, {
238
- 'test-module/component': 'test-module/component.js',
239
- 'test-module/url-import': 'https://example.com/lib.js',
240
- 'test-module/relative-import': './local/file.js',
241
- 'test-module/identifier-import': 'test-module/component.js'
103
+ 'module-a/utils': 'module-a/utils.js'
242
104
  });
243
105
  });
244
106
 
@@ -246,9 +108,6 @@ describe('buildImportsMap', () => {
246
108
  const manifests: ImportMapManifest[] = [
247
109
  {
248
110
  name: 'test-module',
249
- imports: {
250
- external: 'https://cdn.com/lib.js'
251
- },
252
111
  exports: {},
253
112
  scopes: {}
254
113
  }
@@ -259,43 +118,13 @@ describe('buildImportsMap', () => {
259
118
  (name, file) => `${name}/${file}`
260
119
  );
261
120
 
262
- assert.deepEqual(result, {
263
- 'test-module/external': 'https://cdn.com/lib.js'
264
- });
265
- });
266
-
267
- test('should handle empty imports', () => {
268
- const manifests: ImportMapManifest[] = [
269
- {
270
- name: 'test-module',
271
- imports: {},
272
- exports: {
273
- component: {
274
- name: 'component',
275
- pkg: false,
276
- file: 'component.js',
277
- identifier: 'test-module/component'
278
- }
279
- },
280
- scopes: {}
281
- }
282
- ];
283
-
284
- const result = buildImportsMap(
285
- manifests,
286
- (name, file) => `${name}/${file}`
287
- );
288
-
289
- assert.deepEqual(result, {
290
- 'test-module/component': 'test-module/component.js'
291
- });
121
+ assert.deepEqual(result, {});
292
122
  });
293
123
 
294
124
  test('should handle duplicate alias creation', () => {
295
125
  const manifests: ImportMapManifest[] = [
296
126
  {
297
127
  name: 'test-module',
298
- imports: {},
299
128
  exports: {
300
129
  'src/components/index': {
301
130
  name: 'src/components/index',
@@ -320,83 +149,10 @@ describe('buildImportsMap', () => {
320
149
  });
321
150
  });
322
151
 
323
- test('should handle cross-module references', () => {
324
- const manifests: ImportMapManifest[] = [
325
- {
326
- name: 'module-a',
327
- imports: {},
328
- exports: {
329
- utils: {
330
- name: 'utils',
331
- pkg: false,
332
- file: 'utils.js',
333
- identifier: 'module-a/utils'
334
- }
335
- },
336
- scopes: {}
337
- },
338
- {
339
- name: 'module-b',
340
- imports: {
341
- shared: 'module-a/utils'
342
- },
343
- exports: {},
344
- scopes: {}
345
- }
346
- ];
347
-
348
- const result = buildImportsMap(
349
- manifests,
350
- (name, file) => `${name}/${file}`
351
- );
352
-
353
- assert.deepEqual(result, {
354
- 'module-a/utils': 'module-a/utils.js',
355
- 'module-b/shared': 'module-a/utils.js'
356
- });
357
- });
358
-
359
- test('should handle cross-module non-existent references', () => {
360
- const manifests: ImportMapManifest[] = [
361
- {
362
- name: 'module-a',
363
- imports: {},
364
- exports: {
365
- utils: {
366
- name: 'utils',
367
- pkg: false,
368
- file: 'utils.js',
369
- identifier: 'module-a/utils'
370
- }
371
- },
372
- scopes: {}
373
- },
374
- {
375
- name: 'module-b',
376
- imports: {
377
- external: 'module-a/non-existent'
378
- },
379
- exports: {},
380
- scopes: {}
381
- }
382
- ];
383
-
384
- const result = buildImportsMap(
385
- manifests,
386
- (name, file) => `${name}/${file}`
387
- );
388
-
389
- assert.deepEqual(result, {
390
- 'module-a/utils': 'module-a/utils.js',
391
- 'module-b/external': 'module-a/non-existent'
392
- });
393
- });
394
-
395
152
  test('should handle identifier conflicts across modules', () => {
396
153
  const manifests: ImportMapManifest[] = [
397
154
  {
398
155
  name: 'module-a',
399
- imports: {},
400
156
  exports: {
401
157
  utils: {
402
158
  name: 'utils',
@@ -409,7 +165,6 @@ describe('buildImportsMap', () => {
409
165
  },
410
166
  {
411
167
  name: 'module-b',
412
- imports: {},
413
168
  exports: {
414
169
  utils: {
415
170
  name: 'utils',
@@ -433,42 +188,10 @@ describe('buildImportsMap', () => {
433
188
  });
434
189
  });
435
190
 
436
- test('should handle user imports referencing aliased identifiers', () => {
437
- const manifests: ImportMapManifest[] = [
438
- {
439
- name: 'test-module',
440
- imports: {
441
- 'alias-test': 'test-module/src/index'
442
- },
443
- exports: {
444
- 'src/index': {
445
- name: 'src/index',
446
- pkg: false,
447
- file: 'src/index.js',
448
- identifier: 'test-module/src/index'
449
- }
450
- },
451
- scopes: {}
452
- }
453
- ];
454
-
455
- const result = buildImportsMap(
456
- manifests,
457
- (name, file) => `${name}/${file}`
458
- );
459
-
460
- assert.deepEqual(result, {
461
- 'test-module/src/index': 'test-module/src/index.js',
462
- 'test-module/src': 'test-module/src/index.js',
463
- 'test-module/alias-test': 'test-module/src/index.js'
464
- });
465
- });
466
-
467
191
  test('should handle nested index aliases', () => {
468
192
  const manifests: ImportMapManifest[] = [
469
193
  {
470
194
  name: 'test-module',
471
- imports: {},
472
195
  exports: {
473
196
  'src/components/utils/index': {
474
197
  name: 'src/components/utils/index',
@@ -1221,7 +944,6 @@ describe('buildScopesMap', () => {
1221
944
  const manifests: ImportMapManifest[] = [
1222
945
  {
1223
946
  name: 'test-module',
1224
- imports: {},
1225
947
  exports: {
1226
948
  component: {
1227
949
  name: 'component',
@@ -1249,7 +971,6 @@ describe('buildScopesMap', () => {
1249
971
  const manifests: ImportMapManifest[] = [
1250
972
  {
1251
973
  name: 'test-module',
1252
- imports: {},
1253
974
  exports: {
1254
975
  component: {
1255
976
  name: 'component',
@@ -1292,7 +1013,6 @@ describe('buildScopesMap', () => {
1292
1013
  const manifests: ImportMapManifest[] = [
1293
1014
  {
1294
1015
  name: 'test-module',
1295
- imports: {},
1296
1016
  exports: {
1297
1017
  component: {
1298
1018
  name: 'component',
@@ -1329,7 +1049,6 @@ describe('buildScopesMap', () => {
1329
1049
  const manifests: ImportMapManifest[] = [
1330
1050
  {
1331
1051
  name: 'test-module',
1332
- imports: {},
1333
1052
  exports: {
1334
1053
  component: {
1335
1054
  name: 'component',
@@ -1367,7 +1086,6 @@ describe('buildScopesMap', () => {
1367
1086
  const manifests: ImportMapManifest[] = [
1368
1087
  {
1369
1088
  name: 'test-module',
1370
- imports: {},
1371
1089
  exports: {
1372
1090
  node_modules: {
1373
1091
  name: 'node_modules',
@@ -1408,7 +1126,6 @@ describe('buildScopesMap', () => {
1408
1126
  const manifests: ImportMapManifest[] = [
1409
1127
  {
1410
1128
  name: 'test-module',
1411
- imports: {},
1412
1129
  exports: {
1413
1130
  component: {
1414
1131
  name: 'component',
@@ -1444,7 +1161,6 @@ describe('buildScopesMap', () => {
1444
1161
  const manifests: ImportMapManifest[] = [
1445
1162
  {
1446
1163
  name: 'test-module',
1447
- imports: {},
1448
1164
  exports: {
1449
1165
  component: {
1450
1166
  name: 'component',
@@ -1492,7 +1208,6 @@ describe('buildScopesMap', () => {
1492
1208
  const manifests: ImportMapManifest[] = [
1493
1209
  {
1494
1210
  name: 'module-a',
1495
- imports: {},
1496
1211
  exports: {
1497
1212
  component: {
1498
1213
  name: 'component',
@@ -1509,7 +1224,6 @@ describe('buildScopesMap', () => {
1509
1224
  },
1510
1225
  {
1511
1226
  name: 'module-b',
1512
- imports: {},
1513
1227
  exports: {
1514
1228
  utils: {
1515
1229
  name: 'utils',
@@ -1547,7 +1261,6 @@ describe('buildScopesMap', () => {
1547
1261
  const manifests: ImportMapManifest[] = [
1548
1262
  {
1549
1263
  name: 'test-module',
1550
- imports: {},
1551
1264
  exports: {
1552
1265
  component: {
1553
1266
  name: 'component',
@@ -1578,7 +1291,6 @@ describe('buildScopesMap', () => {
1578
1291
  const manifests: ImportMapManifest[] = [
1579
1292
  {
1580
1293
  name: 'test-module',
1581
- imports: {},
1582
1294
  exports: {
1583
1295
  component: {
1584
1296
  name: 'component',
@@ -1613,14 +1325,11 @@ describe('getImportMap', () => {
1613
1325
  });
1614
1326
  });
1615
1327
 
1616
- test('should build complete import map with imports and scopes', () => {
1328
+ test('should build complete import map with exports and scopes', () => {
1617
1329
  const options: GetImportMapOptions = {
1618
1330
  manifests: [
1619
1331
  {
1620
1332
  name: 'test-module',
1621
- imports: {
1622
- 'custom-react': 'test-module/component'
1623
- },
1624
1333
  exports: {
1625
1334
  component: {
1626
1335
  name: 'component',
@@ -1650,8 +1359,7 @@ describe('getImportMap', () => {
1650
1359
  assert.deepEqual(result, {
1651
1360
  imports: {
1652
1361
  'test-module/component': 'test-module/component.js',
1653
- 'test-module/utils': 'test-module/utils.js',
1654
- 'test-module/custom-react': 'test-module/component.js'
1362
+ 'test-module/utils': 'test-module/utils.js'
1655
1363
  },
1656
1364
  scopes: {
1657
1365
  'test-module//node_modules': {
@@ -1667,7 +1375,6 @@ describe('getImportMap', () => {
1667
1375
  manifests: [
1668
1376
  {
1669
1377
  name: 'module-a',
1670
- imports: {},
1671
1378
  exports: {
1672
1379
  utils: {
1673
1380
  name: 'utils',
@@ -1684,9 +1391,6 @@ describe('getImportMap', () => {
1684
1391
  },
1685
1392
  {
1686
1393
  name: 'module-b',
1687
- imports: {
1688
- shared: 'module-a/utils'
1689
- },
1690
1394
  exports: {
1691
1395
  component: {
1692
1396
  name: 'component',
@@ -1709,8 +1413,7 @@ describe('getImportMap', () => {
1709
1413
  assert.deepEqual(result, {
1710
1414
  imports: {
1711
1415
  'module-a/utils': 'module-a/utils.js',
1712
- 'module-b/component': 'module-b/component.js',
1713
- 'module-b/shared': 'module-a/utils.js'
1416
+ 'module-b/component': 'module-b/component.js'
1714
1417
  },
1715
1418
  scopes: {
1716
1419
  'module-a//node_modules': {
@@ -1728,7 +1431,6 @@ describe('getImportMap', () => {
1728
1431
  manifests: [
1729
1432
  {
1730
1433
  name: 'test-module',
1731
- imports: {},
1732
1434
  exports: {
1733
1435
  component: {
1734
1436
  name: 'component',
@@ -1752,36 +1454,11 @@ describe('getImportMap', () => {
1752
1454
  });
1753
1455
  });
1754
1456
 
1755
- test('should handle manifests with only imports', () => {
1756
- const options: GetImportMapOptions = {
1757
- manifests: [
1758
- {
1759
- name: 'test-module',
1760
- imports: {
1761
- external: 'https://cdn.com/lib.js'
1762
- },
1763
- exports: {},
1764
- scopes: {}
1765
- }
1766
- ],
1767
- getFile: (name, file) => `${name}/${file}`,
1768
- getScope: (name, scope) => `${name}/${scope}`
1769
- };
1770
- const result = getImportMap(options);
1771
- assert.deepEqual(result, {
1772
- imports: {
1773
- 'test-module/external': 'https://cdn.com/lib.js'
1774
- },
1775
- scopes: {}
1776
- });
1777
- });
1778
-
1779
1457
  test('should handle manifests with only scopes', () => {
1780
1458
  const options: GetImportMapOptions = {
1781
1459
  manifests: [
1782
1460
  {
1783
1461
  name: 'test-module',
1784
- imports: {},
1785
1462
  exports: {},
1786
1463
  scopes: {
1787
1464
  node_modules: {
@@ -1809,7 +1486,6 @@ describe('getImportMap', () => {
1809
1486
  manifests: [
1810
1487
  {
1811
1488
  name: 'test-module',
1812
- imports: {},
1813
1489
  exports: {
1814
1490
  component: {
1815
1491
  name: 'component',
@@ -1846,7 +1522,6 @@ describe('getImportMap', () => {
1846
1522
  manifests: [
1847
1523
  {
1848
1524
  name: 'test-module',
1849
- imports: {},
1850
1525
  exports: {
1851
1526
  component: {
1852
1527
  name: 'component',
@@ -1875,10 +1550,6 @@ describe('getImportMap', () => {
1875
1550
  manifests: [
1876
1551
  {
1877
1552
  name: 'test-module',
1878
- imports: {
1879
- 'external-react': 'https://cdn.com/react.js',
1880
- 'local-alias': 'test-module/component'
1881
- },
1882
1553
  exports: {
1883
1554
  component: {
1884
1555
  name: 'component',
@@ -1901,9 +1572,7 @@ describe('getImportMap', () => {
1901
1572
  const result = getImportMap(options);
1902
1573
  assert.deepEqual(result, {
1903
1574
  imports: {
1904
- 'test-module/component': 'test-module/component.js',
1905
- 'test-module/external-react': 'https://cdn.com/react.js',
1906
- 'test-module/local-alias': 'test-module/component.js'
1575
+ 'test-module/component': 'test-module/component.js'
1907
1576
  },
1908
1577
  scopes: {
1909
1578
  'test-module//node_modules': {
@@ -1919,7 +1588,6 @@ describe('getImportMap', () => {
1919
1588
  manifests: [
1920
1589
  {
1921
1590
  name: 'test-module',
1922
- imports: {},
1923
1591
  exports: {
1924
1592
  'src/index': {
1925
1593
  name: 'src/index',
@@ -4,7 +4,6 @@ import type { ImportMap, ScopesMap, SpecifierMap } from '@esmx/import';
4
4
 
5
5
  export interface ImportMapManifest {
6
6
  name: string;
7
- imports: Record<string, string>;
8
7
  exports: Record<
9
8
  string,
10
9
  {
@@ -36,13 +35,6 @@ export function buildImportsMap(
36
35
  });
37
36
  });
38
37
 
39
- manifests.forEach((manifest) => {
40
- Object.entries(manifest.imports).forEach(([name, identifier]) => {
41
- const fullName = `${manifest.name}/${name}`;
42
- imports[fullName] = imports[identifier] ?? identifier;
43
- });
44
- });
45
-
46
38
  pathWithoutIndex(imports);
47
39
 
48
40
  return imports;