/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@npmcli/map-workspaces@5.0.3/lib/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
const path=require("path"),getName=require("@npmcli/name-from-folder"),{minimatch:minimatch}=require("minimatch"),pkgJson=require("@npmcli/package-json"),{glob:glob}=require("glob");function appendNegatedPatterns(e){const t=[],r=[];for(let n of e){const e=n.match(/^!+/);e&&(n=n.slice(e[0].length)),n=n.replace(/^\.?\/+/,"");if(e&&e[0].length%2==1)r.push(n);else{for(let e=0;e<r.length;++e){const t=r[e];minimatch(n,t)&&r.splice(e,1)}t.push(n)}}for(const e of r)for(const r of minimatch.match(t,e))t.splice(t.indexOf(r),1);return{patterns:t,negatedPatterns:r}}function getPatterns(e){const t=Array.isArray(e.packages)?e.packages:e;if(!Array.isArray(t))throw getError({message:"workspaces config expects an Array",code:"EWORKSPACESCONFIG"});return appendNegatedPatterns(t)}function getPackageName(e,t){return e.name||getName(t)}function getGlobPattern(e){return(e=e.replace(/\\/g,"/")).endsWith("/")?e:`${e}/`}function getError({Type:e=TypeError,message:t,code:r}){return Object.assign(new e(t),{code:r})}function reverseResultMap(e){return new Map(Array.from(e,(e=>e.reverse())))}async function mapWorkspaces(e={}){if(!e||!e.pkg)throw getError({message:"mapWorkspaces missing pkg info",code:"EMAPWORKSPACESPKG"});e.cwd||(e.cwd=process.cwd());const{workspaces:t=[]}=e.pkg,{patterns:r,negatedPatterns:n}=getPatterns(t),o=new Map;if(!r.length&&!n.length)return o;const a=new Map;let s=await glob(r.map((e=>getGlobPattern(e))),{...e,ignore:[...e.ignore||[],"**/node_modules/**",...n]});s=s.sort(((e,t)=>e.localeCompare(t,"en")));const c=[];for(const e of r)c.push(...s.filter((t=>minimatch(t,e,{partial:!0,windowsPathsNoEscape:!0}))));for(const t of c){let r;try{r=await pkgJson.normalize(path.join(e.cwd,t))}catch(e){if("ENOENT"===e.code||"ENOTDIR"===e.code)continue;throw e}const n=getPackageName(r.content,r.path);let o=a.get(n);o||(o=new Set,a.set(n,o)),o.add(r.path)}const i=["must not have multiple workspaces with the same name"];for(const[e,t]of a)t.size>1?addDuplicateErrorMessages(i,e,t):o.set(e,t.values().next().value);if(i.length>1)throw getError({Type:Error,message:i.join("\n"),code:"EDUPLICATEWORKSPACE"});return o}function addDuplicateErrorMessages(e,t,r){e.push(`package '${t}' has conflicts in the following paths:`);for(const t of r)e.push("    "+t)}mapWorkspaces.virtual=function(e={}){if(!e||!e.lockfile)throw getError({message:"mapWorkspaces.virtual missing lockfile info",code:"EMAPWORKSPACESLOCKFILE"});e.cwd||(e.cwd=process.cwd());const{packages:t={}}=e.lockfile,{workspaces:r=[]}=t[""]||{},n=new Map,{patterns:o,negatedPatterns:a}=getPatterns(r);if(!o.length&&!a.length)return n;a.push("**/node_modules/**");const s=Object.keys(t);for(const e of a)for(const t of minimatch.match(s,e))s.splice(s.indexOf(t),1);for(const r of o)for(const o of minimatch.match(s,r)){const r=path.join(e.cwd,o),a=getPackageName(t[o],r);n.set(r,a)}return reverseResultMap(n)},module.exports=mapWorkspaces;
//# sourceMappingURL=/sm/b93ec4d564faa72b47cab60dc75a08183162cd2db351b7c5ea7dd3d9a6bf517e.map