@esmx/core 3.0.0-rc.60 → 3.0.0-rc.62

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.
@@ -1,21 +1,21 @@
1
1
  /**
2
- * 缓存处理函数的类型定义
2
+ * Type definition for cache handling function
3
3
  *
4
- * @template T - 缓存数据的类型
5
- * @param name - 缓存项的唯一标识符
6
- * @param fetch - 获取数据的异步函数
7
- * @returns 返回缓存的数据或新获取的数据
4
+ * @template T - Type of cached data
5
+ * @param name - Unique identifier for the cache item
6
+ * @param fetch - Asynchronous function to fetch data
7
+ * @returns Returns cached data or newly fetched data
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
11
  * const cache = createCache(true);
12
12
  *
13
- * // 第一次调用会执行 fetch 函数
13
+ * // First call will execute the fetch function
14
14
  * const data1 = await cache('key', async () => {
15
15
  * return await fetchSomeData();
16
16
  * });
17
17
  *
18
- * // 第二次调用会直接返回缓存的结果
18
+ * // Second call will directly return the cached result
19
19
  * const data2 = await cache('key', async () => {
20
20
  * return await fetchSomeData();
21
21
  * });
@@ -23,24 +23,24 @@
23
23
  */
24
24
  export type CacheHandle = <T>(name: string, fetch: () => Promise<T>) => Promise<T>;
25
25
  /**
26
- * 创建一个缓存处理函数
26
+ * Create a cache handling function
27
27
  *
28
- * @param enable - 是否启用缓存功能
29
- * @returns 返回一个缓存处理函数
28
+ * @param enable - Whether to enable caching functionality
29
+ * @returns Returns a cache handling function
30
30
  *
31
31
  * @description
32
- * enable true 时,会创建一个带有内存缓存的处理函数,相同的 name 只会执行一次 fetch
33
- * enable false 时,每次调用都会执行 fetch 函数,不会缓存结果。
32
+ * When enable is true, it creates a processing function with memory cache, the same name will only execute fetch once.
33
+ * When enable is false, each call will execute the fetch function and will not cache the result.
34
34
  *
35
35
  * @example
36
36
  * ```ts
37
- * // 创建一个启用缓存的处理函数
37
+ * // Create a cache-enabled processing function
38
38
  * const cacheEnabled = createCache(true);
39
39
  *
40
- * // 创建一个禁用缓存的处理函数
40
+ * // Create a cache-disabled processing function
41
41
  * const cacheDisabled = createCache(false);
42
42
  *
43
- * // 使用缓存处理函数
43
+ * // Use the cache processing function
44
44
  * const result = await cacheEnabled('userProfile', async () => {
45
45
  * return await fetchUserProfile(userId);
46
46
  * });
@@ -1,18 +1,18 @@
1
1
  import type { IncomingMessage, ServerResponse } from 'node:http';
2
2
  import type { Esmx } from '../core';
3
3
  /**
4
- * 中间件函数类型定义
4
+ * Middleware function type definition
5
5
  *
6
6
  * @description
7
- * 中间件是一个函数,用于处理 HTTP 请求。它接收请求对象、响应对象和下一个中间件函数作为参数。
8
- * 中间件可以执行以下操作:
9
- * - 修改请求和响应对象
10
- * - 结束请求-响应循环
11
- * - 调用下一个中间件
7
+ * Middleware is a function used to handle HTTP requests. It receives the request object, response object, and the next middleware function as parameters.
8
+ * Middleware can perform the following operations:
9
+ * - Modify request and response objects
10
+ * - End the request-response cycle
11
+ * - Call the next middleware
12
12
  *
13
13
  * @example
14
14
  * ```ts
15
- * // 创建一个简单的日志中间件
15
+ * // Create a simple logging middleware
16
16
  * const loggerMiddleware: Middleware = (req, res, next) => {
17
17
  * console.log(`${req.method} ${req.url}`);
18
18
  * next();
@@ -21,21 +21,21 @@ import type { Esmx } from '../core';
21
21
  */
22
22
  export type Middleware = (req: IncomingMessage, res: ServerResponse, next: Function) => void;
23
23
  /**
24
- * 判断文件路径是否是一个符合 esmx 规范的不可变文件
25
- * @param path 文件路径
24
+ * Determine if a file path is an immutable file that complies with esmx specifications
25
+ * @param path File path
26
26
  */
27
27
  export declare function isImmutableFile(filename: string): boolean;
28
28
  /**
29
- * 创建 Esmx 应用的中间件
29
+ * Create middleware for Esmx application
30
30
  *
31
- * @param esmx - Esmx 实例
32
- * @returns 返回一个处理静态资源的中间件
31
+ * @param esmx - Esmx instance
32
+ * @returns Returns a middleware that handles static resources
33
33
  *
34
34
  * @description
35
- * 该函数创建一个中间件,用于处理模块的静态资源请求。它会:
36
- * - 根据模块配置创建对应的静态资源中间件
37
- * - 处理资源的缓存控制
38
- * - 支持不可变文件的长期缓存
35
+ * This function creates a middleware to handle static resource requests for modules. It will:
36
+ * - Create corresponding static resource middleware based on module configuration
37
+ * - Handle cache control for resources
38
+ * - Support long-term caching for immutable files
39
39
  *
40
40
  * @example
41
41
  * ```ts
@@ -44,14 +44,14 @@ export declare function isImmutableFile(filename: string): boolean;
44
44
  * const esmx = new Esmx();
45
45
  * const middleware = createMiddleware(esmx);
46
46
  *
47
- * // HTTP 服务器中使用
47
+ * // Use in HTTP server
48
48
  * server.use(middleware);
49
49
  * ```
50
50
  */
