@esmx/rspack 3.0.0-rc.53 → 3.0.0-rc.55

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.
@@ -0,0 +1,105 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { PRESET_TARGETS, getTargetSetting } from "./target-setting.mjs";
3
+ describe("getTargetSetting", () => {
4
+ const buildTargets = ["client", "server", "node"];
5
+ describe("when setting is undefined", () => {
6
+ it("should return compatible preset for all build targets", () => {
7
+ buildTargets.forEach((buildTarget) => {
8
+ const result = getTargetSetting(void 0, buildTarget);
9
+ expect(result).toEqual(PRESET_TARGETS.compatible[buildTarget]);
10
+ });
11
+ });
12
+ });
13
+ describe("when setting is a string preset", () => {
14
+ it("should return compatible preset for all build targets", () => {
15
+ buildTargets.forEach((buildTarget) => {
16
+ const result = getTargetSetting("compatible", buildTarget);
17
+ expect(result).toEqual(PRESET_TARGETS.compatible[buildTarget]);
18
+ });
19
+ });
20
+ it("should return modern preset for all build targets", () => {
21
+ buildTargets.forEach((buildTarget) => {
22
+ const result = getTargetSetting("modern", buildTarget);
23
+ expect(result).toEqual(PRESET_TARGETS.modern[buildTarget]);
24
+ });
25
+ });
26
+ });
27
+ describe("when setting is a custom array", () => {
28
+ const customTargets = ["chrome>=90", "firefox>=80", "safari>=14"];
29
+ it("should return the custom array for all build targets", () => {
30
+ buildTargets.forEach((buildTarget) => {
31
+ const result = getTargetSetting(customTargets, buildTarget);
32
+ expect(result).toEqual(customTargets);
33
+ });
34
+ });
35
+ });
36
+ describe("when setting is an object with specific build targets", () => {
37
+ it("should return specified preset for configured build targets", () => {
38
+ const setting = {
39
+ client: "modern",
40
+ server: "compatible"
41
+ };
42
+ expect(getTargetSetting(setting, "client")).toEqual(
43
+ PRESET_TARGETS.modern.client
44
+ );
45
+ expect(getTargetSetting(setting, "server")).toEqual(
46
+ PRESET_TARGETS.compatible.server
47
+ );
48
+ });
49
+ it("should return compatible preset for unconfigured build targets", () => {
50
+ const setting = {
51
+ client: "modern"
52
+ };
53
+ expect(getTargetSetting(setting, "client")).toEqual(
54
+ PRESET_TARGETS.modern.client
55
+ );
56
+ expect(getTargetSetting(setting, "server")).toEqual(
57
+ PRESET_TARGETS.compatible.server
58
+ );
59
+ expect(getTargetSetting(setting, "node")).toEqual(
60
+ PRESET_TARGETS.compatible.node
61
+ );
62
+ });
63
+ it("should return custom array for configured build targets", () => {
64
+ const customClientTargets = ["chrome>=90", "firefox>=80"];
65
+ const customServerTargets = ["node>=18"];
66
+ const setting = {
67
+ client: customClientTargets,
68
+ server: customServerTargets
69
+ };
70
+ expect(getTargetSetting(setting, "client")).toEqual(
71
+ customClientTargets
72
+ );
73
+ expect(getTargetSetting(setting, "server")).toEqual(
74
+ customServerTargets
75
+ );
76
+ expect(getTargetSetting(setting, "node")).toEqual(
77
+ PRESET_TARGETS.compatible.node
78
+ );
79
+ });
80
+ it("should handle mixed preset and custom configurations", () => {
81
+ const setting = {
82
+ client: "modern",
83
+ server: ["node>=18"],
84
+ node: "compatible"
85
+ };
86
+ expect(getTargetSetting(setting, "client")).toEqual(
87
+ PRESET_TARGETS.modern.client
88
+ );
89
+ expect(getTargetSetting(setting, "server")).toEqual(["node>=18"]);
90
+ expect(getTargetSetting(setting, "node")).toEqual(
91
+ PRESET_TARGETS.compatible.node
92
+ );
93
+ });
94
+ });
95
+ describe("edge cases", () => {
96
+ it("should handle empty custom array", () => {
97
+ const result = getTargetSetting([], "client");
98
+ expect(result).toEqual([]);
99
+ });
100
+ it("should handle single item custom array", () => {
101
+ const result = getTargetSetting(["chrome>=90"], "client");
102
+ expect(result).toEqual(["chrome>=90"]);
103
+ });
104
+ });
105
+ });
package/package.json CHANGED
@@ -63,8 +63,8 @@
63
63
  }
