@preventive/triage 1.0.0-alpha.53 → 1.0.0-alpha.54

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.
Files changed (109) hide show
  1. package/common/bundle-compare-diff.js +28 -9
  2. package/common/bundle-compare-inputs.d.ts +1 -0
  3. package/common/bundle-compare-inputs.js +91 -15
  4. package/common/bundle-comparison.js +14 -7
  5. package/common/default-scan-models.ts +3 -0
  6. package/common/dependency-reviews.d.ts +1 -1
  7. package/common/dependency-reviews.js +1 -1
  8. package/common/managed/finding-detail.d.ts +1 -1
  9. package/common/managed/finding-detail.js +7 -7
  10. package/common/managed/team-app.d.ts +7 -0
  11. package/common/managed/team-app.js +31 -7
  12. package/common/workspace-app.js +19 -7
  13. package/out/activity.js +4 -4
  14. package/out/chunk-4EMM6UCD.js +1 -0
  15. package/out/chunk-4ISO5F7Y.js +7 -0
  16. package/out/chunk-4XIH7YTX.js +1 -0
  17. package/out/chunk-6W5BMATD.js +1 -0
  18. package/out/{chunk-WFYLMF6Z.js → chunk-74AEKRES.js} +1 -1
  19. package/out/chunk-DEVAORP2.js +1 -0
  20. package/out/{chunk-KOGNQDSJ.js → chunk-DTM47KGS.js} +1 -1
  21. package/out/chunk-E3LFSUDJ.js +9 -0
  22. package/out/chunk-FHIVVVUA.js +6 -0
  23. package/out/chunk-G3LY2FV4.js +1 -0
  24. package/out/chunk-HAZKDK4M.js +4 -0
  25. package/out/chunk-HOB3YPS5.js +1 -0
  26. package/out/chunk-I47TYPXO.js +52 -0
  27. package/out/chunk-J7A5OSZE.js +244 -0
  28. package/out/chunk-JFL7WLRV.js +1 -0
  29. package/out/chunk-JMG5DXII.js +2 -0
  30. package/out/chunk-JOXLZXMI.js +1 -0
  31. package/out/chunk-L4CTEMRG.js +2 -0
  32. package/out/chunk-M37X4LCF.js +14 -0
  33. package/out/chunk-M3Y6SLC4.js +1 -0
  34. package/out/chunk-NXATZJQ2.js +1 -0
  35. package/out/{chunk-MYGJBYYJ.js → chunk-ORIP5INC.js} +1 -1
  36. package/out/chunk-PAD2JHZT.js +1 -0
  37. package/out/chunk-QMVOEBWC.js +13 -0
  38. package/out/{chunk-SXV2T5C4.js → chunk-QRKFPLA4.js} +1 -1
  39. package/out/chunk-RRBIJL2B.js +1 -0
  40. package/out/{chunk-GDPCLSOS.js → chunk-SYXT3SFP.js} +1 -1
  41. package/out/chunk-TOXMUOIW.js +5 -0
  42. package/out/chunk-UBOCLLF2.js +1 -0
  43. package/out/chunk-UCP3JRE2.js +1 -0
  44. package/out/{chunk-JEFZTVNX.js → chunk-VC72ZO3P.js} +1 -1
  45. package/out/chunk-VRX2APNA.js +9 -0
  46. package/out/{chunk-NE2UGKRJ.js → chunk-VZMELPVL.js} +4 -3
  47. package/out/{chunk-YA4ETCFU.js → chunk-WHVXTJHK.js} +1 -1
  48. package/out/chunk-WMFDQS2L.js +11 -0
  49. package/out/chunk-WNSVBOSO.js +41 -0
  50. package/out/chunk-WREU7JAG.js +1 -0
  51. package/out/chunk-Y5ZHFNBD.js +2 -0
  52. package/out/chunk-YF4M5OCI.js +1 -0
  53. package/out/chunk-Z667U2UJ.js +1 -0
  54. package/out/chunk-ZQHLECTI.js +1 -0
  55. package/out/client-managed-import.js +1 -1
  56. package/out/client-managed.js +27 -26
  57. package/out/compare.js +14 -14
  58. package/out/dialogs.js +36 -51
  59. package/out/graph.js +17 -15
  60. package/out/index.html +26 -10
  61. package/out/prism.js +1 -1
  62. package/out/scan.js +2 -2
  63. package/out/terminal.js +232 -232
  64. package/out/view.css +1 -1
  65. package/out/view.js +15 -15
  66. package/package.json +11 -7
  67. package/risk/actions/resolve.js +36 -5
  68. package/risk/index.d.ts +20 -2
  69. package/risk/npm/malware.js +6 -4
  70. package/risk/npm/registry.js +8 -6
  71. package/server-managed/bundle-advisories.ts +56 -74
  72. package/server-managed/bundle-build-worker.js +61 -4
  73. package/server-managed/bundle-build.ts +13 -4
  74. package/server-managed/bundle-dependency-reviews.ts +74 -0
  75. package/server-managed/bundle-validation.ts +32 -0
  76. package/server-managed/db-methods.ts +51 -16
  77. package/server-managed/db-neon.ts +18 -2
  78. package/server-managed/db.ts +11 -2
  79. package/server-managed/github-issue-links.ts +151 -47
  80. package/server-managed/github-pulls.ts +34 -15
  81. package/server-managed/http.ts +227 -12
  82. package/server-managed/index.ts +13 -1
  83. package/server-managed/managed-issues.ts +29 -15
  84. package/server-managed/npm-insights.ts +4 -3
  85. package/server-managed/npm-kept.ts +4 -0
  86. package/server-managed/package-entry-points.ts +37 -9
  87. package/server-managed/pretty-print.ts +7 -5
  88. package/server-managed/public-workspace.ts +2 -2
  89. package/server-managed/repository-actions.ts +7 -4
  90. package/server-managed/repository-browser.ts +11 -4
  91. package/server-managed/repository-risk-audit.ts +4 -5
  92. package/server-managed/repository-risk.ts +4 -4
  93. package/server-managed/sql.ts +2 -1
  94. package/server-managed/stasis-config.ts +46 -0
  95. package/server-managed/team-app-summaries.ts +54 -0
  96. package/server-managed/team-app.ts +52 -31
  97. package/server-managed/team-reports.ts +27 -7
  98. package/server-managed/upstream-cache.ts +41 -32
  99. package/server-managed/workspace-shares.ts +3 -1
  100. package/out/chunk-2ZDZWLFY.js +0 -1
  101. package/out/chunk-7VAWINQF.js +0 -6
  102. package/out/chunk-FMXWXDR4.js +0 -36
  103. package/out/chunk-IZ7POWI3.js +0 -18
  104. package/out/chunk-LJ7XRXFU.js +0 -52
  105. package/out/chunk-QB4CBOX2.js +0 -1
  106. package/out/chunk-TQJDYHVE.js +0 -2
  107. package/out/chunk-TSIFIFBX.js +0 -232
  108. package/out/chunk-VH4XMZIW.js +0 -2
  109. package/out/chunk-WYLQWYLA.js +0 -1
