@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.
Files changed (74) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +52 -20
  3. package/README.zh-CN.md +61 -0
  4. package/dist/app.d.ts +28 -28
  5. package/dist/app.mjs +1 -1
  6. package/dist/cli/cli.mjs +31 -10
  7. package/dist/cli/index.mjs +5 -0
  8. package/dist/core.d.ts +714 -0
  9. package/dist/core.mjs +907 -0
  10. package/dist/index.d.ts +6 -6
  11. package/dist/index.mjs +3 -10
  12. package/dist/manifest-json.d.ts +53 -26
  13. package/dist/manifest-json.mjs +7 -8
  14. package/dist/module-config.d.ts +47 -177
  15. package/dist/module-config.mjs +180 -69
  16. package/dist/module-config.test.d.ts +1 -0
  17. package/dist/module-config.test.mjs +743 -0
  18. package/dist/pack-config.d.ts +95 -95
  19. package/dist/pack-config.test.d.ts +1 -0
  20. package/dist/pack-config.test.mjs +60 -0
  21. package/dist/render-context.d.ts +466 -466
  22. package/dist/render-context.mjs +338 -338
  23. package/dist/utils/cache.d.ts +15 -15
  24. package/dist/utils/cache.test.d.ts +1 -0
  25. package/dist/utils/cache.test.mjs +47 -0
  26. package/dist/utils/file-size-stats.d.ts +29 -0
  27. package/dist/utils/file-size-stats.mjs +120 -0
  28. package/dist/utils/file-size-stats.test.d.ts +1 -0
  29. package/dist/utils/file-size-stats.test.mjs +183 -0
  30. package/dist/utils/import-map.d.ts +50 -6
  31. package/dist/utils/import-map.mjs +104 -24
  32. package/dist/utils/import-map.test.d.ts +1 -0
  33. package/dist/utils/import-map.test.mjs +1586 -0
  34. package/dist/utils/middleware.d.ts +20 -20
  35. package/dist/utils/middleware.mjs +26 -25
  36. package/dist/utils/middleware.test.d.ts +1 -0
  37. package/dist/utils/middleware.test.mjs +109 -0
  38. package/dist/utils/path-without-index.mjs +1 -0
  39. package/dist/utils/path-without-index.test.d.ts +1 -0
  40. package/dist/utils/path-without-index.test.mjs +23 -0
  41. package/dist/utils/resolve-path.d.ts +2 -1
  42. package/dist/utils/resolve-path.mjs +5 -0
  43. package/dist/utils/resolve-path.test.d.ts +1 -0
  44. package/dist/utils/resolve-path.test.mjs +81 -0
  45. package/dist/utils/static-import-lexer.d.ts +17 -15
  46. package/dist/utils/static-import-lexer.mjs +21 -22
  47. package/package.json +17 -20
  48. package/src/app.ts +37 -37
  49. package/src/cli/cli.ts +40 -18
  50. package/src/cli/index.ts +7 -0
  51. package/src/core.ts +1190 -0
  52. package/src/index.ts +30 -23
  53. package/src/manifest-json.ts +59 -35
  54. package/src/module-config.test.ts +828 -0
  55. package/src/module-config.ts +292 -253
  56. package/src/pack-config.test.ts +75 -0
  57. package/src/pack-config.ts +95 -95
  58. package/src/render-context.ts +466 -466
  59. package/src/utils/cache.test.ts +56 -0
  60. package/src/utils/cache.ts +15 -15
  61. package/src/utils/file-size-stats.test.ts +212 -0
  62. package/src/utils/file-size-stats.ts +189 -0
  63. package/src/utils/import-map.test.ts +1780 -0
  64. package/src/utils/import-map.ts +191 -37
  65. package/src/utils/middleware.test.ts +168 -0
  66. package/src/utils/middleware.ts +48 -48
  67. package/src/utils/path-without-index.test.ts +25 -0
  68. package/src/utils/path-without-index.ts +1 -0
  69. package/src/utils/resolve-path.test.ts +91 -0
  70. package/src/utils/resolve-path.ts +10 -2
  71. package/src/utils/static-import-lexer.ts +41 -42
  72. package/dist/gez.d.ts +0 -703
  73. package/dist/gez.mjs +0 -842
  74. package/src/gez.ts +0 -1026
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Vanelink
3
+ Copyright (c) 2020 Esmx Team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,29 +1,61 @@
1
- # @esmx/core
2
-
3
- 提供现代化的微前端解决方案和模块链接能力,为应用开发提供强大的基础支持。
4
-
5
- ## 特性
6
-
7
- - 🚀 **原生微前端** - 基于 ESM + importmap 的原生模块加载,零运行时开销
8
- - 💡 **依赖管理** - 中心化的依赖管理,基于内容哈希的强缓存策略
9
- - 🎨 **应用隔离** - ESM 原生模块隔离,保障应用运行时的稳定性
10
- - 🛠️ **SSR 支持** - 灵活的服务端渲染策略,支持任意前端框架
11
- - 🔧 **开发体验** - 完整的 TypeScript 支持,原生模块链接能力
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
- 访问 [@esmx/core 官方文档](https://www.esmnext.com) 获取详细的使用指南和 API 文档。
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)
@@ -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 './esmx';
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 Esmx 框架的应用抽象,提供了统一的接口来管理应用的生命周期、
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
- * // 自定义 Rspack 配置
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
- * - 使用 no-cache 缓存策略
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
- * - 支持不可变文件的长期缓存(.final.xxx
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
- * - 生产环境(start):加载构建后的服务端入口文件(entry.server)执行渲染
52
- * - 开发环境(dev):加载源码中的服务端入口文件执行渲染
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 构建成功返回 true,失败返回 false
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 清理成功返回 true,失败返回 false
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.root);
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 path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { COMMAND, Esmx } from "../esmx";
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(path.resolve(process.cwd(), "./src/entry.node.ts")).then(
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
- if (command !== COMMAND.dev) {
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
- throw new Error(
26
- `Please use 'NODE_ENV=production node dist/index.js' to run the built program`
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(path.resolve(process.cwd(), command));
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(fileURLToPath(import.meta.url), {
86
+ module.register(import.meta.url, {
66
87
  parentURL: import.meta.url
67
88
  });
68
89
  export function resolve(specifier, context, nextResolve) {
@@ -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] || "");