@longzai-intelligence-tsconfig/core 0.0.1 → 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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ type EngineInput = {
|
|
|
85
85
|
/**
|
|
86
86
|
* 执行形态检测
|
|
87
87
|
*
|
|
88
|
-
* 目标含 workspaces 声明时按模块根模式——模块根与全部子包单元逐一经 R1 到
|
|
88
|
+
* 目标含 workspaces 声明时按模块根模式——模块根与全部子包单元逐一经 R1 到 R7 判定;无 workspaces 而实有 `tsconfig.json`
|
|
89
89
|
* 时按单包模式——目标整体作为一个子包单元判定,不套用模块根判据。`exclude` 声明的单元整体跳过
|
|
90
90
|
*
|
|
91
91
|
* @param input - 引擎入参
|
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{
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{existsSync as e,readFileSync as t,readdirSync as n}from"node:fs";import{dirname as r,isAbsolute as i,join as a,relative as o,resolve as s}from"node:path";function c(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function l(e){return typeof e==`string`}function u(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);else if(i===`"`)n=!0,t.push(i);else if(i===`/`&&a===`/`){for(;r<e.length&&e[r]!==`
|
|
2
2
|
`;)r+=1;t.push(`
|
|
3
|
-
`)
|
|
3
|
+
`)}else if(i===`/`&&a===`*`){for(r+=2;r<e.length&&(e[r]!==`*`||e[r+1]!==`/`);)r+=1;r+=1,t.push(` `)}else t.push(i??``)}return t.join(``)}function d(e){try{let n=t(e,`utf8`).replace(/^\uFEFF/,``),r=JSON.parse(u(n));return c(r)?r:null}catch{return null}}function f(e,t){if(e===null)return[];let n=e[t];return Array.isArray(n)?n.filter(l):[]}function p(e){if(!Array.isArray(e))return[];let t=[];for(let n of e)c(n)&&l(n.path)&&t.push(m(n.path));return t}function m(e){let t=e.startsWith(`./`)?e.slice(2):e;for(;t.endsWith(`/`)&&t.length>1;)t=t.slice(0,-1);return t}const h=[{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 g(e){for(let t of h)for(let n of t.fields){let r=e?.[n];if(c(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 _=/^(?:lzi-[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|oxlint|oxfmt)\.config\.ts$/,v=[`@longzai-intelligence-typescript/bun-config/`,`@longzai-intelligence-typescript/node-config/`],y=/\/presets\/[a-z0-9-]+-test\.json$/;function b(e){return _.test(e)}function x(e){try{return n(e,{withFileTypes:!0}).filter(e=>e.isFile()&&b(e.name)).map(e=>e.name).sort()}catch{return[]}}function S(e){try{return n(e,{withFileTypes:!0}).filter(e=>e.isFile()&&e.name.endsWith(`.json`)).map(e=>e.name).sort()}catch{return[]}}function C(e){return e===`app.json`?`app`:e===`node.json`?`node`:e===`test.json`?`test`:`other`}function w(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 T(e,t,n,r,i){e.push({unit:t,rule:n,severity:`error`,file:r,message:i})}function E(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(`/`)&&T(i,e,`R4`,n,`include 条目 ${t} 为 dot-style 相对基准,相对 tsconfig 目录解析悬空——改写为 ../ 起`)}function D(e,t,n,r,i,a){for(let o of x(n)){let n=i===`../`?`../${o}`:o;w(t,n)||T(a,e,`R4`,r,`include 未覆盖 ${r===`tsconfig.json`?o:`包根配置文件 ${o}`}——C6,补列 ${n} 或以通配一次列全`)}}function O(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)T(a,e,`R5`,n,`缺失 extends——须指向共享配置包预设`);else{for(let t of s)t.startsWith(`.`)?T(a,e,`R5`,n,`extends 指向仓内相对路径 ${t}——D4 禁任意本地 base,改指共享配置包预设`):v.some(e=>t.startsWith(e))||T(a,e,`R5`,n,`extends 指向共享配置包以外的 ${t}——D4,改指 bun-config 或 node-config 预设`);r===`node`&&!s.some(e=>e.endsWith(`/presets/node.json`))&&T(a,e,`R5`,n,`node 片须 extends node 预设`),r===`test`&&!s.some(e=>y.test(e))&&T(a,e,`R5`,n,`test 片须 extends 对应的 *-test 预设`),r===`app`&&i!==null&&!s.some(e=>e.endsWith(`/presets/${i.preset}.json`))&&T(a,e,`R5`,n,i.isOverride?`app 片须 extends 配置覆写的 ${i.preset} 预设`:`app 片须 extends 包型 ${i.preset} 预设——${i.basis}自动推断,误判经配置 appPreset 覆写`)}}function k(e){let t=e.compilerOptions;if(!c(t))return[];let n=t.paths;if(!c(n))return[];let r=[];for(let[e,t]of Object.entries(n)){if(!Array.isArray(t))continue;let n=t.filter(e=>typeof e==`string`);n.length>0&&r.push({alias:e,targets:n})}return r}function A(e){return e.replace(/[/\\*]+$/u,``)}function j(e,t){let n=o(e,t);return n===``||!n.startsWith(`..`)&&!i(n)}function M(e,t,n){let r=A(n),i=e.compilerOptions,a=c(i)&&typeof i.baseUrl==`string`?s(t,i.baseUrl):t;return s(a,r)}function N(e,t,n,i,o){let s=a(i,r(n));for(let r of k(t))for(let a of r.targets)j(i,M(t,s,a))||T(o,e,`R7`,n,`paths 条目 ${r.alias} 目标 ${a} 逸出单元——ADR 0008 禁止跨包 paths,跨包依赖改经 package.json dependencies 引用 exports 契约`)}function P(e,t,n,i,o){let s=a(n,r(t));for(let n of k(e))for(let r of n.targets){let a=M(e,s,r);i.some(e=>j(e,a))&&T(o,`.`,`R7`,t,`paths 条目 ${n.alias} 目标 ${r} 指向子包目录——模块根无自身源码,ADR 0008 禁止跨包 paths,裁量保留经配置 moduleRootPaths 登记`)}}const F=/* @__PURE__ */ new Set([`node_modules`,`dist`,`.turbo`,`.git`,`.cache`,`out`,`build`,`coverage`,`.bun`,`.swc`]);function I(e,t){let n=/* @__PURE__ */ new Set;for(let r of t)r.startsWith(`!`)||L(e,r.split(`/`).filter(e=>e.length>0),0,``,n);return[...n].sort()}function L(t,r,i,o,s){if(i===r.length){e(a(t,`package.json`))&&s.add(o);return}let c=r[i];if(c===void 0)return;if(c===`*`){let e=[];try{e=n(t,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!F.has(e.name)).map(e=>e.name)}catch{e=[]}for(let n of e)L(a(t,n),r,i+1,o===``?n:`${o}/${n}`,s);return}let l=a(t,c);e(l)&&L(l,r,i+1,o===``?c:`${o}/${c}`,s)}const R=[`app.json`,`node.json`,`test.json`];function z(e){let t=d(a(e,`package.json`));if(t===null)return[];let n=t.workspaces;return Array.isArray(n)?n.filter(l):c(n)&&Array.isArray(n.packages)?n.packages.filter(l):[]}function B(t,n,r,i){let o=d(a(t,`package.json`)),s=o?.scripts,u=c(s)&&l(s.typecheck),m=a(t,`tsconfig.json`),h=e(m),_=r.packages?.[n],v=_?.appPreset===void 0?g(o):{preset:_.appPreset,basis:`配置覆写`,isOverride:!0};if(_?.singleTsconfig!==void 0){V(t,n,h,i);return}if(!u&&!h)return;if(u&&!h){T(i,n,`R1`,`package.json`,`声明 typecheck 脚本但缺失 tsconfig.json——C1,补建 solution 根与分片`);return}!u&&h&&T(i,n,`R1`,`package.json`,`实有 tsconfig.json 但缺失 typecheck 脚本——C3,补齐标准三件套脚本`);let y=S(a(t,`tsconfig`));for(let e of R)y.includes(e)||T(i,n,`R1`,`tsconfig/${e}`,`缺失分片 tsconfig/${e}——C2,照产品群标准模板补建`);let b=d(m);if(b===null){T(i,n,`R2`,`tsconfig.json`,`tsconfig.json 解析失败`);return}let x=Array.isArray(b.files)&&b.files.length===0,C=p(b.references);(!x||C.length===0||f(b,`include`).length>0)&&T(i,n,`R2`,`tsconfig.json`,`包根 tsconfig.json 须为 solution 形态——files 空数组、references 非空且不含 include,编译项归各分片`);let w=new Set(C);for(let e of y){let t=`tsconfig/${e}`;w.has(t)||T(i,n,`R3`,`tsconfig.json`,`分片 ${t} 未被根 tsconfig.json references 引用——C5,补引 { "path": "./${t}" }`)}for(let r of w)e(a(t,r))||T(i,n,`R3`,`tsconfig.json`,`references 指向不存在路径 ${r}——C5,移除悬空引用或补建目标`);N(n,b,`tsconfig.json`,t,i),H(t,n,y,v,i)}function V(e,t,n,r){if(!n){T(r,t,`R1`,`tsconfig.json`,`声明单一 tsconfig 豁免但缺失 tsconfig.json——ADR 0050 豁免以实有为前提`);return}let i=d(a(e,`tsconfig.json`));if(i===null){T(r,t,`R2`,`tsconfig.json`,`tsconfig.json 解析失败`);return}let o=f(i,`include`);E(t,i,`tsconfig.json`,``,r),D(t,o,e,`tsconfig.json`,``,r),O(t,i,`tsconfig.json`,`other`,null,r),N(t,i,`tsconfig.json`,e,r)}function H(e,t,n,r,i){for(let o of n){let n=d(a(e,`tsconfig`,o)),s=`tsconfig/${o}`;if(n===null){T(i,t,`R2`,s,`分片 ${s} 解析失败`);continue}let c=C(o);c!==`other`&&E(t,n,s,`../`,i),o===`node.json`&&D(t,f(n,`include`),e,s,`../`,i),O(t,n,s,c,r,i),N(t,n,s,e,i)}}function U(t,n,r,i){let o=S(a(t,`tsconfig`));for(let e of o)e!==`node.json`&&T(i,`.`,`R3`,`tsconfig/${e}`,`模块根 tsconfig 目录仅允许 node.json——ADR 0011,发现 ${e}`);let s=a(t,`tsconfig.json`),c=a(t,`tsconfig`,`node.json`);if(e(s)?W(t,n,r,i):T(i,`.`,`R3`,`tsconfig.json`,`模块根缺失溶液根 tsconfig.json——ADR 0011,补建 files 空数组加 references 形态`),e(c)){let e=d(c);e===null?T(i,`.`,`R2`,`tsconfig/node.json`,`根 node 片解析失败`):(E(`.`,e,`tsconfig/node.json`,`../`,i),D(`.`,f(e,`include`),t,`tsconfig/node.json`,`../`,i),O(`.`,e,`tsconfig/node.json`,`node`,null,i),r.moduleRootPaths===void 0&&P(e,`tsconfig/node.json`,t,n.map(e=>a(t,e)),i))}else x(t).length>0&&T(i,`.`,`R4`,`tsconfig/node.json`,`模块根缺失 tsconfig/node.json,根配置文件零类型检查覆盖——C6,照标准模板补建`)}function W(t,n,r,i){let o=d(a(t,`tsconfig.json`));if(o===null){T(i,`.`,`R2`,`tsconfig.json`,`模块根 tsconfig.json 解析失败`);return}r.moduleRootPaths===void 0&&P(o,`tsconfig.json`,t,n.map(e=>a(t,e)),i),(!(Array.isArray(o.files)&&o.files.length===0)||f(o,`include`).length>0)&&T(i,`.`,`R2`,`tsconfig.json`,`模块根 tsconfig.json 须为 files 空数组且不含 include——编译项归子包分片`);let s=p(o.references),c=new Set(s);s.length===0&&T(i,`.`,`R2`,`tsconfig.json`,`模块根 tsconfig.json references 为空——须引用自身 node 片与子包`);for(let n of c)n!==`tsconfig/node.json`&&(n.startsWith(`tsconfig/`)?T(i,`.`,`R3`,`tsconfig.json`,`模块根 references 引用了 node 片以外的 ${n}——ADR 0011 只准引 node 片与子包`):e(a(t,n))||T(i,`.`,`R3`,`tsconfig.json`,`模块根 references 指向不存在路径 ${n}——C5`));e(a(t,`tsconfig`,`node.json`))&&!c.has(`tsconfig/node.json`)&&T(i,`.`,`R3`,`tsconfig.json`,`根 node 片未被模块根 references 引用——C5,补引 { "path": "./tsconfig/node.json" }`);for(let r of n)e(a(t,r,`tsconfig.json`))&&!c.has(r)&&!c.has(`${r}/tsconfig.json`)&&T(i,`.`,`R3`,`tsconfig.json`,`仓根溶液 references 缺引单元 ${r}——C5,补引 { "path": "./${r}" }`)}function G(e){let t=[],n=z(e.rootDir);if(n.length===0)return K(e,t);let r=I(e.rootDir,n),i=new Set(e.config.exclude??[]),o=r.filter(e=>!i.has(e));U(e.rootDir,o,e.config,t);for(let n of o)B(a(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 K(t,n){return e(a(t.rootDir,`tsconfig.json`))?(B(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{I as expandWorkspaceUnits,G 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.3",
|
|
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.3"
|
|
36
36
|
}
|
|
37
37
|
}
|