@longzai-intelligence-debts/config 0.0.0-stage → 0.0.3
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 +226 -0
- package/dist/index.js +2 -0
- package/dist/rolldown-runtime-BqT_7tdF.js +1 -0
- package/package.json +44 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import "./rolldown-runtime-BqT_7tdF.js";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* scope key 合法形态
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* kebab-case,小写字母开头,仅小写字母、数字与连字符
|
|
8
|
+
*/
|
|
9
|
+
declare const SCOPE_KEY_PATTERN: RegExp;
|
|
10
|
+
/**
|
|
11
|
+
* init 缺省注册表目录
|
|
12
|
+
*
|
|
13
|
+
* @default docs/debts
|
|
14
|
+
*/
|
|
15
|
+
declare const DEFAULT_REGISTRY_DIR = "docs/debts";
|
|
16
|
+
/**
|
|
17
|
+
* 棘轮基线条目 schema
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* 存量豁免逐条带理由登记,存量不追溯,豁免面只许缩短
|
|
21
|
+
*/
|
|
22
|
+
declare const baselineEntrySchema: z.ZodObject<{
|
|
23
|
+
file: z.ZodString;
|
|
24
|
+
rule: z.ZodString;
|
|
25
|
+
reason: z.ZodString;
|
|
26
|
+
}, z.core.$strip>;
|
|
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.$strip>;
|
|
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-debts 配置根 schema
|
|
46
|
+
*
|
|
47
|
+
* @remarks
|
|
48
|
+
* scopes 与 lint 均可整体省略,零参 `defineConfig()` 书写形态下由解析层
|
|
49
|
+
* 落定缺省单 scope 与空基线
|
|
50
|
+
*/
|
|
51
|
+
declare const lziDebtsConfigSchema: z.ZodObject<{
|
|
52
|
+
scopes: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
53
|
+
key: z.ZodString;
|
|
54
|
+
title: z.ZodString;
|
|
55
|
+
paths: z.ZodArray<z.ZodString>;
|
|
56
|
+
registryDir: z.ZodString;
|
|
57
|
+
}, z.core.$strip>>>;
|
|
58
|
+
lint: z.ZodDefault<z.ZodObject<{
|
|
59
|
+
baseline: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
60
|
+
file: z.ZodString;
|
|
61
|
+
rule: z.ZodString;
|
|
62
|
+
reason: z.ZodString;
|
|
63
|
+
}, z.core.$strip>>>;
|
|
64
|
+
}, z.core.$strip>>;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
/**
|
|
67
|
+
* lzi-debts 配置用户书写形态
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* 可省略各默认值
|
|
71
|
+
*/
|
|
72
|
+
type LziDebtsConfigInput = z.input<typeof lziDebtsConfigSchema>;
|
|
73
|
+
/**
|
|
74
|
+
* lzi-debts 配置解析后形态
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* 默认值全部落定
|
|
78
|
+
*/
|
|
79
|
+
type LziDebtsConfig = z.output<typeof lziDebtsConfigSchema>;
|
|
80
|
+
/**
|
|
81
|
+
* 棘轮基线条目
|
|
82
|
+
*/
|
|
83
|
+
type LintBaselineEntry = z.infer<typeof baselineEntrySchema>;
|
|
84
|
+
/**
|
|
85
|
+
* 解析并校验配置
|
|
86
|
+
*
|
|
87
|
+
* @param input - 配置原始对象,即 `defineConfig` 产物
|
|
88
|
+
* @returns 默认值落定的配置
|
|
89
|
+
* @throws {@link Error} 形态违规,消息聚合全部违规项。跨条目语义校验由
|
|
90
|
+
* `validateLziDebtsConfig` 在加载链路上追加执行
|
|
91
|
+
*/
|
|
92
|
+
declare function parseLziDebtsConfig(input: unknown): LziDebtsConfig;
|
|
93
|
+
/**
|
|
94
|
+
* 定义 lzi-debts 配置的 identity 工厂
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* 类型透传,与 `lzi-dev.config.ts` 等 workspace 配置惯例同构,不在工厂层
|
|
98
|
+
* 做任何合并,默认值由本模块 schema 解析层统一落定
|
|
99
|
+
* @param config - 配置对象,可整体省略,零参形态由解析层落定全部缺省
|
|
100
|
+
* @returns 原样返回传入的配置对象
|
|
101
|
+
*/
|
|
102
|
+
declare function defineConfig(config?: LziDebtsConfigInput): LziDebtsConfigInput;
|
|
103
|
+
/**
|
|
104
|
+
* 配置来源类型
|
|
105
|
+
*/
|
|
106
|
+
type LziDebtsConfigSource = 'standalone' | 'unified' | 'explicit';
|
|
107
|
+
/**
|
|
108
|
+
* 加载成功结果
|
|
109
|
+
*/
|
|
110
|
+
type LoadLziDebtsConfigSuccess = {
|
|
111
|
+
/**
|
|
112
|
+
* 加载成功标记
|
|
113
|
+
*/
|
|
114
|
+
ok: true;
|
|
115
|
+
/**
|
|
116
|
+
* 解析并校验后的配置
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* 默认值全部落定
|
|
120
|
+
*/
|
|
121
|
+
config: LziDebtsConfig;
|
|
122
|
+
/**
|
|
123
|
+
* 命中的配置文件绝对路径
|
|
124
|
+
*/
|
|
125
|
+
configFilePath: string;
|
|
126
|
+
/**
|
|
127
|
+
* 配置来源
|
|
128
|
+
*/
|
|
129
|
+
source: LziDebtsConfigSource;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* 加载失败结果
|
|
133
|
+
*/
|
|
134
|
+
type LoadLziDebtsConfigFailure = {
|
|
135
|
+
/**
|
|
136
|
+
* 加载成功标记
|
|
137
|
+
*/
|
|
138
|
+
ok: false;
|
|
139
|
+
/**
|
|
140
|
+
* 失败原因
|
|
141
|
+
*/
|
|
142
|
+
reason: string;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* 加载结果
|
|
146
|
+
*/
|
|
147
|
+
type LoadLziDebtsConfigResult = LoadLziDebtsConfigSuccess | LoadLziDebtsConfigFailure;
|
|
148
|
+
/**
|
|
149
|
+
* 加载选项
|
|
150
|
+
*/
|
|
151
|
+
type LoadLziDebtsConfigOptions = {
|
|
152
|
+
/**
|
|
153
|
+
* 查找起点目录
|
|
154
|
+
*
|
|
155
|
+
* @default process.cwd()
|
|
156
|
+
*/
|
|
157
|
+
cwd?: string;
|
|
158
|
+
/**
|
|
159
|
+
* 显式配置文件路径
|
|
160
|
+
*
|
|
161
|
+
* @remarks
|
|
162
|
+
* 优先级最高,绕过向上查找
|
|
163
|
+
*/
|
|
164
|
+
configPath?: string;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* 加载 lzi-debts 配置
|
|
168
|
+
*
|
|
169
|
+
* @param options - 加载选项
|
|
170
|
+
* @returns 加载结果。命中返回解析后配置,未找到返回失败,显式路径不存在也按失败处理
|
|
171
|
+
* @throws {@link Error} 命中配置但形态或跨条目非法,加载即失败语义
|
|
172
|
+
*/
|
|
173
|
+
declare function loadLziDebtsConfig(options?: LoadLziDebtsConfigOptions): Promise<LoadLziDebtsConfigResult>;
|
|
174
|
+
/**
|
|
175
|
+
* 按显式文件 URL 动态导入配置模块
|
|
176
|
+
*
|
|
177
|
+
* @param configPath - 配置文件绝对路径
|
|
178
|
+
* @returns 配置模块 default 导出
|
|
179
|
+
* @throws {@link Error} 导入失败或无 default 导出
|
|
180
|
+
*/
|
|
181
|
+
declare function importConfigModule(configPath: string): Promise<unknown>;
|
|
182
|
+
/**
|
|
183
|
+
* lzi-debts 配置脚手架渲染
|
|
184
|
+
*
|
|
185
|
+
* init 命令落盘用,渲染 `lzi-debts.config.ts` 全文即单 scope 起步形态。
|
|
186
|
+
* 幂等不覆盖由命令层守卫
|
|
187
|
+
*/
|
|
188
|
+
/**
|
|
189
|
+
* 脚手架渲染入参
|
|
190
|
+
*/
|
|
191
|
+
type ConfigScaffoldInput = {
|
|
192
|
+
/**
|
|
193
|
+
* scope key
|
|
194
|
+
*
|
|
195
|
+
* @remarks
|
|
196
|
+
* kebab-case
|
|
197
|
+
*/
|
|
198
|
+
scopeKey: string;
|
|
199
|
+
/**
|
|
200
|
+
* scope 人类可读名
|
|
201
|
+
*/
|
|
202
|
+
scopeTitle: string;
|
|
203
|
+
/**
|
|
204
|
+
* 注册表目录
|
|
205
|
+
*
|
|
206
|
+
* @remarks
|
|
207
|
+
* posix 相对仓库根
|
|
208
|
+
*/
|
|
209
|
+
registryDir: string;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* 渲染 lzi-debts.config.ts 脚手架全文
|
|
213
|
+
*
|
|
214
|
+
* @param input - 脚手架入参
|
|
215
|
+
* @returns 可直接落盘的配置文件全文
|
|
216
|
+
*/
|
|
217
|
+
declare function renderConfigScaffold(input: ConfigScaffoldInput): string;
|
|
218
|
+
/**
|
|
219
|
+
* 校验并透传配置
|
|
220
|
+
*
|
|
221
|
+
* @param config - 形态解析后的配置
|
|
222
|
+
* @returns 原样透传,校验通过
|
|
223
|
+
* @throws {@link Error} 跨条目语义违规,消息聚合全部违规项
|
|
224
|
+
*/
|
|
225
|
+
declare function validateLziDebtsConfig(config: LziDebtsConfig): LziDebtsConfig;
|
|
226
|
+
export { ConfigScaffoldInput, DEFAULT_REGISTRY_DIR, LintBaselineEntry, LoadLziDebtsConfigFailure, LoadLziDebtsConfigOptions, LoadLziDebtsConfigResult, LoadLziDebtsConfigSuccess, LziDebtsConfig, LziDebtsConfigInput, LziDebtsConfigSource, SCOPE_KEY_PATTERN, ScopeEntry, ScopeEntryInput, baselineEntrySchema, defineConfig, importConfigModule, loadLziDebtsConfig, lziDebtsConfigSchema, parseLziDebtsConfig, renderConfigScaffold, validateLziDebtsConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{ensureError as e}from"@longzai-intelligence-error/utils";import{loadUnifiedConfig as t}from"@longzai-intelligence-shared-config/core";import{existsSync as n}from"node:fs";import{resolve as r}from"node:path";import{pathToFileURL as i}from"node:url";import*as a from"zod";const o=/^[a-z][a-z0-9-]*$/,s=`docs/debts`,c=a.object({file:a.string().min(1),rule:a.string().min(1),reason:a.string().min(1)}),l=a.object({key:a.string().regex(o),title:a.string().min(1),paths:a.array(a.string().min(1)).min(1),registryDir:a.string().min(1)}),u=a.object({baseline:a.array(c).default([])}),d=a.object({scopes:a.array(l).min(1).default([{key:`root`,title:`全局`,paths:[`.`],registryDir:s}]),lint:u.default({baseline:[]})});function f(e){let t=d.safeParse(e);if(!t.success){let e=t.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`,`);throw Error(`lzi-debts 配置形态非法:${e}`)}return t.data}function p(e={}){return e}function m(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.lint.baseline)e.scopes.some(e=>n.file===e.registryDir||n.file.startsWith(`${e.registryDir}/`))||t.push(`lint.baseline: 豁免条目「${n.file}」规则为 ${n.rule},不在任何 scope 注册表目录内`);if(t.length>0)throw Error(`lzi-debts 配置跨条目语义非法:${t.join(`,`)}`);return e}function h(t,n){try{return m(f(t))}catch(t){let r=e(t).message;throw Error(`${r},配置文件:${n}`)}}async function g(e={}){if(e.configPath!==void 0){let t=r(e.cwd??process.cwd(),e.configPath);return n(t)?{ok:!0,config:h(await _(t),t),configFilePath:t,source:`explicit`}:{ok:!1,reason:`未找到配置文件:${t}`}}let i=await t({standaloneFile:`lzi-debts.config.ts`,unifiedField:`debts`,cwd:e.cwd});return i.success?{ok:!0,config:h(i.config,i.configFilePath),configFilePath:i.configFilePath,source:i.source}:{ok:!1,reason:`未找到 lzi-debts.config.ts,且 lzi.config.ts 无 debts 字段,可先执行 lzi-debts init`}}async function _(e){let t=await import(i(e).href);if(t.default===void 0)throw Error(`配置文件缺少 default 导出:${e}`);return t.default}function v(e){return[`import { defineConfig } from '@longzai-intelligence-debts/config';`,``,`/**`,` * lzi-debts 配置`,` */`,`export default defineConfig({`,` scopes: [`,` { key: '${e.scopeKey}', title: '${e.scopeTitle}', paths: ['.'], registryDir: '${e.registryDir}' },`,` ],`,`});`,``].join(`
|
|
2
|
+
`)}export{s as DEFAULT_REGISTRY_DIR,o as SCOPE_KEY_PATTERN,c as baselineEntrySchema,p as defineConfig,_ as importConfigModule,g as loadLziDebtsConfig,d as lziDebtsConfigSchema,f as parseLziDebtsConfig,v as renderConfigScaffold,m as validateLziDebtsConfig};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"node:module";export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-debts/config",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Longzai Intelligence Debts 配置",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"config",
|
|
7
|
+
"debts",
|
|
8
|
+
"longzai-intelligence",
|
|
9
|
+
"schema"
|
|
10
|
+
],
|
|
11
|
+
"license": "UNLICENSED",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "lzi-builder",
|
|
26
|
+
"build:prod": "NODE_ENV=production bun run build",
|
|
27
|
+
"prepublishOnly": "bun run build:prod",
|
|
28
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
29
|
+
"typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
|
|
30
|
+
"typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
|
|
31
|
+
"typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
|
|
32
|
+
"lint": "lzi-lint lint",
|
|
33
|
+
"lint:fix": "lzi-lint fix",
|
|
34
|
+
"test": "bun test",
|
|
35
|
+
"test:watch": "bun test --watch",
|
|
36
|
+
"test:coverage": "bun test --coverage"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@longzai-intelligence-error/utils": "^0.2.0",
|
|
40
|
+
"@longzai-intelligence-shared-config/core": "^0.0.5",
|
|
41
|
+
"zod": "^4.4.3"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/bun": "latest"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/README.md
DELETED