@longzai-intelligence-tsconfig/core 0.0.1 → 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/dist/index.js +2 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import"./rolldown-runtime-BqT_7tdF.js";import{existsSync as e,readFileSync as t,readdirSync as n}from"node:fs";import{join as r}from"node:path";
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{existsSync as e,readFileSync as t,readdirSync as n}from"node:fs";import{join as r}from"node:path";function i(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function a(e){return typeof e==`string`}function o(e){let t=[],n=!1;for(let r=0;r<e.length;r+=1){let i=e[r],a=e[r+1];if(n){t.push(i??``),i===`\\`?(a!==void 0&&t.push(a),r+=1):i===`"`&&(n=!1);continue}if(i===`"`){n=!0,t.push(i);continue}if(i===`/`&&a===`/`){for(;r<e.length&&e[r]!==`
|
|
2
2
|
`;)r+=1;t.push(`
|
|
3
|
-
`);continue}if(i===`/`&&a===`*`){for(r+=2;r<e.length&&(e[r]!==`*`||e[r+1]!==`/`);)r+=1;r+=1,t.push(` `);continue}t.push(i??``)}return t.join(``)}function
|
|
3
|
+
`);continue}if(i===`/`&&a===`*`){for(r+=2;r<e.length&&(e[r]!==`*`||e[r+1]!==`/`);)r+=1;r+=1,t.push(` `);continue}t.push(i??``)}return t.join(``)}function s(e){try{let n=t(e,`utf8`),r=JSON.parse(o(n));return i(r)?r:null}catch{return null}}function c(e,t){if(e===null)return[];let n=e[t];return Array.isArray(n)?n.filter(a):[]}function l(e){if(!Array.isArray(e))return[];let t=[];for(let n of e)i(n)&&a(n.path)&&t.push(u(n.path));return t}function u(e){let t=e.startsWith(`./`)?e.slice(2):e;for(;t.endsWith(`/`)&&t.length>1;)t=t.slice(0,-1);return t}const d=[{preset:`next`,basis:`依赖 next`,fields:[`dependencies`],packages:[`next`]},{preset:`taro`,basis:`依赖 @tarojs`,fields:[`dependencies`],packages:[`@tarojs/core`,`@tarojs/taro`]},{preset:`electron`,basis:`依赖 electron`,fields:[`dependencies`,`devDependencies`],packages:[`electron`]},{preset:`nest`,basis:`依赖 @nestjs/core`,fields:[`dependencies`],packages:[`@nestjs/core`]},{preset:`elysia`,basis:`依赖 elysia`,fields:[`dependencies`],packages:[`elysia`]},{preset:`react`,basis:`依赖 react`,fields:[`dependencies`,`peerDependencies`],packages:[`react`]}];function f(e){for(let t of d)for(let n of t.fields){let r=e?.[n];if(i(r)&&t.packages.some(e=>typeof r[e]==`string`))return{preset:t.preset,basis:t.basis,isOverride:!1}}return{preset:`library`,basis:`无框架依赖默认包型`,isOverride:!1}}const p=/^(?:lzi-[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|oxlint|oxfmt)\.config\.ts$/,m=[`@longzai-intelligence-typescript/bun-config/`,`@longzai-intelligence-typescript/node-config/`],h=/\/presets\/[a-z0-9-]+-test\.json$/;function g(e){return p.test(e)}function _(e){try{return n(e,{withFileTypes:!0}).filter(e=>e.isFile()&&g(e.name)).map(e=>e.name).sort()}catch{return[]}}function v(e){try{return n(e,{withFileTypes:!0}).filter(e=>e.isFile()&&e.name.endsWith(`.json`)).map(e=>e.name).sort()}catch{return[]}}function y(e){return e===`app.json`?`app`:e===`node.json`?`node`:e===`test.json`?`test`:`other`}function b(e,t){let n=t.startsWith(`./`)?t.slice(2):t;return e.some(e=>{let t=e.startsWith(`./`)?e.slice(2):e;return t===n||new Bun.Glob(t).match(n)})}function x(e,t,n,r,i){e.push({unit:t,rule:n,severity:`error`,file:r,message:i})}function S(e,t,n,r,i){if(r!==`../`)return;let a=t.include;if(Array.isArray(a))for(let t of a)typeof t==`string`&&!t.startsWith(`../`)&&!t.startsWith(`/`)&&x(i,e,`R4`,n,`include 条目 ${t} 为 dot-style 相对基准,相对 tsconfig 目录解析悬空——改写为 ../ 起`)}function C(e,t,n,r,i,a){for(let o of _(n)){let n=i===`../`?`../${o}`:o;b(t,n)||x(a,e,`R4`,r,`include 未覆盖 ${r===`tsconfig.json`?o:`包根配置文件 ${o}`}——C6,补列 ${n} 或以通配一次列全`)}}function w(e,t,n,r,i,a){let o=t.extends,s=typeof o==`string`?[o]:Array.isArray(o)?o.filter(e=>typeof e==`string`):[];if(s.length===0){x(a,e,`R5`,n,`缺失 extends——须指向共享配置包预设`);return}for(let t of s)t.startsWith(`.`)?x(a,e,`R5`,n,`extends 指向仓内相对路径 ${t}——D4 禁任意本地 base,改指共享配置包预设`):m.some(e=>t.startsWith(e))||x(a,e,`R5`,n,`extends 指向共享配置包以外的 ${t}——D4,改指 bun-config 或 node-config 预设`);r===`node`&&!s.some(e=>e.endsWith(`/presets/node.json`))&&x(a,e,`R5`,n,`node 片须 extends node 预设`),r===`test`&&!s.some(e=>h.test(e))&&x(a,e,`R5`,n,`test 片须 extends 对应的 *-test 预设`),r===`app`&&i!==null&&!s.some(e=>e.endsWith(`/presets/${i.preset}.json`))&&x(a,e,`R5`,n,i.isOverride?`app 片须 extends 配置覆写的 ${i.preset} 预设`:`app 片须 extends 包型 ${i.preset} 预设——${i.basis}自动推断,误判经配置 appPreset 覆写`)}const T=/* @__PURE__ */ new Set([`node_modules`,`dist`,`.turbo`,`.git`,`.cache`,`out`,`build`,`coverage`,`.bun`,`.swc`]);function E(e,t){let n=/* @__PURE__ */ new Set;for(let r of t)r.startsWith(`!`)||D(e,r.split(`/`).filter(e=>e.length>0),0,``,n);return[...n].sort()}function D(t,i,a,o,s){if(a===i.length){e(r(t,`package.json`))&&s.add(o);return}let c=i[a];if(c===void 0)return;if(c===`*`){let e=[];try{e=n(t,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!T.has(e.name)).map(e=>e.name)}catch{e=[]}for(let n of e)D(r(t,n),i,a+1,o===``?n:`${o}/${n}`,s);return}let l=r(t,c);e(l)&&D(l,i,a+1,o===``?c:`${o}/${c}`,s)}const O=[`app.json`,`node.json`,`test.json`];function k(e){let t=s(r(e,`package.json`));if(t===null)return[];let n=t.workspaces;return Array.isArray(n)?n.filter(a):i(n)&&Array.isArray(n.packages)?n.packages.filter(a):[]}function A(t,n,o,u){let d=s(r(t,`package.json`)),p=d?.scripts,m=i(p)&&a(p.typecheck),h=r(t,`tsconfig.json`),g=e(h),_=o.packages?.[n],y=_?.appPreset===void 0?f(d):{preset:_.appPreset,basis:`配置覆写`,isOverride:!0};if(_?.singleTsconfig!==void 0){j(t,n,g,u);return}if(!m&&!g)return;if(m&&!g){x(u,n,`R1`,`package.json`,`声明 typecheck 脚本但缺失 tsconfig.json——C1,补建 solution 根与分片`);return}!m&&g&&x(u,n,`R1`,`package.json`,`实有 tsconfig.json 但缺失 typecheck 脚本——C3,补齐标准三件套脚本`);let b=v(r(t,`tsconfig`));for(let e of O)b.includes(e)||x(u,n,`R1`,`tsconfig/${e}`,`缺失分片 tsconfig/${e}——C2,照产品群标准模板补建`);let S=s(h);if(S===null){x(u,n,`R2`,`tsconfig.json`,`tsconfig.json 解析失败`);return}let C=Array.isArray(S.files)&&S.files.length===0,w=l(S.references);(!C||w.length===0||c(S,`include`).length>0)&&x(u,n,`R2`,`tsconfig.json`,`包根 tsconfig.json 须为 solution 形态——files 空数组、references 非空且不含 include,编译项归各分片`);let T=new Set(w);for(let e of b){let t=`tsconfig/${e}`;T.has(t)||x(u,n,`R3`,`tsconfig.json`,`分片 ${t} 未被根 tsconfig.json references 引用——C5,补引 { "path": "./${t}" }`)}for(let i of T)e(r(t,i))||x(u,n,`R3`,`tsconfig.json`,`references 指向不存在路径 ${i}——C5,移除悬空引用或补建目标`);M(t,n,b,y,u)}function j(e,t,n,i){if(!n){x(i,t,`R1`,`tsconfig.json`,`声明单一 tsconfig 豁免但缺失 tsconfig.json——ADR 0050 豁免以实有为前提`);return}let a=s(r(e,`tsconfig.json`));if(a===null){x(i,t,`R2`,`tsconfig.json`,`tsconfig.json 解析失败`);return}let o=c(a,`include`);S(t,a,`tsconfig.json`,``,i),C(t,o,e,`tsconfig.json`,``,i),w(t,a,`tsconfig.json`,`other`,null,i)}function M(e,t,n,i,a){for(let o of n){let n=s(r(e,`tsconfig`,o)),l=`tsconfig/${o}`;if(n===null){x(a,t,`R2`,l,`分片 ${l} 解析失败`);continue}S(t,n,l,`../`,a),o===`node.json`&&C(t,c(n,`include`),e,l,`../`,a),w(t,n,l,y(o),i,a)}}function N(t,n,i){let a=v(r(t,`tsconfig`));for(let e of a)e!==`node.json`&&x(i,`.`,`R3`,`tsconfig/${e}`,`模块根 tsconfig 目录仅允许 node.json——ADR 0011,发现 ${e}`);let o=r(t,`tsconfig.json`),l=r(t,`tsconfig`,`node.json`);if(e(o)?P(t,n,i):x(i,`.`,`R3`,`tsconfig.json`,`模块根缺失溶液根 tsconfig.json——ADR 0011,补建 files 空数组加 references 形态`),e(l)){let e=s(l);e===null?x(i,`.`,`R2`,`tsconfig/node.json`,`根 node 片解析失败`):(S(`.`,e,`tsconfig/node.json`,`../`,i),C(`.`,c(e,`include`),t,`tsconfig/node.json`,`../`,i),w(`.`,e,`tsconfig/node.json`,`node`,null,i))}else _(t).length>0&&x(i,`.`,`R4`,`tsconfig/node.json`,`模块根缺失 tsconfig/node.json,根配置文件零类型检查覆盖——C6,照标准模板补建`)}function P(t,n,i){let a=s(r(t,`tsconfig.json`));if(a===null){x(i,`.`,`R2`,`tsconfig.json`,`模块根 tsconfig.json 解析失败`);return}(!(Array.isArray(a.files)&&a.files.length===0)||c(a,`include`).length>0)&&x(i,`.`,`R2`,`tsconfig.json`,`模块根 tsconfig.json 须为 files 空数组且不含 include——编译项归子包分片`);let o=l(a.references),u=new Set(o);o.length===0&&x(i,`.`,`R2`,`tsconfig.json`,`模块根 tsconfig.json references 为空——须引用自身 node 片与子包`);for(let n of u)n!==`tsconfig/node.json`&&(n.startsWith(`tsconfig/`)?x(i,`.`,`R3`,`tsconfig.json`,`模块根 references 引用了 node 片以外的 ${n}——ADR 0011 只准引 node 片与子包`):e(r(t,n))||x(i,`.`,`R3`,`tsconfig.json`,`模块根 references 指向不存在路径 ${n}——C5`));e(r(t,`tsconfig`,`node.json`))&&!u.has(`tsconfig/node.json`)&&x(i,`.`,`R3`,`tsconfig.json`,`根 node 片未被模块根 references 引用——C5,补引 { "path": "./tsconfig/node.json" }`);for(let a of n)e(r(t,a,`tsconfig.json`))&&!u.has(a)&&!u.has(`${a}/tsconfig.json`)&&x(i,`.`,`R3`,`tsconfig.json`,`仓根溶液 references 缺引单元 ${a}——C5,补引 { "path": "./${a}" }`)}function F(e){let t=[],n=k(e.rootDir);if(n.length===0)return I(e,t);let i=E(e.rootDir,n),a=new Set(e.config.exclude??[]),o=i.filter(e=>!a.has(e));N(e.rootDir,o,t);for(let n of o)A(r(e.rootDir,n),n,e.config,t);return{violations:t,summary:{unitCount:o.length+1,errorCount:t.filter(e=>e.severity===`error`).length,warnCount:t.filter(e=>e.severity===`warn`).length}}}function I(t,n){return e(r(t.rootDir,`tsconfig.json`))?(A(t.rootDir,`.`,t.config,n),{violations:n,summary:{unitCount:1,errorCount:n.filter(e=>e.severity===`error`).length,warnCount:n.filter(e=>e.severity===`warn`).length}}):{violations:n,summary:{unitCount:0,errorCount:0,warnCount:0}}}export{E as expandWorkspaceUnits,F as runCheck};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-tsconfig/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Longzai Intelligence tsconfig 形态校验引擎",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
"clean": "lzi-dev-cli clean"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@longzai-intelligence-tsconfig/config": "0.0.
|
|
35
|
+
"@longzai-intelligence-tsconfig/config": "0.0.2"
|
|
36
36
|
}
|
|
37
37
|
}
|