64
64
  },
65
65
  "dependencies": {
66
- "@esmx/import": "3.0.0-rc.53",
67
- "@esmx/rspack-module-link-plugin": "3.0.0-rc.53",
66
+ "@esmx/import": "3.0.0-rc.55",
67
+ "@esmx/rspack-module-link-plugin": "3.0.0-rc.55",
68
68
  "@npmcli/arborist": "^9.0.1",
69
69
  "@rspack/core": "1.4.8",
70
70
  "css-loader": "^7.1.2",
@@ -80,7 +80,7 @@
80
80
  },
81
81
  "devDependencies": {
82
82
  "@biomejs/biome": "1.9.4",
83
- "@esmx/core": "3.0.0-rc.53",
83
+ "@esmx/core": "3.0.0-rc.55",
84
84
  "@types/node": "^24.0.0",
85
85
  "@types/npmcli__arborist": "^6.3.1",
86
86
  "@types/pacote": "^11.1.8",
@@ -91,7 +91,7 @@
91
91
  "unbuild": "3.5.0",
92
92
  "vitest": "3.2.4"
93
93
  },
94
- "version": "3.0.0-rc.53",
94
+ "version": "3.0.0-rc.55",
95
95
  "type": "module",
96
96
  "private": false,
97
97
  "exports": {
@@ -110,5 +110,5 @@
110
110
  "template",
111
111
  "public"
112
112
  ],
113
- "gitHead": "e76fe45c0af262d52944c038f04e62b3b0fca3f7"
113
+ "gitHead": "e7d0c88a376ad5bd3d88a48240e4ed4891c0b275"
114
114
  }
package/src/rspack/app.ts CHANGED
@@ -26,13 +26,13 @@ const hotFixCode = fs.readFileSync(
26
26
  );
27
27
 
28
28
  /**
29
- * Rspack 应用配置上下文接口。
29
+ * Rspack application configuration context interface.
30
30
  *
31
- * 该接口提供了在配置钩子函数中可以访问的上下文信息,允许你:
32
- * - 访问 Esmx 框架实例
33
- * - 获取当前的构建目标(client/server/node
34
- * - 修改 Rspack 配置
35
- * - 访问应用选项
31
+ * This interface provides context information accessible in configuration hook functions, allowing you to:
32
+ * - Access the Esmx framework instance
33
+ * - Get the current build target (client/server/node)
34
+ * - Modify Rspack configuration
35
+ * - Access application options
36
36
  *
37
37
  * @example
38
38
  * ```ts
@@ -41,11 +41,11 @@ const hotFixCode = fs.readFileSync(
41
41
  * async devApp(esmx) {
42
42
  * return import('@esmx/rspack').then((m) =>
43
43
  * m.createRspackApp(esmx, {
44
- * // 配置钩子函数
44
+ * // Configuration hook function
45
45
  * config(context) {
46
- * // 访问构建目标
46
+ * // Access build target
47
47
  * if (context.buildTarget === 'client') {
48
- * // 修改客户端构建配置
48
+ * // Modify client build configuration
49
49
  * context.config.optimization = {
50
50
  * ...context.config.optimization,
51
51
  * splitChunks: {
@@ -62,73 +62,73 @@ const hotFixCode = fs.readFileSync(
62
62
  */
