@esmx/core 3.0.0-rc.11 → 3.0.0-rc.111
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/LICENSE +1 -1
- package/README.md +52 -20
- package/README.zh-CN.md +61 -0
- package/dist/app.d.ts +28 -28
- package/dist/app.mjs +1 -1
- package/dist/cli/cli.mjs +31 -10
- package/dist/cli/index.mjs +5 -0
- package/dist/core.d.ts +714 -0
- package/dist/core.mjs +907 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +3 -10
- package/dist/manifest-json.d.ts +53 -26
- package/dist/manifest-json.mjs +7 -8
- package/dist/module-config.d.ts +47 -177
- package/dist/module-config.mjs +180 -69
- package/dist/module-config.test.d.ts +1 -0
- package/dist/module-config.test.mjs +743 -0
- package/dist/pack-config.d.ts +95 -95
- package/dist/pack-config.test.d.ts +1 -0
- package/dist/pack-config.test.mjs +60 -0
- package/dist/render-context.d.ts +466 -466
- package/dist/render-context.mjs +338 -338
- package/dist/utils/cache.d.ts +15 -15
- package/dist/utils/cache.test.d.ts +1 -0
- package/dist/utils/cache.test.mjs +47 -0
- package/dist/utils/file-size-stats.d.ts +29 -0
- package/dist/utils/file-size-stats.mjs +120 -0
- package/dist/utils/file-size-stats.test.d.ts +1 -0
- package/dist/utils/file-size-stats.test.mjs +183 -0
- package/dist/utils/import-map.d.ts +50 -6
- package/dist/utils/import-map.mjs +104 -24
- package/dist/utils/import-map.test.d.ts +1 -0
- package/dist/utils/import-map.test.mjs +1586 -0
- package/dist/utils/middleware.d.ts +20 -20
- package/dist/utils/middleware.mjs +26 -25
- package/dist/utils/middleware.test.d.ts +1 -0
- package/dist/utils/middleware.test.mjs +109 -0
- package/dist/utils/path-without-index.mjs +1 -0
- package/dist/utils/path-without-index.test.d.ts +1 -0
- package/dist/utils/path-without-index.test.mjs +23 -0
- package/dist/utils/resolve-path.d.ts +2 -1
- package/dist/utils/resolve-path.mjs +5 -0
- package/dist/utils/resolve-path.test.d.ts +1 -0
- package/dist/utils/resolve-path.test.mjs +81 -0
- package/dist/utils/static-import-lexer.d.ts +17 -15
- package/dist/utils/static-import-lexer.mjs +21 -22
- package/package.json +17 -20
- package/src/app.ts +37 -37
- package/src/cli/cli.ts +40 -18
- package/src/cli/index.ts +7 -0
- package/src/core.ts +1190 -0
- package/src/index.ts +30 -23
- package/src/manifest-json.ts +59 -35
- package/src/module-config.test.ts +828 -0
- package/src/module-config.ts +292 -253
- package/src/pack-config.test.ts +75 -0
- package/src/pack-config.ts +95 -95
- package/src/render-context.ts +466 -466
- package/src/utils/cache.test.ts +56 -0
- package/src/utils/cache.ts +15 -15
- package/src/utils/file-size-stats.test.ts +212 -0
- package/src/utils/file-size-stats.ts +189 -0
- package/src/utils/import-map.test.ts +1780 -0
- package/src/utils/import-map.ts +191 -37
- package/src/utils/middleware.test.ts +168 -0
- package/src/utils/middleware.ts +48 -48
- package/src/utils/path-without-index.test.ts +25 -0
- package/src/utils/path-without-index.ts +1 -0
- package/src/utils/resolve-path.test.ts +91 -0
- package/src/utils/resolve-path.ts +10 -2
- package/src/utils/static-import-lexer.ts +41 -42
- package/dist/gez.d.ts +0 -703
- package/dist/gez.mjs +0 -842
- package/src/gez.ts +0 -1026
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,29 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://esmx.dev/logo.svg?t=2025" width="120" alt="Esmx Logo" />
|
|
3
|
+
<h1>@esmx/core</h1>
|
|
4
|
+
|
|
5
|
+
<div>
|
|
6
|
+
<a href="https://www.npmjs.com/package/@esmx/core">
|
|
7
|
+
<img src="https://img.shields.io/npm/v/@esmx/core.svg" alt="npm version" />
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://github.com/esmnext/esmx/actions/workflows/build.yml">
|
|
10
|
+
<img src="https://github.com/esmnext/esmx/actions/workflows/build.yml/badge.svg" alt="Build" />
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://esmx.dev/coverage/">
|
|
13
|
+
<img src="https://img.shields.io/badge/coverage-live%20report-brightgreen" alt="Coverage Report" />
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://nodejs.org/">
|
|
16
|
+
<img src="https://img.shields.io/node/v/@esmx/core.svg" alt="node version" />
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://bundlephobia.com/package/@esmx/core">
|
|
19
|
+
<img src="https://img.shields.io/bundlephobia/minzip/@esmx/core" alt="size" />
|
|
20
|
+
</a>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<p>A high-performance microfrontend framework supporting Vue, React, Preact, Solid, and Svelte with SSR and Module Linking capabilities</p>
|
|
24
|
+
|
|
25
|
+
<p>
|
|
26
|
+
English | <a href="https://github.com/esmnext/esmx/blob/master/packages/core/README.zh-CN.md">中文</a>
|
|
27
|
+
</p>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## 🚀 Features
|
|
31
|
+
|
|
32
|
+
- **Native Microfrontend** - Based on ESM + ImportMap for native module loading with zero runtime overhead
|
|
33
|
+
- **Dependency Management** - Centralized dependency management with content-hash-based strong caching strategy
|
|
34
|
+
- **Application Isolation** - ESM native module isolation ensuring runtime stability
|
|
35
|
+
- **SSR Support** - Flexible server-side rendering strategy supporting any frontend framework
|
|
36
|
+
- **Developer Experience** - Complete TypeScript support with native Module Linking capabilities
|
|
37
|
+
|
|
38
|
+
## 📦 Installation
|
|
14
39
|
|
|
15
40
|
```bash
|
|
41
|
+
# npm
|
|
42
|
+
npm install @esmx/core
|
|
43
|
+
|
|
44
|
+
# pnpm
|
|
16
45
|
pnpm add @esmx/core
|
|
17
|
-
|
|
46
|
+
|
|
47
|
+
# yarn
|
|
18
48
|
yarn add @esmx/core
|
|
19
|
-
# 或
|
|
20
|
-
npm install @esmx/core
|
|
21
49
|
```
|
|
22
50
|
|
|
23
|
-
##
|
|
51
|
+
## 🚀 Quick Start
|
|
52
|
+
|
|
53
|
+
See Quick Start guide: https://esmx.dev/guide/start/getting-started.html
|
|
54
|
+
|
|
55
|
+
## 📚 Documentation
|
|
24
56
|
|
|
25
|
-
|
|
57
|
+
Visit the [official documentation](https://esmx.dev) for detailed usage guides and API reference.
|
|
26
58
|
|
|
27
|
-
##
|
|
59
|
+
## 📄 License
|
|
28
60
|
|
|
29
|
-
MIT
|
|
61
|
+
MIT © [Esmx Team](https://github.com/esmnext/esmx)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://esmx.dev/logo.svg?t=2025" width="120" alt="Esmx Logo" />
|
|
3
|
+
<h1>@esmx/core</h1>
|
|
4
|
+
|
|
5
|
+
<div>
|
|
6
|
+
<a href="https://www.npmjs.com/package/@esmx/core">
|
|
7
|
+
<img src="https://img.shields.io/npm/v/@esmx/core.svg" alt="npm version" />
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://github.com/esmnext/esmx/actions/workflows/build.yml">
|
|
10
|
+
<img src="https://github.com/esmnext/esmx/actions/workflows/build.yml/badge.svg" alt="Build" />
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://esmx.dev/coverage/">
|
|
13
|
+
<img src="https://img.shields.io/badge/coverage-live%20report-brightgreen" alt="Coverage Report" />
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://nodejs.org/">
|
|
16
|
+
<img src="https://img.shields.io/node/v/@esmx/core.svg" alt="node version" />
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://bundlephobia.com/package/@esmx/core">
|
|
19
|
+
<img src="https://img.shields.io/bundlephobia/minzip/@esmx/core" alt="size" />
|
|
20
|
+
</a>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<p>支持 Vue、React、Preact、Solid、Svelte 的高性能微前端框架,具备 SSR 和模块链接能力</p>
|
|
24
|
+
|
|
25
|
+
<p>
|
|
26
|
+
<a href="https://github.com/esmnext/esmx/blob/master/packages/core/README.md">English</a> | 中文
|
|
27
|
+
</p>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## 🚀 特性
|
|
31
|
+
|
|
32
|
+
- **原生微前端** - 基于 ESM + ImportMap 的原生模块加载,零运行时开销
|
|
33
|
+
- **依赖管理** - 中心化的依赖管理,基于内容哈希的强缓存策略
|
|
34
|
+
- **应用隔离** - ESM 原生模块隔离,保障应用运行时的稳定性
|
|
35
|
+
- **SSR 支持** - 灵活的服务端渲染策略,支持任意前端框架
|
|
36
|
+
- **开发体验** - 完整的 TypeScript 支持,原生模块链接能力
|
|
37
|
+
|
|
38
|
+
## 📦 安装
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# npm
|
|
42
|
+
npm install @esmx/core
|
|
43
|
+
|
|
44
|
+
# pnpm
|
|
45
|
+
pnpm add @esmx/core
|
|
46
|
+
|
|
47
|
+
# yarn
|
|
48
|
+
yarn add @esmx/core
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 🚀 快速开始
|
|
52
|
+
|
|
53
|
+
查看快速开始指南:https://esmx.dev/zh-CN/guide/start/getting-started.html
|
|
54
|
+
|
|
55
|
+
## 📚 文档
|
|
56
|
+
|
|
57
|
+
访问[官方文档](https://esmx.dev)获取详细的使用指南和 API 参考。
|
|
58
|
+
|
|
59
|
+
## 📄 许可证
|
|
60
|
+
|
|
61
|
+
MIT © [Esmx Team](https://github.com/esmnext/esmx)
|
package/dist/app.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type { COMMAND, Esmx } from './
|
|
1
|
+
import type { COMMAND, Esmx } from './core';
|
|
2
2
|
import { RenderContext, type RenderContextOptions } from './render-context';
|
|
3
3
|
import { type Middleware } from './utils/middleware';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Application instance interface.
|
|
6
6
|
*
|
|
7
|
-
* App
|
|
8
|
-
*
|
|
7
|
+
* App is the application abstraction of the Esmx framework, providing a unified interface
|
|
8
|
+
* to manage application lifecycle, static assets, and server-side rendering.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
12
|
* // entry.node.ts
|
|
13
13
|
* export default {
|
|
14
|
-
* //
|
|
14
|
+
* // Development environment configuration
|
|
15
15
|
* async devApp(esmx) {
|
|
16
16
|
* return import('@esmx/rspack').then((m) =>
|
|
17
17
|
* m.createRspackHtmlApp(esmx, {
|
|
18
18
|
* config(rc) {
|
|
19
|
-
* //
|
|
19
|
+
* // Custom Rspack configuration
|
|
20
20
|
* }
|
|
21
21
|
* })
|
|
22
22
|
* );
|
|
@@ -26,17 +26,17 @@ import { type Middleware } from './utils/middleware';
|
|
|
26
26
|
*/
|
|
27
27
|
export interface App {
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Static asset processing middleware.
|
|
30
30
|
*
|
|
31
|
-
*
|
|
32
|
-
* -
|
|
33
|
-
* -
|
|
34
|
-
* -
|
|
31
|
+
* Development environment:
|
|
32
|
+
* - Handles static asset requests from source code
|
|
33
|
+
* - Supports real-time compilation and hot reloading
|
|
34
|
+
* - Uses no-cache strategy
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
* -
|
|
38
|
-
* -
|
|
39
|
-
* -
|
|
36
|
+
* Production environment:
|
|
37
|
+
* - Handles built static assets
|
|
38
|
+
* - Supports long-term caching for immutable files (.final.xxx)
|
|
39
|
+
* - Optimized asset loading strategy
|
|
40
40
|
*
|
|
41
41
|
* @example
|
|
42
42
|
* ```ts
|
|
@@ -45,14 +45,14 @@ export interface App {
|
|
|
45
45
|
*/
|
|
46
46
|
middleware: Middleware;
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* Server-side rendering function.
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
* -
|
|
52
|
-
* -
|
|
50
|
+
* Provides different implementations based on the runtime environment:
|
|
51
|
+
* - Production environment (start): Loads the built server entry file (entry.server) to execute rendering
|
|
52
|
+
* - Development environment (dev): Loads the server entry file from source code to execute rendering
|
|
53
53
|
*
|
|
54
|
-
* @param options -
|
|
55
|
-
* @returns
|
|
54
|
+
* @param options - Rendering options
|
|
55
|
+
* @returns Returns the rendering context containing the rendering result
|
|
56
56
|
*
|
|
57
57
|
* @example
|
|
58
58
|
* ```ts
|
|
@@ -64,21 +64,21 @@ export interface App {
|
|
|
64
64
|
*/
|
|
65
65
|
render: (options?: RenderContextOptions) => Promise<RenderContext>;
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
67
|
+
* Production environment build function.
|
|
68
|
+
* Used for asset packaging and optimization.
|
|
69
69
|
*
|
|
70
|
-
* @returns
|
|
70
|
+
* @returns Returns true for successful build, false for failed build
|
|
71
71
|
*/
|
|
72
72
|
build?: () => Promise<boolean>;
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
74
|
+
* Resource cleanup function.
|
|
75
|
+
* Used for shutting down servers, disconnecting connections, etc.
|
|
76
76
|
*
|
|
77
|
-
* @returns
|
|
77
|
+
* @returns Returns true for successful cleanup, false for failed cleanup
|
|
78
78
|
*/
|
|
79
79
|
destroy?: () => Promise<boolean>;
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
*
|
|
82
|
+
* Create an application instance for production environment, not available in development environment.
|
|
83
83
|
*/
|
|
84
84
|
export declare function createApp(esmx: Esmx, command: COMMAND): Promise<App>;
|
package/dist/app.mjs
CHANGED
|
@@ -12,7 +12,7 @@ export async function createApp(esmx, command) {
|
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
async function createStartRender(esmx) {
|
|
15
|
-
const baseURL = pathToFileURL(esmx.
|
|
15
|
+
const baseURL = pathToFileURL(esmx.resolvePath("dist/server"));
|
|
16
16
|
const importMap = await esmx.getImportMap("server");
|
|
17
17
|
const loaderImport = createLoaderImport(baseURL, importMap);
|
|
18
18
|
return async (options) => {
|
package/dist/cli/cli.mjs
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
import module from "node:module";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { COMMAND, Esmx } from "../
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
|
+
import pkg from "../../package.json" with { type: "json" };
|
|
4
|
+
import { COMMAND, Esmx } from "../core.mjs";
|
|
5
|
+
import { resolveImportPath } from "../utils/resolve-path.mjs";
|
|
5
6
|
async function getSrcOptions() {
|
|
6
|
-
return import(
|
|
7
|
+
return import(resolveImportPath(process.cwd(), "./src/entry.node.ts")).then(
|
|
7
8
|
(m) => m.default
|
|
8
9
|
);
|
|
9
10
|
}
|
|
11
|
+
async function getDistOptions() {
|
|
12
|
+
try {
|
|
13
|
+
const m = await import(resolveImportPath(process.cwd(), "./dist/node/src/entry.node.mjs"));
|
|
14
|
+
return m.default;
|
|
15
|
+
} catch (e) {
|
|
16
|
+
console.error(
|
|
17
|
+
styleText(
|
|
18
|
+
"red",
|
|
19
|
+
"Failed to load dist entry: dist/node/src/entry.node.mjs"
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
console.error(styleText("yellow", "Run `esmx build` and try again."));
|
|
23
|
+
process.exit(17);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
10
26
|
export async function cli(command) {
|
|
11
|
-
|
|
27
|
+
console.log(`\u{1F525} ${styleText("yellow", "Esmx")} v${pkg.version}
|
|
28
|
+
`);
|
|
29
|
+
if (command !== COMMAND.dev && typeof process.env.NODE_ENV === "undefined") {
|
|
12
30
|
process.env.NODE_ENV = "production";
|
|
13
31
|
}
|
|
14
32
|
let esmx;
|
|
@@ -22,9 +40,12 @@ export async function cli(command) {
|
|
|
22
40
|
opts = null;
|
|
23
41
|
break;
|
|
24
42
|
case COMMAND.start:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
43
|
+
opts = await getDistOptions();
|
|
44
|
+
esmx = new Esmx(opts);
|
|
45
|
+
exit(await esmx.init(COMMAND.start));
|
|
46
|
+
esmx = null;
|
|
47
|
+
opts = null;
|
|
48
|
+
break;
|
|
28
49
|
case COMMAND.build:
|
|
29
50
|
opts = await getSrcOptions();
|
|
30
51
|
esmx = new Esmx(opts);
|
|
@@ -53,7 +74,7 @@ export async function cli(command) {
|
|
|
53
74
|
opts = null;
|
|
54
75
|
break;
|
|
55
76
|
default:
|
|
56
|
-
await import(
|
|
77
|
+
await import(resolveImportPath(process.cwd(), command));
|
|
57
78
|
break;
|
|
58
79
|
}
|
|
59
80
|
}
|
|
@@ -62,7 +83,7 @@ function exit(ok) {
|
|
|
62
83
|
process.exit(17);
|
|
63
84
|
}
|
|
64
85
|
}
|
|
65
|
-
module.register(
|
|
86
|
+
module.register(import.meta.url, {
|
|
66
87
|
parentURL: import.meta.url
|
|
67
88
|
});
|
|
68
89
|
export function resolve(specifier, context, nextResolve) {
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node --no-warnings --experimental-vm-modules --experimental-import-meta-resolve --experimental-strip-types
|
|
2
|
+
import { enableCompileCache } from "node:module";
|
|
3
|
+
try {
|
|
4
|
+
enableCompileCache();
|
|
5
|
+
} catch {
|
|
6
|
+
}
|
|
2
7
|
import { cli } from "./cli.mjs";
|
|
3
8
|
cli(process.argv.slice(2)[0] || "");
|