@pactor-app/module-pack 0.0.0-stage → 1.56.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pactor Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,104 @@
1
- # Temporary Holding Version
1
+ # @pactor-app/module-pack
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 把 Pactor 应用工程打包为 Shell(如 innospots-web-shell)可装配的 npm 模块(Manifest V1)。
4
+
5
+ - 可编程 API:`buildModule` / `validateModule` / `initModule` / `bumpPackageVersion`;
6
+ - CLI 薄封装:`pactor module init|build|validate|pack|publish`(见 `@pactor-app/cli`)。
7
+
8
+ ## 用法
9
+
10
+ ```bash
11
+ pactor module init # 一次性:生成 pactor.module.json、module/client.ts、module/module.css,注入 package.json
12
+ pactor module init --server # 同上,并额外生成 module/server.ts、写入 serverEntry / apiPrefixes
13
+ pactor module build # 每次发布:构建 dist-module/(Manifest V1 + DSL + client + server + assets)
14
+ pactor module validate # 校验产物契约
15
+ pactor module pack # 递增版本号(默认 patch,--bump/--no-bump 控制)+ build + npm pack 生成 tgz
16
+ pactor module publish # pack 全流程 + npm publish 发布(--registry/--tag/--access/--otp/--dry-run)
17
+ ```
18
+
19
+ ```ts
20
+ import { buildModule } from '@pactor-app/module-pack';
21
+
22
+ const result = buildModule({ dir: process.cwd() });
23
+ console.log(result.stats, result.warnings);
24
+ ```
25
+
26
+ ## 转换链路
27
+
28
+ 收集 `yamlRoot`(页面 / 布局 / 片段)→ `$include` 递归展开(循环引用检测)→
29
+ sitemap 转换(布局字符串内联、菜单去 `path`、`lazy` 按 target profile 开关、
30
+ demo `public` 标记)→ URL 重写(导航 `to` 加 `basePath` 前缀、资源 URL 重写为
31
+ `/modules/<id>/<version>/`、http 外链不动、绝对 API 地址告警并降相对;
32
+ 配置了 `apiPrefixes` 时命中前缀的 `/api/...` 改写为
33
+ `/api/modules/<id>/...`)→
34
+ esbuild 打包 client entry(react / next / pactor-app / @pactor-app/* external,
35
+ alias 自动取 tsconfig paths)→ 可选 Tailwind 预编译 → 可选 server entry 打包
36
+ (`server/index.mjs`,Node ESM,框架依赖 external)→ Manifest V1 + assets(sha256 清单)。
37
+
38
+ ## target profile
39
+
40
+ 底座契约显式化,避免把 Shell 的临时缺陷写死:
41
+
42
+ - `innospots-web-shell@1`:`forceInlinePages: true`(兼容 lazy 端点未修复的旧 Shell);
43
+ - `innospots-web-shell@2`:lazy 端点已返回 PageResource 信封,`lazy: true` 保留;
44
+ - `innospots-web-shell@3`(默认):在 @2 基础上支持 `/api/modules/<moduleId>/*`
45
+ 通用模块 API 分发(`moduleServerApi: true`)。未使用 server entry 的模块产物与 @2 一致。
46
+
47
+ 未知 profile 报错并列出可用值;`basePath: "/"` 被 `forbidRootBasePath` 拒绝。
48
+
49
+ ## 模块服务端 API(server entry)
50
+
51
+ 模块可把自己的业务 API 一起打进 tgz,由 Shell 统一承接,无需在宿主工程复制路由。
52
+
53
+ `pactor module init --server` 会生成 `module/server.ts` 模板,并在新建的
54
+ `pactor.module.json` 中写入 `serverEntry` 与默认 `apiPrefixes`(`/api/<模块 slug>`);
55
+ 已有配置不会被改写,需手动补齐这两项。
56
+
57
+ ```jsonc
58
+ {
59
+ "serverEntry": "module/server.ts", // 与 apiPrefixes 必须成对出现
60
+ "apiPrefixes": ["/api/risk-analysis"] // 命中前缀的 DSL URL 自动 namespacing
61
+ }
62
+ ```
63
+
64
+ `module/server.ts` 导出逻辑路径到方法的处理函数映射:
65
+
66
+ ```ts
67
+ export const handlers = {
68
+ "/api/risk-analysis/data-value": {
69
+ GET: (request, context) =>
70
+ Response.json({ code: 0, data: { ok: true }, message: "ok" }),
71
+ },
72
+ };
73
+ ```
74
+
75
+ - 路径键使用模块逻辑路径(原始 `/api/...`),支持 `:param` 段;handler 只依赖
76
+ Web 标准 `Request` / `Response`,`context.url` 是逻辑 URL(含 query)。
77
+ - 公开 URL 为 `/api/modules/<moduleId>/<原 /api 之后的路径>`。
78
+ - 产物 `server/index.mjs`(使用 `.mjs` 是因为模块包通常没有 `"type": "module"`);
79
+ manifest 同步输出可选的 `serverEntry` / `apiPrefixes`。
80
+ - `package.json` 需声明 `"exports": { "./server": "./dist-module/server/index.mjs" }`
81
+ (`pactor module init` 检测到 `module/server.ts` 时会自动注入)。
82
+ - 使用 server entry 的模块必须把 `target` 设为 `innospots-web-shell@3`。
83
+ - 前缀不能是 `/api`、不能含尾斜杠/query/hash/通配/`:param`;`/api/modules` 与
84
+ `/api/runtime` 为保留前缀;同一模块内前缀不得重复或互相包含。
85
+
86
+ ## 配置(pactor.module.json)
87
+
88
+ ```jsonc
89
+ {
90
+ "id": "risk", // 必填,模块 id(globalPageId 前缀)
91
+ "name": "AI Risk Mesh",
92
+ "basePath": "/risk", // 默认 /<id>;禁止 "/"
93
+ "yamlRoot": "src/server/yaml", // 默认值
94
+ "clientEntry": "module/client.ts", // 默认值;不存在时按纯 DSL 模块跳过 bundle
95
+ "serverEntry": "module/server.ts", // 可选;与 apiPrefixes 成对配置
96
+ "apiPrefixes": ["/api/risk-analysis"], // 可选;模块 API 逻辑前缀
97
+ "actions": [], // init 自动发现 src/pactor/*-actions.ts
98
+ "publicDir": "public", // 默认值
99
+ "target": "innospots-web-shell@3", // 默认值;server entry 需要 @3
100
+ "access": { "default": "public" }, // 访问默认值:public 时给未声明 public/permission 的页面/菜单补 public
101
+ "tailwind": { "enabled": false }, // 可选 Tailwind 预编译
102
+ "rewrite": { "absoluteApiToRelative": true } // 绝对 API 地址降为相对路径
103
+ }
104
+ ```