var e=Object.defineProperty,t=Object.defineProperties,n=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,o=(t,n,r)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[n]=r,s=(e,t)=>{for(var n in t||={})i.call(t,n)&&o(e,n,t[n]);if(r)for(var n of r(t))a.call(t,n)&&o(e,n,t[n]);return e},c=(e,r)=>t(e,n(r)),l=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())}),u=(e,t)=>m(e,`https://data.jsdelivr.com/v1/package/npm/${t}`,{cache:`no-store`}),d=(e,t,n)=>m(e,`https://data.jsdelivr.com/v1/package/resolve/npm/${t}@${n}`),f=(e,t,n)=>l(void 0,null,function*(){let r=yield m(e,`https://data.jsdelivr.com/v1/package/npm/${t}@${n}/flat`);return r instanceof Error?r:c(s({},r),{moduleName:t,version:n})}),p=(e,t,n,r)=>l(void 0,null,function*(){let i=`https://cdn.jsdelivr.net/npm/${t}@${n}${r}`,a=yield(e.fetcher||fetch)(i);return a.ok?a.text():Error(`OK`)});function m(e,t,n){return(e.fetcher||fetch)(t,n).then(e=>e.ok?e.json().then(e=>e):Error(`OK`))}var h=e=>{if(e.indexOf(`node:`)===0||`assert.assert/strict.async_hooks.buffer.child_process.cluster.console.constants.crypto.dgram.diagnostics_channel.dns.dns/promises.domain.events.fs.fs/promises.http.http2.https.inspector.inspector/promises.module.net.os.path.path/posix.path/win32.perf_hooks.process.punycode.querystring.readline.repl.stream.stream/promises.stream/consumers.stream/web.string_decoder.sys.timers.timers/promises.tls.trace_events.tty.url.util.util/types.v8.vm.wasi.worker_threads.zlib`.split(`.`).includes(e))return`node`;let[t=``,n=``]=e.split(`/`);return t.startsWith(`@`)?`${t}/${n}`:t},g=e=>{let t=new Map,n=new Map,r=0,i=0;return t=>(r=0,i=0,a(t,0).then(t=>{var r,a;i>0&&((a=(r=e.delegate).finished)==null||a.call(r,n))}));function a(o,s){return l(this,null,function*(){var c,u,d,f,m;let h=y(e,t,o);h.forEach(e=>t.set(e.module,{state:`loading`}));let g=(yield Promise.all(h.map(t=>b(e,t.module,t.version)))).filter(e=>!(`error`in e)),v=g.filter(e=>e.files.find(e=>S(e.name))),C=v.map(e=>_(e,`/node_modules/${e.moduleName}`)),w=g.filter(e=>!v.includes(e)),T=(yield Promise.all(w.map(t=>b(e,`@types/${x(t.moduleName)}`,`latest`)))).filter(e=>!(`error`in e)),E=T.map(e=>_(e,`/node_modules/@types/${x(e.moduleName).replace(`types__`,``)}`)),D=C.concat(E).reduce((e,t)=>e.concat(t),[]);r+=D.length,D.length&&s===0&&((u=(c=e.delegate).started)==null||u.call(c));for(let t of g){let r=`/node_modules/${t.moduleName}`;T.includes(t)&&(r=`/node_modules/@types/${x(t.moduleName).replace(`types__`,``)}`);let i=r+`/package.json`,a=yield p(e,t.moduleName,t.version,`/package.json`);typeof a==`string`?(n.set(i,a),(f=(d=e.delegate).receivedFile)==null||f.call(d,a,i)):(m=e.logger)==null||m.error(`Could not download package.json for ${t.moduleName}`)}yield Promise.all(D.map(t=>l(this,null,function*(){var o,c,l;let u=yield p(e,t.moduleName,t.moduleVersion,t.path);i++,u instanceof Error?(o=e.logger)==null||o.error(`Had an issue getting ${t.path} for ${t.moduleName}`):(n.set(t.vfsPath,u),(l=(c=e.delegate).receivedFile)==null||l.call(c,u,t.vfsPath),e.delegate.progress&&i%5==0&&e.delegate.progress(i,r),yield a(u,s+1))})))})}};function _(e,t){let n=[];for(let r of e.files)S(r.name)&&n.push({moduleName:e.moduleName,moduleVersion:e.version,vfsPath:`${t}${r.name}`,path:r.name});return n}var v=(e,t)=>{let n=e.preProcessFile(t),r=e.libMap||new Map;return n.referencedFiles.concat(n.importedFiles).concat(n.libReferenceDirectives).filter(e=>!S(e.fileName)).filter(e=>!r.has(e.fileName)).map(e=>{let n;if(!e.fileName.startsWith(`.`)){n=`latest`;let r=t.slice(e.end).split(`
`)[0];r.includes(`// types:`)&&(n=r.split(`// types: `)[1].trim())}return{module:e.fileName,version:n}}).filter((e,t,n)=>n.findIndex(t=>t.module===e.module&&t.version===e.version)===t)};function y(e,t,n){return v(e.typescript,n).map(e=>c(s({},e),{module:h(e.module)})).filter(e=>!e.module.startsWith(`.`)).filter(e=>!t.has(e.module))}var b=(e,t,n)=>l(void 0,null,function*(){let r=n||`latest`;if(r.split(`.`).length<2){let i=yield d(e,t,r);if(i instanceof Error)return{error:i,userFacingMessage:`Could not go from a tag to version on npm for ${t} - possible typo?`};let a=i.version;if(!a){let r=yield u(e,t);if(r instanceof Error)return{error:i,userFacingMessage:`Could not get versions on npm for ${t} - possible typo?`};let a=Object.entries(r.tags).join(`, `);return{error:Error(`Could not find tag for module`),userFacingMessage:`Could not find a tag for ${t} called ${n}. Did find ${a}`}}r=a}let i=yield f(e,t,r);return i instanceof Error?{error:i,userFacingMessage:`Could not get the files for ${t}@${r}. Is it possibly a typo?`}:i});function x(e){return e.indexOf(`@`)===0&&e.indexOf(`/`)!==-1&&(e=e.substr(1).replace(`/`,`__`)),e}function S(e){return/\.d\.([^\.]+\.)?[cm]?ts$/i.test(e)}export{g as setupTypeAcquisition};
//# sourceMappingURL=dist-D5VV8yNp.js.map