@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
|
@@ -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
|
-
*
|
|
6
|
-
* @param code
|
|
7
|
-
* @returns `Promise<string[]>`
|
|
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
|
-
*
|
|
12
|
-
* @param filepath
|
|
13
|
-
* @returns `Promise<string[]>`
|
|
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.
|
|
62
|
+
"@esmx/import": "3.0.0-rc.63",
|
|
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.
|
|
80
|
+
"version": "3.0.0-rc.63",
|
|
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": "18a524ff1b7f9c6ea60d8bb57ad314329febc58c"
|
|
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
|
|
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
|
-
* //
|
|
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
|
-
* -
|
|
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
|
-
* -
|
|
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
|
-
* -
|
|
60
|
-
* -
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
-
* //
|
|
116
|
+
* // Server entry file (entry.server)
|
|
117
117
|
* export default async function render(rc: RenderContext) {
|
|
118
118
|
* rc.html = '<html>...</html>';
|
|
119
119
|
* }
|