@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.
@@ -11,50 +11,84 @@ export interface ImportMapManifest {
11
11
  name: string;
12
12
  file: string;
13
13
  identifier: string;
14
- rewrite: boolean;
14
+ pkg: boolean;
15
15
  }
16
16
  >;
17
+ scopes: Record<string, Record<string, string>>;
17
18
  }
18
19
 
19
- export function getImportMap({
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
- }): ImportMap {
28
- const imports: SpecifierMap = {};
29
- const scopes: ScopesMap = {};
30
- Object.values(manifests).forEach((manifest) => {
31
- const scopeImports: SpecifierMap = {};
24
+ }
32
25
 
33
- Object.entries(manifest.exports).forEach(([key, exportItem]) => {
34
- // Handle the case where exportItem is a string in legacy builds
35
- if (typeof exportItem === 'string') {
36
- throw new Error(
37
- `Detected incompatible legacy manifest format in ${manifest.name}. Please upgrade your ESMX dependencies first, then rebuild and redeploy your service.`
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
- pathWithoutIndex(imports);
52
- Object.values(manifests).forEach((manifest) => {
38
+
39
+ manifests.forEach((manifest) => {
53
40
  Object.entries(manifest.imports).forEach(([name, identifier]) => {
54
- scopes[getScope(manifest.name)][name] =
55
- imports[identifier] ?? identifier;
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