@esmx/core 3.0.0-rc.25 → 3.0.0-rc.26

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.
@@ -12,7 +12,7 @@ export async function getManifestList(target, moduleConfig) {
12
12
  return data;
13
13
  } catch (e) {
14
14
  throw new Error(
15
- `'${item.name}' service '${target}/manifest.json' file read error`
15
+ `'${item.name}' service '${filename}' file read error on target '${target}': ${e instanceof Error ? e.message : String(e)}`
16
16
  );
17
17
  }
18
18
  })
@@ -1,245 +1,158 @@
1
1
  import type { BuildSsrTarget } from './core';
2
2
  /**
3
- * 模块配置接口
4
- * 在微服务架构中,一个服务既可以作为主服务使用其他服务的模块,
5
- * 也可以作为远程服务(remote)向其他服务提供模块。
6
- *
7
- * @example
8
- * // 假设有两个服务:
9
- * // 1. vue-host-service:主服务,需要使用远程服务的 Vue 组件
10
- * // 2. vue-remote-service:远程服务,提供可复用的 Vue 组件
11
- *
12
- * // vue-remote-service 的配置示例:
13
- * const remoteConfig: ModuleConfig = {
14
- * // 服务名称
15
- * name: 'vue-remote-service',
16
- * // 导入配置:空,因为这个服务不需要导入其他服务的模块
17
- * imports: {},
18
- * // 导出配置:将组件库暴露给其他服务使用
19
- * exports: [
20
- * {
21
- * 'components/button': {
22
- * input: './src/components/button.ts' // 必须指定具体的源文件
23
- * }
24
- * }
25
- * ]
26
- * };
27
- *
28
- * // vue-host-service 的配置示例:
29
- * const hostConfig: ModuleConfig = {
30
- * // 服务名称
31
- * name: 'vue-host-service',
32
- * // 链接配置:指定远程服务的构建产物位置
33
- * links: {
34
- * 'vue-remote-service': '../vue-remote-service/dist'
35
- * },
36
- * // 导入配置:使用远程服务提供的组件
37
- * imports: {
38
- * 'remote-button': 'vue-remote-service/components/button'
39
- * },
40
- * // 导出配置:可选,如果这个服务也需要暴露模块给其他服务使用
41
- * exports: []
42
- * };
3
+ * Core configuration interface for the module system.
4
+ * Defines module linking, import mapping, and export configurations.
43
5
  */
44
6
  export interface ModuleConfig {
45
7
  /**
46
- * 服务与服务之间的链接配置
47
- * 键:远程服务的名称
48
- * 值:远程服务的构建产物目录路径
8
+ * Module link configuration.
9
+ * Key is remote module name, value is module build output directory path.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * links: {
14
+ * 'shared-lib': '../shared-lib/dist',
15
+ * 'api-utils': '/var/www/api-utils/dist'
16
+ * }
17
+ * ```
49
18
  */
50
19
  links?: Record<string, string>;
51
20
  /**
52
- * 导入配置
53
- * 用于将当前服务中的某个模块标识符映射到远程服务提供的模块
54
- * 键:在当前服务中使用的模块标识符
55
- * 值:远程服务导出的模块路径
21
+ * Module import mapping configuration.
22
+ * Key is local module identifier, value is remote module path.
23
+ * Mainly used for standard imports of third-party libraries.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * imports: {
28
+ * 'axios': 'shared-lib/axios',
29
+ * 'lodash': 'shared-lib/lodash'
30
+ * }
31
+ * ```
56
32
  */
57
33
  imports?: Record<string, string>;
58
34
  /**
59
- * 导出配置
60
- * 用于将当前服务的模块暴露给其他服务使用
61
- * 其他服务可以通过 imports 配置来使用这里导出的模块
35
+ * Module export configuration.
36
+ * Supports multiple configuration forms: mixed array and object.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Array form
41
+ * exports: ['npm:axios', 'root:src/utils/format.ts']
42
+ *
43
+ * // Object form
44
+ * exports: {
45
+ * 'axios': 'axios',
46
+ * 'utils': './src/utils/index.ts'
47
+ * }
48
+ * ```
62
49
  */
63
50
  exports?: ModuleConfigExportExports;
64
51
  }
