mejora 2.3.6 → 2.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/README.md CHANGED
@@ -125,10 +125,9 @@ Create one of:
125
125
  Example:
126
126
 
127
127
  ```ts
128
- import { defineConfig, eslint, regex, regexRunner, typescript } from "mejora";
128
+ import { defineConfig, eslint, regex, typescript } from "mejora";
129
129
 
130
130
  export default defineConfig({
131
- runners: [regexRunner()],
132
131
  checks: {
133
132
  "eslint > no-nested-ternary": eslint({
134
133
  files: ["src/**/*.{ts,tsx,js,jsx}"],
@@ -0,0 +1 @@
1
+ import{o as e,r as t,t as n}from"./typescript-BG8_PZiP.mjs";var r=class{runners=new Map;static getRequiredTypes(e){return new Set(Object.values(e).map(e=>e.type))}get(e){let t=this.runners.get(e);if(!t)throw Error(`Unknown check type: ${e}`);return t}getTypes(){return new Set(this.runners.keys())}has(e){return this.runners.has(e)}init(r={}){if(this.register(new e),this.register(new n),this.register(new t),r.runners)for(let e of r.runners)this.register(e)}register(e){this.runners.has(e.type)||this.runners.set(e.type,e)}async setup(e){await this.runLifecycle(e,`setup`)}async validate(e){await this.runLifecycle(e,`validate`)}async runLifecycle(e,t){let n=[];for(let r of e){let e=this.get(r)[t]?.();e&&n.push(e)}await Promise.all(n)}};export{r as t};
@@ -340,6 +340,34 @@ declare function eslintCheck(config: ESLintCheckConfig): {
340
340
  type: "eslint";
341
341
  };
342
342
  //#endregion
343
+ //#region src/runners/regex.d.ts
344
+ /**
345
+ * Check runner for regex pattern matching.
346
+ */
347
+ declare class RegexCheckRunner implements CheckRunner {
348
+ readonly type = "regex";
349
+ run(config: RegexCheckConfig): Promise<{
350
+ items: IssueInput[];
351
+ type: "items";
352
+ }>;
353
+ setup(): Promise<void>;
354
+ }
355
+ declare const regexRunner: () => RegexCheckRunner;
356
+ /**
357
+ * Create a regex check configuration.
358
+ *
359
+ * @param config - Regex check configuration options.
360
+ *
361
+ * @returns A regex check configuration object.
362
+ */
363
+ declare function regexCheck(config: RegexCheckConfig): {
364
+ concurrency?: number;
365
+ files: string[];
366
+ ignore?: string[];
367
+ patterns: RegexPattern[];
368
+ type: "regex";
369
+ };
370
+ //#endregion
343
371
  //#region src/runners/typescript.d.ts
344
372
  /**
345
373
  * Check runner for TypeScript.
@@ -376,7 +404,7 @@ type ExtractConfig<TRunner> = TRunner extends CheckRunner<infer C> ? C : never;
376
404
  type CheckConfig<TRunners extends readonly CheckRunner[], TType extends TRunners[number]["type"]> = ExtractConfig<ExtractRunnerByType<TRunners, TType>> & {
377
405
  type: TType;
378
406
  };
379
- type InternalRunners = readonly [ESLintCheckRunner, TypeScriptCheckRunner];
407
+ type InternalRunners = readonly [ESLintCheckRunner, TypeScriptCheckRunner, RegexCheckRunner];
380
408
  /**
381
409
  * Define mejora configuration.
382
410
  *
@@ -396,32 +424,4 @@ declare function defineConfig<const TRunners extends readonly CheckRunner[]>(con
396
424
  runners?: TRunners;
397
425
  };
398
426
  //#endregion
399
- //#region src/runners/regex.d.ts
400
- /**
401
- * Check runner for regex pattern matching.
402
- */
403
- declare class RegexCheckRunner implements CheckRunner {
404
- readonly type = "regex";
405
- run(config: RegexCheckConfig): Promise<{
406
- items: IssueInput[];
407
- type: "items";
408
- }>;
409
- setup(): Promise<void>;
410
- }
411
- declare const regexRunner: () => RegexCheckRunner;
412
- /**
413
- * Create a regex check configuration.
414
- *
415
- * @param config - Regex check configuration options.
416
- *
417
- * @returns A regex check configuration object.
418
- */
419
- declare function regexCheck(config: RegexCheckConfig): {
420
- concurrency?: number;
421
- files: string[];
422
- ignore?: string[];
423
- patterns: RegexPattern[];
424
- type: "regex";
425
- };
426
- //#endregion
427
- export { eslintCheck as a, Issue as c, Snapshot as d, typescriptCheck as i, IssueInput as l, regexRunner as n, CheckRunner as o, defineConfig as r, Config as s, regexCheck as t, RawSnapshot as u };
427
+ export { eslintCheck as a, Issue as c, Snapshot as d, regexRunner as i, IssueInput as l, typescriptCheck as n, CheckRunner as o, regexCheck as r, Config as s, defineConfig as t, RawSnapshot as u };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as eslintCheck, c as Issue, d as Snapshot, i as typescriptCheck, l as IssueInput, n as regexRunner, o as CheckRunner, r as defineConfig, s as Config, t as regexCheck, u as RawSnapshot } from "./index-DL3YfUFl.mjs";
1
+ import { a as eslintCheck, c as Issue, d as Snapshot, i as regexRunner, l as IssueInput, n as typescriptCheck, o as CheckRunner, r as regexCheck, s as Config, t as defineConfig, u as RawSnapshot } from "./index-BHX-tY_Y.mjs";
2
2
  export { CheckRunner, Config, Issue, IssueInput, RawSnapshot, Snapshot, defineConfig, eslintCheck as eslint, eslintCheck, regexCheck as regex, regexCheck, regexRunner, typescriptCheck as typescript, typescriptCheck };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{a as e,c as t,h as n,i as r,l as i,n as a,o,p as s,s as c}from"./typescript-JQUGT569.mjs";import{glob as l,mkdir as u}from"node:fs/promises";import{createReadStream as d}from"node:fs";import{createInterface as f}from"node:readline/promises";const p=[`**/node_modules/**`,`**/dist/**`,`**/.git/**`];function m(e,t){if(t?.length)return t;let n=e.map(e=>/^([^*]+\/)/.exec(e)?.[1]).filter(e=>e!==void 0);return[...p,...n.flatMap(e=>p.map(t=>t.replace(/^\*\*\//,e)))]}async function h(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}var g=class{type=`regex`;async run(n){let r=process.cwd(),a=Array.isArray(n.files)?n.files:[n.files],u=m(a,n.ignore),p=new Set;for(let e of a){let t=l(e,{cwd:r,exclude:u});for await(let e of t)p.add(e)}let g=[...p],_=n.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}}),v=s(o(this.type,r),`${e(n)}.json`),y=await t(v),b={},x=await h(g,n.concurrency??10,async e=>{let t=s(r,e),n=await c(t);if(!n)return[];let i=y[e];if(i?.hash===n)return b[e]=i,i.items;try{let r=[],i=f({crlfDelay:1/0,input:d(t,{encoding:`utf8`})}),a=0;try{for await(let t of i){a++;for(let n of _){n.regex.lastIndex=0;let i;for(;(i=n.regex.exec(t))!==null;){let t=i.index+1,o=typeof n.message==`function`?n.message(i):n.message??`Pattern matched: ${i[0]}`;r.push({column:t,file:e,line:a,message:o,rule:n.ruleText})}}}}finally{i.close()}return b[e]={hash:n,items:r},r}catch{return[]}}),S=[];for(let e of x)S.push(...e);return await i(v,b),{items:S,type:`items`}}async setup(){let e=process.cwd();await u(o(this.type,e),{recursive:!0})}};const _=()=>new g;function v(e){return{type:`regex`,...e}}export{n as defineConfig,r as eslint,r as eslintCheck,v as regex,v as regexCheck,_ as regexRunner,a as typescript,a as typescriptCheck};
1
+ import{a as e,f as t,i as n,n as r,s as i}from"./typescript-BG8_PZiP.mjs";export{t as defineConfig,i as eslint,i as eslintCheck,n as regex,n as regexCheck,e as regexRunner,r as typescript,r as typescriptCheck};
package/dist/run.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import{d as e,f as t,g as n,m as r,u as i}from"./typescript-JQUGT569.mjs";import{t as a}from"./check-registry-BJlMzCIV.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{Tinypool as p}from"tinypool";import{env as m}from"node:process";const h=e=>t=>f(e,typeof t==`number`?t.toString():t),g=h(`blue`),_=h(`bold`),v=h(`cyan`),y=h(`dim`),b=h(`green`),x=h(`red`),S=h(`gray`),ee=h(`underline`),te=h(`yellow`);function ne(e){let t=[e.message];if(e.stack){let n=e.stack.split(`
2
+ import{c as e,d as t,l as n,p as r,u as i}from"./typescript-BG8_PZiP.mjs";import{t as a}from"./check-registry-D0NGvrkK.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`),v=h(`cyan`),y=h(`dim`),b=h(`green`),x=h(`red`),S=h(`gray`),ee=h(`underline`),te=h(`yellow`);function ne(e){let t=[e.message];if(e.stack){let n=e.stack.split(`
3
3
  `).slice(1).map(e=>y(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(x(`✖`),C(...e))},log:(...e)=>{console.log(C(...e))},start:(...e)=>{console.log(v(`◐`),C(...e))},success:(...e)=>{console.log(b(`✔`),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.localeCompare(t.file)}function re(e){let t=Map.groupBy(e,e=>e.signature),n=[];for(let[e,r]of t){r.sort(T);for(let[t,{signature:a,...o}]of r.entries())n.push({...o,id:i(`${e}:${t}`)})}return n}function E(e){return{items:re(e.items.map(e=>({...e,signature:`${e.file} - ${e.rule}: ${e.message}`}))).toSorted(T),type:`items`}}function D(e,t){return e===1?t:`${t}s`}const O=`__unparsable__`;function k(e){return e.replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`[`,`&#91;`).replaceAll(`]`,`&#93;`)}function A(e,t,n){let i=r(t,e);return n?`${i}#L${n}`:i}function j(e,t){return`[${e}](${t})`}function ie(e,t){let n=A(e.file,t,e.line);return`- ${j(e.line?`Line ${e.line}`:e.file,n)} - ${`${e.rule}: ${k(e.message)}`}`}function ae(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?-1:e.filePath.localeCompare(t.filePath))}function oe(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}: ${k(t.message)}`);return i.push(`\n${n} ${r} in Other Issues`,``),i.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(x(`✖`),C(...e))},log:(...e)=>{console.log(C(...e))},start:(...e)=>{console.log(v(`◐`),C(...e))},success:(...e)=>{console.log(b(`✔`),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.localeCompare(t.file)}function re(t){let n=Map.groupBy(t,e=>e.signature),r=[];for(let[t,i]of n){i.sort(T);for(let[n,{signature:a,...o}]of i.entries())r.push({...o,id:e(`${t}:${n}`)})}return r}function E(e){return{items:re(e.items.map(e=>({...e,signature:`${e.file} - ${e.rule}: ${e.message}`}))).toSorted(T),type:`items`}}function D(e,t){return e===1?t:`${t}s`}const O=`__unparsable__`;function k(e){return e.replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`[`,`&#91;`).replaceAll(`]`,`&#93;`)}function A(e,n,r){let i=t(n,e);return r?`${i}#L${r}`:i}function j(e,t){return`[${e}](${t})`}function ie(e,t){let n=A(e.file,t,e.line);return`- ${j(e.line?`Line ${e.line}`:e.file,n)} - ${`${e.rule}: ${k(e.message)}`}`}function ae(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?-1:e.filePath.localeCompare(t.filePath))}function oe(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}: ${k(t.message)}`);return i.push(`\n${n} ${r} in Other Issues`,``),i.join(`
6
6
  `)}function M(e,t,n){if(e.filePath===O)return oe(e.items,n);let r=A(e.filePath,t),i=j(e.filePath,r),a=e.items.length,o=D(a,`issue`),s=[`\n### ${i} · ${n}\n`];for(let n of e.items)s.push(ie(n,t));return s.push(`\n${a} ${o} in ${e.filePath}`,``),s.join(`
7
7
  `)}function se(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
8
  `);let o=ae(t);for(let t of o)a.push(M(t,n,e));return a.push(`---\n${r} total ${i} for ${e}`),a.join(`
@@ -16,7 +16,7 @@ import{d as e,f as t,g as n,m as r,u as i}from"./typescript-JQUGT569.mjs";import
16
16
  }`.repeat(t)}`}function fe(e){let t=(e.match(/\{/g)?.length??0)-(e.match(/\}/g)?.length??0);return t===0?e:t<0?V(e,-t):H(e,t)}function pe(e){try{return JSON.parse(e)}catch{return}}function U(e){let t=e.trim();return t.endsWith(`,`)?t.slice(0,-1):t}function me(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=pe(e.trim());if(t)return W(t);let n=me(fe(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 he(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 ge(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((e,t)=>e.id.localeCompare(t.id)),type:`items`};return{checks:n,version:2}}function _e(e){let t=he(e),n=[];for(let{ours:e,theirs:r}of t)n.push(G(e),G(r));return ge(n)}var K=class e{baselinePath;constructor(e=`.mejora/baseline.json`){this.baselinePath=e}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 B(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=_e(e);return await this.save(t,!0),w.success(`Baseline conflict resolved`),t}return await this.resolveMarkdownConflictIfNeeded(e),JSON.parse(e)}catch(e){if(e.code===`ENOENT`)return null;throw e}}async save(e,n=!1){if(le&&!n)return;let r=`${JSON.stringify(e,null,2)}\n`,i=this.baselinePath.replace(`.json`,`.md`),a=N(e,t(this.baselinePath));await s(t(this.baselinePath),{recursive:!0}),await Promise.all([l(this.baselinePath,r,`utf8`),l(i,a,`utf8`)])}async resolveMarkdownConflictIfNeeded(e){let n=this.baselinePath.replace(`.json`,`.md`);try{(await c(n,`utf8`)).includes(`<<<<<<<`)&&(w.start(`Merge conflict detected in markdown report, regenerating...`),await l(n,N(JSON.parse(e),t(this.baselinePath)),`utf8`),w.success(`Markdown report regenerated`))}catch{}}};const ve=o(new URL(`workers/check.mjs`,import.meta.url));var ye=class e{baselineManager;registry;constructor(e,t){this.registry=e,this.baselineManager=new K(t)}static async executeChecksParallel(e,t){let n=Object.keys(e),r=new p({filename:ve});try{let e=n.map(async e=>{let n=await r.run({checkId:e}),i=E(n.snapshot),a=K.getEntry(t,e),o=z(i,a);return{baseline:a,checkId:e,duration:n.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(e)}catch(e){return w.error(`Parallel execution failed:`,e),null}finally{await r.destroy()}}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:Object.fromEntries(Object.entries(t).filter(([e])=>!(r&&!r.test(e)||i?.test(e))))};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=Object.keys(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=i,l=!1,u=!1,d=!1;for(let e of s)e.hasRegression&&(l=!0),e.hasImprovement&&(u=!0),e.isInitial&&(d=!0),(e.hasImprovement||e.hasRelocation||n.force||e.isInitial)&&(c=K.update(c,e.checkId,{items:e.snapshot.items,type:e.snapshot.type}));return c&&c!==i&&(!l||n.force||d)&&await this.baselineManager.save(c,n.force),{exitCode:l&&!n.force?1:0,hasImprovement:u,hasRegression:l,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,i]of Object.entries(e))try{let e=performance.now(),a=await this.registry.get(i.type).run(i),o=performance.now()-e,s=E(a),c=K.getEntry(t,r),l=z(s,c);n.push({baseline:c,checkId:r,duration:o,hasImprovement:l.hasImprovement,hasRegression:l.hasRegression,hasRelocation:l.hasRelocation,isInitial:l.isInitial,newIssues:l.newIssues,removedIssues:l.removedIssues,snapshot:s})}catch(e){return w.error(`Error running check "${r}":`,e),null}return n}};function q(e,t){if(!(e===void 0||t===0))return e/t}function be(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 xe(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`:xe(t)}const Y=` `,Se=`${Y} `;function Ce(e){return e===`initial`?y(`→`):e===`improvement`?b(`↑`):x(`↓`)}function we(n,r,i){let a=t(n),o=e(n),s=r>0?`:${r}:${i>0?i:1}`:``;return`${a===`.`?``:y(`${a}/`)}${ee(o)}${s?y(s):``}`}function Te(e,t){return[`${Ce(t)} ${we(e.file,e.line,e.column)} ${y(e.rule)}`,e.message]}function X(e,t){let n=[],r=e.slice(0,10);for(let e of r){let[r,i]=Te(e,t);n.push(`${Y}${r}`,`${Se}${i}`)}let i=e.length-r.length;return i>0&&n.push(`${Y}${y(`... and ${i} more`)}`),n}function Ee(e){return e===void 0?[]:[` ${y(`Duration`)} ${J(e)}`]}function De(e){return[` ${y(`Issues`)} ${_(e)}`]}function Z(e){return[...Ee(e.duration),...De(e.snapshot.items.length)]}function Oe(e){if(!e.hasRegression)return[];let t=e.newIssues.length;return[` ${x(t)} new ${D(t,`issue`)} (${D(t,`regression`)}):`,...X(e.newIssues,`regression`)]}function Q(e){if(!e.hasImprovement)return[];let t=e.removedIssues.length;return[` ${b(t)} ${D(t,`issue`)} fixed (${D(t,`improvement`)}):`,...X(e.removedIssues,`improvement`)]}function ke(e,t){let n=t?``:`
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=pe(e.trim());if(t)return W(t);let n=me(fe(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 he(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 ge(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((e,t)=>e.id.localeCompare(t.id)),type:`items`};return{checks:n,version:2}}function _e(e){let t=he(e),n=[];for(let{ours:e,theirs:r}of t)n.push(G(e),G(r));return ge(n)}var K=class e{baselinePath;constructor(e=`.mejora/baseline.json`){this.baselinePath=e}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 B(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=_e(e);return await this.save(t,!0),w.success(`Baseline conflict resolved`),t}return await this.resolveMarkdownConflictIfNeeded(e),JSON.parse(e)}catch(e){if(e.code===`ENOENT`)return null;throw e}}async save(e,t=!1){if(le&&!t)return;let n=`${JSON.stringify(e,null,2)}\n`,r=this.baselinePath.replace(`.json`,`.md`),a=N(e,i(this.baselinePath));await s(i(this.baselinePath),{recursive:!0}),await Promise.all([l(this.baselinePath,n,`utf8`),l(r,a,`utf8`)])}async resolveMarkdownConflictIfNeeded(e){let t=this.baselinePath.replace(`.json`,`.md`);try{(await c(t,`utf8`)).includes(`<<<<<<<`)&&(w.start(`Merge conflict detected in markdown report, regenerating...`),await l(t,N(JSON.parse(e),i(this.baselinePath)),`utf8`),w.success(`Markdown report regenerated`))}catch{}}};const ve=o(new URL(`workers/check.mjs`,import.meta.url));var ye=class e{baselineManager;registry;constructor(e,t){this.registry=e,this.baselineManager=new K(t)}static async executeChecksParallel(t,n){let r=Object.keys(t);try{let t=r.map(async t=>{let r=await e.executeWorker(t),i=E(r.snapshot),a=K.getEntry(n,t),o=z(i,a);return{baseline:a,checkId:t,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(t)}catch(e){return w.error(`Parallel execution failed:`,e),null}}static async executeWorker(e){return new Promise((t,n)=>{let r=new p(ve,{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:Object.fromEntries(Object.entries(t).filter(([e])=>!(r&&!r.test(e)||i?.test(e))))};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=Object.keys(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=i,l=!1,u=!1,d=!1;for(let e of s)e.hasRegression&&(l=!0),e.hasImprovement&&(u=!0),e.isInitial&&(d=!0),(e.hasImprovement||e.hasRelocation||n.force||e.isInitial)&&(c=K.update(c,e.checkId,{items:e.snapshot.items,type:e.snapshot.type}));return c&&c!==i&&(!l||n.force||d)&&await this.baselineManager.save(c,n.force),{exitCode:l&&!n.force?1:0,hasImprovement:u,hasRegression:l,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,i]of Object.entries(e))try{let e=performance.now(),a=await this.registry.get(i.type).run(i),o=performance.now()-e,s=E(a),c=K.getEntry(t,r),l=z(s,c);n.push({baseline:c,checkId:r,duration:o,hasImprovement:l.hasImprovement,hasRegression:l.hasRegression,hasRelocation:l.hasRelocation,isInitial:l.isInitial,newIssues:l.newIssues,removedIssues:l.removedIssues,snapshot:s})}catch(e){return w.error(`Error running check "${r}":`,e),null}return n}};function q(e,t){if(!(e===void 0||t===0))return e/t}function be(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 xe(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`:xe(t)}const Y=` `,Se=`${Y} `;function Ce(e){return e===`initial`?y(`→`):e===`improvement`?b(`↑`):x(`↓`)}function we(e,t,r){let a=i(e),o=n(e),s=t>0?`:${t}:${r>0?r:1}`:``;return`${a===`.`?``:y(`${a}/`)}${ee(o)}${s?y(s):``}`}function Te(e,t){return[`${Ce(t)} ${we(e.file,e.line,e.column)} ${y(e.rule)}`,e.message]}function X(e,t){let n=[],r=e.slice(0,10);for(let e of r){let[r,i]=Te(e,t);n.push(`${Y}${r}`,`${Se}${i}`)}let i=e.length-r.length;return i>0&&n.push(`${Y}${y(`... and ${i} more`)}`),n}function Ee(e){return e===void 0?[]:[` ${y(`Duration`)} ${J(e)}`]}function De(e){return[` ${y(`Issues`)} ${_(e)}`]}function Z(e){return[...Ee(e.duration),...De(e.snapshot.items.length)]}function Oe(e){if(!e.hasRegression)return[];let t=e.newIssues.length;return[` ${x(t)} new ${D(t,`issue`)} (${D(t,`regression`)}):`,...X(e.newIssues,`regression`)]}function Q(e){if(!e.hasImprovement)return[];let t=e.removedIssues.length;return[` ${b(t)} ${D(t,`issue`)} fixed (${D(t,`improvement`)}):`,...X(e.removedIssues,`improvement`)]}function ke(e,t){let n=t?``:`
20
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(``,...Z(e)),i}function Ae(e,t){return[`${t?``:`
21
21
  `}${e.hasRegression?x(`✖`):b(`✔`)} ${e.checkId}:`,...Oe(e),...Q(e),``,...Z(e)]}function je(e,t){let n=t?``:`
22
22
  `,r=e.snapshot.items.length;return e.duration===void 0?[`${n}${S(`ℹ`)} ${e.checkId} (${_(r)})`]:[`${n}${S(`ℹ`)} ${e.checkId} (${_(r)}) ${y(J(e.duration))}`]}function Me(e,t){return e.isInitial?ke(e,t):e.hasRegression||e.hasImprovement?Ae(e,t):je(e,t)}function Ne(e,t,n){return t?g(`✔ Initial baseline created successfully`):e.hasRegression?n?te(`⚠ Regressions detected (forced)`):`${x(`✗ Regressions detected`)} - Run failed`:e.hasImprovement?`${b(`✔ Improvements detected`)} - Baseline updated`:b(`✔ All checks passed`)}function Pe(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=[` ${y(`Improvements`)} ${b(n.totalImprovements)}`,` ${y(`Regressions`)} ${x(n.totalRegressions)}`,` ${y(`Initial`)} ${g(n.totalInitial)}`,` ${y(`Checks`)} ${e.results.length}`,` ${y(`Issues`)} ${_(n.totalIssues)}`],i=q(e.totalDuration,e.results.length);return e.totalDuration!==void 0&&i!==void 0&&r.push(` ${y(`Duration`)} ${J(e.totalDuration)} ${S(`(avg ${J(i)})`)}`),r.push(``,Ne(e,n.hasAnyInitial,t)),r.join(`
@@ -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 e=new a,t=await n();e.init(t);let r=await new ye(e).run(t,{force:$.force,json:$.json,only:$.only,skip:$.skip});$.json?w.log(be(r)):(w.log(``),w.log(Fe(r,$.force))),process.exit(r.exitCode)}catch(e){e instanceof Error?w.error(e.message):w.error(e),process.exit(2)}export{};
43
+ `),process.exit(0));try{let e=new a,t=await r();e.init(t);let n=await new ye(e).run(t,{force:$.force,json:$.json,only:$.only,skip:$.skip});$.json?w.log(be(n)):(w.log(``),w.log(Fe(n,$.force))),process.exit(n.exitCode)}catch(e){e instanceof Error?w.error(e.message):w.error(e),process.exit(2)}export{};
@@ -0,0 +1,3 @@
1
+ import{createRequire as e}from"node:module";import{pathToFileURL as t}from"node:url";import{glob as n,mkdir as r,readFile as i,stat as a,writeFile as o}from"node:fs/promises";import{hash as s}from"node:crypto";import{createReadStream as c}from"node:fs";import{createInterface as l}from"node:readline/promises";var u=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),d=e(import.meta.url),f=u(((e,t)=>{let n=d(`path`),r=d(`fs`),i=d(`os`),a=d(`url`),o=r.promises.readFile;function s(e,t){return[`package.json`,`.${e}rc.json`,`.${e}rc.js`,`.${e}rc.cjs`,...t?[]:[`.${e}rc.mjs`],`.config/${e}rc`,`.config/${e}rc.json`,`.config/${e}rc.js`,`.config/${e}rc.cjs`,...t?[]:[`.config/${e}rc.mjs`],`${e}.config.js`,`${e}.config.cjs`,...t?[]:[`${e}.config.mjs`]]}function c(e){return n.dirname(e)||n.sep}let l=(e,t)=>JSON.parse(t),u=typeof __webpack_require__==`function`?__non_webpack_require__:d,f=Object.freeze({".js":u,".json":u,".cjs":u,noExt:l});t.exports.defaultLoadersSync=f;let p=async e=>{try{return(await import(a.pathToFileURL(e).href)).default}catch(t){try{return u(e)}catch(e){throw e.code===`ERR_REQUIRE_ESM`||e instanceof SyntaxError&&e.toString().includes(`Cannot use import statement outside a module`)?t:e}}},m=Object.freeze({".js":p,".mjs":p,".cjs":p,".json":l,noExt:l});t.exports.defaultLoaders=m;function h(e,t,r){let a={stopDir:i.homedir(),searchPlaces:s(e,r),ignoreEmptySearchPlaces:!0,cache:!0,transform:e=>e,packageProp:[e],...t,loaders:{...r?f:m,...t.loaders}};return a.searchPlaces.forEach(e=>{let t=n.extname(e)||`noExt`,r=a.loaders[t];if(!r)throw Error(`Missing loader for extension "${e}"`);if(typeof r!=`function`)throw Error(`Loader for extension "${e}" is not a function: Received ${typeof r}.`)}),a}function g(e,t){return typeof e==`string`&&e in t?t[e]:(Array.isArray(e)?e:e.split(`.`)).reduce((e,t)=>e===void 0?e:e[t],t)||null}function _(e){if(!e)throw Error(`load must pass a non-empty string`)}function v(e,t){if(!e)throw Error(`No loader specified for extension "${t}"`);if(typeof e!=`function`)throw Error(`loader is not a function`)}let y=e=>(t,n,r)=>(e&&t.set(n,r),r);t.exports.lilconfig=function(e,t){let{ignoreEmptySearchPlaces:i,loaders:a,packageProp:s,searchPlaces:l,stopDir:u,transform:d,cache:f}=h(e,t??{},!1),p=new Map,m=new Map,b=y(f);return{async search(e=process.cwd()){let t={config:null,filepath:``},m=new Set,h=e;dirLoop:for(;;){if(f){let e=p.get(h);if(e!==void 0){for(let t of m)p.set(t,e);return e}m.add(h)}for(let e of l){let c=n.join(h,e);try{await r.promises.access(c)}catch{continue}let l=String(await o(c)),u=n.extname(e)||`noExt`,d=a[u];if(e===`package.json`){let e=g(s,await d(c,l));if(e!=null){t.config=e,t.filepath=c;break dirLoop}continue}let f=l.trim()===``;if(!(f&&i)){f?(t.isEmpty=!0,t.config=void 0):(v(d,u),t.config=await d(c,l)),t.filepath=c;break dirLoop}}if(h===u||h===c(h))break dirLoop;h=c(h)}let _=t.filepath===``&&t.config===null?d(null):d(t);if(f)for(let e of m)p.set(e,_);return _},async load(e){_(e);let t=n.resolve(process.cwd(),e);if(f&&m.has(t))return m.get(t);let{base:r,ext:c}=n.parse(t),l=c||`noExt`,u=a[l];v(u,l);let p=String(await o(t));if(r===`package.json`)return b(m,t,d({config:g(s,await u(t,p)),filepath:t}));let h={config:null,filepath:t},y=p.trim()===``;return y&&i?b(m,t,d({config:void 0,filepath:t,isEmpty:!0})):(h.config=y?void 0:await u(t,p),b(m,t,d(y?{...h,isEmpty:y,config:void 0}:h)))},clearLoadCache(){f&&m.clear()},clearSearchCache(){f&&p.clear()},clearCaches(){f&&(m.clear(),p.clear())}}},t.exports.lilconfigSync=function(e,t){let{ignoreEmptySearchPlaces:i,loaders:a,packageProp:o,searchPlaces:s,stopDir:l,transform:u,cache:d}=h(e,t??{},!0),f=new Map,p=new Map,m=y(d);return{search(e=process.cwd()){let t={config:null,filepath:``},p=new Set,m=e;dirLoop:for(;;){if(d){let e=f.get(m);if(e!==void 0){for(let t of p)f.set(t,e);return e}p.add(m)}for(let e of s){let s=n.join(m,e);try{r.accessSync(s)}catch{continue}let c=n.extname(e)||`noExt`,l=a[c],u=String(r.readFileSync(s));if(e===`package.json`){let e=g(o,l(s,u));if(e!=null){t.config=e,t.filepath=s;break dirLoop}continue}let d=u.trim()===``;if(!(d&&i)){d?(t.isEmpty=!0,t.config=void 0):(v(l,c),t.config=l(s,u)),t.filepath=s;break dirLoop}}if(m===l||m===c(m))break dirLoop;m=c(m)}let h=t.filepath===``&&t.config===null?u(null):u(t);if(d)for(let e of p)f.set(e,h);return h},load(e){_(e);let t=n.resolve(process.cwd(),e);if(d&&p.has(t))return p.get(t);let{base:s,ext:c}=n.parse(t),l=c||`noExt`,f=a[l];v(f,l);let h=String(r.readFileSync(t));if(s===`package.json`)return u({config:g(o,f(t,h)),filepath:t});let y={config:null,filepath:t},b=h.trim()===``;return b&&i?m(p,t,u({filepath:t,config:void 0,isEmpty:!0})):(y.config=b?void 0:f(t,h),m(p,t,u(b?{...y,isEmpty:b,config:void 0}:y)))},clearLoadCache(){d&&p.clear()},clearSearchCache(){d&&f.clear()},clearCaches(){d&&(p.clear(),f.clear())}}}}))();const p=async e=>{let n=await import(t(e).href);return n&&typeof n==`object`&&`default`in n?n.default:n};function m(e){return e}const h=async()=>{let e=await(0,f.lilconfig)(`mejora`,{loaders:{".js":p,".mjs":p,".mts":p,".ts":p},searchPlaces:[`mejora.config.ts`,`mejora.config.mts`,`mejora.config.js`,`mejora.config.mjs`]}).search(process.cwd());if(!e?.config)throw Error(`No configuration file found.`);return e.config},g=/^[A-Za-z]:\//;function _(e=``){return e&&e.replace(/\\/g,`/`).replace(g,e=>e.toUpperCase())}const v=/^[/\\]{2}/,y=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,b=/^[A-Za-z]:$/,x=/^\/([A-Za-z]:)?$/,S=function(e){if(e.length===0)return`.`;e=_(e);let t=e.match(v),n=D(e),r=e[e.length-1]===`/`;return e=E(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),b.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!D(e)?`/${e}`:e)},C=function(...e){let t=``;for(let n of e)if(n)if(t.length>0){let e=t[t.length-1]===`/`,r=n[0]===`/`;e&&r?t+=n.slice(1):t+=e||r?n:`/${n}`}else t+=n;return S(t)};function w(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}const T=function(...e){e=e.map(e=>_(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:w();!i||i.length===0||(t=`${i}/${t}`,n=D(i))}return t=E(t,!n),n&&!D(t)?`/${t}`:t.length>0?t:`.`};function E(e,t){let n=``,r=0,i=-1,a=0,o=null;for(let s=0;s<=e.length;++s){if(s<e.length)o=e[s];else if(o===`/`)break;else o=`/`;if(o===`/`){if(!(i===s-1||a===1))if(a===2){if(n.length<2||r!==2||n[n.length-1]!==`.`||n[n.length-2]!==`.`){if(n.length>2){let e=n.lastIndexOf(`/`);e===-1?(n=``,r=0):(n=n.slice(0,e),r=n.length-1-n.lastIndexOf(`/`)),i=s,a=0;continue}else if(n.length>0){n=``,r=0,i=s,a=0;continue}}t&&(n+=n.length>0?`/..`:`..`,r=2)}else n.length>0?n+=`/${e.slice(i+1,s)}`:n=e.slice(i+1,s),r=s-i-1;i=s,a=0}else o===`.`&&a!==-1?++a:a=-1}return n}const D=function(e){return y.test(e)},O=function(e,t){let n=T(e).replace(x,`$1`).split(`/`),r=T(t).replace(x,`$1`).split(`/`);if(r[0][1]===`:`&&n[0][1]===`:`&&n[0]!==r[0])return r.join(`/`);let i=[...n];for(let e of i){if(r[0]!==e)break;n.shift(),r.shift()}return[...n.map(()=>`..`),...r].join(`/`)},k=function(e){let t=_(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&b.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(D(e)?`/`:`.`)},A=function(e,t){let n=_(e).split(`/`),r=``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){r=t;break}}return t&&r.endsWith(t)?r.slice(0,-t.length):r},j=e=>s(`sha256`,e,`hex`);function M(){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 N(e){return j(JSON.stringify(e??null,M()))}function P(e,t=process.cwd()){return T(t,`node_modules`,`.cache`,`mejora`,e)}async function F(e){try{let t=await i(e,`utf8`);return JSON.parse(t)}catch{return{}}}async function I(e,t){try{await o(e,JSON.stringify(t,null,2),`utf8`)}catch{}}async function L(e){try{let t=await a(e);return`${t.mtimeMs}-${t.size}`}catch{return null}}var R=class{type=`eslint`;async run(e){let{ESLint:t}=await import(`eslint`),n=process.cwd(),r=P(this.type,n),i=N(e),a=new Set;if(e.overrides){let t=Array.isArray(e.overrides)?e.overrides:[e.overrides];for(let e of t)if(e.rules)for(let t of Object.keys(e.rules))a.add(t)}let o=a.size>0,s=await new t({cache:!0,cacheLocation:`${r}/${i}.eslintcache`,overrideConfig:e.overrides,...!o&&{concurrency:e.concurrency??`auto`},...o&&{ruleFilter:({ruleId:e})=>a.has(e)}}).lintFiles(e.files),c=[];for(let{filePath:e,messages:t}of s){let r=O(n,e);for(let{column:e,line:n,message:i,ruleId:a}of t)a&&c.push({column:e,file:r,line:n,message:i,rule:a})}return{items:c,type:`items`}}async setup(){let e=process.cwd(),t=P(this.type,e),{mkdir:n}=await import(`node:fs/promises`);await n(t,{recursive:!0})}async validate(){try{await import(`eslint`)}catch{throw Error(`${this.type} check requires "eslint" package to be installed. Run: npm install eslint`)}}};function z(e){return{type:`eslint`,...e}}const B=[`**/node_modules/**`,`**/dist/**`,`**/.git/**`];function V(e,t){if(t?.length)return t;let n=e.map(e=>/^([^*]+\/)/.exec(e)?.[1]).filter(e=>e!==void 0);return[...B,...n.flatMap(e=>B.map(t=>t.replace(/^\*\*\//,e)))]}async function H(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}var U=class{type=`regex`;async run(e){let t=process.cwd(),r=Array.isArray(e.files)?e.files:[e.files],i=V(r,e.ignore),a=new Set;for(let e of r){let r=n(e,{cwd:t,exclude:i});for await(let e of r)a.add(e)}let o=[...a],s=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}}),u=C(P(this.type,t),`${N(e)}.json`),d=await F(u),f={},p=await H(o,e.concurrency??10,async e=>{let n=C(t,e),r=await L(n);if(!r)return[];let i=d[e];if(i?.hash===r)return f[e]=i,i.items;try{let t=[],i=l({crlfDelay:1/0,input:c(n,{encoding:`utf8`})}),a=0;try{for await(let n of i){a++;for(let r of s){r.regex.lastIndex=0;let i;for(;(i=r.regex.exec(n))!==null;){let n=i.index+1,o=typeof r.message==`function`?r.message(i):r.message??`Pattern matched: ${i[0]}`;t.push({column:n,file:e,line:a,message:o,rule:r.ruleText})}}}}finally{i.close()}return f[e]={hash:r,items:t},t}catch{return[]}}),m=[];for(let e of p)m.push(...e);return await I(u,f),{items:m,type:`items`}}async setup(){let e=process.cwd();await r(P(this.type,e),{recursive:!0})}};const W=()=>new U;function G(e){return{type:`regex`,...e}}function K(e,t){return e.replaceAll(/import\("([^"]+)"\)/g,(e,n)=>{try{if(D(n)){let e=O(t,n);if(!e.startsWith(`..`))return`import("${e||`.`}")`}}catch{}return e})}var q=class{type=`typescript`;async run(e){let{createIncrementalCompilerHost:t,createIncrementalProgram:n,findConfigFile:r,flattenDiagnosticMessageText:i,getPreEmitDiagnostics:a,parseJsonConfigFileContent:o,readConfigFile:s,sys:c,version:l}=await import(`typescript`),u=process.cwd(),d=c.fileExists.bind(c),f=c.readFile.bind(c),p=e.tsconfig?T(e.tsconfig):r(u,d,`tsconfig.json`);if(!p)throw Error(`TypeScript config file not found`);let{config:m,error:h}=s(p,f);if(h){let e=typeof h.messageText==`string`?h.messageText:i(h.messageText,`
2
+ `);throw TypeError(`Failed to read TypeScript config: ${e}`)}let g=o(m,c,u,e.overrides?.compilerOptions),_=T(P(this.type,u),`${N({configPath:p,overrides:e.overrides?.compilerOptions??{},parsedOptions:g.options,typescriptVersion:l})}.tsbuildinfo`),v={...g.options,incremental:!0,noEmit:!0,skipLibCheck:g.options.skipLibCheck??!0,tsBuildInfoFile:_},y=t(v,c),b=y.writeFile.bind(y);y.writeFile=(e,t,...n)=>{T(e)===_&&b(e,t,...n)};let x=n({host:y,options:v,projectReferences:g.projectReferences??[],rootNames:g.fileNames}),S=a(x.getProgram());x.emit();let C=T(u),w=C+`/`,E=S.filter(e=>{if(!e.file)return!0;let t=T(e.file.fileName);return t===C||t.startsWith(w)}),D=[];for(let e of E){let t=i(e.messageText,`
3
+ `),n=`TS${e.code}`;if(e.file&&e.start!==void 0){let{character:r,line:i}=e.file.getLineAndCharacterOfPosition(e.start),a=O(u,e.file.fileName);D.push({column:r+1,file:a,line:i+1,message:K(t,u),rule:n})}else D.push({column:0,file:`(global)`,line:0,message:K(t,u),rule:n})}return{items:D,type:`items`}}async setup(){let e=process.cwd(),t=P(this.type,e),{mkdir:n}=await import(`node:fs/promises`);await n(t,{recursive:!0})}async validate(){try{await import(`typescript`)}catch{throw Error(`${this.type} check requires "typescript" package to be installed. Run: npm install typescript`)}}};function J(e){return{type:`typescript`,...e}}export{W as a,j as c,O as d,m as f,G as i,A as l,J as n,R as o,h as p,U as r,z as s,q as t,k as u};
@@ -1,4 +1,4 @@
1
- import { u as RawSnapshot } from "../index-DL3YfUFl.mjs";
1
+ import { u as RawSnapshot } from "../index-BHX-tY_Y.mjs";
2
2
 
3
3
  //#region src/workers/check.d.ts
4
4
  declare function checkWorker({
@@ -10,4 +10,4 @@ declare function checkWorker({
10
10
  snapshot: RawSnapshot;
11
11
  }>;
12
12
  //#endregion
13
- export { checkWorker as default };
13
+ export { checkWorker };
@@ -1 +1 @@
1
- import{g as e}from"../typescript-JQUGT569.mjs";import{t}from"../check-registry-BJlMzCIV.mjs";let n=null,r=null;const i=new Map;async function a({checkId:a}){n||(r??=(async()=>{n=await e()})(),await r);let o=n?.checks[a];if(!o)throw Error(`Check not found in config: ${a}`);let s=i.get(o.type);if(!s){s=new t,s.init(n);let e=new Set([o.type]);await Promise.all([s.setup(e),s.validate(e)]),i.set(o.type,s)}let c=performance.now(),l=await s.get(o.type).run(o);return{duration:performance.now()-c,snapshot:l}}export{a as default};
1
+ import{p as e}from"../typescript-BG8_PZiP.mjs";import{t}from"../check-registry-D0NGvrkK.mjs";import{parentPort as n,workerData as r}from"node:worker_threads";let i=null,a=null;const o=new Map;async function s({checkId:n}){i||(a??=(async()=>{i=await e()})(),await a);let r=i?.checks[n];if(!r)throw Error(`Check not found in config: ${n}`);let s=o.get(r.type);if(!s){s=new t,s.init(i);let e=new Set([r.type]);await Promise.all([s.setup(e),s.validate(e)]),o.set(r.type,s)}let c=performance.now(),l=await s.get(r.type).run(r);return{duration:performance.now()-c,snapshot:l}}if(n){let e=await s(r);n.postMessage(e)}export{s as checkWorker};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mejora",
3
- "version": "2.3.6",
3
+ "version": "2.4.0",
4
4
  "description": "Prevent regressions. Allow improvement.",
5
5
  "keywords": [
6
6
  "regression",
@@ -36,9 +36,6 @@
36
36
  "files": [
37
37
  "dist"
38
38
  ],
39
- "dependencies": {
40
- "tinypool": "^2.1.0"
41
- },
42
39
  "peerDependencies": {
43
40
  "eslint": "^9.34.0",
44
41
  "typescript": "^5.0.0"
@@ -1 +0,0 @@
1
- import{r as e,t}from"./typescript-JQUGT569.mjs";var n=class{runners=new Map;static getRequiredTypes(e){return new Set(Object.values(e).map(e=>e.type))}get(e){let t=this.runners.get(e);if(!t)throw Error(`Unknown check type: ${e}`);return t}getTypes(){return new Set(this.runners.keys())}has(e){return this.runners.has(e)}init(n={}){if(this.register(new e),this.register(new t),n.runners)for(let e of n.runners)this.register(e)}register(e){if(this.runners.has(e.type))throw Error(`Check runner already registered: ${e.type}`);this.runners.set(e.type,e)}async setup(e){await this.runLifecycle(e,`setup`)}async validate(e){await this.runLifecycle(e,`validate`)}async runLifecycle(e,t){let n=[];for(let r of e){let e=this.get(r)[t]?.();e&&n.push(e)}await Promise.all(n)}};export{n as t};
@@ -1,3 +0,0 @@
1
- import{createRequire as e}from"node:module";import{pathToFileURL as t}from"node:url";import{readFile as n,stat as r,writeFile as i}from"node:fs/promises";import{hash as a}from"node:crypto";var o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=e(import.meta.url),c=o(((e,t)=>{let n=s(`path`),r=s(`fs`),i=s(`os`),a=s(`url`),o=r.promises.readFile;function c(e,t){return[`package.json`,`.${e}rc.json`,`.${e}rc.js`,`.${e}rc.cjs`,...t?[]:[`.${e}rc.mjs`],`.config/${e}rc`,`.config/${e}rc.json`,`.config/${e}rc.js`,`.config/${e}rc.cjs`,...t?[]:[`.config/${e}rc.mjs`],`${e}.config.js`,`${e}.config.cjs`,...t?[]:[`${e}.config.mjs`]]}function l(e){return n.dirname(e)||n.sep}let u=(e,t)=>JSON.parse(t),d=typeof __webpack_require__==`function`?__non_webpack_require__:s,f=Object.freeze({".js":d,".json":d,".cjs":d,noExt:u});t.exports.defaultLoadersSync=f;let p=async e=>{try{return(await import(a.pathToFileURL(e).href)).default}catch(t){try{return d(e)}catch(e){throw e.code===`ERR_REQUIRE_ESM`||e instanceof SyntaxError&&e.toString().includes(`Cannot use import statement outside a module`)?t:e}}},m=Object.freeze({".js":p,".mjs":p,".cjs":p,".json":u,noExt:u});t.exports.defaultLoaders=m;function h(e,t,r){let a={stopDir:i.homedir(),searchPlaces:c(e,r),ignoreEmptySearchPlaces:!0,cache:!0,transform:e=>e,packageProp:[e],...t,loaders:{...r?f:m,...t.loaders}};return a.searchPlaces.forEach(e=>{let t=n.extname(e)||`noExt`,r=a.loaders[t];if(!r)throw Error(`Missing loader for extension "${e}"`);if(typeof r!=`function`)throw Error(`Loader for extension "${e}" is not a function: Received ${typeof r}.`)}),a}function g(e,t){return typeof e==`string`&&e in t?t[e]:(Array.isArray(e)?e:e.split(`.`)).reduce((e,t)=>e===void 0?e:e[t],t)||null}function _(e){if(!e)throw Error(`load must pass a non-empty string`)}function v(e,t){if(!e)throw Error(`No loader specified for extension "${t}"`);if(typeof e!=`function`)throw Error(`loader is not a function`)}let y=e=>(t,n,r)=>(e&&t.set(n,r),r);t.exports.lilconfig=function(e,t){let{ignoreEmptySearchPlaces:i,loaders:a,packageProp:s,searchPlaces:c,stopDir:u,transform:d,cache:f}=h(e,t??{},!1),p=new Map,m=new Map,b=y(f);return{async search(e=process.cwd()){let t={config:null,filepath:``},m=new Set,h=e;dirLoop:for(;;){if(f){let e=p.get(h);if(e!==void 0){for(let t of m)p.set(t,e);return e}m.add(h)}for(let e of c){let c=n.join(h,e);try{await r.promises.access(c)}catch{continue}let l=String(await o(c)),u=n.extname(e)||`noExt`,d=a[u];if(e===`package.json`){let e=g(s,await d(c,l));if(e!=null){t.config=e,t.filepath=c;break dirLoop}continue}let f=l.trim()===``;if(!(f&&i)){f?(t.isEmpty=!0,t.config=void 0):(v(d,u),t.config=await d(c,l)),t.filepath=c;break dirLoop}}if(h===u||h===l(h))break dirLoop;h=l(h)}let _=t.filepath===``&&t.config===null?d(null):d(t);if(f)for(let e of m)p.set(e,_);return _},async load(e){_(e);let t=n.resolve(process.cwd(),e);if(f&&m.has(t))return m.get(t);let{base:r,ext:c}=n.parse(t),l=c||`noExt`,u=a[l];v(u,l);let p=String(await o(t));if(r===`package.json`)return b(m,t,d({config:g(s,await u(t,p)),filepath:t}));let h={config:null,filepath:t},y=p.trim()===``;return y&&i?b(m,t,d({config:void 0,filepath:t,isEmpty:!0})):(h.config=y?void 0:await u(t,p),b(m,t,d(y?{...h,isEmpty:y,config:void 0}:h)))},clearLoadCache(){f&&m.clear()},clearSearchCache(){f&&p.clear()},clearCaches(){f&&(m.clear(),p.clear())}}},t.exports.lilconfigSync=function(e,t){let{ignoreEmptySearchPlaces:i,loaders:a,packageProp:o,searchPlaces:s,stopDir:c,transform:u,cache:d}=h(e,t??{},!0),f=new Map,p=new Map,m=y(d);return{search(e=process.cwd()){let t={config:null,filepath:``},p=new Set,m=e;dirLoop:for(;;){if(d){let e=f.get(m);if(e!==void 0){for(let t of p)f.set(t,e);return e}p.add(m)}for(let e of s){let s=n.join(m,e);try{r.accessSync(s)}catch{continue}let c=n.extname(e)||`noExt`,l=a[c],u=String(r.readFileSync(s));if(e===`package.json`){let e=g(o,l(s,u));if(e!=null){t.config=e,t.filepath=s;break dirLoop}continue}let d=u.trim()===``;if(!(d&&i)){d?(t.isEmpty=!0,t.config=void 0):(v(l,c),t.config=l(s,u)),t.filepath=s;break dirLoop}}if(m===c||m===l(m))break dirLoop;m=l(m)}let h=t.filepath===``&&t.config===null?u(null):u(t);if(d)for(let e of p)f.set(e,h);return h},load(e){_(e);let t=n.resolve(process.cwd(),e);if(d&&p.has(t))return p.get(t);let{base:s,ext:c}=n.parse(t),l=c||`noExt`,f=a[l];v(f,l);let h=String(r.readFileSync(t));if(s===`package.json`)return u({config:g(o,f(t,h)),filepath:t});let y={config:null,filepath:t},b=h.trim()===``;return b&&i?m(p,t,u({filepath:t,config:void 0,isEmpty:!0})):(y.config=b?void 0:f(t,h),m(p,t,u(b?{...y,isEmpty:b,config:void 0}:y)))},clearLoadCache(){d&&p.clear()},clearSearchCache(){d&&f.clear()},clearCaches(){d&&(p.clear(),f.clear())}}}}))();const l=async e=>{let n=await import(t(e).href);return n&&typeof n==`object`&&`default`in n?n.default:n};function u(e){return e}const d=async()=>{let e=await(0,c.lilconfig)(`mejora`,{loaders:{".js":l,".mjs":l,".mts":l,".ts":l},searchPlaces:[`mejora.config.ts`,`mejora.config.mts`,`mejora.config.js`,`mejora.config.mjs`]}).search(process.cwd());if(!e?.config)throw Error(`No configuration file found.`);return e.config},f=/^[A-Za-z]:\//;function p(e=``){return e&&e.replace(/\\/g,`/`).replace(f,e=>e.toUpperCase())}const m=/^[/\\]{2}/,h=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,g=/^[A-Za-z]:$/,_=/^\/([A-Za-z]:)?$/,v=function(e){if(e.length===0)return`.`;e=p(e);let t=e.match(m),n=C(e),r=e[e.length-1]===`/`;return e=S(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),g.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!C(e)?`/${e}`:e)},y=function(...e){let t=``;for(let n of e)if(n)if(t.length>0){let e=t[t.length-1]===`/`,r=n[0]===`/`;e&&r?t+=n.slice(1):t+=e||r?n:`/${n}`}else t+=n;return v(t)};function b(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}const x=function(...e){e=e.map(e=>p(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:b();!i||i.length===0||(t=`${i}/${t}`,n=C(i))}return t=S(t,!n),n&&!C(t)?`/${t}`:t.length>0?t:`.`};function S(e,t){let n=``,r=0,i=-1,a=0,o=null;for(let s=0;s<=e.length;++s){if(s<e.length)o=e[s];else if(o===`/`)break;else o=`/`;if(o===`/`){if(!(i===s-1||a===1))if(a===2){if(n.length<2||r!==2||n[n.length-1]!==`.`||n[n.length-2]!==`.`){if(n.length>2){let e=n.lastIndexOf(`/`);e===-1?(n=``,r=0):(n=n.slice(0,e),r=n.length-1-n.lastIndexOf(`/`)),i=s,a=0;continue}else if(n.length>0){n=``,r=0,i=s,a=0;continue}}t&&(n+=n.length>0?`/..`:`..`,r=2)}else n.length>0?n+=`/${e.slice(i+1,s)}`:n=e.slice(i+1,s),r=s-i-1;i=s,a=0}else o===`.`&&a!==-1?++a:a=-1}return n}const C=function(e){return h.test(e)},w=function(e,t){let n=x(e).replace(_,`$1`).split(`/`),r=x(t).replace(_,`$1`).split(`/`);if(r[0][1]===`:`&&n[0][1]===`:`&&n[0]!==r[0])return r.join(`/`);let i=[...n];for(let e of i){if(r[0]!==e)break;n.shift(),r.shift()}return[...n.map(()=>`..`),...r].join(`/`)},T=function(e){let t=p(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&g.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(C(e)?`/`:`.`)},E=function(e,t){let n=p(e).split(`/`),r=``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){r=t;break}}return t&&r.endsWith(t)?r.slice(0,-t.length):r},D=e=>a(`sha256`,e,`hex`);function O(){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 k(e){return D(JSON.stringify(e??null,O()))}function A(e,t=process.cwd()){return x(t,`node_modules`,`.cache`,`mejora`,e)}async function j(e){try{let t=await n(e,`utf8`);return JSON.parse(t)}catch{return{}}}async function M(e,t){try{await i(e,JSON.stringify(t,null,2),`utf8`)}catch{}}async function N(e){try{let t=await r(e);return`${t.mtimeMs}-${t.size}`}catch{return null}}var P=class{type=`eslint`;async run(e){let{ESLint:t}=await import(`eslint`),n=process.cwd(),r=A(this.type,n),i=k(e),a=new Set;if(e.overrides){let t=Array.isArray(e.overrides)?e.overrides:[e.overrides];for(let e of t)if(e.rules)for(let t of Object.keys(e.rules))a.add(t)}let o=a.size>0,s=await new t({cache:!0,cacheLocation:`${r}/${i}.eslintcache`,overrideConfig:e.overrides,...!o&&{concurrency:e.concurrency??`auto`},...o&&{ruleFilter:({ruleId:e})=>a.has(e)}}).lintFiles(e.files),c=[];for(let{filePath:e,messages:t}of s){let r=w(n,e);for(let{column:e,line:n,message:i,ruleId:a}of t)a&&c.push({column:e,file:r,line:n,message:i,rule:a})}return{items:c,type:`items`}}async setup(){let e=process.cwd(),t=A(this.type,e),{mkdir:n}=await import(`node:fs/promises`);await n(t,{recursive:!0})}async validate(){try{await import(`eslint`)}catch{throw Error(`${this.type} check requires "eslint" package to be installed. Run: npm install eslint`)}}};function F(e){return{type:`eslint`,...e}}function I(e,t){return e.replaceAll(/import\("([^"]+)"\)/g,(e,n)=>{try{if(C(n)){let e=w(t,n);if(!e.startsWith(`..`))return`import("${e||`.`}")`}}catch{}return e})}var L=class{type=`typescript`;async run(e){let{createIncrementalCompilerHost:t,createIncrementalProgram:n,findConfigFile:r,flattenDiagnosticMessageText:i,getPreEmitDiagnostics:a,parseJsonConfigFileContent:o,readConfigFile:s,sys:c,version:l}=await import(`typescript`),u=process.cwd(),d=c.fileExists.bind(c),f=c.readFile.bind(c),p=e.tsconfig?x(e.tsconfig):r(u,d,`tsconfig.json`);if(!p)throw Error(`TypeScript config file not found`);let{config:m,error:h}=s(p,f);if(h){let e=typeof h.messageText==`string`?h.messageText:i(h.messageText,`
2
- `);throw TypeError(`Failed to read TypeScript config: ${e}`)}let g=o(m,c,u,e.overrides?.compilerOptions),_=x(A(this.type,u),`${k({configPath:p,overrides:e.overrides?.compilerOptions??{},parsedOptions:g.options,typescriptVersion:l})}.tsbuildinfo`),v={...g.options,incremental:!0,noEmit:!0,skipLibCheck:g.options.skipLibCheck??!0,tsBuildInfoFile:_},y=t(v,c),b=y.writeFile.bind(y);y.writeFile=(e,t,...n)=>{x(e)===_&&b(e,t,...n)};let S=n({host:y,options:v,projectReferences:g.projectReferences??[],rootNames:g.fileNames}),C=a(S.getProgram());S.emit();let T=x(u),E=T+`/`,D=C.filter(e=>{if(!e.file)return!0;let t=x(e.file.fileName);return t===T||t.startsWith(E)}),O=[];for(let e of D){let t=i(e.messageText,`
3
- `),n=`TS${e.code}`;if(e.file&&e.start!==void 0){let{character:r,line:i}=e.file.getLineAndCharacterOfPosition(e.start),a=w(u,e.file.fileName);O.push({column:r+1,file:a,line:i+1,message:I(t,u),rule:n})}else O.push({column:0,file:`(global)`,line:0,message:I(t,u),rule:n})}return{items:O,type:`items`}}async setup(){let e=process.cwd(),t=A(this.type,e),{mkdir:n}=await import(`node:fs/promises`);await n(t,{recursive:!0})}async validate(){try{await import(`typescript`)}catch{throw Error(`${this.type} check requires "typescript" package to be installed. Run: npm install typescript`)}}};function R(e){return{type:`typescript`,...e}}export{k as a,j as c,E as d,T as f,d as g,u as h,F as i,M as l,w as m,R as n,A as o,y as p,P as r,N as s,L as t,D as u};