@@ -1,2 +0,0 @@
1
- var e=/[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}]/gu,t=(e,t)=>e.length>t?e.slice(0,e.codePointAt(t-1)>65535?t-1:t):e,n=e=>`U+${e.codePointAt(0).toString(16).toUpperCase().padStart(4,`0`)}`,r=t=>JSON.stringify(t).replaceAll(e,e=>`\\u${e.codePointAt(0).toString(16).padStart(4,`0`)}`);function i(e){let n=t(e,64);return n===e?r(e):`${r(n)}...`}var a=class extends Error{constructor(e,t){super(t===void 0?e:`${e} at line ${t+1}`),this.name=new.target.name,this.line=t}},o=class extends Error{constructor(e,t){super(t===void 0?e:`${t}: ${e}`),this.name=`LockfileError`,this.where=t}},s=(e,t)=>{throw new o(e,t)};function c(e,t){try{return e()}catch(e){return t(e)}}function l(e){let n=t(e,200);return r(n===e?e:`${n}\u2026`)}var u=/^[A-Za-z_$][\w$]*$/u;function d(e,t){return u.test(t)?e===``?t:`${e}.${t}`:`${e}[${l(t)}]`}var f=(e,t)=>new o(`${e} at line ${Math.max(t,0)+1}`),p=/[\p{Cc}\p{Cs}\uFEFF\uFFFE\uFFFF\u2028\u2029]/u,m=[`<<<<<<<`,`=======`,`>>>>>>>`];function h(e,t){if(m.every(t=>e.includes(t)))throw new o(`${t} reads a file with ${m.map(e=>l(e)).join(`, `)} in it as a merge conflict`)}function g(e,t){let n=/^\{(\r?\n)([\t ]+)"/u.exec(e);if(n===null)throw f(`expected "{" alone on the first line and an indented key on the next, as ${t} writes the file`,0);return n.slice(1)}function _(e,t){t.lastIndex=e.pos;let n=t.exec(e.text);return n!==null&&(e.pos=t.lastIndex),n}var v=(e,t)=>t<e.length?l(e.slice(t)):`the end of the line`,y=e=>/^ */u.exec(e)[0].length,b=2**20,x=(e,t)=>({text:e,forbidden:t,pos:0,number:-1,line:void 0,crlf:void 0});function S(e){let{text:t,pos:r}=e;if(e.line=void 0,r>=t.length)return;let i=t.indexOf(`
2
- `,r);i===-1&&(i=t.length),e.pos=i+1,e.number++;let a=i<t.length&&t[i-1]===`\r`,o=t.slice(r,a?i-1:i);if(o.length>b)throw f(`a line longer than ${b} characters`,e.number);let s=e.forbidden.exec(o)?.[0];if(s!==void 0)throw f(`${n(s)} is not allowed`,e.number);if(i<t.length&&a!==(e.crlf??=a))throw f(`a ${a?`CRLF`:`LF`} line end, after ${e.crlf?`CRLF`:`LF`} ones`,e.number);e.line=o}function C(e,t,n){let r=t+1;for(;r<e.length&&e[r]!==`"`;)r+=e[r]===`\\`?2:1;if(r>=e.length)throw f(`a string with no closing quote`,n);let i=e.slice(t,++r);if(!i.includes(`\\`))return[i.slice(1,-1),r];let a=c(()=>JSON.parse(i),()=>{throw f(`${l(i)} is not a string as JSON writes it`,n)});if(JSON.stringify(a)!==i)throw f(`${l(i)} is not written as JSON writes ${l(a)}`,n);return[a,r]}export{n as a,i as b,a as c,o as d,s as e,c as f,l as g,d as h,f as i,p as j,h as k,g as l,_ as m,v as n,y as o,b as p,x as q,S as r,C as s};
@@ -1 +0,0 @@
1
- import{a as e}from"./chunk-GO7FT4OD.js";import{c as t,d as n,e as r,h as i,i as a,j as o,m as s,n as c,o as l}from"./chunk-TQJDYHVE.js";import{i as u}from"./chunk-4HI2MSAV.js";import"./chunk-PXK7EU4V.js";import{a as d,c as f}from"./chunk-JCIIBLKR.js";import{k as p,o as m,p as h,u as g}from"./chunk-7VAWINQF.js";import{b as _}from"./chunk-IYPY47MC.js";import"./chunk-SXV2T5C4.js";import"./chunk-TUII34K2.js";import"./chunk-OOJM4CTU.js";function v(e){if(typeof e!=`string`)throw TypeError(`a text must be a string, not ${typeof e}`);if(!e.isWellFormed())throw TypeError(`a text must be a well-formed string`);return{proven:!1,reason:`unsupported`,at:null}}var y=e=>e.subarray(0,8e3).includes(0),b=(e,t)=>(e+Math.imul(t,97)>>>0)%107927,x=e=>Uint8Array.from({length:256},(t,n)=>Number(n===10||e.includes(String.fromCodePoint(n)))),S=x(``),C=x(`,;={}`);function w(e,t=S){let n=!y(e),r=new Map,i=(e,t)=>r.set(e,(r.get(e)??0)+t),a=0,o=0,s=0;for(let r=0;r<e.length;r++){let c=e[r];if(n&&c===13&&e[r+1]===10)continue;let l=a;a=(a<<7^o>>>25)+c>>>0,o=(o<<7^l>>>25)>>>0,!(++s<64&&t[c]===0)&&(i(b(a,o),s),s=0,a=0,o=0)}s>0&&i(b(a,o),s);let c=Uint32Array.from(r.keys()).sort();return{hashes:c,bytes:Float64Array.from(c,e=>r.get(e)),total:r.values().reduce((e,t)=>e+t,0)}}function T(e,t){let n=0;for(let r=0,i=0;r<e.hashes.length&&i<t.hashes.length;)e.hashes[r]<t.hashes[i]?r++:e.hashes[r]>t.hashes[i]?i++:n+=Math.min(e.bytes[r++],t.bytes[i++]);return n}function E(e,t,n){let r=0,i=e.total,a=t.total;for(let o=0,s=0;o<e.hashes.length&&s<t.hashes.length;)if(e.hashes[o]<t.hashes[s]?i-=e.bytes[o++]:(e.hashes[o]>t.hashes[s]||(r+=Math.min(e.bytes[o],t.bytes[s]),i-=e.bytes[o++]),a-=t.bytes[s++]),(r+Math.min(i,a))*6e4<n)return 0;return r}function ee(e,t,n,r,i=!1){if(e===null||t===null||t.length===0)return 0;let a=Math.abs(e.length-t.length),o=Math.max(e.length,t.length);if(o*(6e4-n)<a*6e4)return 0;let s=r(e),c=r(t),l=i?E(s,c,n*o):T(s,c);return Math.trunc(l*6e4/o)}var D=/^[\w-]{6,}$/u,O=/[\dA-Z]/u,te=/^(?:\.[\w-]+)+$/u,ne=/^[\w-]{8,32}$/u;function k(e){let t=[];for(let n=e.length-1;n>0;n--){if(e[n]!==`-`&&e[n]!==`.`)continue;let r=e.indexOf(`.`,n+1),i=e.slice(r),a=e.slice(n+1,r);r!==-1&&ne.test(a)&&te.test(i)&&/[A-Za-z]/u.test(a)&&O.test(a)&&t.push([e.slice(0,n),a,i])}return t}var re=e=>e.replaceAll(/\d/gu,`0`).replaceAll(/[a-z]/gu,`a`).replaceAll(/[A-Z]/gu,`A`);function ie(e,t){let n=k(t);for(let[t,r,i]of k(e)){let e=n.find(e=>e[2]===i);if(e&&e[1]!==r)return e[0]===t&&re(e[1])!==re(r)}return!1}function ae(e){let t=e.lastIndexOf(`/`),n=e.slice(t+1),r=n.lastIndexOf(`.`),i=r>0?n.slice(r):``;return{name:n,key:`${e.slice(0,t+1)}\0${i}\0${n.length}`}}function oe(e,t){let n=e.length,r=0;for(;r<e.length&&e[r]===t[r];)r++;for(;n>r&&e[n-1]===t[n-1];)n--;for(;r>0&&!`-._`.includes(e[r-1]);)r--;for(;n<e.length&&e[n]!==`.`;)n++;let i=e.slice(r,n),a=t.slice(r,n);return r>0&&D.test(i)&&D.test(a)&&(O.test(i)||O.test(a))}function se({sources:e,dests:t,pairs:n,used:r,record:i,punctuatedScoreOf:a},{remaining:o,open:s},c,l){let u=(e,t)=>new Map(t.filter(t=>e[t].type===`file`).map(t=>[t,ae(e[t].path)])),d=u(t,s),f=u(e,o),p=Map.groupBy(f.keys(),e=>f.get(e).key),m=Map.groupBy(d.keys(),e=>d.get(e).key),h=[];for(let[e,t]of m){let n=p.get(e)??[];for(let e of t)for(let t of n)oe(f.get(t).name,d.get(e).name)&&h.push({s:t,d:e})}let g=Map.groupBy(h,({d:e})=>e),_=Map.groupBy(h,({s:e})=>e),v=[];for(let{s:e,d:t}of h){let n=_.get(e).length===1&&g.get(t).length===1&&ie(f.get(e).name,d.get(t).name),r=a(e,t,n?0:c);(n||r>=c)&&v.push({s:e,d:t,score:r})}let y=[],b=new Set,x=new Set;for(let e of v.sort((e,t)=>t.score-e.score))n.has(e.d)||r.has(e.s)||(x.has(e.s)||b.has(e.d)||l(e)?(y.push(e),x.add(e.s),b.add(e.d)):i(e.d,e.s,e.score));return y}function ce(e,t){let n=e.length;if(n!==t.length)return!1;let r=0;if(n>=32&&(e.byteOffset&3)==(t.byteOffset&3)){for(let n=4-(e.byteOffset&3)&3;r<n;r++)if(e[r]!==t[r])return!1;let i=n-r>>>2,a=new Int32Array(e.buffer,e.byteOffset+r,i),o=new Int32Array(t.buffer,t.byteOffset+r,i);for(let e=0;e<i;e++)if(a[e]!==o[e])return!1;r+=i*4}for(;r<n;r++)if(e[r]!==t[r])return!1;return!0}var A=class extends Error{constructor(e,t,n){let r=n===void 0?``:` in the ${n} tree`;super(t===void 0?e:`${e}: ${JSON.stringify(t)}${r}`),this.name=`CompareError`,this.path=t,this.tree=n}},le=new Set([`file`,`contiguous-file`]),ue=new Set([`fifo`,`character-device`,`block-device`]),de=/(?:^|\/)\.{0,2}(?:\/|$)/u;function fe(e){if(!Number.isInteger(e)||e<0||e>4095)throw RangeError(`a mode must be an integer from 0 to 0o7777, not ${e}`)}function pe(e,t,n,r){if(typeof e!=`string`)throw TypeError(`an entry's name must be a string, not ${typeof e}`);if(e!==`.`||t!==`directory`){if(r?e===``:de.test(e))throw new A(r?`a name must not be empty`:"a name must be a relative path with no empty, `.` or `..` segment",e,n);if(!e.isWellFormed())throw new A(`a name must be well-formed Unicode`,e,n)}}function me(e,t,n){if(typeof e!=`string`||e===``)throw new A(`a link must name its target`,t,n);if(!e.isWellFormed())throw new A(`a link target must be well-formed Unicode`,t,n);return e}function he(e){if(e===void 0)return new Uint8Array;if(e instanceof Uint8Array)return e;if(typeof e!=`string`)throw TypeError(`a file's data must be a string or a Uint8Array, not ${typeof e}`);if(!e.isWellFormed())throw TypeError(`a file's text must be well-formed Unicode`);return e}var j=e=>typeof e==`string`?u(e):e;function ge(e,t,n){if(typeof e!=`object`||!e)throw TypeError(`an entry must be an object, not ${e===null?`null`:typeof e}`);let{name:r,type:i=`file`,mode:a,linkname:o,data:s}=e;if(pe(r,i,t,n),a!==void 0&&fe(a),le.has(i))return{path:r,type:`file`,mode:a??420,data:he(s)};if(i===`symlink`||i===`hardlink`)return{path:r,type:i,target:me(o,r,t)};if(i===`directory`)return{path:r,type:i};throw ue.has(i)?new A(`a ${i} is neither a file nor a link`,r,t):TypeError(`${JSON.stringify(i)} is not an entry type`)}function M(e,t){return e.type===t.type?e.type===`symlink`?e.target===t.target:e.data===t.data?!0:typeof e.data==`string`&&typeof t.data==`string`?!1:ce(j(e.data),j(t.data)):!1}function _e(e,t,n){let r=new Set([e.path]),i=t.get(e.target);for(;i?.type===`hardlink`;){if(r.has(i.path))throw new A(`a hard link leads back to itself`,e.path,n);r.add(i.path),i=t.get(i.target)}if(i===void 0||i.type===`directory`)throw new A(`a hard link must name a file or a link in the tree`,e.path,n);return{...i,path:e.path}}function N(e,t,n){let r=new Map;for(let i of e){let e=ge(i,t,n);if(e.type!==`directory`||e.path!==`.`){if(r.has(e.path))throw new A(`a name is given twice`,e.path,t);r.set(e.path,e)}}let i=new Map;for(let[e,a]of r){for(let i=n?-1:e.lastIndexOf(`/`);i>0;i=e.lastIndexOf(`/`,i-1)){let n=r.get(e.slice(0,i));if(n!==void 0&&n.type!==`directory`)throw new A(`a path lies under a ${n.type===`symlink`?`link`:`file`}`,e,t)}a.type===`hardlink`?i.set(e,_e(a,r,t)):a.type!==`directory`&&i.set(e,a)}return i}var ve=100,ye=4,P=e=>e.slice(e.lastIndexOf(`/`)+1);function F(t,n){if(t.type===`symlink`)return`l${t.target}`;let r=n(t);return`f${r.length}:${e(r)}`}function be({sources:e,dests:t,sourceNames:n,destNames:r,used:i,record:a,bytes:o}){let s=Map.groupBy(e.keys(),t=>F(e[t],o));for(let c=0;c<t.length;c++){let l=-1,u=ve;for(let a of s.get(F(t[c],o))??[])if(!i.has(a)&&M(e[a],t[c])&&((l===-1||n[a]===r[c])&&(l=a),n[a]===r[c]||--u===0))break;l!==-1&&a(c,l,6e4)}}var xe=new Map([[`.ts`,`.js`],[`.mts`,`.mjs`],[`.cts`,`.cjs`],[`.tsx`,`.jsx`]]),Se=new Map([...[`.js`,`.mjs`,`.cjs`,`.jsx`,`.ts`,`.mts`,`.cts`,`.tsx`].map(e=>[e,`script`]),...[`.css`,`.scss`,`.sass`,`.less`].map(e=>[e,`style`])]);function I(e){let t=e.split(`/`),n=t.pop(),r=n.lastIndexOf(`.`);return r>0?{dirs:t,stem:n.slice(0,r),extension:n.slice(r)}:{dirs:t,stem:n,extension:``}}function L(e){let{dirs:t,stem:n,extension:r}=I(e);return JSON.stringify([t.map(e=>e===`lib`||e===`src`?null:e),n,xe.get(r)??r])}function Ce(e){let{dirs:t,stem:n,extension:r}=I(e),i=[n,Se.get(r)??r],a=t.lastIndexOf(`node_modules`),o=a===-1?0:a+(t[a+1]?.startsWith(`@`)?3:2),s=[JSON.stringify([...i,t])];for(let e=o;e<t.length;e++)s.push(JSON.stringify([...i,t.toSpliced(e,1,null)]));return s}var R=(e,t)=>Math.max(t,e+Math.trunc((6e4-e)/2));function z({pairs:e,used:t,scoreOf:n},{remaining:r,open:i},{s:a,d:o,score:s},c){let l=R(s,c);return i.some(t=>t!==o&&!e.has(t)&&n(a,t,l)>=l)||r.some(e=>e!==a&&!t.has(e)&&n(e,o,l)>=l)}function we(e,t,n,r){let{sources:i,dests:a,pairs:o,used:s,record:c,scoreOf:l}=e,u=Map.groupBy(t.remaining.filter(e=>i[e].type===`file`),e=>L(i[e].path)),d=t.open.filter(e=>a[e].type===`file`).flatMap(e=>(u.get(L(a[e].path))??[]).map(t=>({s:t,d:e,score:l(t,e,0)})));for(let i of d.sort((e,t)=>t.score-e.score))!o.has(i.d)&&!s.has(i.s)&&!(n&&z(e,t,i,r))&&c(i.d,i.s,i.score)}function Te(e,t,n,r){let{sources:i,dests:a,pairs:o,used:s,record:c,scoreOf:l}=e,u=new Map,d=(e,t,n)=>new Map(t.filter(t=>e[t].type===`file`).map(t=>{let r=Ce(e[t].path);for(let e of r)(u.get(e)??u.set(e,{sources:[],dests:[]}).get(e))[n].push(t);return[t,r]})),f=d(a,t.open.filter(e=>!o.has(e)),`dests`),p=d(i,t.remaining.filter(e=>!s.has(e)),`sources`),m=(e,t)=>{let n=new Set(e.flatMap(e=>u.get(e)[t]));return n.size===1?[...n][0]:-1};for(let[i,a]of p){let o=m(a,`dests`);if(o===-1||m(f.get(o),`sources`)!==i)continue;let s={s:i,d:o,score:l(i,o,0)};n&&z(e,t,s,r)||c(o,i,s.score)}}function Ee(e,t,n){let r=H(e),i=t<6e4&&r.remaining.length*r.open.length<=n*n;we(e,r,i,t),Te(e,r,i,t)}function B(e,t){let n=new Map;for(let r of t)n.set(e[r],n.has(e[r])?-1:r);return n}function De({sourceNames:e,destNames:t,record:n,scoreOf:r},{remaining:i,open:a},o){let s=B(t,a),c=B(e,i);for(let t of i){let i=s.get(e[t]);if(i===void 0||i===-1||c.get(e[t])===-1)continue;let a=r(t,i,o);a>=o&&n(i,t,a)}}var V=(e,t)=>t.score-e.score||t.nameScore-e.nameScore;function Oe(e,t){if(e.length<ye){e.push(t);return}let n=0;for(let t=1;t<e.length;t++)V(e[t],e[n])>0&&(n=t);V(e[n],t)>0&&(e[n]=t)}function ke({sourceNames:e,destNames:t,pairs:n,used:r,record:i,scoreOf:a},{remaining:o,open:s},c,l){let u=[];for(let n of s){let r=[];for(let i of o)Oe(r,{score:a(i,n,c),nameScore:+(e[i]===t[n]),dst:n,src:i});u.push(...r)}let d=0,f=e=>{for(;d<l.length&&R(l[d].score,c)>e;d++){let{s:e,d:t,score:a}=l[d];!n.has(t)&&!r.has(e)&&i(t,e,a)}};for(let{dst:e,src:t,score:a}of u.sort(V)){if(a<c)break;f(a),!n.has(e)&&!r.has(t)&&i(e,t,a)}f(-1/0)}var H=({sources:e,dests:t,pairs:n,used:r})=>({remaining:e.keys().filter(e=>!r.has(e)).toArray(),open:t.keys().filter(e=>!n.has(e)).toArray()}),U=e=>e+Math.trunc(.5*(6e4-e));function W(e,t,{minimum:n,limit:r,byPath:i}){let a=new Map,o=new Set;if(e.length===0||t.length===0)return a;let s=new Map,c=new Map,l=new Map,u=e=>e.type===`file`?c.get(e)??c.set(e,j(e.data)).get(e):null,d=e=>s.get(e)??s.set(e,w(e)).get(e),f=e=>l.get(e)??l.set(e,w(e,C)).get(e),p={sources:e,dests:t,pairs:a,used:o,sourceNames:e.map(e=>P(e.path)),destNames:t.map(e=>P(e.path)),record(e,t,n){a.set(e,{source:t,score:n}),o.add(t)},bytes:u,scoreOf:(n,r,i)=>ee(u(e[n]),u(t[r]),i,d),punctuatedScoreOf:(n,r,i)=>ee(u(e[n]),u(t[r]),i,f,!0)};if(be(p),i&&Ee(p,n,r),n>=6e4)return a;De(p,H(p),U(n));let m=H(p);if(m.remaining.length*m.open.length>r*r)return a;let h=i?se(p,m,U(n),e=>z(p,m,e,n)):[];return ke(p,H(p),n,h),a}var Ae=50,je=1e3;function G(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e[r]!==t[r])return e.codePointAt(r)-t.codePointAt(r);return e.length-t.length}function Me(e){if(e===!1)return null;let t=e===!0?Ae:e;if(typeof t!=`number`)throw TypeError(`renames must be a boolean or a percentage, not ${typeof e}`);if(!(t>0&&t<=100))throw RangeError(`renames must be a percentage above 0 and at most 100, not ${e}`);return Math.max(1,Math.trunc(6e4*t/100))}function Ne({renamesByPath:e,renameLimit:t,renameGroup:n,paths:r,lines:i}){if(typeof e!=`boolean`)throw TypeError(`renamesByPath must be a boolean, not ${typeof e}`);if(t!==1/0&&!(Number.isSafeInteger(t)&&t>=0))throw RangeError(`renameLimit must be a whole number or Infinity, not ${t}`);if(n!==null&&typeof n!=`function`)throw TypeError(`renameGroup must be a function, not ${typeof n}`);if(r!==`tree`&&r!==`keys`)throw RangeError(`paths must be 'tree' or 'keys', not ${r}`);if(typeof i!=`boolean`)throw TypeError(`lines must be a boolean, not ${typeof i}`)}var Pe=(e,t)=>M(e,t)&&(e.type!==`file`||e.mode===t.mode),K=(e,t,n,r=null)=>({status:e,old:t,new:n,similarity:r}),Fe=/\.d\.(?:[^./]+\.)?[cm]?ts$/u,q=e=>e.endsWith(`.mts`)?`module`:e.endsWith(`.cts`)?`commonjs`:null,Ie=/^export\s*\{\s*\}\s*;?$/u;function J(e){if(e===null)return{proven:!0,runtime:``,loads:!1};let n=t(e);try{return n===void 0?{proven:!1}:v(n)}catch{return{proven:!1}}}function Le(e){if(![e.old,e.new].filter(e=>e!==null).every(e=>e.type===`file`&&Fe.test(e.path))||e.old&&e.new&&e.old.mode!==e.new.mode)return e;let t=J(e.new),n=J(e.old);return!n.proven||!t.proven||n.runtime!==t.runtime&&!(e.old===null&&Ie.test(t.runtime))||n.loads&&e.old&&e.new&&e.old.path!==e.new.path&&q(e.old.path)!==q(e.new.path)?e:{...e,typeOnly:!0}}function Re(e,t){let n=[],r=[],i=[];for(let[n,a]of e){let e=t.get(n);e===void 0?i.push(a):e.type===a.type?Pe(a,e)||r.push(K(`modified`,a,e)):r.push(K(`type-changed`,a,e))}for(let[r,i]of t)e.has(r)||n.push(i);return i.sort((e,t)=>G(e.path,t.path)),n.sort((e,t)=>G(e.path,t.path)),{changes:r,deleted:i,added:n}}function ze(e,t,{group:n,...r}){if(n===null)return W(e,t,r);let i=new Map,a=e=>Map.groupBy(e.keys(),t=>n(e[t].path)),o=a(e);for(let[n,s]of a(t)){let a=o.get(n);if(a!==void 0)for(let[n,{source:o,score:c}]of W(a.map(t=>e[t]),s.map(e=>t[e]),r))i.set(s[n],{source:a[o],score:c})}return i}function Be(e,t,{renames:i=!0,renamesByPath:a=!0,renameLimit:o=je,renameGroup:s=null,paths:c=`tree`,lines:l=!0,horizon:u,whitespace:d,ignoreCase:f}={}){let p=Me(i);Ne({renamesByPath:a,renameLimit:o,renameGroup:s,paths:c,lines:l});let m=n({horizon:u,whitespace:d,ignoreCase:f}),h=c===`keys`,{changes:g,deleted:_,added:v}=Re(N(e,`old`,h),N(t,`new`,h)),y=p===null?new Map:ze(_,v,{minimum:p,limit:o,byPath:a,group:s});for(let[e,t]of v.entries()){let n=y.get(e);g.push(n===void 0?K(`added`,null,t):K(`renamed`,_[n.source],t,Math.trunc(n.score*100/6e4)))}let b=new Set(y.values().map(({source:e})=>e));for(let[e,t]of _.entries())b.has(e)||g.push(K(`deleted`,t,null));return g.sort((e,t)=>G((e.new??e.old).path,(t.new??t.old).path)),(l?g.map(e=>({...e,...r(e.old,e.new,m)})):g).map(Le)}function Y(e,t,n){let r=new Map,o=new Set,s=0;for(let a of e){let e=i(n,a);e===null||!t.has(e)||(r.set(a,e),o.add(e),e!==a&&s++)}for(let n of e)r.has(n)||!t.has(n)||o.has(n)||(r.set(n,n),o.add(n));let c=r.size;for(let s of e){if(r.has(s))continue;let e=i(n,s)??a(n,s);for(;t.has(e)||o.has(e);)e=`../${e}`;r.set(s,e),o.add(e)}return{paths:r,paired:c,moved:s}}function Ve(e,t){let n=new Set(e),r=new Set(t),i=(e,t)=>{let n=new Map;for(let r of e)for(let e=r.indexOf(`/`);e!==-1;e=r.indexOf(`/`,e+1))t.has(r.slice(e+1))&&n.set(r.slice(0,e+1),(n.get(r.slice(0,e+1))??0)+1);let r=null,i=!1;for(let[e,t]of n)t>(n.get(r)??0)?[r,i]=[e,!1]:t===n.get(r)&&(i=!0);return i?null:r},a=Y(n,r,null).paired,o=[[{base:``,other:i(r,n)},n],[{base:i(n,r),other:``},r]].filter(([e])=>e.base!==null&&e.other!==null).map(([e,t])=>({root:e,side:t,...Y(n,r,e)})).filter(({side:e,paired:t,moved:n})=>t>a&&n*2>=e.size);return o.length===2&&o[0].paired===o[1].paired?null:o.toSorted((e,t)=>t.paired-e.paired)[0]?.root??null}function X(e,t){let n=[...e],r=new Set(t),i=Ve(n,r);return{root:i,paths:Y(n,r,i).paths}}function He(e,t,n){if(!e&&!t)return null;let r=Map.groupBy([...e??[]],([,e])=>e),i=new Map([...r].map(([e,t])=>[e,o(n,e,t.map(([t])=>t.slice(e.length+1)))]));return new Map([...[...e??[]].map(([e,t])=>[n.paths.get(e)??e,i.get(t)]),...t??[]])}function Ue(e,t,n=new Map,r=new Map,i=null){let a=e=>{let t=n.get(e)??r.get(e);return t===void 0?[...new Set([e,Xe(i,e)??e])]:[t]},o=[];for(let n of e.values()){let e=a(n.parent).map(e=>t.get(c(e,n.specifier,n.conditions,n.platform))).find(Boolean);if(e&&!a(n.target).includes(e.target)){let{target:t,...i}=e;o.push({...i,baseTarget:r.get(n.target)??n.target,otherTarget:t})}}return o.sort((e,t)=>e.key.localeCompare(t.key)),{changed:o,totalChanges:o.length}}function Z(e){return p(e)??0}function Q(e,t){return e===t||e?.format===`base64`&&t?.format===`base64`&&e.data===t.data||e?.format===`digest`&&t?.format===`digest`&&e.digest===t.digest}function We(e){if(e?.kind!==`stasis`||!e.bundle)return null;let{formats:t,executable:n,entries:r}=e.bundle;return e=>({format:t?.get(e),executable:n?.has(e)??!1,entry:r?.has(e)??!1})}function Ge(e,t){return!e||!t?[]:[`format`,`executable`,`entry`].filter(n=>e[n]!==t[n]).map(n=>({field:n,from:e[n],to:t[n]}))}function Ke(e){return(t,n)=>Math.abs(n.delta)-Math.abs(t.delta)||t[e].localeCompare(n[e])}function $(e){return(t,n)=>n.bytes-t.bytes||t[e].localeCompare(n[e])}function qe(e,t){return typeof e==`string`?`\0text\0${e.toWellFormed()}`:e?.format===`base64`?`\0base64\0${e.data}`:e?.format===`digest`?`\0digest\0${e.digest}`:`\0none\0${t}`}var Je=250;function Ye(e,t,n,r,i){let a=(e,t,n)=>e.filter(({path:e})=>e!==``&&e.isWellFormed()).map(({path:e},r)=>({name:e,data:qe(t.get(e),`${n}${r}`)})),o={paths:`keys`,renameGroup:i,renameLimit:Je,lines:!1},s=Be(a(e,n,`a`),a(t,r,`b`),o);return new Map(s.filter(({status:e})=>e===`renamed`).map(e=>[e.old.path,e.new.path]))}function Xe(e,t){return e?e.base===``?`${e.other}${t}`:t.startsWith(e.base)?t.slice(e.base.length):null:t}function Ze(){return{baseBytes:0,otherBytes:0,onlyBaseFiles:0,onlyOtherFiles:0,changedFiles:0}}function Qe(e,t,n,r=X(e.keys(),t.keys()),i=[]){let{root:a,paths:o}=r,s=new Map([...o].map(([e,t])=>[t,e]));e=new Map([...e].map(([e,t])=>[o.get(e),t]));let c=e=>s.get(e)===e?{}:{basePath:s.get(e)},l=(e,t)=>{let n=Ge(i[0]?.(e),i[1]?.(t));return n.length>0?{meta:n}:{}},u=[],d=[],f=[],p=0,m=0,h=0,g=0,_=0,v=0,y=new Map,b=e=>{let t=n(e),r=y.get(t);return r||(r=Ze(),y.set(t,r)),r},x=new Set([...e.keys(),...t.keys()]);for(let n of x){let r=e.has(n),i=t.has(n),a=b(n);if(r&&i){let r=e.get(n),i=t.get(n),o=Q(r,i),u=l(s.get(n),n),d=Z(r),h=o?d:Z(i);if(p+=d,m+=h,a.baseBytes+=d,a.otherBytes+=h,o&&!u.meta)v++;else{let e=h-d;f.push({path:n,...c(n),baseBytes:d,otherBytes:h,delta:e,...u,...o?{modified:!1}:{}}),_+=e,a.changedFiles++}}else if(r){let t=Z(e.get(n));p+=t,h+=t,a.baseBytes+=t,a.onlyBaseFiles++,u.push({path:n,...c(n),bytes:t})}else{let e=Z(t.get(n));m+=e,g+=e,a.otherBytes+=e,a.onlyOtherFiles++,d.push({path:n,bytes:e})}}let S=Ye(u,d,e,t,n);if(S.size>0){let n=new Set(S.values());for(let[n,r]of S){let i=e.get(n),a=t.get(r),o=Q(i,a),c=Z(i),u=o?c:Z(a);h-=c,g-=u,f.push({path:r,renamedFrom:n,basePath:s.get(n),baseBytes:c,otherBytes:u,delta:u-c,modified:!o,...l(s.get(n),r)}),_+=u-c;let d=b(n);d.onlyBaseFiles--,d.onlyOtherFiles--,d.changedFiles++}u.splice(0,u.length,...u.filter(e=>!S.has(e.path))),d.splice(0,d.length,...d.filter(e=>!n.has(e.path)))}let C=[],w=[],T=[],E=[];for(let[e,t]of y){let n=t.baseBytes>0||t.onlyBaseFiles>0||t.changedFiles>0,r=t.otherBytes>0||t.onlyOtherFiles>0||t.changedFiles>0,i=t.onlyBaseFiles+t.onlyOtherFiles+t.changedFiles;n&&!r?C.push({pkg:e,bytes:t.baseBytes}):r&&!n?w.push({pkg:e,bytes:t.otherBytes}):i>0||t.baseBytes!==t.otherBytes?T.push({pkg:e,baseBytes:t.baseBytes,otherBytes:t.otherBytes,delta:t.otherBytes-t.baseBytes}):E.push({pkg:e,bytes:t.baseBytes})}return u.sort($(`path`)),d.sort($(`path`)),f.sort(Ke(`path`)),C.sort($(`pkg`)),w.sort($(`pkg`)),T.sort(Ke(`pkg`)),{totals:{baseFiles:e.size,baseBytes:p,otherFiles:t.size,otherBytes:m,onlyBaseFiles:u.length,onlyBaseBytes:h,onlyOtherFiles:d.length,onlyOtherBytes:g,changedFiles:f.length,renamedFiles:S.size,changedDelta:_,unchangedFiles:v,fileDelta:t.size-e.size,byteDelta:m-p,identical:u.length===0&&d.length===0&&f.length===0},files:{onlyBase:u,onlyOther:d,changed:f,root:a,basePaths:o},packages:{onlyBase:C,onlyOther:w,changed:T,unchanged:E}}}function $e(e,t,n=null){let[r,i]=[e,t],a=s(r,n),o=s(i,n),c=X(a.keys(),o.keys()),u=He(m(r),m(i),c),p=Qe(a,o,e=>_(e,{packageDir:u?.get(e)}),c,[We(r),We(i)]),v=g(r),y=g(i),b=(e,t)=>{let n=0;for(let r of t)n+=e.get(r)??0;return n};Object.assign(p.totals,{baseLines:b(v,a.keys()),otherLines:b(y,o.keys())});for(let e of p.files.onlyBase)e.lines=v.get(e.basePath??e.path)??0;for(let e of p.files.onlyOther)e.lines=y.get(e.path)??0;for(let e of p.files.changed)Object.assign(e,{baseLines:v.get(e.basePath??e.path)??0,otherLines:y.get(e.path)??0});p.resolutions=Ue(l(r,n),l(i,n),new Map(p.files.changed.filter(e=>e.renamedFrom!=null).map(e=>[e.basePath,e.path])),p.files.basePaths,p.files.root);let x=e=>_(``,{packageDir:e}),S=h(r,n?a.keys():null,x),C=h(i,n?o.keys():null,x);return p.versionUpdates=f(S,C),p.packageRows=d(p.packages,S,C),p.scope=n??``,p}export{$e as prepareComparison};