65
52
  /**
66
- * 模块导出配置类型
67
- * 用于定义当前服务要暴露哪些模块供其他服务使用
68
- *
69
- * @example
70
- * // 1. 数组形式 - 字符串简写
71
- * const exports1: ModuleConfigExportExports = [
72
- * // npm 包导出
73
- * 'npm:lodash',
74
- * // 本地文件导出(必须指定具体文件名)
75
- * 'root:src/components/button.ts'
76
- * ];
77
- *
78
- * // 2. 数组形式 - 对象配置
79
- * const exports2: ModuleConfigExportExports = [
80
- * // 简单的键值对映射
81
- * { 'button': './src/components/button.ts' },
82
- * // 带完整配置的对象
83
- * {
84
- * 'store': {
85
- * input: './src/store.ts',
86
- * inputTarget: {
87
- * client: './src/store.client.ts',
88
- * server: './src/store.server.ts'
89
- * }
90
- * }
91
- * }
92
- * ];
93
- *
94
- * // 3. 对象形式
95
- * const exports3: ModuleConfigExportExports = {
96
- * // 简单路径映射
97
- * 'utils': './src/utils.ts',
98
- *
99
- * // 完整配置对象
100
- * 'api': {
101
- * input: './src/api/index.ts'
102
- * },
103
- *
104
- * // 客户端/服务端分离
105
- * 'entry': {
106
- * inputTarget: {
107
- * client: './src/entry.client.ts',
108
- * server: './src/entry.server.ts'
109
- * }
110
- * }
111
- * };
53
+ * Union type for export configuration.
54
+ * Supports mixed array and object forms to provide flexibility
55
+ * for different configuration scenarios.
112
56
  */
113
57
  export type ModuleConfigExportExports = Array<string | Record<string, string | ModuleConfigExportObject>> | Record<string, string | ModuleConfigExportObject>;
114
58
  /**
115
- * 模块导出对象配置
116
- * 用于详细定义一个要导出的模块的配置
117
- *
118
- * @property input - 模块的源文件路径
119
- * @property inputTarget - 针对客户端和服务端分别配置不同的入口文件
120
- * @property rewrite - 是否需要重写模块路径,默认为 true
121
- * 可以对 npm 包设置为 false 以保持原始路径
122
- *
123
- * @example
124
- * // 导出一个同构组件(客户端和服务端使用相同的实现)
125
- * const buttonExport: ModuleConfigExportObject = {
126
- * input: './src/components/button'
127
- * };
128
- *
129
- * // 导出一个具有不同客户端和服务端实现的模块
130
- * const storeExport: ModuleConfigExportObject = {
131
- * inputTarget: {
132
- * client: './src/store/client', // 客户端特定实现
133
- * server: './src/store/server' // 服务端特定实现
134
- * }
135
- * };
59
+ * Configuration object for individual module exports.
60
+ * Provides fine-grained control over module export behavior.
136
61
  */
137
62
  export type ModuleConfigExportObject = {
138
63
  /**
139
- * 模块的源文件路径,用于指定导出的具体文件
64
+ * Input file path, relative to project root directory.
65
+ *
66
+ * @example './src/utils/format'
140
67
  */
141
68
  input?: string;
142
69
  /**
143
- * 客户端和服务端的不同入口文件配置
144
- * - false 表示在该环境下不提供实现
70
+ * Environment-specific input file configuration.
71
+ * Supports client and server differentiated builds.
72
+ * Set to `false` to disable builds for specific environments.
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * inputTarget: {
77
+ * client: './src/storage/indexedDB.ts',
78
+ * server: './src/storage/filesystem.ts'
79
+ * }
80
+ * ```
145
81
  */
146
82
  inputTarget?: Record<BuildSsrTarget, string | false>;
147
83
  /**
148
- * 是否需要重写模块路径(不常用)
149
- * @default true - 适用于大多数情况
150
- * @remarks 仅在导出 npm 包时可能需要设为 false
84
+ * Whether to rewrite import paths within modules.
85
+ *
86
+ * @default true
87
+ * @remarks Only needs to be false when exporting npm packages
151
88
  */
152
89
  rewrite?: boolean;
153
90
  };
154
91
  /**
155
- * 解析后的模块配置接口
156
- * 这是运行时实际使用的配置格式,由原始配置解析得到
157
- * 包含了所有必要的绝对路径和解析后的模块映射关系
158
- *
159
- * @example
160
- * const parsedConfig: ParsedModuleConfig = {
161
- * // 服务名称
162
- * name: 'vue-remote-service',
163
- * // 服务根目录
164
- * root: '/path/to/vue-remote-service',
165
- * // 解析后的服务链接配置(包含了完整的文件路径)
166
- * links: {
167
- * 'vue-remote-service': {
168
- * name: 'vue-remote-service',
169
- * root: '/path/to/vue-remote-service/dist',
170
- * client: '/path/to/vue-remote-service/dist/client',
171
- * clientManifestJson: '/path/to/vue-remote-service/dist/client/manifest.json',
172
- * server: '/path/to/vue-remote-service/dist/server',
173
- * serverManifestJson: '/path/to/vue-remote-service/dist/server/manifest.json'
174
- * }
175
- * },
176
- * // 模块导入映射
177
- * imports: {
178
- * 'remote-button': 'vue-remote-service/components/button'
179
- * },
180
- * // 解析后的导出配置
181
- * exports: {
182
- * 'components/button': {
183
- * name: 'components/button',
184
- * inputTarget: {
185
- * client: './src/components/button',
186
- * server: './src/components/button'
187
- * },
188
- * // 系统内部标记,用户通常不需要关心
189
- * rewrite: true
190
- * }
191
- * }
192
- * };
92
+ * Parsed and normalized module configuration.
93
+ * Contains resolved paths and processed configuration data.
193
94
  */