63
63
  export interface RspackAppConfigContext {
64
64
  /**
65
- * Esmx 框架实例。
66
- * 可用于访问框架提供的 API 和工具函数。
65
+ * Esmx framework instance.
66
+ * Can be used to access framework APIs and utility functions.
67
67
  */
68
68
  esmx: Esmx;
69
69
 
70
70
  /**
71
- * 当前的构建目标。
72
- * - 'client': 客户端构建,生成浏览器可执行的代码
73
- * - 'server': 服务端构建,生成 SSR 渲染代码
74
- * - 'node': Node.js 构建,生成服务器入口代码
71
+ * Current build target.
72
+ * - 'client': Client build, generates browser-executable code
73
+ * - 'server': Server build, generates SSR rendering code
74
+ * - 'node': Node.js build, generates server entry code
75
75
  */
76
76
  buildTarget: BuildTarget;
77
77
 
78
78
  /**
79
- * Rspack 编译配置对象。
80
- * 你可以在配置钩子中修改这个对象来自定义构建行为。
79
+ * Rspack compilation configuration object.
80
+ * You can modify this object in configuration hooks to customize build behavior.
81
81
  */
82
82
  config: RspackOptions;
83
83
 
84
84
  /**
85
- * 创建应用时传入的选项对象。
85
+ * Options object passed when creating the application.
86
86
  */
87
87
  options: RspackAppOptions;
88
88
  }
89
89
 
90
90
  /**
91
- * Rspack 链式配置上下文接口。
91
+ * Rspack chain configuration context interface.
92
92
  *
93
- * 该接口提供了在 chain 钩子函数中可以访问的上下文信息,允许你:
94
- * - 访问 Esmx 框架实例
95
- * - 获取当前的构建目标(client/server/node
96
- * - 使用 rspack-chain 修改配置
97
- * - 访问应用选项
93
+ * This interface provides context information accessible in chain hook functions, allowing you to:
94
+ * - Access the Esmx framework instance
95
+ * - Get the current build target (client/server/node)
96
+ * - Modify configuration using rspack-chain
97
+ * - Access application options
98
98
  */
99
99
  export interface RspackAppChainContext {
100
100
  /**
101
- * Esmx 框架实例。
102
- * 可用于访问框架提供的 API 和工具函数。
101
+ * Esmx framework instance.
102
+ * Can be used to access framework APIs and utility functions.
103
103
  */
104
104
  esmx: Esmx;
105
105
 
106
106
  /**
107
- * 当前的构建目标。
108
- * - 'client': 客户端构建,生成浏览器可执行的代码
109
- * - 'server': 服务端构建,生成 SSR 渲染代码
110
- * - 'node': Node.js 构建,生成服务器入口代码
107
+ * Current build target.
108
+ * - 'client': Client build, generates browser-executable code
109
+ * - 'server': Server build, generates SSR rendering code
110
+ * - 'node': Node.js build, generates server entry code
111
111
  */
112
112
  buildTarget: BuildTarget;
113
113
 
114
114
  /**
115
- * rspack-chain 配置对象。
116
- * 你可以在 chain 钩子中使用链式 API 修改配置。
115
+ * rspack-chain configuration object.
116
+ * You can use the chain API in chain hooks to modify the configuration.
117
117
  */
118
118
  chain: import('rspack-chain');
119
119
 
120
120
  /**
121
- * 创建应用时传入的选项对象。
121
+ * Options object passed when creating the application.
122
122
  */
123
123
  options: RspackAppOptions;
124
124
  }
125
125
 
