@longzai-intelligence-npm-registry/config 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 +188 -0
- package/dist/index.js +2 -0
- package/dist/rolldown-runtime-BqT_7tdF.js +1 -0
- package/package.json +37 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import "./rolldown-runtime-BqT_7tdF.js";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
//#region src/env.constants.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* env 键名单一真源与缺省常量(agent-tools 范式:env 名一律 `LZI_<TOOL>_` 前缀)。
|
|
6
|
+
*
|
|
7
|
+
* 机器本地数据(集中数据根 / 监听地址端口)只走 .env + 环境变量;
|
|
8
|
+
* 跨机器稳定的项目事实在 lzi-npm-registry.config.ts(见 config.loader.ts)。
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* 集中数据根 env 键(绝对路径;缺省回退仓库根同级 data/ 惯例,见 data-root.utils.ts)
|
|
12
|
+
*/
|
|
13
|
+
declare const ENV_KEY_DATA_ROOT = "LZI_NPM_REGISTRY_DATA_ROOT";
|
|
14
|
+
/**
|
|
15
|
+
* 监听地址 env 键(缺省仅本机回环——local-first 安全缺省)
|
|
16
|
+
*/
|
|
17
|
+
declare const ENV_KEY_HOST = "LZI_NPM_REGISTRY_HOST";
|
|
18
|
+
/**
|
|
19
|
+
* 监听端口 env 键(0 = 随机端口,供发现式拉起)
|
|
20
|
+
*/
|
|
21
|
+
declare const ENV_KEY_PORT = "LZI_NPM_REGISTRY_PORT";
|
|
22
|
+
/**
|
|
23
|
+
* env 键名单一真源(供校验/文档/CLI 提示统一引用)
|
|
24
|
+
*/
|
|
25
|
+
declare const ENV_KEYS: {
|
|
26
|
+
readonly dataRoot: "LZI_NPM_REGISTRY_DATA_ROOT";
|
|
27
|
+
readonly host: "LZI_NPM_REGISTRY_HOST";
|
|
28
|
+
readonly port: "LZI_NPM_REGISTRY_PORT";
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 缺省监听地址(仅本机回环)
|
|
32
|
+
*/
|
|
33
|
+
declare const DEFAULT_HOST = "127.0.0.1";
|
|
34
|
+
/**
|
|
35
|
+
* 缺省监听端口(避开 Verdaccio 惯用 4873,防止双装冲突)
|
|
36
|
+
*/
|
|
37
|
+
declare const DEFAULT_PORT = 4874;
|
|
38
|
+
/**
|
|
39
|
+
* 集中数据目录名(位于产品群 data/ 集中目录下,命名对齐 `<project-name>-data` 惯例)
|
|
40
|
+
*/
|
|
41
|
+
declare const CENTRAL_DATA_DIR_NAME = "longzai-intelligence-npm-registry-data";
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/env.config.d.ts
|
|
44
|
+
/**
|
|
45
|
+
* env 契约(HOST / PORT 必填有缺省;DATA_ROOT 可空——由 resolveDataRoot 解析链兜底)
|
|
46
|
+
*/
|
|
47
|
+
declare const NpmRegistryEnvSchema: z.ZodObject<{
|
|
48
|
+
host: z.ZodDefault<z.ZodString>;
|
|
49
|
+
port: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
50
|
+
dataRoot: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
/**
|
|
53
|
+
* env 形态
|
|
54
|
+
*/
|
|
55
|
+
type NpmRegistryEnv = z.infer<typeof NpmRegistryEnvSchema>;
|
|
56
|
+
/**
|
|
57
|
+
* 解析极简 .env 文本(KEY=VALUE 行;# 注释与空行跳过;成对单/双引号剥壳;不展开变量)
|
|
58
|
+
*
|
|
59
|
+
* @param content - .env 文件全文
|
|
60
|
+
* @returns 键值表
|
|
61
|
+
*/
|
|
62
|
+
declare function parseEnvFileContent(content: string): Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* 合成有效 env:仓库根 .env 兜底 + process.env 覆盖(同名后者优先)
|
|
65
|
+
*
|
|
66
|
+
* @param repoRoot - 仓库根(null 时跳过文件兜底)
|
|
67
|
+
* @returns 有效 env 键值表
|
|
68
|
+
*/
|
|
69
|
+
declare function loadEffectiveEnv(repoRoot: string | null): Record<string, string | undefined>;
|
|
70
|
+
/**
|
|
71
|
+
* 解析 env(显式传入来源,便于测试)
|
|
72
|
+
*
|
|
73
|
+
* @param source - 有效 env 键值表(loadEffectiveEnv 产物)
|
|
74
|
+
* @returns env 形态(含缺省值填充)
|
|
75
|
+
* @throws {@link Error} 任一键取值不合法时(启动期响亮失败)
|
|
76
|
+
*/
|
|
77
|
+
declare function parseNpmRegistryEnv(source: Record<string, string | undefined>): NpmRegistryEnv;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/data-root.utils.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* 集中数据根解析链(agent-tools hub-resolution 同款范式:显式 env > 惯例回退 > 响亮报错)。
|
|
82
|
+
*
|
|
83
|
+
* 惯例回退:`<repoRoot>/../../data/longzai-intelligence-npm-registry-data`
|
|
84
|
+
* (仓库群平铺于 m5-edition 下,../.. 即产品群根,data/ 为集中数据目录)。
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* 数据根解析结果
|
|
88
|
+
*/
|
|
89
|
+
type ResolvedDataRoot = {
|
|
90
|
+
/**
|
|
91
|
+
* 集中数据根绝对路径(调用方负责建目录,见 core.ensureLayout)
|
|
92
|
+
*/
|
|
93
|
+
dataRoot: string;
|
|
94
|
+
/**
|
|
95
|
+
* 命中来源:env = 环境变量/.env 显式指定;convention = 仓库根惯例回退
|
|
96
|
+
*/
|
|
97
|
+
source: 'env' | 'convention';
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* 解析集中数据根
|
|
101
|
+
*
|
|
102
|
+
* @param envValue - env 提供的路径文本(可空;相对路径以 cwd 为基)
|
|
103
|
+
* @param repoRoot - 仓库根(convention 回退的前提;可为 null)
|
|
104
|
+
* @returns 数据根与命中来源
|
|
105
|
+
* @throws {@link Error} env 与惯例均无法提供时(列出全部尝试,附修复指引)
|
|
106
|
+
*/
|
|
107
|
+
declare function resolveDataRoot(envValue: string | undefined, repoRoot: string | null): ResolvedDataRoot;
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/npm-registry.config.d.ts
|
|
110
|
+
/**
|
|
111
|
+
* 上游直通模式集合:off = 纯本地孤仓;passthrough = 本地 miss 透传上游 packument
|
|
112
|
+
*/
|
|
113
|
+
declare const UPSTREAM_MODES: readonly ['off', 'passthrough'];
|
|
114
|
+
/**
|
|
115
|
+
* 上游直通模式
|
|
116
|
+
*/
|
|
117
|
+
declare const UpstreamModeSchema: z.ZodEnum<{
|
|
118
|
+
off: "off";
|
|
119
|
+
passthrough: "passthrough";
|
|
120
|
+
}>;
|
|
121
|
+
/**
|
|
122
|
+
* lzi-npm-registry 根配置 zod 契约(strict:多余键即报错,防止拼写漂移静默失效)
|
|
123
|
+
*/
|
|
124
|
+
declare const NpmRegistryConfigSchema: z.ZodObject<{
|
|
125
|
+
upstream: z.ZodObject<{
|
|
126
|
+
registry: z.ZodURL;
|
|
127
|
+
mode: z.ZodEnum<{
|
|
128
|
+
off: "off";
|
|
129
|
+
passthrough: "passthrough";
|
|
130
|
+
}>;
|
|
131
|
+
}, z.core.$strict>;
|
|
132
|
+
publish: z.ZodObject<{
|
|
133
|
+
allowPattern: z.ZodString;
|
|
134
|
+
}, z.core.$strict>;
|
|
135
|
+
}, z.core.$strict>;
|
|
136
|
+
/**
|
|
137
|
+
* lzi-npm-registry 根配置形态
|
|
138
|
+
*/
|
|
139
|
+
type NpmRegistryConfig = z.infer<typeof NpmRegistryConfigSchema>;
|
|
140
|
+
/**
|
|
141
|
+
* 内置缺省配置(未找到配置文件时的回退;与仓内 lzi-npm-registry.config.ts 保持一致)
|
|
142
|
+
*/
|
|
143
|
+
declare const DEFAULT_NPM_REGISTRY_CONFIG: NpmRegistryConfig;
|
|
144
|
+
/**
|
|
145
|
+
* 解析并校验根配置
|
|
146
|
+
*
|
|
147
|
+
* @param source - 载入的配置原文(loadUnifiedConfig 的 config 字段)
|
|
148
|
+
* @returns 校验后的根配置
|
|
149
|
+
* @throws {@link Error} 配置形状或取值不合法时(响亮失败并逐键列出原因)
|
|
150
|
+
*/
|
|
151
|
+
declare function parseNpmRegistryConfig(source: unknown): NpmRegistryConfig;
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/config.loader.d.ts
|
|
154
|
+
/**
|
|
155
|
+
* standalone 配置文件名(单一约定,供本装载器与文档引用)
|
|
156
|
+
*/
|
|
157
|
+
declare const STANDALONE_CONFIG_FILE = "lzi-npm-registry.config.ts";
|
|
158
|
+
/**
|
|
159
|
+
* lzi.config.ts 统一字段名
|
|
160
|
+
*/
|
|
161
|
+
declare const UNIFIED_CONFIG_FIELD = "npmRegistry";
|
|
162
|
+
/**
|
|
163
|
+
* 根配置装载结果
|
|
164
|
+
*/
|
|
165
|
+
type LoadedNpmRegistryConfig = {
|
|
166
|
+
/**
|
|
167
|
+
* 校验后的根配置
|
|
168
|
+
*/
|
|
169
|
+
config: NpmRegistryConfig;
|
|
170
|
+
/**
|
|
171
|
+
* 配置来源:standalone / unified / builtin
|
|
172
|
+
*/
|
|
173
|
+
source: 'standalone' | 'unified' | 'builtin';
|
|
174
|
+
/**
|
|
175
|
+
* 仓库根(standalone/unified 命中时为配置文件所在目录;builtin 时为 null)
|
|
176
|
+
*/
|
|
177
|
+
repoRoot: string | null;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* 装载根配置(cwd 起向上寻找;未命中回退内置缺省)
|
|
181
|
+
*
|
|
182
|
+
* @param cwd - 装载起点目录(缺省 process.cwd())
|
|
183
|
+
* @returns 根配置装载结果
|
|
184
|
+
* @throws {@link Error} 找到配置文件但内容不合法时(交由 parseNpmRegistryConfig 响亮失败)
|
|
185
|
+
*/
|
|
186
|
+
declare function loadNpmRegistryConfig(cwd?: string): Promise<LoadedNpmRegistryConfig>;
|
|
187
|
+
//#endregion
|
|
188
|
+
export { CENTRAL_DATA_DIR_NAME, DEFAULT_HOST, DEFAULT_NPM_REGISTRY_CONFIG, DEFAULT_PORT, ENV_KEYS, ENV_KEY_DATA_ROOT, ENV_KEY_HOST, ENV_KEY_PORT, type LoadedNpmRegistryConfig, type NpmRegistryConfig, NpmRegistryConfigSchema, type NpmRegistryEnv, NpmRegistryEnvSchema, type ResolvedDataRoot, STANDALONE_CONFIG_FILE, UNIFIED_CONFIG_FIELD, UPSTREAM_MODES, UpstreamModeSchema, loadEffectiveEnv, loadNpmRegistryConfig, parseEnvFileContent, parseNpmRegistryConfig, parseNpmRegistryEnv, resolveDataRoot };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{existsSync as e,readFileSync as t}from"node:fs";import{dirname as n,isAbsolute as r,join as i,resolve as a}from"node:path";import*as o from"zod";import{loadUnifiedConfig as s}from"@longzai-intelligence-shared-config/core";const c=`LZI_NPM_REGISTRY_DATA_ROOT`,l=`LZI_NPM_REGISTRY_HOST`,u=`LZI_NPM_REGISTRY_PORT`,d={dataRoot:c,host:l,port:u},f=`127.0.0.1`,p=4874,m=`longzai-intelligence-npm-registry-data`,h=o.object({host:o.string().min(1).default(f),port:o.coerce.number().int().min(0).max(65535).default(p),dataRoot:o.string().min(1).optional()});function g(e){let t={};for(let n of e.split(`
|
|
2
|
+
`)){let e=n.trim();if(e===``||e.startsWith(`#`))continue;let r=e.indexOf(`=`);if(r<=0)continue;let i=e.slice(0,r).trim(),a=e.slice(r+1).trim();(a.startsWith(`"`)&&a.endsWith(`"`)&&a.length>=2||a.startsWith(`'`)&&a.endsWith(`'`)&&a.length>=2)&&(a=a.slice(1,-1)),t[i]=a}return t}function _(n){let r={};if(n!==null){let a=i(n,`.env`);e(a)&&(r=g(t(a,`utf8`)))}return{...r,...process.env}}function v(e){let t=h.safeParse({host:e[d.host],port:e[d.port],dataRoot:e[d.dataRoot]});if(!t.success)throw Error(`[config] lzi-npm-registry env 不合法:${t.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`);return t.data}function y(e,t){if(e!==void 0&&e!==``)return{dataRoot:r(e)?e:a(process.cwd(),e),source:`env`};if(t!==null)return{dataRoot:a(t,`../../data`,m),source:`convention`};throw Error(`[config] 无法解析集中数据根(尝试:1) ${d.dataRoot} 环境变量/.env;2) 仓库根 ../../data/${m} 惯例回退,但未找到 lzi-npm-registry.config.ts 无法推导仓库根)。修复:在仓库根运行 \`bun run init\` 固化 .env,或显式设置 ${d.dataRoot}。`)}const b=[`off`,`passthrough`],x=o.enum(b),S=o.strictObject({upstream:o.strictObject({registry:o.url(),mode:x}),publish:o.strictObject({allowPattern:o.string().min(1).refine(e=>{try{return new RegExp(e),!0}catch{return!1}},{error:`allowPattern 必须是合法正则源文本`})})}),C={upstream:{registry:`https://mirrors.cloud.tencent.com/npm/`,mode:`passthrough`},publish:{allowPattern:`^@longzai-intelligence(-[a-z0-9-]+)?/`}};function w(e){let t=S.safeParse(e);if(!t.success)throw Error(`[config] lzi-npm-registry.config.ts 不合法:${t.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`);return t.data}const T=`lzi-npm-registry.config.ts`,E=`npmRegistry`;async function D(e=process.cwd()){let t=await s({cwd:e,standaloneFile:T,unifiedField:E});return t.success?{config:w(t.config),source:t.source,repoRoot:a(n(t.configFilePath))}:{config:C,source:`builtin`,repoRoot:null}}export{m as CENTRAL_DATA_DIR_NAME,f as DEFAULT_HOST,C as DEFAULT_NPM_REGISTRY_CONFIG,p as DEFAULT_PORT,d as ENV_KEYS,c as ENV_KEY_DATA_ROOT,l as ENV_KEY_HOST,u as ENV_KEY_PORT,S as NpmRegistryConfigSchema,h as NpmRegistryEnvSchema,T as STANDALONE_CONFIG_FILE,E as UNIFIED_CONFIG_FIELD,b as UPSTREAM_MODES,x as UpstreamModeSchema,_ as loadEffectiveEnv,D as loadNpmRegistryConfig,g as parseEnvFileContent,w as parseNpmRegistryConfig,v as parseNpmRegistryEnv,y as resolveDataRoot};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"node:module";export{};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-npm-registry/config",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Longzai Intelligence 本地 npm registry 配置收口:lzi-npm-registry.config.ts 契约加载 / env 单一真源 / 集中数据根解析链",
|
|
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",
|
|
29
|
+
"test:watch": "bun test --watch",
|
|
30
|
+
"test:coverage": "bun test --coverage",
|
|
31
|
+
"clean": "lzi-dev-cli clean"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@longzai-intelligence-shared-config/core": "^0.0.7",
|
|
35
|
+
"zod": "^4.4.3"
|
|
36
|
+
}
|
|
37
|
+
}
|