194
95
  export interface ParsedModuleConfig {
96
+ /** Module name */
195
97
  name: string;
98
+ /** Module root directory path */
196
99
  root: string;
100
+ /**
101
+ * Resolved link information for connected modules.
102
+ * Contains absolute paths to client/server directories and manifest files.
103
+ */
197
104
  links: Record<string, {
105
+ /** Module name */
198
106
  name: string;
107
+ /** Original root path (relative or absolute) */
199
108
  root: string;
109
+ /** Absolute path to client build directory */
200
110
  client: string;
111
+ /** Absolute path to client manifest.json */
201
112
  clientManifestJson: string;
113
+ /** Absolute path to server build directory */
202
114
  server: string;
115
+ /** Absolute path to server manifest.json */
203
116
  serverManifestJson: string;
204
117
  }>;
118
+ /** Import mapping configuration (passed through as-is) */
205
119
  imports: Record<string, string>;
120
+ /** Processed export configuration */
206
121
  exports: ParsedModuleConfigExports;
207
122
  }
208
123
  /**
209
- * 解析后的模块导出配置
210
- * 将原始的导出配置转换为标准化的格式
211
- * 键为导出模块的名称,值为该模块的详细配置
124
+ * Processed export configuration mapping.
125
+ * Maps export names to their resolved configuration objects.
212
126
  */
213
127
  export type ParsedModuleConfigExports = Record<string, ParsedModuleConfigExport>;
214
128
  /**
215
- * 解析后的单个导出模块配置
216
- * @property name - 导出模块的名称,用于其他服务导入此模块
217
- * @property inputTarget - 客户端和服务端的入口文件配置
218
- * @property rewrite - 模块路径重写标志,true 表示需要调整路径以适配微服务架构
129
+ * Processed export configuration for a single module.
130
+ * Contains resolved input targets and processing flags.
219
131
  */
220
132
  export interface ParsedModuleConfigExport {
133
+ /** Export name/identifier */
221
134
  name: string;
135
+ /** Resolved input targets for different build environments */
222
136
  inputTarget: Record<BuildSsrTarget, string | false>;
137
+ /** Whether to rewrite import paths within this module */
223
138
  rewrite: boolean;
224
139
  }
225
140
  /**
226
- * 解析模块配置
227
- * 将原始的模块配置转换为标准化的格式,处理路径解析和模块映射
141
+ * Parse and normalize module configuration.
142
+ * Resolves paths, processes exports, and creates a standardized configuration object.
228
143
  *
229
- * @param name - 服务的名称
230
- * @param root - 服务的根目录路径
231
- * @param config - 原始的模块配置对象
232
- * @returns 解析后的模块配置
144
+ * @param name - Module name
145
+ * @param root - Module root directory path
146
+ * @param config - Raw module configuration (optional)
147
+ * @returns Parsed and normalized module configuration
233
148
  *
234
149
  * @example
235
- * const parsedConfig = parseModuleConfig('vue-remote-service', '/path/to/service', {
236
- * links: {
237
- * 'vue-remote-service': 'dist'
238
- * },
239
- * imports: {
240
- * 'remote-button': 'vue-remote-service/components/button'
241
- * },
242
- * exports: ['root:src/components/button.ts'] // 必须指定具体文件名
150
+ * ```typescript
151
+ * const parsed = parseModuleConfig('my-app', '/path/to/app', {
152
+ * links: { 'shared-lib': '../shared-lib/dist' },
153
+ * imports: { 'axios': 'shared-lib/axios' },
154
+ * exports: ['npm:axios', 'root:src/utils/format.ts']
243
155
  * });
156
+ * ```
244
157
  */
245
158
  export declare function parseModuleConfig(name: string, root: string, config?: ModuleConfig): ParsedModuleConfig;
@@ -9,9 +9,9 @@ export function parseModuleConfig(name, root, config = {}) {
9
9
  };
10
10
  }
11
11
  const PREFIX = {
12
- /** npm 包前缀 */
12
+ /** Prefix for npm package exports */
13
13
  npm: "npm:",
14
- /** 根路径前缀 */
14
+ /** Prefix for source file exports */
15
15
  root: "root:"
16
16
  };
17
17
  function getLinks(name, root, config) {
@@ -0,0 +1 @@
1
+ export {};