126
126
  /**
127
- * Rspack 应用配置选项接口。
127
+ * Rspack application configuration options interface.
128
128
  *
129
- * 该接口提供了创建 Rspack 应用时可以使用的配置选项,包括:
130
- * - 代码压缩选项
131
- * - Rspack 配置钩子函数
129
+ * This interface provides configuration options available when creating a Rspack application, including:
130
+ * - Code compression options
131
+ * - Rspack configuration hook functions
132
132
  *
133
133
  * @example
134
134
  * ```ts
@@ -137,9 +137,9 @@ export interface RspackAppChainContext {
137
137
  * async devApp(esmx) {
138
138
  * return import('@esmx/rspack').then((m) =>
139
139
  * m.createRspackApp(esmx, {
140
- * // 禁用代码压缩
140
+ * // Disable code compression
141
141
  * minimize: false,
142
- * // 自定义 Rspack 配置
142
+ * // Custom Rspack configuration
143
143
  * config(context) {
144
144
  * if (context.buildTarget === 'client') {
145
145
  * context.config.optimization.splitChunks = {
@@ -155,47 +155,43 @@ export interface RspackAppChainContext {
155
155
  */
156
156
  export interface RspackAppOptions {
157
157
  /**
158
- * 是否启用代码压缩。
158
+ * Whether to enable code compression.
159
159
  *
160
- * - true: 启用代码压缩
161
- * - false: 禁用代码压缩
162
- * - undefined: 根据环境自动判断(生产环境启用,开发环境禁用)
160
+ * - true: Enable code compression
161
+ * - false: Disable code compression
162
+ * - undefined: Automatically determine based on environment (enabled in production, disabled in development)
163
163
  *
164
164
  * @default undefined
165
165
  */
166
166
  minimize?: boolean;
167
167
 
168
168
  /**
169
- * Rspack 配置钩子函数。
169
+ * Called before the build starts, this function allows you to modify the Rspack compilation configuration.
170
+ * Supports differentiated configuration for different build targets (client/server/node).
170
171
  *
171
- * 在构建开始前调用,可以通过该函数修改 Rspack 的编译配置。
172
- * 支持针对不同的构建目标(client/server/node)进行差异化配置。
173
- *
174
- * @param context - 配置上下文,包含框架实例、构建目标和配置对象
172
+ * @param context - Configuration context, containing framework instance, build target, and configuration object
175
173
  */
176
174
  config?: (context: RspackAppConfigContext) => void;
177
175
 
178
176
  /**
179
- * Rspack chain 配置钩子函数。
180
- *
181
- * 使用 rspack-chain 提供链式配置方式,可以更灵活地修改 Rspack 配置。
182
- * 在 config 钩子之后调用,如果有 chain 钩子则优先使用链式配置。
177
+ * Uses rspack-chain to provide chained configuration method, allowing more flexible modification of Rspack configuration.
178
+ * Called after the config hook, if chain hook exists, chained configuration is preferred.
183
179
  *
184
- * @param context - 配置上下文,包含框架实例、构建目标和 chain 配置对象
180
+ * @param context - Configuration context, containing framework instance, build target, and chain configuration object
185
181
  */
186
182
  chain?: (context: RspackAppChainContext) => void;
187
183
  }
188
184
 
