@esmx/core 3.0.0-rc.59 → 3.0.0-rc.60

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.
@@ -1,135 +1,1171 @@
1
- import { assert, expect, test } from "vitest";
2
- import { getImportMap } from "./import-map.mjs";
3
- test("should return empty import map when no manifests provided", async () => {
4
- assert.deepEqual(
5
- getImportMap({
6
- manifests: [],
7
- getScope(name) {
8
- return `/${name}/`;
9
- },
10
- getFile(name, file) {
11
- return `${name}/${file}`;
12
- }
13
- }),
14
- {
15
- imports: {},
16
- scopes: {}
17
- }
18
- );
19
- });
20
- test("should generate import map with remote exports and module scopes", async () => {
21
- const result = getImportMap({
22
- manifests: [
1
+ import { assert, describe, test } from "vitest";
2
+ import { buildImportsMap, buildScopesMap, getImportMap } from "./import-map.mjs";
3
+ describe("buildImportsMap", () => {
4
+ test("should return empty object for empty manifests", () => {
5
+ const result = buildImportsMap([], (name, file) => `${name}/${file}`);
6
+ assert.deepEqual(result, {});
7
+ });
8
+ test("should process all exports including package exports", () => {
9
+ const manifests = [
23
10
  {
24
- name: "ssr-vue2-remote",
11
+ name: "test-module",
25
12
  imports: {},
26
13
  exports: {
27
- "src/entry.server": {
28
- name: "src/entry.server",
29
- rewrite: true,
30
- file: "src/entry.server.mjs",
31
- identifier: "ssr-vue2-remote/src/entry.server"
14
+ component: {
15
+ name: "component",
16
+ pkg: false,
17
+ file: "component.js",
18
+ identifier: "test-module/component"
32
19
  },
33
20
  vue: {
34
21
  name: "vue",
35
- rewrite: false,
36
- file: "vue.mjs",
37
- identifier: "ssr-vue2-remote/vue"
22
+ pkg: true,
23
+ file: "vue.js",
24
+ identifier: "test-module/vue"
25
+ }
26
+ },
27
+ scopes: {}
28
+ }
29
+ ];
30
+ const result = buildImportsMap(
31
+ manifests,
32
+ (name, file) => `${name}/${file}`
33
+ );
34
+ assert.deepEqual(result, {
35
+ "test-module/component": "test-module/component.js",
36
+ "test-module/vue": "test-module/vue.js"
37
+ });
38
+ });
39
+ test("should handle user imports with existing identifiers", () => {
40
+ const manifests = [
41
+ {
42
+ name: "test-module",
43
+ imports: {
44
+ "custom-name": "test-module/component"
45
+ },
46
+ exports: {
47
+ component: {
48
+ name: "component",
49
+ pkg: false,
50
+ file: "component.js",
51
+ identifier: "test-module/component"
52
+ }
53
+ },
54
+ scopes: {}
55
+ }
56
+ ];
57
+ const result = buildImportsMap(
58
+ manifests,
59
+ (name, file) => `${name}/${file}`
60
+ );
61
+ assert.deepEqual(result, {
62
+ "test-module/component": "test-module/component.js",
63
+ "test-module/custom-name": "test-module/component.js"
64
+ });
65
+ });
66
+ test("should handle user imports with non existing identifiers", () => {
67
+ const manifests = [
68
+ {
69
+ name: "test-module",
70
+ imports: {
71
+ external: "https://cdn.com/lib.js"
72
+ },
73
+ exports: {
74
+ component: {
75
+ name: "component",
76
+ pkg: false,
77
+ file: "component.js",
78
+ identifier: "test-module/component"
79
+ }
80
+ },
81
+ scopes: {}
82
+ }
83
+ ];
84
+ const result = buildImportsMap(
85
+ manifests,
86
+ (name, file) => `${name}/${file}`
87
+ );
88
+ assert.deepEqual(result, {
89
+ "test-module/component": "test-module/component.js",
90
+ "test-module/external": "https://cdn.com/lib.js"
91
+ });
92
+ });
93
+ test("should create aliases for index suffixes", () => {
94
+ const manifests = [
95
+ {
96
+ name: "test-module",
97
+ imports: {},
98
+ exports: {
99
+ "src/index": {
100
+ name: "src/index",
101
+ pkg: false,
102
+ file: "src/index.js",
103
+ identifier: "test-module/src/index"
104
+ }
105
+ },
106
+ scopes: {}
107
+ }
108
+ ];
109
+ const result = buildImportsMap(
110
+ manifests,
111
+ (name, file) => `${name}/${file}`
112
+ );
113
+ assert.deepEqual(result, {
114
+ "test-module/src/index": "test-module/src/index.js",
115
+ "test-module/src": "test-module/src/index.js"
116
+ });
117
+ });
118
+ test("should handle multiple manifests", () => {
119
+ const manifests = [
120
+ {
121
+ name: "module-a",
122
+ imports: {},
123
+ exports: {
124
+ utils: {
125
+ name: "utils",
126
+ pkg: false,
127
+ file: "utils.js",
128
+ identifier: "module-a/utils"
129
+ }
130
+ },
131
+ scopes: {}
132
+ },
133
+ {
134
+ name: "module-b",
135
+ imports: {
136
+ shared: "module-a/utils"
137
+ },
138
+ exports: {},
139
+ scopes: {}
140
+ }
141
+ ];
142
+ const result = buildImportsMap(
143
+ manifests,
144
+ (name, file) => `${name}/${file}`
145
+ );
146
+ assert.deepEqual(result, {
147
+ "module-a/utils": "module-a/utils.js",
148
+ "module-b/shared": "module-a/utils.js"
149
+ });
150
+ });
151
+ test("should prioritize user imports", () => {
152
+ const manifests = [
153
+ {
154
+ name: "test-module",
155
+ imports: {
156
+ react: "preact",
157
+ vue: "./custom/vue.js"
158
+ },
159
+ exports: {
160
+ react: {
161
+ name: "react",
162
+ pkg: false,
163
+ file: "react.js",
164
+ identifier: "test-module/react"
38
165
  },
166
+ vue: {
167
+ name: "vue",
168
+ pkg: false,
169
+ file: "vue.js",
170
+ identifier: "test-module/vue"
171
+ }
172
+ },
173
+ scopes: {}
174
+ }
175
+ ];
176
+ const result = buildImportsMap(
177
+ manifests,
178
+ (name, file) => `${name}/${file}`
179
+ );
180
+ assert.deepEqual(result, {
181
+ "test-module/react": "preact",
182
+ "test-module/vue": "./custom/vue.js"
183
+ });
184
+ });
185
+ test("should handle mixed user import types", () => {
186
+ const manifests = [
187
+ {
188
+ name: "test-module",
189
+ imports: {
190
+ "url-import": "https://example.com/lib.js",
191
+ "relative-import": "./local/file.js",
192
+ "identifier-import": "test-module/component"
193
+ },
194
+ exports: {
195
+ component: {
196
+ name: "component",
197
+ pkg: false,
198
+ file: "component.js",
199
+ identifier: "test-module/component"
200
+ }
201
+ },
202
+ scopes: {}
203
+ }
204
+ ];
205
+ const result = buildImportsMap(
206
+ manifests,
207
+ (name, file) => `${name}/${file}`
208
+ );
209
+ assert.deepEqual(result, {
210
+ "test-module/component": "test-module/component.js",
211
+ "test-module/url-import": "https://example.com/lib.js",
212
+ "test-module/relative-import": "./local/file.js",
213
+ "test-module/identifier-import": "test-module/component.js"
214
+ });
215
+ });
216
+ test("should handle empty exports", () => {
217
+ const manifests = [
218
+ {
219
+ name: "test-module",
220
+ imports: {
221
+ external: "https://cdn.com/lib.js"
222
+ },
223
+ exports: {},
224
+ scopes: {}
225
+ }
226
+ ];
227
+ const result = buildImportsMap(
228
+ manifests,
229
+ (name, file) => `${name}/${file}`
230
+ );
231
+ assert.deepEqual(result, {
232
+ "test-module/external": "https://cdn.com/lib.js"
233
+ });
234
+ });
235
+ test("should handle empty imports", () => {
236
+ const manifests = [
237
+ {
238
+ name: "test-module",
239
+ imports: {},
240
+ exports: {
241
+ component: {
242
+ name: "component",
243
+ pkg: false,
244
+ file: "component.js",
245
+ identifier: "test-module/component"
246
+ }
247
+ },
248
+ scopes: {}
249
+ }
250
+ ];
251
+ const result = buildImportsMap(
252
+ manifests,
253
+ (name, file) => `${name}/${file}`
254
+ );
255
+ assert.deepEqual(result, {
256
+ "test-module/component": "test-module/component.js"
257
+ });
258
+ });
259
+ test("should handle duplicate alias creation", () => {
260
+ const manifests = [
261
+ {
262
+ name: "test-module",
263
+ imports: {},
264
+ exports: {
39
265
  "src/components/index": {
40
266
  name: "src/components/index",
41
- rewrite: true,
42
- file: "src/components/index.mjs",
43
- identifier: "ssr-vue2-remote/src/components/index"
267
+ pkg: false,
268
+ file: "src/components/index.js",
269
+ identifier: "test-module/src/components/index"
44
270
  }
45
- }
271
+ },
272
+ scopes: {}
273
+ }
274
+ ];
275
+ const result = buildImportsMap(
276
+ manifests,
277
+ (name, file) => `${name}/${file}`
278
+ );
279
+ assert.deepEqual(result, {
280
+ "test-module/src/components/index": "test-module/src/components/index.js",
281
+ "test-module/src/components": "test-module/src/components/index.js"
282
+ });
283
+ });
284
+ test("should handle cross-module references", () => {
285
+ const manifests = [
286
+ {
287
+ name: "module-a",
288
+ imports: {},
289
+ exports: {
290
+ utils: {
291
+ name: "utils",
292
+ pkg: false,
293
+ file: "utils.js",
294
+ identifier: "module-a/utils"
295
+ }
296
+ },
297
+ scopes: {}
46
298
  },
47
299
  {
48
- name: "ssr-vue2-host",
300
+ name: "module-b",
49
301
  imports: {
50
- vue: "ssr-vue2-remote/vue"
51
- },
52
- exports: {}
53
- }
54
- ],
55
- getScope(name) {
56
- return `/${name}/`;
57
- },
58
- getFile(name, file) {
59
- return `${name}/${file}`;
60
- }
61
- });
62
- assert.deepEqual(result, {
63
- imports: {
64
- "ssr-vue2-remote/src/entry.server": "ssr-vue2-remote/src/entry.server.mjs",
65
- "ssr-vue2-remote/vue": "ssr-vue2-remote/vue.mjs",
66
- "ssr-vue2-remote/src/components/index": "ssr-vue2-remote/src/components/index.mjs",
67
- "ssr-vue2-remote/src/components": "ssr-vue2-remote/src/components/index.mjs"
68
- },
69
- scopes: {
70
- "/ssr-vue2-host/": {
71
- vue: "ssr-vue2-remote/vue.mjs"
302
+ shared: "module-a/utils"
303
+ },
304
+ exports: {},
305
+ scopes: {}
306
+ }
307
+ ];
308
+ const result = buildImportsMap(
309
+ manifests,
310
+ (name, file) => `${name}/${file}`
311
+ );
312
+ assert.deepEqual(result, {
313
+ "module-a/utils": "module-a/utils.js",
314
+ "module-b/shared": "module-a/utils.js"
315
+ });
316
+ });
317
+ test("should handle cross-module non-existent references", () => {
318
+ const manifests = [
319
+ {
320
+ name: "module-a",
321
+ imports: {},
322
+ exports: {
323
+ utils: {
324
+ name: "utils",
325
+ pkg: false,
326
+ file: "utils.js",
327
+ identifier: "module-a/utils"
328
+ }
329
+ },
330
+ scopes: {}
72
331
  },
73
- "/ssr-vue2-remote/": { vue: "ssr-vue2-remote/vue.mjs" }
74
- }
332
+ {
333
+ name: "module-b",
334
+ imports: {
335
+ external: "module-a/non-existent"
336
+ },
337
+ exports: {},
338
+ scopes: {}
339
+ }
340
+ ];
341
+ const result = buildImportsMap(
342
+ manifests,
343
+ (name, file) => `${name}/${file}`
344
+ );
345
+ assert.deepEqual(result, {
346
+ "module-a/utils": "module-a/utils.js",
347
+ "module-b/external": "module-a/non-existent"
348
+ });
349
+ });
350
+ test("should handle identifier conflicts across modules", () => {
351
+ const manifests = [
352
+ {
353
+ name: "module-a",
354
+ imports: {},
355
+ exports: {
356
+ utils: {
357
+ name: "utils",
358
+ pkg: false,
359
+ file: "utils-a.js",
360
+ identifier: "module-a/utils"
361
+ }
362
+ },
363
+ scopes: {}
364
+ },
365
+ {
366
+ name: "module-b",
367
+ imports: {},
368
+ exports: {
369
+ utils: {
370
+ name: "utils",
371
+ pkg: false,
372
+ file: "utils-b.js",
373
+ identifier: "module-b/utils"
374
+ }
375
+ },
376
+ scopes: {}
377
+ }
378
+ ];
379
+ const result = buildImportsMap(
380
+ manifests,
381
+ (name, file) => `${name}/${file}`
382
+ );
383
+ assert.deepEqual(result, {
384
+ "module-a/utils": "module-a/utils-a.js",
385
+ "module-b/utils": "module-b/utils-b.js"
386
+ });
387
+ });
388
+ test("should handle user imports referencing aliased identifiers", () => {
389
+ const manifests = [
390
+ {
391
+ name: "test-module",
392
+ imports: {
393
+ "alias-test": "test-module/src/index"
394
+ },
395
+ exports: {
396
+ "src/index": {
397
+ name: "src/index",
398
+ pkg: false,
399
+ file: "src/index.js",
400
+ identifier: "test-module/src/index"
401
+ }
402
+ },
403
+ scopes: {}
404
+ }
405
+ ];
406
+ const result = buildImportsMap(
407
+ manifests,
408
+ (name, file) => `${name}/${file}`
409
+ );
410
+ assert.deepEqual(result, {
411
+ "test-module/src/index": "test-module/src/index.js",
412
+ "test-module/src": "test-module/src/index.js",
413
+ "test-module/alias-test": "test-module/src/index.js"
414
+ });
415
+ });
416
+ test("should handle nested index aliases", () => {
417
+ const manifests = [
418
+ {
419
+ name: "test-module",
420
+ imports: {},
421
+ exports: {
422
+ "src/components/utils/index": {
423
+ name: "src/components/utils/index",
424
+ pkg: false,
425
+ file: "src/components/utils/index.js",
426
+ identifier: "test-module/src/components/utils/index"
427
+ }
428
+ },
429
+ scopes: {}
430
+ }
431
+ ];
432
+ const result = buildImportsMap(
433
+ manifests,
434
+ (name, file) => `${name}/${file}`
435
+ );
436
+ assert.deepEqual(result, {
437
+ "test-module/src/components/utils/index": "test-module/src/components/utils/index.js",
438
+ "test-module/src/components/utils": "test-module/src/components/utils/index.js"
439
+ });
75
440
  });
76
441
  });
77
- test("should generate import map with remote exports and module scopes", async () => {
78
- const result = getImportMap({
79
- manifests: [
442
+ describe("buildScopesMap", () => {
443
+ test("should return empty object for empty manifests", () => {
444
+ const imports = {};
445
+ const manifests = [];
446
+ const result = buildScopesMap(
447
+ imports,
448
+ manifests,
449
+ (name, scope) => `${name}/${scope}`
450
+ );
451
+ assert.deepEqual(result, {});
452
+ });
453
+ test("should return empty object when manifests have no scopes", () => {
454
+ const imports = {
455
+ "test-module/component": "test-module/component.js"
456
+ };
457
+ const manifests = [
80
458
  {
81
- name: "ssr-vue2-remote",
459
+ name: "test-module",
82
460
  imports: {},
83
461
  exports: {
84
- vue: {
85
- name: "vue",
86
- rewrite: false,
87
- file: "vue.mjs",
88
- identifier: "ssr-vue2-remote/vue"
462
+ component: {
463
+ name: "component",
464
+ pkg: false,
465
+ file: "component.js",
466
+ identifier: "test-module/component"
467
+ }
468
+ },
469
+ scopes: {}
470
+ }
471
+ ];
472
+ const result = buildScopesMap(
473
+ imports,
474
+ manifests,
475
+ (name, scope) => `${name}/${scope}`
476
+ );
477
+ assert.deepEqual(result, {});
478
+ });
479
+ test("should build scopes map with basic scope configuration", () => {
480
+ const imports = {
481
+ "test-module/component": "test-module/component.js",
482
+ "test-module/utils": "test-module/utils.js"
483
+ };
484
+ const manifests = [
485
+ {
486
+ name: "test-module",
487
+ imports: {},
488
+ exports: {
489
+ component: {
490
+ name: "component",
491
+ pkg: false,
492
+ file: "component.js",
493
+ identifier: "test-module/component"
494
+ },
495
+ utils: {
496
+ name: "utils",
497
+ pkg: false,
498
+ file: "utils.js",
499
+ identifier: "test-module/utils"
500
+ }
501
+ },
502
+ scopes: {
503
+ node_modules: {
504
+ react: "test-module/component",
505
+ lodash: "test-module/utils"
89
506
  }
90
507
  }
508
+ }
509
+ ];
510
+ const result = buildScopesMap(
511
+ imports,
512
+ manifests,
513
+ (name, scope) => `${name}/${scope}`
514
+ );
515
+ assert.deepEqual(result, {
516
+ "test-module//node_modules": {
517
+ react: "test-module/component.js",
518
+ lodash: "test-module/utils.js"
519
+ }
520
+ });
521
+ });
522
+ test("should handle scope with non-existent identifiers", () => {
523
+ const imports = {
524
+ "test-module/component": "test-module/component.js"
525
+ };
526
+ const manifests = [
527
+ {
528
+ name: "test-module",
529
+ imports: {},
530
+ exports: {
531
+ component: {
532
+ name: "component",
533
+ pkg: false,
534
+ file: "component.js",
535
+ identifier: "test-module/component"
536
+ }
537
+ },
538
+ scopes: {
539
+ node_modules: {
540
+ react: "test-module/component",
541
+ "non-existent": "test-module/non-existent"
542
+ }
543
+ }
544
+ }
545
+ ];
546
+ const result = buildScopesMap(
547
+ imports,
548
+ manifests,
549
+ (name, scope) => `${name}/${scope}`
550
+ );
551
+ assert.deepEqual(result, {
552
+ "test-module//node_modules": {
553
+ react: "test-module/component.js",
554
+ "non-existent": "test-module/non-existent"
555
+ }
556
+ });
557
+ });
558
+ test("should handle scope with external URLs", () => {
559
+ const imports = {
560
+ "test-module/component": "test-module/component.js"
561
+ };
562
+ const manifests = [
563
+ {
564
+ name: "test-module",
565
+ imports: {},
566
+ exports: {
567
+ component: {
568
+ name: "component",
569
+ pkg: false,
570
+ file: "component.js",
571
+ identifier: "test-module/component"
572
+ }
573
+ },
574
+ scopes: {
575
+ node_modules: {
576
+ react: "https://cdn.com/react.js",
577
+ "local-component": "test-module/component"
578
+ }
579
+ }
580
+ }
581
+ ];
582
+ const result = buildScopesMap(
583
+ imports,
584
+ manifests,
585
+ (name, scope) => `${name}/${scope}`
586
+ );
587
+ assert.deepEqual(result, {
588
+ "test-module//node_modules": {
589
+ react: "https://cdn.com/react.js",
590
+ "local-component": "test-module/component.js"
591
+ }
592
+ });
593
+ });
594
+ test("should use scope path from imports when available", () => {
595
+ const imports = {
596
+ "test-module/node_modules": "test-module/node_modules/index.js",
597
+ "test-module/component": "test-module/component.js"
598
+ };
599
+ const manifests = [
600
+ {
601
+ name: "test-module",
602
+ imports: {},
603
+ exports: {
604
+ node_modules: {
605
+ name: "node_modules",
606
+ pkg: false,
607
+ file: "node_modules/index.js",
608
+ identifier: "test-module/node_modules"
609
+ },
610
+ component: {
611
+ name: "component",
612
+ pkg: false,
613
+ file: "component.js",
614
+ identifier: "test-module/component"
615
+ }
616
+ },
617
+ scopes: {
618
+ node_modules: {
619
+ react: "test-module/component"
620
+ }
621
+ }
622
+ }
623
+ ];
624
+ const result = buildScopesMap(
625
+ imports,
626
+ manifests,
627
+ (name, scope) => `${name}/${scope}`
628
+ );
629
+ assert.deepEqual(result, {
630
+ "test-module/test-module/node_modules/index.js": {
631
+ react: "test-module/component.js"
632
+ }
633
+ });
634
+ });
635
+ test("should fall back to scope path when not found in imports", () => {
636
+ const imports = {
637
+ "test-module/component": "test-module/component.js"
638
+ };
639
+ const manifests = [
640
+ {
641
+ name: "test-module",
642
+ imports: {},
643
+ exports: {
644
+ component: {
645
+ name: "component",
646
+ pkg: false,
647
+ file: "component.js",
648
+ identifier: "test-module/component"
649
+ }
650
+ },
651
+ scopes: {
652
+ node_modules: {
653
+ react: "test-module/component"
654
+ }
655
+ }
656
+ }
657
+ ];
658
+ const result = buildScopesMap(
659
+ imports,
660
+ manifests,
661
+ (name, scope) => `${name}/${scope}`
662
+ );
663
+ assert.deepEqual(result, {
664
+ "test-module//node_modules": {
665
+ react: "test-module/component.js"
666
+ }
667
+ });
668
+ });
669
+ test("should handle multiple scopes in single manifest", () => {
670
+ const imports = {
671
+ "test-module/component": "test-module/component.js",
672
+ "test-module/utils": "test-module/utils.js"
673
+ };
674
+ const manifests = [
675
+ {
676
+ name: "test-module",
677
+ imports: {},
678
+ exports: {
679
+ component: {
680
+ name: "component",
681
+ pkg: false,
682
+ file: "component.js",
683
+ identifier: "test-module/component"
684
+ },
685
+ utils: {
686
+ name: "utils",
687
+ pkg: false,
688
+ file: "utils.js",
689
+ identifier: "test-module/utils"
690
+ }
691
+ },
692
+ scopes: {
693
+ node_modules: {
694
+ react: "test-module/component"
695
+ },
696
+ vendor: {
697
+ lodash: "test-module/utils"
698
+ }
699
+ }
700
+ }
701
+ ];
702
+ const result = buildScopesMap(
703
+ imports,
704
+ manifests,
705
+ (name, scope) => `${name}/${scope}`
706
+ );
707
+ assert.deepEqual(result, {
708
+ "test-module//node_modules": {
709
+ react: "test-module/component.js"
91
710
  },
711
+ "test-module//vendor": {
712
+ lodash: "test-module/utils.js"
713
+ }
714
+ });
715
+ });
716
+ test("should handle multiple manifests with scopes", () => {
717
+ const imports = {
718
+ "module-a/component": "module-a/component.js",
719
+ "module-b/utils": "module-b/utils.js"
720
+ };
721
+ const manifests = [
92
722
  {
93
- name: "ssr-vue2-host",
94
- imports: {
95
- vue: "ssr-vue2-remote/vue3"
723
+ name: "module-a",
724
+ imports: {},
725
+ exports: {
726
+ component: {
727
+ name: "component",
728
+ pkg: false,
729
+ file: "component.js",
730
+ identifier: "module-a/component"
731
+ }
732
+ },
733
+ scopes: {
734
+ node_modules: {
735
+ react: "module-a/component"
736
+ }
737
+ }
738
+ },
739
+ {
740
+ name: "module-b",
741
+ imports: {},
742
+ exports: {
743
+ utils: {
744
+ name: "utils",
745
+ pkg: false,
746
+ file: "utils.js",
747
+ identifier: "module-b/utils"
748
+ }
96
749
  },
97
- exports: {}
750
+ scopes: {
751
+ vendor: {
752
+ lodash: "module-b/utils"
753
+ }
754
+ }
755
+ }
756
+ ];
757
+ const result = buildScopesMap(
758
+ imports,
759
+ manifests,
760
+ (name, scope) => `${name}/${scope}`
761
+ );
762
+ assert.deepEqual(result, {
763
+ "module-a//node_modules": {
764
+ react: "module-a/component.js"
765
+ },
766
+ "module-b//vendor": {
767
+ lodash: "module-b/utils.js"
98
768
  }
99
- ],
100
- getScope(name) {
101
- return `/${name}/`;
102
- },
103
- getFile(name, file) {
104
- return `${name}/${file}`;
105
- }
769
+ });
106
770
  });
107
- assert.deepEqual(result, {
108
- imports: { "ssr-vue2-remote/vue": "ssr-vue2-remote/vue.mjs" },
109
- scopes: {
110
- "/ssr-vue2-remote/": { vue: "ssr-vue2-remote/vue.mjs" },
111
- "/ssr-vue2-host/": { vue: "ssr-vue2-remote/vue3" }
112
- }
771
+ test("should handle empty scope specifier map", () => {
772
+ const imports = {
773
+ "test-module/component": "test-module/component.js"
774
+ };
775
+ const manifests = [
776
+ {
777
+ name: "test-module",
778
+ imports: {},
779
+ exports: {
780
+ component: {
781
+ name: "component",
782
+ pkg: false,
783
+ file: "component.js",
784
+ identifier: "test-module/component"
785
+ }
786
+ },
787
+ scopes: {
788
+ "./node_modules": {}
789
+ }
790
+ }
791
+ ];
792
+ const result = buildScopesMap(
793
+ imports,
794
+ manifests,
795
+ (name, scope) => `${name}/${scope}`
796
+ );
797
+ assert.deepEqual(result, {
798
+ "test-module//./node_modules": {}
799
+ });
800
+ });
801
+ test("should handle undefined scopes property", () => {
802
+ const imports = {
803
+ "test-module/component": "test-module/component.js"
804
+ };
805
+ const manifests = [
806
+ {
807
+ name: "test-module",
808
+ imports: {},
809
+ exports: {
810
+ component: {
811
+ name: "component",
812
+ pkg: false,
813
+ file: "component.js",
814
+ identifier: "test-module/component"
815
+ }
816
+ },
817
+ scopes: void 0
818
+ }
819
+ ];
820
+ const result = buildScopesMap(
821
+ imports,
822
+ manifests,
823
+ (name, scope) => `${name}/${scope}`
824
+ );
825
+ assert.deepEqual(result, {});
113
826
  });
114
827
  });
115
- test("should throw error when encountering legacy format manifests", async () => {
116
- const legacyManifest = {
117
- name: "legacy-module",
118
- imports: {},
119
- exports: {
120
- "legacy-export": "legacy-module/legacy-file.js"
121
- }
122
- };
123
- const expectedErrorMessage = "Detected incompatible legacy manifest format in legacy-module. Please upgrade your ESMX dependencies first, then rebuild and redeploy your service.";
124
- expect(() => {
125
- getImportMap({
126
- manifests: [legacyManifest],
127
- getScope(name) {
128
- return `/${name}/`;
828
+ describe("getImportMap", () => {
829
+ test("should return empty import map for empty manifests", () => {
830
+ const options = {
831
+ manifests: [],
832
+ getFile: (name, file) => `${name}/${file}`,
833
+ getScope: (name, scope) => `${name}/${scope}`
834
+ };
835
+ const result = getImportMap(options);
836
+ assert.deepEqual(result, {
837
+ imports: {},
838
+ scopes: {}
839
+ });
840
+ });
841
+ test("should build complete import map with imports and scopes", () => {
842
+ const options = {
843
+ manifests: [
844
+ {
845
+ name: "test-module",
846
+ imports: {
847
+ "custom-react": "test-module/component"
848
+ },
849
+ exports: {
850
+ component: {
851
+ name: "component",
852
+ pkg: false,
853
+ file: "component.js",
854
+ identifier: "test-module/component"
855
+ },
856
+ utils: {
857
+ name: "utils",
858
+ pkg: false,
859
+ file: "utils.js",
860
+ identifier: "test-module/utils"
861
+ }
862
+ },
863
+ scopes: {
864
+ node_modules: {
865
+ react: "test-module/component",
866
+ lodash: "test-module/utils"
867
+ }
868
+ }
869
+ }
870
+ ],
871
+ getFile: (name, file) => `${name}/${file}`,
872
+ getScope: (name, scope) => `${name}/${scope}`
873
+ };
874
+ const result = getImportMap(options);
875
+ assert.deepEqual(result, {
876
+ imports: {
877
+ "test-module/component": "test-module/component.js",
878
+ "test-module/utils": "test-module/utils.js",
879
+ "test-module/custom-react": "test-module/component.js"
880
+ },
881
+ scopes: {
882
+ "test-module//node_modules": {
883
+ react: "test-module/component.js",
884
+ lodash: "test-module/utils.js"
885
+ }
886
+ }
887
+ });
888
+ });
889
+ test("should handle complex multi-module scenario", () => {
890
+ const options = {
891
+ manifests: [
892
+ {
893
+ name: "module-a",
894
+ imports: {},
895
+ exports: {
896
+ utils: {
897
+ name: "utils",
898
+ pkg: false,
899
+ file: "utils.js",
900
+ identifier: "module-a/utils"
901
+ }
902
+ },
903
+ scopes: {
904
+ node_modules: {
905
+ react: "module-a/utils"
906
+ }
907
+ }
908
+ },
909
+ {
910
+ name: "module-b",
911
+ imports: {
912
+ shared: "module-a/utils"
913
+ },
914
+ exports: {
915
+ component: {
916
+ name: "component",
917
+ pkg: false,
918
+ file: "component.js",
919
+ identifier: "module-b/component"
920
+ }
921
+ },
922
+ scopes: {
923
+ vendor: {
924
+ lodash: "module-a/utils"
925
+ }
926
+ }
927
+ }
928
+ ],
929
+ getFile: (name, file) => `${name}/${file}`,
930
+ getScope: (name, scope) => `${name}/${scope}`
931
+ };
932
+ const result = getImportMap(options);
933
+ assert.deepEqual(result, {
934
+ imports: {
935
+ "module-a/utils": "module-a/utils.js",
936
+ "module-b/component": "module-b/component.js",
937
+ "module-b/shared": "module-a/utils.js"
938
+ },
939
+ scopes: {
940
+ "module-a//node_modules": {
941
+ react: "module-a/utils.js"
942
+ },
943
+ "module-b//vendor": {
944
+ lodash: "module-a/utils.js"
945
+ }
946
+ }
947
+ });
948
+ });
949
+ test("should handle manifests with only exports", () => {
950
+ const options = {
951
+ manifests: [
952
+ {
953
+ name: "test-module",
954
+ imports: {},
955
+ exports: {
956
+ component: {
957
+ name: "component",
958
+ pkg: false,
959
+ file: "component.js",
960
+ identifier: "test-module/component"
961
+ }
962
+ },
963
+ scopes: {}
964
+ }
965
+ ],
966
+ getFile: (name, file) => `${name}/${file}`,
967
+ getScope: (name, scope) => `${name}/${scope}`
968
+ };
969
+ const result = getImportMap(options);
970
+ assert.deepEqual(result, {
971
+ imports: {
972
+ "test-module/component": "test-module/component.js"
973
+ },
974
+ scopes: {}
975
+ });
976
+ });
977
+ test("should handle manifests with only imports", () => {
978
+ const options = {
979
+ manifests: [
980
+ {
981
+ name: "test-module",
982
+ imports: {
983
+ external: "https://cdn.com/lib.js"
984
+ },
985
+ exports: {},
986
+ scopes: {}
987
+ }
988
+ ],
989
+ getFile: (name, file) => `${name}/${file}`,
990
+ getScope: (name, scope) => `${name}/${scope}`
991
+ };
992
+ const result = getImportMap(options);
993
+ assert.deepEqual(result, {
994
+ imports: {
995
+ "test-module/external": "https://cdn.com/lib.js"
996
+ },
997
+ scopes: {}
998
+ });
999
+ });
1000
+ test("should handle manifests with only scopes", () => {
1001
+ const options = {
1002
+ manifests: [
1003
+ {
1004
+ name: "test-module",
1005
+ imports: {},
1006
+ exports: {},
1007
+ scopes: {
1008
+ node_modules: {
1009
+ react: "https://cdn.com/react.js"
1010
+ }
1011
+ }
1012
+ }
1013
+ ],
1014
+ getFile: (name, file) => `${name}/${file}`,
1015
+ getScope: (name, scope) => `${name}/${scope}`
1016
+ };
1017
+ const result = getImportMap(options);
1018
+ assert.deepEqual(result, {
1019
+ imports: {},
1020
+ scopes: {
1021
+ "test-module//node_modules": {
1022
+ react: "https://cdn.com/react.js"
1023
+ }
1024
+ }
1025
+ });
1026
+ });
1027
+ test("should handle custom getFile and getScope functions", () => {
1028
+ const options = {
1029
+ manifests: [
1030
+ {
1031
+ name: "test-module",
1032
+ imports: {},
1033
+ exports: {
1034
+ component: {
1035
+ name: "component",
1036
+ pkg: false,
1037
+ file: "component.js",
1038
+ identifier: "test-module/component"
1039
+ }
1040
+ },
1041
+ scopes: {
1042
+ node_modules: {
1043
+ react: "test-module/component"
1044
+ }
1045
+ }
1046
+ }
1047
+ ],
1048
+ getFile: (name, file) => `/custom/path/${name}/${file}`,
1049
+ getScope: (name, scope) => `custom-scope-${name}-${scope}`
1050
+ };
1051
+ const result = getImportMap(options);
1052
+ assert.deepEqual(result, {
1053
+ imports: {
1054
+ "test-module/component": "/custom/path/test-module/component.js"
1055
+ },
1056
+ scopes: {
1057
+ "custom-scope-test-module-/node_modules": {
1058
+ react: "/custom/path/test-module/component.js"
1059
+ }
1060
+ }
1061
+ });
1062
+ });
1063
+ test("should handle edge case with undefined scopes in manifests", () => {
1064
+ const options = {
1065
+ manifests: [
1066
+ {
1067
+ name: "test-module",
1068
+ imports: {},
1069
+ exports: {
1070
+ component: {
1071
+ name: "component",
1072
+ pkg: false,
1073
+ file: "component.js",
1074
+ identifier: "test-module/component"
1075
+ }
1076
+ },
1077
+ scopes: void 0
1078
+ }
1079
+ ],
1080
+ getFile: (name, file) => `${name}/${file}`,
1081
+ getScope: (name, scope) => `${name}/${scope}`
1082
+ };
1083
+ const result = getImportMap(options);
1084
+ assert.deepEqual(result, {
1085
+ imports: {
1086
+ "test-module/component": "test-module/component.js"
1087
+ },
1088
+ scopes: {}
1089
+ });
1090
+ });
1091
+ test("should handle mixed scenarios with external URLs and local modules", () => {
1092
+ const options = {
1093
+ manifests: [
1094
+ {
1095
+ name: "test-module",
1096
+ imports: {
1097
+ "external-react": "https://cdn.com/react.js",
1098
+ "local-alias": "test-module/component"
1099
+ },
1100
+ exports: {
1101
+ component: {
1102
+ name: "component",
1103
+ pkg: false,
1104
+ file: "component.js",
1105
+ identifier: "test-module/component"
1106
+ }
1107
+ },
1108
+ scopes: {
1109
+ node_modules: {
1110
+ "external-lib": "https://cdn.com/lodash.js",
1111
+ "local-lib": "test-module/component"
1112
+ }
1113
+ }
1114
+ }
1115
+ ],
1116
+ getFile: (name, file) => `${name}/${file}`,
1117
+ getScope: (name, scope) => `${name}/${scope}`
1118
+ };
1119
+ const result = getImportMap(options);
1120
+ assert.deepEqual(result, {
1121
+ imports: {
1122
+ "test-module/component": "test-module/component.js",
1123
+ "test-module/external-react": "https://cdn.com/react.js",
1124
+ "test-module/local-alias": "test-module/component.js"
129
1125
  },
130
- getFile(name, file) {
131
- return `${name}/${file}`;
1126
+ scopes: {
1127
+ "test-module//node_modules": {
1128
+ "external-lib": "https://cdn.com/lodash.js",
1129
+ "local-lib": "test-module/component.js"
1130
+ }
1131
+ }
1132
+ });
1133
+ });
1134
+ test("should handle index path aliases in complete import map", () => {
1135
+ const options = {
1136
+ manifests: [
1137
+ {
1138
+ name: "test-module",
1139
+ imports: {},
1140
+ exports: {
1141
+ "src/index": {
1142
+ name: "src/index",
1143
+ pkg: false,
1144
+ file: "src/index.js",
1145
+ identifier: "test-module/src/index"
1146
+ }
1147
+ },
1148
+ scopes: {
1149
+ src: {
1150
+ main: "test-module/src/index"
1151
+ }
1152
+ }
1153
+ }
1154
+ ],
1155
+ getFile: (name, file) => `${name}/${file}`,
1156
+ getScope: (name, scope) => `${name}/${scope}`
1157
+ };
1158
+ const result = getImportMap(options);
1159
+ assert.deepEqual(result, {
1160
+ imports: {
1161
+ "test-module/src/index": "test-module/src/index.js",
1162
+ "test-module/src": "test-module/src/index.js"
1163
+ },
1164
+ scopes: {
1165
+ "test-module/test-module/src/index.js": {
1166
+ main: "test-module/src/index.js"
1167
+ }
132
1168
  }
133
1169
  });
134
- }).toThrowError(expectedErrorMessage);
1170
+ });
135
1171
  });