@longzai-intelligence-plans/config 0.0.0-stage → 0.0.2
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 +2 -2
- package/dist/index.d.ts +191 -0
- package/dist/index.js +10 -0
- package/dist/rolldown-runtime-BqT_7tdF.js +1 -0
- package/package.json +37 -4
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @longzai-intelligence-plans/config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`lzi-plans.config.ts` 的 schema、加载器与脚手架渲染。零参 `defineConfig()` 即接入,缺省单 root 注册面指向 `docs/plans`。
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import "./rolldown-runtime-BqT_7tdF.js";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* scope key 合法形态——kebab-case
|
|
5
|
+
*/
|
|
6
|
+
declare const SCOPE_KEY_PATTERN: RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* init 缺省注册表目录
|
|
9
|
+
*
|
|
10
|
+
* @default 'docs/plans'
|
|
11
|
+
*/
|
|
12
|
+
declare const DEFAULT_REGISTRY_DIR = "docs/plans";
|
|
13
|
+
/**
|
|
14
|
+
* scope 注册条目 schema
|
|
15
|
+
*/
|
|
16
|
+
declare const scopeSchema: z.ZodObject<{
|
|
17
|
+
key: z.ZodString;
|
|
18
|
+
title: z.ZodString;
|
|
19
|
+
paths: z.ZodArray<z.ZodString>;
|
|
20
|
+
registryDir: z.ZodString;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
/**
|
|
23
|
+
* scope 注册条目——书写形态
|
|
24
|
+
*/
|
|
25
|
+
type ScopeEntryInput = z.input<typeof scopeSchema>;
|
|
26
|
+
/**
|
|
27
|
+
* scope 注册条目——解析后形态
|
|
28
|
+
*/
|
|
29
|
+
type ScopeEntry = z.output<typeof scopeSchema>;
|
|
30
|
+
/**
|
|
31
|
+
* 缺省 scope 注册——全仓标准单 root 注册面
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* 开箱即用全局规定——无信息增量的内容内置为程序侧参数,不显性化到
|
|
35
|
+
* 配置文件;`defineConfig()` 无参产物的解析落点即本注册面
|
|
36
|
+
*/
|
|
37
|
+
declare const DEFAULT_SCOPES: ScopeEntry[];
|
|
38
|
+
/**
|
|
39
|
+
* lzi-plans 配置根 schema
|
|
40
|
+
*/
|
|
41
|
+
declare const lziPlansConfigSchema: z.ZodObject<{
|
|
42
|
+
scopes: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
43
|
+
key: z.ZodString;
|
|
44
|
+
title: z.ZodString;
|
|
45
|
+
paths: z.ZodArray<z.ZodString>;
|
|
46
|
+
registryDir: z.ZodString;
|
|
47
|
+
}, z.core.$strip>>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
/**
|
|
50
|
+
* lzi-plans 配置——用户书写形态,可省略各默认值
|
|
51
|
+
*/
|
|
52
|
+
type LziPlansConfigInput = z.input<typeof lziPlansConfigSchema>;
|
|
53
|
+
/**
|
|
54
|
+
* lzi-plans 配置——解析后形态,默认值全部落定
|
|
55
|
+
*/
|
|
56
|
+
type LziPlansConfig = z.output<typeof lziPlansConfigSchema>;
|
|
57
|
+
/**
|
|
58
|
+
* 解析并校验配置,非法即抛,加载即失败
|
|
59
|
+
*
|
|
60
|
+
* @param input - 配置原始对象,即 defineConfig 产物
|
|
61
|
+
* @returns 默认值落定的配置
|
|
62
|
+
* @throws {@link Error} 形态违规,消息聚合全部违规项——跨条目语义校验由
|
|
63
|
+
* `validateLziPlansConfig` 在加载链路上追加执行
|
|
64
|
+
*/
|
|
65
|
+
declare function parseLziPlansConfig(input: unknown): LziPlansConfig;
|
|
66
|
+
/**
|
|
67
|
+
* 定义 lzi-plans 配置——identity 工厂
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* 类型透传,与 `lzi-dev-tools.config.ts` / `oxfmt.config.ts` 等 workspace 配置惯例
|
|
71
|
+
* 同构:不在工厂层做任何合并,默认值由本模块 schema 解析层统一落定
|
|
72
|
+
* 开箱即用全局规定——无参调用即完成接入,无参产物为 `undefined`,解析
|
|
73
|
+
* 层归一落缺省 scope
|
|
74
|
+
* @param config - 可选配置对象,仅在真实信息增量时填写
|
|
75
|
+
* @returns 原样返回传入的配置对象,无参时为 `undefined`
|
|
76
|
+
*/
|
|
77
|
+
declare function defineConfig(config?: LziPlansConfigInput): LziPlansConfigInput | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* 配置来源类型
|
|
80
|
+
*/
|
|
81
|
+
type LziPlansConfigSource = 'standalone' | 'unified' | 'explicit';
|
|
82
|
+
/**
|
|
83
|
+
* 加载成功结果
|
|
84
|
+
*/
|
|
85
|
+
type LoadLziPlansConfigSuccess = {
|
|
86
|
+
/**
|
|
87
|
+
* 加载成功标记
|
|
88
|
+
*/
|
|
89
|
+
ok: true;
|
|
90
|
+
/**
|
|
91
|
+
* 解析并校验后的配置——默认值全部落定
|
|
92
|
+
*/
|
|
93
|
+
config: LziPlansConfig;
|
|
94
|
+
/**
|
|
95
|
+
* 命中的配置文件绝对路径
|
|
96
|
+
*/
|
|
97
|
+
configFilePath: string;
|
|
98
|
+
/**
|
|
99
|
+
* 配置来源
|
|
100
|
+
*/
|
|
101
|
+
source: LziPlansConfigSource;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* 加载失败结果——未找到配置
|
|
105
|
+
*/
|
|
106
|
+
type LoadLziPlansConfigFailure = {
|
|
107
|
+
/**
|
|
108
|
+
* 加载成功标记
|
|
109
|
+
*/
|
|
110
|
+
ok: false;
|
|
111
|
+
/**
|
|
112
|
+
* 失败原因
|
|
113
|
+
*/
|
|
114
|
+
reason: string;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* 加载结果
|
|
118
|
+
*/
|
|
119
|
+
type LoadLziPlansConfigResult = LoadLziPlansConfigSuccess | LoadLziPlansConfigFailure;
|
|
120
|
+
/**
|
|
121
|
+
* 加载选项
|
|
122
|
+
*/
|
|
123
|
+
type LoadLziPlansConfigOptions = {
|
|
124
|
+
/**
|
|
125
|
+
* 查找起点目录,缺省 `process.cwd()`
|
|
126
|
+
*/
|
|
127
|
+
cwd?: string;
|
|
128
|
+
/**
|
|
129
|
+
* 显式配置文件路径——优先级最高,绕过向上查找
|
|
130
|
+
*/
|
|
131
|
+
configPath?: string;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* 加载 lzi-plans 配置
|
|
135
|
+
*
|
|
136
|
+
* @param options - 加载选项
|
|
137
|
+
* @returns 加载结果——命中返回解析后配置,未找到返回失败,显式路径不存在也按失败处理
|
|
138
|
+
* @throws {@link Error} 命中配置但形态或跨条目非法——加载即失败语义
|
|
139
|
+
*/
|
|
140
|
+
declare function loadLziPlansConfig(options?: LoadLziPlansConfigOptions): Promise<LoadLziPlansConfigResult>;
|
|
141
|
+
/**
|
|
142
|
+
* 按显式文件 URL 动态导入配置模块——测试与工具内部使用
|
|
143
|
+
*
|
|
144
|
+
* @param configPath - 配置文件绝对路径
|
|
145
|
+
* @returns 配置模块 default 导出
|
|
146
|
+
* @throws {@link Error} 导入失败或无 default 导出
|
|
147
|
+
*/
|
|
148
|
+
declare function importConfigModule(configPath: string): Promise<unknown>;
|
|
149
|
+
/**
|
|
150
|
+
* lzi-plans 配置脚手架渲染——init 命令落盘
|
|
151
|
+
*
|
|
152
|
+
* 双形态渲染 `lzi-plans.config.ts`——全缺省产出无参正形,任一旗标显式
|
|
153
|
+
* 给定即真实信息增量、落显式形态;幂等不覆盖由命令层守卫
|
|
154
|
+
*/
|
|
155
|
+
/**
|
|
156
|
+
* 脚手架渲染入参——全字段可选,全缺省即无参正形
|
|
157
|
+
*/
|
|
158
|
+
type ConfigScaffoldInput = {
|
|
159
|
+
/**
|
|
160
|
+
* scope key——kebab-case,缺省以标准默认补齐
|
|
161
|
+
*/
|
|
162
|
+
scopeKey?: string;
|
|
163
|
+
/**
|
|
164
|
+
* scope 人类可读名——缺省以标准默认补齐
|
|
165
|
+
*/
|
|
166
|
+
scopeTitle?: string;
|
|
167
|
+
/**
|
|
168
|
+
* 注册表目录——posix 相对仓库根,缺省以标准默认补齐
|
|
169
|
+
*/
|
|
170
|
+
registryDir?: string;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* 渲染 lzi-plans.config.ts 脚手架全文
|
|
174
|
+
*
|
|
175
|
+
* @remarks
|
|
176
|
+
* 开箱即用全局规定——`defineConfig()` 无参调用即接入,无信息增量内容不
|
|
177
|
+
* 显性化;任一字段给定时 scope 结构四字段必填,未给定字段以标准默认
|
|
178
|
+
* 补齐,属部分信息增量的显式形态
|
|
179
|
+
* @param input - 脚手架入参,缺省为无参正形
|
|
180
|
+
* @returns 可直接落盘的配置文件全文
|
|
181
|
+
*/
|
|
182
|
+
declare function renderConfigScaffold(input?: ConfigScaffoldInput): string;
|
|
183
|
+
/**
|
|
184
|
+
* 校验并透传配置——语义非法即抛,消息聚合全部违规项
|
|
185
|
+
*
|
|
186
|
+
* @param config - 形态解析后的配置
|
|
187
|
+
* @returns 原样透传——校验通过
|
|
188
|
+
* @throws {@link Error} 跨条目语义违规
|
|
189
|
+
*/
|
|
190
|
+
declare function validateLziPlansConfig(config: LziPlansConfig): LziPlansConfig;
|
|
191
|
+
export { ConfigScaffoldInput, DEFAULT_REGISTRY_DIR, DEFAULT_SCOPES, LoadLziPlansConfigFailure, LoadLziPlansConfigOptions, LoadLziPlansConfigResult, LoadLziPlansConfigSuccess, LziPlansConfig, LziPlansConfigInput, LziPlansConfigSource, SCOPE_KEY_PATTERN, ScopeEntry, ScopeEntryInput, defineConfig, importConfigModule, loadLziPlansConfig, lziPlansConfigSchema, parseLziPlansConfig, renderConfigScaffold, validateLziPlansConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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=/^[a-z][a-z0-9-]*$/,o=`docs/plans`,s=i.object({key:i.string().regex(a),title:i.string().min(1),paths:i.array(i.string().min(1)).min(1),registryDir:i.string().min(1)}),c=[{key:`root`,title:`全局`,paths:[`.`],registryDir:o}],l=i.object({scopes:i.array(s).min(1).default([...c])});function u(e){let t=l.safeParse(e??{});if(!t.success){let e=t.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`,`);throw Error(`lzi-plans 配置形态非法:${e}`)}return t.data}function d(e){return e}function f(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,否则归档扫描与报告歧义`);if(t.length>0)throw Error(`lzi-plans 配置跨条目语义非法:${t.join(`,`)}`);return e}function p(e,t){try{return f(u(e))}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(`${n}——配置文件 ${t}`)}}const m=`@longzai-intelligence-plans/config`,h=/Cannot find (?:module|package)|ModuleNotFound|Could not resolve|ERR_MODULE_NOT_FOUND/i,g=`在目标仓执行 bun add -d ${m} 后重试——已声明未安装时执行 bun install`;function _(e,t){if(e instanceof Error&&h.test(e.message)&&e.message.includes(m)){let e=t===void 0?``:`——配置文件 ${t}`;return/* @__PURE__ */ Error(`配置 import 的 ${m} 未安装——${g}${e}`)}return e}async function v(r={}){if(r.configPath!==void 0){let e=n(r.cwd??process.cwd(),r.configPath);return t(e)?{ok:!0,config:p(await y(e),e),configFilePath:e,source:`explicit`}:{ok:!1,reason:`未找到配置文件:${e}`}}let i;try{i=await e({standaloneFile:`lzi-plans.config.ts`,unifiedField:`plans`,cwd:r.cwd})}catch(e){throw _(e)}return i.success?{ok:!0,config:p(i.config,i.configFilePath),configFilePath:i.configFilePath,source:i.source}:{ok:!1,reason:`未找到 lzi-plans.config.ts——且 lzi.config.ts 无 plans 字段,归档检查走缺省注册面可先落配置文件`}}async function y(e){let t;try{t=await import(r(e).href)}catch(t){throw _(t,e)}if(t.default===void 0)throw Error(`配置文件缺少 default 导出:${e}`);return t.default}function b(e={}){return e.scopeKey===void 0&&e.scopeTitle===void 0&&e.registryDir===void 0?`import { defineConfig } from '@longzai-intelligence-plans/config';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* lzi-plans 就地配置
|
|
5
|
+
*
|
|
6
|
+
* 开箱即用零参数,文件存在即声明本仓接入 plans 治理;仅在出现真实信息增量的配置项时显式填写
|
|
7
|
+
*/
|
|
8
|
+
export default defineConfig();
|
|
9
|
+
`:[`import { defineConfig } from '@longzai-intelligence-plans/config';`,``,`/**`,` * lzi-plans 配置`,` */`,`export default defineConfig({`,` scopes: [`,` { key: '${e.scopeKey??`root`}', title: '${e.scopeTitle??`全局`}', paths: ['.'], registryDir: '${e.registryDir??`docs/plans`}' },`,` ],`,`});`,``].join(`
|
|
10
|
+
`)}export{o as DEFAULT_REGISTRY_DIR,c as DEFAULT_SCOPES,a as SCOPE_KEY_PATTERN,d as defineConfig,y as importConfigModule,v as loadLziPlansConfig,l as lziPlansConfigSchema,u as parseLziPlansConfig,b as renderConfigScaffold,f as validateLziPlansConfig};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"node:module";export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-plans/config",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Longzai Intelligence Plans 配置",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"config",
|
|
7
|
+
"longzai-intelligence",
|
|
8
|
+
"plans",
|
|
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": "lzi-typecheck",
|
|
29
|
+
"lint": "lzi-lint lint",
|
|
30
|
+
"lint:fix": "lzi-lint fix",
|
|
31
|
+
"test": "bun test",
|
|
32
|
+
"test:watch": "bun test --watch",
|
|
33
|
+
"test:coverage": "bun test --coverage"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@longzai-intelligence-shared-config/core": "^0.0.5",
|
|
37
|
+
"zod": "^4.4.3"
|
|
38
|
+
}
|
|
39
|
+
}
|