189
185
  /**
190
- * 创建 Rspack 应用实例。
186
+ * Create Rspack application instance.
191
187
  *
192
- * 该函数根据运行环境(开发/生产)创建不同的应用实例:
193
- * - 开发环境:配置热更新中间件和实时渲染
194
- * - 生产环境:配置构建任务
188
+ * This function creates different application instances based on the runtime environment (development/production):
189
+ * - Development environment: Configures hot update middleware and real-time rendering
190
+ * - Production environment: Configures build tasks
195
191
  *
196
- * @param esmx - Esmx 框架实例
197
- * @param options - Rspack 应用配置选项
198
- * @returns 返回应用实例
192
+ * @param esmx - Esmx framework instance
193
+ * @param options - Rspack application configuration options
194
+ * @returns Returns application instance
199
195
  *
200
196
  * @example
201
197
  * ```ts
@@ -205,7 +201,7 @@ export interface RspackAppOptions {
205
201
  * return import('@esmx/rspack').then((m) =>
206
202
  * m.createRspackApp(esmx, {
207
203
  * config(context) {
208
- * // 配置 loader 处理不同类型的文件
204
+ * // Configure loader to handle different file types
209
205
  * context.config.module = {
210
206
  * rules: [
211
207
  * {
@@ -259,8 +255,6 @@ async function createMiddleware(
259
255
  if (esmx.command !== esmx.COMMAND.dev) {
260
256
  return [];
261
257
  }
262
- // const middlewares: Middleware[] = [];
263
-
264
258
  const rsBuild = createRsBuild([
265
259
  generateBuildConfig(esmx, options, 'client'),
266
260
  generateBuildConfig(esmx, options, 'server')
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * Build target environment type
3
- * @description Defines the build target environment for the application, used to configure specific optimizations and features during the build process
4
- * - node: Build code to run in Node.js environment
5
- * - client: Build code to run in browser environment
6
- * - server: Build code to run in server environment
3
+ * - node: Node.js environment build
4
+ * - client: Browser environment build
5
+ * - server: Server-side rendering build
7
6
  */
8
7
  export type BuildTarget = 'node' | 'client' | 'server';
@@ -13,7 +13,7 @@ import type { BuildTarget } from './build-target';
13
13
  import { HMR_DIR, HMR_JSONP } from './hmr-config';
14
14
 
15
15
  /**
16
- * 构建 ClientServerNode 的基础配置
16
+ * Base configuration for building Client, Server, and Node targets
17
17
  */
18
18
  export function createRspackConfig(
19
19
  esmx: Esmx,
@@ -23,7 +23,7 @@ export function createRspackConfig(
23
23
  const isHot = buildTarget === 'client' && !esmx.isProd;
24
24
  return {
25
25
  /**
26
- * 项目根目录,不可修改
26
+ * Project root directory, cannot be modified
27
27
  */
28
28
  context: esmx.root,
29
29
  output: {
@@ -5,32 +5,11 @@ function resolve(name: string) {
5
5
  }
6
6
 
7
7
  export const RSPACK_LOADER = {
8
- /**
9
- * Rspack 内置的 builtin:swc-loader
10
- */
11
8
  builtinSwcLoader: 'builtin:swc-loader',
12
- /**
13
- * Rspack 内置的 lightningcss-loader
14
- */
15
9
  lightningcssLoader: 'builtin:lightningcss-loader',
16
- /**
17
- * css-loader
18
- */
19
10
  cssLoader: resolve('css-loader'),
20
- /**
21
- * style-loader
22
- */
23
11
  styleLoader: resolve('style-loader'),
24
- /**
25
- * less-loader
26
- */
27
12
  lessLoader: resolve('less-loader'),
28
- /**
29
- * style-resources-loader
30
- */
31
13
  styleResourcesLoader: resolve('style-resources-loader'),
32
- /**
33
- * worker-rspack-loader
34
- */
35
14
  workerRspackLoader: resolve('worker-rspack-loader')
36
15
  } satisfies Record<string, string>;
@@ -51,7 +51,7 @@ export function createRsBuild(options: RspackOptions[]) {
51
51
  }
52
52
  });
53
53
 
54
- // 监听进程信号,确保优雅退出
54
+ // Listen to process signals to ensure graceful shutdown
55
55
  const signals = ['SIGINT', 'SIGTERM', 'SIGHUP'] satisfies string[];
56
56
  signals.forEach((signal) => {
57
57
  process.on(signal, () => {
@@ -61,7 +61,7 @@ export function createRsBuild(options: RspackOptions[]) {
61
61
  });
62
62
  });
63
63
 
64
- // 监听未捕获的异常和 Promise 拒绝
64
+ // Listen to uncaught exceptions and Promise rejections
65
65
  process.on('uncaughtException', handleExit);
66
66
  process.on('unhandledRejection', handleExit);
67
67