@esmx/core 3.0.0-rc.60 → 3.0.0-rc.63
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/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/dist/app.d.ts +27 -27
- package/dist/core.d.ts +274 -272
- package/dist/core.mjs +235 -232
- package/dist/pack-config.d.ts +92 -92
- package/dist/render-context.d.ts +465 -465
- package/dist/render-context.mjs +338 -338
- package/dist/utils/cache.d.ts +15 -15
- package/dist/utils/import-map.d.ts +31 -1
- package/dist/utils/import-map.mjs +18 -0
- package/dist/utils/import-map.test.mjs +577 -1
- package/dist/utils/middleware.d.ts +19 -19
- package/dist/utils/static-import-lexer.d.ts +12 -12
- package/dist/utils/static-import-lexer.mjs +1 -1
- package/package.json +3 -3
- package/src/app.ts +34 -34
- package/src/core.ts +320 -317
- package/src/pack-config.ts +92 -92
- package/src/render-context.ts +465 -465
- package/src/utils/cache.ts +15 -15
- package/src/utils/import-map.test.ts +713 -1
- package/src/utils/import-map.ts +53 -1
- package/src/utils/middleware.ts +19 -19
- package/src/utils/static-import-lexer.ts +18 -18
package/dist/core.d.ts
CHANGED
|
@@ -8,93 +8,93 @@ import type { RenderContext, RenderContextOptions } from './render-context';
|
|
|
8
8
|
import type { Middleware } from './utils/middleware';
|
|
9
9
|
import { type ProjectPath } from './utils/resolve-path';
|
|
10
10
|
/**
|
|
11
|
-
* Esmx
|
|
11
|
+
* Core configuration options interface for the Esmx framework
|
|
12
12
|
*/
|
|
13
13
|
export interface EsmxOptions {
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
15
|
+
* Project root directory path
|
|
16
|
+
* - Can be absolute or relative path
|
|
17
|
+
* - Defaults to current working directory (process.cwd())
|
|
18
18
|
*/
|
|
19
19
|
root?: string;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
* - true:
|
|
23
|
-
* - false:
|
|
24
|
-
* -
|
|
21
|
+
* Whether it is production environment
|
|
22
|
+
* - true: Production environment
|
|
23
|
+
* - false: Development environment
|
|
24
|
+
* - Defaults to process.env.NODE_ENV === 'production'
|
|
25
25
|
*/
|
|
26
26
|
isProd?: boolean;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
* - string:
|
|
30
|
-
* - false:
|
|
31
|
-
* -
|
|
32
|
-
* -
|
|
28
|
+
* Base path placeholder configuration
|
|
29
|
+
* - string: Custom placeholder
|
|
30
|
+
* - false: Disable placeholder
|
|
31
|
+
* - Default value is '[[[___ESMX_DYNAMIC_BASE___]]]'
|
|
32
|
+
* - Used for dynamically replacing the base path of assets at runtime
|
|
33
33
|
*/
|
|
34
34
|
basePathPlaceholder?: string | false;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
* -
|
|
38
|
-
* -
|
|
36
|
+
* Module configuration options
|
|
37
|
+
* - Used to configure module resolution rules for the project
|
|
38
|
+
* - Includes module aliases, external dependencies, etc.
|
|
39
39
|
*/
|
|
40
40
|
modules?: ModuleConfig;
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
* -
|
|
44
|
-
* -
|
|
42
|
+
* Package configuration options
|
|
43
|
+
* - Used to package build artifacts into standard npm .tgz format packages
|
|
44
|
+
* - Includes output path, package.json handling, packaging hooks, etc.
|
|
45
45
|
*/
|
|
46
46
|
packs?: PackConfig;
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
49
|
-
* -
|
|
50
|
-
* -
|
|
51
|
-
* @param esmx Esmx
|
|
48
|
+
* Development environment application creation function
|
|
49
|
+
* - Only used in development environment
|
|
50
|
+
* - Used to create application instance for development server
|
|
51
|
+
* @param esmx Esmx instance
|
|
52
52
|
*/
|
|
53
53
|
devApp?: (esmx: Esmx) => Promise<App>;
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
56
|
-
* -
|
|
57
|
-
* -
|
|
58
|
-
* @param esmx Esmx
|
|
55
|
+
* Server startup configuration function
|
|
56
|
+
* - Used to configure and start HTTP server
|
|
57
|
+
* - Can be used in both development and production environments
|
|
58
|
+
* @param esmx Esmx instance
|
|
59
59
|
*/
|
|
60
60
|
server?: (esmx: Esmx) => Promise<void>;
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
63
|
-
* -
|
|
64
|
-
* -
|
|
65
|
-
* @param esmx Esmx
|
|
62
|
+
* Post-build processing function
|
|
63
|
+
* - Executed after project build is completed
|
|
64
|
+
* - Can be used to perform additional resource processing, deployment, etc.
|
|
65
|
+
* @param esmx Esmx instance
|
|
66
66
|
*/
|
|
67
67
|
postBuild?: (esmx: Esmx) => Promise<void>;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
71
|
-
* - client:
|
|
72
|
-
* - server:
|
|
70
|
+
* Application build target types.
|
|
71
|
+
* - client: Client build target, used to generate code that runs in the browser
|
|
72
|
+
* - server: Server build target, used to generate code that runs in Node.js environment
|
|
73
73
|
*/
|
|
74
74
|
export type BuildEnvironment = 'client' | 'server';
|
|
75
75
|
/**
|
|
76
|
-
* Esmx
|
|
77
|
-
*
|
|
76
|
+
* Command enumeration for the Esmx framework.
|
|
77
|
+
* Used to control the runtime mode and lifecycle of the framework.
|
|
78
78
|
*/
|
|
79
79
|
export declare enum COMMAND {
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
81
|
+
* Development mode
|
|
82
|
+
* Starts development server with hot reload support
|
|
83
83
|
*/
|
|
84
84
|
dev = "dev",
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
86
|
+
* Build mode
|
|
87
|
+
* Generates production build artifacts
|
|
88
88
|
*/
|
|
89
89
|
build = "build",
|
|
90
90
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
91
|
+
* Preview mode
|
|
92
|
+
* Preview build artifacts
|
|
93
93
|
*/
|
|
94
94
|
preview = "preview",
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
96
|
+
* Start mode
|
|
97
|
+
* Starts production environment server
|
|
98
98
|
*/
|
|
99
99
|
start = "start"
|
|
100
100
|
}
|
|
@@ -105,76 +105,77 @@ export declare class Esmx {
|
|
|
105
105
|
private _importmapHash;
|
|
106
106
|
private get readied();
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
109
|
-
* @returns {string}
|
|
110
|
-
* @throws {NotReadyError}
|
|
108
|
+
* Get module name
|
|
109
|
+
* @returns {string} The name of the current module, sourced from module configuration
|
|
110
|
+
* @throws {NotReadyError} Throws error when framework instance is not initialized
|
|
111
111
|
*/
|
|
112
112
|
get name(): string;
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
115
|
-
* @returns {string}
|
|
116
|
-
* @throws {NotReadyError}
|
|
114
|
+
* Get module variable name
|
|
115
|
+
* @returns {string} A valid JavaScript variable name generated based on the module name
|
|
116
|
+
* @throws {NotReadyError} Throws error when framework instance is not initialized
|
|
117
117
|
*/
|
|
118
118
|
get varName(): string;
|
|
119
119
|
/**
|
|
120
|
-
*
|
|
121
|
-
* @returns {string}
|
|
122
|
-
*
|
|
120
|
+
* Get the absolute path of the project root directory
|
|
121
|
+
* @returns {string} The absolute path of the project root directory
|
|
122
|
+
* If the configured root is a relative path, it is resolved to an absolute path based on the current working directory
|
|
123
123
|
*/
|
|
124
124
|
get root(): string;
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
127
|
-
* @returns {boolean}
|
|
128
|
-
*
|
|
126
|
+
* Determine if currently in production environment
|
|
127
|
+
* @returns {boolean} Environment flag
|
|
128
|
+
* Prioritizes the isProd in configuration, if not configured, judges based on process.env.NODE_ENV
|
|
129
129
|
*/
|
|
130
130
|
get isProd(): boolean;
|
|
131
131
|
/**
|
|
132
|
-
*
|
|
133
|
-
* @returns {string}
|
|
134
|
-
*
|
|
132
|
+
* Get the base path of the module
|
|
133
|
+
* @returns {string} The base path of the module starting and ending with a slash
|
|
134
|
+
* Used to construct the access path for module assets
|
|
135
135
|
*/
|
|
136
136
|
get basePath(): string;
|
|
137
137
|
/**
|
|
138
|
-
*
|
|
139
|
-
* @returns {string}
|
|
140
|
-
*
|
|
138
|
+
* Get the base path placeholder
|
|
139
|
+
* @returns {string} Base path placeholder or empty string
|
|
140
|
+
* Used for dynamically replacing the base path of the module at runtime, can be disabled through configuration
|
|
141
141
|
*/
|
|
142
142
|
get basePathPlaceholder(): string;
|
|
143
143
|
/**
|
|
144
|
-
*
|
|
145
|
-
* @returns {COMMAND}
|
|
146
|
-
* @throws {NotReadyError}
|
|
144
|
+
* Get the currently executing command
|
|
145
|
+
* @returns {COMMAND} The command enumeration value currently being executed
|
|
146
|
+
* @throws {NotReadyError} Throws error when calling this method if the framework instance is not initialized
|
|
147
147
|
*/
|
|
148
148
|
get command(): COMMAND;
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
151
|
-
* @returns {typeof COMMAND}
|
|
150
|
+
* Get the command enumeration type
|
|
151
|
+
* @returns {typeof COMMAND} Command enumeration type definition
|
|
152
152
|
*/
|
|
153
153
|
get COMMAND(): typeof COMMAND;
|
|
154
154
|
/**
|
|
155
|
-
*
|
|
156
|
-
* @returns {ParsedModuleConfig}
|
|
155
|
+
* Get module configuration information
|
|
156
|
+
* @returns {ParsedModuleConfig} Complete configuration information of the current module
|
|
157
157
|
*/
|
|
158
158
|
get moduleConfig(): ParsedModuleConfig;
|
|
159
159
|
/**
|
|
160
|
-
*
|
|
161
|
-
* @returns {ParsedPackConfig}
|
|
160
|
+
* Get package configuration information
|
|
161
|
+
* @returns {ParsedPackConfig} Package-related configuration of the current module
|
|
162
162
|
*/
|
|
163
163
|
get packConfig(): ParsedPackConfig;
|
|
164
164
|
/**
|
|
165
|
-
*
|
|
165
|
+
* Get the static asset processing middleware for the application.
|
|
166
166
|
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* -
|
|
167
|
+
* This middleware is responsible for handling static asset requests for the application,
|
|
168
|
+
* providing different implementations based on the runtime environment:
|
|
169
|
+
* - Development environment: Supports real-time compilation and hot reloading of source code, uses no-cache strategy
|
|
170
|
+
* - Production environment: Handles built static assets, supports long-term caching for immutable files
|
|
170
171
|
*
|
|
171
|
-
* @returns {Middleware}
|
|
172
|
-
* @throws {NotReadyError}
|
|
172
|
+
* @returns {Middleware} Returns the static asset processing middleware function
|
|
173
|
+
* @throws {NotReadyError} Throws error when calling this method if the framework instance is not initialized
|
|
173
174
|
*
|
|
174
175
|
* @example
|
|
175
176
|
* ```ts
|
|
176
177
|
* const server = http.createServer((req, res) => {
|
|
177
|
-
* //
|
|
178
|
+
* // Use middleware to handle static asset requests
|
|
178
179
|
* esmx.middleware(req, res, async () => {
|
|
179
180
|
* const rc = await esmx.render({ url: req.url });
|
|
180
181
|
* res.end(rc.html);
|
|
@@ -184,28 +185,29 @@ export declare class Esmx {
|
|
|
184
185
|
*/
|
|
185
186
|
get middleware(): Middleware;
|
|
186
187
|
/**
|
|
187
|
-
*
|
|
188
|
+
* Get the server-side rendering function for the application.
|
|
188
189
|
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* -
|
|
190
|
+
* This function is responsible for executing server-side rendering,
|
|
191
|
+
* providing different implementations based on the runtime environment:
|
|
192
|
+
* - Development environment: Loads server entry file from source code, supports hot reloading and real-time preview
|
|
193
|
+
* - Production environment: Loads built server entry file, provides optimized rendering performance
|
|
192
194
|
*
|
|
193
|
-
* @returns {(options?: RenderContextOptions) => Promise<RenderContext>}
|
|
194
|
-
* @throws {NotReadyError}
|
|
195
|
+
* @returns {(options?: RenderContextOptions) => Promise<RenderContext>} Returns the server-side rendering function
|
|
196
|
+
* @throws {NotReadyError} Throws error when calling this method if the framework instance is not initialized
|
|
195
197
|
*
|
|
196
198
|
* @example
|
|
197
199
|
* ```ts
|
|
198
|
-
* //
|
|
200
|
+
* // Basic usage
|
|
199
201
|
* const rc = await esmx.render({
|
|
200
202
|
* params: { url: req.url }
|
|
201
203
|
* });
|
|
202
204
|
* res.end(rc.html);
|
|
203
205
|
*
|
|
204
|
-
* //
|
|
206
|
+
* // Advanced configuration
|
|
205
207
|
* const rc = await esmx.render({
|
|
206
|
-
* base: '', //
|
|
207
|
-
* importmapMode: 'inline', //
|
|
208
|
-
* entryName: 'default', //
|
|
208
|
+
* base: '', // Set base path
|
|
209
|
+
* importmapMode: 'inline', // Set import map mode
|
|
210
|
+
* entryName: 'default', // Specify render entry
|
|
209
211
|
* params: {
|
|
210
212
|
* url: req.url,
|
|
211
213
|
* state: { user: 'admin' }
|
|
@@ -216,21 +218,21 @@ export declare class Esmx {
|
|
|
216
218
|
get render(): (options?: RenderContextOptions) => Promise<RenderContext>;
|
|
217
219
|
constructor(options?: EsmxOptions);
|
|
218
220
|
/**
|
|
219
|
-
*
|
|
221
|
+
* Initialize the Esmx framework instance.
|
|
220
222
|
*
|
|
221
|
-
*
|
|
222
|
-
* 1.
|
|
223
|
-
* 2.
|
|
224
|
-
* 3.
|
|
223
|
+
* This method executes the following core initialization process:
|
|
224
|
+
* 1. Parse project configuration (package.json, module configuration, package configuration, etc.)
|
|
225
|
+
* 2. Create application instance (development or production environment)
|
|
226
|
+
* 3. Execute corresponding lifecycle methods based on the command
|
|
225
227
|
*
|
|
226
|
-
* @param command -
|
|
227
|
-
* - dev:
|
|
228
|
-
* - build:
|
|
229
|
-
* - preview:
|
|
230
|
-
* - start:
|
|
228
|
+
* @param command - Framework running command
|
|
229
|
+
* - dev: Start development server with hot reload support
|
|
230
|
+
* - build: Build production artifacts
|
|
231
|
+
* - preview: Preview build artifacts
|
|
232
|
+
* - start: Start production environment server
|
|
231
233
|
*
|
|
232
|
-
* @returns
|
|
233
|
-
* @throws {Error}
|
|
234
|
+
* @returns Returns true for successful initialization
|
|
235
|
+
* @throws {Error} Throws error when initializing repeatedly
|
|
234
236
|
*
|
|
235
237
|
* @example
|
|
236
238
|
* ```ts
|
|
@@ -238,32 +240,32 @@ export declare class Esmx {
|
|
|
238
240
|
* import type { EsmxOptions } from '@esmx/core';
|
|
239
241
|
*
|
|
240
242
|
* export default {
|
|
241
|
-
* //
|
|
243
|
+
* // Development environment configuration
|
|
242
244
|
* async devApp(esmx) {
|
|
243
245
|
* return import('@esmx/rspack').then((m) =>
|
|
244
246
|
* m.createRspackHtmlApp(esmx, {
|
|
245
247
|
* config(context) {
|
|
246
|
-
* //
|
|
248
|
+
* // Custom Rspack configuration
|
|
247
249
|
* }
|
|
248
250
|
* })
|
|
249
251
|
* );
|
|
250
252
|
* },
|
|
251
253
|
*
|
|
252
|
-
* // HTTP
|
|
254
|
+
* // HTTP server configuration
|
|
253
255
|
* async server(esmx) {
|
|
254
256
|
* const server = http.createServer((req, res) => {
|
|
255
|
-
* //
|
|
257
|
+
* // Static file handling
|
|
256
258
|
* esmx.middleware(req, res, async () => {
|
|
257
|
-
* //
|
|
259
|
+
* // Pass rendering parameters
|
|
258
260
|
* const render = await esmx.render({
|
|
259
261
|
* params: { url: req.url }
|
|
260
262
|
* });
|
|
261
|
-
* //
|
|
263
|
+
* // Respond with HTML content
|
|
262
264
|
* res.end(render.html);
|
|
263
265
|
* });
|
|
264
266
|
* });
|
|
265
267
|
*
|
|
266
|
-
* //
|
|
268
|
+
* // Listen to port
|
|
267
269
|
* server.listen(3000, () => {
|
|
268
270
|
* console.log('http://localhost:3000');
|
|
269
271
|
* });
|
|
@@ -273,46 +275,46 @@ export declare class Esmx {
|
|
|
273
275
|
*/
|
|
274
276
|
init(command: COMMAND): Promise<boolean>;
|
|
275
277
|
/**
|
|
276
|
-
*
|
|
278
|
+
* Destroy the Esmx framework instance, performing resource cleanup and connection closing operations.
|
|
277
279
|
*
|
|
278
|
-
*
|
|
279
|
-
* -
|
|
280
|
-
* -
|
|
281
|
-
* -
|
|
280
|
+
* This method is mainly used for resource cleanup in development environment, including:
|
|
281
|
+
* - Closing development servers (such as Rspack Dev Server)
|
|
282
|
+
* - Cleaning up temporary files and cache
|
|
283
|
+
* - Releasing system resources
|
|
282
284
|
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
+
* Note: In general, the framework automatically handles resource release, users do not need to manually call this method.
|
|
286
|
+
* Only use it when custom resource cleanup logic is needed.
|
|
285
287
|
*
|
|
286
|
-
* @returns
|
|
287
|
-
* - true:
|
|
288
|
-
* - false:
|
|
288
|
+
* @returns Returns a Promise that resolves to a boolean value
|
|
289
|
+
* - true: Cleanup successful or no cleanup needed
|
|
290
|
+
* - false: Cleanup failed
|
|
289
291
|
*
|
|
290
292
|
* @example
|
|
291
293
|
* ```ts
|
|
292
|
-
* //
|
|
294
|
+
* // Use when custom cleanup logic is needed
|
|
293
295
|
* process.once('SIGTERM', async () => {
|
|
294
|
-
* await esmx.destroy(); //
|
|
296
|
+
* await esmx.destroy(); // Clean up resources
|
|
295
297
|
* process.exit(0);
|
|
296
298
|
* });
|
|
297
299
|
* ```
|
|
298
300
|
*/
|
|
299
301
|
destroy(): Promise<boolean>;
|
|
300
302
|
/**
|
|
301
|
-
*
|
|
303
|
+
* Execute the application's build process.
|
|
302
304
|
*
|
|
303
|
-
*
|
|
304
|
-
* -
|
|
305
|
-
* -
|
|
306
|
-
* -
|
|
307
|
-
* -
|
|
305
|
+
* This method is responsible for executing the entire application build process, including:
|
|
306
|
+
* - Compiling source code
|
|
307
|
+
* - Generating production build artifacts
|
|
308
|
+
* - Optimizing and compressing code
|
|
309
|
+
* - Generating asset manifests
|
|
308
310
|
*
|
|
309
|
-
*
|
|
311
|
+
* The build process prints start and end times, as well as total duration and other information.
|
|
310
312
|
*
|
|
311
|
-
* @returns
|
|
312
|
-
* - true:
|
|
313
|
-
* - false:
|
|
313
|
+
* @returns Returns a Promise that resolves to a boolean value
|
|
314
|
+
* - true: Build successful or build method not implemented
|
|
315
|
+
* - false: Build failed
|
|
314
316
|
*
|
|
315
|
-
* @throws {NotReadyError}
|
|
317
|
+
* @throws {NotReadyError} Throws error when calling this method if the framework instance is not initialized
|
|
316
318
|
*
|
|
317
319
|
* @example
|
|
318
320
|
* ```ts
|
|
@@ -320,20 +322,20 @@ export declare class Esmx {
|
|
|
320
322
|
* import type { EsmxOptions } from '@esmx/core';
|
|
321
323
|
*
|
|
322
324
|
* export default {
|
|
323
|
-
* //
|
|
325
|
+
* // Development environment configuration
|
|
324
326
|
* async devApp(esmx) {
|
|
325
327
|
* return import('@esmx/rspack').then((m) =>
|
|
326
328
|
* m.createRspackHtmlApp(esmx, {
|
|
327
329
|
* config(context) {
|
|
328
|
-
* //
|
|
330
|
+
* // Custom Rspack configuration
|
|
329
331
|
* }
|
|
330
332
|
* })
|
|
331
333
|
* );
|
|
332
334
|
* },
|
|
333
335
|
*
|
|
334
|
-
* //
|
|
336
|
+
* // Post-build processing
|
|
335
337
|
* async postBuild(esmx) {
|
|
336
|
-
* //
|
|
338
|
+
* // Generate static HTML after build completion
|
|
337
339
|
* const render = await esmx.render({
|
|
338
340
|
* params: { url: '/' }
|
|
339
341
|
* });
|
|
@@ -347,21 +349,21 @@ export declare class Esmx {
|
|
|
347
349
|
*/
|
|
348
350
|
build(): Promise<boolean>;
|
|
349
351
|
/**
|
|
350
|
-
*
|
|
352
|
+
* Start HTTP server and configure server instance.
|
|
351
353
|
*
|
|
352
|
-
*
|
|
353
|
-
* -
|
|
354
|
-
* -
|
|
354
|
+
* This method is called in the following lifecycle of the framework:
|
|
355
|
+
* - Development environment (dev): Start development server, providing features like hot reload
|
|
356
|
+
* - Production environment (start): Start production server, providing production-grade performance
|
|
355
357
|
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
* -
|
|
359
|
-
* -
|
|
360
|
-
* -
|
|
361
|
-
* -
|
|
358
|
+
* The specific implementation of the server is provided by the user through the server configuration function in EsmxOptions.
|
|
359
|
+
* This function is responsible for:
|
|
360
|
+
* - Creating HTTP server instance
|
|
361
|
+
* - Configuring middleware and routes
|
|
362
|
+
* - Handling requests and responses
|
|
363
|
+
* - Starting server listening
|
|
362
364
|
*
|
|
363
|
-
* @returns
|
|
364
|
-
* @throws {NotReadyError}
|
|
365
|
+
* @returns Returns a Promise that resolves when the server startup is complete
|
|
366
|
+
* @throws {NotReadyError} Throws error when calling this method if the framework instance is not initialized
|
|
365
367
|
*
|
|
366
368
|
* @example
|
|
367
369
|
* ```ts
|
|
@@ -370,12 +372,12 @@ export declare class Esmx {
|
|
|
370
372
|
* import type { EsmxOptions } from '@esmx/core';
|
|
371
373
|
*
|
|
372
374
|
* export default {
|
|
373
|
-
* //
|
|
375
|
+
* // Server configuration
|
|
374
376
|
* async server(esmx) {
|
|
375
377
|
* const server = http.createServer((req, res) => {
|
|
376
|
-
* //
|
|
378
|
+
* // Handle static assets
|
|
377
379
|
* esmx.middleware(req, res, async () => {
|
|
378
|
-
* //
|
|
380
|
+
* // Server-side rendering
|
|
379
381
|
* const render = await esmx.render({
|
|
380
382
|
* params: { url: req.url }
|
|
381
383
|
* });
|
|
@@ -383,7 +385,7 @@ export declare class Esmx {
|
|
|
383
385
|
* });
|
|
384
386
|
* });
|
|
385
387
|
*
|
|
386
|
-
* //
|
|
388
|
+
* // Start server
|
|
387
389
|
* server.listen(3000, () => {
|
|
388
390
|
* console.log('Server running at http://localhost:3000');
|
|
389
391
|
* });
|
|
@@ -393,19 +395,19 @@ export declare class Esmx {
|
|
|
393
395
|
*/
|
|
394
396
|
server(): Promise<void>;
|
|
395
397
|
/**
|
|
396
|
-
*
|
|
398
|
+
* Execute post-build processing logic.
|
|
397
399
|
*
|
|
398
|
-
*
|
|
399
|
-
* -
|
|
400
|
-
* -
|
|
401
|
-
* -
|
|
402
|
-
* -
|
|
400
|
+
* This method is called after the application build is completed, used to perform additional resource processing, such as:
|
|
401
|
+
* - Generating static HTML files
|
|
402
|
+
* - Processing build artifacts
|
|
403
|
+
* - Executing deployment tasks
|
|
404
|
+
* - Sending build notifications
|
|
403
405
|
*
|
|
404
|
-
*
|
|
406
|
+
* The method automatically captures and handles exceptions during execution, ensuring it does not affect the main build process.
|
|
405
407
|
*
|
|
406
|
-
* @returns
|
|
407
|
-
* - true:
|
|
408
|
-
* - false:
|
|
408
|
+
* @returns Returns a Promise that resolves to a boolean value
|
|
409
|
+
* - true: Post-processing successful or no processing needed
|
|
410
|
+
* - false: Post-processing failed
|
|
409
411
|
*
|
|
410
412
|
* @example
|
|
411
413
|
* ```ts
|
|
@@ -413,9 +415,9 @@ export declare class Esmx {
|
|
|
413
415
|
* import type { EsmxOptions } from '@esmx/core';
|
|
414
416
|
*
|
|
415
417
|
* export default {
|
|
416
|
-
* //
|
|
418
|
+
* // Post-build processing
|
|
417
419
|
* async postBuild(esmx) {
|
|
418
|
-
* //
|
|
420
|
+
* // Generate static HTML for multiple pages
|
|
419
421
|
* const pages = ['/', '/about', '/404'];
|
|
420
422
|
*
|
|
421
423
|
* for (const url of pages) {
|
|
@@ -423,7 +425,7 @@ export declare class Esmx {
|
|
|
423
425
|
* params: { url }
|
|
424
426
|
* });
|
|
425
427
|
*
|
|
426
|
-
* //
|
|
428
|
+
* // Write static HTML file
|
|
427
429
|
* esmx.writeSync(
|
|
428
430
|
* esmx.resolvePath('dist/client', url.substring(1), 'index.html'),
|
|
429
431
|
* render.html
|
|
@@ -435,32 +437,32 @@ export declare class Esmx {
|
|
|
435
437
|
*/
|
|
436
438
|
postBuild(): Promise<boolean>;
|
|
437
439
|
/**
|
|
438
|
-
*
|
|
440
|
+
* Resolve project relative path to absolute path
|
|
439
441
|
*
|
|
440
|
-
* @param projectPath -
|
|
441
|
-
* @param args -
|
|
442
|
-
* @returns
|
|
442
|
+
* @param projectPath - Project path type, such as 'dist/client', 'dist/server', etc.
|
|
443
|
+
* @param args - Path segments to be concatenated
|
|
444
|
+
* @returns Resolved absolute path
|
|
443
445
|
*
|
|
444
446
|
* @example
|
|
445
447
|
* ```ts
|
|
446
|
-
* //
|
|
448
|
+
* // Used in entry.node.ts
|
|
447
449
|
* async postBuild(esmx) {
|
|
448
450
|
* const outputPath = esmx.resolvePath('dist/client', 'index.html');
|
|
449
|
-
* //
|
|
451
|
+
* // Output: /project/root/dist/client/index.html
|
|
450
452
|
* }
|
|
451
453
|
* ```
|
|
452
454
|
*/
|
|
453
455
|
resolvePath(projectPath: ProjectPath, ...args: string[]): string;
|
|
454
456
|
/**
|
|
455
|
-
*
|
|
457
|
+
* Write file content synchronously
|
|
456
458
|
*
|
|
457
|
-
* @param filepath -
|
|
458
|
-
* @param data -
|
|
459
|
-
* @returns
|
|
459
|
+
* @param filepath - Absolute path of the file
|
|
460
|
+
* @param data - Data to be written, can be string, Buffer or object
|
|
461
|
+
* @returns Whether the write was successful
|
|
460
462
|
*
|
|
461
463
|
* @example
|
|
462
464
|
* ```ts
|
|
463
|
-
* //
|
|
465
|
+
* // Used in entry.node.ts
|
|
464
466
|
* async postBuild(esmx) {
|
|
465
467
|
* const htmlPath = esmx.resolvePath('dist/client', 'index.html');
|
|
466
468
|
* const success = esmx.writeSync(htmlPath, '<html>...</html>');
|
|
@@ -469,15 +471,15 @@ export declare class Esmx {
|
|
|
469
471
|
*/
|
|
470
472
|
writeSync(filepath: string, data: any): boolean;
|
|
471
473
|
/**
|
|
472
|
-
*
|
|
474
|
+
* Write file content asynchronously
|
|
473
475
|
*
|
|
474
|
-
* @param filepath -
|
|
475
|
-
* @param data -
|
|
476
|
-
* @returns Promise<boolean>
|
|
476
|
+
* @param filepath - Absolute path of the file
|
|
477
|
+
* @param data - Data to be written, can be string, Buffer or object
|
|
478
|
+
* @returns Promise<boolean> Whether the write was successful
|
|
477
479
|
*
|
|
478
480
|
* @example
|
|
479
481
|
* ```ts
|
|
480
|
-
* //
|
|
482
|
+
* // Used in entry.node.ts
|
|
481
483
|
* async postBuild(esmx) {
|
|
482
484
|
* const htmlPath = esmx.resolvePath('dist/client', 'index.html');
|
|
483
485
|
* const success = await esmx.write(htmlPath, '<html>...</html>');
|
|
@@ -486,72 +488,72 @@ export declare class Esmx {
|
|
|
486
488
|
*/
|
|
487
489
|
write(filepath: string, data: any): Promise<boolean>;
|
|
488
490
|
/**
|
|
489
|
-
*
|
|
491
|
+
* Read and parse JSON file synchronously
|
|
490
492
|
*
|
|
491
|
-
* @template T -
|
|
492
|
-
* @param filename - JSON
|
|
493
|
-
* @returns {T}
|
|
494
|
-
* @throws
|
|
493
|
+
* @template T - Expected JSON object type to return
|
|
494
|
+
* @param filename - Absolute path of the JSON file
|
|
495
|
+
* @returns {T} Parsed JSON object
|
|
496
|
+
* @throws Throws exception when file does not exist or JSON format is incorrect
|
|
495
497
|
*
|
|
496
498
|
* @example
|
|
497
499
|
* ```ts
|
|
498
|
-
* //
|
|
500
|
+
* // Used in entry.node.ts
|
|
499
501
|
* async server(esmx) {
|
|
500
502
|
* const manifest = esmx.readJsonSync<Manifest>(esmx.resolvePath('dist/client', 'manifest.json'));
|
|
501
|
-
* //
|
|
503
|
+
* // Use manifest object
|
|
502
504
|
* }
|
|
503
505
|
* ```
|
|
504
506
|
*/
|
|
505
507
|
readJsonSync<T = any>(filename: string): T;
|
|
506
508
|
/**
|
|
507
|
-
*
|
|
509
|
+
* Read and parse JSON file asynchronously
|
|
508
510
|
*
|
|
509
|
-
* @template T -
|
|
510
|
-
* @param filename - JSON
|
|
511
|
-
* @returns {Promise<T>}
|
|
512
|
-
* @throws
|
|
511
|
+
* @template T - Expected JSON object type to return
|
|
512
|
+
* @param filename - Absolute path of the JSON file
|
|
513
|
+
* @returns {Promise<T>} Parsed JSON object
|
|
514
|
+
* @throws Throws exception when file does not exist or JSON format is incorrect
|
|
513
515
|
*
|
|
514
516
|
* @example
|
|
515
517
|
* ```ts
|
|
516
|
-
* //
|
|
518
|
+
* // Used in entry.node.ts
|
|
517
519
|
* async server(esmx) {
|
|
518
520
|
* const manifest = await esmx.readJson<Manifest>(esmx.resolvePath('dist/client', 'manifest.json'));
|
|
519
|
-
* //
|
|
521
|
+
* // Use manifest object
|
|
520
522
|
* }
|
|
521
523
|
* ```
|
|
522
524
|
*/
|
|
523
525
|
readJson<T = any>(filename: string): Promise<T>;
|
|
524
526
|
/**
|
|
525
|
-
*
|
|
527
|
+
* Get build manifest list
|
|
526
528
|
*
|
|
527
529
|
* @description
|
|
528
|
-
*
|
|
529
|
-
* 1.
|
|
530
|
-
* -
|
|
531
|
-
* -
|
|
530
|
+
* This method is used to get the build manifest list for the specified target environment, including the following features:
|
|
531
|
+
* 1. **Cache Management**
|
|
532
|
+
* - Uses internal caching mechanism to avoid repeated loading
|
|
533
|
+
* - Returns immutable manifest list
|
|
532
534
|
*
|
|
533
|
-
* 2.
|
|
534
|
-
* -
|
|
535
|
-
* -
|
|
535
|
+
* 2. **Environment Adaptation**
|
|
536
|
+
* - Supports both client and server environments
|
|
537
|
+
* - Returns corresponding manifest information based on the target environment
|
|
536
538
|
*
|
|
537
|
-
* 3.
|
|
538
|
-
* -
|
|
539
|
-
* -
|
|
539
|
+
* 3. **Module Mapping**
|
|
540
|
+
* - Contains module export information
|
|
541
|
+
* - Records resource dependency relationships
|
|
540
542
|
*
|
|
541
|
-
* @param env -
|
|
542
|
-
* - 'client':
|
|
543
|
-
* - 'server':
|
|
544
|
-
* @returns
|
|
545
|
-
* @throws {NotReadyError}
|
|
543
|
+
* @param env - Target environment type
|
|
544
|
+
* - 'client': Client environment
|
|
545
|
+
* - 'server': Server environment
|
|
546
|
+
* @returns Returns read-only build manifest list
|
|
547
|
+
* @throws {NotReadyError} Throws error when calling this method if the framework instance is not initialized
|
|
546
548
|
*
|
|
547
549
|
* @example
|
|
548
550
|
* ```ts
|
|
549
|
-
* //
|
|
551
|
+
* // Used in entry.node.ts
|
|
550
552
|
* async server(esmx) {
|
|
551
|
-
* //
|
|
553
|
+
* // Get client build manifest
|
|
552
554
|
* const manifests = await esmx.getManifestList('client');
|
|
553
555
|
*
|
|
554
|
-
* //
|
|
556
|
+
* // Find build information for a specific module
|
|
555
557
|
* const appModule = manifests.find(m => m.name === 'my-app');
|
|
556
558
|
* if (appModule) {
|
|
557
559
|
* console.log('App exports:', appModule.exports);
|
|
@@ -562,37 +564,37 @@ export declare class Esmx {
|
|
|
562
564
|
*/
|
|
563
565
|
getManifestList(env: BuildEnvironment): Promise<readonly ManifestJson[]>;
|
|
564
566
|
/**
|
|
565
|
-
*
|
|
567
|
+
* Get import map object
|
|
566
568
|
*
|
|
567
569
|
* @description
|
|
568
|
-
*
|
|
569
|
-
* 1.
|
|
570
|
-
* -
|
|
571
|
-
* -
|
|
572
|
-
* -
|
|
573
|
-
*
|
|
574
|
-
* 2.
|
|
575
|
-
* -
|
|
576
|
-
* -
|
|
577
|
-
*
|
|
578
|
-
* 3.
|
|
579
|
-
* -
|
|
580
|
-
* -
|
|
581
|
-
*
|
|
582
|
-
* @param env -
|
|
583
|
-
* - 'client':
|
|
584
|
-
* - 'server':
|
|
585
|
-
* @returns
|
|
586
|
-
* @throws {NotReadyError}
|
|
570
|
+
* This method is used to generate ES module import maps with the following features:
|
|
571
|
+
* 1. **Module Resolution**
|
|
572
|
+
* - Generate module mappings based on build manifests
|
|
573
|
+
* - Support both client and server environments
|
|
574
|
+
* - Automatically handle module path resolution
|
|
575
|
+
*
|
|
576
|
+
* 2. **Cache Optimization**
|
|
577
|
+
* - Use internal caching mechanism
|
|
578
|
+
* - Return immutable mapping objects
|
|
579
|
+
*
|
|
580
|
+
* 3. **Path Handling**
|
|
581
|
+
* - Automatically handle module paths
|
|
582
|
+
* - Support dynamic base paths
|
|
583
|
+
*
|
|
584
|
+
* @param env - Target environment type
|
|
585
|
+
* - 'client': Generate import map for browser environment
|
|
586
|
+
* - 'server': Generate import map for server environment
|
|
587
|
+
* @returns Returns read-only import map object
|
|
588
|
+
* @throws {NotReadyError} Throws error when calling this method if the framework instance is not initialized
|
|
587
589
|
*
|
|
588
590
|
* @example
|
|
589
591
|
* ```ts
|
|
590
|
-
* //
|
|
592
|
+
* // Used in entry.node.ts
|
|
591
593
|
* async server(esmx) {
|
|
592
|
-
* //
|
|
594
|
+
* // Get client import map
|
|
593
595
|
* const importmap = await esmx.getImportMap('client');
|
|
594
596
|
*
|
|
595
|
-
* //
|
|
597
|
+
* // Custom HTML template
|
|
596
598
|
* const html = `
|
|
597
599
|
* <!DOCTYPE html>
|
|
598
600
|
* <html>
|
|
@@ -602,7 +604,7 @@ export declare class Esmx {
|
|
|
602
604
|
* </script>
|
|
603
605
|
* </head>
|
|
604
606
|
* <body>
|
|
605
|
-
* <!--
|
|
607
|
+
* <!-- Page content -->
|
|
606
608
|
* </body>
|
|
607
609
|
* </html>
|
|
608
610
|
* `;
|
|
@@ -611,44 +613,44 @@ export declare class Esmx {
|
|
|
611
613
|
*/
|
|
612
614
|
getImportMap(env: BuildEnvironment): Promise<Readonly<ImportMap>>;
|
|
613
615
|
/**
|
|
614
|
-
*
|
|
616
|
+
* Get client import map information
|
|
615
617
|
*
|
|
616
618
|
* @description
|
|
617
|
-
*
|
|
618
|
-
* 1.
|
|
619
|
-
* -
|
|
620
|
-
* -
|
|
621
|
-
* -
|
|
622
|
-
*
|
|
623
|
-
* 2. **JS
|
|
624
|
-
* -
|
|
625
|
-
* -
|
|
626
|
-
* -
|
|
627
|
-
*
|
|
628
|
-
*
|
|
629
|
-
* -
|
|
630
|
-
* -
|
|
631
|
-
* -
|
|
632
|
-
* -
|
|
633
|
-
*
|
|
634
|
-
* @param mode -
|
|
635
|
-
* - 'inline':
|
|
636
|
-
* - 'js': JS
|
|
637
|
-
* @returns
|
|
638
|
-
* - src: JS
|
|
639
|
-
* - filepath: JS
|
|
640
|
-
* - code: HTML script
|
|
641
|
-
* @throws {NotReadyError}
|
|
619
|
+
* This method is used to generate import map code for client environment, supporting two modes:
|
|
620
|
+
* 1. **Inline Mode (inline)**
|
|
621
|
+
* - Inline import map directly into HTML
|
|
622
|
+
* - Reduce additional network requests
|
|
623
|
+
* - Suitable for scenarios with smaller import maps
|
|
624
|
+
*
|
|
625
|
+
* 2. **JS File Mode (js)**
|
|
626
|
+
* - Generate standalone JS file
|
|
627
|
+
* - Support browser caching
|
|
628
|
+
* - Suitable for scenarios with larger import maps
|
|
629
|
+
*
|
|
630
|
+
* Core Features:
|
|
631
|
+
* - Automatically handle dynamic base paths
|
|
632
|
+
* - Support module path runtime replacement
|
|
633
|
+
* - Optimize caching strategy
|
|
634
|
+
* - Ensure module loading order
|
|
635
|
+
*
|
|
636
|
+
* @param mode - Import map mode
|
|
637
|
+
* - 'inline': Inline mode, returns HTML script tag
|
|
638
|
+
* - 'js': JS file mode, returns information with file path
|
|
639
|
+
* @returns Returns import map related information
|
|
640
|
+
* - src: URL of the JS file (only in js mode)
|
|
641
|
+
* - filepath: Local path of the JS file (only in js mode)
|
|
642
|
+
* - code: HTML script tag content
|
|
643
|
+
* @throws {NotReadyError} Throws error when calling this method if the framework instance is not initialized
|
|
642
644
|
*
|
|
643
645
|
* @example
|
|
644
646
|
* ```ts
|
|
645
|
-
* //
|
|
647
|
+
* // Used in entry.node.ts
|
|
646
648
|
* async server(esmx) {
|
|
647
649
|
* const server = express();
|
|
648
650
|
* server.use(esmx.middleware);
|
|
649
651
|
*
|
|
650
652
|
* server.get('*', async (req, res) => {
|
|
651
|
-
* //
|
|
653
|
+
* // Use JS file mode
|
|
652
654
|
* const result = await esmx.render({
|
|
653
655
|
* importmapMode: 'js',
|
|
654
656
|
* params: { url: req.url }
|
|
@@ -656,7 +658,7 @@ export declare class Esmx {
|
|
|
656
658
|
* res.send(result.html);
|
|
657
659
|
* });
|
|
658
660
|
*
|
|
659
|
-
* //
|
|
661
|
+
* // Or use inline mode
|
|
660
662
|
* server.get('/inline', async (req, res) => {
|
|
661
663
|
* const result = await esmx.render({
|
|
662
664
|
* importmapMode: 'inline',
|
|
@@ -677,16 +679,16 @@ export declare class Esmx {
|
|
|
677
679
|
code: string;
|
|
678
680
|
}>;
|
|
679
681
|
/**
|
|
680
|
-
*
|
|
682
|
+
* Get the list of static import paths for a module.
|
|
681
683
|
*
|
|
682
|
-
* @param env -
|
|
683
|
-
* @param specifier -
|
|
684
|
-
* @returns
|
|
685
|
-
* @throws {NotReadyError}
|
|
684
|
+
* @param env - Build target ('client' | 'server')
|
|
685
|
+
* @param specifier - Module specifier
|
|
686
|
+
* @returns Returns the list of static import paths, returns null if not found
|
|
687
|
+
* @throws {NotReadyError} Throws error when calling this method if the framework instance is not initialized
|
|
686
688
|
*
|
|
687
689
|
* @example
|
|
688
690
|
* ```ts
|
|
689
|
-
* //
|
|
691
|
+
* // Get static import paths for client entry module
|
|
690
692
|
* const paths = await esmx.getStaticImportPaths(
|
|
691
693
|
* 'client',
|
|
692
694
|
* `your-app-name/src/entry.client`
|