@longzai-intelligence-dependencies/cli 0.0.2 → 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.
Files changed (2) hide show
  1. package/dist/index.js +6 -5
  2. package/package.json +2 -7
package/dist/index.js CHANGED
@@ -306,9 +306,10 @@ n?this.stack.push(n):(yield*this.pop(),yield*this.step())}else{let t=this.peek(2
306
306
  版本同步完成`),$(`- ${m}: ${u.length} 个包`),$(`- 已跳过: ${d} 个包(已是目标版本)`),f>0&&$(`- 失败: ${f} 个包`),u.length>0&&($(`
307
307
  变更详情:`),$(Tx(u))),!r&&f===0&&($(`
308
308
  下一步:生成 Changelog`),$(` bun release:log ${e}`))},Dx=async()=>{let e=process.cwd();$(`正在扫描 ${e} 下的 package.json 文件...`);let t=await Rb(),n=Bb(t.versionSync?.ignorePaths),r=await Cx(e,e,n),i=r.packages;if(i.length===0){r.scannedFiles>0?$(`扫描到 ${r.scannedFiles} 个 package.json 文件,但没有可识别的 npm 包(均缺少 name 字段或解析失败)`):$(`未找到任何 package.json 文件`);return}$(`找到 ${i.length} 个包`);let a=i.filter(e=>e.version===null).map(e=>e.name);a.length>0&&($(`\n以下 ${a.length} 个包缺少 version 字段(尚未打版):`),$(` ${a.join(`, `)}`),$(`请先执行 version sync <目标版本> 完成首次打版`),process.exit(1));let o=/* @__PURE__ */ new Map;for(let e of i){let t=o.get(e.version??`0.0.0`)??[];t.push(e.name),o.set(e.version??`0.0.0`,t)}if(o.size===1){let[e]=o.keys();$(`所有包版本一致: ${e}`);return}$(`
309
- 版本号不一致:`);for(let[e,t]of o)$(` ${e}: ${t.join(`, `)}`);process.exit(1)},Ox=`lzi-architecture.yaml`,kx=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`),Ax=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{};let t={};return`root`in e&&typeof e.root==`string`&&(t.root=e.root),`exclude`in e&&kx(e.exclude)&&(t.exclude=e.exclude),t},jx=async e=>{try{let t=await Bun.file(e).text();return Ax(Bun.YAML.parse(t))}catch(t){Fb(`错误: 加载配置文件失败: ${e}`,t instanceof Error?t.message:String(t)),process.exit(1)}},Mx=e=>typeof e!=`object`||!e||Array.isArray(e)?{}:`exclude`in e&&kx(e.exclude)?{exclude:e.exclude}:{},Nx=e=>typeof e==`object`&&e&&`default`in e?e.default:void 0,Px=async e=>{if(e){let t=ne(process.cwd(),e);w(t)||(Fb(`错误: 配置文件不存在: ${t}`),process.exit(1));let n=await jx(t);return{rootDir:ne(k(t),n.root??`../`),exclude:n.exclude??[],source:`explicit`}}let t=process.env.LZI_GLOBALS_ROOT;if(t!==void 0&&t!==``){let e=A(ne(t),`lzi-architecture.config.ts`);if(w(e))try{let n=Mx(Nx(await import(e)));return{rootDir:k(ne(t)),exclude:n.exclude??[],source:`globals`}}catch(t){Fb(`错误: 加载 globals 聚合配置失败: ${e}`,t instanceof Error?t.message:String(t)),process.exit(1)}}let n=process.cwd();for(;n!==`/`;){let e=A(n,Ox);if(w(e)){let t=await jx(e);return{rootDir:ne(k(e),t.root??`../`),exclude:t.exclude??[],source:`yaml-upward`}}n=k(n)}return null},Fx=(e,t)=>{let n;try{n=O(e)}catch{Fb(`错误: 无法读取聚合根目录: ${e}`),process.exit(1)}let r=new Set(t);return n.filter(e=>!(e.startsWith(`.`)||e===`node_modules`||r.has(e))).map(t=>{let n=A(e,t),r=A(n,`package.json`);try{if(ee(n).isDirectory()&&w(r))return{name:t,dir:n}}catch{}return null}).filter(e=>e!==null)},Ix=(e,t)=>Bun.spawnSync([`git`,`diff`,`--quiet`,`HEAD`,`--`,t],{cwd:e,stdout:`pipe`,stderr:`pipe`}).exitCode===0,Lx=e=>{let t=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`("${t}/[^"]+":\\s*")[^"]*(")`,`g`)},Rx=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),zx=e=>/^[~^]?\d/.test(e),Bx=(e,t)=>`${/^[~^]/.exec(e)?.[0]??``}${t}`,Vx=e=>{let t=Bun.spawnSync([`git`,`ls-files`,`--`,`*/package.json`],{cwd:e,stdout:`pipe`,stderr:`pipe`});return t.exitCode===0?[`package.json`,...(t.stdout?.toString()??``).trim().split(`
310
- `).map(e=>e.trim()).filter(e=>e.length>0).filter(t=>w(A(e,t)))]:[`package.json`]},Hx=(e,t,n)=>Bun.spawnSync([`git`,`commit`,...t,`-m`,n],{cwd:e,stdout:`pipe`,stderr:`pipe`}).exitCode===0,Ux=async(e,t,n)=>{let r=await Bun.file(e).text(),i=[],a=[],o=[],s;for(t.lastIndex=0;(s=t.exec(r))!==null;){let e=s[0],t=s[1]??``,r=s[2]??``,i=/^"([^"]+)"/.exec(t)?.[1]??``,a=e.slice(t.length,e.length-r.length),c=n(i,a);a!==c&&zx(a)&&o.push({name:i,oldVersion:a,targetVersion:c,prefix:t,suffix:r})}if(o.length===0)return{matchedPackages:i,changes:a};let c=r;for(let e of o){let t=RegExp(`("${Rx(e.name)}":\\s*")[^"]*(")`);c=c.replace(t,`$1${e.targetVersion}$2`),i.push(e.name),a.push({name:e.name,from:e.oldVersion,to:e.targetVersion})}return await Bun.write(e,c),{matchedPackages:i,changes:a}},Wx=async(e,t,n)=>{let r=await Bun.file(e).text(),i=[],a=[];t.lastIndex=0;let o;for(;(o=t.exec(r))!==null;){let e=o[0],t=o[1]??``,r=o[2]??``,s=/^"([^"]+)"/.exec(t)?.[1]??``,c=e.slice(t.length,e.length-r.length),l=n(s,c);c!==l&&zx(c)&&(i.push(s),a.push({name:s,from:c,to:l}))}return{matchedPackages:i,changes:a}},Gx=async(e,t,n,r,i)=>{let{name:a,dir:o}=e,s=Vx(o),c=[],l=[],u=[],d=[];for(let e of s){let r=A(o,e),a=await Wx(r,t,n);if(a.matchedPackages.length!==0){if(!Ix(o,e)){u.push(e);continue}if(i)c.push(...a.matchedPackages),l.push(...a.changes);else{let e=await Ux(r,t,n);c.push(...e.matchedPackages),l.push(...e.changes)}d.push(e)}}return d.length===0?u.length>0?{name:a,dir:o,matchedPackages:c,changes:l,skippedFiles:u,status:`skipped-dirty`,reason:`package.json 已有未提交改动:${u.join(`,`)}`}:{name:a,dir:o,matchedPackages:c,changes:l,status:`skipped-nochange`,reason:`无匹配 scope 或已是目标版本`}:i||Hx(o,d,r)?{name:a,dir:o,matchedPackages:c,changes:l,skippedFiles:u,status:`success`}:{name:a,dir:o,matchedPackages:c,changes:l,skippedFiles:u,status:`failed`,reason:`git commit 失败,文件已修改,需人工介入`}},Kx=async(e,t)=>{let n=/* @__PURE__ */ new Set;for(let r of e){let e=Vx(r.dir);for(let i of e){let e=A(r.dir,i),a=await Bun.file(e).text();t.lastIndex=0;let o;for(;(o=t.exec(a))!==null;){let e=o[1]??``,t=/^"([^"]+)"/.exec(e)?.[1];t&&n.add(t)}}}return[...n]},qx=async(e,t)=>{let n=/* @__PURE__ */ new Map,r=[],i=0,a=async e=>{let t=await oy(e),i=t.tags?.latest;if(i===void 0){let n=t.error instanceof Error?t.error.message:t.error??`未找到 dist-tags.latest`;r.push({name:e,reason:n})}else n.set(e,i)},o=async()=>{for(;i<e.length;){let t=e[i];i++,t!==void 0&&await a(t)}},s=Array.from({length:Math.min(t,e.length)},()=>o());if(await Promise.all(s),r.length>0){Fb(`${Nb.RED}错误: 部分包查询 npm latest 失败,已中止(0 文件改动、0 提交)${Nb.RESET}`);for(let e of r)Fb(` ${e.name}: ${e.reason}`);process.exit(1)}return n},Jx=async e=>{let{scope:t,version:n,message:r,dryRun:i}=e,a=e.concurrency??10,o=await Px(e.config);o||(Fb(`错误: 未找到产品群配置文件 ${Ox}`),Fb(`提示: 请在 architecture 项目创建该配置文件(参考 lzi-architecture.sample.yaml)`),Fb(`提示: 或使用 --config <path> 显式指定`),Fb(`提示: 或在 .env 设置 LZI_GLOBALS_ROOT 定位 globals 仓 TS 配置(ADR 0081)`),process.exit(1));let s=o.rootDir;w(s)||(Fb(`错误: 聚合根目录不存在: ${s}`),process.exit(1));let c=o.exclude,l=n===void 0,u=l?`latest(各自 npm 最新)`:n,d=r??(l?`chore: bump ${t} deps to latest`:`chore: bump ${t} deps to ${n.replace(/^[~^]/,``)}`),f=Lx(t);$(`${Nb.BLUE}═══ version upgrade-across ═══${Nb.RESET}`),$(`聚合配置来源: ${o.source}(--config 显式 / env globals / cwd 上溯 yaml)`),$(`聚合根: ${s}`),$(`升级范围: ${t} 下的所有包 -> ${u}`),$(`并发数: ${a}`),c.length>0&&$(`排除项目: ${c.join(`, `)}`),i&&$(`${Nb.YELLOW}[dry-run] 预览模式,不写文件、不提交${Nb.RESET}`),$(``);let p=Fx(s,c);$(`发现 ${p.length} 个子项目,并发处理(并发 ${a})...`),$(``);let m;if(l){let e=await Kx(p,f);if(e.length===0){$(`${Nb.YELLOW}未匹配到任何 ${t} 下的包,结束${Nb.RESET}`);return}$(`匹配到 ${e.length} 个 ${t} 下的包,查询 npm latest...`);let n=await qx(e,a);m=(e,t)=>Bx(t,n.get(e)??``)}else{let e=n??``;m=()=>e}let h=[],g=0,_=p.length;await(async(e,t)=>{let n=0,r=async()=>{for(;n<e.length;){let t=e[n];if(n++,t===void 0)break;let r=await Gx(t,f,m,d,i);h.push(r),g++;let a=r.status===`success`?`${Nb.GREEN}✓${Nb.RESET}`:r.status===`failed`?`${Nb.RED}✗${Nb.RESET}`:`·`;$(` [${g}/${_}] ${a} ${t.name}`)}},a=Array.from({length:Math.min(t,e.length)},()=>r());await Promise.all(a)})(p,a),$(``),Yx(h,i)},Yx=(e,t)=>{let n=e.filter(e=>e.status===`success`),r=e.filter(e=>e.status===`skipped-dirty`),i=e.filter(e=>e.status===`skipped-nochange`),a=e.filter(e=>e.status===`failed`);$(`${Nb.BLUE}═══ 处理结果 ═══${Nb.RESET}`);let o=t?`将提交`:`已提交`;$(`${Nb.GREEN}✓ ${o}: ${n.length}${Nb.RESET}`);for(let e of n){let t=e.changes.map(e=>`${e.name.split(`/`).pop()}: ${e.from} → ${e.to}`).join(`, `);$(` ${e.name}`),$(` ${t}`),e.skippedFiles!==void 0&&e.skippedFiles.length>0&&$(` ⚠ 脏文件跳过:${e.skippedFiles.join(`,`)}`)}if(r.length>0){$(``),$(`${Nb.YELLOW}⚠ 跳过(文件已改动): ${r.length}${Nb.RESET}`);for(let e of r)$(` ${e.name}: ${e.reason}`)}if(i.length>0&&($(``),$(`跳过(无匹配/已是目标版本): ${i.length}`)),a.length>0){$(``),$(`${Nb.RED}✗ 失败(需人工介入): ${a.length}${Nb.RESET}`);for(let e of a)$(` ${e.name}: ${e.reason}`),$(` ${e.changes.map(e=>`${e.name.split(`/`).pop()}: ${e.from} → ${e.to}`).join(`, `)}`)}$(``),$(`${Nb.BLUE}汇总: ${n.length} ${o} / ${r.length} 跳过(dirty) / ${i.length} 跳过(无变更) / ${a.length} 失败${Nb.RESET}`),!t&&n.length>0&&($(``),$(`下一步:推送到远程`),$(` bun push-all`)),a.length>0&&(process.exitCode=1)},Xx=pl([`default`,`major`,`minor`,`patch`,`latest`,`newest`]).default(`default`),Zx=async e=>{let t=(await Rb()).versionUpgrade??{},n=e.mode||t.mode||`default`,r=Xx.safeParse(n),i=r.success?r.data:`default`,a=[...e.scope?[`${e.scope}/*`]:[],...t.include??[]],{packages:o}=await jb({cwd:process.cwd(),mode:i,write:!e.dryRun&&e.write,recursive:t.recursive??!0,timeout:t.timeout??3e4,retries:t.retries??3,exclude:t.exclude??[],include:a,depFields:t.depFields,ignorePaths:t.ignorePaths??[],concurrency:t.concurrency??10,force:!1,all:!1,install:!1,update:!1,interactive:!1,group:!0,includeLocked:!1,timediff:!0,nodecompat:!0,loglevel:`info`,silent:!1,failOnOutdated:!1},{afterPackagesLoaded:e=>{$(`扫描到 ${e.length} 个包,正在检查依赖更新...`)},beforePackageStart:e=>{$(`正在检查 ${e.name||e.relative}...`)},afterPackageEnd:e=>{let t=e.resolved.filter(e=>e.update).length;$(t>0?` ✓ ${e.name||e.relative}: 发现 ${t} 个可更新依赖`:` ✓ ${e.name||e.relative}: 所有依赖已是最新`)},afterPackageWrite:e=>{$(` 📝 已写入 ${e.name||e.relative}`)}}),s=0;$(`
311
- --- 检查结果 ---`);for(let e of o){let t=e.resolved.filter(e=>e.update);if(t.length>0){s+=t.length,$(`\n${e.name||e.relative}:`);for(let e of t){let t=e.diff??``;$(` ${e.name}: ${e.currentVersion} -> ${e.targetVersion} (${t})`)}}}s===0?$(`所有依赖已是最新版本`):($(`\n共发现 ${s} 个可更新依赖`),e.write?$(`已写入 package.json`):$(`使用 --write 参数写入 package.json`))};function Qx(e){Zl(e,{name:`version sync`,description:`同步所有包的版本号`,arguments:[{signature:`<version>`,description:`目标版本号(X.Y.Z)`}],options:[{flags:`--dry-run`,description:`仅预览,不实际修改`}],schema:al({dryRun:Xc().optional()}),action:async(e,[t])=>{t||(process.stderr.write(`错误: version sync 需要指定目标版本号
312
- `),process.exit(1)),await Ex(t,{dryRun:e.dryRun===!0})}}),Zl(e,{name:`version check`,description:`检查所有包的版本号是否一致`,schema:al({}),action:async()=>{await Dx()}}),Zl(e,{name:`version upgrade`,description:`检查依赖版本更新`,arguments:[{signature:`[mode]`,description:`升级模式(major/minor/patch/latest/newest)`},{signature:`[scope]`,description:`可选。仅升级指定 scope 下的依赖(如 @longzai-intelligence-oxlint),内部展开为 include @scope/*`}],options:[{flags:`--write`,description:`将更新写入 package.json`},{flags:`--dry-run`,description:`仅预览`}],schema:al({write:Xc().optional(),dryRun:Xc().optional()}),action:async(e,t)=>{let n=t[0],r=t[1];await Zx({mode:n,write:e.write===!0,dryRun:e.dryRun===!0,scope:r})}}),Zl(e,{name:`version upgrade-across`,description:`跨产品群批量升级依赖(读 lzi-architecture.yaml)`,options:[{flags:`--scope <scope>`,description:`依赖 scope(必填,如 @longzai-intelligence-builder)`},{flags:`--target <version>`,description:`目标版本号(可选,如 ^0.0.8。省略时自动取每个匹配包的 npm latest)`},{flags:`-m, --message <message>`,description:`自定义提交信息`},{flags:`--config <path>`,description:`配置文件路径(显式指定,覆盖自动查找)`},{flags:`--concurrency <n>`,description:`并发数(默认 10)`},{flags:`--dry-run`,description:`仅预览(不写文件、不提交)`}],schema:al({scope:xc().optional(),target:xc().optional(),message:xc().optional(),config:xc().optional(),concurrency:Ll().int().positive().optional(),dryRun:Xc().optional()}),action:async e=>{e.scope||(process.stderr.write(`错误: version upgrade-across 需要指定 --scope <@scope>
309
+ 版本号不一致:`);for(let[e,t]of o)$(` ${e}: ${t.join(`, `)}`);process.exit(1)},Ox=il({name:xc().optional(),workspaces:Qc().optional(),devDependencies:dl(xc(),xc()).optional()}),kx=async()=>{let e=process.cwd();$(`正在扫描 ${e} 下的 package.json 文件...`);let t=null;try{let n=Ox.safeParse(await Bun.file(`${e}/package.json`).json());t=n.success?n.data:null}catch{t=null}t===null&&($(`未找到可解析的 workspace 根 package.json,请在仓库根目录执行本命令`),process.exit(1));let n=await Rb(),r=Bb(n.hoisting?.ignorePaths),i=new Set(n.hoisting?.allowlist??[]),a=t.devDependencies??{},o=await Wd(`**/package.json`,{cwd:e,ignore:r,onlyFiles:!0,dot:!1}),s=0,c=[];for(let t of o){if(t===`package.json`)continue;let n=null;try{let r=Ox.safeParse(await Bun.file(`${e}/${t}`).json());n=r.success?r.data:null}catch{n=null}if(n===null||n.workspaces!==void 0)continue;let r=n.devDependencies??{};if(Object.keys(r).length!==0){s+=1;for(let[o,s]of Object.entries(r)){let r=a[o];r===void 0||i.has(o)||c.push({packageName:n.name??t,relPath:j(e,`${e}/${t}`),dependency:o,subRange:s,rootRange:r,drifted:s!==r})}}}if($(`找到 ${s} 个子包,根声明开发依赖 ${Object.keys(a).length} 项`),c.length===0){$(`所有子包均未重复声明根已有的开发依赖`);return}$(`
310
+ 以下子包重复声明根已有的开发依赖:`);for(let e of c){let t=e.drifted?` 版本漂移`:``;$(` ${e.packageName} ${e.relPath}`),$(` ${e.dependency} 子声明 ${e.subRange} 根声明 ${e.rootRange}${t}`)}$(`共 ${c.length} 处重复声明,处置口径见 ADR 0036`),process.exit(1)},Ax=`lzi-architecture.yaml`,jx=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`),Mx=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{};let t={};return`root`in e&&typeof e.root==`string`&&(t.root=e.root),`exclude`in e&&jx(e.exclude)&&(t.exclude=e.exclude),t},Nx=async e=>{try{let t=await Bun.file(e).text();return Mx(Bun.YAML.parse(t))}catch(t){Fb(`错误: 加载配置文件失败: ${e}`,t instanceof Error?t.message:String(t)),process.exit(1)}},Px=e=>typeof e!=`object`||!e||Array.isArray(e)?{}:`exclude`in e&&jx(e.exclude)?{exclude:e.exclude}:{},Fx=e=>typeof e==`object`&&e&&`default`in e?e.default:void 0,Ix=async e=>{if(e){let t=ne(process.cwd(),e);w(t)||(Fb(`错误: 配置文件不存在: ${t}`),process.exit(1));let n=await Nx(t);return{rootDir:ne(k(t),n.root??`../`),exclude:n.exclude??[],source:`explicit`}}let t=process.env.LZI_GLOBALS_ROOT;if(t!==void 0&&t!==``){let e=A(ne(t),`lzi-architecture.config.ts`);if(w(e))try{let n=Px(Fx(await import(e)));return{rootDir:k(ne(t)),exclude:n.exclude??[],source:`globals`}}catch(t){Fb(`错误: 加载 globals 聚合配置失败: ${e}`,t instanceof Error?t.message:String(t)),process.exit(1)}}let n=process.cwd();for(;n!==`/`;){let e=A(n,Ax);if(w(e)){let t=await Nx(e);return{rootDir:ne(k(e),t.root??`../`),exclude:t.exclude??[],source:`yaml-upward`}}n=k(n)}return null},Lx=(e,t)=>{let n;try{n=O(e)}catch{Fb(`错误: 无法读取聚合根目录: ${e}`),process.exit(1)}let r=new Set(t);return n.filter(e=>!(e.startsWith(`.`)||e===`node_modules`||r.has(e))).map(t=>{let n=A(e,t),r=A(n,`package.json`);try{if(ee(n).isDirectory()&&w(r))return{name:t,dir:n}}catch{}return null}).filter(e=>e!==null)},Rx=(e,t)=>Bun.spawnSync([`git`,`diff`,`--quiet`,`HEAD`,`--`,t],{cwd:e,stdout:`pipe`,stderr:`pipe`}).exitCode===0,zx=e=>{let t=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`("${t}/[^"]+":\\s*")[^"]*(")`,`g`)},Bx=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),Vx=e=>/^[~^]?\d/.test(e),Hx=(e,t)=>`${/^[~^]/.exec(e)?.[0]??``}${t}`,Ux=e=>{let t=Bun.spawnSync([`git`,`ls-files`,`--`,`*/package.json`],{cwd:e,stdout:`pipe`,stderr:`pipe`});return t.exitCode===0?[`package.json`,...(t.stdout?.toString()??``).trim().split(`
311
+ `).map(e=>e.trim()).filter(e=>e.length>0).filter(t=>w(A(e,t)))]:[`package.json`]},Wx=(e,t,n)=>Bun.spawnSync([`git`,`commit`,...t,`-m`,n],{cwd:e,stdout:`pipe`,stderr:`pipe`}).exitCode===0,Gx=async(e,t,n)=>{let r=await Bun.file(e).text(),i=[],a=[],o=[],s;for(t.lastIndex=0;(s=t.exec(r))!==null;){let e=s[0],t=s[1]??``,r=s[2]??``,i=/^"([^"]+)"/.exec(t)?.[1]??``,a=e.slice(t.length,e.length-r.length),c=n(i,a);a!==c&&Vx(a)&&o.push({name:i,oldVersion:a,targetVersion:c,prefix:t,suffix:r})}if(o.length===0)return{matchedPackages:i,changes:a};let c=r;for(let e of o){let t=RegExp(`("${Bx(e.name)}":\\s*")[^"]*(")`);c=c.replace(t,`$1${e.targetVersion}$2`),i.push(e.name),a.push({name:e.name,from:e.oldVersion,to:e.targetVersion})}return await Bun.write(e,c),{matchedPackages:i,changes:a}},Kx=async(e,t,n)=>{let r=await Bun.file(e).text(),i=[],a=[];t.lastIndex=0;let o;for(;(o=t.exec(r))!==null;){let e=o[0],t=o[1]??``,r=o[2]??``,s=/^"([^"]+)"/.exec(t)?.[1]??``,c=e.slice(t.length,e.length-r.length),l=n(s,c);c!==l&&Vx(c)&&(i.push(s),a.push({name:s,from:c,to:l}))}return{matchedPackages:i,changes:a}},qx=async(e,t,n,r,i)=>{let{name:a,dir:o}=e,s=Ux(o),c=[],l=[],u=[],d=[];for(let e of s){let r=A(o,e),a=await Kx(r,t,n);if(a.matchedPackages.length!==0){if(!Rx(o,e)){u.push(e);continue}if(i)c.push(...a.matchedPackages),l.push(...a.changes);else{let e=await Gx(r,t,n);c.push(...e.matchedPackages),l.push(...e.changes)}d.push(e)}}return d.length===0?u.length>0?{name:a,dir:o,matchedPackages:c,changes:l,skippedFiles:u,status:`skipped-dirty`,reason:`package.json 已有未提交改动:${u.join(`,`)}`}:{name:a,dir:o,matchedPackages:c,changes:l,status:`skipped-nochange`,reason:`无匹配 scope 或已是目标版本`}:i||Wx(o,d,r)?{name:a,dir:o,matchedPackages:c,changes:l,skippedFiles:u,status:`success`}:{name:a,dir:o,matchedPackages:c,changes:l,skippedFiles:u,status:`failed`,reason:`git commit 失败,文件已修改,需人工介入`}},Jx=async(e,t)=>{let n=/* @__PURE__ */ new Set;for(let r of e){let e=Ux(r.dir);for(let i of e){let e=A(r.dir,i),a=await Bun.file(e).text();t.lastIndex=0;let o;for(;(o=t.exec(a))!==null;){let e=o[1]??``,t=/^"([^"]+)"/.exec(e)?.[1];t&&n.add(t)}}}return[...n]},Yx=async(e,t)=>{let n=/* @__PURE__ */ new Map,r=[],i=0,a=async e=>{let t=await oy(e),i=t.tags?.latest;if(i===void 0){let n=t.error instanceof Error?t.error.message:t.error??`未找到 dist-tags.latest`;r.push({name:e,reason:n})}else n.set(e,i)},o=async()=>{for(;i<e.length;){let t=e[i];i++,t!==void 0&&await a(t)}},s=Array.from({length:Math.min(t,e.length)},()=>o());if(await Promise.all(s),r.length>0){Fb(`${Nb.RED}错误: 部分包查询 npm latest 失败,已中止(0 文件改动、0 提交)${Nb.RESET}`);for(let e of r)Fb(` ${e.name}: ${e.reason}`);process.exit(1)}return n},Xx=async e=>{let{scope:t,version:n,message:r,dryRun:i}=e,a=e.concurrency??10,o=await Ix(e.config);o||(Fb(`错误: 未找到产品群配置文件 ${Ax}`),Fb(`提示: 请在 architecture 项目创建该配置文件(参考 lzi-architecture.sample.yaml)`),Fb(`提示: 或使用 --config <path> 显式指定`),Fb(`提示: 或在 .env 设置 LZI_GLOBALS_ROOT 定位 globals 仓 TS 配置(ADR 0081)`),process.exit(1));let s=o.rootDir;w(s)||(Fb(`错误: 聚合根目录不存在: ${s}`),process.exit(1));let c=o.exclude,l=n===void 0,u=l?`latest(各自 npm 最新)`:n,d=r??(l?`chore: bump ${t} deps to latest`:`chore: bump ${t} deps to ${n.replace(/^[~^]/,``)}`),f=zx(t);$(`${Nb.BLUE}═══ version upgrade-across ═══${Nb.RESET}`),$(`聚合配置来源: ${o.source}(--config 显式 / env globals / cwd 上溯 yaml)`),$(`聚合根: ${s}`),$(`升级范围: ${t} 下的所有包 -> ${u}`),$(`并发数: ${a}`),c.length>0&&$(`排除项目: ${c.join(`, `)}`),i&&$(`${Nb.YELLOW}[dry-run] 预览模式,不写文件、不提交${Nb.RESET}`),$(``);let p=Lx(s,c);$(`发现 ${p.length} 个子项目,并发处理(并发 ${a})...`),$(``);let m;if(l){let e=await Jx(p,f);if(e.length===0){$(`${Nb.YELLOW}未匹配到任何 ${t} 下的包,结束${Nb.RESET}`);return}$(`匹配到 ${e.length} 个 ${t} 下的包,查询 npm latest...`);let n=await Yx(e,a);m=(e,t)=>Hx(t,n.get(e)??``)}else{let e=n??``;m=()=>e}let h=[],g=0,_=p.length;await(async(e,t)=>{let n=0,r=async()=>{for(;n<e.length;){let t=e[n];if(n++,t===void 0)break;let r=await qx(t,f,m,d,i);h.push(r),g++;let a=r.status===`success`?`${Nb.GREEN}✓${Nb.RESET}`:r.status===`failed`?`${Nb.RED}✗${Nb.RESET}`:`·`;$(` [${g}/${_}] ${a} ${t.name}`)}},a=Array.from({length:Math.min(t,e.length)},()=>r());await Promise.all(a)})(p,a),$(``),Zx(h,i)},Zx=(e,t)=>{let n=e.filter(e=>e.status===`success`),r=e.filter(e=>e.status===`skipped-dirty`),i=e.filter(e=>e.status===`skipped-nochange`),a=e.filter(e=>e.status===`failed`);$(`${Nb.BLUE}═══ 处理结果 ═══${Nb.RESET}`);let o=t?`将提交`:`已提交`;$(`${Nb.GREEN}✓ ${o}: ${n.length}${Nb.RESET}`);for(let e of n){let t=e.changes.map(e=>`${e.name.split(`/`).pop()}: ${e.from} → ${e.to}`).join(`, `);$(` ${e.name}`),$(` ${t}`),e.skippedFiles!==void 0&&e.skippedFiles.length>0&&$(` ⚠ 脏文件跳过:${e.skippedFiles.join(`,`)}`)}if(r.length>0){$(``),$(`${Nb.YELLOW}⚠ 跳过(文件已改动): ${r.length}${Nb.RESET}`);for(let e of r)$(` ${e.name}: ${e.reason}`)}if(i.length>0&&($(``),$(`跳过(无匹配/已是目标版本): ${i.length}`)),a.length>0){$(``),$(`${Nb.RED}✗ 失败(需人工介入): ${a.length}${Nb.RESET}`);for(let e of a)$(` ${e.name}: ${e.reason}`),$(` ${e.changes.map(e=>`${e.name.split(`/`).pop()}: ${e.from} → ${e.to}`).join(`, `)}`)}$(``),$(`${Nb.BLUE}汇总: ${n.length} ${o} / ${r.length} 跳过(dirty) / ${i.length} 跳过(无变更) / ${a.length} 失败${Nb.RESET}`),!t&&n.length>0&&($(``),$(`下一步:推送到远程`),$(` bun push-all`)),a.length>0&&(process.exitCode=1)},Qx=pl([`default`,`major`,`minor`,`patch`,`latest`,`newest`]).default(`default`),$x=async e=>{let t=(await Rb()).versionUpgrade??{},n=e.mode||t.mode||`default`,r=Qx.safeParse(n),i=r.success?r.data:`default`,a=[...e.scope?[`${e.scope}/*`]:[],...t.include??[]],{packages:o}=await jb({cwd:process.cwd(),mode:i,write:!e.dryRun&&e.write,recursive:t.recursive??!0,timeout:t.timeout??3e4,retries:t.retries??3,exclude:t.exclude??[],include:a,depFields:t.depFields,ignorePaths:t.ignorePaths??[],concurrency:t.concurrency??10,force:!1,all:!1,install:!1,update:!1,interactive:!1,group:!0,includeLocked:!1,timediff:!0,nodecompat:!0,loglevel:`info`,silent:!1,failOnOutdated:!1},{afterPackagesLoaded:e=>{$(`扫描到 ${e.length} 个包,正在检查依赖更新...`)},beforePackageStart:e=>{$(`正在检查 ${e.name||e.relative}...`)},afterPackageEnd:e=>{let t=e.resolved.filter(e=>e.update).length;$(t>0?` ✓ ${e.name||e.relative}: 发现 ${t} 个可更新依赖`:` ✓ ${e.name||e.relative}: 所有依赖已是最新`)},afterPackageWrite:e=>{$(` 📝 已写入 ${e.name||e.relative}`)}}),s=0;$(`
312
+ --- 检查结果 ---`);for(let e of o){let t=e.resolved.filter(e=>e.update);if(t.length>0){s+=t.length,$(`\n${e.name||e.relative}:`);for(let e of t){let t=e.diff??``;$(` ${e.name}: ${e.currentVersion} -> ${e.targetVersion} (${t})`)}}}s===0?$(`所有依赖已是最新版本`):($(`\n共发现 ${s} 个可更新依赖`),e.write?$(`已写入 package.json`):$(`使用 --write 参数写入 package.json`))};function eS(e){Zl(e,{name:`version sync`,description:`同步所有包的版本号`,arguments:[{signature:`<version>`,description:`目标版本号(X.Y.Z)`}],options:[{flags:`--dry-run`,description:`仅预览,不实际修改`}],schema:al({dryRun:Xc().optional()}),action:async(e,[t])=>{t||(process.stderr.write(`错误: version sync 需要指定目标版本号
313
+ `),process.exit(1)),await Ex(t,{dryRun:e.dryRun===!0})}}),Zl(e,{name:`version check`,description:`检查所有包的版本号是否一致`,schema:al({}),action:async()=>{await Dx()}}),Zl(e,{name:`version upgrade`,description:`检查依赖版本更新`,arguments:[{signature:`[mode]`,description:`升级模式(major/minor/patch/latest/newest)`},{signature:`[scope]`,description:`可选。仅升级指定 scope 下的依赖(如 @longzai-intelligence-oxlint),内部展开为 include @scope/*`}],options:[{flags:`--write`,description:`将更新写入 package.json`},{flags:`--dry-run`,description:`仅预览`}],schema:al({write:Xc().optional(),dryRun:Xc().optional()}),action:async(e,t)=>{let n=t[0],r=t[1];await $x({mode:n,write:e.write===!0,dryRun:e.dryRun===!0,scope:r})}}),Zl(e,{name:`version upgrade-across`,description:`跨产品群批量升级依赖(读 lzi-architecture.yaml)`,options:[{flags:`--scope <scope>`,description:`依赖 scope(必填,如 @longzai-intelligence-builder)`},{flags:`--target <version>`,description:`目标版本号(可选,如 ^0.0.8。省略时自动取每个匹配包的 npm latest)`},{flags:`-m, --message <message>`,description:`自定义提交信息`},{flags:`--config <path>`,description:`配置文件路径(显式指定,覆盖自动查找)`},{flags:`--concurrency <n>`,description:`并发数(默认 10)`},{flags:`--dry-run`,description:`仅预览(不写文件、不提交)`}],schema:al({scope:xc().optional(),target:xc().optional(),message:xc().optional(),config:xc().optional(),concurrency:Ll().int().positive().optional(),dryRun:Xc().optional()}),action:async e=>{e.scope||(process.stderr.write(`错误: version upgrade-across 需要指定 --scope <@scope>
313
314
  `),process.stderr.write(`示例: --scope @longzai-intelligence-builder
314
- `),process.exit(1)),await Jx({scope:e.scope,version:e.target,message:e.message,config:e.config,concurrency:e.concurrency,dryRun:e.dryRun===!0})}})}function $x(){let e=ql({name:`lzi-dependencies`,description:`Longzai Intelligence 依赖版本管理工具`,version:`0.0.2`});return Qx(e),e}async function eS(){await $x().parseAsync(process.argv)}import.meta.main===!0&&await eS();export{$x as buildProgram};
315
+ `),process.exit(1)),await Xx({scope:e.scope,version:e.target,message:e.message,config:e.config,concurrency:e.concurrency,dryRun:e.dryRun===!0})}})}function tS(e){Zl(e,{name:`hoisting check`,description:`检查子包开发依赖是否重复声明 workspace 根已有依赖`,schema:al({}),action:async()=>{await kx()}})}function nS(){let e=ql({name:`lzi-dependencies`,description:`Longzai Intelligence 依赖版本管理工具`,version:`0.0.3`});return eS(e),tS(e),e}async function rS(){await nS().parseAsync(process.argv)}import.meta.main===!0&&await rS();export{nS as buildProgram};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-dependencies/cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Longzai Intelligence 依赖版本管理 CLI(bin lzi-dependencies)",
5
5
  "keywords": [
6
6
  "cli",
@@ -39,11 +39,6 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@longzai-intelligence-cli/core": "^0.0.10",
42
- "@longzai-intelligence-dependencies/core": "0.0.2"
43
- },
44
- "devDependencies": {
45
- "@longzai-intelligence-builder/esm": "^0.2.19",
46
- "@longzai-intelligence-builder/utils": "^0.2.19",
47
- "@types/bun": "^1.4.2"
42
+ "@longzai-intelligence-dependencies/core": "0.0.3"
48
43
  }
49
44
  }