diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..8c605db --- /dev/null +++ b/biome.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.0.5/schema.json", + "formatter": { + "enabled": true, + "indentStyle": "space" + }, + "linter": { + "enabled": true + } + } \ No newline at end of file diff --git a/bundles/@yarnpkg/plugin-catalogs.js b/bundles/@yarnpkg/plugin-catalogs.js index c1286e4..6e33c9d 100644 --- a/bundles/@yarnpkg/plugin-catalogs.js +++ b/bundles/@yarnpkg/plugin-catalogs.js @@ -3,11 +3,11 @@ module.exports = { name: "@yarnpkg/plugin-catalogs", factory: function (require) { -"use strict";var plugin=(()=>{var Lt=Object.create;var _e=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var wt=Object.getOwnPropertyNames;var kt=Object.getPrototypeOf,Nt=Object.prototype.hasOwnProperty;var fe=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(r,e)=>(typeof require<"u"?require:r)[e]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var ae=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),Ht=(t,r)=>{for(var e in r)_e(t,e,{get:r[e],enumerable:!0})},Ue=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of wt(r))!Nt.call(t,n)&&n!==e&&_e(t,n,{get:()=>r[n],enumerable:!(o=It(r,n))||o.enumerable});return t};var Ee=(t,r,e)=>(e=t!=null?Lt(kt(t)):{},Ue(r||!t||!t.__esModule?_e(e,"default",{value:t,enumerable:!0}):e,t)),Dt=t=>Ue(_e({},"__esModule",{value:!0}),t);var de=ae((Wr,at)=>{"use strict";var z="\\\\/",ot=`[^${z}]`,te="\\.",Zt="\\+",zt="\\?",Se="\\/",Jt="(?=.)",nt="[^/]",He=`(?:${Se}|$)`,st=`(?:^|${Se})`,De=`${te}{1,2}${He}`,er=`(?!${te})`,tr=`(?!${st}${De})`,rr=`(?!${te}{0,1}${He})`,or=`(?!${De})`,nr=`[^.${Se}]`,sr=`${nt}*?`,ir="/",it={DOT_LITERAL:te,PLUS_LITERAL:Zt,QMARK_LITERAL:zt,SLASH_LITERAL:Se,ONE_CHAR:Jt,QMARK:nt,END_ANCHOR:He,DOTS_SLASH:De,NO_DOT:er,NO_DOTS:tr,NO_DOT_SLASH:rr,NO_DOTS_SLASH:or,QMARK_NO_DOT:nr,STAR:sr,START_ANCHOR:st,SEP:ir},ar={...it,SLASH_LITERAL:`[${z}]`,QMARK:ot,STAR:`${ot}*?`,DOTS_SLASH:`${te}{1,2}(?:[${z}]|$)`,NO_DOT:`(?!${te})`,NO_DOTS:`(?!(?:^|[${z}])${te}{1,2}(?:[${z}]|$))`,NO_DOT_SLASH:`(?!${te}{0,1}(?:[${z}]|$))`,NO_DOTS_SLASH:`(?!${te}{1,2}(?:[${z}]|$))`,QMARK_NO_DOT:`[^.${z}]`,START_ANCHOR:`(?:^|[${z}])`,END_ANCHOR:`(?:[${z}]|$)`,SEP:"\\"},ur={alnum:"a-zA-Z0-9",alpha:"a-zA-Z",ascii:"\\x00-\\x7F",blank:" \\t",cntrl:"\\x00-\\x1F\\x7F",digit:"0-9",graph:"\\x21-\\x7E",lower:"a-z",print:"\\x20-\\x7E ",punct:"\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",space:" \\t\\r\\n\\v\\f",upper:"A-Z",word:"A-Za-z0-9_",xdigit:"A-Fa-f0-9"};at.exports={MAX_LENGTH:1024*64,POSIX_REGEX_SOURCE:ur,REGEX_BACKSLASH:/\\(?![*+?^${}(|)[\]])/g,REGEX_NON_SPECIAL_CHARS:/^[^@![\].,$*+?^{}()|\\/]+/,REGEX_SPECIAL_CHARS:/[-*+?.^${}(|)[\]]/,REGEX_SPECIAL_CHARS_BACKREF:/(\\?)((\W)(\3*))/g,REGEX_SPECIAL_CHARS_GLOBAL:/([-*+?.^${}(|)[\]])/g,REGEX_REMOVE_BACKSLASH:/(?:\[.*?[^\\]\]|\\(?=.))/g,REPLACEMENTS:{"***":"*","**/**":"**","**/**/**":"**"},CHAR_0:48,CHAR_9:57,CHAR_UPPERCASE_A:65,CHAR_LOWERCASE_A:97,CHAR_UPPERCASE_Z:90,CHAR_LOWERCASE_Z:122,CHAR_LEFT_PARENTHESES:40,CHAR_RIGHT_PARENTHESES:41,CHAR_ASTERISK:42,CHAR_AMPERSAND:38,CHAR_AT:64,CHAR_BACKWARD_SLASH:92,CHAR_CARRIAGE_RETURN:13,CHAR_CIRCUMFLEX_ACCENT:94,CHAR_COLON:58,CHAR_COMMA:44,CHAR_DOT:46,CHAR_DOUBLE_QUOTE:34,CHAR_EQUAL:61,CHAR_EXCLAMATION_MARK:33,CHAR_FORM_FEED:12,CHAR_FORWARD_SLASH:47,CHAR_GRAVE_ACCENT:96,CHAR_HASH:35,CHAR_HYPHEN_MINUS:45,CHAR_LEFT_ANGLE_BRACKET:60,CHAR_LEFT_CURLY_BRACE:123,CHAR_LEFT_SQUARE_BRACKET:91,CHAR_LINE_FEED:10,CHAR_NO_BREAK_SPACE:160,CHAR_PERCENT:37,CHAR_PLUS:43,CHAR_QUESTION_MARK:63,CHAR_RIGHT_ANGLE_BRACKET:62,CHAR_RIGHT_CURLY_BRACE:125,CHAR_RIGHT_SQUARE_BRACKET:93,CHAR_SEMICOLON:59,CHAR_SINGLE_QUOTE:39,CHAR_SPACE:32,CHAR_TAB:9,CHAR_UNDERSCORE:95,CHAR_VERTICAL_LINE:124,CHAR_ZERO_WIDTH_NOBREAK_SPACE:65279,extglobChars(t){return{"!":{type:"negate",open:"(?:(?!(?:",close:`))${t.STAR})`},"?":{type:"qmark",open:"(?:",close:")?"},"+":{type:"plus",open:"(?:",close:")+"},"*":{type:"star",open:"(?:",close:")*"},"@":{type:"at",open:"(?:",close:")"}}},globChars(t){return t===!0?ar:it}}});var Ae=ae(M=>{"use strict";var{REGEX_BACKSLASH:cr,REGEX_REMOVE_BACKSLASH:lr,REGEX_SPECIAL_CHARS:fr,REGEX_SPECIAL_CHARS_GLOBAL:pr}=de();M.isObject=t=>t!==null&&typeof t=="object"&&!Array.isArray(t);M.hasRegexChars=t=>fr.test(t);M.isRegexChar=t=>t.length===1&&M.hasRegexChars(t);M.escapeRegex=t=>t.replace(pr,"\\$1");M.toPosixSlashes=t=>t.replace(cr,"/");M.isWindows=()=>{if(typeof navigator<"u"&&navigator.platform){let t=navigator.platform.toLowerCase();return t==="win32"||t==="windows"}return typeof process<"u"&&process.platform?process.platform==="win32":!1};M.removeBackslashes=t=>t.replace(lr,r=>r==="\\"?"":r);M.escapeLast=(t,r,e)=>{let o=t.lastIndexOf(r,e);return o===-1?t:t[o-1]==="\\"?M.escapeLast(t,r,o-1):`${t.slice(0,o)}\\${t.slice(o)}`};M.removePrefix=(t,r={})=>{let e=t;return e.startsWith("./")&&(e=e.slice(2),r.prefix="./"),e};M.wrapOutput=(t,r={},e={})=>{let o=e.contains?"":"^",n=e.contains?"":"$",a=`${o}(?:${t})${n}`;return r.negated===!0&&(a=`(?:^(?!${a}).*$)`),a};M.basename=(t,{windows:r}={})=>{let e=t.split(r?/[\\/]/:"/"),o=e[e.length-1];return o===""?e[e.length-2]:o}});var dt=ae((Ur,ht)=>{"use strict";var ut=Ae(),{CHAR_ASTERISK:Pe,CHAR_AT:gr,CHAR_BACKWARD_SLASH:Re,CHAR_COMMA:hr,CHAR_DOT:Ge,CHAR_EXCLAMATION_MARK:Me,CHAR_FORWARD_SLASH:gt,CHAR_LEFT_CURLY_BRACE:Be,CHAR_LEFT_PARENTHESES:je,CHAR_LEFT_SQUARE_BRACKET:dr,CHAR_PLUS:Ar,CHAR_QUESTION_MARK:ct,CHAR_RIGHT_CURLY_BRACE:Rr,CHAR_RIGHT_PARENTHESES:lt,CHAR_RIGHT_SQUARE_BRACKET:br}=de(),ft=t=>t===gt||t===Re,pt=t=>{t.isPrefix!==!0&&(t.depth=t.isGlobstar?1/0:1)},Cr=(t,r)=>{let e=r||{},o=t.length-1,n=e.parts===!0||e.scanToEnd===!0,a=[],u=[],p=[],l=t,h=-1,C=0,L=0,I=!1,j=!1,y=!1,N=!1,ne=!1,Q=!1,E=!1,Z=!1,se=!1,D=!1,H=0,F,d,R={value:"",depth:0,isGlob:!1},c=()=>h>=o,G=()=>l.charCodeAt(h+1),w=()=>(F=d,l.charCodeAt(++h));for(;h0&&(s=l.slice(0,C),l=l.slice(C),L-=C),T&&y===!0&&L>0?(T=l.slice(0,L),i=l.slice(L)):y===!0?(T="",i=l):T=l,T&&T!==""&&T!=="/"&&T!==l&&ft(T.charCodeAt(T.length-1))&&(T=T.slice(0,-1)),e.unescape===!0&&(i&&(i=ut.removeBackslashes(i)),T&&E===!0&&(T=ut.removeBackslashes(T)));let V={prefix:s,input:t,start:C,base:T,glob:i,isBrace:I,isBracket:j,isGlob:y,isExtglob:N,isGlobstar:ne,negated:Z,negatedExtglob:se};if(e.tokens===!0&&(V.maxDepth=0,ft(d)||u.push(R),V.tokens=u),e.parts===!0||e.tokens===!0){let _;for(let O=0;O{"use strict";var ve=de(),J=Ae(),{MAX_LENGTH:Te,POSIX_REGEX_SOURCE:yr,REGEX_NON_SPECIAL_CHARS:_r,REGEX_SPECIAL_CHARS_BACKREF:Er,REPLACEMENTS:At}=ve,mr=(t,r)=>{if(typeof r.expandRange=="function")return r.expandRange(...t,r);t.sort();let e=`[${t.join("-")}]`;try{new RegExp(e)}catch{return t.map(n=>J.escapeRegex(n)).join("..")}return e},le=(t,r)=>`Missing ${t}: "${r}" - use "\\\\${r}" to match literal characters`,Fe=(t,r)=>{if(typeof t!="string")throw new TypeError("Expected a string");t=At[t]||t;let e={...r},o=typeof e.maxLength=="number"?Math.min(Te,e.maxLength):Te,n=t.length;if(n>o)throw new SyntaxError(`Input length: ${n}, exceeds maximum allowed length: ${o}`);let a={type:"bos",value:"",output:e.prepend||""},u=[a],p=e.capture?"":"?:",l=ve.globChars(e.windows),h=ve.extglobChars(l),{DOT_LITERAL:C,PLUS_LITERAL:L,SLASH_LITERAL:I,ONE_CHAR:j,DOTS_SLASH:y,NO_DOT:N,NO_DOT_SLASH:ne,NO_DOTS_SLASH:Q,QMARK:E,QMARK_NO_DOT:Z,STAR:se,START_ANCHOR:D}=l,H=g=>`(${p}(?:(?!${D}${g.dot?y:C}).)*?)`,F=e.dot?"":N,d=e.dot?E:Z,R=e.bash===!0?H(e):se;e.capture&&(R=`(${R})`),typeof e.noext=="boolean"&&(e.noextglob=e.noext);let c={input:t,index:-1,start:0,dot:e.dot===!0,consumed:"",output:"",prefix:"",backtrack:!1,negated:!1,brackets:0,braces:0,parens:0,quotes:0,globstar:!1,tokens:u};t=J.removePrefix(t,c),n=t.length;let G=[],w=[],T=[],s=a,i,V=()=>c.index===n-1,_=c.peek=(g=1)=>t[c.index+g],O=c.advance=()=>t[++c.index]||"",ee=()=>t.slice(c.index+1),U=(g="",m=0)=>{c.consumed+=g,c.index+=m},oe=g=>{c.output+=g.output!=null?g.output:g.value,U(g.value)},Tt=()=>{let g=1;for(;_()==="!"&&(_(2)!=="("||_(3)==="?");)O(),c.start++,g++;return g%2===0?!1:(c.negated=!0,c.start++,!0)},be=g=>{c[g]++,T.push(g)},ie=g=>{c[g]--,T.pop()},b=g=>{if(s.type==="globstar"){let m=c.braces>0&&(g.type==="comma"||g.type==="brace"),f=g.extglob===!0||G.length&&(g.type==="pipe"||g.type==="paren");g.type!=="slash"&&g.type!=="paren"&&!m&&!f&&(c.output=c.output.slice(0,-s.output.length),s.type="star",s.value="*",s.output=R,c.output+=s.output)}if(G.length&&g.type!=="paren"&&(G[G.length-1].inner+=g.value),(g.value||g.output)&&oe(g),s&&s.type==="text"&&g.type==="text"){s.output=(s.output||s.value)+g.value,s.value+=g.value;return}g.prev=s,u.push(g),s=g},Ce=(g,m)=>{let f={...h[m],conditions:1,inner:""};f.prev=s,f.parens=c.parens,f.output=c.output;let A=(e.capture?"(":"")+f.open;be("parens"),b({type:g,value:m,output:c.output?"":j}),b({type:"paren",extglob:!0,value:O(),output:A}),G.push(f)},$t=g=>{let m=g.close+(e.capture?")":""),f;if(g.type==="negate"){let A=R;if(g.inner&&g.inner.length>1&&g.inner.includes("/")&&(A=H(e)),(A!==R||V()||/^\)+$/.test(ee()))&&(m=g.close=`)$))${A}`),g.inner.includes("*")&&(f=ee())&&/^\.[^\\/.]+$/.test(f)){let S=Fe(f,{...r,fastpaths:!1}).output;m=g.close=`)${S})${A})`}g.prev.type==="bos"&&(c.negatedExtglob=!0)}b({type:"paren",extglob:!0,value:i,output:m}),ie("parens")};if(e.fastpaths!==!1&&!/(^[*!]|[/()[\]{}"])/.test(t)){let g=!1,m=t.replace(Er,(f,A,S,P,k,Le)=>P==="\\"?(g=!0,f):P==="?"?A?A+P+(k?E.repeat(k.length):""):Le===0?d+(k?E.repeat(k.length):""):E.repeat(S.length):P==="."?C.repeat(S.length):P==="*"?A?A+P+(k?R:""):R:A?f:`\\${f}`);return g===!0&&(e.unescape===!0?m=m.replace(/\\/g,""):m=m.replace(/\\+/g,f=>f.length%2===0?"\\\\":f?"\\":"")),m===t&&e.contains===!0?(c.output=t,c):(c.output=J.wrapOutput(m,c,r),c)}for(;!V();){if(i=O(),i==="\0")continue;if(i==="\\"){let f=_();if(f==="/"&&e.bash!==!0||f==="."||f===";")continue;if(!f){i+="\\",b({type:"text",value:i});continue}let A=/^\\+/.exec(ee()),S=0;if(A&&A[0].length>2&&(S=A[0].length,c.index+=S,S%2!==0&&(i+="\\")),e.unescape===!0?i=O():i+=O(),c.brackets===0){b({type:"text",value:i});continue}}if(c.brackets>0&&(i!=="]"||s.value==="["||s.value==="[^")){if(e.posix!==!1&&i===":"){let f=s.value.slice(1);if(f.includes("[")&&(s.posix=!0,f.includes(":"))){let A=s.value.lastIndexOf("["),S=s.value.slice(0,A),P=s.value.slice(A+2),k=yr[P];if(k){s.value=S+k,c.backtrack=!0,O(),!a.output&&u.indexOf(s)===1&&(a.output=j);continue}}}(i==="["&&_()!==":"||i==="-"&&_()==="]")&&(i=`\\${i}`),i==="]"&&(s.value==="["||s.value==="[^")&&(i=`\\${i}`),e.posix===!0&&i==="!"&&s.value==="["&&(i="^"),s.value+=i,oe({value:i});continue}if(c.quotes===1&&i!=='"'){i=J.escapeRegex(i),s.value+=i,oe({value:i});continue}if(i==='"'){c.quotes=c.quotes===1?0:1,e.keepQuotes===!0&&b({type:"text",value:i});continue}if(i==="("){be("parens"),b({type:"paren",value:i});continue}if(i===")"){if(c.parens===0&&e.strictBrackets===!0)throw new SyntaxError(le("opening","("));let f=G[G.length-1];if(f&&c.parens===f.parens+1){$t(G.pop());continue}b({type:"paren",value:i,output:c.parens?")":"\\)"}),ie("parens");continue}if(i==="["){if(e.nobracket===!0||!ee().includes("]")){if(e.nobracket!==!0&&e.strictBrackets===!0)throw new SyntaxError(le("closing","]"));i=`\\${i}`}else be("brackets");b({type:"bracket",value:i});continue}if(i==="]"){if(e.nobracket===!0||s&&s.type==="bracket"&&s.value.length===1){b({type:"text",value:i,output:`\\${i}`});continue}if(c.brackets===0){if(e.strictBrackets===!0)throw new SyntaxError(le("opening","["));b({type:"text",value:i,output:`\\${i}`});continue}ie("brackets");let f=s.value.slice(1);if(s.posix!==!0&&f[0]==="^"&&!f.includes("/")&&(i=`/${i}`),s.value+=i,oe({value:i}),e.literalBrackets===!1||J.hasRegexChars(f))continue;let A=J.escapeRegex(s.value);if(c.output=c.output.slice(0,-s.value.length),e.literalBrackets===!0){c.output+=A,s.value=A;continue}s.value=`(${p}${A}|${s.value})`,c.output+=s.value;continue}if(i==="{"&&e.nobrace!==!0){be("braces");let f={type:"brace",value:i,output:"(",outputIndex:c.output.length,tokensIndex:c.tokens.length};w.push(f),b(f);continue}if(i==="}"){let f=w[w.length-1];if(e.nobrace===!0||!f){b({type:"text",value:i,output:i});continue}let A=")";if(f.dots===!0){let S=u.slice(),P=[];for(let k=S.length-1;k>=0&&(u.pop(),S[k].type!=="brace");k--)S[k].type!=="dots"&&P.unshift(S[k].value);A=mr(P,e),c.backtrack=!0}if(f.comma!==!0&&f.dots!==!0){let S=c.output.slice(0,f.outputIndex),P=c.tokens.slice(f.tokensIndex);f.value=f.output="\\{",i=A="\\}",c.output=S;for(let k of P)c.output+=k.output||k.value}b({type:"brace",value:i,output:A}),ie("braces"),w.pop();continue}if(i==="|"){G.length>0&&G[G.length-1].conditions++,b({type:"text",value:i});continue}if(i===","){let f=i,A=w[w.length-1];A&&T[T.length-1]==="braces"&&(A.comma=!0,f="|"),b({type:"comma",value:i,output:f});continue}if(i==="/"){if(s.type==="dot"&&c.index===c.start+1){c.start=c.index+1,c.consumed="",c.output="",u.pop(),s=a;continue}b({type:"slash",value:i,output:I});continue}if(i==="."){if(c.braces>0&&s.type==="dot"){s.value==="."&&(s.output=C);let f=w[w.length-1];s.type="dots",s.output+=i,s.value+=i,f.dots=!0;continue}if(c.braces+c.parens===0&&s.type!=="bos"&&s.type!=="slash"){b({type:"text",value:i,output:C});continue}b({type:"dot",value:i,output:C});continue}if(i==="?"){if(!(s&&s.value==="(")&&e.noextglob!==!0&&_()==="("&&_(2)!=="?"){Ce("qmark",i);continue}if(s&&s.type==="paren"){let A=_(),S=i;(s.value==="("&&!/[!=<:]/.test(A)||A==="<"&&!/<([!=]|\w+>)/.test(ee()))&&(S=`\\${i}`),b({type:"text",value:i,output:S});continue}if(e.dot!==!0&&(s.type==="slash"||s.type==="bos")){b({type:"qmark",value:i,output:Z});continue}b({type:"qmark",value:i,output:E});continue}if(i==="!"){if(e.noextglob!==!0&&_()==="("&&(_(2)!=="?"||!/[!=<:]/.test(_(3)))){Ce("negate",i);continue}if(e.nonegate!==!0&&c.index===0){Tt();continue}}if(i==="+"){if(e.noextglob!==!0&&_()==="("&&_(2)!=="?"){Ce("plus",i);continue}if(s&&s.value==="("||e.regex===!1){b({type:"plus",value:i,output:L});continue}if(s&&(s.type==="bracket"||s.type==="paren"||s.type==="brace")||c.parens>0){b({type:"plus",value:i});continue}b({type:"plus",value:L});continue}if(i==="@"){if(e.noextglob!==!0&&_()==="("&&_(2)!=="?"){b({type:"at",extglob:!0,value:i,output:""});continue}b({type:"text",value:i});continue}if(i!=="*"){(i==="$"||i==="^")&&(i=`\\${i}`);let f=_r.exec(ee());f&&(i+=f[0],c.index+=f[0].length),b({type:"text",value:i});continue}if(s&&(s.type==="globstar"||s.star===!0)){s.type="star",s.star=!0,s.value+=i,s.output=R,c.backtrack=!0,c.globstar=!0,U(i);continue}let g=ee();if(e.noextglob!==!0&&/^\([^?]/.test(g)){Ce("star",i);continue}if(s.type==="star"){if(e.noglobstar===!0){U(i);continue}let f=s.prev,A=f.prev,S=f.type==="slash"||f.type==="bos",P=A&&(A.type==="star"||A.type==="globstar");if(e.bash===!0&&(!S||g[0]&&g[0]!=="/")){b({type:"star",value:i,output:""});continue}let k=c.braces>0&&(f.type==="comma"||f.type==="brace"),Le=G.length&&(f.type==="pipe"||f.type==="paren");if(!S&&f.type!=="paren"&&!k&&!Le){b({type:"star",value:i,output:""});continue}for(;g.slice(0,3)==="/**";){let ye=t[c.index+4];if(ye&&ye!=="/")break;g=g.slice(3),U("/**",3)}if(f.type==="bos"&&V()){s.type="globstar",s.value+=i,s.output=H(e),c.output=s.output,c.globstar=!0,U(i);continue}if(f.type==="slash"&&f.prev.type!=="bos"&&!P&&V()){c.output=c.output.slice(0,-(f.output+s.output).length),f.output=`(?:${f.output}`,s.type="globstar",s.output=H(e)+(e.strictSlashes?")":"|$)"),s.value+=i,c.globstar=!0,c.output+=f.output+s.output,U(i);continue}if(f.type==="slash"&&f.prev.type!=="bos"&&g[0]==="/"){let ye=g[1]!==void 0?"|$":"";c.output=c.output.slice(0,-(f.output+s.output).length),f.output=`(?:${f.output}`,s.type="globstar",s.output=`${H(e)}${I}|${I}${ye})`,s.value+=i,c.output+=f.output+s.output,c.globstar=!0,U(i+O()),b({type:"slash",value:"/",output:""});continue}if(f.type==="bos"&&g[0]==="/"){s.type="globstar",s.value+=i,s.output=`(?:^|${I}|${H(e)}${I})`,c.output=s.output,c.globstar=!0,U(i+O()),b({type:"slash",value:"/",output:""});continue}c.output=c.output.slice(0,-s.output.length),s.type="globstar",s.output=H(e),s.value+=i,c.output+=s.output,c.globstar=!0,U(i);continue}let m={type:"star",value:i,output:R};if(e.bash===!0){m.output=".*?",(s.type==="bos"||s.type==="slash")&&(m.output=F+m.output),b(m);continue}if(s&&(s.type==="bracket"||s.type==="paren")&&e.regex===!0){m.output=i,b(m);continue}(c.index===c.start||s.type==="slash"||s.type==="dot")&&(s.type==="dot"?(c.output+=ne,s.output+=ne):e.dot===!0?(c.output+=Q,s.output+=Q):(c.output+=F,s.output+=F),_()!=="*"&&(c.output+=j,s.output+=j)),b(m)}for(;c.brackets>0;){if(e.strictBrackets===!0)throw new SyntaxError(le("closing","]"));c.output=J.escapeLast(c.output,"["),ie("brackets")}for(;c.parens>0;){if(e.strictBrackets===!0)throw new SyntaxError(le("closing",")"));c.output=J.escapeLast(c.output,"("),ie("parens")}for(;c.braces>0;){if(e.strictBrackets===!0)throw new SyntaxError(le("closing","}"));c.output=J.escapeLast(c.output,"{"),ie("braces")}if(e.strictSlashes!==!0&&(s.type==="star"||s.type==="bracket")&&b({type:"maybe_slash",value:"",output:`${I}?`}),c.backtrack===!0){c.output="";for(let g of c.tokens)c.output+=g.output!=null?g.output:g.value,g.suffix&&(c.output+=g.suffix)}return c};Fe.fastpaths=(t,r)=>{let e={...r},o=typeof e.maxLength=="number"?Math.min(Te,e.maxLength):Te,n=t.length;if(n>o)throw new SyntaxError(`Input length: ${n}, exceeds maximum allowed length: ${o}`);t=At[t]||t;let{DOT_LITERAL:a,SLASH_LITERAL:u,ONE_CHAR:p,DOTS_SLASH:l,NO_DOT:h,NO_DOTS:C,NO_DOTS_SLASH:L,STAR:I,START_ANCHOR:j}=ve.globChars(e.windows),y=e.dot?C:h,N=e.dot?L:h,ne=e.capture?"":"?:",Q={negated:!1,prefix:""},E=e.bash===!0?".*?":I;e.capture&&(E=`(${E})`);let Z=F=>F.noglobstar===!0?E:`(${ne}(?:(?!${j}${F.dot?l:a}).)*?)`,se=F=>{switch(F){case"*":return`${y}${p}${E}`;case".*":return`${a}${p}${E}`;case"*.*":return`${y}${E}${a}${p}${E}`;case"*/*":return`${y}${E}${u}${p}${N}${E}`;case"**":return y+Z(e);case"**/*":return`(?:${y}${Z(e)}${u})?${N}${p}${E}`;case"**/*.*":return`(?:${y}${Z(e)}${u})?${N}${E}${a}${p}${E}`;case"**/.*":return`(?:${y}${Z(e)}${u})?${a}${p}${E}`;default:{let d=/^(.*?)\.(\w+)$/.exec(F);if(!d)return;let R=se(d[1]);return R?R+a+d[2]:void 0}}},D=J.removePrefix(t,Q),H=se(D);return H&&e.strictSlashes!==!0&&(H+=`${u}?`),H};Rt.exports=Fe});var _t=ae((Xr,yt)=>{"use strict";var xr=dt(),We=bt(),Ct=Ae(),Or=de(),Sr=t=>t&&typeof t=="object"&&!Array.isArray(t),$=(t,r,e=!1)=>{if(Array.isArray(t)){let C=t.map(I=>$(I,r,e));return I=>{for(let j of C){let y=j(I);if(y)return y}return!1}}let o=Sr(t)&&t.tokens&&t.input;if(t===""||typeof t!="string"&&!o)throw new TypeError("Expected pattern to be a non-empty string");let n=r||{},a=n.windows,u=o?$.compileRe(t,r):$.makeRe(t,r,!1,!0),p=u.state;delete u.state;let l=()=>!1;if(n.ignore){let C={...r,ignore:null,onMatch:null,onResult:null};l=$(n.ignore,C,e)}let h=(C,L=!1)=>{let{isMatch:I,match:j,output:y}=$.test(C,u,r,{glob:t,posix:a}),N={glob:t,state:p,regex:u,posix:a,input:C,output:y,match:j,isMatch:I};return typeof n.onResult=="function"&&n.onResult(N),I===!1?(N.isMatch=!1,L?N:!1):l(C)?(typeof n.onIgnore=="function"&&n.onIgnore(N),N.isMatch=!1,L?N:!1):(typeof n.onMatch=="function"&&n.onMatch(N),L?N:!0)};return e&&(h.state=p),h};$.test=(t,r,e,{glob:o,posix:n}={})=>{if(typeof t!="string")throw new TypeError("Expected input to be a string");if(t==="")return{isMatch:!1,output:""};let a=e||{},u=a.format||(n?Ct.toPosixSlashes:null),p=t===o,l=p&&u?u(t):t;return p===!1&&(l=u?u(t):t,p=l===o),(p===!1||a.capture===!0)&&(a.matchBase===!0||a.basename===!0?p=$.matchBase(t,r,e,n):p=r.exec(l)),{isMatch:!!p,match:p,output:l}};$.matchBase=(t,r,e)=>(r instanceof RegExp?r:$.makeRe(r,e)).test(Ct.basename(t));$.isMatch=(t,r,e)=>$(r,e)(t);$.parse=(t,r)=>Array.isArray(t)?t.map(e=>$.parse(e,r)):We(t,{...r,fastpaths:!1});$.scan=(t,r)=>xr(t,r);$.compileRe=(t,r,e=!1,o=!1)=>{if(e===!0)return t.output;let n=r||{},a=n.contains?"":"^",u=n.contains?"":"$",p=`${a}(?:${t.output})${u}`;t&&t.negated===!0&&(p=`^(?!${p}).*$`);let l=$.toRegex(p,r);return o===!0&&(l.state=t),l};$.makeRe=(t,r={},e=!1,o=!1)=>{if(!t||typeof t!="string")throw new TypeError("Expected a non-empty string");let n={negated:!1,fastpaths:!0};return r.fastpaths!==!1&&(t[0]==="."||t[0]==="*")&&(n.output=We.fastpaths(t,r)),n.output||(n=We(t,r)),$.compileRe(n,r,e,o)};$.toRegex=(t,r)=>{try{let e=r||{};return new RegExp(t,e.flags||(e.nocase?"i":""))}catch(e){if(r&&r.debug===!0)throw e;return/$^/}};$.constants=Or;yt.exports=$});var Ot=ae((qr,xt)=>{"use strict";var Et=_t(),vr=Ae();function mt(t,r,e=!1){return r&&(r.windows===null||r.windows===void 0)&&(r={...r,windows:vr.isWindows()}),Et(t,r,e)}Object.assign(mt,Et);xt.exports=mt});var Ir={};Ht(Ir,{default:()=>Lr});var B=fe("@yarnpkg/core");var Ke=(t=0)=>r=>`\x1B[${r+t}m`,Xe=(t=0)=>r=>`\x1B[${38+t};5;${r}m`,qe=(t=0)=>(r,e,o)=>`\x1B[${38+t};2;${r};${e};${o}m`,x={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},kr=Object.keys(x.modifier),Pt=Object.keys(x.color),Gt=Object.keys(x.bgColor),Nr=[...Pt,...Gt];function Mt(){let t=new Map;for(let[r,e]of Object.entries(x)){for(let[o,n]of Object.entries(e))x[o]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},e[o]=x[o],t.set(n[0],n[1]);Object.defineProperty(x,r,{value:e,enumerable:!1})}return Object.defineProperty(x,"codes",{value:t,enumerable:!1}),x.color.close="\x1B[39m",x.bgColor.close="\x1B[49m",x.color.ansi=Ke(),x.color.ansi256=Xe(),x.color.ansi16m=qe(),x.bgColor.ansi=Ke(10),x.bgColor.ansi256=Xe(10),x.bgColor.ansi16m=qe(10),Object.defineProperties(x,{rgbToAnsi256:{value(r,e,o){return r===e&&e===o?r<8?16:r>248?231:Math.round((r-8)/247*24)+232:16+36*Math.round(r/255*5)+6*Math.round(e/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(r){let e=/[a-f\d]{6}|[a-f\d]{3}/i.exec(r.toString(16));if(!e)return[0,0,0];let[o]=e;o.length===3&&(o=[...o].map(a=>a+a).join(""));let n=Number.parseInt(o,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:r=>x.rgbToAnsi256(...x.hexToRgb(r)),enumerable:!1},ansi256ToAnsi:{value(r){if(r<8)return 30+r;if(r<16)return 90+(r-8);let e,o,n;if(r>=232)e=((r-232)*10+8)/255,o=e,n=e;else{r-=16;let p=r%36;e=Math.floor(r/36)/5,o=Math.floor(p/6)/5,n=p%6/5}let a=Math.max(e,o,n)*2;if(a===0)return 30;let u=30+(Math.round(n)<<2|Math.round(o)<<1|Math.round(e));return a===2&&(u+=60),u},enumerable:!1},rgbToAnsi:{value:(r,e,o)=>x.ansi256ToAnsi(x.rgbToAnsi256(r,e,o)),enumerable:!1},hexToAnsi:{value:r=>x.ansi256ToAnsi(x.hexToAnsi256(r)),enumerable:!1}}),x}var Bt=Mt(),q=Bt;var xe=Ee(fe("process"),1),Qe=Ee(fe("os"),1),Ie=Ee(fe("tty"),1);function K(t,r=globalThis.Deno?globalThis.Deno.args:xe.default.argv){let e=t.startsWith("-")?"":t.length===1?"-":"--",o=r.indexOf(e+t),n=r.indexOf("--");return o!==-1&&(n===-1||o=2,has16m:t>=3}}function Wt(t,{streamIsTTY:r,sniffFlags:e=!0}={}){let o=jt();o!==void 0&&(me=o);let n=e?me:o;if(n===0)return 0;if(e){if(K("color=16m")||K("color=full")||K("color=truecolor"))return 3;if(K("color=256"))return 2}if("TF_BUILD"in v&&"AGENT_NAME"in v)return 1;if(t&&!r&&n===void 0)return 0;let a=n||0;if(v.TERM==="dumb")return a;if(xe.default.platform==="win32"){let u=Qe.default.release().split(".");return Number(u[0])>=10&&Number(u[2])>=10586?Number(u[2])>=14931?3:2:1}if("CI"in v)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(u=>u in v)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(u=>u in v)||v.CI_NAME==="codeship"?1:a;if("TEAMCITY_VERSION"in v)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(v.TEAMCITY_VERSION)?1:0;if(v.COLORTERM==="truecolor"||v.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in v){let u=Number.parseInt((v.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(v.TERM_PROGRAM){case"iTerm.app":return u>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(v.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(v.TERM)||"COLORTERM"in v?1:a}function Ye(t,r={}){let e=Wt(t,{streamIsTTY:t&&t.isTTY,...r});return Ft(e)}var Vt={stdout:Ye({isTTY:Ie.default.isatty(1)}),stderr:Ye({isTTY:Ie.default.isatty(2)})},Ze=Vt;function ze(t,r,e){let o=t.indexOf(r);if(o===-1)return t;let n=r.length,a=0,u="";do u+=t.slice(a,o)+r+e,a=o+n,o=t.indexOf(r,a);while(o!==-1);return u+=t.slice(a),u}function Je(t,r,e,o){let n=0,a="";do{let u=t[o-1]==="\r";a+=t.slice(n,u?o-1:o)+r+(u?`\r +"use strict";var plugin=(()=>{var kt=Object.create;var ye=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var Nt=Object.getOwnPropertyNames;var Dt=Object.getPrototypeOf,Gt=Object.prototype.hasOwnProperty;var ae=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(r,e)=>(typeof require<"u"?require:r)[e]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var ue=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),Pt=(t,r)=>{for(var e in r)ye(t,e,{get:r[e],enumerable:!0})},qe=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of Nt(r))!Gt.call(t,n)&&n!==e&&ye(t,n,{get:()=>r[n],enumerable:!(o=Ht(r,n))||o.enumerable});return t};var _e=(t,r,e)=>(e=t!=null?kt(Dt(t)):{},qe(r||!t||!t.__esModule?ye(e,"default",{value:t,enumerable:!0}):e,t)),Mt=t=>qe(ye({},"__esModule",{value:!0}),t);var de=ue((Kr,ct)=>{"use strict";var z="\\\\/",it=`[^${z}]`,re="\\.",er="\\+",tr="\\?",ve="\\/",rr="(?=.)",at="[^/]",De=`(?:${ve}|$)`,ut=`(?:^|${ve})`,Ge=`${re}{1,2}${De}`,or=`(?!${re})`,nr=`(?!${ut}${Ge})`,sr=`(?!${re}{0,1}${De})`,ir=`(?!${Ge})`,ar=`[^.${ve}]`,ur=`${at}*?`,lr="/",lt={DOT_LITERAL:re,PLUS_LITERAL:er,QMARK_LITERAL:tr,SLASH_LITERAL:ve,ONE_CHAR:rr,QMARK:at,END_ANCHOR:De,DOTS_SLASH:Ge,NO_DOT:or,NO_DOTS:nr,NO_DOT_SLASH:sr,NO_DOTS_SLASH:ir,QMARK_NO_DOT:ar,STAR:ur,START_ANCHOR:ut,SEP:lr},cr={...lt,SLASH_LITERAL:`[${z}]`,QMARK:it,STAR:`${it}*?`,DOTS_SLASH:`${re}{1,2}(?:[${z}]|$)`,NO_DOT:`(?!${re})`,NO_DOTS:`(?!(?:^|[${z}])${re}{1,2}(?:[${z}]|$))`,NO_DOT_SLASH:`(?!${re}{0,1}(?:[${z}]|$))`,NO_DOTS_SLASH:`(?!${re}{1,2}(?:[${z}]|$))`,QMARK_NO_DOT:`[^.${z}]`,START_ANCHOR:`(?:^|[${z}])`,END_ANCHOR:`(?:[${z}]|$)`,SEP:"\\"},fr={alnum:"a-zA-Z0-9",alpha:"a-zA-Z",ascii:"\\x00-\\x7F",blank:" \\t",cntrl:"\\x00-\\x1F\\x7F",digit:"0-9",graph:"\\x21-\\x7E",lower:"a-z",print:"\\x20-\\x7E ",punct:"\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",space:" \\t\\r\\n\\v\\f",upper:"A-Z",word:"A-Za-z0-9_",xdigit:"A-Fa-f0-9"};ct.exports={MAX_LENGTH:1024*64,POSIX_REGEX_SOURCE:fr,REGEX_BACKSLASH:/\\(?![*+?^${}(|)[\]])/g,REGEX_NON_SPECIAL_CHARS:/^[^@![\].,$*+?^{}()|\\/]+/,REGEX_SPECIAL_CHARS:/[-*+?.^${}(|)[\]]/,REGEX_SPECIAL_CHARS_BACKREF:/(\\?)((\W)(\3*))/g,REGEX_SPECIAL_CHARS_GLOBAL:/([-*+?.^${}(|)[\]])/g,REGEX_REMOVE_BACKSLASH:/(?:\[.*?[^\\]\]|\\(?=.))/g,REPLACEMENTS:{"***":"*","**/**":"**","**/**/**":"**"},CHAR_0:48,CHAR_9:57,CHAR_UPPERCASE_A:65,CHAR_LOWERCASE_A:97,CHAR_UPPERCASE_Z:90,CHAR_LOWERCASE_Z:122,CHAR_LEFT_PARENTHESES:40,CHAR_RIGHT_PARENTHESES:41,CHAR_ASTERISK:42,CHAR_AMPERSAND:38,CHAR_AT:64,CHAR_BACKWARD_SLASH:92,CHAR_CARRIAGE_RETURN:13,CHAR_CIRCUMFLEX_ACCENT:94,CHAR_COLON:58,CHAR_COMMA:44,CHAR_DOT:46,CHAR_DOUBLE_QUOTE:34,CHAR_EQUAL:61,CHAR_EXCLAMATION_MARK:33,CHAR_FORM_FEED:12,CHAR_FORWARD_SLASH:47,CHAR_GRAVE_ACCENT:96,CHAR_HASH:35,CHAR_HYPHEN_MINUS:45,CHAR_LEFT_ANGLE_BRACKET:60,CHAR_LEFT_CURLY_BRACE:123,CHAR_LEFT_SQUARE_BRACKET:91,CHAR_LINE_FEED:10,CHAR_NO_BREAK_SPACE:160,CHAR_PERCENT:37,CHAR_PLUS:43,CHAR_QUESTION_MARK:63,CHAR_RIGHT_ANGLE_BRACKET:62,CHAR_RIGHT_CURLY_BRACE:125,CHAR_RIGHT_SQUARE_BRACKET:93,CHAR_SEMICOLON:59,CHAR_SINGLE_QUOTE:39,CHAR_SPACE:32,CHAR_TAB:9,CHAR_UNDERSCORE:95,CHAR_VERTICAL_LINE:124,CHAR_ZERO_WIDTH_NOBREAK_SPACE:65279,extglobChars(t){return{"!":{type:"negate",open:"(?:(?!(?:",close:`))${t.STAR})`},"?":{type:"qmark",open:"(?:",close:")?"},"+":{type:"plus",open:"(?:",close:")+"},"*":{type:"star",open:"(?:",close:")*"},"@":{type:"at",open:"(?:",close:")"}}},globChars(t){return t===!0?cr:lt}}});var Ae=ue(j=>{"use strict";var{REGEX_BACKSLASH:pr,REGEX_REMOVE_BACKSLASH:gr,REGEX_SPECIAL_CHARS:hr,REGEX_SPECIAL_CHARS_GLOBAL:dr}=de();j.isObject=t=>t!==null&&typeof t=="object"&&!Array.isArray(t);j.hasRegexChars=t=>hr.test(t);j.isRegexChar=t=>t.length===1&&j.hasRegexChars(t);j.escapeRegex=t=>t.replace(dr,"\\$1");j.toPosixSlashes=t=>t.replace(pr,"/");j.isWindows=()=>{if(typeof navigator<"u"&&navigator.platform){let t=navigator.platform.toLowerCase();return t==="win32"||t==="windows"}return typeof process<"u"&&process.platform?process.platform==="win32":!1};j.removeBackslashes=t=>t.replace(gr,r=>r==="\\"?"":r);j.escapeLast=(t,r,e)=>{let o=t.lastIndexOf(r,e);return o===-1?t:t[o-1]==="\\"?j.escapeLast(t,r,o-1):`${t.slice(0,o)}\\${t.slice(o)}`};j.removePrefix=(t,r={})=>{let e=t;return e.startsWith("./")&&(e=e.slice(2),r.prefix="./"),e};j.wrapOutput=(t,r={},e={})=>{let o=e.contains?"":"^",n=e.contains?"":"$",a=`${o}(?:${t})${n}`;return r.negated===!0&&(a=`(?:^(?!${a}).*$)`),a};j.basename=(t,{windows:r}={})=>{let e=t.split(r?/[\\/]/:"/"),o=e[e.length-1];return o===""?e[e.length-2]:o}});var bt=ue((qr,Rt)=>{"use strict";var ft=Ae(),{CHAR_ASTERISK:Pe,CHAR_AT:Ar,CHAR_BACKWARD_SLASH:Re,CHAR_COMMA:Rr,CHAR_DOT:Me,CHAR_EXCLAMATION_MARK:Be,CHAR_FORWARD_SLASH:At,CHAR_LEFT_CURLY_BRACE:je,CHAR_LEFT_PARENTHESES:Fe,CHAR_LEFT_SQUARE_BRACKET:br,CHAR_PLUS:Cr,CHAR_QUESTION_MARK:pt,CHAR_RIGHT_CURLY_BRACE:mr,CHAR_RIGHT_PARENTHESES:gt,CHAR_RIGHT_SQUARE_BRACKET:yr}=de(),ht=t=>t===At||t===Re,dt=t=>{t.isPrefix!==!0&&(t.depth=t.isGlobstar?1/0:1)},_r=(t,r)=>{let e=r||{},o=t.length-1,n=e.parts===!0||e.scanToEnd===!0,a=[],u=[],f=[],g=t,h=-1,C=0,$=0,I=!1,W=!1,m=!1,H=!1,ne=!1,Q=!1,_=!1,Z=!1,se=!1,D=!1,N=0,U,d,R={value:"",depth:0,isGlob:!1},l=()=>h>=o,M=()=>g.charCodeAt(h+1),w=()=>(U=d,g.charCodeAt(++h));for(;h0&&(s=g.slice(0,C),g=g.slice(C),$-=C),T&&m===!0&&$>0?(T=g.slice(0,$),i=g.slice($)):m===!0?(T="",i=g):T=g,T&&T!==""&&T!=="/"&&T!==g&&ht(T.charCodeAt(T.length-1))&&(T=T.slice(0,-1)),e.unescape===!0&&(i&&(i=ft.removeBackslashes(i)),T&&_===!0&&(T=ft.removeBackslashes(T)));let V={prefix:s,input:t,start:C,base:T,glob:i,isBrace:I,isBracket:W,isGlob:m,isExtglob:H,isGlobstar:ne,negated:Z,negatedExtglob:se};if(e.tokens===!0&&(V.maxDepth=0,ht(d)||u.push(R),V.tokens=u),e.parts===!0||e.tokens===!0){let y;for(let x=0;x{"use strict";var Se=de(),J=Ae(),{MAX_LENGTH:Te,POSIX_REGEX_SOURCE:Er,REGEX_NON_SPECIAL_CHARS:Or,REGEX_SPECIAL_CHARS_BACKREF:xr,REPLACEMENTS:Ct}=Se,vr=(t,r)=>{if(typeof r.expandRange=="function")return r.expandRange(...t,r);t.sort();let e=`[${t.join("-")}]`;try{new RegExp(e)}catch{return t.map(n=>J.escapeRegex(n)).join("..")}return e},pe=(t,r)=>`Missing ${t}: "${r}" - use "\\\\${r}" to match literal characters`,We=(t,r)=>{if(typeof t!="string")throw new TypeError("Expected a string");t=Ct[t]||t;let e={...r},o=typeof e.maxLength=="number"?Math.min(Te,e.maxLength):Te,n=t.length;if(n>o)throw new SyntaxError(`Input length: ${n}, exceeds maximum allowed length: ${o}`);let a={type:"bos",value:"",output:e.prepend||""},u=[a],f=e.capture?"":"?:",g=Se.globChars(e.windows),h=Se.extglobChars(g),{DOT_LITERAL:C,PLUS_LITERAL:$,SLASH_LITERAL:I,ONE_CHAR:W,DOTS_SLASH:m,NO_DOT:H,NO_DOT_SLASH:ne,NO_DOTS_SLASH:Q,QMARK:_,QMARK_NO_DOT:Z,STAR:se,START_ANCHOR:D}=g,N=p=>`(${f}(?:(?!${D}${p.dot?m:C}).)*?)`,U=e.dot?"":H,d=e.dot?_:Z,R=e.bash===!0?N(e):se;e.capture&&(R=`(${R})`),typeof e.noext=="boolean"&&(e.noextglob=e.noext);let l={input:t,index:-1,start:0,dot:e.dot===!0,consumed:"",output:"",prefix:"",backtrack:!1,negated:!1,brackets:0,braces:0,parens:0,quotes:0,globstar:!1,tokens:u};t=J.removePrefix(t,l),n=t.length;let M=[],w=[],T=[],s=a,i,V=()=>l.index===n-1,y=l.peek=(p=1)=>t[l.index+p],x=l.advance=()=>t[++l.index]||"",te=()=>t.slice(l.index+1),K=(p="",E=0)=>{l.consumed+=p,l.index+=E},oe=p=>{l.output+=p.output!=null?p.output:p.value,K(p.value)},It=()=>{let p=1;for(;y()==="!"&&(y(2)!=="("||y(3)==="?");)x(),l.start++,p++;return p%2===0?!1:(l.negated=!0,l.start++,!0)},be=p=>{l[p]++,T.push(p)},ie=p=>{l[p]--,T.pop()},b=p=>{if(s.type==="globstar"){let E=l.braces>0&&(p.type==="comma"||p.type==="brace"),c=p.extglob===!0||M.length&&(p.type==="pipe"||p.type==="paren");p.type!=="slash"&&p.type!=="paren"&&!E&&!c&&(l.output=l.output.slice(0,-s.output.length),s.type="star",s.value="*",s.output=R,l.output+=s.output)}if(M.length&&p.type!=="paren"&&(M[M.length-1].inner+=p.value),(p.value||p.output)&&oe(p),s&&s.type==="text"&&p.type==="text"){s.output=(s.output||s.value)+p.value,s.value+=p.value;return}p.prev=s,u.push(p),s=p},Ce=(p,E)=>{let c={...h[E],conditions:1,inner:""};c.prev=s,c.parens=l.parens,c.output=l.output;let A=(e.capture?"(":"")+c.open;be("parens"),b({type:p,value:E,output:l.output?"":W}),b({type:"paren",extglob:!0,value:x(),output:A}),M.push(c)},wt=p=>{let E=p.close+(e.capture?")":""),c;if(p.type==="negate"){let A=R;if(p.inner&&p.inner.length>1&&p.inner.includes("/")&&(A=N(e)),(A!==R||V()||/^\)+$/.test(te()))&&(E=p.close=`)$))${A}`),p.inner.includes("*")&&(c=te())&&/^\.[^\\/.]+$/.test(c)){let v=We(c,{...r,fastpaths:!1}).output;E=p.close=`)${v})${A})`}p.prev.type==="bos"&&(l.negatedExtglob=!0)}b({type:"paren",extglob:!0,value:i,output:E}),ie("parens")};if(e.fastpaths!==!1&&!/(^[*!]|[/()[\]{}"])/.test(t)){let p=!1,E=t.replace(xr,(c,A,v,G,k,Ie)=>G==="\\"?(p=!0,c):G==="?"?A?A+G+(k?_.repeat(k.length):""):Ie===0?d+(k?_.repeat(k.length):""):_.repeat(v.length):G==="."?C.repeat(v.length):G==="*"?A?A+G+(k?R:""):R:A?c:`\\${c}`);return p===!0&&(e.unescape===!0?E=E.replace(/\\/g,""):E=E.replace(/\\+/g,c=>c.length%2===0?"\\\\":c?"\\":"")),E===t&&e.contains===!0?(l.output=t,l):(l.output=J.wrapOutput(E,l,r),l)}for(;!V();){if(i=x(),i==="\0")continue;if(i==="\\"){let c=y();if(c==="/"&&e.bash!==!0||c==="."||c===";")continue;if(!c){i+="\\",b({type:"text",value:i});continue}let A=/^\\+/.exec(te()),v=0;if(A&&A[0].length>2&&(v=A[0].length,l.index+=v,v%2!==0&&(i+="\\")),e.unescape===!0?i=x():i+=x(),l.brackets===0){b({type:"text",value:i});continue}}if(l.brackets>0&&(i!=="]"||s.value==="["||s.value==="[^")){if(e.posix!==!1&&i===":"){let c=s.value.slice(1);if(c.includes("[")&&(s.posix=!0,c.includes(":"))){let A=s.value.lastIndexOf("["),v=s.value.slice(0,A),G=s.value.slice(A+2),k=Er[G];if(k){s.value=v+k,l.backtrack=!0,x(),!a.output&&u.indexOf(s)===1&&(a.output=W);continue}}}(i==="["&&y()!==":"||i==="-"&&y()==="]")&&(i=`\\${i}`),i==="]"&&(s.value==="["||s.value==="[^")&&(i=`\\${i}`),e.posix===!0&&i==="!"&&s.value==="["&&(i="^"),s.value+=i,oe({value:i});continue}if(l.quotes===1&&i!=='"'){i=J.escapeRegex(i),s.value+=i,oe({value:i});continue}if(i==='"'){l.quotes=l.quotes===1?0:1,e.keepQuotes===!0&&b({type:"text",value:i});continue}if(i==="("){be("parens"),b({type:"paren",value:i});continue}if(i===")"){if(l.parens===0&&e.strictBrackets===!0)throw new SyntaxError(pe("opening","("));let c=M[M.length-1];if(c&&l.parens===c.parens+1){wt(M.pop());continue}b({type:"paren",value:i,output:l.parens?")":"\\)"}),ie("parens");continue}if(i==="["){if(e.nobracket===!0||!te().includes("]")){if(e.nobracket!==!0&&e.strictBrackets===!0)throw new SyntaxError(pe("closing","]"));i=`\\${i}`}else be("brackets");b({type:"bracket",value:i});continue}if(i==="]"){if(e.nobracket===!0||s&&s.type==="bracket"&&s.value.length===1){b({type:"text",value:i,output:`\\${i}`});continue}if(l.brackets===0){if(e.strictBrackets===!0)throw new SyntaxError(pe("opening","["));b({type:"text",value:i,output:`\\${i}`});continue}ie("brackets");let c=s.value.slice(1);if(s.posix!==!0&&c[0]==="^"&&!c.includes("/")&&(i=`/${i}`),s.value+=i,oe({value:i}),e.literalBrackets===!1||J.hasRegexChars(c))continue;let A=J.escapeRegex(s.value);if(l.output=l.output.slice(0,-s.value.length),e.literalBrackets===!0){l.output+=A,s.value=A;continue}s.value=`(${f}${A}|${s.value})`,l.output+=s.value;continue}if(i==="{"&&e.nobrace!==!0){be("braces");let c={type:"brace",value:i,output:"(",outputIndex:l.output.length,tokensIndex:l.tokens.length};w.push(c),b(c);continue}if(i==="}"){let c=w[w.length-1];if(e.nobrace===!0||!c){b({type:"text",value:i,output:i});continue}let A=")";if(c.dots===!0){let v=u.slice(),G=[];for(let k=v.length-1;k>=0&&(u.pop(),v[k].type!=="brace");k--)v[k].type!=="dots"&&G.unshift(v[k].value);A=vr(G,e),l.backtrack=!0}if(c.comma!==!0&&c.dots!==!0){let v=l.output.slice(0,c.outputIndex),G=l.tokens.slice(c.tokensIndex);c.value=c.output="\\{",i=A="\\}",l.output=v;for(let k of G)l.output+=k.output||k.value}b({type:"brace",value:i,output:A}),ie("braces"),w.pop();continue}if(i==="|"){M.length>0&&M[M.length-1].conditions++,b({type:"text",value:i});continue}if(i===","){let c=i,A=w[w.length-1];A&&T[T.length-1]==="braces"&&(A.comma=!0,c="|"),b({type:"comma",value:i,output:c});continue}if(i==="/"){if(s.type==="dot"&&l.index===l.start+1){l.start=l.index+1,l.consumed="",l.output="",u.pop(),s=a;continue}b({type:"slash",value:i,output:I});continue}if(i==="."){if(l.braces>0&&s.type==="dot"){s.value==="."&&(s.output=C);let c=w[w.length-1];s.type="dots",s.output+=i,s.value+=i,c.dots=!0;continue}if(l.braces+l.parens===0&&s.type!=="bos"&&s.type!=="slash"){b({type:"text",value:i,output:C});continue}b({type:"dot",value:i,output:C});continue}if(i==="?"){if(!(s&&s.value==="(")&&e.noextglob!==!0&&y()==="("&&y(2)!=="?"){Ce("qmark",i);continue}if(s&&s.type==="paren"){let A=y(),v=i;(s.value==="("&&!/[!=<:]/.test(A)||A==="<"&&!/<([!=]|\w+>)/.test(te()))&&(v=`\\${i}`),b({type:"text",value:i,output:v});continue}if(e.dot!==!0&&(s.type==="slash"||s.type==="bos")){b({type:"qmark",value:i,output:Z});continue}b({type:"qmark",value:i,output:_});continue}if(i==="!"){if(e.noextglob!==!0&&y()==="("&&(y(2)!=="?"||!/[!=<:]/.test(y(3)))){Ce("negate",i);continue}if(e.nonegate!==!0&&l.index===0){It();continue}}if(i==="+"){if(e.noextglob!==!0&&y()==="("&&y(2)!=="?"){Ce("plus",i);continue}if(s&&s.value==="("||e.regex===!1){b({type:"plus",value:i,output:$});continue}if(s&&(s.type==="bracket"||s.type==="paren"||s.type==="brace")||l.parens>0){b({type:"plus",value:i});continue}b({type:"plus",value:$});continue}if(i==="@"){if(e.noextglob!==!0&&y()==="("&&y(2)!=="?"){b({type:"at",extglob:!0,value:i,output:""});continue}b({type:"text",value:i});continue}if(i!=="*"){(i==="$"||i==="^")&&(i=`\\${i}`);let c=Or.exec(te());c&&(i+=c[0],l.index+=c[0].length),b({type:"text",value:i});continue}if(s&&(s.type==="globstar"||s.star===!0)){s.type="star",s.star=!0,s.value+=i,s.output=R,l.backtrack=!0,l.globstar=!0,K(i);continue}let p=te();if(e.noextglob!==!0&&/^\([^?]/.test(p)){Ce("star",i);continue}if(s.type==="star"){if(e.noglobstar===!0){K(i);continue}let c=s.prev,A=c.prev,v=c.type==="slash"||c.type==="bos",G=A&&(A.type==="star"||A.type==="globstar");if(e.bash===!0&&(!v||p[0]&&p[0]!=="/")){b({type:"star",value:i,output:""});continue}let k=l.braces>0&&(c.type==="comma"||c.type==="brace"),Ie=M.length&&(c.type==="pipe"||c.type==="paren");if(!v&&c.type!=="paren"&&!k&&!Ie){b({type:"star",value:i,output:""});continue}for(;p.slice(0,3)==="/**";){let me=t[l.index+4];if(me&&me!=="/")break;p=p.slice(3),K("/**",3)}if(c.type==="bos"&&V()){s.type="globstar",s.value+=i,s.output=N(e),l.output=s.output,l.globstar=!0,K(i);continue}if(c.type==="slash"&&c.prev.type!=="bos"&&!G&&V()){l.output=l.output.slice(0,-(c.output+s.output).length),c.output=`(?:${c.output}`,s.type="globstar",s.output=N(e)+(e.strictSlashes?")":"|$)"),s.value+=i,l.globstar=!0,l.output+=c.output+s.output,K(i);continue}if(c.type==="slash"&&c.prev.type!=="bos"&&p[0]==="/"){let me=p[1]!==void 0?"|$":"";l.output=l.output.slice(0,-(c.output+s.output).length),c.output=`(?:${c.output}`,s.type="globstar",s.output=`${N(e)}${I}|${I}${me})`,s.value+=i,l.output+=c.output+s.output,l.globstar=!0,K(i+x()),b({type:"slash",value:"/",output:""});continue}if(c.type==="bos"&&p[0]==="/"){s.type="globstar",s.value+=i,s.output=`(?:^|${I}|${N(e)}${I})`,l.output=s.output,l.globstar=!0,K(i+x()),b({type:"slash",value:"/",output:""});continue}l.output=l.output.slice(0,-s.output.length),s.type="globstar",s.output=N(e),s.value+=i,l.output+=s.output,l.globstar=!0,K(i);continue}let E={type:"star",value:i,output:R};if(e.bash===!0){E.output=".*?",(s.type==="bos"||s.type==="slash")&&(E.output=U+E.output),b(E);continue}if(s&&(s.type==="bracket"||s.type==="paren")&&e.regex===!0){E.output=i,b(E);continue}(l.index===l.start||s.type==="slash"||s.type==="dot")&&(s.type==="dot"?(l.output+=ne,s.output+=ne):e.dot===!0?(l.output+=Q,s.output+=Q):(l.output+=U,s.output+=U),y()!=="*"&&(l.output+=W,s.output+=W)),b(E)}for(;l.brackets>0;){if(e.strictBrackets===!0)throw new SyntaxError(pe("closing","]"));l.output=J.escapeLast(l.output,"["),ie("brackets")}for(;l.parens>0;){if(e.strictBrackets===!0)throw new SyntaxError(pe("closing",")"));l.output=J.escapeLast(l.output,"("),ie("parens")}for(;l.braces>0;){if(e.strictBrackets===!0)throw new SyntaxError(pe("closing","}"));l.output=J.escapeLast(l.output,"{"),ie("braces")}if(e.strictSlashes!==!0&&(s.type==="star"||s.type==="bracket")&&b({type:"maybe_slash",value:"",output:`${I}?`}),l.backtrack===!0){l.output="";for(let p of l.tokens)l.output+=p.output!=null?p.output:p.value,p.suffix&&(l.output+=p.suffix)}return l};We.fastpaths=(t,r)=>{let e={...r},o=typeof e.maxLength=="number"?Math.min(Te,e.maxLength):Te,n=t.length;if(n>o)throw new SyntaxError(`Input length: ${n}, exceeds maximum allowed length: ${o}`);t=Ct[t]||t;let{DOT_LITERAL:a,SLASH_LITERAL:u,ONE_CHAR:f,DOTS_SLASH:g,NO_DOT:h,NO_DOTS:C,NO_DOTS_SLASH:$,STAR:I,START_ANCHOR:W}=Se.globChars(e.windows),m=e.dot?C:h,H=e.dot?$:h,ne=e.capture?"":"?:",Q={negated:!1,prefix:""},_=e.bash===!0?".*?":I;e.capture&&(_=`(${_})`);let Z=U=>U.noglobstar===!0?_:`(${ne}(?:(?!${W}${U.dot?g:a}).)*?)`,se=U=>{switch(U){case"*":return`${m}${f}${_}`;case".*":return`${a}${f}${_}`;case"*.*":return`${m}${_}${a}${f}${_}`;case"*/*":return`${m}${_}${u}${f}${H}${_}`;case"**":return m+Z(e);case"**/*":return`(?:${m}${Z(e)}${u})?${H}${f}${_}`;case"**/*.*":return`(?:${m}${Z(e)}${u})?${H}${_}${a}${f}${_}`;case"**/.*":return`(?:${m}${Z(e)}${u})?${a}${f}${_}`;default:{let d=/^(.*?)\.(\w+)$/.exec(U);if(!d)return;let R=se(d[1]);return R?R+a+d[2]:void 0}}},D=J.removePrefix(t,Q),N=se(D);return N&&e.strictSlashes!==!0&&(N+=`${u}?`),N};mt.exports=We});var Ot=ue((Qr,Et)=>{"use strict";var Sr=bt(),Ue=yt(),_t=Ae(),Tr=de(),Lr=t=>t&&typeof t=="object"&&!Array.isArray(t),L=(t,r,e=!1)=>{if(Array.isArray(t)){let C=t.map(I=>L(I,r,e));return I=>{for(let W of C){let m=W(I);if(m)return m}return!1}}let o=Lr(t)&&t.tokens&&t.input;if(t===""||typeof t!="string"&&!o)throw new TypeError("Expected pattern to be a non-empty string");let n=r||{},a=n.windows,u=o?L.compileRe(t,r):L.makeRe(t,r,!1,!0),f=u.state;delete u.state;let g=()=>!1;if(n.ignore){let C={...r,ignore:null,onMatch:null,onResult:null};g=L(n.ignore,C,e)}let h=(C,$=!1)=>{let{isMatch:I,match:W,output:m}=L.test(C,u,r,{glob:t,posix:a}),H={glob:t,state:f,regex:u,posix:a,input:C,output:m,match:W,isMatch:I};return typeof n.onResult=="function"&&n.onResult(H),I===!1?(H.isMatch=!1,$?H:!1):g(C)?(typeof n.onIgnore=="function"&&n.onIgnore(H),H.isMatch=!1,$?H:!1):(typeof n.onMatch=="function"&&n.onMatch(H),$?H:!0)};return e&&(h.state=f),h};L.test=(t,r,e,{glob:o,posix:n}={})=>{if(typeof t!="string")throw new TypeError("Expected input to be a string");if(t==="")return{isMatch:!1,output:""};let a=e||{},u=a.format||(n?_t.toPosixSlashes:null),f=t===o,g=f&&u?u(t):t;return f===!1&&(g=u?u(t):t,f=g===o),(f===!1||a.capture===!0)&&(a.matchBase===!0||a.basename===!0?f=L.matchBase(t,r,e,n):f=r.exec(g)),{isMatch:!!f,match:f,output:g}};L.matchBase=(t,r,e)=>(r instanceof RegExp?r:L.makeRe(r,e)).test(_t.basename(t));L.isMatch=(t,r,e)=>L(r,e)(t);L.parse=(t,r)=>Array.isArray(t)?t.map(e=>L.parse(e,r)):Ue(t,{...r,fastpaths:!1});L.scan=(t,r)=>Sr(t,r);L.compileRe=(t,r,e=!1,o=!1)=>{if(e===!0)return t.output;let n=r||{},a=n.contains?"":"^",u=n.contains?"":"$",f=`${a}(?:${t.output})${u}`;t&&t.negated===!0&&(f=`^(?!${f}).*$`);let g=L.toRegex(f,r);return o===!0&&(g.state=t),g};L.makeRe=(t,r={},e=!1,o=!1)=>{if(!t||typeof t!="string")throw new TypeError("Expected a non-empty string");let n={negated:!1,fastpaths:!0};return r.fastpaths!==!1&&(t[0]==="."||t[0]==="*")&&(n.output=Ue.fastpaths(t,r)),n.output||(n=Ue(t,r)),L.compileRe(n,r,e,o)};L.toRegex=(t,r)=>{try{let e=r||{};return new RegExp(t,e.flags||(e.nocase?"i":""))}catch(e){if(r&&r.debug===!0)throw e;return/$^/}};L.constants=Tr;Et.exports=L});var Tt=ue((Zr,St)=>{"use strict";var xt=Ot(),$r=Ae();function vt(t,r,e=!1){return r&&(r.windows===null||r.windows===void 0)&&(r={...r,windows:$r.isWindows()}),xt(t,r,e)}Object.assign(vt,xt);St.exports=vt});var kr={};Pt(kr,{default:()=>wr});var F=ae("@yarnpkg/core");var Ye=(t=0)=>r=>`\x1B[${r+t}m`,Qe=(t=0)=>r=>`\x1B[${38+t};5;${r}m`,Ze=(t=0)=>(r,e,o)=>`\x1B[${38+t};2;${r};${e};${o}m`,O={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},Nr=Object.keys(O.modifier),Bt=Object.keys(O.color),jt=Object.keys(O.bgColor),Dr=[...Bt,...jt];function Ft(){let t=new Map;for(let[r,e]of Object.entries(O)){for(let[o,n]of Object.entries(e))O[o]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},e[o]=O[o],t.set(n[0],n[1]);Object.defineProperty(O,r,{value:e,enumerable:!1})}return Object.defineProperty(O,"codes",{value:t,enumerable:!1}),O.color.close="\x1B[39m",O.bgColor.close="\x1B[49m",O.color.ansi=Ye(),O.color.ansi256=Qe(),O.color.ansi16m=Ze(),O.bgColor.ansi=Ye(10),O.bgColor.ansi256=Qe(10),O.bgColor.ansi16m=Ze(10),Object.defineProperties(O,{rgbToAnsi256:{value(r,e,o){return r===e&&e===o?r<8?16:r>248?231:Math.round((r-8)/247*24)+232:16+36*Math.round(r/255*5)+6*Math.round(e/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(r){let e=/[a-f\d]{6}|[a-f\d]{3}/i.exec(r.toString(16));if(!e)return[0,0,0];let[o]=e;o.length===3&&(o=[...o].map(a=>a+a).join(""));let n=Number.parseInt(o,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:r=>O.rgbToAnsi256(...O.hexToRgb(r)),enumerable:!1},ansi256ToAnsi:{value(r){if(r<8)return 30+r;if(r<16)return 90+(r-8);let e,o,n;if(r>=232)e=((r-232)*10+8)/255,o=e,n=e;else{r-=16;let f=r%36;e=Math.floor(r/36)/5,o=Math.floor(f/6)/5,n=f%6/5}let a=Math.max(e,o,n)*2;if(a===0)return 30;let u=30+(Math.round(n)<<2|Math.round(o)<<1|Math.round(e));return a===2&&(u+=60),u},enumerable:!1},rgbToAnsi:{value:(r,e,o)=>O.ansi256ToAnsi(O.rgbToAnsi256(r,e,o)),enumerable:!1},hexToAnsi:{value:r=>O.ansi256ToAnsi(O.hexToAnsi256(r)),enumerable:!1}}),O}var Wt=Ft(),Y=Wt;var Oe=_e(ae("process"),1),Je=_e(ae("os"),1),we=_e(ae("tty"),1);function X(t,r=globalThis.Deno?globalThis.Deno.args:Oe.default.argv){let e=t.startsWith("-")?"":t.length===1?"-":"--",o=r.indexOf(e+t),n=r.indexOf("--");return o!==-1&&(n===-1||o=2,has16m:t>=3}}function Kt(t,{streamIsTTY:r,sniffFlags:e=!0}={}){let o=Ut();o!==void 0&&(Ee=o);let n=e?Ee:o;if(n===0)return 0;if(e){if(X("color=16m")||X("color=full")||X("color=truecolor"))return 3;if(X("color=256"))return 2}if("TF_BUILD"in S&&"AGENT_NAME"in S)return 1;if(t&&!r&&n===void 0)return 0;let a=n||0;if(S.TERM==="dumb")return a;if(Oe.default.platform==="win32"){let u=Je.default.release().split(".");return Number(u[0])>=10&&Number(u[2])>=10586?Number(u[2])>=14931?3:2:1}if("CI"in S)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(u=>u in S)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(u=>u in S)||S.CI_NAME==="codeship"?1:a;if("TEAMCITY_VERSION"in S)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(S.TEAMCITY_VERSION)?1:0;if(S.COLORTERM==="truecolor"||S.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in S){let u=Number.parseInt((S.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(S.TERM_PROGRAM){case"iTerm.app":return u>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(S.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(S.TERM)||"COLORTERM"in S?1:a}function ze(t,r={}){let e=Kt(t,{streamIsTTY:t&&t.isTTY,...r});return Vt(e)}var Xt={stdout:ze({isTTY:we.default.isatty(1)}),stderr:ze({isTTY:we.default.isatty(2)})},et=Xt;function tt(t,r,e){let o=t.indexOf(r);if(o===-1)return t;let n=r.length,a=0,u="";do u+=t.slice(a,o)+r+e,a=o+n,o=t.indexOf(r,a);while(o!==-1);return u+=t.slice(a),u}function rt(t,r,e,o){let n=0,a="";do{let u=t[o-1]==="\r";a+=t.slice(n,u?o-1:o)+r+(u?`\r `:` `)+e,n=o+1,o=t.indexOf(` -`,n)}while(o!==-1);return a+=t.slice(n),a}var{stdout:et,stderr:tt}=Ze,we=Symbol("GENERATOR"),ue=Symbol("STYLER"),pe=Symbol("IS_EMPTY"),rt=["ansi","ansi","ansi256","ansi16m"],ce=Object.create(null),Ut=(t,r={})=>{if(r.level&&!(Number.isInteger(r.level)&&r.level>=0&&r.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let e=et?et.level:0;t.level=r.level===void 0?e:r.level};var Kt=t=>{let r=(...e)=>e.join(" ");return Ut(r,t),Object.setPrototypeOf(r,ge.prototype),r};function ge(t){return Kt(t)}Object.setPrototypeOf(ge.prototype,Function.prototype);for(let[t,r]of Object.entries(q))ce[t]={get(){let e=Oe(this,Ne(r.open,r.close,this[ue]),this[pe]);return Object.defineProperty(this,t,{value:e}),e}};ce.visible={get(){let t=Oe(this,this[ue],!0);return Object.defineProperty(this,"visible",{value:t}),t}};var ke=(t,r,e,...o)=>t==="rgb"?r==="ansi16m"?q[e].ansi16m(...o):r==="ansi256"?q[e].ansi256(q.rgbToAnsi256(...o)):q[e].ansi(q.rgbToAnsi(...o)):t==="hex"?ke("rgb",r,e,...q.hexToRgb(...o)):q[e][t](...o),Xt=["rgb","hex","ansi256"];for(let t of Xt){ce[t]={get(){let{level:e}=this;return function(...o){let n=Ne(ke(t,rt[e],"color",...o),q.color.close,this[ue]);return Oe(this,n,this[pe])}}};let r="bg"+t[0].toUpperCase()+t.slice(1);ce[r]={get(){let{level:e}=this;return function(...o){let n=Ne(ke(t,rt[e],"bgColor",...o),q.bgColor.close,this[ue]);return Oe(this,n,this[pe])}}}}var qt=Object.defineProperties(()=>{},{...ce,level:{enumerable:!0,get(){return this[we].level},set(t){this[we].level=t}}}),Ne=(t,r,e)=>{let o,n;return e===void 0?(o=t,n=r):(o=e.openAll+t,n=r+e.closeAll),{open:t,close:r,openAll:o,closeAll:n,parent:e}},Oe=(t,r,e)=>{let o=(...n)=>Yt(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,qt),o[we]=t,o[ue]=r,o[pe]=e,o},Yt=(t,r)=>{if(t.level<=0||!r)return t[pe]?"":r;let e=t[ue];if(e===void 0)return r;let{openAll:o,closeAll:n}=e;if(r.includes("\x1B"))for(;e!==void 0;)r=ze(r,e.close,e.open),e=e.parent;let a=r.indexOf(` -`);return a!==-1&&(r=Je(r,n,o,a)),o+r+n};Object.defineProperties(ge.prototype,ce);var Qt=ge(),jr=ge({level:tt?tt.level:0});var he=Qt;var Ve=fe("@yarnpkg/core"),St=Ee(Ot()),re="root",X="catalog:",W=class extends Error{constructor(e,o){super(e);this.code=o;this.name="CatalogConfigurationError"}static{this.FILE_NOT_FOUND="FILE_NOT_FOUND"}static{this.INVALID_FORMAT="INVALID_FORMAT"}static{this.INVALID_ALIAS="INVALID_ALIAS"}},$e=class{constructor(){this.configCache=new Map}getInheritanceChain(r){let e=r.split("/"),o=[];for(let n=0;n=0;u--){let p=n[u],l=r.list?.[p];if(l&&typeof l=="object"){let h=l[o];if(h)return h}}if(r.list&&typeof r.list=="object"){let u=r.list[o];if(typeof u=="string")return u}let a=r.list?.[re];if(a&&typeof a=="object"){let u=a[o];if(u)return u}return null}validateInheritanceStructure(r){if(!r.list)return!0;let e=Object.keys(r.list);for(let o of e)if(typeof r.list[o]!="string"&&o.includes("/")){let n=this.getInheritanceChain(o);for(let a=0;a(typeof h=="string"?p[re]={...p[re]||{},[l]:h}:p[l]=h,p),{}):u.list={},!this.isValidConfiguration(u))throw new W("Invalid catalogs configuration format. Expected structure: { options?: { default?: string[] | 'max', ignoredWorkspaces?: string[], validation?: 'off' | 'warn' | 'strict' | { [package: string]: 'off' | 'warn' | 'strict' } }, list: { [alias: string]: { [packageName: string]: string } } }",W.INVALID_FORMAT);if(!this.validateInheritanceStructure(u))throw new W("Invalid inheritance structure in catalogs configuration. Check for missing parent groups.",W.INVALID_ALIAS);return this.configCache.set(o,u),u}async getRange(r,e,o){let n=await this.readConfiguration(r),a=e.length===0?re:e,u=this.resolveInheritedRange(n,a,o);if(u)return/^[^:]+:/.test(u)?u:`${r.configuration.get("defaultProtocol")}${u}`;let p=n.list?.[a];if(!p||typeof p=="string")throw new W(`Alias "${a}" not found in .yarnrc.yml catalogs.`,W.INVALID_ALIAS);let l=p[o];if(!l)throw new W(`Package "${o}" not found in alias "${a}"`,W.INVALID_ALIAS);return/^[^:]+:/.test(l)?l:`${r.configuration.get("defaultProtocol")}${l}`}async getDefaultAliasGroups(r){let e=await this.readConfiguration(r.project);if(e.options){if(await this.shouldIgnoreWorkspace(r))return[];if(e.options.default){if(Array.isArray(e.options.default))return e.options.default;if(e.options.default==="max"){let o=Object.keys(e.list||{}),n=[...r.manifest.dependencies,...r.manifest.devDependencies],a=Object.fromEntries(o.map(p=>[p,0]));for(let[p,l]of n)if(l.range.startsWith(X)){let h=l.range.substring(X.length);a[h]=(a[h]||0)+1}let u=Math.max(...Object.values(a));return Object.keys(a).filter(p=>a[p]===u)}}}return[]}async findAllAccessibleGroups(r,e){let o=await this.readConfiguration(r),n=[];for(let a of Object.keys(o.list||{}))this.resolveInheritedRange(o,a,e)&&n.push(a);return n}async getGroupValidationLevel(r,e){let n=(await this.readConfiguration(r.project)).options?.validation||"warn";if(typeof n=="string")return n;let a=this.getInheritanceChain(e);for(let u=a.length-1;u>=0;u--){let p=a[u];if(n[p]!==void 0)return n[p]}return"warn"}async getValidationLevelForPackage(r,e){let o=await this.findAllAccessibleGroups(r.project,e);if(o.length===0)return"off";let n=[];for(let a of o){let u=await this.getGroupValidationLevel(r,a);n.push(u)}return n.includes("strict")?"strict":n.includes("warn")?"warn":"off"}async findDependency(r,e){let o=Ve.structUtils.stringifyIdent(e),n=await this.readConfiguration(r),a=[],u=Object.entries(n.list||{}).filter(([p,l])=>typeof l=="string"?o===l:Object.keys(l).includes(o));a.push(...u.map(([p,l])=>{let h=typeof l=="string"?l:l[o];return[p,h]}));for(let[p]of Object.entries(n.list||{})){if(a.some(([h])=>h===p))continue;let l=this.resolveInheritedRange(n,p,o);l&&a.push([p,l])}return a}clearCache(r){this.configCache.delete(r)}async shouldIgnoreWorkspace(r){if(!r.manifest.name)return!1;let e=await this.readConfiguration(r.project);return e.options?.ignoredWorkspaces?(0,St.isMatch)(Ve.structUtils.stringifyIdent(r.manifest.name),e.options.ignoredWorkspaces):!1}async getValidationLevel(r){let e=await this.readConfiguration(r.project);return e.options?.validation&&typeof e.options.validation=="string"?e.options.validation:"warn"}isValidConfiguration(r){if(!r||typeof r!="object"||!("list"in r)||!r.list||typeof r.list!="object")return!1;for(let[e,o]of Object.entries(r.list)){if(!o||typeof o!="object")return!1;for(let n of Object.values(o))if(typeof n!="string")return!1}if("options"in r&&r.options&&typeof r.options=="object"){if("ignoredWorkspaces"in r.options&&r.options.ignoredWorkspaces&&(!Array.isArray(r.options.ignoredWorkspaces)||r.options.ignoredWorkspaces.length===0))return!1;if("default"in r.options&&r.options.default){if(Array.isArray(r.options.default)){if(r.options.default.length===0)return!1;let e=Object.keys(r.list||{});for(let o of r.options.default)if(o!=="root"&&!e.includes(o))if(o.includes("/")){let n=this.getInheritanceChain(o),a=!0;for(let u of n)if(u!=="root"&&!e.includes(u)){a=!1;break}if(!a)return!1}else return!1}else if(typeof r.options.default!="string"||r.options.default!=="max")return!1}if("validation"in r.options){let e=r.options.validation;if(typeof e=="string"){if(!["warn","strict","off"].includes(e))return!1}else if(typeof e=="object"&&e!==null)for(let[o,n]of Object.entries(e)){if(typeof n!="string"||!["warn","strict","off"].includes(n))return!1;let a=Object.keys(r.list||{});if(!a.includes(o)&&o!==re)if(o.includes("/")){let u=this.getInheritanceChain(o),p=!0;for(let l of u)if(l!==re&&!a.includes(l)){p=!1;break}if(!p)return!1}else return!1}else return!1}}return!0}};var Y=new $e,Tr={configuration:{catalogs:{description:"Define dependency version ranges as reusable constants across your project.",type:B.SettingsType.ANY,default:{}}},hooks:{validateWorkspace:async(t,r)=>{let e=await Y.shouldIgnoreWorkspace(t);if(!e){let n=await $r(t);if(n.length>0){let a=n.filter(l=>l.validationLevel==="strict"),u=n.filter(l=>l.validationLevel==="warn"),p=l=>`The following dependencies are listed in the catalogs but not using the catalog protocol: ${l.map(C=>he.yellow(C.packageName)).join(", ")}. Consider using the catalog protocol instead.`;a.length>0&&r.reportError(B.MessageName.INVALID_MANIFEST,p(a)),u.length>0&&r.reportWarning(B.MessageName.INVALID_MANIFEST,p(u))}}let o=[...Object.values(t.manifest.raw.dependencies||{}),...Object.values(t.manifest.raw.devDependencies||{})].some(n=>n.startsWith(X));e&&o&&r.reportError(B.MessageName.INVALID_MANIFEST,"Workspace is ignored from the catalogs, but it has dependencies with the catalog protocol. Consider removing the protocol.")},reduceDependency:async(t,r,...e)=>{let o=t.range.startsWith(X),n=t.range.includes("catalog%3A")&&t.range.startsWith("patch:");if(!o&&!n)return t;try{let a="",u=t.range;if(o)a=t.range.slice(X.length);else if(n){let L=t.range.match(/catalog%3A([^#&]*)/);L&&(a=L[1]||"")}let p=B.structUtils.stringifyIdent(t),l=await Y.getRange(r,a,p),h;if(o?h=B.structUtils.makeDescriptor(B.structUtils.makeIdent(t.scope,t.name),l):h=B.structUtils.makeDescriptor(B.structUtils.makeIdent(t.scope,t.name),u.replace(/catalog%3A[^#&]*/,l)),n)return h;let C=await r.configuration.reduceHook(L=>L.reduceDependency,h,r,...e);return C!==h?C:h}catch(a){throw a instanceof W?new Error(`Failed to resolve ${B.structUtils.stringifyDescriptor(t)}: ${a.message}`):a}},afterWorkspaceDependencyAddition:async(t,r,e)=>{vt(t,e)},afterWorkspaceDependencyReplacement:async(t,r,e,o)=>{vt(t,o)},beforeWorkspacePacking:async(t,r)=>{if(await Y.shouldIgnoreWorkspace(t))return;let e=["dependencies","devDependencies","peerDependencies","optionalDependencies"];for(let o of e){let n=r[o];if(!(!n||typeof n!="object"))for(let[a,u]of Object.entries(n)){let p=u;if(p.startsWith(X))try{let l=p.slice(X.length),h=await Y.getRange(t.project,l,a);n[a]=h}catch(l){throw l instanceof W?new Error(`Failed to resolve catalog dependency ${a}@${p} during packaging: ${l.message}`):l}}}}}};async function $r(t){let r=[...Object.entries(t.manifest.raw.dependencies||{}),...Object.entries(t.manifest.raw.devDependencies||{})],e=[];for(let[o,n]of r){if(n.startsWith(X))continue;let u=await Y.findAllAccessibleGroups(t.project,o);if(u.length>0){let p=await Y.getValidationLevelForPackage(t,o);p!=="off"&&e.push({packageName:o,validationLevel:p,applicableGroups:u})}}return e}async function vt(t,r){if(r.range.startsWith(X)){if(await Y.shouldIgnoreWorkspace(t))throw new Error(he.red("The workspace is ignored from the catalogs, but the dependency to add is using the catalog protocol. Consider removing the protocol."));return}if(await Y.shouldIgnoreWorkspace(t))return;let e=await Y.findDependency(t.project,r);if(e.length===0)return;let o=await Y.getDefaultAliasGroups(t);if(o.length>0){for(let l of o)if(e.some(([h])=>h===l)){r.range=`${X}${l}`;return}}let n=e.map(([l])=>l===re?"":l),a=n.filter(l=>l!=="").length>0?` (${n.join(", ")})`:"",u=await Y.getValidationLevelForPackage(t,B.structUtils.stringifyIdent(r)),p=`\u27A4 ${r.name} is listed in the catalogs config${a}, but it seems you're adding it without the catalog protocol. Consider running 'yarn add ${r.name}@${X}${n[0]}' instead.`;if(u==="strict")throw new Error(he.red(p));u==="warn"&&console.warn(he.yellow(p))}var Lr=Tr;return Dt(Ir);})(); +`,n)}while(o!==-1);return a+=t.slice(n),a}var{stdout:ot,stderr:nt}=et,ke=Symbol("GENERATOR"),le=Symbol("STYLER"),ge=Symbol("IS_EMPTY"),st=["ansi","ansi","ansi256","ansi16m"],ce=Object.create(null),qt=(t,r={})=>{if(r.level&&!(Number.isInteger(r.level)&&r.level>=0&&r.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let e=ot?ot.level:0;t.level=r.level===void 0?e:r.level};var Yt=t=>{let r=(...e)=>e.join(" ");return qt(r,t),Object.setPrototypeOf(r,he.prototype),r};function he(t){return Yt(t)}Object.setPrototypeOf(he.prototype,Function.prototype);for(let[t,r]of Object.entries(Y))ce[t]={get(){let e=xe(this,Ne(r.open,r.close,this[le]),this[ge]);return Object.defineProperty(this,t,{value:e}),e}};ce.visible={get(){let t=xe(this,this[le],!0);return Object.defineProperty(this,"visible",{value:t}),t}};var He=(t,r,e,...o)=>t==="rgb"?r==="ansi16m"?Y[e].ansi16m(...o):r==="ansi256"?Y[e].ansi256(Y.rgbToAnsi256(...o)):Y[e].ansi(Y.rgbToAnsi(...o)):t==="hex"?He("rgb",r,e,...Y.hexToRgb(...o)):Y[e][t](...o),Qt=["rgb","hex","ansi256"];for(let t of Qt){ce[t]={get(){let{level:e}=this;return function(...o){let n=Ne(He(t,st[e],"color",...o),Y.color.close,this[le]);return xe(this,n,this[ge])}}};let r="bg"+t[0].toUpperCase()+t.slice(1);ce[r]={get(){let{level:e}=this;return function(...o){let n=Ne(He(t,st[e],"bgColor",...o),Y.bgColor.close,this[le]);return xe(this,n,this[ge])}}}}var Zt=Object.defineProperties(()=>{},{...ce,level:{enumerable:!0,get(){return this[ke].level},set(t){this[ke].level=t}}}),Ne=(t,r,e)=>{let o,n;return e===void 0?(o=t,n=r):(o=e.openAll+t,n=r+e.closeAll),{open:t,close:r,openAll:o,closeAll:n,parent:e}},xe=(t,r,e)=>{let o=(...n)=>zt(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,Zt),o[ke]=t,o[le]=r,o[ge]=e,o},zt=(t,r)=>{if(t.level<=0||!r)return t[ge]?"":r;let e=t[le];if(e===void 0)return r;let{openAll:o,closeAll:n}=e;if(r.includes("\x1B"))for(;e!==void 0;)r=tt(r,e.close,e.open),e=e.parent;let a=r.indexOf(` +`);return a!==-1&&(r=rt(r,n,o,a)),o+r+n};Object.defineProperties(he.prototype,ce);var Jt=he(),Wr=he({level:nt?nt.level:0});var fe=Jt;var B=class extends Error{constructor(e,o){super(e);this.code=o;this.name="CatalogConfigurationError"}static{this.FILE_NOT_FOUND="FILE_NOT_FOUND"}static{this.INVALID_FORMAT="INVALID_FORMAT"}static{this.INVALID_ALIAS="INVALID_ALIAS"}};var Ve=ae("@yarnpkg/core"),Lt=_e(Tt());var ee="root",P="catalog:";var Le=class{constructor(){this.configCache=new Map}getInheritanceChain(r){let e=r.split("/"),o=[];for(let n=0;n=0;u--){let f=n[u],g=r.list?.[f];if(g&&typeof g=="object"){let h=g[o];if(h)return h}}if(r.list&&typeof r.list=="object"){let u=r.list[o];if(typeof u=="string")return u}let a=r.list?.[ee];if(a&&typeof a=="object"){let u=a[o];if(u)return u}return null}validateInheritanceStructure(r){if(!r.list)return!0;let e=Object.keys(r.list);for(let o of e)if(typeof r.list[o]!="string"&&o.includes("/")){let n=this.getInheritanceChain(o);for(let a=0;a(typeof h=="string"?f[ee]={...f[ee]||{},[g]:h}:f[g]=h,f),{}):u.list={},!this.isValidConfiguration(u))throw new B("Invalid catalogs configuration format. Expected structure: { options?: { default?: string[] | 'max', ignoredWorkspaces?: string[], validation?: 'off' | 'warn' | 'strict' | { [package: string]: 'off' | 'warn' | 'strict' } }, list: { [alias: string]: { [packageName: string]: string } } }",B.INVALID_FORMAT);if(!this.validateInheritanceStructure(u))throw new B("Invalid inheritance structure in catalogs configuration. Check for missing parent groups.",B.INVALID_ALIAS);return this.configCache.set(o,u),u}async getRange(r,e,o){let n=await this.readConfiguration(r),a=e.length===0?ee:e,u=this.resolveInheritedRange(n,a,o);if(u)return/^[^:]+:/.test(u)?u:`${r.configuration.get("defaultProtocol")}${u}`;let f=n.list?.[a];if(!f||typeof f=="string")throw new B(`Alias "${a}" not found in .yarnrc.yml catalogs.`,B.INVALID_ALIAS);let g=f[o];if(!g)throw new B(`Package "${o}" not found in alias "${a}"`,B.INVALID_ALIAS);return/^[^:]+:/.test(g)?g:`${r.configuration.get("defaultProtocol")}${g}`}async getDefaultAliasGroups(r){let e=await this.readConfiguration(r.project);if(e.options){if(await this.shouldIgnoreWorkspace(r))return[];if(e.options.default){if(Array.isArray(e.options.default))return e.options.default;if(e.options.default==="max"){let o=Object.keys(e.list||{}),n=[...r.manifest.dependencies,...r.manifest.devDependencies],a=Object.fromEntries(o.map(f=>[f,0]));for(let[f,g]of n)if(g.range.startsWith(P)){let h=g.range.substring(P.length);a[h]=(a[h]||0)+1}let u=Math.max(...Object.values(a));return Object.keys(a).filter(f=>a[f]===u)}}}return[]}async getGroupValidationLevel(r,e){let n=(await this.readConfiguration(r.project)).options?.validation||"warn";if(typeof n=="string")return n;let a=this.getInheritanceChain(e);for(let u=a.length-1;u>=0;u--){let f=a[u];if(n[f]!==void 0)return n[f]}return"warn"}async getValidationLevelForPackage(r,e){let o=(await this.findDependency(r.project,e)).map(({groupName:a})=>a);if(o.length===0)return"off";let n=[];for(let a of o){let u=await this.getGroupValidationLevel(r,a);n.push(u)}return n.includes("strict")?"strict":n.includes("warn")?"warn":"off"}async findDependency(r,e){let o=Ve.structUtils.stringifyIdent(e),n=await this.readConfiguration(r),a=[];for(let u of Object.keys(n.list||{})){let f=this.resolveInheritedRange(n,u,o);f&&a.push({groupName:u,version:f})}return a}clearCache(r){this.configCache.delete(r)}async shouldIgnoreWorkspace(r){if(!r.manifest.name)return!1;let e=await this.readConfiguration(r.project);return e.options?.ignoredWorkspaces?(0,Lt.isMatch)(Ve.structUtils.stringifyIdent(r.manifest.name),e.options.ignoredWorkspaces):!1}async getValidationLevel(r){let e=await this.readConfiguration(r.project);return e.options?.validation&&typeof e.options.validation=="string"?e.options.validation:"warn"}isValidConfiguration(r){if(!r||typeof r!="object"||!("list"in r)||!r.list||typeof r.list!="object")return!1;for(let[e,o]of Object.entries(r.list)){if(!o||typeof o!="object")return!1;for(let n of Object.values(o))if(typeof n!="string")return!1}if("options"in r&&r.options&&typeof r.options=="object"){if("ignoredWorkspaces"in r.options&&r.options.ignoredWorkspaces&&(!Array.isArray(r.options.ignoredWorkspaces)||r.options.ignoredWorkspaces.length===0))return!1;if("default"in r.options&&r.options.default){if(Array.isArray(r.options.default)){if(r.options.default.length===0)return!1;let e=Object.keys(r.list||{});for(let o of r.options.default)if(o!=="root"&&!e.includes(o))if(o.includes("/")){let n=this.getInheritanceChain(o),a=!0;for(let u of n)if(u!=="root"&&!e.includes(u)){a=!1;break}if(!a)return!1}else return!1}else if(typeof r.options.default!="string"||r.options.default!=="max")return!1}if("validation"in r.options){let e=r.options.validation;if(typeof e=="string"){if(!["warn","strict","off"].includes(e))return!1}else if(typeof e=="object"&&e!==null)for(let[o,n]of Object.entries(e)){if(typeof n!="string"||!["warn","strict","off"].includes(n))return!1;let a=Object.keys(r.list||{});if(!a.includes(o)&&o!==ee)if(o.includes("/")){let u=this.getInheritanceChain(o),f=!0;for(let g of u)if(g!==ee&&!a.includes(g)){f=!1;break}if(!f)return!1}else return!1}else return!1}}return!0}};var q=new Le;var Ke=ae("@yarnpkg/core");async function $e(t,r){if(r.range.startsWith(P)||await q.shouldIgnoreWorkspace(t))return null;let e=(await q.findDependency(t.project,r)).map(({groupName:n})=>n);return e.length===0?null:{validationLevel:await q.getValidationLevelForPackage(t,r),applicableGroups:e}}async function $t(t){let r=[...Object.entries(t.manifest.raw.dependencies??{}),...Object.entries(t.manifest.raw.devDependencies??{})].map(([o,n])=>{let a=Ke.structUtils.parseIdent(o);return Ke.structUtils.makeDescriptor(a,n)}),e=[];for(let o of r){let n=await $e(t,o);n&&n.validationLevel!=="off"&&e.push({descriptor:o,validationLevel:n.validationLevel,applicableGroups:n.applicableGroups})}return e}async function Xe(t,r){if(r.range.startsWith(P)){if(await q.shouldIgnoreWorkspace(t))throw new Error(fe.red("The workspace is ignored from the catalogs, but the dependency to add is using the catalog protocol. Consider removing the protocol."));return}let e=await $e(t,r);if(!e)return;let{validationLevel:o,applicableGroups:n}=e,a=await q.getDefaultAliasGroups(t);if(a.length>0){for(let h of a)if(n.includes(h)){r.range=`${P}${h}`;return}}let u=n.map(h=>h===ee?"":h),f=u.filter(h=>h!=="").length>0?` (${u.join(", ")})`:"",g=`\u27A4 ${r.name} is listed in the catalogs config${f}, but it seems you're adding it without the catalog protocol. Consider running 'yarn add ${r.name}@${P}${u[0]}' instead.`;if(o==="strict")throw new Error(fe.red(g));o==="warn"&&console.warn(fe.yellow(g))}var Ir={configuration:{catalogs:{description:"Define dependency version ranges as reusable constants across your project.",type:F.SettingsType.ANY,default:{}}},hooks:{validateWorkspace:async(t,r)=>{let e=await q.shouldIgnoreWorkspace(t);if(!e){let n=await $t(t);if(n.length>0){let a=n.filter(g=>g.validationLevel==="strict"),u=n.filter(g=>g.validationLevel==="warn"),f=g=>`The following dependencies are listed in the catalogs but not using the catalog protocol: ${g.map(C=>fe.yellow(F.structUtils.stringifyDescriptor(C.descriptor))).join(", ")}. Consider using the catalog protocol instead.`;a.length>0&&r.reportError(F.MessageName.INVALID_MANIFEST,f(a)),u.length>0&&r.reportWarning(F.MessageName.INVALID_MANIFEST,f(u))}}let o=[...Object.values(t.manifest.raw.dependencies||{}),...Object.values(t.manifest.raw.devDependencies||{})].some(n=>n.startsWith(P));e&&o&&r.reportError(F.MessageName.INVALID_MANIFEST,"Workspace is ignored from the catalogs, but it has dependencies with the catalog protocol. Consider removing the protocol.")},reduceDependency:async(t,r,...e)=>{let o=t.range.startsWith(P),n=t.range.includes("catalog%3A")&&t.range.startsWith("patch:");if(!o&&!n)return t;try{let a="",u=t.range;if(o)a=t.range.slice(P.length);else if(n){let $=t.range.match(/catalog%3A([^#&]*)/);$&&(a=$[1]||"")}let f=F.structUtils.stringifyIdent(t),g=await q.getRange(r,a,f),h;if(o?h=F.structUtils.makeDescriptor(F.structUtils.makeIdent(t.scope,t.name),g):h=F.structUtils.makeDescriptor(F.structUtils.makeIdent(t.scope,t.name),u.replace(/catalog%3A[^#&]*/,g)),n)return h;let C=await r.configuration.reduceHook($=>$.reduceDependency,h,r,...e);return C!==h?C:h}catch(a){throw a instanceof B?new Error(`Failed to resolve ${F.structUtils.stringifyDescriptor(t)}: ${a.message}`):a}},afterWorkspaceDependencyAddition:async(t,r,e)=>{Xe(t,e)},afterWorkspaceDependencyReplacement:async(t,r,e,o)=>{Xe(t,o)},beforeWorkspacePacking:async(t,r)=>{if(await q.shouldIgnoreWorkspace(t))return;let e=["dependencies","devDependencies","peerDependencies","optionalDependencies"];for(let o of e){let n=r[o];if(!(!n||typeof n!="object"))for(let[a,u]of Object.entries(n)){let f=u;if(f.startsWith(P))try{let g=f.slice(P.length),h=await q.getRange(t.project,g,a);n[a]=h}catch(g){throw g instanceof B?new Error(`Failed to resolve catalog dependency ${a}@${f} during packaging: ${g.message}`):g}}}}}},wr=Ir;return Mt(kr);})(); return plugin; } }; diff --git a/package.json b/package.json index b548463..d77ca59 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "build:dev": "builder build plugin --no-minify", "clean": "rimraf bundles", "test": "yarn build && vitest run", - "test:watch": "yarn build && vitest watch" + "test:watch": "yarn build && vitest watch", + "typecheck": "tsc --noEmit" }, "packageManager": "yarn@4.6.0" } diff --git a/sources/__tests__/utils.ts b/sources/__tests__/utils.ts index 148b619..932be5e 100644 --- a/sources/__tests__/utils.ts +++ b/sources/__tests__/utils.ts @@ -1,10 +1,10 @@ import { dir as tmpDir } from "tmp-promise"; -import { writeFile } from "fs/promises"; -import { join } from "path"; -import { execFile } from "child_process"; -import { promisify } from "util"; +import { writeFile } from "node:fs/promises"; +import { join } from "node:path"; +import { execFile } from "node:child_process"; +import { promisify } from "node:util"; import { dump as yamlDump } from "js-yaml"; -import * as fs from "fs/promises"; +import * as fs from "node:fs/promises"; const execFileAsync = promisify(execFile); @@ -58,7 +58,7 @@ export async function createTestWorkspace(): Promise { const existingContent = await fs .readFile(yarnrcPath, "utf8") .catch(() => ""); - await writeFile(yarnrcPath, existingContent + "\n" + yamlDump(content)); + await writeFile(yarnrcPath, `${existingContent}\n${yamlDump(content)}`); }; return { @@ -75,7 +75,7 @@ export async function createTestWorkspace(): Promise { */ export async function createTestProtocolPlugin( workspace: TestWorkspace, - protocolName: string + protocolName: string, ): Promise { const pluginCode = ` module.exports = { @@ -122,7 +122,7 @@ export function extractDependencies(log: string): string[] { .filter((str) => str != null && str.length > 0) .map( (depsString) => - JSON.parse(depsString) as { value: string; children: object } + JSON.parse(depsString) as { value: string; children: object }, ) .reduce((result, item) => [...result, item.value], [] as string[]); } diff --git a/sources/configuration.ts b/sources/configuration.ts deleted file mode 100644 index 62e1193..0000000 --- a/sources/configuration.ts +++ /dev/null @@ -1,644 +0,0 @@ -import { Descriptor, Project, structUtils, Workspace } from "@yarnpkg/core"; -import { isMatch } from "picomatch"; - -export const ROOT_ALIAS_GROUP = "root"; - -export const CATALOG_PROTOCOL = "catalog:"; - -declare module "@yarnpkg/core" { - interface ConfigurationValueMap { - catalogs?: CatalogsConfiguration; - } -} - -type ValidationLevel = "warn" | "strict" | "off"; -type ValidationConfig = - | ValidationLevel - | { [groupName: string]: ValidationLevel }; - -/** - * Configuration structure for .yarnrc.yml#catalogs - */ -export interface CatalogsConfiguration { - options?: { - /** - * The default alias group to be used when no group is specified when adding a dependency - * - if list of alias groups, it will be used in order - * - if 'max', the most frequently used alias group will be used - */ - default?: string[] | "max"; - /** - * List of workspaces to ignore - */ - ignoredWorkspaces?: string[]; - /** - * Validation level for catalog usage - * - 'warn': Show warnings when catalog versions are not used (default) - * - 'strict': Throw errors when catalog versions are not used - * - 'off': Disable validation - * Can also be an object with group-specific settings: { [groupName]: 'warn' | 'strict' | 'off' } - */ - validation?: ValidationConfig; - }; - list?: { - [alias: string]: - | { - [packageName: string]: string; - } - | string; - }; -} - -/** - * Error thrown when .yarnrc.yml#catalogs is invalid or missing - */ -export class CatalogConfigurationError extends Error { - constructor( - message: string, - public readonly code: string, - ) { - super(message); - this.name = "CatalogConfigurationError"; - } - - static FILE_NOT_FOUND = "FILE_NOT_FOUND"; - static INVALID_FORMAT = "INVALID_FORMAT"; - static INVALID_ALIAS = "INVALID_ALIAS"; -} - -/** - * Handles reading and parsing of .yarnrc.yml#catalogs configuration - */ -export class CatalogConfigurationReader { - private configCache: Map = new Map(); - - /** - * Parse inheritance chain from group name - * e.g., "stable/canary/next" to ["stable", "stable/canary", "stable/canary/next"] - */ - private getInheritanceChain(groupName: string): string[] { - const parts = groupName.split("/"); - const chain: string[] = []; - - for (let i = 0; i < parts.length; i++) { - chain.push(parts.slice(0, i + 1).join("/")); - } - - return chain; - } - - /** - * Resolve package version through inheritance chain - */ - private resolveInheritedRange( - config: CatalogsConfiguration, - groupName: string, - packageName: string, - ): string | null { - const chain = this.getInheritanceChain(groupName); - - // Search from most specific to least specific - for (let i = chain.length - 1; i >= 0; i--) { - const currentGroup = chain[i]; - const aliasConfig = config.list?.[currentGroup]; - - if (aliasConfig && typeof aliasConfig === "object") { - const version = aliasConfig[packageName]; - if (version) { - return version; - } - } - } - - // Check root-level packages (packages that are direct string values) - if (config.list && typeof config.list === "object") { - const rootValue = config.list[packageName]; - if (typeof rootValue === "string") { - return rootValue; - } - } - - // Check ROOT_ALIAS_GROUP if it exists - const rootAliasConfig = config.list?.[ROOT_ALIAS_GROUP]; - if (rootAliasConfig && typeof rootAliasConfig === "object") { - const version = rootAliasConfig[packageName]; - if (version) { - return version; - } - } - - return null; - } - - /** - * Validate inheritance structure in configuration - */ - private validateInheritanceStructure(config: CatalogsConfiguration): boolean { - if (!config.list) return true; - - const groups = Object.keys(config.list); - - for (const group of groups) { - // Skip root-level string values - if (typeof config.list[group] === "string") continue; - - // Validate that parent groups exist - if (group.includes("/")) { - const chain = this.getInheritanceChain(group); - for (let i = 0; i < chain.length - 1; i++) { - const parentGroup = chain[i]; - if ( - !groups.includes(parentGroup) && - parentGroup !== ROOT_ALIAS_GROUP - ) { - return false; - } - } - } - } - - return true; - } - - /** - * Read and parse the .yarnrc.yml#catalogs file - */ - async readConfiguration(project: Project): Promise { - const workspaceRoot = project.cwd; - const cacheKey = workspaceRoot; - - // Check cache first - const cached = this.configCache.get(cacheKey); - if (cached) { - return cached; - } - - // Get config from project configuration - const rawConfig = (project.configuration.get("catalogs") || {}) as Record< - string, - object - >; - - let config = rawConfig; - // Transform config to handle root-level string values - if (rawConfig["list"]) { - config["list"] = Object.entries(rawConfig["list"]).reduce( - (acc, [key, value]) => { - if (typeof value === "string") { - // If value is a string, put it under BASE_ALIAS_GROUP - acc[ROOT_ALIAS_GROUP] = { - ...(acc[ROOT_ALIAS_GROUP] || {}), - [key]: value, - }; - } else { - // Otherwise keep the original structure - acc[key] = value; - } - return acc; - }, - {} as Record, - ); - } else { - config["list"] = {}; - } - - // Validate configuration structure - if (!this.isValidConfiguration(config)) { - throw new CatalogConfigurationError( - "Invalid catalogs configuration format. Expected structure: { options?: { default?: string[] | 'max', ignoredWorkspaces?: string[], validation?: 'off' | 'warn' | 'strict' | { [package: string]: 'off' | 'warn' | 'strict' } }, list: { [alias: string]: { [packageName: string]: string } } }", - CatalogConfigurationError.INVALID_FORMAT, - ); - } - - // Validate inheritance structure - if (!this.validateInheritanceStructure(config)) { - throw new CatalogConfigurationError( - "Invalid inheritance structure in catalogs configuration. Check for missing parent groups.", - CatalogConfigurationError.INVALID_ALIAS, - ); - } - - // Cache the configuration - this.configCache.set(cacheKey, config); - - return config; - } - - /** - * Get a specific version from the configuration - */ - async getRange( - project: Project, - aliasGroup: string, - packageName: string, - ): Promise { - const config = await this.readConfiguration(project); - - const aliasGroupToFind = - aliasGroup.length === 0 ? ROOT_ALIAS_GROUP : aliasGroup; - - // Try to resolve through inheritance chain first - const inheritedVersion = this.resolveInheritedRange( - config, - aliasGroupToFind, - packageName, - ); - - if (inheritedVersion) { - // If version doesn't have a protocol prefix (e.g., "npm:"), add "npm:" as default - if (!/^[^:]+:/.test(inheritedVersion)) { - return `${project.configuration.get("defaultProtocol")}${inheritedVersion}`; - } - return inheritedVersion; - } - - // Fallback to direct lookup for backward compatibility - const aliasConfig = config.list?.[aliasGroupToFind]; - - if (!aliasConfig || typeof aliasConfig === "string") { - throw new CatalogConfigurationError( - `Alias "${aliasGroupToFind}" not found in .yarnrc.yml catalogs.`, - CatalogConfigurationError.INVALID_ALIAS, - ); - } - - const version = aliasConfig[packageName]; - if (!version) { - throw new CatalogConfigurationError( - `Package "${packageName}" not found in alias "${aliasGroupToFind}"`, - CatalogConfigurationError.INVALID_ALIAS, - ); - } - - // If version doesn't have a protocol prefix (e.g., "npm:"), add "npm:" as default - if (!/^[^:]+:/.test(version)) { - return `${project.configuration.get("defaultProtocol")}${version}`; - } - - return version; - } - - /** - * Get the default alias group from the configuration if it exists - */ - async getDefaultAliasGroups(workspace: Workspace): Promise { - const config = await this.readConfiguration(workspace.project); - - if (config.options) { - // There's no default alias group if the workspace should be ignored - if (await this.shouldIgnoreWorkspace(workspace)) { - return []; - } - - if (config.options.default) { - // If default value is an list of alias groups, return it - if (Array.isArray(config.options.default)) { - return config.options.default; - } - - // If default value is "max", find the most frequently used alias group - if (config.options.default === "max") { - const aliasGroups = Object.keys(config.list || {}); - - const dependencies = [ - ...workspace.manifest.dependencies, - ...workspace.manifest.devDependencies, - ]; - const counts: Record = Object.fromEntries( - aliasGroups.map((aliasGroup) => [aliasGroup, 0]), - ); - - // Count the occurrences of each alias group in the dependencies - for (const [_, descriptor] of dependencies) { - if (descriptor.range.startsWith(CATALOG_PROTOCOL)) { - const aliasGroup = descriptor.range.substring( - CATALOG_PROTOCOL.length, - ); - counts[aliasGroup] = (counts[aliasGroup] || 0) + 1; - } - } - - // Find the alias group with the maximum count of dependencies - const maxCount = Math.max(...Object.values(counts)); - return Object.keys(counts).filter( - (aliasGroup) => counts[aliasGroup] === maxCount, - ); - } - } - } - - return []; - } - - /** - * Find all groups that can access a specific package (including inheritance) - */ - async findAllAccessibleGroups( - project: Project, - packageName: string, - ): Promise { - const config = await this.readConfiguration(project); - const accessibleGroups: string[] = []; - - for (const groupName of Object.keys(config.list || {})) { - const resolvedRange = this.resolveInheritedRange( - config, - groupName, - packageName, - ); - if (resolvedRange) { - accessibleGroups.push(groupName); - } - } - - return accessibleGroups; - } - - /** - * Get validation level for a specific group (considering inheritance) - */ - async getGroupValidationLevel( - workspace: Workspace, - groupName: string, - ): Promise { - const config = await this.readConfiguration(workspace.project); - const validationConfig = config.options?.validation || "warn"; - - if (typeof validationConfig === "string") { - return validationConfig; - } - - // Search inheritance chain for explicit validation setting - const inheritanceChain = this.getInheritanceChain(groupName); - - for (let i = inheritanceChain.length - 1; i >= 0; i--) { - const currentGroup = inheritanceChain[i]; - if (validationConfig[currentGroup] !== undefined) { - return validationConfig[currentGroup]; - } - } - - return "warn"; // Default fallback - } - - /** - * Get the strictest validation level for a package across all accessible groups - */ - async getValidationLevelForPackage( - workspace: Workspace, - packageName: string, - ): Promise { - const accessibleGroups = await this.findAllAccessibleGroups( - workspace.project, - packageName, - ); - - if (accessibleGroups.length === 0) { - return "off"; - } - - const validationLevels: ValidationLevel[] = []; - for (const groupName of accessibleGroups) { - const level = await this.getGroupValidationLevel(workspace, groupName); - validationLevels.push(level); - } - - // Return the strictest level (strict > warn > off) - if (validationLevels.includes("strict")) return "strict"; - if (validationLevels.includes("warn")) return "warn"; - return "off"; - } - - /** - * Find a specific dependency in the configuration - * and return the names of alias groups it belongs to, along with its versions. - * This method now includes inherited groups in the results. - */ - async findDependency( - project: Project, - dependency: Descriptor, - ): Promise<[string, string][]> { - const dependencyString = structUtils.stringifyIdent(dependency); - const config = await this.readConfiguration(project); - const results: [string, string][] = []; - - // Direct lookup (existing behavior) - const aliasGroups = Object.entries(config.list || {}).filter( - ([_, value]) => { - if (typeof value === "string") { - return dependencyString === value; - } else { - return Object.keys(value).includes(dependencyString); - } - }, - ); - - results.push( - ...aliasGroups.map(([alias, aliasConfig]) => { - const version = - typeof aliasConfig === "string" - ? aliasConfig - : aliasConfig[dependencyString]; - return [alias, version] as [string, string]; - }), - ); - - // Check for inheritance-based matches - for (const [groupName] of Object.entries(config.list || {})) { - // Skip if already found in direct lookup - if (results.some(([alias]) => alias === groupName)) { - continue; - } - - // Check if dependency can be resolved through inheritance - const inheritedVersion = this.resolveInheritedRange( - config, - groupName, - dependencyString, - ); - - if (inheritedVersion) { - results.push([groupName, inheritedVersion]); - } - } - - return results; - } - - /** - * Clear the configuration cache for a specific workspace - */ - clearCache(workspaceRoot: string): void { - this.configCache.delete(workspaceRoot); - } - - /** - * Check if a workspace is ignored based on the configuration - */ - async shouldIgnoreWorkspace(workspace: Workspace): Promise { - if (!workspace.manifest.name) return false; - - const config = await this.readConfiguration(workspace.project); - - if (config.options?.ignoredWorkspaces) { - return isMatch( - structUtils.stringifyIdent(workspace.manifest.name), - config.options.ignoredWorkspaces, - ); - } - - return false; - } - - async getValidationLevel(workspace: Workspace): Promise { - const config = await this.readConfiguration(workspace.project); - - if (config.options?.validation) { - if (typeof config.options.validation === "string") { - return config.options.validation; - } - } - - return "warn"; - } - - private isValidConfiguration( - config: unknown, - ): config is CatalogsConfiguration { - if (!config || typeof config !== "object") { - return false; - } - - // The list property must be an object - if ( - !("list" in config) || - !config["list"] || - typeof config["list"] !== "object" - ) { - return false; - } - - for (const [_, aliasConfig] of Object.entries(config["list"])) { - if (!aliasConfig || typeof aliasConfig !== "object") { - return false; - } - - for (const version of Object.values(aliasConfig)) { - if (typeof version !== "string") { - return false; - } - } - } - - // Check the default option if it exists - if ( - "options" in config && - config["options"] && - typeof config["options"] === "object" - ) { - if ( - "ignoredWorkspaces" in config["options"] && - config["options"]["ignoredWorkspaces"] - ) { - if (!Array.isArray(config["options"]["ignoredWorkspaces"])) { - return false; - } - - if (config["options"]["ignoredWorkspaces"].length === 0) { - return false; - } - } - - if ("default" in config["options"] && config["options"]["default"]) { - if (Array.isArray(config["options"]["default"])) { - if (config["options"]["default"].length === 0) { - return false; - } - - const aliasGroups = Object.keys(config.list || {}); - for (const group of config.options.default) { - if (group !== "root" && !aliasGroups.includes(group)) { - // Check if it's a valid inheritance chain - if (group.includes("/")) { - const chain = this.getInheritanceChain(group); - let isValid = true; - for (const chainGroup of chain) { - if ( - chainGroup !== "root" && - !aliasGroups.includes(chainGroup) - ) { - isValid = false; - break; - } - } - if (!isValid) { - return false; - } - } else { - return false; - } - } - } - } else { - if (typeof config["options"]["default"] !== "string") { - return false; - } - - if (config["options"]["default"] !== "max") { - return false; - } - } - } - - if ("validation" in config["options"]) { - const validation = config["options"]["validation"]; - - if (typeof validation === "string") { - if (!["warn", "strict", "off"].includes(validation)) { - return false; - } - } else if (typeof validation === "object" && validation !== null) { - // Validate group-specific validation config - for (const [groupName, level] of Object.entries(validation)) { - if ( - typeof level !== "string" || - !["warn", "strict", "off"].includes(level) - ) { - return false; - } - - // Validate that the group exists or is a valid inheritance chain - const aliasGroups = Object.keys(config.list || {}); - if ( - !aliasGroups.includes(groupName) && - groupName !== ROOT_ALIAS_GROUP - ) { - if (groupName.includes("/")) { - const chain = this.getInheritanceChain(groupName); - let isValid = true; - for (const chainGroup of chain) { - if ( - chainGroup !== ROOT_ALIAS_GROUP && - !aliasGroups.includes(chainGroup) - ) { - isValid = false; - break; - } - } - if (!isValid) { - return false; - } - } else { - return false; - } - } - } - } else { - return false; - } - } - } - - return true; - } -} diff --git a/sources/configuration/errors.ts b/sources/configuration/errors.ts new file mode 100644 index 0000000..4eade52 --- /dev/null +++ b/sources/configuration/errors.ts @@ -0,0 +1,13 @@ +/** + * Error thrown when .yarnrc.yml#catalogs is invalid or missing + */ +export class CatalogConfigurationError extends Error { + constructor(message: string, public readonly code: string) { + super(message); + this.name = "CatalogConfigurationError"; + } + + static FILE_NOT_FOUND = "FILE_NOT_FOUND"; + static INVALID_FORMAT = "INVALID_FORMAT"; + static INVALID_ALIAS = "INVALID_ALIAS"; +} diff --git a/sources/configuration/index.ts b/sources/configuration/index.ts new file mode 100644 index 0000000..de03669 --- /dev/null +++ b/sources/configuration/index.ts @@ -0,0 +1,6 @@ +export * from "./types"; +export * from "./errors"; + +// Create a singleton instance of our configuration reader +import { CatalogConfigurationReader } from "./reader"; +export const configReader = new CatalogConfigurationReader(); diff --git a/sources/configuration/reader.ts b/sources/configuration/reader.ts new file mode 100644 index 0000000..bb40b35 --- /dev/null +++ b/sources/configuration/reader.ts @@ -0,0 +1,279 @@ +import { + type Descriptor, + type Project, + structUtils, + type Workspace, +} from "@yarnpkg/core"; +import { isMatch } from "picomatch"; +import type { CatalogsConfiguration } from "./types"; +import { CatalogConfigurationError } from "./errors"; +import { ROOT_ALIAS_GROUP, CATALOG_PROTOCOL } from "../constants"; +import type { ValidationLevel } from "../types"; +import { getInheritanceChain } from "../utils/functions"; + +/** + * Handles reading and parsing of .yarnrc.yml#catalogs configuration + */ +export class CatalogConfigurationReader { + private configCache: Map = new Map(); + + /** + * Read and parse the .yarnrc.yml#catalogs file + */ + async readConfiguration(project: Project): Promise { + const workspaceRoot = project.cwd; + const cacheKey = workspaceRoot; + + // Check cache first + const cached = this.configCache.get(cacheKey); + if (cached) { + return cached; + } + + // Get config from project configuration + const rawConfig = (project.configuration.get("catalogs") || {}) as Record< + string, + object + >; + + const config = rawConfig; + // Transform config to handle root-level string values + if (rawConfig.list) { + config.list = Object.entries(rawConfig.list).reduce( + (acc, [key, value]) => { + if (typeof value === "string") { + // If value is a string, put it under BASE_ALIAS_GROUP + acc[ROOT_ALIAS_GROUP] = { + ...(acc[ROOT_ALIAS_GROUP] || {}), + [key]: value, + }; + } else { + // Otherwise keep the original structure + acc[key] = value; + } + return acc; + }, + {} as Record, + ); + } else { + config.list = {}; + } + + // Validate configuration structure + if (!this.isValidConfiguration(config)) { + throw new CatalogConfigurationError( + "Invalid catalogs configuration format. Expected structure: { options?: { default?: string[] | 'max', ignoredWorkspaces?: string[], validation?: 'off' | 'warn' | 'strict' | { [package: string]: 'off' | 'warn' | 'strict' } }, list: { [alias: string]: { [packageName: string]: string } } }", + CatalogConfigurationError.INVALID_FORMAT, + ); + } + + // Validate inheritance structure + if (!this.validateInheritanceStructure(config)) { + throw new CatalogConfigurationError( + "Invalid inheritance structure in catalogs configuration. Check for missing parent groups.", + CatalogConfigurationError.INVALID_ALIAS, + ); + } + + // Cache the configuration + this.configCache.set(cacheKey, config); + + return config; + } + + /** + * Clear the configuration cache for a specific workspace + */ + clearCache(project: Project): void { + const workspaceRoot = project.cwd; + this.configCache.delete(workspaceRoot); + } + + /** + * Validate inheritance structure in configuration + */ + private validateInheritanceStructure(config: CatalogsConfiguration): boolean { + if (!config.list) return true; + + const groups = Object.keys(config.list); + + for (const group of groups) { + // Skip root-level string values + if (typeof config.list[group] === "string") continue; + + // Validate that parent groups exist + if (group.includes("/")) { + const chain = getInheritanceChain(group); + for (let i = 0; i < chain.length - 1; i++) { + const parentGroup = chain[i]; + if ( + !groups.includes(parentGroup) && + parentGroup !== ROOT_ALIAS_GROUP + ) { + return false; + } + } + } + } + + return true; + } + + private isValidConfiguration( + config: unknown, + ): config is CatalogsConfiguration { + if (!config || typeof config !== "object") { + return false; + } + + // The list property must be an object + if ( + !("list" in config) || + !config.list || + typeof config.list !== "object" + ) { + return false; + } + + for (const [_, aliasConfig] of Object.entries(config.list)) { + if (!aliasConfig || typeof aliasConfig !== "object") { + return false; + } + + for (const version of Object.values(aliasConfig)) { + if (typeof version !== "string") { + return false; + } + } + } + + // Check the default option if it exists + if ( + "options" in config && + config.options && + typeof config.options === "object" + ) { + if ( + "ignoredWorkspaces" in config.options && + config.options.ignoredWorkspaces + ) { + if (!Array.isArray(config.options.ignoredWorkspaces)) { + return false; + } + + if (config.options.ignoredWorkspaces.length === 0) { + return false; + } + } + + if ("default" in config.options && config.options.default) { + if (Array.isArray(config.options.default)) { + if (config.options.default.length === 0) { + return false; + } + + const aliasGroups = Object.keys(config.list || {}); + for (const group of config.options.default) { + if (group !== "root" && !aliasGroups.includes(group)) { + // Check if it's a valid inheritance chain + if (group.includes("/")) { + const chain = getInheritanceChain(group); + let isValid = true; + for (const chainGroup of chain) { + if ( + chainGroup !== "root" && + !aliasGroups.includes(chainGroup) + ) { + isValid = false; + break; + } + } + if (!isValid) { + return false; + } + } else { + return false; + } + } + } + } else { + if (typeof config.options.default !== "string") { + return false; + } + + if (config.options.default !== "max") { + return false; + } + } + } + + if ("validation" in config.options) { + const validation = config.options.validation; + + if (typeof validation === "string") { + if (!["warn", "strict", "off"].includes(validation)) { + return false; + } + } else if (typeof validation === "object" && validation !== null) { + // Validate group-specific validation config + for (const [groupName, level] of Object.entries(validation)) { + if ( + typeof level !== "string" || + !["warn", "strict", "off"].includes(level) + ) { + return false; + } + + // Validate that the group exists or is a valid inheritance chain + const aliasGroups = Object.keys(config.list || {}); + if ( + !aliasGroups.includes(groupName) && + groupName !== ROOT_ALIAS_GROUP + ) { + if (groupName.includes("/")) { + const chain = getInheritanceChain(groupName); + let isValid = true; + for (const chainGroup of chain) { + if ( + chainGroup !== ROOT_ALIAS_GROUP && + !aliasGroups.includes(chainGroup) + ) { + isValid = false; + break; + } + } + if (!isValid) { + return false; + } + } else { + return false; + } + } + } + } else { + return false; + } + } + } + + return true; + } + + /** + * Check if a workspace is ignored based on the configuration + */ + async shouldIgnoreWorkspace(workspace: Workspace): Promise { + if (!workspace.manifest.name) return false; + + const config = await this.readConfiguration(workspace.project); + + if (config.options?.ignoredWorkspaces) { + return isMatch( + structUtils.stringifyIdent(workspace.manifest.name), + config.options.ignoredWorkspaces, + ); + } + + return false; + } +} diff --git a/sources/configuration/types.ts b/sources/configuration/types.ts new file mode 100644 index 0000000..78ee0bc --- /dev/null +++ b/sources/configuration/types.ts @@ -0,0 +1,44 @@ +import type { ValidationLevel } from "../types"; + +declare module "@yarnpkg/core" { + interface ConfigurationValueMap { + catalogs?: CatalogsConfiguration; + } +} + +export type ValidationConfig = + | ValidationLevel + | { [groupName: string]: ValidationLevel }; + +/** + * Configuration structure for .yarnrc.yml#catalogs + */ +export interface CatalogsConfiguration { + options?: { + /** + * The default alias group to be used when no group is specified when adding a dependency + * - if list of alias groups, it will be used in order + * - if 'max', the most frequently used alias group will be used + */ + default?: string[] | "max"; + /** + * List of workspaces to ignore + */ + ignoredWorkspaces?: string[]; + /** + * Validation level for catalog usage + * - 'warn': Show warnings when catalog versions are not used (default) + * - 'strict': Throw errors when catalog versions are not used + * - 'off': Disable validation + * Can also be an object with group-specific settings: { [groupName]: 'warn' | 'strict' | 'off' } + */ + validation?: ValidationConfig; + }; + list?: { + [alias: string]: + | { + [packageName: string]: string; + } + | string; + }; +} diff --git a/sources/constants.ts b/sources/constants.ts new file mode 100644 index 0000000..d424786 --- /dev/null +++ b/sources/constants.ts @@ -0,0 +1,3 @@ +export const ROOT_ALIAS_GROUP = "root"; + +export const CATALOG_PROTOCOL = "catalog:"; diff --git a/sources/index.ts b/sources/index.ts index 38dbfd8..51a757c 100644 --- a/sources/index.ts +++ b/sources/index.ts @@ -1,23 +1,26 @@ import { - Plugin, - Project, - Descriptor, - structUtils, - Hooks, - SettingsType, - Workspace, + type Descriptor, + type Hooks, + Manifest, MessageName, + type Plugin, + type Project, + SettingsType, + structUtils, + type Workspace, } from "@yarnpkg/core"; -import { Hooks as EssentialHooks } from "@yarnpkg/plugin-essentials"; -import { Hooks as PackHooks } from "@yarnpkg/plugin-pack"; +import type { Hooks as EssentialHooks } from "@yarnpkg/plugin-essentials"; +import type { Hooks as PackHooks } from "@yarnpkg/plugin-pack"; import chalk from "chalk"; import { - CatalogConfigurationReader, CatalogConfigurationError, - CatalogsConfiguration, - CATALOG_PROTOCOL, - ROOT_ALIAS_GROUP, + type CatalogsConfiguration, + configReader, } from "./configuration"; +import { CATALOG_PROTOCOL } from "./constants"; +import { validateWorkspaceCatalogUsability } from "./utils/validation"; +import { resolveCatalogDependency } from "./utils/resolution"; +import { fallbackDefaultAliasGroup } from "./utils/default"; declare module "@yarnpkg/core" { interface ConfigurationValueMap { @@ -25,9 +28,6 @@ declare module "@yarnpkg/core" { } } -// Create a singleton instance of our configuration reader -const configReader = new CatalogConfigurationReader(); - const plugin: Plugin = { configuration: { catalogs: { @@ -44,7 +44,7 @@ const plugin: Plugin = { // Check if any dependencies in manifest are in catalog but not using catalog protocol if (!shouldIgnore) { const violatedDependencies = - await getCatalogDependenciesWithoutProtocol(workspace); + await validateWorkspaceCatalogUsability(workspace); if (violatedDependencies.length > 0) { // Group dependencies by validation level @@ -59,7 +59,9 @@ const plugin: Plugin = { violations: typeof strictViolations | typeof warnViolations, ) => { const packageList = violations - .map((dep) => chalk.yellow(dep.packageName)) + .map((dep) => + chalk.yellow(structUtils.stringifyDescriptor(dep.descriptor)), + ) .join(", "); return `The following dependencies are listed in the catalogs but not using the catalog protocol: ${packageList}. Consider using the catalog protocol instead.`; }; @@ -82,14 +84,14 @@ const plugin: Plugin = { // Check the workspace's raw manifest to find dependencies with the catalog protocol const hasCatalogProtocol = [ - ...Object.values(workspace.manifest.raw["dependencies"] || {}), - ...Object.values(workspace.manifest.raw["devDependencies"] || {}), - ].some((version) => (version as string).startsWith(CATALOG_PROTOCOL)); + ...Object.values(workspace.manifest.raw.dependencies || {}), + ...Object.values(workspace.manifest.raw.devDependencies || {}), + ].some((version) => version.startsWith(CATALOG_PROTOCOL)); if (shouldIgnore && hasCatalogProtocol) { report.reportError( MessageName.INVALID_MANIFEST, - `Workspace is ignored from the catalogs, but it has dependencies with the catalog protocol. Consider removing the protocol.`, + "Workspace is ignored from the catalogs, but it has dependencies with the catalog protocol. Consider removing the protocol.", ); } }, @@ -125,7 +127,7 @@ const plugin: Plugin = { // Get the actual version from .yarnrc.yml const dependencyName = structUtils.stringifyIdent(dependency); - const range = await configReader.getRange( + const range = await resolveCatalogDependency( project, catalogAlias, dependencyName, @@ -187,7 +189,10 @@ const plugin: Plugin = { ) => { fallbackDefaultAliasGroup(workspace, dependency); }, - beforeWorkspacePacking: async (workspace: Workspace, rawManifest: any) => { + beforeWorkspacePacking: async ( + workspace: Workspace, + rawManifest: Workspace["manifest"]["raw"], + ) => { // Only process if the workspace is not ignored if (await configReader.shouldIgnoreWorkspace(workspace)) { return; @@ -221,7 +226,7 @@ const plugin: Plugin = { const catalogAlias = versionString.slice(CATALOG_PROTOCOL.length); // Get the resolved version from catalog configuration - const resolvedRange = await configReader.getRange( + const resolvedRange = await resolveCatalogDependency( workspace.project, catalogAlias, packageName, @@ -242,113 +247,5 @@ const plugin: Plugin = { }, }; -async function getCatalogDependenciesWithoutProtocol( - workspace: Workspace, -): Promise< - Array<{ - packageName: string; - validationLevel: "warn" | "strict"; - applicableGroups: string[]; - }> -> { - const dependencyEntries = [ - ...Object.entries(workspace.manifest.raw["dependencies"] || {}), - ...Object.entries(workspace.manifest.raw["devDependencies"] || {}), - ]; - - const results = []; - - for (const [packageName, version] of dependencyEntries) { - const versionString = version as string; - - // Skip if already using catalog protocol - if (versionString.startsWith(CATALOG_PROTOCOL)) { - continue; - } - - // Find all groups that can access this package - const accessibleGroups = await configReader.findAllAccessibleGroups( - workspace.project, - packageName, - ); - - if (accessibleGroups.length > 0) { - const validationLevel = await configReader.getValidationLevelForPackage( - workspace, - packageName, - ); - - // Only include packages that have validation enabled (not 'off') - if (validationLevel !== "off") { - results.push({ - packageName, - validationLevel: validationLevel as "warn" | "strict", - applicableGroups: accessibleGroups, - }); - } - } - } - - return results; -} - -async function fallbackDefaultAliasGroup( - workspace: Workspace, - dependency: Descriptor, -) { - if (dependency.range.startsWith(CATALOG_PROTOCOL)) { - if (await configReader.shouldIgnoreWorkspace(workspace)) { - throw new Error( - chalk.red( - `The workspace is ignored from the catalogs, but the dependency to add is using the catalog protocol. Consider removing the protocol.`, - ), - ); - } - return; - } - - if (await configReader.shouldIgnoreWorkspace(workspace)) return; - - const aliases = await configReader.findDependency( - workspace.project, - dependency, - ); - if (aliases.length === 0) return; - - // If there's a default alias group, fallback to it - const defaultAliasGroups = - await configReader.getDefaultAliasGroups(workspace); - if (defaultAliasGroups.length > 0) { - for (const aliasGroup of defaultAliasGroups) { - if (aliases.some(([alias]) => alias === aliasGroup)) { - dependency.range = `${CATALOG_PROTOCOL}${aliasGroup}`; - return; - } - } - } - - // If no default alias group is specified, show warning message - const aliasGroups = aliases.map(([aliasGroup]) => - aliasGroup === ROOT_ALIAS_GROUP ? "" : aliasGroup, - ); - - const aliasGroupsText = - aliasGroups.filter((aliasGroup) => aliasGroup !== "").length > 0 - ? ` (${aliasGroups.join(", ")})` - : ""; - - const validationLevel = await configReader.getValidationLevelForPackage( - workspace, - structUtils.stringifyIdent(dependency), - ); - - const message = `➤ ${dependency.name} is listed in the catalogs config${aliasGroupsText}, but it seems you're adding it without the catalog protocol. Consider running 'yarn add ${dependency.name}@${CATALOG_PROTOCOL}${aliasGroups[0]}' instead.`; - if (validationLevel === "strict") { - throw new Error(chalk.red(message)); - } else if (validationLevel === "warn") { - console.warn(chalk.yellow(message)); - } -} - // Export the plugin factory export default plugin; diff --git a/sources/types.ts b/sources/types.ts new file mode 100644 index 0000000..6808665 --- /dev/null +++ b/sources/types.ts @@ -0,0 +1 @@ +export type ValidationLevel = "warn" | "strict" | "off"; diff --git a/sources/utils/default.ts b/sources/utils/default.ts new file mode 100644 index 0000000..6baa740 --- /dev/null +++ b/sources/utils/default.ts @@ -0,0 +1,110 @@ +import type { Descriptor, Workspace } from "@yarnpkg/core"; +import { configReader } from "../configuration"; +import { CATALOG_PROTOCOL, ROOT_ALIAS_GROUP } from "../constants"; +import chalk from "chalk"; +import { validateCatalogUsability } from "./validation"; + +export async function fallbackDefaultAliasGroup( + workspace: Workspace, + dependency: Descriptor, +) { + if (dependency.range.startsWith(CATALOG_PROTOCOL)) { + if (await configReader.shouldIgnoreWorkspace(workspace)) { + throw new Error( + chalk.red( + "The workspace is ignored from the catalogs, but the dependency to add is using the catalog protocol. Consider removing the protocol.", + ), + ); + } + return; + } + + const validationInfo = await validateCatalogUsability(workspace, dependency); + + // If no applicable groups found, return early + if (!validationInfo) return; + + const { validationLevel, applicableGroups } = validationInfo; + + // If there's a default alias group, fallback to it + const defaultAliasGroups = await getDefaultAliasGroups(workspace); + if (defaultAliasGroups.length > 0) { + for (const aliasGroup of defaultAliasGroups) { + if (applicableGroups.includes(aliasGroup)) { + dependency.range = `${CATALOG_PROTOCOL}${aliasGroup}`; + return; + } + } + } + + // If no default alias group is specified, show warning message + const aliasGroups = applicableGroups.map((groupName) => + groupName === ROOT_ALIAS_GROUP ? "" : groupName, + ); + + const aliasGroupsText = + aliasGroups.filter((aliasGroup) => aliasGroup !== "").length > 0 + ? ` (${aliasGroups.join(", ")})` + : ""; + + const message = `➤ ${dependency.name} is listed in the catalogs config${aliasGroupsText}, but it seems you're adding it without the catalog protocol. Consider running 'yarn add ${dependency.name}@${CATALOG_PROTOCOL}${aliasGroups[0]}' instead.`; + if (validationLevel === "strict") { + throw new Error(chalk.red(message)); + } + + if (validationLevel === "warn") { + console.warn(chalk.yellow(message)); + } +} + +/** + * Get the default alias group from the configuration if it exists + */ +async function getDefaultAliasGroups(workspace: Workspace): Promise { + const config = await configReader.readConfiguration(workspace.project); + + if (config.options) { + // There's no default alias group if the workspace should be ignored + if (await configReader.shouldIgnoreWorkspace(workspace)) { + return []; + } + + if (config.options.default) { + // If default value is an list of alias groups, return it + if (Array.isArray(config.options.default)) { + return config.options.default; + } + + // If default value is "max", find the most frequently used alias group + if (config.options.default === "max") { + const aliasGroups = Object.keys(config.list || {}); + + const dependencies = [ + ...workspace.manifest.dependencies, + ...workspace.manifest.devDependencies, + ]; + const counts: Record = Object.fromEntries( + aliasGroups.map((aliasGroup) => [aliasGroup, 0]), + ); + + // Count the occurrences of each alias group in the dependencies + for (const [_, descriptor] of dependencies) { + if (descriptor.range.startsWith(CATALOG_PROTOCOL)) { + const aliasGroup = descriptor.range.substring( + CATALOG_PROTOCOL.length, + ); + counts[aliasGroup] = (counts[aliasGroup] || 0) + 1; + } + } + + // Find the alias group with the maximum count of dependencies + const maxCount = Math.max(...Object.values(counts)); + return Object.keys(counts).filter( + (aliasGroup) => counts[aliasGroup] === maxCount, + ); + } + } + } + + return []; +} diff --git a/sources/utils/functions.ts b/sources/utils/functions.ts new file mode 100644 index 0000000..c972e31 --- /dev/null +++ b/sources/utils/functions.ts @@ -0,0 +1,14 @@ +/** + * Parse inheritance chain from group name + * e.g., "stable/canary/next" to ["stable", "stable/canary", "stable/canary/next"] + */ +export function getInheritanceChain(groupName: string): string[] { + const parts = groupName.split("/"); + const chain: string[] = []; + + for (let i = 0; i < parts.length; i++) { + chain.push(parts.slice(0, i + 1).join("/")); + } + + return chain; +} diff --git a/sources/utils/resolution.ts b/sources/utils/resolution.ts new file mode 100644 index 0000000..76b485e --- /dev/null +++ b/sources/utils/resolution.ts @@ -0,0 +1,136 @@ +import { type Descriptor, structUtils, type Project } from "@yarnpkg/core"; +import { + CatalogConfigurationError, + type CatalogsConfiguration, + configReader, +} from "../configuration"; +import { ROOT_ALIAS_GROUP } from "../constants"; +import { getInheritanceChain } from "./functions"; + +/** + * Get a specific version from the configuration + */ +export async function resolveCatalogDependency( + project: Project, + aliasGroup: string, + packageName: string, +): Promise { + const config = await configReader.readConfiguration(project); + + const aliasGroupToFind = + aliasGroup.length === 0 ? ROOT_ALIAS_GROUP : aliasGroup; + + // Try to resolve through inheritance chain first + const inheritedVersion = resolveInheritedRange( + config, + aliasGroupToFind, + packageName, + ); + + if (inheritedVersion) { + // If version doesn't have a protocol prefix (e.g., "npm:"), add "npm:" as default + if (!/^[^:]+:/.test(inheritedVersion)) { + return `${project.configuration.get( + "defaultProtocol", + )}${inheritedVersion}`; + } + return inheritedVersion; + } + + // Fallback to direct lookup for backward compatibility + const aliasConfig = config.list?.[aliasGroupToFind]; + + if (!aliasConfig || typeof aliasConfig === "string") { + throw new CatalogConfigurationError( + `Alias "${aliasGroupToFind}" not found in .yarnrc.yml catalogs.`, + CatalogConfigurationError.INVALID_ALIAS, + ); + } + + const version = aliasConfig[packageName]; + if (!version) { + throw new CatalogConfigurationError( + `Package "${packageName}" not found in alias "${aliasGroupToFind}"`, + CatalogConfigurationError.INVALID_ALIAS, + ); + } + + // If version doesn't have a protocol prefix (e.g., "npm:"), add "npm:" as default + if (!/^[^:]+:/.test(version)) { + return `${project.configuration.get("defaultProtocol")}${version}`; + } + + return version; +} + +/** + * Find a specific dependency in the configuration + * and return the names of alias groups it belongs to, along with its versions. + * This method now includes inherited groups in the results. + */ +export async function findAllGroupsWithSpecificDependency( + project: Project, + dependency: Descriptor, +): Promise> { + const dependencyString = structUtils.stringifyIdent(dependency); + const config = await configReader.readConfiguration(project); + const results: Array<{ groupName: string; version: string }> = []; + + // Use resolveInheritedRange for all groups to handle both direct and inherited matches + for (const groupName of Object.keys(config.list || {})) { + const resolvedVersion = resolveInheritedRange( + config, + groupName, + dependencyString, + ); + + if (resolvedVersion) { + results.push({ groupName, version: resolvedVersion }); + } + } + + return results; +} + +/** + * Resolve package version through inheritance chain + */ +function resolveInheritedRange( + config: CatalogsConfiguration, + groupName: string, + packageName: string, +): string | null { + const chain = getInheritanceChain(groupName); + + // Search from most specific to least specific + for (let i = chain.length - 1; i >= 0; i--) { + const currentGroup = chain[i]; + const aliasConfig = config.list?.[currentGroup]; + + if (aliasConfig && typeof aliasConfig === "object") { + const version = aliasConfig[packageName]; + if (version) { + return version; + } + } + } + + // Check root-level packages (packages that are direct string values) + if (config.list && typeof config.list === "object") { + const rootValue = config.list[packageName]; + if (typeof rootValue === "string") { + return rootValue; + } + } + + // Check ROOT_ALIAS_GROUP if it exists + const rootAliasConfig = config.list?.[ROOT_ALIAS_GROUP]; + if (rootAliasConfig && typeof rootAliasConfig === "object") { + const version = rootAliasConfig[packageName]; + if (version) { + return version; + } + } + + return null; +} diff --git a/sources/utils/validation.ts b/sources/utils/validation.ts new file mode 100644 index 0000000..9f3a73e --- /dev/null +++ b/sources/utils/validation.ts @@ -0,0 +1,137 @@ +import { type Workspace, type Descriptor, structUtils } from "@yarnpkg/core"; +import type { ValidationLevel } from "../types"; +import { getInheritanceChain } from "./functions"; +import { configReader } from "../configuration"; +import { findAllGroupsWithSpecificDependency } from "./resolution"; +import { CATALOG_PROTOCOL } from "../constants"; + +/** + * Check if a package can be used with the catalog protocol + */ +export async function validateCatalogUsability( + workspace: Workspace, + descriptor: Descriptor, +): Promise<{ + validationLevel: "warn" | "strict" | "off"; + applicableGroups: string[]; +} | null> { + // Skip if already using catalog protocol + if (descriptor.range.startsWith(CATALOG_PROTOCOL)) { + return null; + } + + // Skip if workspace is ignored + if (await configReader.shouldIgnoreWorkspace(workspace)) { + return null; + } + + // Find all groups that can access this package + const accessibleGroups = ( + await findAllGroupsWithSpecificDependency(workspace.project, descriptor) + ).map(({ groupName }) => groupName); + + // Return null if no applicable groups found + if (accessibleGroups.length === 0) { + return null; + } + + // Get validation level for the package + const validationLevel = await getPackageVaidationLevel(workspace, descriptor); + + return { + validationLevel, + applicableGroups: accessibleGroups, + }; +} + +export async function validateWorkspaceCatalogUsability( + workspace: Workspace, +): Promise< + Array<{ + descriptor: Descriptor; + validationLevel: Omit; + applicableGroups: string[]; + }> +> { + const dependencyDescriptors = [ + ...Object.entries(workspace.manifest.raw.dependencies ?? {}), + ...Object.entries(workspace.manifest.raw.devDependencies ?? {}), + ].map(([stringifiedIdent, version]) => { + const ident = structUtils.parseIdent(stringifiedIdent); + return structUtils.makeDescriptor(ident, version); + }); + + const results = []; + + for (const descriptor of dependencyDescriptors) { + const validationInfo = await validateCatalogUsability( + workspace, + descriptor, + ); + + // Only include packages that have validation enabled (not 'off') + if (validationInfo && validationInfo.validationLevel !== "off") { + results.push({ + descriptor, + validationLevel: validationInfo.validationLevel, + applicableGroups: validationInfo.applicableGroups, + }); + } + } + + return results; +} + +/** + * Get validation level for a specific group (considering inheritance) + */ +async function getGroupValidationLevel( + workspace: Workspace, + groupName: string, +): Promise { + const config = await configReader.readConfiguration(workspace.project); + const validationConfig = config.options?.validation || "warn"; + + if (typeof validationConfig === "string") { + return validationConfig; + } + + // Search inheritance chain for explicit validation setting + const inheritanceChain = getInheritanceChain(groupName); + + for (let i = inheritanceChain.length - 1; i >= 0; i--) { + const currentGroup = inheritanceChain[i]; + if (validationConfig[currentGroup] !== undefined) { + return validationConfig[currentGroup]; + } + } + + return "warn"; // Default fallback +} + +/** + * Get the strictest validation level for a package across all accessible groups + */ +async function getPackageVaidationLevel( + workspace: Workspace, + descriptor: Descriptor, +): Promise { + const accessibleGroups = ( + await findAllGroupsWithSpecificDependency(workspace.project, descriptor) + ).map(({ groupName }) => groupName); + + if (accessibleGroups.length === 0) { + return "off"; + } + + const validationLevels: ValidationLevel[] = []; + for (const groupName of accessibleGroups) { + const level = await getGroupValidationLevel(workspace, groupName); + validationLevels.push(level); + } + + // Return the strictest level (strict > warn > off) + if (validationLevels.includes("strict")) return "strict"; + if (validationLevels.includes("warn")) return "warn"; + return "off"; +}