51
51
  export declare function createMiddleware(esmx: Esmx): Middleware;
52
52
  /**
53
- * 将多个中间件,合并成一个中间件执行
54
- * @param middlewares 中间件列表
53
+ * Merge multiple middlewares into one middleware execution
54
+ * @param middlewares List of middlewares
55
55
  * @returns
56
56
  */
57
57
  export declare function mergeMiddlewares(middlewares: Middleware[]): Middleware;
@@ -2,26 +2,26 @@ import type fs from 'node:fs';
2
2
  import type { ImportMap, SpecifierMap } from '@esmx/import';
3
3
  import type { ParsedModuleConfig } from '../module-config';
4
4
  /**
5
- * JS 代码中获取静态 import 的模块名列表。也许不能并发多个调用,没实验过。
6
- * @param code js 代码
7
- * @returns `Promise<string[]>` 静态 import 的模块名列表
5
+ * Get the list of statically imported module names from JS code. Maybe cannot handle multiple concurrent calls, not tested.
6
+ * @param code JS code
7
+ * @returns `Promise<string[]>` List of statically imported module names
8
8
  */
9
9
  export declare function getImportsFromJsCode(code: string): Promise<string[]>;
10
10
  /**
11
- * JS 文件中获取静态 import 的模块名列表。
12
- * @param filepath js 文件路径
13
- * @returns `Promise<string[]>` 静态 import 的模块名列表
11
+ * Get the list of statically imported module names from a JS file.
12
+ * @param filepath JS file path
13
+ * @returns `Promise<string[]>` List of statically imported module names
14
14
  */
15
15
  export declare function getImportsFromJsFile(filepath: fs.PathLike | fs.promises.FileHandle): Promise<string[]>;
16
16
  export type ImportPreloadInfo = SpecifierMap;
17
17
  /**
18
- * 获取导入的预加载信息。
19
- * @param specifier 模块名
20
- * @param importMap 导入映射对象
21
- * @param moduleConfig 模块配置
18
+ * Get import preload information.
19
+ * @param specifier Module name
20
+ * @param importMap Import map object
21
+ * @param moduleConfig Module configuration
22
22
  * @returns
23
- * - `Promise<{ [specifier: string]: ImportPreloadPathString }>` 模块名和文件路径的映射对象
24
- * - `null` specifier 不存在
23
+ * - `Promise<{ [specifier: string]: ImportPreloadPathString }>` Mapping object of module names to file paths
24
+ * - `null` specifier does not exist
25
25
  */
26
26
  export declare function getImportPreloadInfo(specifier: string, importMap: ImportMap, moduleConfig: ParsedModuleConfig): Promise<{
27
27
  [k: string]: string;
@@ -16,7 +16,7 @@ export async function getImportPreloadInfo(specifier, importMap, moduleConfig) {
16
16
  return null;
17
17
  }
18
18
  const ans = {
19
- // 入口文件也放入预加载列表
19
+ // Entry file is also added to the preload list
20
20
  [specifier]: importInfo[specifier]
21
21
  };
22
22
  const needHandles = [specifier];
package/package.json CHANGED
@@ -59,7 +59,7 @@
59
59
  "build": "unbuild"
60
60
  },
61
61
  "dependencies": {
62
- "@esmx/import": "3.0.0-rc.60",
62
+ "@esmx/import": "3.0.0-rc.62",
63
63
  "@types/serialize-javascript": "^5.0.4",
64
64
  "es-module-lexer": "^1.7.0",
65
65
  "find": "^0.3.0",
@@ -77,7 +77,7 @@
77
77
  "unbuild": "3.6.0",
78
78
  "vitest": "3.2.4"
79
79
  },
80
- "version": "3.0.0-rc.60",
80
+ "version": "3.0.0-rc.62",
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": "615e91c617e0a58796c591643c6a2e1d2a1f0a76"
103
+ "gitHead": "e5a1e811403bf1db4437dff88c3ea8bc6b576f64"
104
104
  }
