@longzai-intelligence-scripts/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.
@@ -0,0 +1,251 @@
1
+ //#region src/types.d.ts
2
+ /**
3
+ * 定义 lzi-scripts.config.ts 配置结构与真源注册数据契约
4
+ *
5
+ * 契约类型与真源仓 `registry/types.ts` 保持结构一致;真源仓发包后真源侧将改为
6
+ * `import type` 引用本包,消除双定义
7
+ */
8
+ /**
9
+ * 注册条目严格级别
10
+ *
11
+ * - `required` 违例报错
12
+ * - `recommended` 违例仅警告
13
+ */
14
+ type ScriptSeverity = 'required' | 'recommended';
15
+ /**
16
+ * 标准档案键
17
+ *
18
+ * - `root` 产品群根仓基础档案
19
+ * - `root-engineering` 工程类根仓档案,追加 forbid 族与构建治理族
20
+ * - `package` 仓内子包档案
21
+ */
22
+ type ScriptsProfileKey = 'root' | 'root-engineering' | 'package';
23
+ /**
24
+ * 单条标准脚本注册条目
25
+ */
26
+ type ScriptEntry = {
27
+ /**
28
+ * 脚本名,如 `version:sync`
29
+ */
30
+ name: string;
31
+ /**
32
+ * 标准命令行原文,如 `lzi-version sync`
33
+ */
34
+ definition: string;
35
+ /**
36
+ * 严格级别,见 `ScriptSeverity`
37
+ */
38
+ severity: ScriptSeverity;
39
+ /**
40
+ * 脚本族归属,如 `version`、`changelog`、`forbid`
41
+ */
42
+ family: string;
43
+ /**
44
+ * 允许的等价命令行列表,命中任一即视为合规
45
+ */
46
+ alternatives?: string[];
47
+ };
48
+ /**
49
+ * 兼伴配置文件注册条目
50
+ */
51
+ type CompanionEntry = {
52
+ /**
53
+ * 相对仓根的文件路径,如 `lzi-version.config.ts`
54
+ */
55
+ path: string;
56
+ /**
57
+ * 严格级别,同脚本条目口径
58
+ */
59
+ severity: ScriptSeverity;
60
+ /**
61
+ * 登记依据,如 `ADR 0097 决策 9`
62
+ */
63
+ reason: string;
64
+ };
65
+ /**
66
+ * 遗留死链映射条目
67
+ */
68
+ type LegacyMapping = {
69
+ /**
70
+ * 遗留命令前缀,如 `lzi-dev-cli version sync`
71
+ */
72
+ legacyPrefix: string;
73
+ /**
74
+ * 对应的标准脚本名,如 `version:sync`
75
+ */
76
+ targetScript: string;
77
+ /**
78
+ * 新命令行所属的 npm 包名,供改写后的依赖补装提示
79
+ */
80
+ targetPackage: string;
81
+ /**
82
+ * 迁出说明,供违例报告展示
83
+ */
84
+ note: string;
85
+ };
86
+ /**
87
+ * 真源仓注册数据整体形状(真源仓 `registry/index.ts` 的 default export 类型)
88
+ */
89
+ type ScriptsRegistryData = {
90
+ /**
91
+ * 数据格式版本,当前为 1
92
+ */
93
+ formatVersion: 1;
94
+ /**
95
+ * 各档案的标准脚本条目集合
96
+ */
97
+ profiles: Partial<Record<ScriptsProfileKey, ScriptEntry[]>>;
98
+ /**
99
+ * 兼伴配置文件条目集合
100
+ */
101
+ companions: CompanionEntry[];
102
+ /**
103
+ * 遗留死链映射条目集合
104
+ */
105
+ legacyMappings: LegacyMapping[];
106
+ };
107
+ /**
108
+ * 就地配置的单条豁免声明
109
+ */
110
+ type ExemptionDeclaration = {
111
+ /**
112
+ * 豁免的脚本名列表
113
+ */
114
+ scripts: string[];
115
+ /**
116
+ * 豁免理由(必填,审计报告原样展示)
117
+ */
118
+ reason: string;
119
+ };
120
+ /**
121
+ * 就地配置的单条等价形态追加
122
+ */
123
+ type AlternativeDeclaration = {
124
+ /**
125
+ * 追加等价形态的脚本名
126
+ */
127
+ script: string;
128
+ /**
129
+ * 该仓合法的命令行形态
130
+ */
131
+ definition: string;
132
+ };
133
+ /**
134
+ * lzi-scripts.config.ts 配置根类型
135
+ */
136
+ type LziScriptsConfig = {
137
+ /**
138
+ * 真源仓路径指针(相对或绝对),进入真源解析链第二优先级
139
+ */
140
+ registryRoot?: string;
141
+ /**
142
+ * 显式指定审计档案,缺省按 `workspaces` 有无自动判定
143
+ */
144
+ profile?: ScriptsProfileKey;
145
+ /**
146
+ * 豁免声明列表,豁免必须附理由
147
+ */
148
+ exempt?: ExemptionDeclaration[];
149
+ /**
150
+ * 等价形态追加列表
151
+ */
152
+ extraAlternatives?: AlternativeDeclaration[];
153
+ };
154
+ /**
155
+ * 配置加载结果
156
+ */
157
+ type ScriptsConfigResult = {
158
+ /**
159
+ * 加载后的配置对象(无配置文件时为空对象走全缺省)
160
+ */
161
+ config: LziScriptsConfig;
162
+ /**
163
+ * 命中的配置文件绝对路径(同时用于推导目标仓根目录),无配置时为 null
164
+ */
165
+ configPath: string | null;
166
+ };
167
+ //#endregion
168
+ //#region src/define.config.d.ts
169
+ /**
170
+ * lzi-scripts 配置工厂(恒等返回,仅提供类型约束)
171
+ *
172
+ * @param config - 配置对象,缺省为空对象(全字段走默认值)
173
+ * @returns 原样返回的配置对象
174
+ */
175
+ declare const defineConfig: (config?: LziScriptsConfig) => LziScriptsConfig;
176
+ //#endregion
177
+ //#region src/load.config.d.ts
178
+ /**
179
+ * 自起点目录逐级上溯查找就地配置文件
180
+ *
181
+ * @param startDir - 发现起点目录(单仓检查为 cwd,跨仓普查为各项目目录)
182
+ * @returns 命中的配置文件绝对路径,未找到返回 null
183
+ */
184
+ declare const findScriptsConfigFile: (startDir: string) => string | null;
185
+ /**
186
+ * 加载就地配置
187
+ *
188
+ * @param startDir - 发现起点目录,缺省为进程 cwd
189
+ * @returns 配置加载结果;未找到配置文件时返回空配置且 `configPath` 为 null
190
+ * @throws {@link Error} 配置文件存在但动态加载失败或 default export 形态非法
191
+ */
192
+ declare const loadScriptsConfig: (startDir?: string) => Promise<ScriptsConfigResult>;
193
+ //#endregion
194
+ //#region src/registry-resolution.utils.d.ts
195
+ /**
196
+ * 真源命中来源(解析链层级)
197
+ */
198
+ type RegistrySource = 'explicit' | 'config' | 'env' | 'sibling';
199
+ /**
200
+ * 解析完成的真源(数据 + 根路径 + 来源)
201
+ */
202
+ type ResolvedRegistry = {
203
+ /**
204
+ * 运行时守卫规整后的注册数据
205
+ */
206
+ data: ScriptsRegistryData;
207
+ /**
208
+ * 真源仓根绝对路径
209
+ */
210
+ root: string;
211
+ /**
212
+ * 命中的解析链层级
213
+ */
214
+ source: RegistrySource;
215
+ };
216
+ /**
217
+ * 将未知值规整为真源注册数据
218
+ *
219
+ * 只接受普通对象并逐层校验 profiles、companions、legacyMappings,不合法字段被忽略
220
+ * (等效空集),`formatVersion` 非 1 视为整体非法
221
+ *
222
+ * @param value - 真源 default export 的未知值
223
+ * @returns 规整后的注册数据,非法时返回 null
224
+ */
225
+ declare const asRegistryData: (value: unknown) => ScriptsRegistryData | null;
226
+ /**
227
+ * 真源解析选项
228
+ */
229
+ type ResolveRegistryOptions = {
230
+ /**
231
+ * `--registry` 显式指定的真源根目录
232
+ */
233
+ explicit?: string;
234
+ /**
235
+ * 就地配置的 `registryRoot` 指针
236
+ */
237
+ configRoot?: string;
238
+ /**
239
+ * 目标仓根目录(兄弟目录约定以其父目录为基准)
240
+ */
241
+ repoDir: string;
242
+ };
243
+ /**
244
+ * 解析真源仓并加载注册数据
245
+ *
246
+ * @param options - 解析选项
247
+ * @returns 解析结果;全链未命中返回 null
248
+ */
249
+ declare const resolveRegistry: (options: ResolveRegistryOptions) => Promise<ResolvedRegistry | null>;
250
+ //#endregion
251
+ export { type AlternativeDeclaration, type CompanionEntry, type ExemptionDeclaration, type LegacyMapping, type LziScriptsConfig, type RegistrySource, type ResolveRegistryOptions, type ResolvedRegistry, type ScriptEntry, type ScriptSeverity, type ScriptsConfigResult, type ScriptsProfileKey, type ScriptsRegistryData, asRegistryData, defineConfig, findScriptsConfigFile, loadScriptsConfig, resolveRegistry };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{existsSync as e}from"node:fs";import{dirname as t,isAbsolute as n,join as r,resolve as i}from"node:path";const a=(e={})=>e,o=[`root`,`root-engineering`,`package`],s=a=>{let o=n(a)?a:i(process.cwd(),a);for(;o!==`/`;){let n=r(o,`lzi-scripts.config.ts`);if(e(n))return n;o=t(o)}return null},c=e=>typeof e==`object`&&!!e&&!Array.isArray(e),l=e=>typeof e==`string`&&o.includes(e),u=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`),d=e=>{if(!c(e))return{};let t={};typeof e.registryRoot==`string`&&(t.registryRoot=e.registryRoot),l(e.profile)&&(t.profile=e.profile);let n=[];if(Array.isArray(e.exempt))for(let t of e.exempt)c(t)&&u(t.scripts)&&typeof t.reason==`string`&&t.reason.length>0&&n.push({scripts:t.scripts,reason:t.reason});n.length>0&&(t.exempt=n);let r=[];if(Array.isArray(e.extraAlternatives))for(let t of e.extraAlternatives)c(t)&&typeof t.script==`string`&&typeof t.definition==`string`&&r.push({script:t.script,definition:t.definition});return r.length>0&&(t.extraAlternatives=r),t},f=async(e=process.cwd())=>{let t=s(e);if(t===null)return{config:{},configPath:null};try{let e=await import(t),n=typeof e==`object`&&e&&`default`in e?e.default:e;if(typeof n!=`object`||!n||Array.isArray(n))throw Error(`配置 default export 须为对象: ${t}`);return{config:d(n),configPath:t}}catch(e){throw e instanceof Error&&e.message.startsWith(`配置 default export`)?e:Error(`加载配置文件失败: ${t} ${e instanceof Error?e.message:String(e)}`)}},p=r(`registry`,`index.ts`),m=e=>typeof e==`string`,h=e=>typeof e==`object`&&!!e&&!Array.isArray(e),g=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`),_=e=>e===`required`||e===`recommended`,v=e=>{if(!h(e)||!m(e.name)||!m(e.definition)||!m(e.family)||!_(e.severity)||e.alternatives!==void 0&&!g(e.alternatives))return null;let t={name:e.name,definition:e.definition,severity:e.severity,family:e.family};return e.alternatives!==void 0&&(t.alternatives=e.alternatives),t},y=e=>{if(!h(e)||e.formatVersion!==1)return null;let t={};if(h(e.profiles))for(let[n,r]of Object.entries(e.profiles)){if(n!==`root`&&n!==`root-engineering`&&n!==`package`)continue;let e=[];if(Array.isArray(r))for(let t of r){let n=v(t);n!==null&&e.push(n)}t[n]=e}let n=[];if(Array.isArray(e.companions))for(let t of e.companions)h(t)&&m(t.path)&&m(t.reason)&&_(t.severity)&&n.push({path:t.path,severity:t.severity,reason:t.reason});let r=[];if(Array.isArray(e.legacyMappings))for(let t of e.legacyMappings)h(t)&&m(t.legacyPrefix)&&m(t.targetScript)&&m(t.targetPackage)&&m(t.note)&&r.push({legacyPrefix:t.legacyPrefix,targetScript:t.targetScript,targetPackage:t.targetPackage,note:t.note});return{formatVersion:1,profiles:t,companions:n,legacyMappings:r}},b=async t=>{let a=n(t)?t:i(process.cwd(),t),o=r(a,p);if(!e(o))return null;try{let e=await import(o),t=typeof e==`object`&&e&&`default`in e?e.default:e;return y(t)}catch{return null}},x=async e=>{if(e.explicit!==void 0&&e.explicit!==``){let t=await b(e.explicit);return t===null?null:{data:t,root:i(process.cwd(),e.explicit),source:`explicit`}}if(e.configRoot!==void 0&&e.configRoot!==``){let t=await b(i(e.repoDir,e.configRoot));if(t!==null)return{data:t,root:i(e.repoDir,e.configRoot),source:`config`}}let n=process.env.LZI_SCRIPTS_REGISTRY_ROOT;if(n!==void 0&&n!==``){let e=await b(n);if(e!==null)return{data:e,root:i(n),source:`env`}}let a=r(t(e.repoDir),`longzai-intelligence-scripts-registry`),o=await b(a);return o===null?null:{data:o,root:a,source:`sibling`}};export{y as asRegistryData,a as defineConfig,s as findScriptsConfigFile,f as loadScriptsConfig,x as resolveRegistry};
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-scripts/config",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "description": "Longzai Intelligence 标准脚本审计配置类型定义与加载器(lzi-scripts.config.ts)",
5
+ "license": "UNLICENSED",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "type": "module",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "lzi-builder",
20
+ "build:prod": "NODE_ENV=production bun run build",
21
+ "prepublishOnly": "bun run build:prod",
22
+ "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
23
+ "typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
24
+ "typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
25
+ "typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
26
+ "lint": "oxlint && oxfmt --check",
27
+ "lint:fix": "oxlint --fix && oxfmt",
28
+ "test": "bun test --pass-with-no-tests",
29
+ "test:watch": "bun test --watch",
30
+ "test:coverage": "bun test --coverage",
31
+ "clean": "lzi-dev-cli clean"
32
+ },
33
+ "devDependencies": {
34
+ "@types/bun": "^1.4.0",
35
+ "@types/node": "^26.2.0"
36
+ }
37
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
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.