@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.
- package/dist/core.mjs +4 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +0 -6
- package/dist/manifest-json.d.ts +8 -21
- package/dist/module-config.d.ts +39 -144
- package/dist/module-config.mjs +145 -57
- package/dist/module-config.test.mjs +620 -509
- package/dist/pack-config.d.ts +2 -2
- package/dist/utils/import-map.d.ts +9 -5
- package/dist/utils/import-map.mjs +36 -23
- package/dist/utils/import-map.test.mjs +1139 -103
- package/package.json +3 -3
- package/src/core.ts +5 -4
- package/src/index.ts +14 -9
- package/src/manifest-json.ts +8 -22
- package/src/module-config.test.ts +636 -637
- package/src/module-config.ts +242 -257
- package/src/pack-config.ts +2 -2
- package/src/utils/import-map.test.ts +1207 -110
- package/src/utils/import-map.ts +63 -29
package/src/utils/import-map.ts
CHANGED
|
@@ -11,50 +11,84 @@ export interface ImportMapManifest {
|
|
|
11
11
|
name: string;
|
|
12
12
|
file: string;
|
|
13
13
|
identifier: string;
|
|
14
|
-
|
|
14
|
+
pkg: boolean;
|
|
15
15
|
}
|
|
16
16
|
>;
|
|
17
|
+
scopes: Record<string, Record<string, string>>;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
export
|
|
20
|
-
manifests,
|
|
21
|
-
getFile,
|
|
22
|
-
getScope
|
|
23
|
-
}: {
|
|
20
|
+
export interface GetImportMapOptions {
|
|
24
21
|
manifests: readonly ImportMapManifest[];
|
|
25
|
-
getScope: (name: string) => string;
|
|
22
|
+
getScope: (name: string, scope: string) => string;
|
|
26
23
|
getFile: (name: string, file: string) => string;
|
|
27
|
-
}
|
|
28
|
-
const imports: SpecifierMap = {};
|
|
29
|
-
const scopes: ScopesMap = {};
|
|
30
|
-
Object.values(manifests).forEach((manifest) => {
|
|
31
|
-
const scopeImports: SpecifierMap = {};
|
|
24
|
+
}
|
|
32
25
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
39
|
-
}
|
|
26
|
+
export function buildImportsMap(
|
|
27
|
+
manifests: readonly ImportMapManifest[],
|
|
28
|
+
getFile: (name: string, file: string) => string
|
|
29
|
+
): SpecifierMap {
|
|
30
|
+
const imports: SpecifierMap = {};
|
|
40
31
|
|
|
32
|
+
manifests.forEach((manifest) => {
|
|
33
|
+
Object.entries(manifest.exports).forEach(([, exportItem]) => {
|
|
41
34
|
const file = getFile(manifest.name, exportItem.file);
|
|
42
35
|
imports[exportItem.identifier] = file;
|
|
43
|
-
if (!exportItem.rewrite) {
|
|
44
|
-
scopeImports[exportItem.name] = file;
|
|
45
|
-
}
|
|
46
36
|
});
|
|
47
|
-
if (Object.keys(scopeImports).length || Object.keys(imports).length) {
|
|
48
|
-
scopes[getScope(manifest.name)] = scopeImports;
|
|
49
|
-
}
|
|
50
37
|
});
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
|
|
39
|
+
manifests.forEach((manifest) => {
|
|
53
40
|
Object.entries(manifest.imports).forEach(([name, identifier]) => {
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
const fullName = `${manifest.name}/${name}`;
|
|
42
|
+
imports[fullName] = imports[identifier] ?? identifier;
|
|
56
43
|
});
|
|
57
44
|
});
|
|
45
|
+
|
|
46
|
+
pathWithoutIndex(imports);
|
|
47
|
+
|
|
48
|
+
return imports;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function buildScopesMap(
|
|
52
|
+
imports: SpecifierMap,
|
|
53
|
+
manifests: readonly ImportMapManifest[],
|
|
54
|
+
getScope: (name: string, scope: string) => string
|
|
55
|
+
): ScopesMap {
|
|
56
|
+
const scopes: ScopesMap = {};
|
|
57
|
+
|
|
58
|
+
manifests.forEach((manifest) => {
|
|
59
|
+
if (!manifest.scopes) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Object.entries(manifest.scopes).forEach(([scopeName, specifierMap]) => {
|
|
64
|
+
const scopedImports: SpecifierMap = {};
|
|
65
|
+
|
|
66
|
+
Object.entries(specifierMap).forEach(
|
|
67
|
+
([specifierName, identifier]) => {
|
|
68
|
+
scopedImports[specifierName] =
|
|
69
|
+
imports[identifier] ?? identifier;
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const scopePath =
|
|
74
|
+
imports[`${manifest.name}/${scopeName}`] ?? `/${scopeName}`;
|
|
75
|
+
|
|
76
|
+
const scopeKey = getScope(manifest.name, scopePath);
|
|
77
|
+
scopes[scopeKey] = scopedImports;
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return scopes;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function getImportMap({
|
|
85
|
+
manifests,
|
|
86
|
+
getFile,
|
|
87
|
+
getScope
|
|
88
|
+
}: GetImportMapOptions): ImportMap {
|
|
89
|
+
const imports = buildImportsMap(manifests, getFile);
|
|
90
|
+
|
|
91
|
+
const scopes = buildScopesMap(imports, manifests, getScope);
|
|
58
92
|
return {
|
|
59
93
|
imports,
|
|
60
94
|
scopes
|