@longzai-intelligence-bun/cli 0.0.11 → 0.0.12

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 +1 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -138,7 +138,7 @@ ${K.default.gray(Ra+Ia.repeat(i+2)+za)}
138
138
  `)}`];return i.length>0&&a.push(`[install.scopes]\n${i.join(`
139
139
  `)}`),a.join(`
140
140
 
141
- `)}function oo(){let e={};for(let[t,n]of to)e[t]=n;return{registry:`https://mirrors.cloud.tencent.com/npm/`,scopes:e,linker:`isolated`,globalStore:!0}}function $(e,t){if(t!==void 0){if(typeof t==`boolean`||typeof t==`number`)return`${e} = ${t}`;if(typeof t==`string`)return`${e} = ${no(t)}`;if(Array.isArray(t))return t.length===0?void 0:`${e} = ${ro(t)}`}}function so(e){let t=[];e.install&&t.push(ao(e.install));let n=e.test,r=[],i=$(`preload`,n.preload);i&&r.push(i);let a=$(`coverage`,n.coverage);a&&r.push(a);let o=$(`coverageSkipTestFiles`,n.coverageSkipTestFiles);o&&r.push(o);let s=$(`coverageReporter`,n.coverageReporter);s&&r.push(s);let c=$(`coverageDir`,n.coverageDir);c&&r.push(c);let l=$(`coveragePathIgnorePatterns`,n.coveragePathIgnorePatterns);l&&r.push(l),n.coverageThreshold!==void 0&&(typeof n.coverageThreshold==`number`?r.push(`coverageThreshold = ${n.coverageThreshold}`):r.push(`coverageThreshold = ${io(n.coverageThreshold)}`));let u=$(`coverageIgnoreSourcemaps`,n.coverageIgnoreSourcemaps);u&&r.push(u);let d=$(`timeout`,n.timeout);return d&&r.push(d),r.length>0&&t.push(`[test]\n${r.join(`
141
+ `)}function oo(){let e={};for(let[t,n]of to)e[t]=n;return{registry:`https://mirrors.cloud.tencent.com/npm/`,scopes:e}}function $(e,t){if(t!==void 0){if(typeof t==`boolean`||typeof t==`number`)return`${e} = ${t}`;if(typeof t==`string`)return`${e} = ${no(t)}`;if(Array.isArray(t))return t.length===0?void 0:`${e} = ${ro(t)}`}}function so(e){let t=[];e.install&&t.push(ao(e.install));let n=e.test,r=[],i=$(`preload`,n.preload);i&&r.push(i);let a=$(`coverage`,n.coverage);a&&r.push(a);let o=$(`coverageSkipTestFiles`,n.coverageSkipTestFiles);o&&r.push(o);let s=$(`coverageReporter`,n.coverageReporter);s&&r.push(s);let c=$(`coverageDir`,n.coverageDir);c&&r.push(c);let l=$(`coveragePathIgnorePatterns`,n.coveragePathIgnorePatterns);l&&r.push(l),n.coverageThreshold!==void 0&&(typeof n.coverageThreshold==`number`?r.push(`coverageThreshold = ${n.coverageThreshold}`):r.push(`coverageThreshold = ${io(n.coverageThreshold)}`));let u=$(`coverageIgnoreSourcemaps`,n.coverageIgnoreSourcemaps);u&&r.push(u);let d=$(`timeout`,n.timeout);return d&&r.push(d),r.length>0&&t.push(`[test]\n${r.join(`
142
142
  `)}`),`# @lzi-bun-cli 自动生成,请勿编辑\n${t.join(`
143
143
 
144
144
  `)}\n`}function co(e,t={}){let n=t.isRoot===!0,r=e?.test,i=r?r.coverage!==void 0||r.coverageThreshold!==void 0||r.coveragePathIgnorePatterns!==void 0||r.coverageReporter!==void 0||r.coverageSkipTestFiles!==void 0||r.coverageDir!==void 0||r.preload!==void 0||r.timeout!==void 0:!1;if(!n&&!i)return null;let a={test:r??{}};return n&&(a.install=oo()),{content:so(a),shouldWrite:!0}}function lo(e){return e.map(e=>{if(typeof e==`string`)return e;if(e instanceof Error)return e.message;try{return JSON.stringify(e)}catch{return String(e)}}).join(` `)}function uo(...e){process.stdout.write(`${lo(e)}\n`)}function fo(...e){process.stderr.write(`${lo(e)}\n`)}const po=async(e=process.cwd())=>{let t=await h({cwd:e,standaloneFile:`lzi-bun.config.ts`,unifiedField:`bun`});return t.success?t.config:(uo(`提示: 未找到配置文件 lzi-bun.config.ts,使用默认配置`),{})},mo=[`src/**/*.test.ts`,`src/**/*.test.tsx`,`__tests__/**/*.test.ts`],ho=e=>{let r=i(e,`package.json`);if(!t(r))return!1;let a;try{a=JSON.parse(n(r,`utf8`)).workspaces}catch{return!1}return Array.isArray(a)||typeof a==`object`&&!!a&&`packages`in a};function go(e){let t=[`bun`,`test`];return e.watch===!0&&t.push(`--watch`),e.coverage===!0&&t.push(`--coverage`),e.extra&&e.extra.length>0&&t.push(...e.extra),t}async function _o(e){let t=new Set;for(let n of e){let e=new Bun.Glob(n);for await(let n of e.scan({cwd:process.cwd(),onlyFiles:!0}))t.add(n)}return t.size}const vo=async(e,a={})=>{let o=a.dir??process.cwd(),s=i(o,`bunfig.toml`),c=co(e,{isRoot:ho(o)});if(!c?.shouldWrite)return a.dryRun&&uo(`(无 coverage 配置,不会生成 bunfig.toml)`),{status:`skipped`,bunfigPath:s};if(a.dryRun)return uo(`[dry-run] 将写入 ${s}:`),uo(c.content),{status:`generated`,bunfigPath:s};if(t(s)&&!n(s,`utf8`).includes(`@lzi-bun-cli 自动生成,请勿编辑`))throw new eo(s);return r(s,c.content,`utf8`),uo(`已生成 ${s}(lzi-bun-cli 接管覆盖率配置)`),{status:`generated`,bunfigPath:s}},yo=async e=>{let t=await po(),n=t.test?.passWithNoTests??!0;await _o(t.test?.include??mo)===0&&(n&&(uo(`无测试文件,跳过(type-only / facade 包,passWithNoTests)`),process.exit(0)),fo(`错误: 未找到测试文件,且 test.passWithNoTests 为 false`),fo(`(如该包确为 type-only / facade 包,请在 lzi-dev.config.ts 设置 test.passWithNoTests: true)`),process.exit(1));try{await vo(t)}catch(e){throw e instanceof eo&&(fo(`错误: ${e.message}`),process.exit(1)),e}let r=go(e),i=await Bun.spawn(r,{cwd:process.cwd(),stdout:`inherit`,stderr:`inherit`}).exited;i!==0&&process.exit(i)},bo=async e=>{let t=await po();try{await vo(t,{dryRun:e})}catch(e){throw e instanceof eo&&(fo(`错误: ${e.message}`),process.exit(1)),e}},xo=e=>{let r=a(e,`package.json`);t(r)||(fo(`错误: 当前目录 ${e} 无 package.json,--recursive 须在 monorepo root 执行`),process.exit(1));let i;try{i=JSON.parse(n(r,`utf8`)).workspaces}catch{i=void 0}Array.isArray(i)||typeof i==`object`&&i&&`packages`in i||(fo(`错误: ${e} 的 package.json 未声明 workspaces 字段,--recursive 须在 monorepo root 执行`),process.exit(1))},So=async e=>{let t=process.cwd();xo(t);let r=await m(t,{configFileName:`lzi-bun.config.ts`}),i=t.split(`/`).pop()??`root`;try{let e=JSON.parse(n(a(t,`package.json`),`utf8`));e.name&&(i=e.name)}catch{}let o=[{name:i,dir:t}];o.push(...r.map(e=>({name:e.name,dir:e.dir}))),uo(`发现 ${o.length} 个目标(root 1 + 子包 ${r.length}),开始${e?`预览`:`生成`}...`);let s=[];for(let t of o){uo(`▶ ${t.name}`);try{let n=await po(t.dir),{status:r}=await vo(n,{dryRun:e,dir:t.dir});s.push({name:t.name,dir:t.dir,status:r})}catch(e){s.push({name:t.name,dir:t.dir,status:`failed`,reason:e instanceof Error?e.message:String(e)})}}let c=s.filter(e=>e.status===`generated`),l=s.filter(e=>e.status===`skipped`),u=s.filter(e=>e.status===`failed`);if(uo(``),uo(`汇总:${c.length} 生成 / ${l.length} 跳过 / ${u.length} 失败`),u.length>0){fo(``),fo(`失败子包:`);for(let e of u)fo(` - ${e.name}:${e.reason}`);process.exitCode=1}},Co=async e=>{let t=e.dryRun===!0;if(e.recursive===!0){await So(t);return}await bo(t)};function wo(e){To(e),Eo(e)}function To(e){Ii(e,{name:`test`,description:`运行 bun 测试(替代三件套,零测试包默认放行)`,options:[{flags:`--watch`,description:`监听模式(对应 test:watch)`},{flags:`--coverage`,description:`覆盖率(对应 test:coverage)`}],schema:qr({watch:zr().optional(),coverage:zr().optional()}),action:async(e,t)=>{await yo({watch:e.watch===!0,coverage:e.coverage===!0,extra:t})}})}function Eo(e){Ii(e,{name:`config generate`,description:`生成 bunfig.toml(不执行测试,支持 --dry-run 预览、-r 批量)`,options:[{flags:`--dry-run`,description:`仅预览将写入的内容,不写盘`},{flags:`-r, --recursive`,description:`递归处理 monorepo 下含 lzi-bun.config.ts 的子包`}],schema:qr({dryRun:zr().optional(),recursive:zr().optional()}),action:async e=>{await Co({dryRun:e.dryRun===!0,recursive:e.recursive===!0})}})}const Do=Mi({name:`lzi-bun-cli`,description:`Longzai Intelligence bun 工具集`,interaction:$a,color:Qa});wo(Do);async function Oo(){await Do.parseAsync(process.argv)}Oo().catch(e=>{process.stderr.write(`错误: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)});export{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-bun/cli",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Longzai Intelligence bun 工具集 CLI",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {
@@ -33,6 +33,6 @@
33
33
  "test:coverage": "bun test --coverage"
34
34
  },
35
35
  "dependencies": {
36
- "@longzai-intelligence-bun/config": "0.0.11"
36
+ "@longzai-intelligence-bun/config": "0.0.12"
37
37
  }
38
38
  }