@longzai-intelligence-features/config 0.0.0-stage → 0.0.1
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/dist/index.d.ts +237 -0
- package/dist/index.js +5 -0
- package/dist/rolldown-runtime-BqT_7tdF.js +1 -0
- package/package.json +36 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import "./rolldown-runtime-BqT_7tdF.js";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
//#region src/schema/lzi-features-config.schema.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* scope key 合法形态,kebab-case
|
|
6
|
+
*/
|
|
7
|
+
declare const SCOPE_KEY_PATTERN: RegExp;
|
|
8
|
+
/**
|
|
9
|
+
* init 缺省注册表目录
|
|
10
|
+
*/
|
|
11
|
+
declare const DEFAULT_REGISTRY_DIR = "docs/features";
|
|
12
|
+
/**
|
|
13
|
+
* 棘轮基线条目 schema,存量豁免逐条带理由登记——存量不追溯,豁免只许缩短
|
|
14
|
+
*/
|
|
15
|
+
declare const baselineEntrySchema: z.ZodObject<{
|
|
16
|
+
file: z.ZodString;
|
|
17
|
+
rule: z.ZodString;
|
|
18
|
+
reason: z.ZodString;
|
|
19
|
+
}, z.core.$strict>;
|
|
20
|
+
/**
|
|
21
|
+
* 注册表排除条目 schema,存量子树保护——posix 相对注册表目录的路径前缀
|
|
22
|
+
*/
|
|
23
|
+
declare const exclusionEntrySchema: z.ZodObject<{
|
|
24
|
+
path: z.ZodString;
|
|
25
|
+
reason: z.ZodString;
|
|
26
|
+
}, z.core.$strict>;
|
|
27
|
+
/**
|
|
28
|
+
* scope 注册条目 schema
|
|
29
|
+
*/
|
|
30
|
+
declare const scopeSchema: z.ZodObject<{
|
|
31
|
+
key: z.ZodString;
|
|
32
|
+
title: z.ZodString;
|
|
33
|
+
paths: z.ZodArray<z.ZodString>;
|
|
34
|
+
registryDir: z.ZodString;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
/**
|
|
37
|
+
* scope 注册条目,书写形态
|
|
38
|
+
*/
|
|
39
|
+
type ScopeEntryInput = z.input<typeof scopeSchema>;
|
|
40
|
+
/**
|
|
41
|
+
* scope 注册条目,解析后形态
|
|
42
|
+
*/
|
|
43
|
+
type ScopeEntry = z.output<typeof scopeSchema>;
|
|
44
|
+
/**
|
|
45
|
+
* lzi-features 配置根 schema
|
|
46
|
+
*/
|
|
47
|
+
declare const lziFeaturesConfigSchema: z.ZodObject<{
|
|
48
|
+
scopes: z.ZodArray<z.ZodObject<{
|
|
49
|
+
key: z.ZodString;
|
|
50
|
+
title: z.ZodString;
|
|
51
|
+
paths: z.ZodArray<z.ZodString>;
|
|
52
|
+
registryDir: z.ZodString;
|
|
53
|
+
}, z.core.$strict>>;
|
|
54
|
+
check: z.ZodDefault<z.ZodObject<{
|
|
55
|
+
baseline: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
56
|
+
file: z.ZodString;
|
|
57
|
+
rule: z.ZodString;
|
|
58
|
+
reason: z.ZodString;
|
|
59
|
+
}, z.core.$strict>>>;
|
|
60
|
+
exclusions: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
61
|
+
path: z.ZodString;
|
|
62
|
+
reason: z.ZodString;
|
|
63
|
+
}, z.core.$strict>>>;
|
|
64
|
+
}, z.core.$strict>>;
|
|
65
|
+
}, z.core.$strict>;
|
|
66
|
+
/**
|
|
67
|
+
* lzi-features 配置,用户书写形态,可省略各默认值
|
|
68
|
+
*/
|
|
69
|
+
type LziFeaturesConfigInput = z.input<typeof lziFeaturesConfigSchema>;
|
|
70
|
+
/**
|
|
71
|
+
* lzi-features 配置,解析后形态,默认值全部落定
|
|
72
|
+
*/
|
|
73
|
+
type LziFeaturesConfig = z.output<typeof lziFeaturesConfigSchema>;
|
|
74
|
+
/**
|
|
75
|
+
* 棘轮基线条目
|
|
76
|
+
*/
|
|
77
|
+
type CheckBaselineEntry = z.infer<typeof baselineEntrySchema>;
|
|
78
|
+
/**
|
|
79
|
+
* 注册表排除条目
|
|
80
|
+
*/
|
|
81
|
+
type CheckExclusionEntry = z.infer<typeof exclusionEntrySchema>;
|
|
82
|
+
/**
|
|
83
|
+
* 解析并校验配置,非法即抛,加载即失败
|
|
84
|
+
*
|
|
85
|
+
* @param input - 配置原始对象,defineConfig 产物
|
|
86
|
+
* @returns 默认值落定的配置
|
|
87
|
+
* @throws {@link Error} 形态违规,消息聚合全部违规项,跨条目语义校验由
|
|
88
|
+
* validateLziFeaturesConfig 在加载链路上追加执行
|
|
89
|
+
*/
|
|
90
|
+
declare function parseLziFeaturesConfig(input: unknown): LziFeaturesConfig;
|
|
91
|
+
/**
|
|
92
|
+
* 定义 lzi-features 配置,identity 工厂
|
|
93
|
+
*
|
|
94
|
+
* 类型透传,与 lzi-dev.config.ts 等 workspace 配置惯例同构:不在工厂层做任何
|
|
95
|
+
* 合并,默认值由本模块 schema 解析层统一落定
|
|
96
|
+
*
|
|
97
|
+
* @param config - 配置对象,可省略各默认值
|
|
98
|
+
* @returns 原样返回传入的配置对象
|
|
99
|
+
*/
|
|
100
|
+
declare function defineConfig(config: LziFeaturesConfigInput): LziFeaturesConfigInput;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/baseline/render-baseline.renderer.d.ts
|
|
103
|
+
/**
|
|
104
|
+
* 棘轮契约注释头,再生文件头
|
|
105
|
+
*/
|
|
106
|
+
declare const RATCHET_CONTRACT_HEADER: string;
|
|
107
|
+
/**
|
|
108
|
+
* 基线条目排序与去重,file 与 rule 组合唯一,file 升序、rule 次序
|
|
109
|
+
*
|
|
110
|
+
* @param entries - 原始条目列表
|
|
111
|
+
* @returns 排序去重后的条目列表
|
|
112
|
+
*/
|
|
113
|
+
declare function deriveBaselineEntries(entries: readonly CheckBaselineEntry[]): CheckBaselineEntry[];
|
|
114
|
+
/**
|
|
115
|
+
* 渲染基线再生后的完整配置文件
|
|
116
|
+
*
|
|
117
|
+
* @param config - 当前解析后配置,其余节值原样保留
|
|
118
|
+
* @param baseline - 再生基线条目,通常为 deriveBaselineEntries 产物
|
|
119
|
+
* @returns 完整配置文件文本,棘轮契约头加 defineConfig 体
|
|
120
|
+
*/
|
|
121
|
+
declare function renderBaselineRegeneratedConfig(config: LziFeaturesConfig, baseline: readonly CheckBaselineEntry[]): string;
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/loader/load-features-config.utils.d.ts
|
|
124
|
+
/**
|
|
125
|
+
* 配置来源类型
|
|
126
|
+
*/
|
|
127
|
+
type LziFeaturesConfigSource = 'standalone' | 'unified' | 'explicit';
|
|
128
|
+
/**
|
|
129
|
+
* 加载成功结果
|
|
130
|
+
*/
|
|
131
|
+
type LoadLziFeaturesConfigSuccess = {
|
|
132
|
+
/**
|
|
133
|
+
* 加载成功标记
|
|
134
|
+
*/
|
|
135
|
+
ok: true;
|
|
136
|
+
/**
|
|
137
|
+
* 解析并校验后的配置,默认值全部落定
|
|
138
|
+
*/
|
|
139
|
+
config: LziFeaturesConfig;
|
|
140
|
+
/**
|
|
141
|
+
* 命中的配置文件绝对路径
|
|
142
|
+
*/
|
|
143
|
+
configFilePath: string;
|
|
144
|
+
/**
|
|
145
|
+
* 配置来源
|
|
146
|
+
*/
|
|
147
|
+
source: LziFeaturesConfigSource;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* 加载失败结果,未找到配置
|
|
151
|
+
*/
|
|
152
|
+
type LoadLziFeaturesConfigFailure = {
|
|
153
|
+
/**
|
|
154
|
+
* 加载成功标记
|
|
155
|
+
*/
|
|
156
|
+
ok: false;
|
|
157
|
+
/**
|
|
158
|
+
* 失败原因
|
|
159
|
+
*/
|
|
160
|
+
reason: string;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* 加载结果
|
|
164
|
+
*/
|
|
165
|
+
type LoadLziFeaturesConfigResult = LoadLziFeaturesConfigSuccess | LoadLziFeaturesConfigFailure;
|
|
166
|
+
/**
|
|
167
|
+
* 加载选项
|
|
168
|
+
*/
|
|
169
|
+
type LoadLziFeaturesConfigOptions = {
|
|
170
|
+
/**
|
|
171
|
+
* 查找起点目录,缺省取当前工作目录
|
|
172
|
+
*/
|
|
173
|
+
cwd?: string;
|
|
174
|
+
/**
|
|
175
|
+
* 显式配置文件路径,优先级最高,绕过向上查找
|
|
176
|
+
*/
|
|
177
|
+
configPath?: string;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* 加载 lzi-features 配置
|
|
181
|
+
*
|
|
182
|
+
* @param options - 加载选项
|
|
183
|
+
* @returns 加载结果:命中返回解析后配置,未找到返回失败,显式路径不存在也按失败处理
|
|
184
|
+
* @throws {@link Error} 命中配置但形态或跨条目非法,加载即失败语义
|
|
185
|
+
*/
|
|
186
|
+
declare function loadLziFeaturesConfig(options?: LoadLziFeaturesConfigOptions): Promise<LoadLziFeaturesConfigResult>;
|
|
187
|
+
/**
|
|
188
|
+
* 按显式文件 URL 动态导入配置模块,测试与工具内部使用
|
|
189
|
+
*
|
|
190
|
+
* @param configPath - 配置文件绝对路径
|
|
191
|
+
* @returns 配置模块 default 导出
|
|
192
|
+
* @throws {@link Error} 导入失败或无 default 导出
|
|
193
|
+
*/
|
|
194
|
+
declare function importConfigModule(configPath: string): Promise<unknown>;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/scaffold/render-scaffold.renderer.d.ts
|
|
197
|
+
/**
|
|
198
|
+
* lzi-features 配置脚手架渲染,init 命令落盘
|
|
199
|
+
*
|
|
200
|
+
* 渲染 lzi-features.config.ts 全文,单 scope 起步形态,幂等不覆盖由命令层守卫
|
|
201
|
+
*/
|
|
202
|
+
/**
|
|
203
|
+
* 脚手架渲染入参
|
|
204
|
+
*/
|
|
205
|
+
type ConfigScaffoldInput = {
|
|
206
|
+
/**
|
|
207
|
+
* scope key,kebab-case
|
|
208
|
+
*/
|
|
209
|
+
scopeKey: string;
|
|
210
|
+
/**
|
|
211
|
+
* scope 人类可读名
|
|
212
|
+
*/
|
|
213
|
+
scopeTitle: string;
|
|
214
|
+
/**
|
|
215
|
+
* 注册表目录,posix 相对仓库根
|
|
216
|
+
*/
|
|
217
|
+
registryDir: string;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* 渲染 lzi-features.config.ts 脚手架全文
|
|
221
|
+
*
|
|
222
|
+
* @param input - 脚手架入参
|
|
223
|
+
* @returns 可直接落盘的配置文件全文
|
|
224
|
+
*/
|
|
225
|
+
declare function renderConfigScaffold(input: ConfigScaffoldInput): string;
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/validation/validate-cross-entries.d.ts
|
|
228
|
+
/**
|
|
229
|
+
* 校验并透传配置,语义非法即抛,消息聚合全部违规项
|
|
230
|
+
*
|
|
231
|
+
* @param config - 形态解析后的配置
|
|
232
|
+
* @returns 原样透传,校验通过
|
|
233
|
+
* @throws {@link Error} 跨条目语义违规
|
|
234
|
+
*/
|
|
235
|
+
declare function validateLziFeaturesConfig(config: LziFeaturesConfig): LziFeaturesConfig;
|
|
236
|
+
//#endregion
|
|
237
|
+
export { CheckBaselineEntry, CheckExclusionEntry, ConfigScaffoldInput, DEFAULT_REGISTRY_DIR, LoadLziFeaturesConfigFailure, LoadLziFeaturesConfigOptions, LoadLziFeaturesConfigResult, LoadLziFeaturesConfigSuccess, LziFeaturesConfig, LziFeaturesConfigInput, LziFeaturesConfigSource, RATCHET_CONTRACT_HEADER, SCOPE_KEY_PATTERN, ScopeEntry, ScopeEntryInput, baselineEntrySchema, defineConfig, deriveBaselineEntries, exclusionEntrySchema, importConfigModule, loadLziFeaturesConfig, lziFeaturesConfigSchema, parseLziFeaturesConfig, renderBaselineRegeneratedConfig, renderConfigScaffold, validateLziFeaturesConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{loadUnifiedConfig as e}from"@longzai-intelligence-shared-config/core";import{existsSync as t}from"node:fs";import{resolve as n}from"node:path";import{pathToFileURL as r}from"node:url";import*as i from"zod";const a=[`/**`," * lzi-features 配置,由 `--write-baseline --reason <理由>` 再生",` *`,` * 棘轮基线语义:基线按 file 与 rule 精确命中豁免存量违规,基线外新增违规仍红,`,` * 基线条目无对应现行违规计陈旧,修复存量即须同步删除对应条目,棘轮只许缩短直至清零,`,` * 每条豁免必须携带收编理由`,` *`,` * 注意:再生以解析值重建本文件,节内手工注释不保留,长篇说明请写入 docs 目录`,` */`].join(`
|
|
2
|
+
`);function o(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=`${n.file}::${n.rule}`;t.has(e)||t.set(e,{...n})}return[...t.values()].sort((e,t)=>e.file===t.file?e.rule.localeCompare(t.rule):e.file.localeCompare(t.file))}function s(e,t){let n=[`import { defineConfig } from '@longzai-intelligence-features/config';`,``,...a.split(`
|
|
3
|
+
`),`export default defineConfig({`,` scopes: [`];for(let t of e.scopes){let e=t.paths.map(e=>`'${e}'`).join(`, `);n.push(` { key: '${t.key}', title: '${t.title}', paths: [${e}], registryDir: '${t.registryDir}' },`)}n.push(` ],`,` check: {`,` baseline: [`);for(let e of t)n.push(` { file: '${e.file}', rule: '${e.rule}', reason: '${e.reason}' },`);n.push(` ],`,` exclusions: [`);for(let t of e.check.exclusions)n.push(` { path: '${t.path}', reason: '${t.reason}' },`);return n.push(` ],`,` },`,`});`,``),n.join(`
|
|
4
|
+
`)}const c=/^[a-z][a-z0-9-]*$/,l=`docs/features`,u=i.strictObject({file:i.string().min(1),rule:i.string().min(1),reason:i.string().min(1)}),d=i.strictObject({path:i.string().min(1),reason:i.string().min(1)}),f=i.strictObject({key:i.string().regex(c),title:i.string().min(1),paths:i.array(i.string().min(1)).min(1),registryDir:i.string().min(1)}),p=i.strictObject({baseline:i.array(u).default([]),exclusions:i.array(d).default([])}),m=i.strictObject({scopes:i.array(f).min(1),check:p.default({baseline:[],exclusions:[]})});function h(e){let t=m.safeParse(e);if(!t.success){let e=t.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`,`);throw Error(`lzi-features 配置形态非法:${e}`)}return t.data}function g(e){return e}function _(e){let t=[],n=/* @__PURE__ */ new Map;for(let t of e.scopes)n.set(t.key,(n.get(t.key)??0)+1);for(let[e,r]of n)r>1&&t.push(`scopes: key「${e}」重复登记 ${r} 次,scope key 必须唯一`);let r=/* @__PURE__ */ new Map;for(let t of e.scopes){let e=r.get(t.registryDir)??[];e.push(t.key),r.set(t.registryDir,e)}for(let[e,n]of r)n.length>1&&t.push(`scopes: 注册表目录「${e}」被 ${n.join(`、`)} 共用,一目录一 scope,否则识别与 lint 歧义`);for(let n of e.check.baseline)e.scopes.some(e=>n.file===e.registryDir||n.file.startsWith(`${e.registryDir}/`))||t.push(`check.baseline: 豁免条目「${n.file}」规则 ${n.rule} 不在任何 scope 注册表目录内`);let i=/* @__PURE__ */ new Map;for(let t of e.check.exclusions)i.set(t.path,(i.get(t.path)??0)+1);for(let[e,n]of i)n>1&&t.push(`check.exclusions: 排除路径「${e}」重复登记 ${n} 次`);for(let n of e.check.exclusions)e.scopes.some(e=>n.path===e.registryDir||n.path.startsWith(`${e.registryDir}/`))||t.push(`check.exclusions: 排除条目「${n.path}」不在任何 scope 注册表目录内`);if(t.length>0)throw Error(`lzi-features 配置跨条目语义非法:${t.join(`,`)}`);return e}function v(e,t){try{return _(h(e))}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(`${n},配置文件:${t}`)}}async function y(r={}){if(r.configPath!==void 0){let e=n(r.cwd??process.cwd(),r.configPath);return t(e)?{ok:!0,config:v(await b(e),e),configFilePath:e,source:`explicit`}:{ok:!1,reason:`未找到配置文件:${e}`}}let i=await e({standaloneFile:`lzi-features.config.ts`,unifiedField:`features`,cwd:r.cwd});return i.success?{ok:!0,config:v(i.config,i.configFilePath),configFilePath:i.configFilePath,source:i.source}:{ok:!1,reason:`未找到 lzi-features.config.ts,且 lzi.config.ts 无 features 字段,可先执行 lzi-features init`}}async function b(e){let t=await import(r(e).href);if(t.default===void 0)throw Error(`配置文件缺少 default 导出:${e}`);return t.default}function x(e){return[`import { defineConfig } from '@longzai-intelligence-features/config';`,``,`/**`,` * lzi-features 配置`,` */`,`export default defineConfig({`,` scopes: [`,` { key: '${e.scopeKey}', title: '${e.scopeTitle}', paths: ['.'], registryDir: '${e.registryDir}' },`,` ],`,`});`,``].join(`
|
|
5
|
+
`)}export{l as DEFAULT_REGISTRY_DIR,a as RATCHET_CONTRACT_HEADER,c as SCOPE_KEY_PATTERN,u as baselineEntrySchema,g as defineConfig,o as deriveBaselineEntries,d as exclusionEntrySchema,b as importConfigModule,y as loadLziFeaturesConfig,m as lziFeaturesConfigSchema,h as parseLziFeaturesConfig,s as renderBaselineRegeneratedConfig,x as renderConfigScaffold,_ as validateLziFeaturesConfig};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"node:module";export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-features/config",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "UNLICENSED",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "lzi-builder",
|
|
19
|
+
"build:prod": "NODE_ENV=production bun run build",
|
|
20
|
+
"prepublishOnly": "bun run build:prod",
|
|
21
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
22
|
+
"typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
|
|
23
|
+
"typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
|
|
24
|
+
"typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
|
|
25
|
+
"lint": "oxlint && oxfmt --check",
|
|
26
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
27
|
+
"test": "bun test",
|
|
28
|
+
"test:watch": "bun test --watch",
|
|
29
|
+
"test:coverage": "bun test --coverage"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@longzai-intelligence-shared-config/core": "^0.0.5",
|
|
33
|
+
"zod": "^4.4.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/bun": "latest"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/README.md
DELETED