@esmx/core 3.0.0-rc.69 → 3.0.0-rc.71
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/README.md +10 -7
- package/README.zh-CN.md +10 -7
- package/dist/cli/cli.mjs +9 -4
- package/dist/core.mjs +3 -3
- package/dist/utils/import-map.d.ts +12 -9
- package/dist/utils/import-map.mjs +56 -6
- package/dist/utils/import-map.test.mjs +214 -68
- package/package.json +9 -9
- package/src/cli/cli.ts +11 -5
- package/src/core.ts +3 -3
- package/src/utils/import-map.test.ts +228 -70
- package/src/utils/import-map.ts +73 -11
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { assert, describe, test } from "vitest";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
compressImportMap,
|
|
4
|
+
createImportMap,
|
|
5
|
+
createImportsMap,
|
|
6
|
+
createScopesMap,
|
|
7
|
+
fixImportMapNestedScopes
|
|
7
8
|
} from "./import-map.mjs";
|
|
8
|
-
describe("
|
|
9
|
+
describe("createImportsMap", () => {
|
|
9
10
|
test("should return empty object for empty manifests", () => {
|
|
10
|
-
const result =
|
|
11
|
+
const result = createImportsMap([], (name, file) => `${name}/${file}`);
|
|
11
12
|
assert.deepEqual(result, {});
|
|
12
13
|
});
|
|
13
14
|
test("should process all exports including package exports", () => {
|
|
@@ -31,7 +32,7 @@ describe("buildImportsMap", () => {
|
|
|
31
32
|
scopes: {}
|
|
32
33
|
}
|
|
33
34
|
];
|
|
34
|
-
const result =
|
|
35
|
+
const result = createImportsMap(
|
|
35
36
|
manifests,
|
|
36
37
|
(name, file) => `${name}/${file}`
|
|
37
38
|
);
|
|
@@ -55,7 +56,7 @@ describe("buildImportsMap", () => {
|
|
|
55
56
|
scopes: {}
|
|
56
57
|
}
|
|
57
58
|
];
|
|
58
|
-
const result =
|
|
59
|
+
const result = createImportsMap(
|
|
59
60
|
manifests,
|
|
60
61
|
(name, file) => `${name}/${file}`
|
|
61
62
|
);
|
|
@@ -84,7 +85,7 @@ describe("buildImportsMap", () => {
|
|
|
84
85
|
scopes: {}
|
|
85
86
|
}
|
|
86
87
|
];
|
|
87
|
-
const result =
|
|
88
|
+
const result = createImportsMap(
|
|
88
89
|
manifests,
|
|
89
90
|
(name, file) => `${name}/${file}`
|
|
90
91
|
);
|
|
@@ -100,7 +101,7 @@ describe("buildImportsMap", () => {
|
|
|
100
101
|
scopes: {}
|
|
101
102
|
}
|
|
102
103
|
];
|
|
103
|
-
const result =
|
|
104
|
+
const result = createImportsMap(
|
|
104
105
|
manifests,
|
|
105
106
|
(name, file) => `${name}/${file}`
|
|
106
107
|
);
|
|
@@ -121,7 +122,7 @@ describe("buildImportsMap", () => {
|
|
|
121
122
|
scopes: {}
|
|
122
123
|
}
|
|
123
124
|
];
|
|
124
|
-
const result =
|
|
125
|
+
const result = createImportsMap(
|
|
125
126
|
manifests,
|
|
126
127
|
(name, file) => `${name}/${file}`
|
|
127
128
|
);
|
|
@@ -157,7 +158,7 @@ describe("buildImportsMap", () => {
|
|
|
157
158
|
scopes: {}
|
|
158
159
|
}
|
|
159
160
|
];
|
|
160
|
-
const result =
|
|
161
|
+
const result = createImportsMap(
|
|
161
162
|
manifests,
|
|
162
163
|
(name, file) => `${name}/${file}`
|
|
163
164
|
);
|
|
@@ -181,7 +182,7 @@ describe("buildImportsMap", () => {
|
|
|
181
182
|
scopes: {}
|
|
182
183
|
}
|
|
183
184
|
];
|
|
184
|
-
const result =
|
|
185
|
+
const result = createImportsMap(
|
|
185
186
|
manifests,
|
|
186
187
|
(name, file) => `${name}/${file}`
|
|
187
188
|
);
|
|
@@ -191,7 +192,7 @@ describe("buildImportsMap", () => {
|
|
|
191
192
|
});
|
|
192
193
|
});
|
|
193
194
|
});
|
|
194
|
-
describe("
|
|
195
|
+
describe("fixImportMapNestedScopes", () => {
|
|
195
196
|
test("should return unchanged import map for empty scopes", () => {
|
|
196
197
|
const importMap = {
|
|
197
198
|
imports: {
|
|
@@ -199,7 +200,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
199
200
|
},
|
|
200
201
|
scopes: {}
|
|
201
202
|
};
|
|
202
|
-
const result =
|
|
203
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
203
204
|
assert.deepEqual(result, importMap);
|
|
204
205
|
});
|
|
205
206
|
test("should return unchanged import map for shallow scopes only", () => {
|
|
@@ -213,7 +214,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
216
|
};
|
|
216
|
-
const result =
|
|
217
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
217
218
|
assert.deepEqual(result, importMap);
|
|
218
219
|
});
|
|
219
220
|
test("should create file-level scopes for nested scopes", () => {
|
|
@@ -255,7 +256,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
255
256
|
}
|
|
256
257
|
}
|
|
257
258
|
};
|
|
258
|
-
const result =
|
|
259
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
259
260
|
assert.deepEqual(result, expected);
|
|
260
261
|
});
|
|
261
262
|
test("should handle multiple nested scopes correctly", () => {
|
|
@@ -305,7 +306,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
305
306
|
}
|
|
306
307
|
}
|
|
307
308
|
};
|
|
308
|
-
const result =
|
|
309
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
309
310
|
assert.deepEqual(result, expected);
|
|
310
311
|
});
|
|
311
312
|
test("should handle deeply nested scopes", () => {
|
|
@@ -334,7 +335,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
334
335
|
}
|
|
335
336
|
}
|
|
336
337
|
};
|
|
337
|
-
const result =
|
|
338
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
338
339
|
assert.deepEqual(result, expected);
|
|
339
340
|
});
|
|
340
341
|
test("should not create file-level scopes for imports not matching nested scope", () => {
|
|
@@ -358,7 +359,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
358
359
|
}
|
|
359
360
|
}
|
|
360
361
|
};
|
|
361
|
-
const result =
|
|
362
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
362
363
|
assert.deepEqual(result, expected);
|
|
363
364
|
});
|
|
364
365
|
test("should handle empty imports", () => {
|
|
@@ -374,7 +375,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
374
375
|
imports: {},
|
|
375
376
|
scopes: {}
|
|
376
377
|
};
|
|
377
|
-
const result =
|
|
378
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
378
379
|
assert.deepEqual(result, expected);
|
|
379
380
|
});
|
|
380
381
|
test("should preserve original import map structure", () => {
|
|
@@ -390,19 +391,17 @@ describe("fixNestedScopesResolution", () => {
|
|
|
390
391
|
}
|
|
391
392
|
}
|
|
392
393
|
};
|
|
393
|
-
const result =
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
{
|
|
402
|
-
vue: "/shared-modules/vue2.q9r8s7t6.final.mjs",
|
|
403
|
-
"vue-router": "/shared-modules/vue2/router.y1z0a9b8.final.mjs"
|
|
394
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
395
|
+
const expected = {
|
|
396
|
+
imports: importMap.imports,
|
|
397
|
+
scopes: {
|
|
398
|
+
"/shared-modules/vue2/component.u5v4w3x2.final.mjs": {
|
|
399
|
+
vue: "/shared-modules/vue2.q9r8s7t6.final.mjs",
|
|
400
|
+
"vue-router": "/shared-modules/vue2/router.y1z0a9b8.final.mjs"
|
|
401
|
+
}
|
|
404
402
|
}
|
|
405
|
-
|
|
403
|
+
};
|
|
404
|
+
assert.deepEqual(result, expected);
|
|
406
405
|
});
|
|
407
406
|
test("should handle complex priority scenarios with multiple nested levels", () => {
|
|
408
407
|
const importMap = {
|
|
@@ -454,7 +453,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
454
453
|
}
|
|
455
454
|
}
|
|
456
455
|
};
|
|
457
|
-
const result =
|
|
456
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
458
457
|
assert.deepEqual(result, expected);
|
|
459
458
|
});
|
|
460
459
|
test("should handle priority with overlapping nested scopes", () => {
|
|
@@ -500,7 +499,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
500
499
|
}
|
|
501
500
|
}
|
|
502
501
|
};
|
|
503
|
-
const result =
|
|
502
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
504
503
|
assert.deepEqual(result, expected);
|
|
505
504
|
});
|
|
506
505
|
test("should handle very deeply nested scope priority scenarios", () => {
|
|
@@ -552,7 +551,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
552
551
|
}
|
|
553
552
|
}
|
|
554
553
|
};
|
|
555
|
-
const result =
|
|
554
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
556
555
|
assert.deepEqual(result, expected);
|
|
557
556
|
});
|
|
558
557
|
test("should ensure different directory levels have distinct values for proper testing", () => {
|
|
@@ -586,7 +585,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
586
585
|
}
|
|
587
586
|
}
|
|
588
587
|
};
|
|
589
|
-
const result =
|
|
588
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
590
589
|
assert.deepEqual(result, expected);
|
|
591
590
|
assert.equal(
|
|
592
591
|
result.scopes["/shared-modules/level1/level2.e5f6g7h8.final.mjs"].vue,
|
|
@@ -608,11 +607,14 @@ describe("fixNestedScopesResolution", () => {
|
|
|
608
607
|
}
|
|
609
608
|
}
|
|
610
609
|
};
|
|
611
|
-
const result =
|
|
612
|
-
|
|
613
|
-
|
|
610
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
611
|
+
const expected = {
|
|
612
|
+
imports: importMap.imports,
|
|
613
|
+
scopes: {}
|
|
614
|
+
};
|
|
615
|
+
assert.deepEqual(result, expected);
|
|
614
616
|
assert.doesNotThrow(() => {
|
|
615
|
-
|
|
617
|
+
fixImportMapNestedScopes(importMap);
|
|
616
618
|
});
|
|
617
619
|
});
|
|
618
620
|
describe("scope path processing logic", () => {
|
|
@@ -651,7 +653,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
651
653
|
}
|
|
652
654
|
}
|
|
653
655
|
};
|
|
654
|
-
const result =
|
|
656
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
655
657
|
assert.deepEqual(result, expected);
|
|
656
658
|
});
|
|
657
659
|
test("should handle scope paths with any depth", () => {
|
|
@@ -671,7 +673,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
671
673
|
},
|
|
672
674
|
scopes: {}
|
|
673
675
|
};
|
|
674
|
-
const result =
|
|
676
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
675
677
|
assert.deepEqual(result, expected);
|
|
676
678
|
});
|
|
677
679
|
test("should handle very deep nested scope paths", () => {
|
|
@@ -691,7 +693,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
691
693
|
},
|
|
692
694
|
scopes: {}
|
|
693
695
|
};
|
|
694
|
-
const result =
|
|
696
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
695
697
|
assert.deepEqual(result, expected);
|
|
696
698
|
});
|
|
697
699
|
test("should create file-level scopes for all scope paths", () => {
|
|
@@ -723,7 +725,7 @@ describe("fixNestedScopesResolution", () => {
|
|
|
723
725
|
}
|
|
724
726
|
}
|
|
725
727
|
};
|
|
726
|
-
const result =
|
|
728
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
727
729
|
assert.deepEqual(result, expected);
|
|
728
730
|
});
|
|
729
731
|
test("should process multiple scope paths in correct order by depth", () => {
|
|
@@ -757,16 +759,16 @@ describe("fixNestedScopesResolution", () => {
|
|
|
757
759
|
}
|
|
758
760
|
}
|
|
759
761
|
};
|
|
760
|
-
const result =
|
|
762
|
+
const result = fixImportMapNestedScopes(importMap);
|
|
761
763
|
assert.deepEqual(result, expected);
|
|
762
764
|
});
|
|
763
765
|
});
|
|
764
766
|
});
|
|
765
|
-
describe("
|
|
767
|
+
describe("createScopesMap", () => {
|
|
766
768
|
test("should return empty object for empty manifests", () => {
|
|
767
769
|
const imports = {};
|
|
768
770
|
const manifests = [];
|
|
769
|
-
const result =
|
|
771
|
+
const result = createScopesMap(
|
|
770
772
|
imports,
|
|
771
773
|
manifests,
|
|
772
774
|
(name, scope) => `${name}/${scope}`
|
|
@@ -791,7 +793,7 @@ describe("buildScopesMap", () => {
|
|
|
791
793
|
scopes: {}
|
|
792
794
|
}
|
|
793
795
|
];
|
|
794
|
-
const result =
|
|
796
|
+
const result = createScopesMap(
|
|
795
797
|
imports,
|
|
796
798
|
manifests,
|
|
797
799
|
(name, scope) => `${name}/${scope}`
|
|
@@ -828,7 +830,7 @@ describe("buildScopesMap", () => {
|
|
|
828
830
|
}
|
|
829
831
|
}
|
|
830
832
|
];
|
|
831
|
-
const result =
|
|
833
|
+
const result = createScopesMap(
|
|
832
834
|
imports,
|
|
833
835
|
manifests,
|
|
834
836
|
(name, scope) => `${name}/${scope}`
|
|
@@ -863,7 +865,7 @@ describe("buildScopesMap", () => {
|
|
|
863
865
|
}
|
|
864
866
|
}
|
|
865
867
|
];
|
|
866
|
-
const result =
|
|
868
|
+
const result = createScopesMap(
|
|
867
869
|
imports,
|
|
868
870
|
manifests,
|
|
869
871
|
(name, scope) => `${name}/${scope}`
|
|
@@ -898,7 +900,7 @@ describe("buildScopesMap", () => {
|
|
|
898
900
|
}
|
|
899
901
|
}
|
|
900
902
|
];
|
|
901
|
-
const result =
|
|
903
|
+
const result = createScopesMap(
|
|
902
904
|
imports,
|
|
903
905
|
manifests,
|
|
904
906
|
(name, scope) => `${name}/${scope}`
|
|
@@ -939,7 +941,7 @@ describe("buildScopesMap", () => {
|
|
|
939
941
|
}
|
|
940
942
|
}
|
|
941
943
|
];
|
|
942
|
-
const result =
|
|
944
|
+
const result = createScopesMap(
|
|
943
945
|
imports,
|
|
944
946
|
manifests,
|
|
945
947
|
(name, scope) => `${name}/${scope}`
|
|
@@ -972,7 +974,7 @@ describe("buildScopesMap", () => {
|
|
|
972
974
|
}
|
|
973
975
|
}
|
|
974
976
|
];
|
|
975
|
-
const result =
|
|
977
|
+
const result = createScopesMap(
|
|
976
978
|
imports,
|
|
977
979
|
manifests,
|
|
978
980
|
(name, scope) => `${name}/${scope}`
|
|
@@ -1015,7 +1017,7 @@ describe("buildScopesMap", () => {
|
|
|
1015
1017
|
}
|
|
1016
1018
|
}
|
|
1017
1019
|
];
|
|
1018
|
-
const result =
|
|
1020
|
+
const result = createScopesMap(
|
|
1019
1021
|
imports,
|
|
1020
1022
|
manifests,
|
|
1021
1023
|
(name, scope) => `${name}/${scope}`
|
|
@@ -1068,7 +1070,7 @@ describe("buildScopesMap", () => {
|
|
|
1068
1070
|
}
|
|
1069
1071
|
}
|
|
1070
1072
|
];
|
|
1071
|
-
const result =
|
|
1073
|
+
const result = createScopesMap(
|
|
1072
1074
|
imports,
|
|
1073
1075
|
manifests,
|
|
1074
1076
|
(name, scope) => `${name}/${scope}`
|
|
@@ -1102,7 +1104,7 @@ describe("buildScopesMap", () => {
|
|
|
1102
1104
|
}
|
|
1103
1105
|
}
|
|
1104
1106
|
];
|
|
1105
|
-
const result =
|
|
1107
|
+
const result = createScopesMap(
|
|
1106
1108
|
imports,
|
|
1107
1109
|
manifests,
|
|
1108
1110
|
(name, scope) => `${name}/${scope}`
|
|
@@ -1129,7 +1131,7 @@ describe("buildScopesMap", () => {
|
|
|
1129
1131
|
scopes: void 0
|
|
1130
1132
|
}
|
|
1131
1133
|
];
|
|
1132
|
-
const result =
|
|
1134
|
+
const result = createScopesMap(
|
|
1133
1135
|
imports,
|
|
1134
1136
|
manifests,
|
|
1135
1137
|
(name, scope) => `${name}/${scope}`
|
|
@@ -1137,14 +1139,14 @@ describe("buildScopesMap", () => {
|
|
|
1137
1139
|
assert.deepEqual(result, {});
|
|
1138
1140
|
});
|
|
1139
1141
|
});
|
|
1140
|
-
describe("
|
|
1142
|
+
describe("createImportMap", () => {
|
|
1141
1143
|
test("should return empty import map for empty manifests", () => {
|
|
1142
1144
|
const options = {
|
|
1143
1145
|
manifests: [],
|
|
1144
1146
|
getFile: (name, file) => `${name}/${file}`,
|
|
1145
1147
|
getScope: (name, scope) => `${name}/${scope}`
|
|
1146
1148
|
};
|
|
1147
|
-
const result =
|
|
1149
|
+
const result = createImportMap(options);
|
|
1148
1150
|
assert.deepEqual(result, {
|
|
1149
1151
|
imports: {},
|
|
1150
1152
|
scopes: {}
|
|
@@ -1180,7 +1182,7 @@ describe("getImportMap", () => {
|
|
|
1180
1182
|
getFile: (name, file) => `${name}/${file}`,
|
|
1181
1183
|
getScope: (name, scope) => `${name}/${scope}`
|
|
1182
1184
|
};
|
|
1183
|
-
const result =
|
|
1185
|
+
const result = createImportMap(options);
|
|
1184
1186
|
assert.deepEqual(result, {
|
|
1185
1187
|
imports: {
|
|
1186
1188
|
"test-module/component": "test-module/component.js",
|
|
@@ -1233,7 +1235,7 @@ describe("getImportMap", () => {
|
|
|
1233
1235
|
getFile: (name, file) => `${name}/${file}`,
|
|
1234
1236
|
getScope: (name, scope) => `${name}/${scope}`
|
|
1235
1237
|
};
|
|
1236
|
-
const result =
|
|
1238
|
+
const result = createImportMap(options);
|
|
1237
1239
|
assert.deepEqual(result, {
|
|
1238
1240
|
imports: {
|
|
1239
1241
|
"module-a/utils": "module-a/utils.js",
|
|
@@ -1268,7 +1270,7 @@ describe("getImportMap", () => {
|
|
|
1268
1270
|
getFile: (name, file) => `${name}/${file}`,
|
|
1269
1271
|
getScope: (name, scope) => `${name}/${scope}`
|
|
1270
1272
|
};
|
|
1271
|
-
const result =
|
|
1273
|
+
const result = createImportMap(options);
|
|
1272
1274
|
assert.deepEqual(result, {
|
|
1273
1275
|
imports: {
|
|
1274
1276
|
"test-module/component": "test-module/component.js"
|
|
@@ -1292,7 +1294,7 @@ describe("getImportMap", () => {
|
|
|
1292
1294
|
getFile: (name, file) => `${name}/${file}`,
|
|
1293
1295
|
getScope: (name, scope) => `${name}/${scope}`
|
|
1294
1296
|
};
|
|
1295
|
-
const result =
|
|
1297
|
+
const result = createImportMap(options);
|
|
1296
1298
|
assert.deepEqual(result, {
|
|
1297
1299
|
imports: {},
|
|
1298
1300
|
scopes: {
|
|
@@ -1325,7 +1327,7 @@ describe("getImportMap", () => {
|
|
|
1325
1327
|
getFile: (name, file) => `/custom/path/${name}/${file}`,
|
|
1326
1328
|
getScope: (name, scope) => `custom-scope-${name}-${scope}`
|
|
1327
1329
|
};
|
|
1328
|
-
const result =
|
|
1330
|
+
const result = createImportMap(options);
|
|
1329
1331
|
assert.deepEqual(result, {
|
|
1330
1332
|
imports: {
|
|
1331
1333
|
"test-module/component": "/custom/path/test-module/component.js"
|
|
@@ -1356,7 +1358,7 @@ describe("getImportMap", () => {
|
|
|
1356
1358
|
getFile: (name, file) => `${name}/${file}`,
|
|
1357
1359
|
getScope: (name, scope) => `${name}/${scope}`
|
|
1358
1360
|
};
|
|
1359
|
-
const result =
|
|
1361
|
+
const result = createImportMap(options);
|
|
1360
1362
|
assert.deepEqual(result, {
|
|
1361
1363
|
imports: {
|
|
1362
1364
|
"test-module/component": "test-module/component.js"
|
|
@@ -1388,7 +1390,7 @@ describe("getImportMap", () => {
|
|
|
1388
1390
|
getFile: (name, file) => `${name}/${file}`,
|
|
1389
1391
|
getScope: (name, scope) => `${name}/${scope}`
|
|
1390
1392
|
};
|
|
1391
|
-
const result =
|
|
1393
|
+
const result = createImportMap(options);
|
|
1392
1394
|
assert.deepEqual(result, {
|
|
1393
1395
|
imports: {
|
|
1394
1396
|
"test-module/component": "test-module/component.js"
|
|
@@ -1424,7 +1426,7 @@ describe("getImportMap", () => {
|
|
|
1424
1426
|
getFile: (name, file) => `${name}/${file}`,
|
|
1425
1427
|
getScope: (name, scope) => `${name}/${scope}`
|
|
1426
1428
|
};
|
|
1427
|
-
const result =
|
|
1429
|
+
const result = createImportMap(options);
|
|
1428
1430
|
assert.deepEqual(result, {
|
|
1429
1431
|
imports: {
|
|
1430
1432
|
"test-module/src/index": "test-module/src/index.js",
|
|
@@ -1438,3 +1440,147 @@ describe("getImportMap", () => {
|
|
|
1438
1440
|
});
|
|
1439
1441
|
});
|
|
1440
1442
|
});
|
|
1443
|
+
describe("compressImportMap", () => {
|
|
1444
|
+
test("does not promote when no global exists; keeps scopes intact", () => {
|
|
1445
|
+
const importMap = {
|
|
1446
|
+
imports: {},
|
|
1447
|
+
scopes: {
|
|
1448
|
+
"/a/": {
|
|
1449
|
+
vue: "/a/vue.final.mjs"
|
|
1450
|
+
},
|
|
1451
|
+
"/b/": {
|
|
1452
|
+
vue: "/a/vue.final.mjs"
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
};
|
|
1456
|
+
const result = compressImportMap(importMap);
|
|
1457
|
+
assert.deepEqual(result, {
|
|
1458
|
+
imports: { vue: "/a/vue.final.mjs" }
|
|
1459
|
+
});
|
|
1460
|
+
});
|
|
1461
|
+
test("does not promote when scoped mappings conflict across scopes", () => {
|
|
1462
|
+
const importMap = {
|
|
1463
|
+
imports: {},
|
|
1464
|
+
scopes: {
|
|
1465
|
+
"/a/": { vue: "/a/vue.final.mjs" },
|
|
1466
|
+
"/b/": { vue: "/b/vue.final.mjs" }
|
|
1467
|
+
}
|
|
1468
|
+
};
|
|
1469
|
+
const result = compressImportMap(importMap);
|
|
1470
|
+
assert.deepEqual(result, importMap);
|
|
1471
|
+
});
|
|
1472
|
+
test("removes scoped entries that equal global mapping", () => {
|
|
1473
|
+
const importMap = {
|
|
1474
|
+
imports: { vue: "/shared/vue.final.mjs" },
|
|
1475
|
+
scopes: {
|
|
1476
|
+
"/a/": {
|
|
1477
|
+
vue: "/shared/vue.final.mjs",
|
|
1478
|
+
lodash: "/a/lodash.final.mjs"
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
const result = compressImportMap(importMap);
|
|
1483
|
+
const expected = {
|
|
1484
|
+
imports: {
|
|
1485
|
+
vue: "/shared/vue.final.mjs",
|
|
1486
|
+
lodash: "/a/lodash.final.mjs"
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
assert.deepEqual(result, expected);
|
|
1490
|
+
});
|
|
1491
|
+
test("promotes to global when global matches single unique target across scopes", () => {
|
|
1492
|
+
const importMap = {
|
|
1493
|
+
imports: { vue: "/shared/vue.final.mjs" },
|
|
1494
|
+
scopes: {
|
|
1495
|
+
"/a/": { vue: "/shared/vue.final.mjs" },
|
|
1496
|
+
"/b/": { vue: "/shared/vue.final.mjs" }
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
const result = compressImportMap(importMap);
|
|
1500
|
+
assert.deepEqual(result, {
|
|
1501
|
+
imports: { vue: "/shared/vue.final.mjs" }
|
|
1502
|
+
});
|
|
1503
|
+
});
|
|
1504
|
+
test("promotes to global when no global exists and targets are consistent across scopes (promote mode)", () => {
|
|
1505
|
+
const importMap = {
|
|
1506
|
+
imports: {},
|
|
1507
|
+
scopes: {
|
|
1508
|
+
"/a/": { vue: "/x/vue.final.mjs" },
|
|
1509
|
+
"/b/": { vue: "/x/vue.final.mjs" }
|
|
1510
|
+
}
|
|
1511
|
+
};
|
|
1512
|
+
const result = compressImportMap(importMap);
|
|
1513
|
+
assert.deepEqual(result, {
|
|
1514
|
+
imports: { vue: "/x/vue.final.mjs" }
|
|
1515
|
+
});
|
|
1516
|
+
});
|
|
1517
|
+
test("promotes dominant target and keeps exceptions in scopes (promote mode)", () => {
|
|
1518
|
+
const importMap = {
|
|
1519
|
+
imports: {},
|
|
1520
|
+
scopes: {
|
|
1521
|
+
"/a/": { vue: "/x/vue.final.mjs" },
|
|
1522
|
+
"/b/": { vue: "/x/vue.final.mjs" },
|
|
1523
|
+
"/c/": { vue: "/y/vue2.final.mjs" }
|
|
1524
|
+
}
|
|
1525
|
+
};
|
|
1526
|
+
const result = compressImportMap(importMap);
|
|
1527
|
+
assert.deepEqual(result, {
|
|
1528
|
+
imports: { vue: "/x/vue.final.mjs" },
|
|
1529
|
+
scopes: {
|
|
1530
|
+
"/c/": { vue: "/y/vue2.final.mjs" }
|
|
1531
|
+
}
|
|
1532
|
+
});
|
|
1533
|
+
});
|
|
1534
|
+
test("does not promote when no global exists; keeps scopes intact", () => {
|
|
1535
|
+
const importMap = {
|
|
1536
|
+
imports: {},
|
|
1537
|
+
scopes: {
|
|
1538
|
+
"/a/": { vue: "/shared/vue.final.mjs" },
|
|
1539
|
+
"/b/": { vue: "/shared/vue.final.mjs" },
|
|
1540
|
+
"/c/": { vue: "/c/vue2.final.mjs" }
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
const result = compressImportMap(importMap);
|
|
1544
|
+
assert.deepEqual(result, {
|
|
1545
|
+
imports: { vue: "/shared/vue.final.mjs" },
|
|
1546
|
+
scopes: { "/c/": { vue: "/c/vue2.final.mjs" } }
|
|
1547
|
+
});
|
|
1548
|
+
});
|
|
1549
|
+
test("aggressive default does not override different existing global", () => {
|
|
1550
|
+
const importMap = {
|
|
1551
|
+
imports: { vue: "/global/vue.final.mjs" },
|
|
1552
|
+
scopes: {
|
|
1553
|
+
"/a/": { vue: "/shared/vue.final.mjs" },
|
|
1554
|
+
"/b/": { vue: "/shared/vue.final.mjs" }
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
const result = compressImportMap(importMap);
|
|
1558
|
+
assert.deepEqual(result, {
|
|
1559
|
+
imports: { vue: "/global/vue.final.mjs" },
|
|
1560
|
+
scopes: {
|
|
1561
|
+
"/a/": { vue: "/shared/vue.final.mjs" },
|
|
1562
|
+
"/b/": { vue: "/shared/vue.final.mjs" }
|
|
1563
|
+
}
|
|
1564
|
+
});
|
|
1565
|
+
});
|
|
1566
|
+
test("returns new object and keeps input unchanged", () => {
|
|
1567
|
+
const original = {
|
|
1568
|
+
imports: {},
|
|
1569
|
+
scopes: {
|
|
1570
|
+
"/a/": { vue: "/x/vue.final.mjs" },
|
|
1571
|
+
"/b/": { vue: "/x/vue.final.mjs" },
|
|
1572
|
+
"/c/": { vue: "/y/vue2.final.mjs" }
|
|
1573
|
+
}
|
|
1574
|
+
};
|
|
1575
|
+
const importMap = JSON.parse(JSON.stringify(original));
|
|
1576
|
+
const result = compressImportMap(importMap);
|
|
1577
|
+
assert.notStrictEqual(result, importMap);
|
|
1578
|
+
assert.notStrictEqual(result.imports, importMap.imports);
|
|
1579
|
+
assert.notStrictEqual(result.scopes, importMap.scopes);
|
|
1580
|
+
assert.deepEqual(importMap, original);
|
|
1581
|
+
assert.deepEqual(result, {
|
|
1582
|
+
imports: { vue: "/x/vue.final.mjs" },
|
|
1583
|
+
scopes: { "/c/": { vue: "/y/vue2.final.mjs" } }
|
|
1584
|
+
});
|
|
1585
|
+
});
|
|
1586
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esmx/core",
|
|
3
|
-
"description": "A high-performance microfrontend framework supporting Vue, React, Preact, Solid, and Svelte with SSR and Module
|
|
3
|
+
"description": "A high-performance microfrontend framework supporting Vue, React, Preact, Solid, and Svelte with SSR and Module Linking capabilities.",
|
|
4
4
|
"contributors": [
|
|
5
5
|
{
|
|
6
6
|
"name": "lzxb",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"Microfrontend",
|
|
40
40
|
"SSR",
|
|
41
41
|
"Rspack",
|
|
42
|
-
"Module
|
|
42
|
+
"Module Linking",
|
|
43
43
|
"High Performance",
|
|
44
44
|
"TypeScript"
|
|
45
45
|
],
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"build": "unbuild"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@esmx/import": "3.0.0-rc.
|
|
62
|
+
"@esmx/import": "3.0.0-rc.71",
|
|
63
63
|
"@types/serialize-javascript": "^5.0.4",
|
|
64
64
|
"es-module-lexer": "^1.7.0",
|
|
65
65
|
"find": "^0.3.0",
|
|
@@ -69,15 +69,15 @@
|
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@biomejs/biome": "1.9.4",
|
|
71
71
|
"@types/find": "^0.2.4",
|
|
72
|
-
"@types/node": "^24.
|
|
73
|
-
"@types/send": "^
|
|
72
|
+
"@types/node": "^24.10.0",
|
|
73
|
+
"@types/send": "^1.2.1",
|
|
74
74
|
"@types/write": "^2.0.4",
|
|
75
75
|
"@vitest/coverage-v8": "3.2.4",
|
|
76
|
-
"typescript": "5.9.
|
|
77
|
-
"unbuild": "3.6.
|
|
76
|
+
"typescript": "5.9.3",
|
|
77
|
+
"unbuild": "3.6.1",
|
|
78
78
|
"vitest": "3.2.4"
|
|
79
79
|
},
|
|
80
|
-
"version": "3.0.0-rc.
|
|
80
|
+
"version": "3.0.0-rc.71",
|
|
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": "
|
|
103
|
+
"gitHead": "1616c7a1f820387d4d14bac0babd42356f6f7f33"
|
|
104
104
|
}
|
package/src/cli/cli.ts
CHANGED
|
@@ -13,13 +13,19 @@ async function getSrcOptions(): Promise<EsmxOptions> {
|
|
|
13
13
|
|
|
14
14
|
async function getDistOptions(): Promise<EsmxOptions> {
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
resolveImportPath(process.cwd(), './dist/
|
|
18
|
-
)
|
|
16
|
+
const m = await import(
|
|
17
|
+
resolveImportPath(process.cwd(), './dist/node/src/entry.node.mjs')
|
|
18
|
+
);
|
|
19
|
+
return m.default;
|
|
19
20
|
} catch (e) {
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
console.error(
|
|
22
|
+
styleText(
|
|
23
|
+
'red',
|
|
24
|
+
'Failed to load dist entry: dist/node/src/entry.node.mjs'
|
|
25
|
+
)
|
|
22
26
|
);
|
|
27
|
+
console.error(styleText('yellow', 'Run `esmx build` and try again.'));
|
|
28
|
+
process.exit(17);
|
|
23
29
|
}
|
|
24
30
|
}
|
|
25
31
|
|