@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.
@@ -24,8 +24,8 @@ import type { Esmx } from './core';
24
24
  * exports: [
25
25
  * 'root:src/components/button.vue',
26
26
  * 'root:src/utils/format.ts',
27
- * 'npm:vue',
28
- * 'npm:vue-router'
27
+ * 'pkg:vue',
28
+ * 'pkg:vue-router'
29
29
  * ]
30
30
  * },
31
31
  * // 打包配置
@@ -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
- rewrite: boolean;
9
+ pkg: boolean;
10
10
  }>;
11
+ scopes: Record<string, Record<string, string>>;
11
12
  }
12
- export declare function getImportMap({ manifests, getFile, getScope }: {
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
- }): ImportMap;
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 getImportMap({
3
- manifests,
4
- getFile,
5
- getScope
6
- }) {
2
+ export function buildImportsMap(manifests, getFile) {
7
3
  const imports = {};
8
- const scopes = {};
9
- Object.values(manifests).forEach((manifest) => {
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
- pathWithoutIndex(imports);
28
- Object.values(manifests).forEach((manifest) => {
10
+ manifests.forEach((manifest) => {
29
11
  Object.entries(manifest.imports).forEach(([name, identifier]) => {
30
- scopes[getScope(manifest.name)][name] = imports[identifier] ?? identifier;
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