@pactor-app/module-pack 1.55.0 → 1.57.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/README.md +56 -10
- package/dist/index.cjs +508 -157
- package/dist/index.d.cts +122 -11
- package/dist/index.d.ts +122 -11
- package/dist/index.js +462 -124
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
把 Pactor 应用工程打包为 Shell(如 innospots-web-shell)可装配的 npm 模块(Manifest V1)。
|
|
4
4
|
|
|
5
|
-
- 可编程 API:`buildModule` / `validateModule` / `initModule`;
|
|
6
|
-
- CLI 薄封装:`pactor module init|build|validate|pack`(见 `@pactor-app/cli`)。
|
|
5
|
+
- 可编程 API:`buildModule` / `validateModule` / `initModule` / `bumpPackageVersion`;
|
|
6
|
+
- CLI 薄封装:`pactor module init|build|validate|pack|publish`(见 `@pactor-app/cli`)。
|
|
7
7
|
|
|
8
8
|
## 用法
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
pactor module init # 一次性:生成 pactor.module.json、module/client.ts,注入 package.json
|
|
12
|
-
pactor module
|
|
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)
|
|
13
14
|
pactor module validate # 校验产物契约
|
|
14
|
-
pactor module pack # build + npm pack 生成 tgz
|
|
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)
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
```ts
|
|
@@ -26,19 +28,61 @@ console.log(result.stats, result.warnings);
|
|
|
26
28
|
收集 `yamlRoot`(页面 / 布局 / 片段)→ `$include` 递归展开(循环引用检测)→
|
|
27
29
|
sitemap 转换(布局字符串内联、菜单去 `path`、`lazy` 按 target profile 开关、
|
|
28
30
|
demo `public` 标记)→ URL 重写(导航 `to` 加 `basePath` 前缀、资源 URL 重写为
|
|
29
|
-
`/modules/<id>/<version
|
|
31
|
+
`/modules/<id>/<version>/`、http 外链不动、绝对 API 地址告警并降相对;
|
|
32
|
+
配置了 `apiPrefixes` 时命中前缀的 `/api/...` 改写为
|
|
33
|
+
`/api/modules/<id>/...`)→
|
|
30
34
|
esbuild 打包 client entry(react / next / pactor-app / @pactor-app/* external,
|
|
31
|
-
alias 自动取 tsconfig paths)→ 可选 Tailwind 预编译 →
|
|
35
|
+
alias 自动取 tsconfig paths)→ 可选 Tailwind 预编译 → 可选 server entry 打包
|
|
36
|
+
(`server/index.mjs`,Node ESM,框架依赖 external)→ Manifest V1 + assets(sha256 清单)。
|
|
32
37
|
|
|
33
38
|
## target profile
|
|
34
39
|
|
|
35
40
|
底座契约显式化,避免把 Shell 的临时缺陷写死:
|
|
36
41
|
|
|
37
42
|
- `innospots-web-shell@1`:`forceInlinePages: true`(兼容 lazy 端点未修复的旧 Shell);
|
|
38
|
-
- `innospots-web-shell@2
|
|
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 一致。
|
|
39
46
|
|
|
40
47
|
未知 profile 报错并列出可用值;`basePath: "/"` 被 `forbidRootBasePath` 拒绝。
|
|
41
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
|
+
|
|
42
86
|
## 配置(pactor.module.json)
|
|
43
87
|
|
|
44
88
|
```jsonc
|
|
@@ -48,10 +92,12 @@ alias 自动取 tsconfig paths)→ 可选 Tailwind 预编译 → Manifest V1 +
|
|
|
48
92
|
"basePath": "/risk", // 默认 /<id>;禁止 "/"
|
|
49
93
|
"yamlRoot": "src/server/yaml", // 默认值
|
|
50
94
|
"clientEntry": "module/client.ts", // 默认值;不存在时按纯 DSL 模块跳过 bundle
|
|
95
|
+
"serverEntry": "module/server.ts", // 可选;与 apiPrefixes 成对配置
|
|
96
|
+
"apiPrefixes": ["/api/risk-analysis"], // 可选;模块 API 逻辑前缀
|
|
51
97
|
"actions": [], // init 自动发现 src/pactor/*-actions.ts
|
|
52
98
|
"publicDir": "public", // 默认值
|
|
53
|
-
"target": "innospots-web-shell@
|
|
54
|
-
"
|
|
99
|
+
"target": "innospots-web-shell@3", // 默认值;server entry 需要 @3
|
|
100
|
+
"access": { "default": "public" }, // 访问默认值:public 时给未声明 public/permission 的页面/菜单补 public
|
|
55
101
|
"tailwind": { "enabled": false }, // 可选 Tailwind 预编译
|
|
56
102
|
"rewrite": { "absoluteApiToRelative": true } // 绝对 API 地址降为相对路径
|
|
57
103
|
}
|