package/src/app.ts CHANGED
@@ -9,21 +9,21 @@ import {
9
9
  import { type Middleware, createMiddleware } from './utils/middleware';
10
10
 
11
11
  /**
12
- * 应用程序实例接口。
12
+ * Application instance interface.
13
13
  *
14
- * App Esmx 框架的应用抽象,提供了统一的接口来管理应用的生命周期、
15
- * 静态资源和服务端渲染。
14
+ * App is the application abstraction of the Esmx framework, providing a unified interface
15
+ * to manage application lifecycle, static assets, and server-side rendering.
16
16
  *
17
17
  * @example
18
18
  * ```ts
19
19
  * // entry.node.ts
20
20
  * export default {
21
- * // 开发环境配置
21
+ * // Development environment configuration
22
22
  * async devApp(esmx) {
23
23
  * return import('@esmx/rspack').then((m) =>
24
24
  * m.createRspackHtmlApp(esmx, {
25
25
  * config(rc) {
26
- * // 自定义 Rspack 配置
26
+ * // Custom Rspack configuration
27
27
  * }
28
28
  * })
29
29
  * );
@@ -33,17 +33,17 @@ import { type Middleware, createMiddleware } from './utils/middleware';
33
33
  */
34
34
  export interface App {
35
35
  /**
36
- * 静态资源处理中间件。
36
+ * Static asset processing middleware.
37
37
  *
38
- * 开发环境:
39
- * - 处理源码的静态资源请求
40
- * - 支持实时编译和热更新
41
- * - 使用 no-cache 缓存策略
38
+ * Development environment:
39
+ * - Handles static asset requests from source code
40
+ * - Supports real-time compilation and hot reloading
41
+ * - Uses no-cache strategy
42
42
  *
43
- * 生产环境:
44
- * - 处理构建后的静态资源
45
- * - 支持不可变文件的长期缓存(.final.xxx
46
- * - 优化的资源加载策略
43
+ * Production environment:
44
+ * - Handles built static assets
45
+ * - Supports long-term caching for immutable files (.final.xxx)
46
+ * - Optimized asset loading strategy
47
47
  *
48
48
  * @example
49
49
  * ```ts
@@ -53,14 +53,14 @@ export interface App {
53
53
  middleware: Middleware;
54
54
 
55
55
  /**
56
- * 服务端渲染函数。
56
+ * Server-side rendering function.
57
57
  *
58
- * 根据运行环境提供不同实现:
59
- * - 生产环境(start):加载构建后的服务端入口文件(entry.server)执行渲染
60
- * - 开发环境(dev):加载源码中的服务端入口文件执行渲染
58
+ * Provides different implementations based on the runtime environment:
59
+ * - Production environment (start): Loads the built server entry file (entry.server) to execute rendering
60
+ * - Development environment (dev): Loads the server entry file from source code to execute rendering
61
61
  *
62
- * @param options - 渲染选项
63
- * @returns 返回渲染上下文,包含渲染结果
62
+ * @param options - Rendering options
63
+ * @returns Returns the rendering context containing the rendering result
64
64
  *
65
65
  * @example
66
66
  * ```ts
@@ -73,30 +73,30 @@ export interface App {
73
73
  render: (options?: RenderContextOptions) => Promise<RenderContext>;
74
74
 
75
75
  /**
76
- * 生产环境构建函数。
77
- * 用于资源打包和优化。
76
+ * Production environment build function.
77
+ * Used for asset packaging and optimization.
78
78
  *
79
- * @returns 构建成功返回 true,失败返回 false
79
+ * @returns Returns true for successful build, false for failed build
80
80
  */
81
81
  build?: () => Promise<boolean>;
82
82
 
83
83
  /**
84
- * 资源清理函数。
85
- * 用于关闭服务器、断开连接等。
84
+ * Resource cleanup function.
85
+ * Used for shutting down servers, disconnecting connections, etc.
86
86
  *
87
- * @returns 清理成功返回 true,失败返回 false
87
+ * @returns Returns true for successful cleanup, false for failed cleanup
88
88
  */
89
89
  destroy?: () => Promise<boolean>;
90
90
  }
91
91
 
92
92
  /**
93
- * 创建生产环境的应用程序实例,开发环境不可用。
93
+ * Create an application instance for production environment, not available in development environment.
94
94
  */
95
95
  export async function createApp(esmx: Esmx, command: COMMAND): Promise<App> {
96
96
  const render =
97
97
  command === esmx.COMMAND.start
98
- ? await createStartRender(esmx) // 提供实际的渲染函数
99
- : createErrorRender(esmx); // 提供错误提示渲染函数
98
+ ? await createStartRender(esmx) // Provides actual rendering function
99
+ : createErrorRender(esmx); // Provides error prompt rendering function
100
100
  return {
101
101
  middleware: createMiddleware(esmx),
102
102
  render
@@ -104,16 +104,16 @@ export async function createApp(esmx: Esmx, command: COMMAND): Promise<App> {
104
104
  }
105
105
 
106
106
  /**
107
- * 创建生产环境渲染函数。
108
- * 加载构建后的服务端入口文件(entry.server)执行渲染。
107
+ * Create production environment rendering function.
108
+ * Loads the built server entry file (entry.server) to execute rendering.
109
109
  *
110
- * @param esmx - Esmx 实例
111
- * @returns 返回渲染函数
110
+ * @param esmx - Esmx instance
111
+ * @returns Returns the rendering function
112
112
  * @internal
113
113
  *
114
114
  * @example
115
115
  * ```ts
116
- * // 服务端入口文件 (entry.server)
116
+ * // Server entry file (entry.server)
117
117
  * export default async function render(rc: RenderContext) {
118
118
  * rc.html = '<html>...</html>';
119
119
  * }