@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.
@@ -0,0 +1,550 @@
1
+ /**
2
+ * `buildModule`:模块构建全链路编排。
3
+ *
4
+ * 收集 → $include 展开 → sitemap 转换(profile)→ URL 重写 → client bundle →
5
+ * Tailwind 预编译 → manifest/assets 落盘 → 产物校验。
6
+ *
7
+ * 失败即阻断:全部产物先写入工程根下的临时目录,校验通过后才整体替换
8
+ * dist-module/;任一页面缺失或校验失败抛 ModuleBuildError,不留半成品。
9
+ */
10
+ /** 构建失败(含结构化错误列表,如页面缺失 / 校验失败) */
11
+ declare class ModuleBuildError extends Error {
12
+ readonly errors: string[];
13
+ constructor(message: string, errors: string[]);
14
+ }
15
+ interface BuildModuleOptions {
16
+ /** 目标工程根(默认 cwd) */
17
+ dir?: string;
18
+ /** 配置文件路径(默认 pactor.module.json) */
19
+ config?: string;
20
+ }
21
+ interface BuildModuleResult {
22
+ /** 产物目录(绝对路径) */
23
+ outDir: string;
24
+ stats: {
25
+ pages: number;
26
+ menus: number;
27
+ layouts: number;
28
+ assets: number;
29
+ };
30
+ clientBundled: boolean;
31
+ serverBundled: boolean;
32
+ warnings: string[];
33
+ }
34
+ /** 执行模块构建全链路,返回产物摘要;失败抛 ModuleBuildError */
35
+ declare function buildModule(options?: BuildModuleOptions): BuildModuleResult;
36
+
37
+ /**
38
+ * 产物校验(`pactor module validate`,构建收尾也会自动执行):
39
+ * - manifest 合法且字段齐备(Manifest V1);
40
+ * - sitemap 每个 pages[].id 在 dslRoot 下存在对应 <id>.yaml(与 Shell 装配器同语义,递归查找);
41
+ * - 产物中无 $include 残留;
42
+ * - layouts 全部为对象(无字符串引用残留);
43
+ * - client bundle 存在且未内嵌 react / @pactor-app(启发式扫描);
44
+ * - package.json exports 含 ./manifest 与 ./client。
45
+ * 输出结构化错误 / 警告列表;有错误时 ok = false。
46
+ */
47
+ interface ValidateModuleOptions {
48
+ /** 目标工程根(默认 cwd) */
49
+ dir?: string;
50
+ /** 配置文件路径(默认 pactor.module.json) */
51
+ config?: string;
52
+ /** 直接指定产物目录(构建流程内部用于校验临时目录;缺省为 <dir>/<outDir>) */
53
+ moduleDir?: string;
54
+ }
55
+ interface ValidateModuleResult {
56
+ ok: boolean;
57
+ errors: string[];
58
+ warnings: string[];
59
+ }
60
+ /** 校验产物目录与工程 package.json,返回结构化结果 */
61
+ declare function validateModule(options?: ValidateModuleOptions): ValidateModuleResult;
62
+
63
+ /**
64
+ * `initModule`:目标工程接入面的一次性初始化(幂等、只新增不破坏):
65
+ * - 生成 pactor.module.json(已存在则跳过);
66
+ * - 生成 module/client.ts + module/module.css(已存在则跳过);
67
+ * - `--server` 时额外生成 module/server.ts 并在新建配置中写入 serverEntry / apiPrefixes;
68
+ * - 向 package.json 注入 files / exports / scripts / peerDependencies
69
+ * (已存在的字段不覆盖,冲突时 warning)。
70
+ * 绝不修改目标工程 app/、src/ 下的任何现有文件。
71
+ */
72
+ /** 生成的模块样式入口(与 client entry 同属脚手架,由 client.ts import) */
73
+ declare const CLIENT_STYLES_ENTRY = "module/module.css";
74
+ /** 默认 server 入口(仅 `init --server` 生成) */
75
+ declare const SERVER_ENTRY = "module/server.ts";
76
+ interface InitModuleOptions {
77
+ /** 目标工程根(默认 cwd) */
78
+ dir?: string;
79
+ /**
80
+ * 覆盖已存在的初始化文件(pactor.module.json / module/client.ts / 脚手架样式,
81
+ * --server 时含 module/server.ts)。
82
+ * 缺省 false 时跳过已存在文件;由 CLI 负责询问用户后传入。
83
+ */
84
+ overwrite?: boolean;
85
+ /**
86
+ * 额外生成 module/server.ts,并在新建的 pactor.module.json 中写入
87
+ * serverEntry 与 apiPrefixes(默认 /api/<模块 slug>)。
88
+ * 缺省 false:纯 DSL 模块不引入 server entry。
89
+ */
90
+ server?: boolean;
91
+ }
92
+ interface InitModuleResult {
93
+ created: string[];
94
+ /** overwrite 时重新生成(覆盖)的文件 */
95
+ overwritten: string[];
96
+ skipped: string[];
97
+ warnings: string[];
98
+ }
99
+ interface ActionSource {
100
+ /** 工程相对导入路径(无扩展名,如 ../src/pactor/risk-actions) */
101
+ specifier: string;
102
+ /** 具名导出(如 riskActions) */
103
+ exports: string[];
104
+ }
105
+ /** 执行初始化,返回创建 / 覆盖 / 跳过 / 告警清单 */
106
+ declare function initModule(options?: InitModuleOptions): InitModuleResult;
107
+ /** 模块 id 统一前缀(缺省自动补齐,已有则不重复添加) */
108
+ declare const MODULE_ID_PREFIX = "pactor-app-";
109
+ /** 从包名推导模块 id:去 scope、kebab 化、补 pactor-app- 前缀 */
110
+ declare function deriveModuleId(name: unknown): string;
111
+ /** 由模块 id 推导默认 API 前缀:/api/<去掉 pactor-app- 前缀的 slug> */
112
+ declare function deriveApiPrefix(moduleId: string): string;
113
+ /** 扫描 src/pactor/*-actions.ts 的具名导出(export const xxx) */
114
+ declare function discoverActions(projectDir: string): ActionSource[];
115
+ /** 检测 src/pactor/components/index.ts 是否导出 pactorComponents */
116
+ declare function discoverComponents(projectDir: string): boolean;
117
+ /** 生成 module/client.ts 内容(export const extensions = { components, actions }) */
118
+ declare function renderClientEntry(hasComponents: boolean, actions: ActionSource[]): string;
119
+ /** 生成 module/module.css 内容(模块自带样式入口,随 client bundle 打进 tgz) */
120
+ declare function renderModuleStyles(): string;
121
+ /** 生成 module/server.ts 内容(逻辑路径 → 方法处理函数映射) */
122
+ declare function renderServerEntry(moduleId: string): string;
123
+
124
+ /**
125
+ * `pactor.module.json` 配置加载与校验(手写校验,避免重依赖)。
126
+ * 字段见设计文档 §3.2;未提供的字段使用合理默认值。
127
+ */
128
+ /** 配置相关错误(缺失 / 解析失败 / 类型非法) */
129
+ declare class ConfigError extends Error {
130
+ }
131
+ declare const CONFIG_FILE = "pactor.module.json";
132
+ interface TailwindConfig {
133
+ enabled: boolean;
134
+ /** 自定义入口 css(工程相对路径);缺省时生成 @import "tailwindcss" + @source */
135
+ input?: string;
136
+ /** 额外扫描目录(绝对路径或工程相对路径);缺省扫描 dist-module/dsl 与 client 源码目录 */
137
+ scan?: string[];
138
+ }
139
+ interface ModulePackConfig {
140
+ /** 模块 id(进入 globalPageId 前缀与资源路径) */
141
+ id: string;
142
+ name: string;
143
+ /** 路由前缀(规范化保证以 / 开头、无尾斜杠) */
144
+ basePath: string;
145
+ yamlRoot: string;
146
+ clientEntry: string;
147
+ /** 服务端入口(工程相对路径,如 module/server.ts);与 apiPrefixes 成对出现 */
148
+ serverEntry?: string;
149
+ /**
150
+ * 模块 API 逻辑前缀(如 /api/risk-analysis)。打包时命中这些前缀的 DSL URL
151
+ * 会改写为 /api/modules/<id>/...,由 Shell 的通用分发入口承接。
152
+ */
153
+ apiPrefixes?: string[];
154
+ /** init 时自动发现的 src/pactor/*-actions.ts(仅记录,client entry 自行 import) */
155
+ actions: string[];
156
+ publicDir: string;
157
+ /** target profile id(如 innospots-web-shell@2) */
158
+ target: string;
159
+ /**
160
+ * 模块级访问默认值:'public' 时构建期给未声明 public/permission 的
161
+ * pages / menus 补 public: true(缺省填充);默认 'authenticated' 不改动。
162
+ */
163
+ access: {
164
+ default: 'public' | 'authenticated';
165
+ };
166
+ tailwind: TailwindConfig;
167
+ rewrite: {
168
+ /** 绝对 API 地址重写为去 origin 的相对路径(默认 true) */
169
+ absoluteApiToRelative: boolean;
170
+ };
171
+ /** 产物目录(工程相对路径,默认 dist-module) */
172
+ outDir: string;
173
+ }
174
+ declare const CONFIG_DEFAULTS: {
175
+ readonly yamlRoot: "src/server/yaml";
176
+ readonly clientEntry: "module/client.ts";
177
+ readonly publicDir: "public";
178
+ readonly target: string;
179
+ readonly outDir: "dist-module";
180
+ };
181
+ /** 加载并校验工程根下的 pactor.module.json(或 --config 指定文件) */
182
+ declare function loadModuleConfig(projectDir: string, configPath?: string): ModulePackConfig;
183
+
184
+ /**
185
+ * Target profile:底座(Shell)装配契约的显式化描述。
186
+ *
187
+ * 若干打包转换本质上是当前 Shell 实现的缺陷规避(菜单去 path、布局内联、
188
+ * 去 lazy、basePath 禁止 "/"),而非永恒契约;Shell 修复后应发布新版本
189
+ * profile,模块侧改一行 `target` 即可重新打包,不改动适配器代码。
190
+ */
191
+ /** 导航重写行为 */
192
+ interface RewriteNavigationProfile {
193
+ /** 模块内绝对导航路径加 basePath 前缀 */
194
+ basePath: boolean;
195
+ /** 绝不重写 request 的 API url 与 http(s) 外链 */
196
+ excludeApiUrls: boolean;
197
+ }
198
+ interface TargetProfile {
199
+ /** profile 名(如 innospots-web-shell) */
200
+ name: string;
201
+ /** profile 版本(与 target 配置 `@<version>` 对应) */
202
+ version: number;
203
+ /** sitemap 中字符串形式的布局引用内联为布局对象 */
204
+ inlineStringLayouts: boolean;
205
+ /** 删除菜单显式 path(交给运行时按 pageId 从 pages 解析) */
206
+ stripMenuPaths: boolean;
207
+ /** 删除页面 lazy(页面随 bootstrap 内联下发;Shell lazy 端点修好前为 true) */
208
+ forceInlinePages: boolean;
209
+ rewriteNavigation: RewriteNavigationProfile;
210
+ /** 静态资源 URL 重写前缀(如 `/modules/<id>/<version>/`) */
211
+ rewriteAssetUrls: (id: string, version: string) => string;
212
+ /** 禁止 basePath: "/"(Shell joinPublicPath 会产生 "//login" 这类坏路径) */
213
+ forbidRootBasePath: boolean;
214
+ /** Shell 支持 `/api/modules/<moduleId>/*` 通用模块 API 分发 */
215
+ moduleServerApi: boolean;
216
+ }
217
+
218
+ /**
219
+ * innospots-web-shell@1:兼容 lazy 页面端点未修复的旧 Shell
220
+ * (端点返回 { version, pageDsl } 与 Pactor loader 期望的 resource.schema
221
+ * 不一致),强制页面随 bootstrap 内联下发(去掉 lazy)。
222
+ */
223
+ declare const innospotsWebShellV1: TargetProfile;
224
+ /**
225
+ * innospots-web-shell@2:Shell lazy 页面端点已修复,
226
+ * 返回 PageResource 信封 { id, resourceType: "page", version, dslVersion, schema },
227
+ * 与 @pactor-app/app createSitemapLoader 契约对齐,lazy: true 原样保留。
228
+ */
229
+ declare const innospotsWebShellV2: TargetProfile;
230
+ /**
231
+ * innospots-web-shell@3(当前默认):在 @2 的页面/导航/资源契约之上,
232
+ * Shell 新增 `/api/modules/<moduleId>/*` 通用分发入口,支持模块把
233
+ * server entry(module/server.ts)打进 tgz 并由 Shell 统一承接。
234
+ * 未使用 serverEntry 的模块产物与 @2 完全一致。
235
+ */
236
+ declare const innospotsWebShellV3: TargetProfile;
237
+
238
+ /** 未知 profile 错误(信息中列出可用值) */
239
+ declare class ProfileError extends Error {
240
+ }
241
+ /** 默认 target:支持模块 server entry 的 Shell 契约版本 */
242
+ declare const DEFAULT_TARGET: string;
243
+ /** 全部可用 profile id(用于报错提示与文档) */
244
+ declare function listProfiles(): string[];
245
+ /** 按 `name@version` 解析 profile;未知名抛出带可用值列表的 ProfileError */
246
+ declare function getProfile(id: string): TargetProfile;
247
+
248
+ /**
249
+ * 从 yamlRoot 收集模块源文件清单(与 PoC collectPages 语义一致):
250
+ * - 页面:递归 `*.yaml`,排除 sitemap.yaml / *.layout.yaml / *.fragment.yaml;
251
+ * 页面 id 为文件名去掉 `.yaml`,再去掉可选的 `.page` 后缀;
252
+ * - 布局文件:*.layout.yaml;片段文件:*.fragment.yaml(仅登记,内容由 $include 引用)。
253
+ */
254
+ interface CollectedSource {
255
+ yamlRoot: string;
256
+ /** pageId -> yamlRoot 相对路径 */
257
+ pages: Map<string, string>;
258
+ /** *.layout.yaml 的 yamlRoot 相对路径列表 */
259
+ layouts: string[];
260
+ /** *.fragment.yaml 的 yamlRoot 相对路径列表 */
261
+ fragments: string[];
262
+ /** 收集期警告(如页面 id 重复) */
263
+ warnings: string[];
264
+ }
265
+ /** 递归收集 yamlRoot 下的页面 / 布局 / 片段文件 */
266
+ declare function collectModuleSource(yamlRoot: string): CollectedSource;
267
+
268
+ /**
269
+ * `$include` 展开器(语义以 PoC build-adapter.mjs 为蓝本):
270
+ * - `$include` 必须是对象唯一键,值为 yamlRoot 相对路径字符串;
271
+ * - 递归展开,循环引用报错并带引用链;
272
+ * - 解析失败的错误均带文件上下文。
273
+ *
274
+ * 注意:`$include` 目前是应用层约定(各工程在自己的 sitemap.ts 中重复实现),
275
+ * 本实现是上游化为框架能力的第一步,后续应迁移到 dsl-io 供运行时与打包共用。
276
+ */
277
+ declare const INCLUDE_KEY = "$include";
278
+ /** include 展开相关错误(循环引用 / 非法 $include / YAML 语法错误) */
279
+ declare class IncludeError extends Error {
280
+ }
281
+ /** 解析 YAML 文件为 JS 值,语法错误带文件路径 */
282
+ declare function parseYamlFile(file: string): unknown;
283
+ interface ExpandContext {
284
+ yamlRoot: string;
285
+ /** 当前文件(yamlRoot 相对路径,用于错误信息) */
286
+ current: string;
287
+ /** 引用链(yamlRoot 相对路径),用于循环检测 */
288
+ stack: string[];
289
+ }
290
+ /**
291
+ * 加载 yamlRoot 下的相对路径文件并递归展开其中的 `$include`。
292
+ * 循环引用时报错,信息形如 `循环引用: a.yaml -> b.yaml -> a.yaml`。
293
+ */
294
+ declare function loadYamlExpanded(yamlRoot: string, relPath: string, stack?: string[]): unknown;
295
+ /** 递归展开值中的 `$include` 节点(非 $include 对象/数组/标量原样递归返回) */
296
+ declare function expandIncludes(value: unknown, ctx: ExpandContext): unknown;
297
+
298
+ /**
299
+ * 按 target profile 转换 sitemap(语义以 PoC 为蓝本,全部由 profile 显式开关):
300
+ * - inlineStringLayouts:字符串形式的布局引用解析为内联布局对象;
301
+ * - stripMenuPaths:删除菜单显式 path(运行时按 pageId 从 pages 回填);
302
+ * - forceInlinePages:删除页面 lazy(随 bootstrap 内联下发);
303
+ * - accessDefault='public':给未声明 public/permission 的 pages / menus 补 public: true。
304
+ */
305
+ interface TransformSitemapOptions {
306
+ profile: TargetProfile;
307
+ /**
308
+ * 模块级访问默认值:'public' 时给未声明 public/permission 的 pages / menus
309
+ * 补 public: true(缺省填充,不覆盖显式声明);'authenticated' 不改动。
310
+ */
311
+ accessDefault?: 'public' | 'authenticated';
312
+ /** 解析字符串布局引用(yamlRoot 相对路径 -> 布局对象,应走 $include 展开) */
313
+ loadLayout: (relPath: string) => unknown;
314
+ }
315
+ interface TransformSitemapResult {
316
+ site: Record<string, unknown>;
317
+ layoutCount: number;
318
+ pageCount: number;
319
+ menuCount: number;
320
+ }
321
+ type AnyRecord = Record<string, unknown>;
322
+ /** 转换 sitemap(不修改入参,返回新对象) */
323
+ declare function transformSitemap(site: AnyRecord, options: TransformSitemapOptions): TransformSitemapResult;
324
+
325
+ /**
326
+ * DSL URL 重写(Shell 装配器不重写 DSL,必须在打包侧处理):
327
+ *
328
+ * - 导航重写:action 为 `navigate` / `app.reload` 的节点,其 `params.to`
329
+ * 若以 `/` 开头且命中模块内页面路径或 loginPath,加 basePath 前缀;
330
+ * 绝不重写 `request` 的 API `url`(`/api/...`)与 http(s) 外链。
331
+ * - 资源重写:字符串值以 `/` 开头、非 `/api/`、非页面路径,且对应文件存在于
332
+ * publicDir(如 `/next.svg`),重写为 `/modules/<id>/<version>/<path>`。
333
+ * - 绝对 API 地址(如 `http://localhost:8011/api/...`):记入 warning 列表;
334
+ * 默认重写为去掉 origin 的相对路径(可由配置关闭)。
335
+ */
336
+ interface RewriteContext {
337
+ /** 模块 basePath(已规范化为 `/xxx`,无尾斜杠) */
338
+ basePath: string;
339
+ /** sitemap 中全部页面 path(可含 `:param` 段) */
340
+ pagePaths: string[];
341
+ /** 登录页路径(sitemap auth.loginPath,默认 /login) */
342
+ loginPath: string;
343
+ /** 目标工程 public 目录(绝对路径,用于判断资源文件存在) */
344
+ publicDir: string;
345
+ /** 是否执行导航重写(profile.rewriteNavigation.basePath) */
346
+ rewriteNavigation: boolean;
347
+ /** 是否执行资源重写 */
348
+ rewriteAssets: boolean;
349
+ /** 资源重写前缀(如 `/modules/risk/0.1.0`,无尾斜杠) */
350
+ assetPrefix: string;
351
+ /** 绝对 API 地址重写为相对路径(false 时仅告警不改写) */
352
+ absoluteApiToRelative: boolean;
353
+ /** 模块 id(与 apiPrefixes 同时存在时,命中前缀的 API URL 改写为模块挂载路径) */
354
+ moduleId?: string;
355
+ /** 模块声明的逻辑 API 前缀(如 `/api/risk-analysis`) */
356
+ apiPrefixes?: string[];
357
+ }
358
+ interface RewriteResult {
359
+ value: unknown;
360
+ warnings: string[];
361
+ }
362
+ /** 遍历 DSL 值并重写 URL(不修改入参,返回新值与告警列表) */
363
+ declare function rewriteDslUrls(value: unknown, ctx: RewriteContext): RewriteResult;
364
+ /**
365
+ * 导航 `to` 重写:命中模块内页面路径或 loginPath 时加 basePath 前缀;
366
+ * 返回 undefined 表示不重写。模板表达式段(`${...}`)按原样保留。
367
+ */
368
+ declare function rewriteNavigationTo(to: string, ctx: RewriteContext): string | undefined;
369
+ /**
370
+ * 路径模式匹配:`:param` 段匹配任意非空段(含 `${...}` 模板段),
371
+ * 字面值段必须相等;忽略查询串。
372
+ */
373
+ declare function matchPathPattern(pattern: string, value: string): boolean;
374
+
375
+ /**
376
+ * client entry 打包(esbuild):
377
+ * - `--bundle --format=esm --platform=browser`,react / react-dom / next /
378
+ * pactor-app / @pactor-app/* 全部 external(peer 单例契约,防双实例);
379
+ * - alias 自动从目标工程 tsconfig.json 的 compilerOptions.paths 生成(如 `@/*` → `./src/*`);
380
+ * - 产出 client/index.js + sourcemap;入口引入的 CSS 由 esbuild 收集为 client/index.css;
381
+ * - client entry 不存在时跳过(纯 DSL 模块合法),由调用方提示。
382
+ */
383
+ /** 内置 externals:peer 单例,绝不打进 bundle */
384
+ declare const CLIENT_EXTERNALS: string[];
385
+ interface BundleClientOptions {
386
+ projectDir: string;
387
+ /** 工程相对路径(配置 clientEntry) */
388
+ clientEntry: string;
389
+ /** 输出目录(绝对路径,产物为 index.js / index.js.map / 可能的 index.css) */
390
+ outDir: string;
391
+ }
392
+ interface BundleClientResult {
393
+ bundled: boolean;
394
+ /** 是否产出 index.css(esbuild 收集的 side-effect CSS) */
395
+ css: boolean;
396
+ /** 跳过打包时的说明(纯 DSL 模块) */
397
+ message?: string;
398
+ }
399
+ /** esbuild 打包 client entry;入口不存在时跳过打包 */
400
+ declare function bundleClient(options: BundleClientOptions): BundleClientResult;
401
+ /**
402
+ * 从目标工程 tsconfig.json 的 compilerOptions.paths 生成 esbuild alias。
403
+ * 支持 `@/*` -> `./src/*` 通配(alias 为去掉 `/*` 的包名)与精确映射;
404
+ * 沿 `extends`(相对路径)合并,子配置覆盖父配置。
405
+ */
406
+ declare function tsconfigAliases(projectDir: string): Record<string, string>;
407
+ /** 宽松 JSONC 解析:去注释(尊重字符串字面量)与尾逗号 */
408
+ declare function parseJsonc(text: string): unknown;
409
+
410
+ /**
411
+ * server entry 打包(esbuild):
412
+ * - `--bundle --format=esm --platform=node --target=node20`;
413
+ * - 产物固定为 server/index.mjs:模块包通常没有 `"type": "module"`,
414
+ * 若输出 .js 会被 Node 按 CJS 解析;esbuild 的 format=esm 不会自动改扩展名,
415
+ * 因此必须显式 outExtension;
416
+ * - react / next / pactor 保持 external(server 端不需要,也不该打入模块);
417
+ * Node built-in 由 platform=node 自动 external;
418
+ * - alias 复用 tsconfig 的 paths(如 `@/*` → `./src/*`);
419
+ * - 入口必须位于工程根内,防止越界读取。
420
+ */
421
+ /** 内置 externals:宿主/框架依赖,绝不打进 server bundle */
422
+ declare const SERVER_EXTERNALS: string[];
423
+ /** server 产物文件名(与 manifest.serverEntry 一致) */
424
+ declare const SERVER_BUNDLE_FILE: "index.mjs";
425
+ /** server 打包错误(入口缺失 / 越界 / 产物缺失) */
426
+ declare class ServerBundleError extends Error {
427
+ }
428
+ interface BundleServerOptions {
429
+ projectDir: string;
430
+ /** 工程相对路径(配置 serverEntry) */
431
+ serverEntry: string;
432
+ /** 输出目录(绝对路径,产物为 index.mjs / index.mjs.map) */
433
+ outDir: string;
434
+ }
435
+ interface BundleServerResult {
436
+ bundled: true;
437
+ entry: typeof SERVER_BUNDLE_FILE;
438
+ }
439
+ /** esbuild 打包 server entry;入口不存在或越界时抛 ServerBundleError */
440
+ declare function bundleServer(options: BundleServerOptions): BundleServerResult;
441
+
442
+ /**
443
+ * 可选 Tailwind 预编译(配置 `tailwind: { enabled, input?, scan? }`):
444
+ * 调用目标工程的 tailwindcss CLI(npx --no-install tailwindcss,v4 / @tailwindcss/cli),
445
+ * 扫描 dist-module/dsl 与 client 源码生成工具类 CSS,合并进 client/index.css。
446
+ * tailwind 不可用或编译失败时降级为 warning,不 fail 构建。
447
+ */
448
+ interface CompileTailwindOptions {
449
+ projectDir: string;
450
+ tailwind: TailwindConfig;
451
+ /** 默认扫描目录(dist-module/dsl 产物目录 + client entry 源码目录) */
452
+ scanDirs: string[];
453
+ /** 目标 CSS 文件(client/index.css,不存在则创建) */
454
+ cssFile: string;
455
+ }
456
+ interface CompileTailwindResult {
457
+ compiled: boolean;
458
+ warnings: string[];
459
+ }
460
+ /** 执行 Tailwind 预编译并把工具类 CSS 追加到 cssFile */
461
+ declare function compileTailwind(options: CompileTailwindOptions): CompileTailwindResult;
462
+
463
+ /**
464
+ * 产物落盘:dist-module/ = Manifest V1 + dsl/(sitemap + 页面 DSL)+
465
+ * assets/(public 复制)+ module-assets.json(sha256 清单)+ client/(由 bundle 阶段写入)。
466
+ *
467
+ * Manifest V1 契约对齐 Shell 装配器(assemble-modules.mjs):
468
+ * require.resolve("<pkg>/manifest") → manifest.json;pages[].id ↔ dslRoot 下
469
+ * <pageId>.yaml;assetsRoot 复制到 public/modules/<id>/<version>/。
470
+ */
471
+ interface ModuleManifest {
472
+ schemaVersion: '1';
473
+ id: string;
474
+ name: string;
475
+ /** 与目标工程 package.json version 同步 */
476
+ version: string;
477
+ /** 从目标工程安装的 pactor-app 版本推导(如 ^1.54.0) */
478
+ pactorVersionRange: string;
479
+ basePath: string;
480
+ sitemap: 'dsl/sitemap.yaml';
481
+ dslRoot: 'dsl';
482
+ assetsRoot: 'assets';
483
+ /** 纯 DSL 模块无 client bundle 时缺省 */
484
+ clientEntry?: 'client/index.js';
485
+ styles?: ['client/index.css'];
486
+ /** 服务端入口(存在 server bundle 时输出) */
487
+ serverEntry?: 'server/index.mjs';
488
+ /** 模块 API 逻辑前缀(与 serverEntry 成对输出) */
489
+ apiPrefixes?: string[];
490
+ }
491
+ interface EmitDslInput {
492
+ config: ModulePackConfig;
493
+ projectDir: string;
494
+ /** 产物目录(绝对路径,通常是临时构建目录) */
495
+ outDir: string;
496
+ /** 转换 + 重写后的 sitemap */
497
+ site: Record<string, unknown>;
498
+ /** pageId -> 展开 + 重写后的页面 DSL */
499
+ pages: Map<string, unknown>;
500
+ }
501
+ interface EmitDslResult {
502
+ assetCount: number;
503
+ }
504
+ interface WriteManifestInput {
505
+ config: ModulePackConfig;
506
+ projectDir: string;
507
+ outDir: string;
508
+ clientEntry?: 'client/index.js';
509
+ styles?: ['client/index.css'];
510
+ serverEntry?: 'server/index.mjs';
511
+ apiPrefixes?: string[];
512
+ /** 追加版本推导相关的告警 */
513
+ warnings: string[];
514
+ }
515
+ /** 一步落盘全部产物(dsl + assets + module-assets.json + manifest.json) */
516
+ declare function emitModule(input: EmitDslInput & Omit<WriteManifestInput, 'config' | 'projectDir' | 'outDir'>): EmitDslResult & {
517
+ manifest: ModuleManifest;
518
+ };
519
+ /** 落盘 dsl/(sitemap.yaml + <pageId>.yaml)与 assets/(含 module-assets.json) */
520
+ declare function emitDsl(input: EmitDslInput): EmitDslResult;
521
+ /** 生成 manifest.json(version 与目标工程 package.json 同步) */
522
+ declare function writeManifest(input: WriteManifestInput): ModuleManifest;
523
+ /** 读取目标工程 package.json 的 version(缺失时回退 0.0.0) */
524
+ declare function readProjectVersion(projectDir: string): string;
525
+ /**
526
+ * 推导 pactorVersionRange:优先目标工程 node_modules 中实际安装的
527
+ * pactor-app / @pactor-app/app 版本(^x.y.z);其次 package.json 中声明的
528
+ * 版本范围;都不可得时告警并回退 ^1.54.0。
529
+ */
530
+ declare function resolvePactorVersionRange(projectDir: string, warnings: string[]): string;
531
+
532
+ /** 版本递增类型:语义化级别或显式版本号(如 2.0.0 / 2.0.0-beta.1) */
533
+ type VersionRelease = 'major' | 'minor' | 'patch' | (string & {});
534
+ /** 计算下一版本号;release 为 major/minor/patch 时递增,否则按显式版本号原样采用 */
535
+ declare function bumpVersion(current: string, release: VersionRelease): string;
536
+ interface BumpPackageVersionOptions {
537
+ /** 工程根目录 */
538
+ dir?: string;
539
+ /** 递增级别或显式版本号 */
540
+ release: VersionRelease;
541
+ }
542
+ interface BumpPackageVersionResult {
543
+ name: string;
544
+ from: string;
545
+ to: string;
546
+ }
547
+ /** 递增工程 package.json 的 version 并写回(保留其余字段,2 空格缩进 + 末尾换行) */
548
+ declare function bumpPackageVersion(options: BumpPackageVersionOptions): BumpPackageVersionResult;
549
+
550
+ export { type BuildModuleOptions, type BuildModuleResult, type BumpPackageVersionOptions, type BumpPackageVersionResult, type BundleClientOptions, type BundleClientResult, type BundleServerOptions, type BundleServerResult, CLIENT_EXTERNALS, CLIENT_STYLES_ENTRY, CONFIG_DEFAULTS, CONFIG_FILE, type CollectedSource, type CompileTailwindOptions, type CompileTailwindResult, ConfigError, DEFAULT_TARGET, INCLUDE_KEY, IncludeError, type InitModuleOptions, type InitModuleResult, MODULE_ID_PREFIX, ModuleBuildError, type ModuleManifest, type ModulePackConfig, ProfileError, type RewriteContext, type RewriteNavigationProfile, type RewriteResult, SERVER_BUNDLE_FILE, SERVER_ENTRY, SERVER_EXTERNALS, ServerBundleError, type TailwindConfig, type TargetProfile, type TransformSitemapOptions, type TransformSitemapResult, type ValidateModuleOptions, type ValidateModuleResult, type VersionRelease, buildModule, bumpPackageVersion, bumpVersion, bundleClient, bundleServer, collectModuleSource, compileTailwind, deriveApiPrefix, deriveModuleId, discoverActions, discoverComponents, emitDsl, emitModule, expandIncludes, getProfile, initModule, innospotsWebShellV1, innospotsWebShellV2, innospotsWebShellV3, listProfiles, loadModuleConfig, loadYamlExpanded, matchPathPattern, parseJsonc, parseYamlFile, readProjectVersion, renderClientEntry, renderModuleStyles, renderServerEntry, resolvePactorVersionRange, rewriteDslUrls, rewriteNavigationTo, transformSitemap, tsconfigAliases, validateModule, writeManifest };