@esmx/core 3.0.0-rc.55 → 3.0.0-rc.57
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.d.ts +7 -7
- package/dist/core.mjs +13 -13
- package/dist/index.d.ts +1 -1
- package/dist/manifest-json.d.ts +2 -2
- package/dist/manifest-json.mjs +3 -3
- package/dist/module-config.d.ts +4 -4
- package/dist/module-config.mjs +5 -5
- package/dist/module-config.test.mjs +30 -30
- package/package.json +6 -6
- package/src/core.ts +14 -14
- package/src/index.ts +1 -1
- package/src/manifest-json.ts +4 -4
- package/src/module-config.test.ts +30 -30
- package/src/module-config.ts +9 -9
package/dist/core.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export interface EsmxOptions {
|
|
|
71
71
|
* - client: 客户端构建目标,用于生成浏览器端运行的代码
|
|
72
72
|
* - server: 服务端构建目标,用于生成 Node.js 环境运行的代码
|
|
73
73
|
*/
|
|
74
|
-
export type
|
|
74
|
+
export type BuildEnvironment = 'client' | 'server';
|
|
75
75
|
/**
|
|
76
76
|
* Esmx 框架的命令枚举。
|
|
77
77
|
* 用于控制框架的运行模式和生命周期。
|
|
@@ -538,7 +538,7 @@ export declare class Esmx {
|
|
|
538
538
|
* - 包含模块导出信息
|
|
539
539
|
* - 记录资源依赖关系
|
|
540
540
|
*
|
|
541
|
-
* @param
|
|
541
|
+
* @param env - 目标环境类型
|
|
542
542
|
* - 'client': 客户端环境
|
|
543
543
|
* - 'server': 服务端环境
|
|
544
544
|
* @returns 返回只读的构建清单列表
|
|
@@ -560,7 +560,7 @@ export declare class Esmx {
|
|
|
560
560
|
* }
|
|
561
561
|
* ```
|
|
562
562
|
*/
|
|
563
|
-
getManifestList(
|
|
563
|
+
getManifestList(env: BuildEnvironment): Promise<readonly ManifestJson[]>;
|
|
564
564
|
/**
|
|
565
565
|
* 获取导入映射对象
|
|
566
566
|
*
|
|
@@ -579,7 +579,7 @@ export declare class Esmx {
|
|
|
579
579
|
* - 自动处理模块路径
|
|
580
580
|
* - 支持动态基础路径
|
|
581
581
|
*
|
|
582
|
-
* @param
|
|
582
|
+
* @param env - 目标环境类型
|
|
583
583
|
* - 'client': 生成浏览器环境的导入映射
|
|
584
584
|
* - 'server': 生成服务端环境的导入映射
|
|
585
585
|
* @returns 返回只读的导入映射对象
|
|
@@ -609,7 +609,7 @@ export declare class Esmx {
|
|
|
609
609
|
* }
|
|
610
610
|
* ```
|
|
611
611
|
*/
|
|
612
|
-
getImportMap(
|
|
612
|
+
getImportMap(env: BuildEnvironment): Promise<Readonly<ImportMap>>;
|
|
613
613
|
/**
|
|
614
614
|
* 获取客户端导入映射信息
|
|
615
615
|
*
|
|
@@ -679,7 +679,7 @@ export declare class Esmx {
|
|
|
679
679
|
/**
|
|
680
680
|
* 获取模块的静态导入路径列表。
|
|
681
681
|
*
|
|
682
|
-
* @param
|
|
682
|
+
* @param env - 构建目标('client' | 'server')
|
|
683
683
|
* @param specifier - 模块标识符
|
|
684
684
|
* @returns 返回静态导入路径列表,如果未找到则返回 null
|
|
685
685
|
* @throws {NotReadyError} 在框架实例未初始化时调用此方法会抛出错误
|
|
@@ -693,5 +693,5 @@ export declare class Esmx {
|
|
|
693
693
|
* );
|
|
694
694
|
* ```
|
|
695
695
|
*/
|
|
696
|
-
getStaticImportPaths(
|
|
696
|
+
getStaticImportPaths(env: BuildEnvironment, specifier: string): Promise<readonly string[] | null>;
|
|
697
697
|
}
|
package/dist/core.mjs
CHANGED
|
@@ -592,7 +592,7 @@ export class Esmx {
|
|
|
592
592
|
* - 包含模块导出信息
|
|
593
593
|
* - 记录资源依赖关系
|
|
594
594
|
*
|
|
595
|
-
* @param
|
|
595
|
+
* @param env - 目标环境类型
|
|
596
596
|
* - 'client': 客户端环境
|
|
597
597
|
* - 'server': 服务端环境
|
|
598
598
|
* @returns 返回只读的构建清单列表
|
|
@@ -614,10 +614,10 @@ export class Esmx {
|
|
|
614
614
|
* }
|
|
615
615
|
* ```
|
|
616
616
|
*/
|
|
617
|
-
async getManifestList(
|
|
617
|
+
async getManifestList(env) {
|
|
618
618
|
return this.readied.cache(
|
|
619
|
-
`getManifestList-${
|
|
620
|
-
async () => Object.freeze(await getManifestList(
|
|
619
|
+
`getManifestList-${env}`,
|
|
620
|
+
async () => Object.freeze(await getManifestList(env, this.moduleConfig))
|
|
621
621
|
);
|
|
622
622
|
}
|
|
623
623
|
/**
|
|
@@ -638,7 +638,7 @@ export class Esmx {
|
|
|
638
638
|
* - 自动处理模块路径
|
|
639
639
|
* - 支持动态基础路径
|
|
640
640
|
*
|
|
641
|
-
* @param
|
|
641
|
+
* @param env - 目标环境类型
|
|
642
642
|
* - 'client': 生成浏览器环境的导入映射
|
|
643
643
|
* - 'server': 生成服务端环境的导入映射
|
|
644
644
|
* @returns 返回只读的导入映射对象
|
|
@@ -668,12 +668,12 @@ export class Esmx {
|
|
|
668
668
|
* }
|
|
669
669
|
* ```
|
|
670
670
|
*/
|
|
671
|
-
async getImportMap(
|
|
672
|
-
return this.readied.cache(`getImportMap-${
|
|
671
|
+
async getImportMap(env) {
|
|
672
|
+
return this.readied.cache(`getImportMap-${env}`, async () => {
|
|
673
673
|
const { moduleConfig } = this.readied;
|
|
674
|
-
const manifests = await this.getManifestList(
|
|
674
|
+
const manifests = await this.getManifestList(env);
|
|
675
675
|
let json = {};
|
|
676
|
-
switch (
|
|
676
|
+
switch (env) {
|
|
677
677
|
case "client":
|
|
678
678
|
json = getImportMap({
|
|
679
679
|
manifests,
|
|
@@ -839,7 +839,7 @@ document.head.appendChild(script);
|
|
|
839
839
|
/**
|
|
840
840
|
* 获取模块的静态导入路径列表。
|
|
841
841
|
*
|
|
842
|
-
* @param
|
|
842
|
+
* @param env - 构建目标('client' | 'server')
|
|
843
843
|
* @param specifier - 模块标识符
|
|
844
844
|
* @returns 返回静态导入路径列表,如果未找到则返回 null
|
|
845
845
|
* @throws {NotReadyError} 在框架实例未初始化时调用此方法会抛出错误
|
|
@@ -853,13 +853,13 @@ document.head.appendChild(script);
|
|
|
853
853
|
* );
|
|
854
854
|
* ```
|
|
855
855
|
*/
|
|
856
|
-
async getStaticImportPaths(
|
|
856
|
+
async getStaticImportPaths(env, specifier) {
|
|
857
857
|
return this.readied.cache(
|
|
858
|
-
`getStaticImportPaths-${
|
|
858
|
+
`getStaticImportPaths-${env}-${specifier}`,
|
|
859
859
|
async () => {
|
|
860
860
|
const result = await getStaticImportPaths(
|
|
861
861
|
specifier,
|
|
862
|
-
await this.getImportMap(
|
|
862
|
+
await this.getImportMap(env),
|
|
863
863
|
this.moduleConfig
|
|
864
864
|
);
|
|
865
865
|
if (!result) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type EsmxOptions, type COMMAND, type
|
|
1
|
+
export { type EsmxOptions, type COMMAND, type BuildEnvironment, type ImportMap, type SpecifierMap, type ScopesMap, Esmx } from './core';
|
|
2
2
|
export { type ModuleConfig, type ParsedModuleConfig, parseModuleConfig } from './module-config';
|
|
3
3
|
export { type PackConfig, type ParsedPackConfig, parsePackConfig } from './pack-config';
|
|
4
4
|
export { type App, createApp } from './app';
|
package/dist/manifest-json.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BuildEnvironment } from './core';
|
|
2
2
|
import type { ParsedModuleConfig } from './module-config';
|
|
3
3
|
export interface ManifestJson {
|
|
4
4
|
/**
|
|
@@ -89,4 +89,4 @@ export interface ManifestJsonChunkSizes {
|
|
|
89
89
|
/**
|
|
90
90
|
* Get service manifest files
|
|
91
91
|
*/
|
|
92
|
-
export declare function getManifestList(
|
|
92
|
+
export declare function getManifestList(env: BuildEnvironment, moduleConfig: ParsedModuleConfig): Promise<ManifestJson[]>;
|
package/dist/manifest-json.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fsp from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
export async function getManifestList(
|
|
3
|
+
export async function getManifestList(env, moduleConfig) {
|
|
4
4
|
return Promise.all(
|
|
5
5
|
Object.values(moduleConfig.links).map(async (item) => {
|
|
6
|
-
const filename = path.resolve(item[
|
|
6
|
+
const filename = path.resolve(item[env], "manifest.json");
|
|
7
7
|
try {
|
|
8
8
|
const data = await JSON.parse(
|
|
9
9
|
await fsp.readFile(filename, "utf-8")
|
|
@@ -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 '${filename}' file read error on
|
|
15
|
+
`'${item.name}' service '${filename}' file read error on environment '${env}': ${e instanceof Error ? e.message : String(e)}`
|
|
16
16
|
);
|
|
17
17
|
}
|
|
18
18
|
})
|
package/dist/module-config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BuildEnvironment } from './core';
|
|
2
2
|
/**
|
|
3
3
|
* Core configuration interface for the module system.
|
|
4
4
|
* Defines module linking, import mapping, and export configurations.
|
|
@@ -73,13 +73,13 @@ export type ModuleConfigExportObject = {
|
|
|
73
73
|
*
|
|
74
74
|
* @example
|
|
75
75
|
* ```typescript
|
|
76
|
-
*
|
|
76
|
+
* entryPoints: {
|
|
77
77
|
* client: './src/storage/indexedDB.ts',
|
|
78
78
|
* server: './src/storage/filesystem.ts'
|
|
79
79
|
* }
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
|
-
|
|
82
|
+
entryPoints?: Record<BuildEnvironment, string | false>;
|
|
83
83
|
/**
|
|
84
84
|
* Whether to rewrite import paths within modules.
|
|
85
85
|
*
|
|
@@ -133,7 +133,7 @@ export interface ParsedModuleConfigExport {
|
|
|
133
133
|
/** Export name/identifier */
|
|
134
134
|
name: string;
|
|
135
135
|
/** Resolved input targets for different build environments */
|
|
136
|
-
|
|
136
|
+
entryPoints: Record<BuildEnvironment, string | false>;
|
|
137
137
|
/** Whether to rewrite import paths within this module */
|
|
138
138
|
rewrite: boolean;
|
|
139
139
|
}
|
package/dist/module-config.mjs
CHANGED
|
@@ -39,13 +39,13 @@ function getExports(config = {}) {
|
|
|
39
39
|
const result = {};
|
|
40
40
|
const exports = {
|
|
41
41
|
"src/entry.client": {
|
|
42
|
-
|
|
42
|
+
entryPoints: {
|
|
43
43
|
client: "./src/entry.client",
|
|
44
44
|
server: false
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"src/entry.server": {
|
|
48
|
-
|
|
48
|
+
entryPoints: {
|
|
49
49
|
client: false,
|
|
50
50
|
server: "./src/entry.server"
|
|
51
51
|
}
|
|
@@ -80,12 +80,12 @@ function getExports(config = {}) {
|
|
|
80
80
|
const opts = typeof value === "string" ? {
|
|
81
81
|
input: value
|
|
82
82
|
} : value;
|
|
83
|
-
const client = opts.
|
|
84
|
-
const server = opts.
|
|
83
|
+
const client = opts.entryPoints?.client ?? opts.input ?? name;
|
|
84
|
+
const server = opts.entryPoints?.server ?? opts.input ?? name;
|
|
85
85
|
result[name] = {
|
|
86
86
|
name,
|
|
87
87
|
rewrite: opts.rewrite ?? true,
|
|
88
|
-
|
|
88
|
+
entryPoints: {
|
|
89
89
|
client,
|
|
90
90
|
server
|
|
91
91
|
}
|
|
@@ -130,7 +130,7 @@ describe("module-config", () => {
|
|
|
130
130
|
expect(result.exports["src/entry.client"]).toEqual({
|
|
131
131
|
name: "src/entry.client",
|
|
132
132
|
rewrite: true,
|
|
133
|
-
|
|
133
|
+
entryPoints: {
|
|
134
134
|
client: "./src/entry.client",
|
|
135
135
|
server: false
|
|
136
136
|
}
|
|
@@ -138,7 +138,7 @@ describe("module-config", () => {
|
|
|
138
138
|
expect(result.exports["src/entry.server"]).toEqual({
|
|
139
139
|
name: "src/entry.server",
|
|
140
140
|
rewrite: true,
|
|
141
|
-
|
|
141
|
+
entryPoints: {
|
|
142
142
|
client: false,
|
|
143
143
|
server: "./src/entry.server"
|
|
144
144
|
}
|
|
@@ -158,7 +158,7 @@ describe("module-config", () => {
|
|
|
158
158
|
expect(result.exports.axios).toEqual({
|
|
159
159
|
name: "axios",
|
|
160
160
|
rewrite: false,
|
|
161
|
-
|
|
161
|
+
entryPoints: {
|
|
162
162
|
client: "axios",
|
|
163
163
|
server: "axios"
|
|
164
164
|
}
|
|
@@ -166,7 +166,7 @@ describe("module-config", () => {
|
|
|
166
166
|
expect(result.exports.lodash).toEqual({
|
|
167
167
|
name: "lodash",
|
|
168
168
|
rewrite: false,
|
|
169
|
-
|
|
169
|
+
entryPoints: {
|
|
170
170
|
client: "lodash",
|
|
171
171
|
server: "lodash"
|
|
172
172
|
}
|
|
@@ -188,7 +188,7 @@ describe("module-config", () => {
|
|
|
188
188
|
expect(result.exports["src/utils/format"]).toEqual({
|
|
189
189
|
name: "src/utils/format",
|
|
190
190
|
rewrite: true,
|
|
191
|
-
|
|
191
|
+
entryPoints: {
|
|
192
192
|
client: "./src/utils/format",
|
|
193
193
|
server: "./src/utils/format"
|
|
194
194
|
}
|
|
@@ -196,7 +196,7 @@ describe("module-config", () => {
|
|
|
196
196
|
expect(result.exports["src/components/Button"]).toEqual({
|
|
197
197
|
name: "src/components/Button",
|
|
198
198
|
rewrite: true,
|
|
199
|
-
|
|
199
|
+
entryPoints: {
|
|
200
200
|
client: "./src/components/Button",
|
|
201
201
|
server: "./src/components/Button"
|
|
202
202
|
}
|
|
@@ -204,7 +204,7 @@ describe("module-config", () => {
|
|
|
204
204
|
expect(result.exports["src/api/client"]).toEqual({
|
|
205
205
|
name: "src/api/client",
|
|
206
206
|
rewrite: true,
|
|
207
|
-
|
|
207
|
+
entryPoints: {
|
|
208
208
|
client: "./src/api/client",
|
|
209
209
|
server: "./src/api/client"
|
|
210
210
|
}
|
|
@@ -258,7 +258,7 @@ describe("module-config", () => {
|
|
|
258
258
|
expect(result.exports["custom-api"]).toEqual({
|
|
259
259
|
name: "custom-api",
|
|
260
260
|
rewrite: true,
|
|
261
|
-
|
|
261
|
+
entryPoints: {
|
|
262
262
|
client: "./src/api/custom.ts",
|
|
263
263
|
server: "./src/api/custom.ts"
|
|
264
264
|
}
|
|
@@ -266,7 +266,7 @@ describe("module-config", () => {
|
|
|
266
266
|
expect(result.exports.utils).toEqual({
|
|
267
267
|
name: "utils",
|
|
268
268
|
rewrite: true,
|
|
269
|
-
|
|
269
|
+
entryPoints: {
|
|
270
270
|
client: "./src/utils/index.ts",
|
|
271
271
|
server: "./src/utils/index.ts"
|
|
272
272
|
}
|
|
@@ -304,7 +304,7 @@ describe("module-config", () => {
|
|
|
304
304
|
expect(result.exports.axios).toEqual({
|
|
305
305
|
name: "axios",
|
|
306
306
|
rewrite: true,
|
|
307
|
-
|
|
307
|
+
entryPoints: {
|
|
308
308
|
client: "axios",
|
|
309
309
|
server: "axios"
|
|
310
310
|
}
|
|
@@ -312,7 +312,7 @@ describe("module-config", () => {
|
|
|
312
312
|
expect(result.exports.utils).toEqual({
|
|
313
313
|
name: "utils",
|
|
314
314
|
rewrite: true,
|
|
315
|
-
|
|
315
|
+
entryPoints: {
|
|
316
316
|
client: "./src/utils/index.ts",
|
|
317
317
|
server: "./src/utils/index.ts"
|
|
318
318
|
}
|
|
@@ -322,7 +322,7 @@ describe("module-config", () => {
|
|
|
322
322
|
const config = {
|
|
323
323
|
exports: {
|
|
324
324
|
storage: {
|
|
325
|
-
|
|
325
|
+
entryPoints: {
|
|
326
326
|
client: "./src/storage/indexedDB.ts",
|
|
327
327
|
server: "./src/storage/filesystem.ts"
|
|
328
328
|
},
|
|
@@ -342,7 +342,7 @@ describe("module-config", () => {
|
|
|
342
342
|
expect(result.exports.storage).toEqual({
|
|
343
343
|
name: "storage",
|
|
344
344
|
rewrite: true,
|
|
345
|
-
|
|
345
|
+
entryPoints: {
|
|
346
346
|
client: "./src/storage/indexedDB.ts",
|
|
347
347
|
server: "./src/storage/filesystem.ts"
|
|
348
348
|
}
|
|
@@ -350,23 +350,23 @@ describe("module-config", () => {
|
|
|
350
350
|
expect(result.exports["npm-package"]).toEqual({
|
|
351
351
|
name: "npm-package",
|
|
352
352
|
rewrite: false,
|
|
353
|
-
|
|
353
|
+
entryPoints: {
|
|
354
354
|
client: "some-package",
|
|
355
355
|
server: "some-package"
|
|
356
356
|
}
|
|
357
357
|
});
|
|
358
358
|
});
|
|
359
|
-
it("should handle
|
|
359
|
+
it("should handle entryPoints with false values", () => {
|
|
360
360
|
const config = {
|
|
361
361
|
exports: {
|
|
362
362
|
"client-only": {
|
|
363
|
-
|
|
363
|
+
entryPoints: {
|
|
364
364
|
client: "./src/client-feature.ts",
|
|
365
365
|
server: false
|
|
366
366
|
}
|
|
367
367
|
},
|
|
368
368
|
"server-only": {
|
|
369
|
-
|
|
369
|
+
entryPoints: {
|
|
370
370
|
client: false,
|
|
371
371
|
server: "./src/server-feature.ts"
|
|
372
372
|
}
|
|
@@ -381,7 +381,7 @@ describe("module-config", () => {
|
|
|
381
381
|
expect(result.exports["client-only"]).toEqual({
|
|
382
382
|
name: "client-only",
|
|
383
383
|
rewrite: true,
|
|
384
|
-
|
|
384
|
+
entryPoints: {
|
|
385
385
|
client: "./src/client-feature.ts",
|
|
386
386
|
server: false
|
|
387
387
|
}
|
|
@@ -389,7 +389,7 @@ describe("module-config", () => {
|
|
|
389
389
|
expect(result.exports["server-only"]).toEqual({
|
|
390
390
|
name: "server-only",
|
|
391
391
|
rewrite: true,
|
|
392
|
-
|
|
392
|
+
entryPoints: {
|
|
393
393
|
client: false,
|
|
394
394
|
server: "./src/server-feature.ts"
|
|
395
395
|
}
|
|
@@ -402,9 +402,9 @@ describe("module-config", () => {
|
|
|
402
402
|
exports: {
|
|
403
403
|
// Simple string mapping
|
|
404
404
|
simple: "./src/simple.ts",
|
|
405
|
-
// Complete object with
|
|
405
|
+
// Complete object with entryPoints
|
|
406
406
|
complex: {
|
|
407
|
-
|
|
407
|
+
entryPoints: {
|
|
408
408
|
client: "./src/complex.client.ts",
|
|
409
409
|
server: "./src/complex.server.ts"
|
|
410
410
|
},
|
|
@@ -428,7 +428,7 @@ describe("module-config", () => {
|
|
|
428
428
|
expect(result.exports.simple).toEqual({
|
|
429
429
|
name: "simple",
|
|
430
430
|
rewrite: true,
|
|
431
|
-
|
|
431
|
+
entryPoints: {
|
|
432
432
|
client: "./src/simple.ts",
|
|
433
433
|
server: "./src/simple.ts"
|
|
434
434
|
}
|
|
@@ -436,7 +436,7 @@ describe("module-config", () => {
|
|
|
436
436
|
expect(result.exports.complex).toEqual({
|
|
437
437
|
name: "complex",
|
|
438
438
|
rewrite: false,
|
|
439
|
-
|
|
439
|
+
entryPoints: {
|
|
440
440
|
client: "./src/complex.client.ts",
|
|
441
441
|
server: "./src/complex.server.ts"
|
|
442
442
|
}
|
|
@@ -444,7 +444,7 @@ describe("module-config", () => {
|
|
|
444
444
|
expect(result.exports["with-input"]).toEqual({
|
|
445
445
|
name: "with-input",
|
|
446
446
|
rewrite: true,
|
|
447
|
-
|
|
447
|
+
entryPoints: {
|
|
448
448
|
client: "./src/with-input.ts",
|
|
449
449
|
server: "./src/with-input.ts"
|
|
450
450
|
}
|
|
@@ -452,7 +452,7 @@ describe("module-config", () => {
|
|
|
452
452
|
expect(result.exports["with-rewrite"]).toEqual({
|
|
453
453
|
name: "with-rewrite",
|
|
454
454
|
rewrite: false,
|
|
455
|
-
|
|
455
|
+
entryPoints: {
|
|
456
456
|
client: "with-rewrite",
|
|
457
457
|
server: "with-rewrite"
|
|
458
458
|
}
|
|
@@ -480,7 +480,7 @@ describe("module-config", () => {
|
|
|
480
480
|
const config = {
|
|
481
481
|
exports: {
|
|
482
482
|
"fallback-test": {
|
|
483
|
-
// No input or
|
|
483
|
+
// No input or entryPoints specified
|
|
484
484
|
rewrite: false
|
|
485
485
|
}
|
|
486
486
|
}
|
|
@@ -490,7 +490,7 @@ describe("module-config", () => {
|
|
|
490
490
|
testRoot,
|
|
491
491
|
config
|
|
492
492
|
);
|
|
493
|
-
expect(result.exports["fallback-test"].
|
|
493
|
+
expect(result.exports["fallback-test"].entryPoints).toEqual({
|
|
494
494
|
client: "fallback-test",
|
|
495
495
|
server: "fallback-test"
|
|
496
496
|
});
|
|
@@ -600,9 +600,9 @@ describe("module-config", () => {
|
|
|
600
600
|
const exportConfig = result.exports.axios;
|
|
601
601
|
expect(typeof exportConfig.name).toBe("string");
|
|
602
602
|
expect(typeof exportConfig.rewrite).toBe("boolean");
|
|
603
|
-
expect(typeof exportConfig.
|
|
604
|
-
expect(typeof exportConfig.
|
|
605
|
-
expect(typeof exportConfig.
|
|
603
|
+
expect(typeof exportConfig.entryPoints).toBe("object");
|
|
604
|
+
expect(typeof exportConfig.entryPoints.client).toBe("string");
|
|
605
|
+
expect(typeof exportConfig.entryPoints.server).toBe("string");
|
|
606
606
|
});
|
|
607
607
|
});
|
|
608
608
|
});
|
package/package.json
CHANGED
|
@@ -52,14 +52,14 @@
|
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"lint:js": "biome check --write --no-errors-on-unmatched",
|
|
55
|
-
"lint:css": "
|
|
55
|
+
"lint:css": "pnpm run lint:js",
|
|
56
56
|
"lint:type": "tsc --noEmit",
|
|
57
57
|
"test": "vitest run --pass-with-no-tests",
|
|
58
58
|
"coverage": "vitest run --coverage --pass-with-no-tests",
|
|
59
59
|
"build": "unbuild"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@esmx/import": "3.0.0-rc.
|
|
62
|
+
"@esmx/import": "3.0.0-rc.57",
|
|
63
63
|
"@types/serialize-javascript": "^5.0.4",
|
|
64
64
|
"es-module-lexer": "^1.7.0",
|
|
65
65
|
"find": "^0.3.0",
|
|
@@ -73,11 +73,11 @@
|
|
|
73
73
|
"@types/send": "^0.17.4",
|
|
74
74
|
"@types/write": "^2.0.4",
|
|
75
75
|
"@vitest/coverage-v8": "3.2.4",
|
|
76
|
-
"typescript": "5.
|
|
77
|
-
"unbuild": "3.
|
|
76
|
+
"typescript": "5.9.2",
|
|
77
|
+
"unbuild": "3.6.0",
|
|
78
78
|
"vitest": "3.2.4"
|
|
79
79
|
},
|
|
80
|
-
"version": "3.0.0-rc.
|
|
80
|
+
"version": "3.0.0-rc.57",
|
|
81
81
|
"type": "module",
|
|
82
82
|
"private": false,
|
|
83
83
|
"exports": {
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"template",
|
|
101
101
|
"public"
|
|
102
102
|
],
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "bb3fbfa6de4906b7e98bc387c3e1d8e0c3164ac7"
|
|
104
104
|
}
|
package/src/core.ts
CHANGED
|
@@ -99,7 +99,7 @@ export interface EsmxOptions {
|
|
|
99
99
|
* - client: 客户端构建目标,用于生成浏览器端运行的代码
|
|
100
100
|
* - server: 服务端构建目标,用于生成 Node.js 环境运行的代码
|
|
101
101
|
*/
|
|
102
|
-
export type
|
|
102
|
+
export type BuildEnvironment = 'client' | 'server';
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
105
|
* Esmx 框架的命令枚举。
|
|
@@ -765,7 +765,7 @@ export class Esmx {
|
|
|
765
765
|
* - 包含模块导出信息
|
|
766
766
|
* - 记录资源依赖关系
|
|
767
767
|
*
|
|
768
|
-
* @param
|
|
768
|
+
* @param env - 目标环境类型
|
|
769
769
|
* - 'client': 客户端环境
|
|
770
770
|
* - 'server': 服务端环境
|
|
771
771
|
* @returns 返回只读的构建清单列表
|
|
@@ -788,10 +788,10 @@ export class Esmx {
|
|
|
788
788
|
* ```
|
|
789
789
|
*/
|
|
790
790
|
public async getManifestList(
|
|
791
|
-
|
|
791
|
+
env: BuildEnvironment
|
|
792
792
|
): Promise<readonly ManifestJson[]> {
|
|
793
|
-
return this.readied.cache(`getManifestList-${
|
|
794
|
-
Object.freeze(await getManifestList(
|
|
793
|
+
return this.readied.cache(`getManifestList-${env}`, async () =>
|
|
794
|
+
Object.freeze(await getManifestList(env, this.moduleConfig))
|
|
795
795
|
);
|
|
796
796
|
}
|
|
797
797
|
|
|
@@ -813,7 +813,7 @@ export class Esmx {
|
|
|
813
813
|
* - 自动处理模块路径
|
|
814
814
|
* - 支持动态基础路径
|
|
815
815
|
*
|
|
816
|
-
* @param
|
|
816
|
+
* @param env - 目标环境类型
|
|
817
817
|
* - 'client': 生成浏览器环境的导入映射
|
|
818
818
|
* - 'server': 生成服务端环境的导入映射
|
|
819
819
|
* @returns 返回只读的导入映射对象
|
|
@@ -844,13 +844,13 @@ export class Esmx {
|
|
|
844
844
|
* ```
|
|
845
845
|
*/
|
|
846
846
|
public async getImportMap(
|
|
847
|
-
|
|
847
|
+
env: BuildEnvironment
|
|
848
848
|
): Promise<Readonly<ImportMap>> {
|
|
849
|
-
return this.readied.cache(`getImportMap-${
|
|
849
|
+
return this.readied.cache(`getImportMap-${env}`, async () => {
|
|
850
850
|
const { moduleConfig } = this.readied;
|
|
851
|
-
const manifests = await this.getManifestList(
|
|
851
|
+
const manifests = await this.getManifestList(env);
|
|
852
852
|
let json: ImportMap = {};
|
|
853
|
-
switch (
|
|
853
|
+
switch (env) {
|
|
854
854
|
case 'client':
|
|
855
855
|
json = getImportMap({
|
|
856
856
|
manifests,
|
|
@@ -1042,7 +1042,7 @@ document.head.appendChild(script);
|
|
|
1042
1042
|
/**
|
|
1043
1043
|
* 获取模块的静态导入路径列表。
|
|
1044
1044
|
*
|
|
1045
|
-
* @param
|
|
1045
|
+
* @param env - 构建目标('client' | 'server')
|
|
1046
1046
|
* @param specifier - 模块标识符
|
|
1047
1047
|
* @returns 返回静态导入路径列表,如果未找到则返回 null
|
|
1048
1048
|
* @throws {NotReadyError} 在框架实例未初始化时调用此方法会抛出错误
|
|
@@ -1057,15 +1057,15 @@ document.head.appendChild(script);
|
|
|
1057
1057
|
* ```
|
|
1058
1058
|
*/
|
|
1059
1059
|
public async getStaticImportPaths(
|
|
1060
|
-
|
|
1060
|
+
env: BuildEnvironment,
|
|
1061
1061
|
specifier: string
|
|
1062
1062
|
) {
|
|
1063
1063
|
return this.readied.cache(
|
|
1064
|
-
`getStaticImportPaths-${
|
|
1064
|
+
`getStaticImportPaths-${env}-${specifier}`,
|
|
1065
1065
|
async () => {
|
|
1066
1066
|
const result = await getStaticImportPaths(
|
|
1067
1067
|
specifier,
|
|
1068
|
-
await this.getImportMap(
|
|
1068
|
+
await this.getImportMap(env),
|
|
1069
1069
|
this.moduleConfig
|
|
1070
1070
|
);
|
|
1071
1071
|
if (!result) {
|
package/src/index.ts
CHANGED
package/src/manifest-json.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fsp from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { BuildEnvironment } from './core';
|
|
5
5
|
import type { ParsedModuleConfig } from './module-config';
|
|
6
6
|
|
|
7
7
|
export interface ManifestJson {
|
|
@@ -100,12 +100,12 @@ export interface ManifestJsonChunkSizes {
|
|
|
100
100
|
* Get service manifest files
|
|
101
101
|
*/
|
|
102
102
|
export async function getManifestList(
|
|
103
|
-
|
|
103
|
+
env: BuildEnvironment,
|
|
104
104
|
moduleConfig: ParsedModuleConfig
|
|
105
105
|
): Promise<ManifestJson[]> {
|
|
106
106
|
return Promise.all(
|
|
107
107
|
Object.values(moduleConfig.links).map(async (item) => {
|
|
108
|
-
const filename = path.resolve(item[
|
|
108
|
+
const filename = path.resolve(item[env], 'manifest.json');
|
|
109
109
|
try {
|
|
110
110
|
const data: ManifestJson = await JSON.parse(
|
|
111
111
|
await fsp.readFile(filename, 'utf-8')
|
|
@@ -114,7 +114,7 @@ export async function getManifestList(
|
|
|
114
114
|
return data;
|
|
115
115
|
} catch (e) {
|
|
116
116
|
throw new Error(
|
|
117
|
-
`'${item.name}' service '${filename}' file read error on
|
|
117
|
+
`'${item.name}' service '${filename}' file read error on environment '${env}': ${e instanceof Error ? e.message : String(e)}`
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
})
|
|
@@ -182,7 +182,7 @@ describe('module-config', () => {
|
|
|
182
182
|
expect(result.exports['src/entry.client']).toEqual({
|
|
183
183
|
name: 'src/entry.client',
|
|
184
184
|
rewrite: true,
|
|
185
|
-
|
|
185
|
+
entryPoints: {
|
|
186
186
|
client: './src/entry.client',
|
|
187
187
|
server: false
|
|
188
188
|
}
|
|
@@ -191,7 +191,7 @@ describe('module-config', () => {
|
|
|
191
191
|
expect(result.exports['src/entry.server']).toEqual({
|
|
192
192
|
name: 'src/entry.server',
|
|
193
193
|
rewrite: true,
|
|
194
|
-
|
|
194
|
+
entryPoints: {
|
|
195
195
|
client: false,
|
|
196
196
|
server: './src/entry.server'
|
|
197
197
|
}
|
|
@@ -217,7 +217,7 @@ describe('module-config', () => {
|
|
|
217
217
|
expect(result.exports.axios).toEqual({
|
|
218
218
|
name: 'axios',
|
|
219
219
|
rewrite: false,
|
|
220
|
-
|
|
220
|
+
entryPoints: {
|
|
221
221
|
client: 'axios',
|
|
222
222
|
server: 'axios'
|
|
223
223
|
}
|
|
@@ -226,7 +226,7 @@ describe('module-config', () => {
|
|
|
226
226
|
expect(result.exports.lodash).toEqual({
|
|
227
227
|
name: 'lodash',
|
|
228
228
|
rewrite: false,
|
|
229
|
-
|
|
229
|
+
entryPoints: {
|
|
230
230
|
client: 'lodash',
|
|
231
231
|
server: 'lodash'
|
|
232
232
|
}
|
|
@@ -254,7 +254,7 @@ describe('module-config', () => {
|
|
|
254
254
|
expect(result.exports['src/utils/format']).toEqual({
|
|
255
255
|
name: 'src/utils/format',
|
|
256
256
|
rewrite: true,
|
|
257
|
-
|
|
257
|
+
entryPoints: {
|
|
258
258
|
client: './src/utils/format',
|
|
259
259
|
server: './src/utils/format'
|
|
260
260
|
}
|
|
@@ -263,7 +263,7 @@ describe('module-config', () => {
|
|
|
263
263
|
expect(result.exports['src/components/Button']).toEqual({
|
|
264
264
|
name: 'src/components/Button',
|
|
265
265
|
rewrite: true,
|
|
266
|
-
|
|
266
|
+
entryPoints: {
|
|
267
267
|
client: './src/components/Button',
|
|
268
268
|
server: './src/components/Button'
|
|
269
269
|
}
|
|
@@ -272,7 +272,7 @@ describe('module-config', () => {
|
|
|
272
272
|
expect(result.exports['src/api/client']).toEqual({
|
|
273
273
|
name: 'src/api/client',
|
|
274
274
|
rewrite: true,
|
|
275
|
-
|
|
275
|
+
entryPoints: {
|
|
276
276
|
client: './src/api/client',
|
|
277
277
|
server: './src/api/client'
|
|
278
278
|
}
|
|
@@ -338,7 +338,7 @@ describe('module-config', () => {
|
|
|
338
338
|
expect(result.exports['custom-api']).toEqual({
|
|
339
339
|
name: 'custom-api',
|
|
340
340
|
rewrite: true,
|
|
341
|
-
|
|
341
|
+
entryPoints: {
|
|
342
342
|
client: './src/api/custom.ts',
|
|
343
343
|
server: './src/api/custom.ts'
|
|
344
344
|
}
|
|
@@ -347,7 +347,7 @@ describe('module-config', () => {
|
|
|
347
347
|
expect(result.exports.utils).toEqual({
|
|
348
348
|
name: 'utils',
|
|
349
349
|
rewrite: true,
|
|
350
|
-
|
|
350
|
+
entryPoints: {
|
|
351
351
|
client: './src/utils/index.ts',
|
|
352
352
|
server: './src/utils/index.ts'
|
|
353
353
|
}
|
|
@@ -399,7 +399,7 @@ describe('module-config', () => {
|
|
|
399
399
|
expect(result.exports.axios).toEqual({
|
|
400
400
|
name: 'axios',
|
|
401
401
|
rewrite: true,
|
|
402
|
-
|
|
402
|
+
entryPoints: {
|
|
403
403
|
client: 'axios',
|
|
404
404
|
server: 'axios'
|
|
405
405
|
}
|
|
@@ -408,7 +408,7 @@ describe('module-config', () => {
|
|
|
408
408
|
expect(result.exports.utils).toEqual({
|
|
409
409
|
name: 'utils',
|
|
410
410
|
rewrite: true,
|
|
411
|
-
|
|
411
|
+
entryPoints: {
|
|
412
412
|
client: './src/utils/index.ts',
|
|
413
413
|
server: './src/utils/index.ts'
|
|
414
414
|
}
|
|
@@ -420,7 +420,7 @@ describe('module-config', () => {
|
|
|
420
420
|
const config: ModuleConfig = {
|
|
421
421
|
exports: {
|
|
422
422
|
storage: {
|
|
423
|
-
|
|
423
|
+
entryPoints: {
|
|
424
424
|
client: './src/storage/indexedDB.ts',
|
|
425
425
|
server: './src/storage/filesystem.ts'
|
|
426
426
|
},
|
|
@@ -444,7 +444,7 @@ describe('module-config', () => {
|
|
|
444
444
|
expect(result.exports.storage).toEqual({
|
|
445
445
|
name: 'storage',
|
|
446
446
|
rewrite: true,
|
|
447
|
-
|
|
447
|
+
entryPoints: {
|
|
448
448
|
client: './src/storage/indexedDB.ts',
|
|
449
449
|
server: './src/storage/filesystem.ts'
|
|
450
450
|
}
|
|
@@ -453,25 +453,25 @@ describe('module-config', () => {
|
|
|
453
453
|
expect(result.exports['npm-package']).toEqual({
|
|
454
454
|
name: 'npm-package',
|
|
455
455
|
rewrite: false,
|
|
456
|
-
|
|
456
|
+
entryPoints: {
|
|
457
457
|
client: 'some-package',
|
|
458
458
|
server: 'some-package'
|
|
459
459
|
}
|
|
460
460
|
});
|
|
461
461
|
});
|
|
462
462
|
|
|
463
|
-
it('should handle
|
|
463
|
+
it('should handle entryPoints with false values', () => {
|
|
464
464
|
// Arrange
|
|
465
465
|
const config: ModuleConfig = {
|
|
466
466
|
exports: {
|
|
467
467
|
'client-only': {
|
|
468
|
-
|
|
468
|
+
entryPoints: {
|
|
469
469
|
client: './src/client-feature.ts',
|
|
470
470
|
server: false
|
|
471
471
|
}
|
|
472
472
|
},
|
|
473
473
|
'server-only': {
|
|
474
|
-
|
|
474
|
+
entryPoints: {
|
|
475
475
|
client: false,
|
|
476
476
|
server: './src/server-feature.ts'
|
|
477
477
|
}
|
|
@@ -490,7 +490,7 @@ describe('module-config', () => {
|
|
|
490
490
|
expect(result.exports['client-only']).toEqual({
|
|
491
491
|
name: 'client-only',
|
|
492
492
|
rewrite: true,
|
|
493
|
-
|
|
493
|
+
entryPoints: {
|
|
494
494
|
client: './src/client-feature.ts',
|
|
495
495
|
server: false
|
|
496
496
|
}
|
|
@@ -499,7 +499,7 @@ describe('module-config', () => {
|
|
|
499
499
|
expect(result.exports['server-only']).toEqual({
|
|
500
500
|
name: 'server-only',
|
|
501
501
|
rewrite: true,
|
|
502
|
-
|
|
502
|
+
entryPoints: {
|
|
503
503
|
client: false,
|
|
504
504
|
server: './src/server-feature.ts'
|
|
505
505
|
}
|
|
@@ -515,9 +515,9 @@ describe('module-config', () => {
|
|
|
515
515
|
// Simple string mapping
|
|
516
516
|
simple: './src/simple.ts',
|
|
517
517
|
|
|
518
|
-
// Complete object with
|
|
518
|
+
// Complete object with entryPoints
|
|
519
519
|
complex: {
|
|
520
|
-
|
|
520
|
+
entryPoints: {
|
|
521
521
|
client: './src/complex.client.ts',
|
|
522
522
|
server: './src/complex.server.ts'
|
|
523
523
|
},
|
|
@@ -547,7 +547,7 @@ describe('module-config', () => {
|
|
|
547
547
|
expect(result.exports.simple).toEqual({
|
|
548
548
|
name: 'simple',
|
|
549
549
|
rewrite: true,
|
|
550
|
-
|
|
550
|
+
entryPoints: {
|
|
551
551
|
client: './src/simple.ts',
|
|
552
552
|
server: './src/simple.ts'
|
|
553
553
|
}
|
|
@@ -556,7 +556,7 @@ describe('module-config', () => {
|
|
|
556
556
|
expect(result.exports.complex).toEqual({
|
|
557
557
|
name: 'complex',
|
|
558
558
|
rewrite: false,
|
|
559
|
-
|
|
559
|
+
entryPoints: {
|
|
560
560
|
client: './src/complex.client.ts',
|
|
561
561
|
server: './src/complex.server.ts'
|
|
562
562
|
}
|
|
@@ -565,7 +565,7 @@ describe('module-config', () => {
|
|
|
565
565
|
expect(result.exports['with-input']).toEqual({
|
|
566
566
|
name: 'with-input',
|
|
567
567
|
rewrite: true,
|
|
568
|
-
|
|
568
|
+
entryPoints: {
|
|
569
569
|
client: './src/with-input.ts',
|
|
570
570
|
server: './src/with-input.ts'
|
|
571
571
|
}
|
|
@@ -574,7 +574,7 @@ describe('module-config', () => {
|
|
|
574
574
|
expect(result.exports['with-rewrite']).toEqual({
|
|
575
575
|
name: 'with-rewrite',
|
|
576
576
|
rewrite: false,
|
|
577
|
-
|
|
577
|
+
entryPoints: {
|
|
578
578
|
client: 'with-rewrite',
|
|
579
579
|
server: 'with-rewrite'
|
|
580
580
|
}
|
|
@@ -610,7 +610,7 @@ describe('module-config', () => {
|
|
|
610
610
|
const config: ModuleConfig = {
|
|
611
611
|
exports: {
|
|
612
612
|
'fallback-test': {
|
|
613
|
-
// No input or
|
|
613
|
+
// No input or entryPoints specified
|
|
614
614
|
rewrite: false
|
|
615
615
|
}
|
|
616
616
|
}
|
|
@@ -624,7 +624,7 @@ describe('module-config', () => {
|
|
|
624
624
|
);
|
|
625
625
|
|
|
626
626
|
// Assert
|
|
627
|
-
expect(result.exports['fallback-test'].
|
|
627
|
+
expect(result.exports['fallback-test'].entryPoints).toEqual({
|
|
628
628
|
client: 'fallback-test',
|
|
629
629
|
server: 'fallback-test'
|
|
630
630
|
});
|
|
@@ -790,9 +790,9 @@ describe('module-config', () => {
|
|
|
790
790
|
const exportConfig: ParsedModuleConfigExport = result.exports.axios;
|
|
791
791
|
expect(typeof exportConfig.name).toBe('string');
|
|
792
792
|
expect(typeof exportConfig.rewrite).toBe('boolean');
|
|
793
|
-
expect(typeof exportConfig.
|
|
794
|
-
expect(typeof exportConfig.
|
|
795
|
-
expect(typeof exportConfig.
|
|
793
|
+
expect(typeof exportConfig.entryPoints).toBe('object');
|
|
794
|
+
expect(typeof exportConfig.entryPoints.client).toBe('string');
|
|
795
|
+
expect(typeof exportConfig.entryPoints.server).toBe('string');
|
|
796
796
|
});
|
|
797
797
|
});
|
|
798
798
|
});
|
package/src/module-config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BuildEnvironment } from './core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Core configuration interface for the module system.
|
|
@@ -82,13 +82,13 @@ export type ModuleConfigExportObject = {
|
|
|
82
82
|
*
|
|
83
83
|
* @example
|
|
84
84
|
* ```typescript
|
|
85
|
-
*
|
|
85
|
+
* entryPoints: {
|
|
86
86
|
* client: './src/storage/indexedDB.ts',
|
|
87
87
|
* server: './src/storage/filesystem.ts'
|
|
88
88
|
* }
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
91
|
-
|
|
91
|
+
entryPoints?: Record<BuildEnvironment, string | false>;
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* Whether to rewrite import paths within modules.
|
|
@@ -157,7 +157,7 @@ export interface ParsedModuleConfigExport {
|
|
|
157
157
|
name: string;
|
|
158
158
|
|
|
159
159
|
/** Resolved input targets for different build environments */
|
|
160
|
-
|
|
160
|
+
entryPoints: Record<BuildEnvironment, string | false>;
|
|
161
161
|
|
|
162
162
|
/** Whether to rewrite import paths within this module */
|
|
163
163
|
rewrite: boolean;
|
|
@@ -258,13 +258,13 @@ function getExports(config: ModuleConfig = {}) {
|
|
|
258
258
|
|
|
259
259
|
const exports: Record<string, ModuleConfigExportObject | string> = {
|
|
260
260
|
'src/entry.client': {
|
|
261
|
-
|
|
261
|
+
entryPoints: {
|
|
262
262
|
client: './src/entry.client',
|
|
263
263
|
server: false
|
|
264
264
|
}
|
|
265
265
|
},
|
|
266
266
|
'src/entry.server': {
|
|
267
|
-
|
|
267
|
+
entryPoints: {
|
|
268
268
|
client: false,
|
|
269
269
|
server: './src/entry.server'
|
|
270
270
|
}
|
|
@@ -312,12 +312,12 @@ function getExports(config: ModuleConfig = {}) {
|
|
|
312
312
|
input: value
|
|
313
313
|
}
|
|
314
314
|
: value;
|
|
315
|
-
const client = opts.
|
|
316
|
-
const server = opts.
|
|
315
|
+
const client = opts.entryPoints?.client ?? opts.input ?? name;
|
|
316
|
+
const server = opts.entryPoints?.server ?? opts.input ?? name;
|
|
317
317
|
result[name] = {
|
|
318
318
|
name,
|
|
319
319
|
rewrite: opts.rewrite ?? true,
|
|
320
|
-
|
|
320
|
+
entryPoints: {
|
|
321
321
|
client,
|
|
322
322
|
server
|
|
323
323
|
}
|