mejora 1.3.0 → 1.4.0
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/run.mjs +7 -6
- package/package.json +1 -1
package/dist/run.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as e,c as t,n,r,s as i}from"./config-c3IzQqLC.mjs";import{dirname as a,relative as o}from"node:path";import*as s from"node:util";import{inspect as c,parseArgs as l,styleText as u}from"node:util";import{mkdir as d,readFile as f,writeFile as p}from"node:fs/promises";import{env as m}from"node:process";const h=e=>u(`blue`,e),g=e=>u(`
|
|
3
|
-
`}${
|
|
4
|
-
`}${
|
|
2
|
+
import{a as e,c as t,n,r,s as i}from"./config-c3IzQqLC.mjs";import{dirname as a,relative as o}from"node:path";import*as s from"node:util";import{inspect as c,parseArgs as l,styleText as u}from"node:util";import{mkdir as d,readFile as f,writeFile as p}from"node:fs/promises";import{env as m}from"node:process";const h=e=>u(`blue`,e),g=e=>u(`cyan`,e),_=e=>u(`dim`,e),v=e=>u(`green`,e),y=e=>u(`red`,e),ee=e=>u(`bgRed`,e),b=e=>u(`yellow`,e),x=e=>u(`black`,e);function S(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 C(e){let t=Math.round(e);if(t<1)return _(`<1ms`);let n=S(t);return t<100?v(n):t<1e3?b(n):y(n)}function w(e){return e.reduce((e,t)=>e+t.snapshot.items.length,0)}function T(e){let t=[],n=[],r=[],i=[];for(let a of e)a.isInitial?i.push(a):(a.hasImprovement&&t.push(a),a.hasRegression&&n.push(a),!a.hasImprovement&&!a.hasRegression&&r.push(a));return{improvements:t,initial:i,regressions:n,unchanged:r}}function E(e){let{improvements:t,initial:n,regressions:r,unchanged:i}=T(e.results),a=w(e.results),o=e.totalDuration!==void 0&&e.results.length>0?e.totalDuration/e.results.length:void 0,s={checks:e.results.map(e=>({checkId:e.checkId,duration:e.duration,hasImprovement:e.hasImprovement,hasRegression:e.hasRegression,isInitial:e.isInitial,newItems:e.newItems,removedItems:e.removedItems,totalIssues:e.snapshot.items.length||0})),exitCode:e.exitCode,hasImprovement:e.hasImprovement,hasRegression:e.hasRegression,summary:{avgDuration:o,checksRun:e.results.length,improvementChecks:t.map(e=>e.checkId),improvements:t.length,initial:n.length,initialChecks:n.map(e=>e.checkId),regressionChecks:r.map(e=>e.checkId),regressions:r.length,totalIssues:a,unchanged:i.length,unchangedChecks:i.map(e=>e.checkId)},totalDuration:e.totalDuration};return JSON.stringify(s,null,2)}function D(e,t=10){let n=[],r=e.slice(0,t);for(let e of r)n.push(` ${_(e)}`);let i=e.length-t;return i>0&&n.push(` ${_(`... and ${i} more`)}`),n}function O(e,t){let n=[`${t?``:`
|
|
3
|
+
`}${e.checkId}:`,` Initial baseline created with ${g(e.snapshot.items.length.toString())} issue(s)`];e.snapshot.items.length>0&&n.push(...D(e.snapshot.items)),e.duration!==void 0&&n.push(` Duration ${C(e.duration)}`);let r=`${e.snapshot.items.length}`;return n.push(` Issues ${r}`),n}function k(e){return e.hasRegression?[` ${y(e.newItems.length.toString())} new issue(s) (regressions):`,...D(e.newItems)]:[]}function A(e){return e.hasImprovement?[` ${v(e.removedItems.length.toString())} issue(s) fixed (improvements):`,...D(e.removedItems)]:[]}function te(e,t){let n=[`${t?``:`
|
|
4
|
+
`}${e.checkId}:`,...k(e),...A(e)];e.duration!==void 0&&n.push(` Duration ${C(e.duration)}`);let r=`${e.snapshot.items.length}`;return n.push(` Issues ${r}`),n}function ne(e,t){let n=t?``:`
|
|
5
|
+
`,r=`${e.snapshot.items.length} issue${e.snapshot.items.length===1?``:`s`}`;if(e.duration!==void 0){let t=C(e.duration);return[`${n}${e.checkId} (${r}) ${t}`]}return[`${n}${e.checkId} (${r})`]}function re(e,t){return e.isInitial?O(e,t):e.hasRegression||e.hasImprovement?te(e,t):ne(e,t)}function ie(e){let t=e.results.some(e=>e.isInitial),{improvements:n,initial:r,regressions:i,unchanged:a}=T(e.results),o=[`Summary`,` Improvements ${n.length}`,` Regressions ${i.length}`,` Unchanged ${a.length}`,` Initial ${r.length}`,` Checks ${e.results.length}`],s=w(e.results);if(o.push(` Issues ${s}`),e.totalDuration!==void 0&&e.results.length>0){let t=e.totalDuration/e.results.length;o.push(` Duration ${C(e.totalDuration)} (avg ${C(t)})`)}return o.push(``),t?o.push(h(`✓ Initial baseline created successfully`)):e.hasRegression?o.push(`${y(`✗ Regressions detected`)} - Run failed`):e.hasImprovement?o.push(`${v(`✓ Improvements detected`)} - Baseline updated`):o.push(v(`✓ All checks passed`)),o.join(`
|
|
5
6
|
`)}function ae(e){let t=[];for(let n=0;n<e.results.length;n++){let r=e.results[n];t.push(...re(r,n===0))}return t.length>0&&t.push(``),t.push(ie(e)),t.join(`
|
|
6
7
|
`)}const oe=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`],j=`\x1B[?25h`,M=`\r\x1B[K`,N={succeed:`✔`,fail:`✖`,warn:`!`,info:`ℹ`},P={succeed:`green`,fail:`red`,warn:`yellow`,info:`blue`,spinner:`cyan`},F=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531],[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]],I=/(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F)(?:\u200d(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F))*/uy,L=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y,R=/\p{M}+/uy;function z(e,t){let n=0,r,i=t.length-1;if(e<t[0][0]||e>t[i][1])return!1;for(;i>=n;)if(r=Math.floor((n+i)/2),e>t[r][1])n=r+1;else if(e<t[r][0])i=r-1;else return!0;return!1}function B(e){return e===0||e<32||e>=127&&e<160||z(e,F)?0:e>=4352&&(e<=4447||e==9001||e==9002||e>=11904&&e<=42191&&e!=12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=131072&&e<=196605||e>=196608&&e<=262141)?2:1}function V(e){let t=0,n=0;for(let r=0;r<e.length;r++){if(n=e[r].charCodeAt(0),n>=32&&n<127){t++;continue}if(L.lastIndex=r,L.test(e)){r=L.lastIndex-1;continue}if(I.lastIndex=r,I.test(e)){r=I.lastIndex-1,t+=2;continue}if(R.lastIndex=r,R.test(e)){r=R.lastIndex-1;continue}t+=B(n)}return t}function H(e,t){let n=e.split(`
|
|
7
8
|
`).length;if(t===1/0)return n;for(let r of e.split(`
|
|
@@ -14,9 +15,9 @@ import{a as e,c as t,n,r,s as i}from"./config-c3IzQqLC.mjs";import{dirname as a,
|
|
|
14
15
|
`,r=Object.entries(e.checks);for(let e=0;e<r.length;e++){let[i,{items:a=[]}]=r[e],s=e===r.length-1;if(n+=`## ${i}\n\n`,a.length===0)n+=`No issues
|
|
15
16
|
`;else for(let e of a){let[r,...i]=e.split(` - `),a=r?.split(`:`),s=a?.[0],c=a?.[1];if(s){let e=o(t,s),a=c?`${e}#L${c}`:e,l=i.length>0?` - ${i.join(` - `)}`:``;n+=`- [${r}](${a})${l}\n`}}s||(n+=`
|
|
16
17
|
`)}return n}const ye=(e,t)=>{if(!t)return!1;let n=e.items??[],r=t.items??[];if(n.length!==r.length)return!1;let i=n.toSorted(),a=r.toSorted();return i.every((e,t)=>e===a[t])};function be(e){let t=[e.message];if(e.stack){let n=e.stack.split(`
|
|
17
|
-
`).slice(1).map(e=>
|
|
18
|
+
`).slice(1).map(e=>_(e.trim())).join(`
|
|
18
19
|
`);t.push(n)}return t.join(`
|
|
19
|
-
`)}function Y(...e){return e.map(e=>typeof e==`string`?e:e instanceof Error?be(e):c(e,{colors:!1,depth:10})).join(` `)}const X={error:(...e)=>{console.error(
|
|
20
|
+
`)}function Y(...e){return e.map(e=>typeof e==`string`?e:e instanceof Error?be(e):c(e,{colors:!1,depth:10})).join(` `)}const X={error:(...e)=>{console.error(ee(x(` ERROR `)),Y(...e))},log:(...e)=>{console.log(Y(...e))},start:(...e)=>{console.log(g(`◐`),Y(...e))},success:(...e)=>{console.log(v(`✔`),Y(...e))}};var Z=class e{baselinePath;constructor(e=`.mejora/baseline.json`){this.baselinePath=e}static create(e){return{checks:e,version:1}}static getEntry(e,t){return e?.checks[t]}static update(t,n,r){let i=t??e.create({}),a=i.checks[n];return ye(r,a)?i:{...i,checks:{...i.checks,[n]:r}}}async load(){try{let e=await f(this.baselinePath,`utf8`);if(e.includes(`<<<<<<<`)){X.start(`Merge conflict detected in baseline, auto-resolving...`);let t=_e(e);return await this.save(t,!0),X.success(`Baseline conflict resolved`),t}return JSON.parse(e)}catch(e){if(e.code===`ENOENT`)return null;throw e}}async save(e,t=!1){if(q&&!t)return;let n=`${JSON.stringify(e,null,2)}\n`,r=this.baselinePath.replace(`.json`,`.md`),i=ve(e,a(this.baselinePath));await d(a(this.baselinePath),{recursive:!0}),await Promise.all([p(this.baselinePath,n,`utf8`),p(r,i,`utf8`)])}};function xe(){return{hasImprovement:!1,hasRegression:!1,isInitial:!0,newItems:[],removedItems:[]}}function Se(e,t){return{hasImprovement:t.length>0,hasRegression:e.length>0,isInitial:!1,newItems:e.toSorted(),removedItems:t.toSorted()}}function Ce(e,t){let n=[];for(let r of e)t.has(r)||n.push(r);return n}function we(e,t){let n=[];for(let r of t)e.has(r)||n.push(r);return n}function Q(e,t){let n=new Set(e.items),r=new Set(t.items);return Se(Ce(n,r),we(n,r))}function Te(e,t){return t?Q(e,t):xe()}var Ee=class n{baselineManager;constructor(e){this.baselineManager=new Z(e)}static filterChecks(e,t){let r={...e};if(t.only){let e=n.resolveRegex(t.only,`--only`);r=Object.fromEntries(Object.entries(r).filter(([t])=>e.test(t)))}if(t.skip){let e=n.resolveRegex(t.skip,`--skip`);r=Object.fromEntries(Object.entries(r).filter(([t])=>!e.test(t)))}return r}static resolveRegex(e,t){try{return new RegExp(e)}catch{throw Error(`Invalid regex pattern for ${t}: "${e}"`)}}static async runCheck(n){return n.type===`eslint`?(await t(),i(n)):(await e(),r(n))}async run(e,t={}){let r=performance.now(),i=await this.baselineManager.load(),a=[],o=!1,s=!1,c=!1,l=i,u=n.filterChecks(e.checks,t);for(let[e,d]of Object.entries(u)){let u=t.json?null:new G(`Running ${e}...`);try{u?.start();let r=performance.now(),f=await n.runCheck(d),p=performance.now()-r,m=Z.getEntry(i,e),h=Te(f,m),g={baseline:m,checkId:e,duration:p,hasImprovement:h.hasImprovement,hasRegression:h.hasRegression,isInitial:h.isInitial,newItems:h.newItems,removedItems:h.removedItems,snapshot:f};a.push(g),h.hasRegression&&(o=!0),h.hasImprovement&&(s=!0),h.isInitial&&(c=!0),(h.hasImprovement||t.force||h.isInitial)&&(l=Z.update(l,e,{items:f.items,type:f.type})),u?.succeed(`${e} complete`)}catch(t){return u?.fail(`${e} failed`),X.error(`Error running check "${e}":`,t),{exitCode:2,hasImprovement:!1,hasRegression:!0,results:a,totalDuration:performance.now()-r}}}l&&l!==i&&(!o||t.force||c)&&await this.baselineManager.save(l,t.force);let d=0;o&&!t.force&&(d=1);let f=performance.now()-r;return{exitCode:d,hasImprovement:s,hasRegression:o,results:a,totalDuration:f}}};const{values:$}=l({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&&(X.log(`
|
|
20
21
|
mejora - Prevent regressions by allowing only improvement
|
|
21
22
|
|
|
22
23
|
Usage:
|
|
@@ -35,4 +36,4 @@ Examples:
|
|
|
35
36
|
mejora --json
|
|
36
37
|
mejora --only "eslint > *"
|
|
37
38
|
mejora --skip typescript
|
|
38
|
-
`),process.exit(0));try{let e=new Ee,t=await n(),r=await e.run(t,{force:$.force,json:$.json,only:$.only,skip:$.skip});$.json?X.log(
|
|
39
|
+
`),process.exit(0));try{let e=new Ee,t=await n(),r=await e.run(t,{force:$.force,json:$.json,only:$.only,skip:$.skip});$.json?X.log(E(r)):(X.log(``),X.log(ae(r))),process.exit(r.exitCode)}catch(e){e instanceof Error?X.error(e.message):X.error(e),process.exit(2)}export{};
|