@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/dist/pack-config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ImportMap } from '@esmx/import';
|
|
1
|
+
import type { ImportMap, ScopesMap, SpecifierMap } from '@esmx/import';
|
|
2
2
|
export interface ImportMapManifest {
|
|
3
3
|
name: string;
|
|
4
4
|
imports: Record<string, string>;
|
|
@@ -6,11 +6,15 @@ export interface ImportMapManifest {
|
|
|
6
6
|
name: string;
|
|
7
7
|
file: string;
|
|
8
8
|
identifier: string;
|
|
9
|
-
|
|
9
|
+
pkg: boolean;
|
|
10
10
|
}>;
|
|
11
|
+
scopes: Record<string, Record<string, string>>;
|
|
11
12
|
}
|
|
12
|
-
export
|
|
13
|
+
export interface GetImportMapOptions {
|
|
13
14
|
manifests: readonly ImportMapManifest[];
|
|
14
|
-
getScope: (name: string) => string;
|
|
15
|
+
getScope: (name: string, scope: string) => string;
|
|
15
16
|
getFile: (name: string, file: string) => string;
|
|
16
|
-
}
|
|
17
|
+
}
|
|
18
|
+
export declare function buildImportsMap(manifests: readonly ImportMapManifest[], getFile: (name: string, file: string) => string): SpecifierMap;
|
|
19
|
+
export declare function buildScopesMap(imports: SpecifierMap, manifests: readonly ImportMapManifest[], getScope: (name: string, scope: string) => string): ScopesMap;
|
|
20
|
+
export declare function getImportMap({ manifests, getFile, getScope }: GetImportMapOptions): ImportMap;
|
|
@@ -1,35 +1,48 @@
|
|
|
1
1
|
import { pathWithoutIndex } from "./path-without-index.mjs";
|
|
2
|
-
export function
|
|
3
|
-
manifests,
|
|
4
|
-
getFile,
|
|
5
|
-
getScope
|
|
6
|
-
}) {
|
|
2
|
+
export function buildImportsMap(manifests, getFile) {
|
|
7
3
|
const imports = {};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const scopeImports = {};
|
|
11
|
-
Object.entries(manifest.exports).forEach(([key, exportItem]) => {
|
|
12
|
-
if (typeof exportItem === "string") {
|
|
13
|
-
throw new Error(
|
|
14
|
-
`Detected incompatible legacy manifest format in ${manifest.name}. Please upgrade your ESMX dependencies first, then rebuild and redeploy your service.`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
4
|
+
manifests.forEach((manifest) => {
|
|
5
|
+
Object.entries(manifest.exports).forEach(([, exportItem]) => {
|
|
17
6
|
const file = getFile(manifest.name, exportItem.file);
|
|
18
7
|
imports[exportItem.identifier] = file;
|
|
19
|
-
if (!exportItem.rewrite) {
|
|
20
|
-
scopeImports[exportItem.name] = file;
|
|
21
|
-
}
|
|
22
8
|
});
|
|
23
|
-
if (Object.keys(scopeImports).length || Object.keys(imports).length) {
|
|
24
|
-
scopes[getScope(manifest.name)] = scopeImports;
|
|
25
|
-
}
|
|
26
9
|
});
|
|
27
|
-
|
|
28
|
-
Object.values(manifests).forEach((manifest) => {
|
|
10
|
+
manifests.forEach((manifest) => {
|
|
29
11
|
Object.entries(manifest.imports).forEach(([name, identifier]) => {
|
|
30
|
-
|
|
12
|
+
const fullName = `${manifest.name}/${name}`;
|
|
13
|
+
imports[fullName] = imports[identifier] ?? identifier;
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
pathWithoutIndex(imports);
|
|
17
|
+
return imports;
|
|
18
|
+
}
|
|
19
|
+
export function buildScopesMap(imports, manifests, getScope) {
|
|
20
|
+
const scopes = {};
|
|
21
|
+
manifests.forEach((manifest) => {
|
|
22
|
+
if (!manifest.scopes) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
Object.entries(manifest.scopes).forEach(([scopeName, specifierMap]) => {
|
|
26
|
+
const scopedImports = {};
|
|
27
|
+
Object.entries(specifierMap).forEach(
|
|
28
|
+
([specifierName, identifier]) => {
|
|
29
|
+
scopedImports[specifierName] = imports[identifier] ?? identifier;
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
const scopePath = imports[`${manifest.name}/${scopeName}`] ?? `/${scopeName}`;
|
|
33
|
+
const scopeKey = getScope(manifest.name, scopePath);
|
|
34
|
+
scopes[scopeKey] = scopedImports;
|
|
31
35
|
});
|
|
32
36
|
});
|
|
37
|
+
return scopes;
|
|
38
|
+
}
|
|
39
|
+
export function getImportMap({
|
|
40
|
+
manifests,
|
|
41
|
+
getFile,
|
|
42
|
+
getScope
|
|
43
|
+
}) {
|
|
44
|
+
const imports = buildImportsMap(manifests, getFile);
|
|
45
|
+
const scopes = buildScopesMap(imports, manifests, getScope);
|
|
33
46
|
return {
|
|
34
47
|
imports,
|
|
35
48
|
scopes
|