mejora 3.0.1 → 3.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.mjs +3 -3
- package/dist/run.mjs +18 -18
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{t as e}from"./config-C0qrgNuO.mjs";import{a as t,c as n,i as r,o as i,s as a,t as o}from"./hash-BaLFZO2A.mjs";import{glob as s,mkdir as c,readFile as l,stat as u,writeFile as d}from"node:fs/promises";import{createReadStream as f}from"node:fs";import{createInterface as p}from"node:readline/promises";function m(e){let{defaults:t,type:n}=e,r=()=>{let t={async run(t){let{type:n,...r}=t;return{items:await e.run(r),type:`items`}},type:n};return e.setup&&(t.setup=e.setup),e.validate&&(t.validate=e.validate),t};return e=>{let{name:i,...a}=e;return{__runnerFactory:r,config:{type:n,...t,...a},id:i}}}function h(){let e=new WeakSet;return(t,n)=>{if(n&&typeof n==`object`){if(e.has(n))return`[Circular]`;if(e.add(n),!Array.isArray(n)){let e=n,t={};for(let n of Object.keys(e).toSorted()){let r=e[n];typeof r==`function`||typeof r==`symbol`||(t[n]=r)}return t}}return n}}function g(e){return o(JSON.stringify(e??null,h()))}function _(e,t=process.cwd()){return a(t,`node_modules`,`.cache`,`mejora`,e)}async function v(e){try{let t=await l(e,`utf8`);return JSON.parse(t)}catch{return{}}}async function y(e,t){try{await d(e,JSON.stringify(t
|
|
2
|
-
`);throw TypeError(`Failed to read TypeScript config: ${e}`)}let x=l(y,d,p,e.compilerOptions),S=a(_(`typescript`,p),`${g({compilerOptions:e.compilerOptions??{},configPath:v,parsedOptions:x.options,typescriptVersion:f})}.tsbuildinfo`),C={...x.options,incremental:!0,noEmit:!0,skipLibCheck:x.options.skipLibCheck??!0,tsBuildInfoFile:S},w=t(C,d),T=w.writeFile.bind(w);w.writeFile=(e,t,...n)=>{a(e)===S&&T(e,t,...n)};let
|
|
3
|
-
`),n=`TS${e.code}`;if(e.file&&e.start!==void 0){let{character:r,line:a}=e.file.getLineAndCharacterOfPosition(e.start),o=i(p,e.file.fileName);M.push({column:r+1,file:o,line:a+1,message:
|
|
1
|
+
import{t as e}from"./config-C0qrgNuO.mjs";import{a as t,c as n,i as r,o as i,s as a,t as o}from"./hash-BaLFZO2A.mjs";import{glob as s,mkdir as c,readFile as l,stat as u,writeFile as d}from"node:fs/promises";import{createReadStream as f}from"node:fs";import{createInterface as p}from"node:readline/promises";function m(e){let{defaults:t,type:n}=e,r=()=>{let t={async run(t){let{type:n,...r}=t;return{items:await e.run(r),type:`items`}},type:n};return e.setup&&(t.setup=e.setup),e.validate&&(t.validate=e.validate),t};return e=>{let{name:i,...a}=e;return{__runnerFactory:r,config:{type:n,...t,...a},id:i}}}function h(){let e=new WeakSet;return(t,n)=>{if(n&&typeof n==`object`){if(e.has(n))return`[Circular]`;if(e.add(n),!Array.isArray(n)){let e=n,t={};for(let n of Object.keys(e).toSorted()){let r=e[n];typeof r==`function`||typeof r==`symbol`||(t[n]=r)}return t}}return n}}function g(e){return o(JSON.stringify(e??null,h()))}function _(e,t=process.cwd()){return a(t,`node_modules`,`.cache`,`mejora`,e)}async function v(e){try{let t=await l(e,`utf8`);return JSON.parse(t)}catch{return{}}}async function y(e,t){try{await d(e,JSON.stringify(t),`utf8`)}catch{}}async function b(e){try{let t=await u(e);return`${t.mtimeMs}-${t.size}`}catch{return null}}const x=m({async run(e){let{ESLint:t}=await import(`eslint`),n=process.cwd(),r=_(`eslint`,n),a=g(e),{concurrency:o,...s}=e,c=new Set;if(s.rules)for(let e of Object.keys(s.rules))c.add(e);let l=c.size>0,u=await new t({cache:!0,cacheLocation:`${r}/${a}.eslintcache`,overrideConfig:s,...!l&&{concurrency:o??`auto`},...l&&{ruleFilter:({ruleId:e})=>c.has(e)}}).lintFiles(s.files),d=[];for(let{filePath:e,messages:t}of u){let r=i(n,e);for(let{column:e,line:n,message:i,ruleId:a}of t)a&&d.push({column:e,file:r,line:n,message:i,rule:a})}return d},async setup(){let e=_(`eslint`,process.cwd()),{mkdir:t}=await import(`node:fs/promises`);await t(e,{recursive:!0})},type:`eslint`,async validate(){try{await import(`eslint`)}catch{throw Error(`eslint check requires "eslint" package to be installed. Run: npm install eslint`)}}}),S=[`**/node_modules/**`,`**/dist/**`,`**/.git/**`],C=/^([^*]+\/)/,w=/^\*\*\//;function T(e,t){if(t?.length)return t;let n=e.map(e=>C.exec(e)?.[1]).filter(e=>e!==void 0);return[...S,...n.flatMap(e=>S.map(t=>t.replace(w,e)))]}async function E(e,t,n){let r=Array.from({length:e.length}),i=0;return await Promise.all(Array.from({length:Math.min(t,e.length)},async()=>{for(;i<e.length;){let t=i++;r[t]=await n(e[t])}})),r}const D=m({async run(e){let n=process.cwd(),r=Array.isArray(e.files)?e.files:[e.files],i=T(r,e.ignore),a=await Promise.all(r.map(e=>Array.fromAsync(s(e,{cwd:n,exclude:i})))),o=[...new Set(a.flat())],c=e.patterns.map(({message:e,pattern:t,rule:n})=>{let r=t.flags.includes(`g`)?t.flags:`${t.flags}g`;return{message:e,regex:new RegExp(t.source,r),ruleText:n??t.source}}),l=t(_(`regex`,n),`${g(e)}.json`),u=await v(l),d={},m=(await E(o,e.concurrency??10,async e=>{let r=t(n,e),i=await b(r);if(!i)return[];let a=u[e];if(a?.hash===i)return d[e]=a,a.items;try{let t=[],n=p({crlfDelay:1/0,input:f(r,{encoding:`utf8`})}),a=0;try{for await(let r of n){a++;for(let n of c){n.regex.lastIndex=0;let i;for(;(i=n.regex.exec(r))!==null;){let r=i.index+1,o=typeof n.message==`function`?n.message(i):n.message??`Pattern matched: ${i[0]}`;t.push({column:r,file:e,line:a,message:o,rule:n.ruleText})}}}}finally{n.close()}return d[e]={hash:i,items:t},t}catch{return[]}})).flat();return await y(l,d),m},async setup(){await c(_(`regex`,process.cwd()),{recursive:!0})},type:`regex`}),O=/import\("([^"]+)"\)/g;function k(e,t){return e.replaceAll(O,(e,n)=>{try{if(r(n)){let e=i(t,n);if(!e.startsWith(`..`))return`import("${e||`.`}")`}}catch{}return e})}const A=m({async run(e){let{createIncrementalCompilerHost:t,createIncrementalProgram:r,findConfigFile:o,flattenDiagnosticMessageText:s,getPreEmitDiagnostics:c,parseJsonConfigFileContent:l,readConfigFile:u,sys:d,version:f}=await import(`typescript`),p=process.cwd(),m=d.fileExists.bind(d),h=d.readFile.bind(d),v=e.tsconfig?a(e.tsconfig):o(p,m,`tsconfig.json`);if(!v)throw Error(`TypeScript config file not found`);let{config:y,error:b}=u(v,h);if(b){let e=typeof b.messageText==`string`?b.messageText:s(b.messageText,`
|
|
2
|
+
`);throw TypeError(`Failed to read TypeScript config: ${e}`)}let x=l(y,d,p,e.compilerOptions),S=a(_(`typescript`,p),`${g({compilerOptions:e.compilerOptions??{},configPath:v,parsedOptions:x.options,typescriptVersion:f})}.tsbuildinfo`),C={...x.options,incremental:!0,noEmit:!0,skipLibCheck:x.options.skipLibCheck??!0,tsBuildInfoFile:S},w=t(C,d),T=w.writeFile.bind(w);w.writeFile=(e,t,...n)=>{a(e)===S&&T(e,t,...n)};let E=r({host:w,options:C,projectReferences:x.projectReferences??[],rootNames:x.fileNames}),D=c(E.getProgram());E.emit();let O=a(p),A=O+n,j=D.filter(e=>{if(!e.file)return!0;let t=a(e.file.fileName);return t===O||t.startsWith(A)}),M=[];for(let e of j){let t=s(e.messageText,`
|
|
3
|
+
`),n=`TS${e.code}`;if(e.file&&e.start!==void 0){let{character:r,line:a}=e.file.getLineAndCharacterOfPosition(e.start),o=i(p,e.file.fileName);M.push({column:r+1,file:o,line:a+1,message:k(t,p),rule:n})}else M.push({column:0,file:`(global)`,line:0,message:k(t,p),rule:n})}return M},async setup(){let e=_(`typescript`,process.cwd()),{mkdir:t}=await import(`node:fs/promises`);await t(e,{recursive:!0})},type:`typescript`,async validate(){try{await import(`typescript`)}catch{throw Error(`typescript check requires "typescript" package to be installed. Run: npm install typescript`)}}});export{m as defineCheck,e as defineConfig,x as eslint,D as regex,A as typescript};
|
package/dist/run.mjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{n as e}from"./config-C0qrgNuO.mjs";import{n as t,o as n,r,t as i}from"./hash-BaLFZO2A.mjs";import{t as a}from"./check-registry-mjn8FfPF.mjs";import{fileURLToPath as o}from"node:url";import{mkdir as s,readFile as c,writeFile as l}from"node:fs/promises";import{inspect as u,parseArgs as d,styleText as f}from"node:util";import{Worker as p}from"node:worker_threads";import{env as m}from"node:process";const h=e=>t=>f(e,typeof t==`number`?t.toString():t),g=h(`blue`),_=h(`bold`),
|
|
3
|
-
`).slice(1).map(e=>
|
|
2
|
+
import{n as e}from"./config-C0qrgNuO.mjs";import{n as t,o as n,r,t as i}from"./hash-BaLFZO2A.mjs";import{t as a}from"./check-registry-mjn8FfPF.mjs";import{fileURLToPath as o}from"node:url";import{mkdir as s,readFile as c,writeFile as l}from"node:fs/promises";import{inspect as u,parseArgs as d,styleText as f}from"node:util";import{Worker as p}from"node:worker_threads";import{env as m}from"node:process";const h=e=>t=>f(e,typeof t==`number`?t.toString():t),g=h(`blue`),_=h(`bold`),ee=h(`cyan`),v=h(`dim`),y=h(`green`),b=h(`red`),x=h(`gray`),S=h(`underline`),te=h(`yellow`);function ne(e){let t=[e.message];if(e.stack){let n=e.stack.split(`
|
|
3
|
+
`).slice(1).map(e=>v(e.trim())).join(`
|
|
4
4
|
`);t.push(n)}return t.join(`
|
|
5
|
-
`)}function C(...e){return e.map(e=>typeof e==`string`?e:e instanceof Error?ne(e):u(e,{colors:!1,depth:10})).join(` `)}const w={error:(...e)=>{console.error(
|
|
6
|
-
`)}function
|
|
7
|
-
`)}function
|
|
8
|
-
`);let o=
|
|
9
|
-
`)}function
|
|
5
|
+
`)}function C(...e){return e.map(e=>typeof e==`string`?e:e instanceof Error?ne(e):u(e,{colors:!1,depth:10})).join(` `)}const w={error:(...e)=>{console.error(b(`✖`),C(...e))},log:(...e)=>{console.log(C(...e))},start:(...e)=>{console.log(ee(`◐`),C(...e))},success:(...e)=>{console.log(y(`✔`),C(...e))}};function T(e,t){return e.file===t.file?e.line===t.line?e.column-t.column:e.line-t.line:e.file<t.file?-1:1}function re(e){return`${e.file} - ${e.rule}: ${e.message}`}function ie(e){let t=Map.groupBy(e,re),n=[];for(let[e,r]of t){r.sort(T);for(let[t,a]of r.entries())n.push({...a,id:i(`${e}:${t}`)})}return n}function E(e){return{items:ie(e.items).toSorted(T),type:`items`}}function D(e,t){return e===1?t:`${t}s`}const O=`__unparsable__`,k={"<":`<`,">":`>`,"[":`[`,"]":`]`},A=/[<>[\]]/g;function j(e){return e.replaceAll(A,e=>k[e])}function M(e,t,r){let i=n(t,e);return r?`${i}#L${r}`:i}function N(e,t){return`[${e}](${t})`}function ae(e,t){let n=M(e.file,t,e.line);return`- ${N(e.line?`Line ${e.line}`:e.file,n)} - ${`${e.rule}: ${j(e.message)}`}`}function oe(e){let t=Object.groupBy(e,e=>e.file||O);return Object.entries(t).map(([e,t=[]])=>({filePath:e,items:t})).toSorted((e,t)=>e.filePath===O?1:t.filePath===O||e.filePath<t.filePath?-1:e.filePath>t.filePath?1:0)}function se(e,t){let n=e.length,r=D(n,`issue`),i=[`\n### Other Issues · ${t}\n`];for(let t of e)i.push(`- ${t.rule}: ${j(t.message)}`);return i.push(`\n${n} ${r} in Other Issues`,``),i.join(`
|
|
6
|
+
`)}function ce(e,t,n){if(e.filePath===O)return se(e.items,n);let r=M(e.filePath,t),i=N(e.filePath,r),a=e.items.length,o=D(a,`issue`),s=[`\n### ${i} · ${n}\n`];for(let n of e.items)s.push(ae(n,t));return s.push(`\n${a} ${o} in ${e.filePath}`,``),s.join(`
|
|
7
|
+
`)}function le(e,t,n){let r=t.length,i=D(r,`issue`),a=[`\n## ${e}\n`];if(t.length===0)return a.push(`No issues`),a.join(`
|
|
8
|
+
`);let o=oe(t);for(let t of o)a.push(ce(t,n,e));return a.push(`---\n${r} total ${i} for ${e}`),a.join(`
|
|
9
|
+
`)}function ue(e){return`${e.replaceAll(/\n{3,}/g,`
|
|
10
10
|
|
|
11
|
-
`).trimEnd()}\n`}function
|
|
11
|
+
`).trimEnd()}\n`}function P(e,t){let n=[`<!-- prettier-ignore-start -->
|
|
12
12
|
`,`# Mejora Baseline
|
|
13
|
-
`,`This file represents the current accepted state of the codebase.`];for(let[r,{items:i=[]}]of Object.entries(e.checks))n.push(
|
|
14
|
-
<!-- prettier-ignore-end -->`),
|
|
15
|
-
`))}const
|
|
16
|
-
}`.repeat(t)}`}function
|
|
13
|
+
`,`This file represents the current accepted state of the codebase.`];for(let[r,{items:i=[]}]of Object.entries(e.checks))n.push(le(r,i,t));return n.push(`
|
|
14
|
+
<!-- prettier-ignore-end -->`),ue(n.join(`
|
|
15
|
+
`))}const de=[`CI`,`CONTINUOUS_INTEGRATION`].some(e=>m[e]&&m[e]!==`0`&&m[e]!==`false`),F=(e,t)=>e.id<t.id?-1:e.id>t.id?1:0;function fe(){return{hasImprovement:!1,hasRegression:!1,hasRelocation:!1,isInitial:!0,newIssues:[],removedIssues:[]}}function pe(e,t,n){return{hasImprovement:t.length>0,hasRegression:e.length>0,hasRelocation:n,isInitial:!1,newIssues:e.toSorted(F),removedIssues:t.toSorted(F)}}function I(e=[]){return new Map(e.map(e=>[e.id,e]))}function L(e){return new Set(e.keys())}function R(e,t){let n=[];for(let r of t){let t=e.get(r);n.push(t)}return n}function z(e,t){for(let[n,r]of e){let e=t.get(n);if(e&&(r.line!==e.line||r.column!==e.column))return!0}return!1}function B(e,t){let n=I(e.items),r=I(t.items),i=L(n),a=L(r),o=i.difference(a),s=a.difference(i);return pe(R(n,o),R(r,s),i.size>o.size?z(n,r):!1)}function V(e,t){return t?B(e,t):fe()}const H=(e,t)=>{if(!t)return!1;let n=e.items,r=t.items;if(n.length!==r.length)return!1;let i=n.toSorted(F),a=r.toSorted(F);return i.every((e,t)=>{let n=a[t];return e.id===n.id&&e.file===n.file&&e.line===n.line&&e.column===n.column&&e.rule===n.rule&&e.message===n.message})};function me(e,t){let n=e;for(let e=0;e<t;e++){let e=n.trimEnd();if(!e.endsWith(`}`))break;n=e.slice(0,-1)}return n}function he(e,t){return`${e}${`
|
|
16
|
+
}`.repeat(t)}`}function ge(e){let t=(e.match(/\{/g)?.length??0)-(e.match(/\}/g)?.length??0);return t===0?e:t<0?me(e,-t):he(e,t)}function _e(e){try{return JSON.parse(e)}catch{return}}function U(e){let t=e.trim();return t.endsWith(`,`)?t.slice(0,-1):t}function ve(e){return`{
|
|
17
17
|
"version": 2,
|
|
18
18
|
${U(e)}
|
|
19
|
-
}`}function W(e){if(typeof e!=`object`||!e)throw TypeError(`Baseline must be an object`);if(`checks`in e&&e.checks&&typeof e.checks==`object`)return{checks:e.checks,version:2};let t={};for(let[n,r]of Object.entries(e))n!==`version`&&(t[n]=r);return{checks:t,version:2}}function G(e){try{let t=
|
|
20
|
-
`,r=e.snapshot.items.length,i=[`${n}${g(`ℹ`)} ${e.checkId}:`,` Initial baseline created with ${g(r)} ${D(r,`issue`)}`];return e.snapshot.items.length>0&&i.push(...X(e.snapshot.items,`initial`)),i.push(``,...
|
|
21
|
-
`}${e.hasRegression?
|
|
22
|
-
`,r=e.snapshot.items.length;return e.duration===void 0?[`${n}${
|
|
23
|
-
`)}function
|
|
19
|
+
}`}function W(e){if(typeof e!=`object`||!e)throw TypeError(`Baseline must be an object`);if(`checks`in e&&e.checks&&typeof e.checks==`object`)return{checks:e.checks,version:2};let t={};for(let[n,r]of Object.entries(e))n!==`version`&&(t[n]=r);return{checks:t,version:2}}function G(e){try{let t=_e(e.trim());if(t)return W(t);let n=ve(ge(U(e)));return W(JSON.parse(n))}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Failed to parse baseline during conflict resolution: ${t}`,{cause:e})}}function ye(e){let t=[...e.matchAll(/<<<<<<< .*\n([\s\S]*?)\n=======\n([\s\S]*?)\n>>>>>>> .*$/gm)];if(t.length===0)throw Error(`Could not parse conflict markers in baseline`);return t.map(([,e=``,t=``])=>({ours:e,theirs:t}))}function be(e){let t=new Map;for(let n of e)for(let[e,{items:r=[]}]of Object.entries(n.checks)){if(r.length===0)continue;let n=t.get(e);n||(n=new Map,t.set(e,n));for(let e of r)n.set(e.id,e)}let n={};for(let[e,r]of t)n[e]={items:[...r.values()].toSorted(F),type:`items`};return{checks:n,version:2}}function xe(e){let t=ye(e),n=[];for(let{ours:e,theirs:r}of t)n.push(G(e),G(r));return be(n)}var K=class e{baselineDir;baselinePath;mdPath;constructor(e=`.mejora/baseline.json`){this.baselinePath=e,this.baselineDir=r(e),this.mdPath=e.replace(/\.json$/,`.md`)}static batchUpdate(t,n){let r=t??e.create({}),i={...r.checks},a=!1;for(let{checkId:e,entry:t}of n)H(t,r.checks[e])||(i[e]=t,a=!0);return a?{...r,checks:i}:r}static create(e){return{checks:e,version:2}}static getEntry(e,t){return e?.checks[t]}static update(t,n,r){let i=t??e.create({}),a=i.checks[n];return H(r,a)?i:{...i,checks:{...i.checks,[n]:r}}}async load(){try{let e=await c(this.baselinePath,`utf8`);if(e.includes(`<<<<<<<`)){w.start(`Merge conflict detected in baseline, auto-resolving...`);let t=xe(e);return await this.save(t,!0),w.success(`Baseline conflict resolved`),t}let t=JSON.parse(e);return await this.resolveMarkdownConflictIfNeeded(t),t}catch(e){if(e.code===`ENOENT`)return null;throw e}}async save(e,t=!1){if(de&&!t)return;let n=`${JSON.stringify(e,null,2)}\n`,r=P(e,this.baselineDir);await s(this.baselineDir,{recursive:!0}),await Promise.all([l(this.baselinePath,n,`utf8`),l(this.mdPath,r,`utf8`)])}async resolveMarkdownConflictIfNeeded(e){try{if((await c(this.mdPath,`utf8`)).includes(`<<<<<<<`)){w.start(`Merge conflict detected in markdown report, regenerating...`);let t=P(e,this.baselineDir);await l(this.mdPath,t,`utf8`),w.success(`Markdown report regenerated`)}}catch{}}};const Se=o(new URL(`workers/check.mjs`,import.meta.url));var Ce=class e{baselineManager;registry;constructor(e,t){this.registry=e,this.baselineManager=new K(t)}static async executeChecksParallel(t,n){try{let r=t.map(async t=>{let r=await e.executeWorker(t.id),i=E(r.snapshot),a=K.getEntry(n,t.id),o=V(i,a);return{baseline:a,checkId:t.id,duration:r.duration,hasImprovement:o.hasImprovement,hasRegression:o.hasRegression,hasRelocation:o.hasRelocation,isInitial:o.isInitial,newIssues:o.newIssues,removedIssues:o.removedIssues,snapshot:i}});return await Promise.all(r)}catch(e){return w.error(`Parallel execution failed:`,e),null}}static async executeWorker(e){return new Promise((t,n)=>{let r=new p(Se,{workerData:{checkId:e}});r.on(`message`,t),r.on(`error`,n),r.on(`exit`,e=>{e!==0&&n(Error(`Worker stopped with exit code ${e}`))})})}static filterChecks=(t,n)=>{let r=n.only?e.resolveRegex(n.only,`--only`):null,i=n.skip?e.resolveRegex(n.skip,`--skip`):null;return!r&&!i?t:t.filter(e=>!(r&&!r.test(e.id)||i?.test(e.id)))};static resolveRegex(e,t){try{return new RegExp(e)}catch{throw Error(`Invalid regex pattern for ${t}: "${e}"`)}}async run(t,n={}){let r=performance.now(),i=await this.baselineManager.load(),a=e.filterChecks(t.checks,n),o=a.length;w.start(`Running ${o} check${o===1?``:`s`}...`);let s=o>1?await e.executeChecksParallel(a,i):await this.executeChecksSequential(a,i);if(!s)return{exitCode:2,hasImprovement:!1,hasRegression:!0,results:[],totalDuration:performance.now()-r};let c=!1,l=!1,u=!1,d=[];for(let e of s)e.hasRegression&&(c=!0),e.hasImprovement&&(l=!0),e.isInitial&&(u=!0),(e.hasImprovement||e.hasRelocation||n.force||e.isInitial)&&d.push({checkId:e.checkId,entry:{items:e.snapshot.items,type:e.snapshot.type}});if(d.length>0){let e=K.batchUpdate(i,d);e!==i&&(!c||n.force||u)&&await this.baselineManager.save(e,n.force)}return{exitCode:c&&!n.force?1:0,hasImprovement:l,hasRegression:c,results:s,totalDuration:performance.now()-r}}async executeChecksSequential(e,t){try{let t=a.getRequiredTypes(e);await Promise.all([this.registry.setup(t),this.registry.validate(t)])}catch(e){return w.error(`Setup failed:`,e),null}let n=[];for(let r of e)try{let e=performance.now(),i=await this.registry.get(r.config.type).run(r.config),a=performance.now()-e,o=E(i),s=K.getEntry(t,r.id),c=V(o,s);n.push({baseline:s,checkId:r.id,duration:a,hasImprovement:c.hasImprovement,hasRegression:c.hasRegression,hasRelocation:c.hasRelocation,isInitial:c.isInitial,newIssues:c.newIssues,removedIssues:c.removedIssues,snapshot:o})}catch(e){return w.error(`Error running check "${r.id}":`,e),null}return n}};function q(e,t){if(!(e===void 0||t===0))return e/t}function we(e){let{results:t,totalDuration:n}=e,r=t.length,i=[],a=[],o=[],s=[],c=0,l=0,u=0,d=0,f=0,p=[];for(let e of t){let t=e.snapshot.items.length;f+=t,e.isInitial?(u+=t,o.push(e.checkId)):(e.hasImprovement&&(c+=e.removedIssues.length,i.push(e.checkId)),e.hasRegression&&(l+=e.newIssues.length,a.push(e.checkId)),!e.hasImprovement&&!e.hasRegression&&(d+=t,s.push(e.checkId))),p.push({checkId:e.checkId,duration:e.duration,hasImprovement:e.hasImprovement,hasRegression:e.hasRegression,isInitial:e.isInitial,newIssues:e.newIssues,removedIssues:e.removedIssues,totalIssues:t})}let m={checks:p,exitCode:e.exitCode,hasImprovement:e.hasImprovement,hasRegression:e.hasRegression,summary:{avgDuration:q(n,r),checksRun:r,improvementChecks:i,improvements:c,initial:u,initialChecks:o,regressionChecks:a,regressions:l,totalIssues:f,unchanged:d,unchangedChecks:s},totalDuration:n};return JSON.stringify(m,null,2)}function Te(e){if(e<1e3)return`${e}ms`;let t=e/1e3;if(t<60)return t%1==0?`${t}s`:`${t.toFixed(1)}s`;let n=e/6e4;if(n<60)return n%1==0?`${n}m`:`${n.toFixed(1)}m`;let r=e/36e5;return r%1==0?`${r}h`:`${r.toFixed(1)}h`}function J(e){let t=Math.round(e);return t<1?`<1ms`:Te(t)}const Y=` `,Ee=`${Y} `;function De(e){return e===`initial`?v(`→`):e===`improvement`?y(`↑`):b(`↓`)}function Oe(e,n,i){let a=r(e),o=t(e),s=n>0?`:${n}:${i>0?i:1}`:``;return`${a===`.`?``:v(`${a}/`)}${S(o)}${s?v(s):``}`}function ke(e,t){return[`${De(t)} ${Oe(e.file,e.line,e.column)} ${v(e.rule)}`,e.message]}function X(e,t){let n=[],r=e.slice(0,10);for(let e of r){let[r,i]=ke(e,t);n.push(`${Y}${r}`,`${Ee}${i}`)}let i=e.length-r.length;return i>0&&n.push(`${Y}${v(`... and ${i} more`)}`),n}function Z(e){return e===void 0?[]:[` ${v(`Duration`)} ${J(e)}`]}function Ae(e){return[` ${v(`Issues`)} ${_(e)}`]}function Q(e){return[...Z(e.duration),...Ae(e.snapshot.items.length)]}function je(e){if(!e.hasRegression)return[];let t=e.newIssues.length;return[` ${b(t)} new ${D(t,`issue`)} (${D(t,`regression`)}):`,...X(e.newIssues,`regression`)]}function Me(e){if(!e.hasImprovement)return[];let t=e.removedIssues.length;return[` ${y(t)} ${D(t,`issue`)} fixed (${D(t,`improvement`)}):`,...X(e.removedIssues,`improvement`)]}function Ne(e,t){let n=t?``:`
|
|
20
|
+
`,r=e.snapshot.items.length,i=[`${n}${g(`ℹ`)} ${e.checkId}:`,` Initial baseline created with ${g(r)} ${D(r,`issue`)}`];return e.snapshot.items.length>0&&i.push(...X(e.snapshot.items,`initial`)),i.push(``,...Q(e)),i}function Pe(e,t){return[`${t?``:`
|
|
21
|
+
`}${e.hasRegression?b(`✖`):y(`✔`)} ${e.checkId}:`,...je(e),...Me(e),``,...Q(e)]}function Fe(e,t){let n=t?``:`
|
|
22
|
+
`,r=e.snapshot.items.length;return e.duration===void 0?[`${n}${x(`ℹ`)} ${e.checkId} (${_(r)})`]:[`${n}${x(`ℹ`)} ${e.checkId} (${_(r)}) ${v(J(e.duration))}`]}function Ie(e,t){return e.isInitial?Ne(e,t):e.hasRegression||e.hasImprovement?Pe(e,t):Fe(e,t)}function Le(e,t,n){return t?g(`✔ Initial baseline created successfully`):e.hasRegression?n?te(`⚠ Regressions detected (forced)`):`${b(`✗ Regressions detected`)} - Run failed`:e.hasImprovement?`${y(`✔ Improvements detected`)} - Baseline updated`:y(`✔ All checks passed`)}function Re(e,t){let n={hasAnyInitial:!1,totalImprovements:0,totalInitial:0,totalIssues:0,totalRegressions:0};for(let t of e.results){let e=t.snapshot.items.length;if(n.totalIssues+=e,t.isInitial){n.hasAnyInitial=!0,n.totalInitial+=e;continue}let{hasImprovement:r,hasRegression:i}=t;r&&(n.totalImprovements+=t.removedIssues.length),i&&(n.totalRegressions+=t.newIssues.length)}let r=[` ${v(`Improvements`)} ${y(n.totalImprovements)}`,` ${v(`Regressions`)} ${b(n.totalRegressions)}`,` ${v(`Initial`)} ${g(n.totalInitial)}`,` ${v(`Checks`)} ${e.results.length}`,` ${v(`Issues`)} ${_(n.totalIssues)}`],i=q(e.totalDuration,e.results.length);return e.totalDuration!==void 0&&i!==void 0&&r.push(` ${v(`Duration`)} ${J(e.totalDuration)} ${x(`(avg ${J(i)})`)}`),r.push(``,Le(e,n.hasAnyInitial,t)),r.join(`
|
|
23
|
+
`)}function ze(e,t){let n=[];for(let[t,r]of e.results.entries())n.push(...Ie(r,t===0));return n.length>0&&n.push(``),n.push(Re(e,t)),n.join(`
|
|
24
24
|
`)}const{values:$}=d({allowPositionals:!1,options:{force:{default:!1,short:`f`,type:`boolean`},help:{short:`h`,type:`boolean`},json:{default:!1,type:`boolean`},only:{type:`string`},skip:{type:`string`}},strict:!0});$.help&&(w.log(`
|
|
25
25
|
mejora - Prevent regressions by allowing only improvement
|
|
26
26
|
|
|
@@ -40,4 +40,4 @@ Examples:
|
|
|
40
40
|
mejora --json
|
|
41
41
|
mejora --only "eslint > *"
|
|
42
42
|
mejora --skip typescript
|
|
43
|
-
`),process.exit(0));try{let t=new a,n=await e();t.init(n);let r=await new
|
|
43
|
+
`),process.exit(0));try{let t=new a,n=await e();t.init(n);let r=await new Ce(t).run(n,{force:$.force,json:$.json,only:$.only,skip:$.skip});$.json?w.log(we(r)):(w.log(``),w.log(ze(r,$.force))),process.exit(r.exitCode)}catch(e){e instanceof Error?w.error(e.message):w.error(e),process.exit(2)}export{};
|