pkgroll 2.18.0 → 2.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs
CHANGED
|
@@ -19,7 +19,7 @@ var Ye=Object.defineProperty;var i=(u,e)=>Ye(u,"name",{value:e,configurable:!0})
|
|
|
19
19
|
`:"")+(D?this.indentText({text:this.render(D),spaces:t}):"")}
|
|
20
20
|
`}table({tableData:e,tableOptions:D,tableBreakpoints:t}){return lD(e.map(n=>n.map(r=>this.render(r))),t?pD(t):D)}flagParameter(e){return e===Boolean?"":e===String?"<string>":e===Number?"<number>":Array.isArray(e)?this.flagParameter(e[0]):"<value>"}flagOperator(e){return" "}flagName(e){const{flag:D,flagFormatted:t,aliasesEnabled:n,aliasFormatted:r}=e;let o="";if(r?o+=`${r}, `:n&&(o+=" "),o+=t,"placeholder"in D&&typeof D.placeholder=="string")o+=`${this.flagOperator(e)}${D.placeholder}`;else{const s=this.flagParameter("type"in D?D.type:D);s&&(o+=`${this.flagOperator(e)}${s}`)}return o}flagDefault(e){return JSON.stringify(e)}flagDescription({flag:e}){let D="description"in e?e.description??"":"";if("default"in e){let{default:t}=e;typeof t=="function"&&(t=t()),t&&(D+=` (default: ${this.flagDefault(t)})`)}return D}render(e){if(typeof e=="string")return e;if(Array.isArray(e))return e.map(D=>this.render(D)).join(`
|
|
21
21
|
`);if("type"in e&&this[e.type]){const D=this[e.type];if(typeof D=="function")return D.call(this,e.data)}throw new Error(`Invalid node type: ${JSON.stringify(e)}`)}}const ce=i(u=>u.length>0&&!u.includes(" "),"y"),{stringify:P}=JSON,xD=/[|\\{}()[\]^$+*?.]/;function gu(u){const e=[];let D,t;for(const n of u){if(t)throw new Error(`Invalid parameter: Spread parameter ${P(t)} must be last`);const r=n[0],o=n[n.length-1];let s;if(r==="<"&&o===">"&&(s=!0,D))throw new Error(`Invalid parameter: Required parameter ${P(n)} cannot come after optional parameter ${P(D)}`);if(r==="["&&o==="]"&&(s=!1,D=n),s===void 0)throw new Error(`Invalid parameter: ${P(n)}. Must be wrapped in <> (required parameter) or [] (optional parameter)`);let a=n.slice(1,-1);const l=a.slice(-3)==="...";l&&(t=n,a=a.slice(0,-3));const c=a.match(xD);if(c)throw new Error(`Invalid parameter: ${P(n)}. Invalid character found ${P(c[0])}`);e.push({name:a,required:s,spread:l})}return e}i(gu,"w$1");function Bu(u,e,D,t){for(let n=0;n<e.length;n+=1){const{name:r,required:o,spread:s}=e[n],a=dD(r);if(a in u)throw new Error(`Invalid parameter: ${P(r)} is used more than once.`);const l=s?D.slice(n):D[n];if(s&&(n=e.length),o&&(!l||s&&l.length===0))return console.error(`Error: Missing required parameter ${P(r)}
|
|
22
|
-
`),t(),process.exit(1);u[a]=l}}i(Bu,"b");function kD(u){return u===void 0||u!==!1}i(kD,"W$1");function fe(u,e,D,t){const n={...e.flags},r=e.version;r&&(n.version={type:Boolean,description:"Show version"});const{help:o}=e,s=kD(o);s&&!("help"in n)&&(n.help={type:Boolean,alias:"h",description:"Show help"});const a=Ot(n,t,{ignore:e.ignoreArgv}),l=i(()=>{console.log(e.version)},"f");if(r&&a.flags.version===!0)return l(),process.exit(0);const c=new $D,f=s&&o?.render?o.render:d=>c.render(d),p=i(d=>{const m=wD({...e,...d?{help:d}:{},flags:n});console.log(f(m,c))},"u");if(s&&a.flags.help===!0)return p(),process.exit(0);if(e.parameters){let{parameters:d}=e,m=a._;const b=d.indexOf("--"),O=d.slice(b+1),A=Object.create(null);if(b>-1&&O.length>0){d=d.slice(0,b);const C=a._["--"];m=m.slice(0,-C.length||void 0),Bu(A,gu(d),m,p),Bu(A,gu(O),C,p)}else Bu(A,gu(d),m,p);Object.assign(a._,A)}const h={...a,showVersion:l,showHelp:p};return typeof D=="function"&&D(h),{command:u,...h}}i(fe,"x$1");function jD(u,e){const D=new Map;for(const t of e){const n=[t.options.name],{alias:r}=t.options;r&&(Array.isArray(r)?n.push(...r):n.push(r));for(const o of n){if(D.has(o))throw new Error(`Duplicate command name found: ${P(o)}`);D.set(o,t)}}return D.get(u)}i(jD,"z$1");function OD(u,e,D=process.argv.slice(2)){if(!u)throw new Error("Options is required");if("name"in u&&(!u.name||!ce(u.name)))throw new Error(`Invalid script name: ${P(u.name)}`);const t=D[0];if(u.commands&&t&&ce(t)){const n=jD(t,u.commands);if(n)return fe(n.options.name,{...n.options,parent:u},n.callback,D.slice(1))}return fe(void 0,u,e,D)}i(OD,"Z$1");var SD="2.18.0";const yu=i(u=>I.promises.access(u).then(()=>!0,()=>!1),"fsExists");let R=!0;const W=typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{};let G=0;if(W.process&&W.process.env&&W.process.stdout){const{FORCE_COLOR:u,NODE_DISABLE_COLORS:e,NO_COLOR:D,TERM:t,COLORTERM:n}=W.process.env;e||D||u==="0"?R=!1:u==="1"||u==="2"||u==="3"?R=!0:t==="dumb"?R=!1:"CI"in W.process.env&&["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE","DRONE"].some(r=>r in W.process.env)?R=!0:R=process.stdout.isTTY,R&&(process.platform==="win32"||n&&(n==="truecolor"||n==="24bit")?G=3:t&&(t.endsWith("-256color")||t.endsWith("256"))?G=2:G=1)}let pe={enabled:R,supportLevel:G};function TD(u,e,D=1){const t=`\x1B[${u}m`,n=`\x1B[${e}m`,r=new RegExp(`\\x1b\\[${e}m`,"g");return o=>pe.enabled&&pe.supportLevel>=D?t+(""+o).replace(r,t)+n:""+o}i(TD,"kolorist");const PD=TD(2,22),$=i((u,e)=>(!E.isAbsolute(u)&&!u.startsWith(".")&&!u.startsWith("/")&&(u=`./${u}`),e&&!u.endsWith("/")&&(u+="/"),u),"normalizePath"),ID=i(()=>new Date().toLocaleTimeString(),"currentTime"),ou=i((...u)=>console.log(PD(ID()),...u),"log"),_D=process.cwd(),Au=i(u=>$(E.relative(_D,u)),"formatPath"),ND=i(async u=>{const e=E.join(u,"package.json");if(!await yu(e))throw new Error(`package.json not found at: ${e}`);const t=await I.promises.readFile(e,"utf8");let n;try{n=JSON.parse(t)}catch(r){throw new Error(`Failed to parse ${Au(e)}: ${r.message}`)}return{packageJson:n,packageJsonPath:e}},"readPackageJson"),RD=i(u=>{let e=!1;if(u.includes("=")){const[D,t]=u.split("=");u=t,e=D==="bin"||D==="binary"}return{type:"legacy",source:"cli",outputPath:$(u),isExecutable:e}},"parseCliInputFlag"),MD=i(({imports:u},e)=>{const D={};if(u)for(const t in u){if(t.startsWith("#"))continue;const n=u[t];typeof n=="string"&&(D[t]=E.join(e,n))}return D},"getAliases"),LD=i(u=>{const{publishConfig:e}=u;if(!e)return;const D=["bin","main","exports","types","module"];for(const t of D)e[t]&&(u[t]=e[t])},"applyPublishConfig"),M=i(u=>{if(u.endsWith(".mjs"))return"module";if(u.endsWith(".cjs"))return"commonjs";if(u.endsWith(".d.ts")||u.endsWith(".d.cts")||u.endsWith(".d.mts"))return"types"},"getFileType"),WD=i(u=>u[0]===".","isPath"),de=i(u=>u.slice(1).filter(e=>typeof e=="string"&&e[0]!=="."),"getConditions"),bu=i((u,e,D=["exports"])=>u?typeof u=="string"?[{source:{type:"package.json",path:[...D]},type:"exportmap",conditions:[],format:M(u)||e,outputPath:$(u)}]:Array.isArray(u)?u.flatMap((t,n)=>{const r=[...D,n];return typeof t=="string"?WD(t)?{source:{type:"package.json",path:[...r]},type:"exportmap",conditions:de(r),format:M(t)||e,outputPath:$(t)}:[]:bu(t,e,r)}):Object.entries(u).flatMap(([t,n])=>{const r=[...D,t];if(typeof n=="string"){const o=de(r),s={type:"exportmap",source:{type:"package.json",path:r},outputPath:$(n),conditions:o};return o.includes("types")?{...s,format:"types"}:{...s,format:M(n)||e}}return bu(n,e,r)}):[],"parseExportsMap"),UD=i((u,e)=>{const D=[],t=u.main;t&&D.push({source:{type:"package.json",path:["main"]},type:"legacy",format:M(t)??e,outputPath:$(t)});const n=u.module;n&&D.push({source:{type:"package.json",path:["module"]},type:"legacy",format:"module",outputPath:$(n)});const r=u.types;r&&D.push({source:{type:"package.json",path:["types"]},type:"legacy",format:"types",outputPath:$(r)});const{bin:o}=u;if(o)if(typeof o=="string")D.push({source:{type:"package.json",path:["bin"]},type:"binary",format:M(o)??e,outputPath:$(o)});else for(const[s,a]of Object.entries(o))D.push({source:{type:"package.json",path:["bin",s]},type:"binary",format:M(a)??e,outputPath:$(a)});if(u.exports){const s=bu(u.exports,e);for(const a of s)D.push(a)}return D},"getPkgEntryPoints"),VD=i(async(u,e)=>{for(const D of e){const t=u+D;if(await yu(t))return{srcExtension:D,sourcePath:t}}},"tryExtensions"),wu={".d.ts":[".d.ts",".d.mts",".d.cts",".ts",".tsx",".mts",".cts"],".d.mts":[".d.mts",".d.ts",".d.cts",".ts",".tsx",".mts",".cts"],".d.cts":[".d.cts",".d.ts",".d.mts",".ts",".tsx",".mts",".cts"],".js":[".js",".ts",".tsx",".mts",".cts"],".mjs":[".mjs",".js",".cjs",".mts",".cts",".ts",".tsx"],".cjs":[".cjs",".js",".mjs",".mts",".cts",".ts",".tsx"]},Fe=Object.keys(wu),qD=i(async(u,e)=>{const{outputPath:D}=u,t=Fe.find(o=>D.endsWith(o));if(!t)return{error:`Unsupported extension (must be ${Fe.join("|")})`,exportEntry:u};const n=D.slice(e.dist.length,-t.length),r=await VD(z.join(e.srcResolved,n),wu[t]);return r?{exportEntry:u,distExtension:t,srcdist:e,...r}:{error:`Source file not found: ${z.join(e.src,n)}(${wu[t].join("|")})`,exportEntry:u}},"getSourcePath"),zD=i(async u=>{try{return await uu.readdir(u,{withFileTypes:!0})}catch(e){const{code:D}=e;if(D==="ENOENT")return[];throw e}},"safeReaddir"),Ce=i(async(u,e)=>{const D=await zD(u);return(await Promise.all(D.map(async n=>{const r=z.join(u,n.name);return n.isDirectory()?Ce(r,e):n.isFile()?z.relative(e,r):[]}))).flat()},"getDirectoryFilesRecursive"),he=new Map,JD=i(async u=>{let e=he.get(u);return e||(e=Ce(u,u),he.set(u,e)),e},"getDirectoryFiles"),Ee=/\.[^./]+$/,KD=i((u,e)=>{const D=u.replace(Ee,""),t=e.at(-1);if(!D.endsWith(t))return;const n=D.split("/").filter(Boolean);for(let r=1;r<=n.length;r+=1){const o=n.slice(0,r).join("/"),s=o+e.join(o);if(s===D)return s}},"extractWildcardMatch"),GD=i(async(u,e)=>{const D=Array.from(e).sort((n,r)=>r.dist.length-n.dist.length);return(await Promise.all(u.map(async n=>{if(typeof n.source=="string"||n.source.path[0]!=="exports"||!n.outputPath.includes("*"))return[n];const r=n.source.path[1];if(!r.includes("*"))return[n];const o=n.outputPath.match(/\.d\.[cm]?ts$/)||n.outputPath.match(Ee);if(!o)return[{exportEntry:n,error:`Wildcard pattern must include a file extension (e.g., ".mjs", ".cjs"). Pattern: ${r}`}];const[s]=o,a=n.outputPath.slice(0,-s.length),[l,...c]=a.split("*"),f=D.find(({dist:d})=>l===d||l.startsWith(d));if(!f)return[];const p=E.posix.join(f.srcResolved,l.slice(f.dist.length));return(await JD(p)).flatMap(d=>{const m=KD(d,c);return m?[{...n,outputPath:l+m+s}]:[]})}))).flat()},"expandBuildOutputWildcards"),HD=i(async(u,e,D)=>{LD(e);const t=e.type??"commonjs",n=await GD(UD(e,t),u);D.length>0&&n.push(...D.map(o=>({...o,format:M(o.outputPath)??t})));const r=new Map;return await Promise.all(n.map(async o=>{if("error"in o)return o;const s=u.find(({dist:l})=>o.outputPath.startsWith(l));if(!s)return{exportEntry:o,error:"Ignoring file outside of dist directories"};const a=r.get(o.outputPath);if(a){if(a.format!==o.format)throw new Error(`Conflicting export types "${a.format}" & "${o.format}" found for ${o.outputPath}`)}else r.set(o.outputPath,o);return await qD(o,s)}))},"getBuildEntryPoints"),ZD=["peerDependencies","dependencies","optionalDependencies"],vu="@types/",me=i((u,e,D=!1)=>{const t=[],{devDependencies:n}=u;for(const r of ZD){const o=u[r];if(!o)continue;const s=Object.keys(o);for(const a of s)if(!(a in e))if(a.startsWith(vu)){if(D){let l=a.slice(vu.length);l.includes("__")&&(l=`@${l.replace("__","/")}`),t.push(l)}}else{if(n&&D){const l=vu+a.replace("@","").replace("/","__");n[l]&&!(l in o)&&console.warn(`Recommendation: "${l}" is externalized because "${a}" is in "${r}". Place "${l}" in "${r}" as well so users don't have missing types.`)}t.push(a)}}return t.flatMap(r=>[r,new RegExp(`^${r}/`)])},"getExternalDependencies"),H=Symbol("entry"),YD=i(u=>{const e=ot(/\.([cm]?[jt]s|[jt]sx)$/);return{name:"esbuild-transform",transform:i(async(D,t)=>{if(!e(t))return null;const n=await zu(D,{...u,supported:{"import-meta":!0},loader:"default",sourcefile:t.replace(/\.[cm]ts/,".ts")});return{code:n.code,map:n.map||null}},"transform")}},"esbuildTransform"),QD=i(u=>{if(u==="es")return"esm";if(u==="cjs"||u==="iife")return u},"getEsbuildFormat"),XD=i(u=>({name:"esbuild-minify",renderChunk:i(async(e,D,t)=>{const n=await zu(e,{...u,format:QD(t.format),minify:!0,keepNames:!0});return{code:n.code,map:n.map||null}},"renderChunk")}),"esbuildMinify"),$u=i((u,e)=>u[0]-e[0]||u[1]-e[1]||u[2]-e[2],"compareSemver"),ge=i(({target:u})=>{const e=u.some(D=>{if(D=D.trim(),!D.startsWith("node"))return;const t=D.slice(4).split(".").map(Number),n=[t[0],t[1]??0,t[2]??0];return!($u(n,[12,20,0])>=0&&$u(n,[13,0,0])<0||$u(n,[14,13,1])>=0)});return{name:"node-builtins",resolveId:i(D=>{const t=D.startsWith("node:");if(e&&t&&(D=D.slice(5)),it.includes(D)||t)return{id:D,external:!0}},"resolveId")}},"nodeBuiltins"),un=i(u=>{const e=u.filter(t=>t.exportEntry.type==="binary");if(e.length===0)return{name:"patch-binary"};let D;return{name:"patch-binary",options:i(()=>{D=new Set(e.flatMap(t=>t.inputNames))},"options"),renderChunk:i((t,n,r)=>{if(!n.isEntry||!n.facadeModuleId||!D.has(n.name))return;const o=new eu(t);return o.prepend(`#!/usr/bin/env node
|
|
22
|
+
`),t(),process.exit(1);u[a]=l}}i(Bu,"b");function kD(u){return u===void 0||u!==!1}i(kD,"W$1");function fe(u,e,D,t){const n={...e.flags},r=e.version;r&&(n.version={type:Boolean,description:"Show version"});const{help:o}=e,s=kD(o);s&&!("help"in n)&&(n.help={type:Boolean,alias:"h",description:"Show help"});const a=Ot(n,t,{ignore:e.ignoreArgv}),l=i(()=>{console.log(e.version)},"f");if(r&&a.flags.version===!0)return l(),process.exit(0);const c=new $D,f=s&&o?.render?o.render:d=>c.render(d),p=i(d=>{const m=wD({...e,...d?{help:d}:{},flags:n});console.log(f(m,c))},"u");if(s&&a.flags.help===!0)return p(),process.exit(0);if(e.parameters){let{parameters:d}=e,m=a._;const b=d.indexOf("--"),O=d.slice(b+1),A=Object.create(null);if(b>-1&&O.length>0){d=d.slice(0,b);const C=a._["--"];m=m.slice(0,-C.length||void 0),Bu(A,gu(d),m,p),Bu(A,gu(O),C,p)}else Bu(A,gu(d),m,p);Object.assign(a._,A)}const h={...a,showVersion:l,showHelp:p};return typeof D=="function"&&D(h),{command:u,...h}}i(fe,"x$1");function jD(u,e){const D=new Map;for(const t of e){const n=[t.options.name],{alias:r}=t.options;r&&(Array.isArray(r)?n.push(...r):n.push(r));for(const o of n){if(D.has(o))throw new Error(`Duplicate command name found: ${P(o)}`);D.set(o,t)}}return D.get(u)}i(jD,"z$1");function OD(u,e,D=process.argv.slice(2)){if(!u)throw new Error("Options is required");if("name"in u&&(!u.name||!ce(u.name)))throw new Error(`Invalid script name: ${P(u.name)}`);const t=D[0];if(u.commands&&t&&ce(t)){const n=jD(t,u.commands);if(n)return fe(n.options.name,{...n.options,parent:u},n.callback,D.slice(1))}return fe(void 0,u,e,D)}i(OD,"Z$1");var SD="2.18.1";const yu=i(u=>I.promises.access(u).then(()=>!0,()=>!1),"fsExists");let R=!0;const W=typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{};let G=0;if(W.process&&W.process.env&&W.process.stdout){const{FORCE_COLOR:u,NODE_DISABLE_COLORS:e,NO_COLOR:D,TERM:t,COLORTERM:n}=W.process.env;e||D||u==="0"?R=!1:u==="1"||u==="2"||u==="3"?R=!0:t==="dumb"?R=!1:"CI"in W.process.env&&["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE","DRONE"].some(r=>r in W.process.env)?R=!0:R=process.stdout.isTTY,R&&(process.platform==="win32"||n&&(n==="truecolor"||n==="24bit")?G=3:t&&(t.endsWith("-256color")||t.endsWith("256"))?G=2:G=1)}let pe={enabled:R,supportLevel:G};function TD(u,e,D=1){const t=`\x1B[${u}m`,n=`\x1B[${e}m`,r=new RegExp(`\\x1b\\[${e}m`,"g");return o=>pe.enabled&&pe.supportLevel>=D?t+(""+o).replace(r,t)+n:""+o}i(TD,"kolorist");const PD=TD(2,22),$=i((u,e)=>(!E.isAbsolute(u)&&!u.startsWith(".")&&!u.startsWith("/")&&(u=`./${u}`),e&&!u.endsWith("/")&&(u+="/"),u),"normalizePath"),ID=i(()=>new Date().toLocaleTimeString(),"currentTime"),ou=i((...u)=>console.log(PD(ID()),...u),"log"),_D=process.cwd(),Au=i(u=>$(E.relative(_D,u)),"formatPath"),ND=i(async u=>{const e=E.join(u,"package.json");if(!await yu(e))throw new Error(`package.json not found at: ${e}`);const t=await I.promises.readFile(e,"utf8");let n;try{n=JSON.parse(t)}catch(r){throw new Error(`Failed to parse ${Au(e)}: ${r.message}`)}return{packageJson:n,packageJsonPath:e}},"readPackageJson"),RD=i(u=>{let e=!1;if(u.includes("=")){const[D,t]=u.split("=");u=t,e=D==="bin"||D==="binary"}return{type:"legacy",source:"cli",outputPath:$(u),isExecutable:e}},"parseCliInputFlag"),MD=i(({imports:u},e)=>{const D={};if(u)for(const t in u){if(t.startsWith("#"))continue;const n=u[t];typeof n=="string"&&(D[t]=E.join(e,n))}return D},"getAliases"),LD=i(u=>{const{publishConfig:e}=u;if(!e)return;const D=["bin","main","exports","types","module"];for(const t of D)e[t]&&(u[t]=e[t])},"applyPublishConfig"),M=i(u=>{if(u.endsWith(".mjs"))return"module";if(u.endsWith(".cjs"))return"commonjs";if(u.endsWith(".d.ts")||u.endsWith(".d.cts")||u.endsWith(".d.mts"))return"types"},"getFileType"),WD=i(u=>u[0]===".","isPath"),de=i(u=>u.slice(1).filter(e=>typeof e=="string"&&e[0]!=="."),"getConditions"),bu=i((u,e,D=["exports"])=>u?typeof u=="string"?[{source:{type:"package.json",path:[...D]},type:"exportmap",conditions:[],format:M(u)||e,outputPath:$(u)}]:Array.isArray(u)?u.flatMap((t,n)=>{const r=[...D,n];return typeof t=="string"?WD(t)?{source:{type:"package.json",path:[...r]},type:"exportmap",conditions:de(r),format:M(t)||e,outputPath:$(t)}:[]:bu(t,e,r)}):Object.entries(u).flatMap(([t,n])=>{const r=[...D,t];if(typeof n=="string"){const o=de(r),s={type:"exportmap",source:{type:"package.json",path:r},outputPath:$(n),conditions:o};return o.includes("types")?{...s,format:"types"}:{...s,format:M(n)||e}}return bu(n,e,r)}):[],"parseExportsMap"),UD=i((u,e)=>{const D=[],t=u.main;t&&D.push({source:{type:"package.json",path:["main"]},type:"legacy",format:M(t)??e,outputPath:$(t)});const n=u.module;n&&D.push({source:{type:"package.json",path:["module"]},type:"legacy",format:"module",outputPath:$(n)});const r=u.types;r&&D.push({source:{type:"package.json",path:["types"]},type:"legacy",format:"types",outputPath:$(r)});const{bin:o}=u;if(o)if(typeof o=="string")D.push({source:{type:"package.json",path:["bin"]},type:"binary",format:M(o)??e,outputPath:$(o)});else for(const[s,a]of Object.entries(o))D.push({source:{type:"package.json",path:["bin",s]},type:"binary",format:M(a)??e,outputPath:$(a)});if(u.exports){const s=bu(u.exports,e);for(const a of s)D.push(a)}return D},"getPkgEntryPoints"),VD=i(async(u,e)=>{for(const D of e){const t=u+D;if(await yu(t))return{srcExtension:D,sourcePath:t}}},"tryExtensions"),wu={".d.ts":[".d.ts",".d.mts",".d.cts",".ts",".tsx",".mts",".cts"],".d.mts":[".d.mts",".d.ts",".d.cts",".ts",".tsx",".mts",".cts"],".d.cts":[".d.cts",".d.ts",".d.mts",".ts",".tsx",".mts",".cts"],".js":[".js",".ts",".tsx",".mts",".cts"],".mjs":[".mjs",".js",".cjs",".mts",".cts",".ts",".tsx"],".cjs":[".cjs",".js",".mjs",".mts",".cts",".ts",".tsx"]},Fe=Object.keys(wu),qD=i(async(u,e)=>{const{outputPath:D}=u,t=Fe.find(o=>D.endsWith(o));if(!t)return{error:`Unsupported extension (must be ${Fe.join("|")})`,exportEntry:u};const n=D.slice(e.dist.length,-t.length),r=await VD(z.join(e.srcResolved,n),wu[t]);return r?{exportEntry:u,distExtension:t,srcdist:e,...r}:{error:`Source file not found: ${z.join(e.src,n)}(${wu[t].join("|")})`,exportEntry:u}},"getSourcePath"),zD=i(async u=>{try{return await uu.readdir(u,{withFileTypes:!0})}catch(e){const{code:D}=e;if(D==="ENOENT")return[];throw e}},"safeReaddir"),Ce=i(async(u,e)=>{const D=await zD(u);return(await Promise.all(D.map(async n=>{const r=z.join(u,n.name);return n.isDirectory()?Ce(r,e):n.isFile()?z.relative(e,r):[]}))).flat()},"getDirectoryFilesRecursive"),he=new Map,JD=i(async u=>{let e=he.get(u);return e||(e=Ce(u,u),he.set(u,e)),e},"getDirectoryFiles"),Ee=/\.[^./]+$/,KD=i((u,e)=>{const D=u.replace(Ee,""),t=e.at(-1);if(!D.endsWith(t))return;const n=D.split("/").filter(Boolean);for(let r=1;r<=n.length;r+=1){const o=n.slice(0,r).join("/"),s=o+e.join(o);if(s===D)return s}},"extractWildcardMatch"),GD=i(async(u,e)=>{const D=Array.from(e).sort((n,r)=>r.dist.length-n.dist.length);return(await Promise.all(u.map(async n=>{if(typeof n.source=="string"||n.source.path[0]!=="exports"||!n.outputPath.includes("*"))return[n];const r=n.source.path[1];if(!r.includes("*"))return[n];const o=n.outputPath.match(/\.d\.[cm]?ts$/)||n.outputPath.match(Ee);if(!o)return[{exportEntry:n,error:`Wildcard pattern must include a file extension (e.g., ".mjs", ".cjs"). Pattern: ${r}`}];const[s]=o,a=n.outputPath.slice(0,-s.length),[l,...c]=a.split("*"),f=D.find(({dist:d})=>l===d||l.startsWith(d));if(!f)return[];const p=E.posix.join(f.srcResolved,l.slice(f.dist.length));return(await JD(p)).flatMap(d=>{const m=KD(d,c);return m?[{...n,outputPath:l+m+s}]:[]})}))).flat()},"expandBuildOutputWildcards"),HD=i(async(u,e,D)=>{LD(e);const t=e.type??"commonjs",n=await GD(UD(e,t),u);D.length>0&&n.push(...D.map(o=>({...o,format:M(o.outputPath)??t})));const r=new Map;return await Promise.all(n.map(async o=>{if("error"in o)return o;const s=u.find(({dist:l})=>o.outputPath.startsWith(l));if(!s)return{exportEntry:o,error:"Ignoring file outside of dist directories"};const a=r.get(o.outputPath);if(a){if(a.format!==o.format)throw new Error(`Conflicting export types "${a.format}" & "${o.format}" found for ${o.outputPath}`)}else r.set(o.outputPath,o);return await qD(o,s)}))},"getBuildEntryPoints"),ZD=["peerDependencies","dependencies","optionalDependencies"],vu="@types/",me=i((u,e,D=!1)=>{const t=[],{devDependencies:n}=u;for(const r of ZD){const o=u[r];if(!o)continue;const s=Object.keys(o);for(const a of s)if(!(a in e))if(a.startsWith(vu)){if(D){let l=a.slice(vu.length);l.includes("__")&&(l=`@${l.replace("__","/")}`),t.push(l)}}else{if(n&&D){const l=vu+a.replace("@","").replace("/","__");n[l]&&!(l in o)&&console.warn(`Recommendation: "${l}" is externalized because "${a}" is in "${r}". Place "${l}" in "${r}" as well so users don't have missing types.`)}t.push(a)}}return t.flatMap(r=>[r,new RegExp(`^${r}/`)])},"getExternalDependencies"),H=Symbol("entry"),YD=i(u=>{const e=ot(/\.([cm]?[jt]s|[jt]sx)$/);return{name:"esbuild-transform",transform:i(async(D,t)=>{if(!e(t))return null;const n=await zu(D,{...u,supported:{"import-meta":!0},loader:"default",sourcefile:t.replace(/\.[cm]ts/,".ts")});return{code:n.code,map:n.map||null}},"transform")}},"esbuildTransform"),QD=i(u=>{if(u==="es")return"esm";if(u==="cjs"||u==="iife")return u},"getEsbuildFormat"),XD=i(u=>({name:"esbuild-minify",renderChunk:i(async(e,D,t)=>{const n=await zu(e,{...u,format:QD(t.format),minify:!0,keepNames:!0});return{code:n.code,map:n.map||null}},"renderChunk")}),"esbuildMinify"),$u=i((u,e)=>u[0]-e[0]||u[1]-e[1]||u[2]-e[2],"compareSemver"),ge=i(({target:u})=>{const e=u.some(D=>{if(D=D.trim(),!D.startsWith("node"))return;const t=D.slice(4).split(".").map(Number),n=[t[0],t[1]??0,t[2]??0];return!($u(n,[12,20,0])>=0&&$u(n,[13,0,0])<0||$u(n,[14,13,1])>=0)});return{name:"node-builtins",resolveId:i(D=>{const t=D.startsWith("node:");if(e&&t&&(D=D.slice(5)),it.includes(D)||t)return{id:D,external:!0}},"resolveId")}},"nodeBuiltins"),un=i(u=>{const e=u.filter(t=>t.exportEntry.type==="binary");if(e.length===0)return{name:"patch-binary"};let D;return{name:"patch-binary",options:i(()=>{D=new Set(e.flatMap(t=>t.inputNames))},"options"),renderChunk:i((t,n,r)=>{if(!n.isEntry||!n.facadeModuleId||!D.has(n.name))return;const o=new eu(t);return o.prepend(`#!/usr/bin/env node
|
|
23
23
|
`),{code:o.toString(),map:r.sourcemap?o.generateMap({hires:!0}):void 0}},"renderChunk"),writeBundle:i(async(t,n)=>{const r=new Set(Object.keys(n).map(o=>$(z.join(t.dir,o))));await Promise.all(e.map(async({exportEntry:o})=>{const{outputPath:s}=o;r.has(s)&&await I.promises.chmod(s,493)}))},"writeBundle")}},"patchBinary"),Be=i(()=>{const u=/\.(?:[mc]?js|jsx)$/;return{name:"resolve-js-to-ts",resolveId(e,D,t){return D&&u.test(e)?this.resolve(e.replace(/js(x?)$/,"ts$1"),D,t):null}}},"resolveJsToTs"),ye=i(u=>u!==null&&typeof u=="object","A"),U=i((u,e)=>Object.assign(new Error(`[${u}]: ${e}`),{code:u}),"a"),Ae="ERR_INVALID_PACKAGE_CONFIG",xu="ERR_INVALID_PACKAGE_TARGET",en="ERR_PACKAGE_PATH_NOT_EXPORTED",tn=/^\d+$/,Dn=/^(\.{1,2}|node_modules)$/i,nn=/\/|\\/;var be=(u=>(u.Export="exports",u.Import="imports",u))(be||{});const ku=i((u,e,D,t,n)=>{if(e==null)return[];if(typeof e=="string"){const[r,...o]=e.split(nn);if(r===".."||o.some(s=>Dn.test(s)))throw U(xu,`Invalid "${u}" target "${e}" defined in the package config`);return[n?e.replace(/\*/g,n):e]}if(Array.isArray(e))return e.flatMap(r=>ku(u,r,D,t,n));if(ye(e)){for(const r of Object.keys(e)){if(tn.test(r))throw U(Ae,"Cannot contain numeric property keys");if(r==="default"||t.includes(r))return ku(u,e[r],D,t,n)}return[]}throw U(xu,`Invalid "${u}" target "${e}"`)},"f"),Z="*",rn=i((u,e)=>{const D=u.indexOf(Z),t=e.indexOf(Z);return D===t?e.length>u.length:t>D},"m");function on(u,e){if(!e.includes(Z)&&u.hasOwnProperty(e))return[e];let D,t;for(const n of Object.keys(u))if(n.includes(Z)){const[r,o,s]=n.split(Z);if(s===void 0&&e.startsWith(r)&&e.endsWith(o)){const a=e.slice(r.length,-o.length||void 0);a&&(!D||rn(D,n))&&(D=n,t=a)}}return[D,t]}i(on,"d");const sn=i(u=>Object.keys(u).reduce((e,D)=>{const t=D===""||D[0]!==".";if(e===void 0||e===t)return t;throw U(Ae,'"exports" cannot contain some keys starting with "." and some not')},void 0),"p"),an=/^\w+:/,ln=i((u,e,D)=>{if(!u)throw new Error('"exports" is required');e=e===""?".":`./${e}`,(typeof u=="string"||Array.isArray(u)||ye(u)&&sn(u))&&(u={".":u});const[t,n]=on(u,e),r=ku(be.Export,u[t],e,D,n);if(r.length===0)throw U(en,e==="."?'No "exports" main defined':`Package subpath '${e}' is not defined by "exports"`);for(const o of r)if(!o.startsWith("./")&&!an.test(o))throw U(xu,`Invalid "exports" target "${o}" defined in the package config`);return r},"v");var cn=Object.defineProperty,F=i((u,e)=>cn(u,"name",{value:e,configurable:!0}),"o");function j(u){return u.startsWith("\\\\?\\")?u:u.replace(/\\/g,"/")}i(j,"E"),F(j,"slash");const ju=F(u=>{const e=I[u];return(D,...t)=>{const n=`${u}:${t.join(":")}`;let r=D?.get(n);return r===void 0&&(r=Reflect.apply(e,I,t),D?.set(n,r)),r}},"cacheFs"),S=ju("existsSync"),fn=ju("readFileSync"),su=ju("statSync"),we=F((u,e,D)=>{for(;;){const t=E.posix.join(u,e);if(S(D,t))return t;const n=E.dirname(u);if(n===u)return;u=n}},"findUp"),Ou=/^\.{1,2}(\/.*)?$/,Su=F(u=>{const e=j(u);return Ou.test(e)?e:`./${e}`},"normalizeRelativePath");function ve(u,e=!1){const D=u.length;let t=0,n="",r=0,o=16,s=0,a=0,l=0,c=0,f=0;function p(C,B){let g=0,w=0;for(;g<C;){let x=u.charCodeAt(t);if(x>=48&&x<=57)w=w*16+x-48;else if(x>=65&&x<=70)w=w*16+x-65+10;else if(x>=97&&x<=102)w=w*16+x-97+10;else break;t++,g++}return g<C&&(w=-1),w}i(p,"_"),F(p,"scanHexDigits");function h(C){t=C,n="",r=0,o=16,f=0}i(h,"d"),F(h,"setPosition");function d(){let C=t;if(u.charCodeAt(t)===48)t++;else for(t++;t<u.length&&L(u.charCodeAt(t));)t++;if(t<u.length&&u.charCodeAt(t)===46)if(t++,t<u.length&&L(u.charCodeAt(t)))for(t++;t<u.length&&L(u.charCodeAt(t));)t++;else return f=3,u.substring(C,t);let B=t;if(t<u.length&&(u.charCodeAt(t)===69||u.charCodeAt(t)===101))if(t++,(t<u.length&&u.charCodeAt(t)===43||u.charCodeAt(t)===45)&&t++,t<u.length&&L(u.charCodeAt(t))){for(t++;t<u.length&&L(u.charCodeAt(t));)t++;B=t}else f=3;return u.substring(C,B)}i(d,"A"),F(d,"scanNumber");function m(){let C="",B=t;for(;;){if(t>=D){C+=u.substring(B,t),f=2;break}const g=u.charCodeAt(t);if(g===34){C+=u.substring(B,t),t++;break}if(g===92){if(C+=u.substring(B,t),t++,t>=D){f=2;break}switch(u.charCodeAt(t++)){case 34:C+='"';break;case 92:C+="\\";break;case 47:C+="/";break;case 98:C+="\b";break;case 102:C+="\f";break;case 110:C+=`
|
|
24
24
|
`;break;case 114:C+="\r";break;case 116:C+=" ";break;case 117:const w=p(4);w>=0?C+=String.fromCharCode(w):f=4;break;default:f=5}B=t;continue}if(g>=0&&g<=31)if(V(g)){C+=u.substring(B,t),f=2;break}else f=6;t++}return C}i(m,"w"),F(m,"scanString");function b(){if(n="",f=0,r=t,a=s,c=l,t>=D)return r=D,o=17;let C=u.charCodeAt(t);if(iu(C)){do t++,n+=String.fromCharCode(C),C=u.charCodeAt(t);while(iu(C));return o=15}if(V(C))return t++,n+=String.fromCharCode(C),C===13&&u.charCodeAt(t)===10&&(t++,n+=`
|
|
25
25
|
`),s++,l=t,o=14;switch(C){case 123:return t++,o=1;case 125:return t++,o=2;case 91:return t++,o=3;case 93:return t++,o=4;case 58:return t++,o=6;case 44:return t++,o=5;case 34:return t++,n=m(),o=10;case 47:const B=t-1;if(u.charCodeAt(t+1)===47){for(t+=2;t<D&&!V(u.charCodeAt(t));)t++;return n=u.substring(B,t),o=12}if(u.charCodeAt(t+1)===42){t+=2;const g=D-1;let w=!1;for(;t<g;){const x=u.charCodeAt(t);if(x===42&&u.charCodeAt(t+1)===47){t+=2,w=!0;break}t++,V(x)&&(x===13&&u.charCodeAt(t)===10&&t++,s++,l=t)}return w||(t++,f=1),n=u.substring(B,t),o=13}return n+=String.fromCharCode(C),t++,o=16;case 45:if(n+=String.fromCharCode(C),t++,t===D||!L(u.charCodeAt(t)))return o=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return n+=d(),o=11;default:for(;t<D&&O(C);)t++,C=u.charCodeAt(t);if(r!==t){switch(n=u.substring(r,t),n){case"true":return o=8;case"false":return o=9;case"null":return o=7}return o=16}return n+=String.fromCharCode(C),t++,o=16}}i(b,"y"),F(b,"scanNext");function O(C){if(iu(C)||V(C))return!1;switch(C){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}i(O,"I"),F(O,"isUnknownContentCharacter");function A(){let C;do C=b();while(C>=12&&C<=15);return C}return i(A,"L"),F(A,"scanNextNonTrivia"),{setPosition:h,getPosition:F(()=>t,"getPosition"),scan:e?A:b,getToken:F(()=>o,"getToken"),getTokenValue:F(()=>n,"getTokenValue"),getTokenOffset:F(()=>r,"getTokenOffset"),getTokenLength:F(()=>t-r,"getTokenLength"),getTokenStartLine:F(()=>a,"getTokenStartLine"),getTokenStartCharacter:F(()=>r-c,"getTokenStartCharacter"),getTokenError:F(()=>f,"getTokenError")}}i(ve,"je"),F(ve,"createScanner");function iu(u){return u===32||u===9}i(iu,"Q"),F(iu,"isWhiteSpace");function V(u){return u===10||u===13}i(V,"x"),F(V,"isLineBreak");function L(u){return u>=48&&u<=57}i(L,"U"),F(L,"isDigit");var $e;(function(u){u[u.lineFeed=10]="lineFeed",u[u.carriageReturn=13]="carriageReturn",u[u.space=32]="space",u[u._0=48]="_0",u[u._1=49]="_1",u[u._2=50]="_2",u[u._3=51]="_3",u[u._4=52]="_4",u[u._5=53]="_5",u[u._6=54]="_6",u[u._7=55]="_7",u[u._8=56]="_8",u[u._9=57]="_9",u[u.a=97]="a",u[u.b=98]="b",u[u.c=99]="c",u[u.d=100]="d",u[u.e=101]="e",u[u.f=102]="f",u[u.g=103]="g",u[u.h=104]="h",u[u.i=105]="i",u[u.j=106]="j",u[u.k=107]="k",u[u.l=108]="l",u[u.m=109]="m",u[u.n=110]="n",u[u.o=111]="o",u[u.p=112]="p",u[u.q=113]="q",u[u.r=114]="r",u[u.s=115]="s",u[u.t=116]="t",u[u.u=117]="u",u[u.v=118]="v",u[u.w=119]="w",u[u.x=120]="x",u[u.y=121]="y",u[u.z=122]="z",u[u.A=65]="A",u[u.B=66]="B",u[u.C=67]="C",u[u.D=68]="D",u[u.E=69]="E",u[u.F=70]="F",u[u.G=71]="G",u[u.H=72]="H",u[u.I=73]="I",u[u.J=74]="J",u[u.K=75]="K",u[u.L=76]="L",u[u.M=77]="M",u[u.N=78]="N",u[u.O=79]="O",u[u.P=80]="P",u[u.Q=81]="Q",u[u.R=82]="R",u[u.S=83]="S",u[u.T=84]="T",u[u.U=85]="U",u[u.V=86]="V",u[u.W=87]="W",u[u.X=88]="X",u[u.Y=89]="Y",u[u.Z=90]="Z",u[u.asterisk=42]="asterisk",u[u.backslash=92]="backslash",u[u.closeBrace=125]="closeBrace",u[u.closeBracket=93]="closeBracket",u[u.colon=58]="colon",u[u.comma=44]="comma",u[u.dot=46]="dot",u[u.doubleQuote=34]="doubleQuote",u[u.minus=45]="minus",u[u.openBrace=123]="openBrace",u[u.openBracket=91]="openBracket",u[u.plus=43]="plus",u[u.slash=47]="slash",u[u.formFeed=12]="formFeed",u[u.tab=9]="tab"})($e||($e={})),new Array(20).fill(0).map((u,e)=>" ".repeat(e));const q=200;new Array(q).fill(0).map((u,e)=>`
|
|
@@ -27,4 +27,4 @@ var Ye=Object.defineProperty;var i=(u,e)=>Ye(u,"name",{value:e,configurable:!0})
|
|
|
27
27
|
`+" ".repeat(e)),new Array(q).fill(0).map((u,e)=>`
|
|
28
28
|
`+" ".repeat(e)),new Array(q).fill(0).map((u,e)=>"\r"+" ".repeat(e)),new Array(q).fill(0).map((u,e)=>`\r
|
|
29
29
|
`+" ".repeat(e));var au;(function(u){u.DEFAULT={allowTrailingComma:!1}})(au||(au={}));function xe(u,e=[],D=au.DEFAULT){let t=null,n=[];const r=[];function o(s){Array.isArray(n)?n.push(s):t!==null&&(n[t]=s)}return i(o,"u"),F(o,"onValue"),ke(u,{onObjectBegin:F(()=>{const s={};o(s),r.push(n),n=s,t=null},"onObjectBegin"),onObjectProperty:F(s=>{t=s},"onObjectProperty"),onObjectEnd:F(()=>{n=r.pop()},"onObjectEnd"),onArrayBegin:F(()=>{const s=[];o(s),r.push(n),n=s,t=null},"onArrayBegin"),onArrayEnd:F(()=>{n=r.pop()},"onArrayEnd"),onLiteralValue:o,onError:F((s,a,l)=>{e.push({error:s,offset:a,length:l})},"onError")},D),n[0]}i(xe,"ye"),F(xe,"parse$1");function ke(u,e,D=au.DEFAULT){const t=ve(u,!1),n=[];function r(y){return y?()=>y(t.getTokenOffset(),t.getTokenLength(),t.getTokenStartLine(),t.getTokenStartCharacter()):()=>!0}i(r,"i"),F(r,"toNoArgVisit");function o(y){return y?()=>y(t.getTokenOffset(),t.getTokenLength(),t.getTokenStartLine(),t.getTokenStartCharacter(),()=>n.slice()):()=>!0}i(o,"u"),F(o,"toNoArgVisitWithPath");function s(y){return y?v=>y(v,t.getTokenOffset(),t.getTokenLength(),t.getTokenStartLine(),t.getTokenStartCharacter()):()=>!0}i(s,"f"),F(s,"toOneArgVisit");function a(y){return y?v=>y(v,t.getTokenOffset(),t.getTokenLength(),t.getTokenStartLine(),t.getTokenStartCharacter(),()=>n.slice()):()=>!0}i(a,"r"),F(a,"toOneArgVisitWithPath");const l=o(e.onObjectBegin),c=a(e.onObjectProperty),f=r(e.onObjectEnd),p=o(e.onArrayBegin),h=r(e.onArrayEnd),d=a(e.onLiteralValue),m=s(e.onSeparator),b=r(e.onComment),O=s(e.onError),A=D&&D.disallowComments,C=D&&D.allowTrailingComma;function B(){for(;;){const y=t.scan();switch(t.getTokenError()){case 4:g(14);break;case 5:g(15);break;case 3:g(13);break;case 1:A||g(11);break;case 2:g(12);break;case 6:g(16);break}switch(y){case 12:case 13:A?g(10):b();break;case 16:g(1);break;case 15:case 14:break;default:return y}}}i(B,"k"),F(B,"scanNext");function g(y,v=[],qu=[]){if(O(y),v.length+qu.length>0){let X=t.getToken();for(;X!==17;){if(v.indexOf(X)!==-1){B();break}else if(qu.indexOf(X)!==-1)break;X=B()}}}i(g,"p"),F(g,"handleError");function w(y){const v=t.getTokenValue();return y?d(v):(c(v),n.push(v)),B(),!0}i(w,"F"),F(w,"parseString");function x(){switch(t.getToken()){case 11:const y=t.getTokenValue();let v=Number(y);isNaN(v)&&(g(2),v=0),d(v);break;case 7:d(null);break;case 8:d(!0);break;case 9:d(!1);break;default:return!1}return B(),!0}i(x,"j"),F(x,"parseLiteral");function Wu(){return t.getToken()!==10?(g(3,[],[2,5]),!1):(w(!1),t.getToken()===6?(m(":"),B(),Q()||g(4,[],[2,5])):g(5,[],[2,5]),n.pop(),!0)}i(Wu,"a"),F(Wu,"parseProperty");function Uu(){l(),B();let y=!1;for(;t.getToken()!==2&&t.getToken()!==17;){if(t.getToken()===5){if(y||g(4,[],[]),m(","),B(),t.getToken()===2&&C)break}else y&&g(6,[],[]);Wu()||g(4,[],[2,5]),y=!0}return f(),t.getToken()!==2?g(7,[2],[]):B(),!0}i(Uu,"N"),F(Uu,"parseObject");function Vu(){p(),B();let y=!0,v=!1;for(;t.getToken()!==4&&t.getToken()!==17;){if(t.getToken()===5){if(v||g(4,[],[]),m(","),B(),t.getToken()===4&&C)break}else v&&g(6,[],[]);y?(n.push(0),y=!1):n[n.length-1]++,Q()||g(4,[],[4,5]),v=!0}return h(),y||n.pop(),t.getToken()!==4?g(8,[4],[]):B(),!0}i(Vu,"be"),F(Vu,"parseArray");function Q(){switch(t.getToken()){case 3:return Vu();case 1:return Uu();case 10:return w(!0);default:return x()}}return i(Q,"J"),F(Q,"parseValue"),B(),t.getToken()===17?D.allowEmptyContent?!0:(g(4,[],[]),!1):Q()?(t.getToken()!==17&&g(9,[],[]),!0):(g(4,[],[]),!1)}i(ke,"Fe"),F(ke,"visit");var je;(function(u){u[u.None=0]="None",u[u.UnexpectedEndOfComment=1]="UnexpectedEndOfComment",u[u.UnexpectedEndOfString=2]="UnexpectedEndOfString",u[u.UnexpectedEndOfNumber=3]="UnexpectedEndOfNumber",u[u.InvalidUnicode=4]="InvalidUnicode",u[u.InvalidEscapeCharacter=5]="InvalidEscapeCharacter",u[u.InvalidCharacter=6]="InvalidCharacter"})(je||(je={}));var Oe;(function(u){u[u.OpenBraceToken=1]="OpenBraceToken",u[u.CloseBraceToken=2]="CloseBraceToken",u[u.OpenBracketToken=3]="OpenBracketToken",u[u.CloseBracketToken=4]="CloseBracketToken",u[u.CommaToken=5]="CommaToken",u[u.ColonToken=6]="ColonToken",u[u.NullKeyword=7]="NullKeyword",u[u.TrueKeyword=8]="TrueKeyword",u[u.FalseKeyword=9]="FalseKeyword",u[u.StringLiteral=10]="StringLiteral",u[u.NumericLiteral=11]="NumericLiteral",u[u.LineCommentTrivia=12]="LineCommentTrivia",u[u.BlockCommentTrivia=13]="BlockCommentTrivia",u[u.LineBreakTrivia=14]="LineBreakTrivia",u[u.Trivia=15]="Trivia",u[u.Unknown=16]="Unknown",u[u.EOF=17]="EOF"})(Oe||(Oe={}));const pn=xe;var Se;(function(u){u[u.InvalidSymbol=1]="InvalidSymbol",u[u.InvalidNumberFormat=2]="InvalidNumberFormat",u[u.PropertyNameExpected=3]="PropertyNameExpected",u[u.ValueExpected=4]="ValueExpected",u[u.ColonExpected=5]="ColonExpected",u[u.CommaExpected=6]="CommaExpected",u[u.CloseBraceExpected=7]="CloseBraceExpected",u[u.CloseBracketExpected=8]="CloseBracketExpected",u[u.EndOfFileExpected=9]="EndOfFileExpected",u[u.InvalidCommentToken=10]="InvalidCommentToken",u[u.UnexpectedEndOfComment=11]="UnexpectedEndOfComment",u[u.UnexpectedEndOfString=12]="UnexpectedEndOfString",u[u.UnexpectedEndOfNumber=13]="UnexpectedEndOfNumber",u[u.InvalidUnicode=14]="InvalidUnicode",u[u.InvalidEscapeCharacter=15]="InvalidEscapeCharacter",u[u.InvalidCharacter=16]="InvalidCharacter"})(Se||(Se={}));const Te=F((u,e)=>pn(fn(e,u,"utf8")),"readJsonc"),Tu=Symbol("implicitBaseUrl"),_="${configDir}",dn=F(()=>{const{findPnpApi:u}=st;return u&&u(process.cwd())},"getPnpApi"),Pu=F((u,e,D,t)=>{const n=`resolveFromPackageJsonPath:${u}:${e}:${D}`;if(t!=null&&t.has(n))return t.get(n);const r=Te(u,t);if(!r)return;let o=e||"tsconfig.json";if(!D&&r.exports)try{const[s]=ln(r.exports,e,["require","types"]);o=s}catch{return!1}else!e&&r.tsconfig&&(o=r.tsconfig);return o=E.join(u,"..",o),t?.set(n,o),o},"resolveFromPackageJsonPath"),Iu="package.json",_u="tsconfig.json",Fn=F((u,e,D)=>{let t=u;if(u===".."&&(t=E.join(t,_u)),u[0]==="."&&(t=E.resolve(e,t)),E.isAbsolute(t)){if(S(D,t)){if(su(D,t).isFile())return t}else if(!t.endsWith(".json")){const h=`${t}.json`;if(S(D,h))return h}return}const[n,...r]=u.split("/"),o=n[0]==="@"?`${n}/${r.shift()}`:n,s=r.join("/"),a=dn();if(a){const{resolveRequest:h}=a;try{if(o===u){const d=h(E.join(o,Iu),e);if(d){const m=Pu(d,s,!1,D);if(m&&S(D,m))return m}}else{let d;try{d=h(u,e,{extensions:[".json"]})}catch{d=h(E.join(u,_u),e)}if(d)return d}}catch{}}const l=we(E.resolve(e),E.join("node_modules",o),D);if(!l||!su(D,l).isDirectory())return;const c=E.join(l,Iu);if(S(D,c)){const h=Pu(c,s,!1,D);if(h===!1)return;if(h&&S(D,h)&&su(D,h).isFile())return h}const f=E.join(l,s),p=f.endsWith(".json");if(!p){const h=`${f}.json`;if(S(D,h))return h}if(S(D,f)){if(su(D,f).isDirectory()){const h=E.join(f,Iu);if(S(D,h)){const m=Pu(h,"",!0,D);if(m&&S(D,m))return m}const d=E.join(f,_u);if(S(D,d))return d}else if(p)return f}},"resolveExtendsPath"),Nu=F((u,e)=>Su(E.relative(u,e)),"pathRelative"),Pe=["files","include","exclude"],Cn=F((u,e,D,t)=>{const n=Fn(u,e,t);if(!n)throw new Error(`File '${u}' not found.`);if(D.has(n))throw new Error(`Circularity detected while resolving configuration: ${n}`);D.add(n);const r=E.dirname(n),o=Ie(n,t,D);delete o.references;const{compilerOptions:s}=o;if(s){const{baseUrl:a}=s;a&&!a.startsWith(_)&&(s.baseUrl=j(E.relative(e,E.join(r,a)))||"./");let{outDir:l}=s;l&&(l.startsWith(_)||(l=E.relative(e,E.join(r,l))),s.outDir=j(l)||"./")}for(const a of Pe){const l=o[a];l&&(o[a]=l.map(c=>c.startsWith(_)?c:j(E.relative(e,E.join(r,c)))))}return o},"resolveExtends"),hn=["outDir","declarationDir"],Ie=F((u,e,D=new Set)=>{let t;try{t=Te(u,e)||{}}catch{throw new Error(`Cannot resolve tsconfig at path: ${u}`)}if(typeof t!="object")throw new SyntaxError(`Failed to parse tsconfig at: ${u}`);const n=E.dirname(u);if(t.compilerOptions){const{compilerOptions:r}=t;r.paths&&!r.baseUrl&&(r[Tu]=n)}if(t.extends){const r=Array.isArray(t.extends)?t.extends:[t.extends];delete t.extends;for(const o of r.reverse()){const s=Cn(o,n,new Set(D),e),a={...s,...t,compilerOptions:{...s.compilerOptions,...t.compilerOptions}};s.watchOptions&&(a.watchOptions={...s.watchOptions,...t.watchOptions}),t=a}}if(t.compilerOptions){const{compilerOptions:r}=t,o=["baseUrl","rootDir"];for(const s of o){const a=r[s];if(a&&!a.startsWith(_)){const l=E.resolve(n,a),c=Nu(n,l);r[s]=c}}for(const s of hn){let a=r[s];a&&(Array.isArray(t.exclude)||(t.exclude=[]),t.exclude.includes(a)||t.exclude.push(a),a.startsWith(_)||(a=Su(a)),r[s]=a)}}else t.compilerOptions={};if(t.include?(t.include=t.include.map(j),t.files&&delete t.files):t.files&&(t.files=t.files.map(r=>r.startsWith(_)?r:Su(r))),t.watchOptions){const{watchOptions:r}=t;r.excludeDirectories&&(r.excludeDirectories=r.excludeDirectories.map(o=>j(E.resolve(n,o))))}return t},"_parseTsconfig"),lu=F((u,e)=>{if(u.startsWith(_))return j(E.join(e,u.slice(_.length)))},"interpolateConfigDir"),En=["outDir","declarationDir","outFile","rootDir","baseUrl","tsBuildInfoFile"],mn=F(u=>{if(u.strict){const e=["noImplicitAny","noImplicitThis","strictNullChecks","strictFunctionTypes","strictBindCallApply","strictPropertyInitialization","strictBuiltinIteratorReturn","alwaysStrict","useUnknownInCatchVariables"];for(const D of e)u[D]===void 0&&(u[D]=!0)}if(u.target){let e=u.target.toLowerCase();e==="es2015"&&(e="es6"),u.target=e,e==="esnext"&&(u.module!=null||(u.module="es6"),u.useDefineForClassFields!=null||(u.useDefineForClassFields=!0)),(e==="es6"||e==="es2016"||e==="es2017"||e==="es2018"||e==="es2019"||e==="es2020"||e==="es2021"||e==="es2022"||e==="es2023"||e==="es2024")&&(u.module!=null||(u.module="es6")),(e==="es2022"||e==="es2023"||e==="es2024")&&(u.useDefineForClassFields!=null||(u.useDefineForClassFields=!0))}if(u.module){let e=u.module.toLowerCase();e==="es2015"&&(e="es6"),u.module=e,(e==="es6"||e==="es2020"||e==="es2022"||e==="esnext"||e==="none"||e==="system"||e==="umd"||e==="amd")&&(u.moduleResolution!=null||(u.moduleResolution="classic")),e==="system"&&(u.allowSyntheticDefaultImports!=null||(u.allowSyntheticDefaultImports=!0)),(e==="node16"||e==="nodenext"||e==="preserve")&&(u.esModuleInterop!=null||(u.esModuleInterop=!0),u.allowSyntheticDefaultImports!=null||(u.allowSyntheticDefaultImports=!0)),(e==="node16"||e==="nodenext")&&(u.moduleDetection!=null||(u.moduleDetection="force"),u.useDefineForClassFields!=null||(u.useDefineForClassFields=!0)),e==="node16"&&(u.target!=null||(u.target="es2022"),u.moduleResolution!=null||(u.moduleResolution="node16")),e==="nodenext"&&(u.target!=null||(u.target="esnext"),u.moduleResolution!=null||(u.moduleResolution="nodenext")),e==="preserve"&&(u.moduleResolution!=null||(u.moduleResolution="bundler"))}if(u.moduleResolution){let e=u.moduleResolution.toLowerCase();e==="node"&&(e="node10"),u.moduleResolution=e,(e==="node16"||e==="nodenext"||e==="bundler")&&(u.resolvePackageJsonExports!=null||(u.resolvePackageJsonExports=!0),u.resolvePackageJsonImports!=null||(u.resolvePackageJsonImports=!0)),e==="bundler"&&(u.allowSyntheticDefaultImports!=null||(u.allowSyntheticDefaultImports=!0),u.resolveJsonModule!=null||(u.resolveJsonModule=!0))}u.esModuleInterop&&(u.allowSyntheticDefaultImports!=null||(u.allowSyntheticDefaultImports=!0)),u.verbatimModuleSyntax&&(u.isolatedModules!=null||(u.isolatedModules=!0),u.preserveConstEnums!=null||(u.preserveConstEnums=!0)),u.isolatedModules&&(u.preserveConstEnums!=null||(u.preserveConstEnums=!0))},"normalizeCompilerOptions"),_e=F((u,e=new Map)=>{const D=E.resolve(u),t=Ie(D,e),n=E.dirname(D),{compilerOptions:r}=t;if(r){for(const s of En){const a=r[s];if(a){const l=lu(a,n);r[s]=l?Nu(n,l):a}}for(const s of["rootDirs","typeRoots"]){const a=r[s];a&&(r[s]=a.map(l=>{const c=lu(l,n);return c?Nu(n,c):l}))}const{paths:o}=r;if(o)for(const s of Object.keys(o))o[s]=o[s].map(a=>{var l;return(l=lu(a,n))!=null?l:a});mn(r)}for(const o of Pe){const s=t[o];s&&(t[o]=s.map(a=>{var l;return(l=lu(a,n))!=null?l:a}))}return t},"parseTsconfig"),gn=F((u=process.cwd(),e="tsconfig.json",D=new Map)=>{const t=we(j(u),e,D);if(!t)return null;const n=_e(t,D);return{path:t,config:n}},"getTsconfig"),Bn=/\*/g,Ne=F((u,e)=>{const D=u.match(Bn);if(D&&D.length>1)throw new Error(e)},"assertStarCount"),yn=F(u=>{if(u.includes("*")){const[e,D]=u.split("*");return{prefix:e,suffix:D}}return u},"parsePattern"),An=F(({prefix:u,suffix:e},D)=>D.startsWith(u)&&D.endsWith(e),"isPatternMatch"),bn=F((u,e,D)=>Object.entries(u).map(([t,n])=>(Ne(t,`Pattern '${t}' can have at most one '*' character.`),{pattern:yn(t),substitutions:n.map(r=>{if(Ne(r,`Substitution '${r}' in pattern '${t}' can have at most one '*' character.`),!e&&!Ou.test(r))throw new Error("Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?");return E.resolve(D,r)})})),"parsePaths"),wn=F(u=>{const{compilerOptions:e}=u.config;if(!e)return null;const{baseUrl:D,paths:t}=e;if(!D&&!t)return null;const n=Tu in e&&e[Tu],r=E.resolve(E.dirname(u.path),D||n||"."),o=t?bn(t,D,r):[];return s=>{if(Ou.test(s))return[];const a=[];for(const p of o){if(p.pattern===s)return p.substitutions.map(j);typeof p.pattern!="string"&&a.push(p)}let l,c=-1;for(const p of a)An(p.pattern,s)&&p.pattern.prefix.length>c&&(c=p.pattern.prefix.length,l=p);if(!l)return D?[j(E.join(r,s))]:[];const f=s.slice(l.pattern.prefix.length,s.length-l.pattern.suffix.length);return l.substitutions.map(p=>j(p.replace("*",f)))}},"createPathsMatcher"),Re=F(u=>{let e="";for(let D=0;D<u.length;D+=1){const t=u[D],n=t.toUpperCase();e+=t===n?t.toLowerCase():n}return e},"s"),vn=65,$n=97,xn=F(()=>Math.floor(Math.random()*26),"m"),kn=F(u=>Array.from({length:u},()=>String.fromCodePoint(xn()+(Math.random()>.5?vn:$n))).join(""),"S"),jn=F((u=at)=>{const e=process.execPath;if(u.existsSync(e))return!u.existsSync(Re(e));const D=`/${kn(10)}`;u.writeFileSync(D,"");const t=!u.existsSync(Re(D));return u.unlinkSync(D),t},"l"),{join:cu}=E.posix,Ru={ts:[".ts",".tsx",".d.ts"],cts:[".cts",".d.cts"],mts:[".mts",".d.mts"]},On=F(u=>{const e=[...Ru.ts],D=[...Ru.cts],t=[...Ru.mts];return u!=null&&u.allowJs&&(e.push(".js",".jsx"),D.push(".cjs"),t.push(".mjs")),[...e,...D,...t]},"getSupportedExtensions"),Sn=F(u=>{const e=[];if(!u)return e;const{outDir:D,declarationDir:t}=u;return D&&e.push(D),t&&e.push(t),e},"getDefaultExcludeSpec"),Me=F(u=>u.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`),"escapeForRegexp"),Tn=["node_modules","bower_components","jspm_packages"],Mu=`(?!(${Tn.join("|")})(/|$))`,Pn=/(?:^|\/)[^.*?]+$/,Le="**/*",fu="[^/]",Lu="[^./]",We=process.platform==="win32";F(({config:u,path:e},D=jn())=>{if("extends"in u)throw new Error("tsconfig#extends must be resolved. Use getTsconfig or parseTsconfig to resolve it.");if(!E.isAbsolute(e))throw new Error("The tsconfig path must be absolute");We&&(e=j(e));const t=E.dirname(e),{files:n,include:r,exclude:o,compilerOptions:s}=u,a=n?.map(d=>cu(t,d)),l=On(s),c=D?"":"i",f=(o||Sn(s)).map(d=>{const m=cu(t,d),b=Me(m).replaceAll(String.raw`\*\*/`,"(.+/)?").replaceAll(String.raw`\*`,`${fu}*`).replaceAll(String.raw`\?`,fu);return new RegExp(`^${b}($|/)`,c)}),p=n||r?r:[Le],h=p?p.map(d=>{let m=cu(t,d);Pn.test(m)&&(m=cu(m,Le));const b=Me(m).replaceAll(String.raw`/\*\*`,`(/${Mu}${Lu}${fu}*)*?`).replaceAll(/(\/)?\\\*/g,(O,A)=>{const C=`(${Lu}|(\\.(?!min\\.js$))?)*`;return A?`/${Mu}${Lu}${C}`:C}).replaceAll(/(\/)?\\\?/g,(O,A)=>{const C=fu;return A?`/${Mu}${C}`:C});return new RegExp(`^${b}$`,c)}):void 0;return d=>{if(!E.isAbsolute(d))throw new Error("filePath must be absolute");if(We&&(d=j(d)),a!=null&&a.includes(d)||!(!l.some(m=>d.endsWith(m))||f.some(m=>m.test(d)))&&h&&h.some(m=>m.test(d)))return u}},"createFilesMatcher");const Ue="resolve-tsconfig-paths",In=i(u=>u[0]===".","isRelative"),_n=i(u=>u[0]==="/"||/^[\s\S]:/.test(u),"isAbsolute"),Ve=i(u=>{const e=wn(u);return e?{name:Ue,async resolveId(D,t,n){if(!t||In(D)||_n(D)||D.startsWith("\0"))return null;const r=e(D);for(const o of r){const s=await this.resolve(o,t,{skipSelf:!0,...n});if(s)return s}return null}}:{name:Ue}},"resolveTsconfigPaths"),qe=/^#!.*/,Nn=i(()=>({name:"strip-hashbang",transform:i(u=>{if(!qe.test(u))return null;const e=new eu(u);return e.replace(qe,""),{code:e.toString(),map:e.generateMap({hires:!0})}},"transform")}),"stripHashbang");class Rn{static{i(this,"WalkerBase")}constructor(){this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.context={skip:i(()=>this.should_skip=!0,"skip"),remove:i(()=>this.should_remove=!0,"remove"),replace:i(e=>this.replacement=e,"replace")}}replace(e,D,t,n){e&&D&&(t!=null?e[D][t]=n:e[D]=n)}remove(e,D,t){e&&D&&(t!=null?e[D].splice(t,1):delete e[D])}}class Mn extends Rn{static{i(this,"SyncWalker")}constructor(e,D){super(),this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.context={skip:i(()=>this.should_skip=!0,"skip"),remove:i(()=>this.should_remove=!0,"remove"),replace:i(t=>this.replacement=t,"replace")},this.enter=e,this.leave=D}visit(e,D,t,n){if(e){if(this.enter){const o=this.should_skip,s=this.should_remove,a=this.replacement;this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.enter.call(this.context,e,D,t,n),this.replacement&&(e=this.replacement,this.replace(D,t,n,e)),this.should_remove&&this.remove(D,t,n);const l=this.should_skip,c=this.should_remove;if(this.should_skip=o,this.should_remove=s,this.replacement=a,l)return e;if(c)return null}let r;for(r in e){const o=e[r];if(o&&typeof o=="object")if(Array.isArray(o)){const s=o;for(let a=0;a<s.length;a+=1){const l=s[a];ze(l)&&(this.visit(l,e,r,a)||a--)}}else ze(o)&&this.visit(o,e,r,null)}if(this.leave){const o=this.replacement,s=this.should_remove;this.replacement=null,this.should_remove=!1,this.leave.call(this.context,e,D,t,n),this.replacement&&(e=this.replacement,this.replace(D,t,n,e)),this.should_remove&&this.remove(D,t,n);const a=this.should_remove;if(this.replacement=o,this.should_remove=s,a)return null}}return e}}function ze(u){return u!==null&&typeof u=="object"&&"type"in u&&typeof u.type=="string"}i(ze,"isNode");function Ln(u,{enter:e,leave:D}){return new Mn(e,D).visit(u,null)}i(Ln,"walk");const Wn=i(()=>{const u='import{createRequire as _pkgrollCR}from"node:module";const require=_pkgrollCR(import.meta.url);';return{name:"esmInjectCreateRequire",renderChunk(e,D,t){if(t.format!=="es"||!/\brequire\b/.test(e))return null;const n=this.parse(e);let r=lt(n,"scope"),o=!1;if(Ln(n,{enter(a,l){a.scope&&(r=a.scope),!(a.type!=="Identifier"||a.name!=="require")&&(l?.type==="Property"&&l.key===a&&!l.compute||l?.type!=="MemberExpression"&&(r.contains("require")||(o=!0,this.skip())))},leave:i(a=>{a.scope&&(r=r.parent)},"leave")}),!o)return null;const s=new eu(e);return s.prepend(u),{code:s.toString(),map:s.generateMap({hires:!0})}}}},"esmInjectCreateRequire"),pu="\0natives:",Un=i(u=>{const e=`${u}/natives`,D=new Map;return{name:"native-modules",buildStart:i(()=>{D.clear()},"buildStart"),async resolveId(t,n){if(t.startsWith(pu)||!t.endsWith(".node"))return null;const r=n?E.resolve(E.dirname(n),t):E.resolve(t);try{await uu.access(r)}catch{return this.warn(`Native module not found: ${r}`),null}const o=E.basename(r);let s=o,a=1;const l=new Set(Array.from(D.values()).map(f=>E.basename(f)));for(;l.has(s);){const f=E.extname(o);s=`${E.basename(o,f)}_${a}${f}`,a+=1}const c=E.join(e,s);return D.set(r,c),pu+r},load(t){if(!t.startsWith(pu))return null;const n=t.slice(pu.length),r=D.get(n);return r?`export default require("${`./${E.relative(u,r)}`.replaceAll("\\","/")}");`:this.error(`Could not find staged native module for: ${n}`)},generateBundle:i(async()=>{D.size!==0&&(await uu.mkdir(e,{recursive:!0}),await Promise.all(Array.from(D.entries()).map(([t,n])=>uu.copyFile(t,n))))},"generateBundle")}},"nativeModules"),du=i(u=>u.replace("\0","").split("?")[0],"cleanRollupId"),Vn=i(u=>{try{return ft(u)}catch{return{exports:[],reexports:[]}}},"safeParse"),qn=i(()=>{const u=new Map,e=i((D,t=new Set)=>{const n=du(D);if(t.has(n))return[];t.add(n);const r=u.get(n);if(!r)return[];const o=[...r.exports];for(const s of r.reexports)o.push(...e(s,t));return o},"getFinalExports");return{name:"cjs-annotate-exports",buildStart:i(async()=>{await ct(),u.clear()},"buildStart"),async transform(D,t){const n=du(t);if(!/\.c?js$/.test(n)||!D.includes("exports"))return;const{exports:r,reexports:o}=Vn(D);if(r.length===0&&o.length===0)return;const a=(await Promise.all(o.map(async l=>{const c=await this.resolve(l,t);return c?du(c.id):""}))).filter(Boolean);u.set(n,{exports:r,reexports:a})},renderChunk:{order:"post",handler(D,t,n){if(n.format!=="cjs"||!t.isEntry||!t.facadeModuleId)return null;const r=du(t.facadeModuleId),o=[...new Set(e(r))];if(o.length>0){const s=new eu(D);return s.append(`
|
|
30
|
-
0&&(module.exports={${o.join(",")}});`),{code:s.toString(),map:s.generateMap({hires:!0})}}}}}},"cjsAnnotateExports"),zn=i((u,e,D,t,n)=>{const r=Object.fromEntries(u.env.map(({key:a,value:l})=>[`process.env.${a}`,JSON.stringify(l)])),o=Object.fromEntries(u.define.map(({key:a,value:l})=>[a,l])),s={target:u.target,tsconfigRaw:t?.config,define:{...r,...o}};return{input:{},preserveEntrySignatures:"strict",plugins:[ge(u),...t?[Ve(t)]:[],Be(),nt({entries:e}),et({extensions:[".mjs",".js",".ts",".jsx",".tsx",".json"],exportConditions:u.exportCondition}),Nn(),Dt(),YD(s),qn(),tt({ignoreDynamicRequires:!0,extensions:[".js",".ts",".jsx",".tsx"],transformMixedEsModules:!0}),rt({warnOnError:!0}),Wn(),Un(n),...u.minify?[XD(s)]:[],un(D)],output:[],external:[]}},"getPkgConfig"),Jn=i(async(u,e)=>{const[D,t]=await Promise.all([import("./rollup-plugin-dts-
|
|
30
|
+
0&&(module.exports={${o.join(",")}});`),{code:s.toString(),map:s.generateMap({hires:!0})}}}}}},"cjsAnnotateExports"),zn=i((u,e,D,t,n)=>{const r=Object.fromEntries(u.env.map(({key:a,value:l})=>[`process.env.${a}`,JSON.stringify(l)])),o=Object.fromEntries(u.define.map(({key:a,value:l})=>[a,l])),s={target:u.target,tsconfigRaw:t?.config,define:{...r,...o}};return{input:{},preserveEntrySignatures:"strict",plugins:[ge(u),...t?[Ve(t)]:[],Be(),nt({entries:e}),et({extensions:[".mjs",".js",".ts",".jsx",".tsx",".json"],exportConditions:u.exportCondition}),Nn(),Dt(),YD(s),qn(),tt({ignoreDynamicRequires:!0,extensions:[".js",".ts",".jsx",".tsx"],transformMixedEsModules:!0}),rt({warnOnError:!0}),Wn(),Un(n),...u.minify?[XD(s)]:[],un(D)],output:[],external:[]}},"getPkgConfig"),Jn=i(async(u,e)=>{const[D,t]=await Promise.all([import("./rollup-plugin-dts-Cax-OLNc.mjs"),import("./local-typescript-loader-CSvrvK-x.mjs")]);return{input:{},preserveEntrySignatures:"strict",plugins:[ge(u),...e?[Ve(e)]:[],Be(),D.default({respectExternal:!0,compilerOptions:{composite:!1,preserveSymlinks:!1,module:t.default.ModuleKind.Preserve,moduleResolution:t.default.ModuleResolutionKind.Bundler},tsconfig:e?.path})],output:[],external:[]}},"getDtsConfig"),Kn=i(u=>{if(u.length===0)return"";const e=u.map(r=>r.split("/")),D=e[0],t=Math.min(...e.map(r=>r.length)),n=[];for(let r=0;r<t;r+=1){const o=D[r];if(e.every(s=>s[r]===o))n.push(o);else break}return n.length===0?"/":n.join("/")||"/"},"getCommonPath"),Gn=i(async(u,e,D,t,n,r)=>{const o=$(Kn(u.map(({dist:a})=>a)),!0);for(const a of u)a.distPrefix=a.dist.slice(o.length);const s=Object.create(null);for(const a of e){const{sourcePath:l,srcdist:c,srcExtension:f,distExtension:p,exportEntry:h}=a,d=c.distPrefix+l.slice(c.srcResolved.length,-f.length);if(a.inputNames=[d],h.format==="types"){let A=s.dts;A||(A=await Jn(D,r),A.external=me(n,t,!0),s.dts=A),A.input[d]||(A.input[d]=l);const C=A.output;if(C[p])C[p][H].inputNames.push(d);else{const B={dir:o,entryFileNames:`[name]${p}`,chunkFileNames:`${c.distPrefix}[name]-[hash]${p}`,exports:"auto",format:"esm",[H]:a};C.push(B),C[p]=B}continue}let m=s.pkg;if(!m){const A=u[0].dist;m=zn(D,t,e,r,A),m.external=me(n,t),s.pkg=m}m.input[d]||(m.input[d]=l);const b=m.output,O=`${h.format}-${p}`;if(b[O])b[O][H].inputNames.push(d);else{const A={dir:o,exports:"auto",format:h.format,sourcemap:D.sourcemap,entryFileNames:`[name]${p}`,chunkFileNames:`${c.distPrefix}[name]-[hash]${p}`,[H]:a};b.push(A),b[O]=A}}return Object.values(s)},"getRollupConfigs"),Hn=i(u=>{if(!u)return gn();const e=E.resolve(u),D=_e(e);return{path:e,config:D}},"getTsconfig"),Zn=i(async u=>{await yu(u)&&await I.promises.rm(u,{recursive:!0,force:!0})},"cleanDist"),Yn=/^[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*$/u,Qn=new Set(["do","if","in","for","int","new","try","var","byte","case","char","else","enum","goto","long","null","this","true","void","with","break","catch","class","const","false","final","float","short","super","throw","while","delete","double","export","import","native","public","return","static","switch","throws","typeof","boolean","default","extends","finally","package","private","abstract","continue","debugger","function","volatile","interface","protected","transient","implements","instanceof","synchronized"]),Xn=i(u=>!Yn.test(u)||Qn.has(u),"propertyNeedsQuotes"),ur=i(u=>u.map((e,D)=>typeof e=="number"?`[${e}]`:Xn(e)?`[${JSON.stringify(e)}]`:D>0?`.${e}`:e).join(""),"prettyPath"),er=i(u=>({name:"filter-unnecessary-outputs",generateBundle:i((e,D)=>{const t=Object.keys(D).filter(o=>D[o].type==="chunk"),n=[];for(const o of t){const s=D[o];s.isEntry&&u.includes(s.name)&&n.push(o)}const r=new Set;for(;n.length>0;){const o=n.shift(),s=D[o];if(!s||r.has(o))continue;r.add(o);const a=[...s.imports,...s.dynamicImports];for(const l of a)n.push(l)}for(const o of t)r.has(o)||delete D[o]},"generateBundle")}),"filterUnnecessaryOutputs"),{stringify:Je}=JSON,Ke=i(u=>{const[e,D]=u.split("=",2);return{key:e,value:D}},"keyValue"),T=OD({name:"pkgroll",version:SD,flags:{input:{type:[RD],alias:"i",description:"Dist paths for source files to bundle (Only use if you cannot use package.json entries)"},src:{type:String,description:"Source directory (Deprecated, use `srcdist` instead)",default:"./src"},dist:{type:String,description:"Distribution directory (Deprecated, use `srcdist` instead)",default:"./dist"},srcdist:{type:[String],description:"Source and distribution folder pairs (eg. default `src:dist`)"},minify:{type:Boolean,description:"Minify output",alias:"m",default:!1},target:{type:[String],default:[`node${process.versions.node}`],description:"Environments to support. `target` in tsconfig.json is automatically added. Defaults to the current Node.js version.",alias:"t"},tsconfig:{type:String,description:"Custom tsconfig.json file path",alias:"p"},watch:{type:Boolean,description:"Watch mode",alias:"w",default:!1},env:{type:[Ke],description:"Compile-time environment variables (eg. --env.NODE_ENV=production)"},define:{type:[Ke],description:"Targeted strings to replace (eg. --define.process.env.NODE_ENV='production')"},exportCondition:{type:[String],description:"Export conditions for resolving dependency export and import maps (eg. --export-condition=node)"},sourcemap:{type:i(u=>{if(u==="")return!0;if(u==="inline")return u;throw new Error(`Invalid sourcemap option ${Je(u)}`)},"type"),description:"Sourcemap generation. Provide `inline` option for inline sourcemap (eg. --sourcemap, --sourcemap=inline)"},cleanDist:{type:Boolean,description:"Clean dist before bundling",default:!1}},help:{description:"Minimalistic package bundler",render:i((u,e)=>(e.flagOperator=D=>D.name==="env"?".key=":" ",e.render(u)),"render")}}),Ge=process.cwd(),Y=[];if(T.flags.srcdist.length>0)for(const u of T.flags.srcdist){const[e,D]=u.split(":",2);if(!e||!D)throw new Error(`Invalid src:dist pair ${Je(u)}. Expected format: src:dist`);Y.push({src:$(e,!0),srcResolved:$(I.realpathSync.native(e),!0),dist:$(D,!0)})}else Y.push({src:$(T.flags.src,!0),srcResolved:$(I.realpathSync.native(T.flags.src),!0),dist:$(T.flags.dist,!0)});const He=Hn(T.flags.tsconfig),Ze=He?.config.compilerOptions?.target;Ze&&T.flags.target.push(Ze),(async()=>{const{packageJson:u}=await ND(Ge),e=await HD(Y,u,T.flags.input);for(const n of e)if("error"in n){const{exportEntry:r}=n,o=typeof r.source=="string"?r.source:`${r.source.type}#${ur(r.source.path)}`;console.warn(`Warning (${o}):`,n.error)}const D=e.filter(n=>!("error"in n));if(D.length===0)throw new Error("No entry points found");const t=await Gn(Y,D,T.flags,MD(u,Ge),u,He);T.flags.cleanDist&&await Promise.all(Y.map(({dist:n})=>Zn(n))),T.flags.watch?(ou("Watch initialized"),t.map(async n=>{Xe(n).on("event",async o=>{if(o.code==="BUNDLE_START"){const s=Array.isArray(o.input)?o.input:Object.values(o.input);ou("Building",...s.map(Au))}if(o.code==="BUNDLE_END"){await Promise.all(n.output.map(a=>o.result.write(a)));const s=Array.isArray(o.input)?o.input:Object.values(o.input);ou("Built",...s.map(Au))}o.code==="ERROR"&&ou("Error:",o.error.message)})})):await Promise.all(t.map(async n=>{const r=await ut(n);return Promise.all(n.output.map(o=>{const s=o[H].inputNames;return o.plugins=[er(s)],r.write(o)}))}))})().catch(u=>{console.error(u),process.exit(1)});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var ce=Object.defineProperty;var m=(n,e)=>ce(n,"name",{value:e,configurable:!0});import{createRequire as le}from"node:module";const pe=le(import.meta.url);import*as x from"node:path";import i from"typescript";import{createRequire as fe}from"node:module";import j from"magic-string";function me(n){return{...n,compilerOptions:n.compilerOptions??{},respectExternal:n.respectExternal??!1,includeExternal:n.includeExternal??[]}}m(me,"resolveDefaultOptions");const k=/\.d\.(c|m)?tsx?$/,_=/\.json$/,X=/((\.d)?\.(c|m)?(t|j)sx?|\.json)$/;function z(n){return n.replace(X,"")}m(z,"trimExtension");function J(n){return n.replace(X,".d.ts")}m(J,"getDeclarationId");function L(n,e){return i.createSourceFile(n,e,i.ScriptTarget.Latest,!0)}m(L,"parse");const V={getCurrentDirectory:m(()=>i.sys.getCurrentDirectory(),"getCurrentDirectory"),getNewLine:m(()=>i.sys.newLine,"getNewLine"),getCanonicalFileName:i.sys.useCaseSensitiveFileNames?n=>n:n=>n.toLowerCase()},ue={declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!0,target:i.ScriptTarget.ESNext,resolveJsonModule:!0},K=new Map,R=m((...n)=>process.env.DTS_LOG_CACHE?console.log("[cache]",...n):null,"logCache");function Q([n,e],t){for(R(n),K.set(n,t);n!==e&&n!==x.dirname(n);){if(n=x.dirname(n),R("up",n),K.has(n))return R("has",n);K.set(n,t)}}m(Q,"cacheConfig");function U(n,e,t){const s={...ue,...e};let r=x.dirname(n),a=[];const c=t||r;if(K.has(c))R("HIT",c);else{R("miss",c);const f=t?x.resolve(process.cwd(),t):i.findConfigFile(r,i.sys.fileExists);if(!f)return{dtsFiles:a,dirName:r,compilerOptions:s};const h=r;r=x.dirname(f);const{config:T,error:D}=i.readConfigFile(f,i.sys.readFile);if(D)return console.error(i.formatDiagnostic(D,V)),{dtsFiles:a,dirName:r,compilerOptions:s};R("tsconfig",T);const I=i.parseJsonConfigFileContent(T,i.sys,r);Q(t?[t,t]:[h,r],I)}const{fileNames:p,options:u,errors:l}=K.get(c);return a=p.filter(f=>k.test(f)),l.length?(console.error(i.formatDiagnostics(l,V)),{dtsFiles:a,dirName:r,compilerOptions:s}):{dtsFiles:a,dirName:r,compilerOptions:{...u,...s}}}m(U,"getCompilerOptions");function de(n,e,t){const{dtsFiles:s,compilerOptions:r}=U(n,e,t);return i.createProgram([n].concat(Array.from(s)),r,i.createCompilerHost(r,!0))}m(de,"createProgram$1");function he(n,e,t){const s=[],r=new Set;let a=[],c="",p={};for(let u of n){if(k.test(u))continue;u=x.resolve(u);const l=U(u,e,t);if(l.dtsFiles.forEach(r.add,r),!a.length){a.push(u),{dirName:c,compilerOptions:p}=l;continue}if(l.dirName===c)a.push(u);else{const f=i.createCompilerHost(p,!0),h=i.createProgram(a.concat(Array.from(r)),p,f);s.push(h),a=[u],{dirName:c,compilerOptions:p}=l}}if(a.length){const u=i.createCompilerHost(p,!0),l=i.createProgram(a.concat(Array.from(r)),p,u);s.push(l)}return s}m(he,"createPrograms");function ye(){let n;try{return{codeFrameColumns:n}=pe("@babel/code-frame"),n}catch{try{return{codeFrameColumns:n}=fe(import.meta.url)("@babel/code-frame"),n}catch{}}}m(ye,"getCodeFrame");function ge(n){const e=n.getSourceFile(),t=e.getLineAndCharacterOfPosition(n.getStart()),s=e.getLineAndCharacterOfPosition(n.getEnd());return{start:{line:t.line+1,column:t.character+1},end:{line:s.line+1,column:s.character+1}}}m(ge,"getLocation");function xe(n){const e=ye(),s=n.getSourceFile().getFullText(),r=ge(n);return e?`
|
|
2
|
+
`+e(s,r,{highlightCode:!0}):`
|
|
3
|
+
${r.start.line}:${r.start.column}: \`${n.getFullText().trim()}\``}m(xe,"frameNode");class g extends Error{static{m(this,"UnsupportedSyntaxError")}constructor(e,t="Syntax not yet supported"){super(`${t}
|
|
4
|
+
${xe(e)}`)}}class Se{static{m(this,"NamespaceFixer")}constructor(e){this.sourceFile=e}findNamespaces(){const e=[],t={};for(const s of this.sourceFile.statements){const r={start:s.getStart(),end:s.getEnd()};if(i.isEmptyStatement(s)){e.unshift({name:"",exports:[],location:r});continue}if((i.isImportDeclaration(s)||i.isExportDeclaration(s))&&s.moduleSpecifier&&i.isStringLiteral(s.moduleSpecifier)){const{text:f}=s.moduleSpecifier;if(f.startsWith(".")&&(f.endsWith(".d.ts")||f.endsWith(".d.cts")||f.endsWith(".d.mts"))){const h=s.moduleSpecifier.getStart()+1,T=s.moduleSpecifier.getEnd()-1;e.unshift({name:"",exports:[],location:{start:h,end:T},textBeforeCodeAfter:f.replace(/\.d\.ts$/,".js").replace(/\.d\.cts$/,".cjs").replace(/\.d\.mts$/,".mjs")})}}if(i.isModuleDeclaration(s)&&s.body&&i.isModuleBlock(s.body)){for(const f of s.body.statements)if(i.isExportDeclaration(f)&&f.exportClause){if(i.isNamespaceExport(f.exportClause))continue;for(const h of f.exportClause.elements)h.propertyName&&h.propertyName.getText()==h.name.getText()&&e.unshift({name:"",exports:[],location:{start:h.propertyName.getEnd(),end:h.name.getEnd()}})}}if(i.isClassDeclaration(s)?t[s.name.getText()]={type:"class",generics:s.typeParameters}:i.isFunctionDeclaration(s)?t[s.name.getText()]={type:"function"}:i.isInterfaceDeclaration(s)?t[s.name.getText()]={type:"interface",generics:s.typeParameters}:i.isTypeAliasDeclaration(s)?t[s.name.getText()]={type:"type",generics:s.typeParameters}:i.isModuleDeclaration(s)&&i.isIdentifier(s.name)?t[s.name.getText()]={type:"namespace"}:i.isEnumDeclaration(s)&&(t[s.name.getText()]={type:"enum"}),!i.isVariableStatement(s))continue;const{declarations:a}=s.declarationList;if(a.length!==1)continue;const c=a[0],p=c.name.getText();if(!c.initializer||!i.isCallExpression(c.initializer)){t[p]={type:"var"};continue}const u=c.initializer.arguments[0];if(!c.initializer.expression.getFullText().includes("/*#__PURE__*/Object.freeze")||!i.isObjectLiteralExpression(u))continue;const l=[];for(const f of u.properties){if(!i.isPropertyAssignment(f)||!(i.isIdentifier(f.name)||i.isStringLiteral(f.name))||f.name.text!=="__proto__"&&!i.isIdentifier(f.initializer))throw new g(f,"Expected a property assignment");f.name.text!=="__proto__"&&l.push({exportedName:f.name.text,localName:f.initializer.getText()})}e.unshift({name:p,exports:l,location:r})}return{namespaces:e,itemTypes:t}}fix(){let e=this.sourceFile.getFullText();const{namespaces:t,itemTypes:s}=this.findNamespaces();for(const r of t){const a=e.slice(r.location.end);e=e.slice(0,r.location.start);for(const{exportedName:c,localName:p}of r.exports)if(c===p){const{type:u,generics:l}=s[p]||{};if(u==="interface"||u==="type"){const f=Y(l);e+=`type ${r.name}_${c}${f.in} = ${p}${f.out};
|
|
5
|
+
`}else if(u==="enum"||u==="class"){const f=Y(l);e+=`type ${r.name}_${c}${f.in} = ${p}${f.out};
|
|
6
|
+
`,e+=`declare const ${r.name}_${c}: typeof ${p};
|
|
7
|
+
`}else u==="namespace"?e+=`import ${r.name}_${c} = ${p};
|
|
8
|
+
`:e+=`declare const ${r.name}_${c}: typeof ${p};
|
|
9
|
+
`}if(r.name){e+=`declare namespace ${r.name} {
|
|
10
|
+
`,e+=` export {
|
|
11
|
+
`;for(const{exportedName:c,localName:p}of r.exports)c===p?e+=` ${r.name}_${c} as ${c},
|
|
12
|
+
`:e+=` ${p} as ${c},
|
|
13
|
+
`;e+=` };
|
|
14
|
+
`,e+="}"}e+=r.textBeforeCodeAfter??"",e+=a}return e}}function Y(n){return!n||!n.length?{in:"",out:""}:{in:`<${n.map(e=>e.getText()).join(", ")}>`,out:`<${n.map(e=>e.name.getText()).join(", ")}>`}}m(Y,"renderTypeParams");let Z=1;function Ee(n){return E({type:"Program",sourceType:"module",body:[]},{start:n.getFullStart(),end:n.getEnd()})}m(Ee,"createProgram");function ve(n){const e={type:"Identifier",name:String(Z++)};return{ident:e,expr:{type:"AssignmentPattern",left:e,right:n}}}m(ve,"createReference");function v(n){return E({type:"Identifier",name:n.getText()},n)}m(v,"createIdentifier");function Te(n){const e=E({type:"FunctionExpression",id:null,params:[],body:{type:"BlockStatement",body:[]}},n),t=E({type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:String(Z++)},arguments:[e],optional:!1}},n);return{fn:e,iife:t}}m(Te,"createIIFE");function Ne(){const n={type:"ArrayExpression",elements:[]};return{expr:n,stmt:{type:"ReturnStatement",argument:n}}}m(Ne,"createReturn");function De(n,e){return E({type:"FunctionDeclaration",id:E({type:"Identifier",name:i.idText(n)},n),params:[],body:{type:"BlockStatement",body:[]}},e)}m(De,"createDeclaration");function w(n){if(i.isLiteralExpression(n))return{type:"Literal",value:n.text};if(i.isPropertyAccessExpression(n)){if(i.isPrivateIdentifier(n.name))throw new g(n.name);return E({type:"MemberExpression",computed:!1,optional:!1,object:w(n.expression),property:w(n.name)},{start:n.expression.getStart(),end:n.name.getEnd()})}if(i.isObjectLiteralExpression(n))return E({type:"ObjectExpression",properties:n.properties.map(e=>{if(i.isPropertyAssignment(e))return E({type:"Property",key:i.isIdentifier(e.name)?v(e.name):w(e.name),value:w(e.initializer),kind:"init",method:!1,shorthand:!1,computed:i.isComputedPropertyName(e.name)},e);if(i.isShorthandPropertyAssignment(e))return E({type:"Property",key:v(e.name),value:v(e.name),kind:"init",method:!1,shorthand:!0,computed:!1},e);throw new g(e,"Unsupported property type in object literal")})},n);if(i.isArrayLiteralExpression(n))return E({type:"ArrayExpression",elements:n.elements.map(e=>{if(i.isExpression(e))return w(e);throw new g(e,"Unsupported element type in array literal")})},n);if(i.isIdentifier(n))return v(n);if(n.kind==i.SyntaxKind.NullKeyword)return{type:"Literal",value:null};throw new g(n)}m(w,"convertExpression");function E(n,e){const t="start"in e?e:{start:e.getStart(),end:e.getEnd()};return Object.assign(n,t)}m(E,"withStartEnd");function B(n,e){return(i.getCombinedModifierFlags(n)&e)===e}m(B,"matchesModifier");class Ie{static{m(this,"LanguageService")}constructor(e){this.fileName="index.d.ts";const t={getCompilationSettings:m(()=>({noEmit:!0,noResolve:!0,skipLibCheck:!0,declaration:!1,checkJs:!1,declarationMap:!1,target:i.ScriptTarget.ESNext}),"getCompilationSettings"),getScriptFileNames:m(()=>[this.fileName],"getScriptFileNames"),getScriptVersion:m(()=>"1","getScriptVersion"),getScriptSnapshot:m(s=>s===this.fileName?i.ScriptSnapshot.fromString(e):void 0,"getScriptSnapshot"),getCurrentDirectory:m(()=>"","getCurrentDirectory"),getDefaultLibFileName:m(()=>"","getDefaultLibFileName"),fileExists:m(s=>s===this.fileName,"fileExists"),readFile:m(s=>s===this.fileName?e:void 0,"readFile")};this.service=i.createLanguageService(t,i.createDocumentRegistry(void 0,""),i.LanguageServiceMode.PartialSemantic)}findReferenceCount(e){const t=this.service.findReferences(this.fileName,e.getStart());return t?.length?t.reduce((s,r)=>s+r.references.length,0):0}}class be{static{m(this,"TypeOnlyFixer")}constructor(e,t){this.DEBUG=!!process.env.DTS_EXPORTS_FIXER_DEBUG,this.types=new Set,this.values=new Set,this.typeHints=new Map,this.reExportTypeHints=new Map,this.importNodes=[],this.exportNodes=[],this.rawCode=t,this.source=L(e,t),this.code=new j(t)}fix(){return this.analyze(this.source.statements),(this.typeHints.size||this.reExportTypeHints.size)&&(this.service=new Ie(this.rawCode),this.importNodes.forEach(e=>this.fixTypeOnlyImport(e))),this.types.size&&this.exportNodes.forEach(e=>this.fixTypeOnlyExport(e)),this.types.size?{magicCode:this.code}:{code:this.rawCode,map:null}}fixTypeOnlyImport(e){let t=!1;const s=[],r=[],a=e.moduleSpecifier.getText(),c=e.importClause.name,p=e.importClause.namedBindings;if(c){const u=c.text;this.isTypeOnly(u)?this.isUselessImport(c)?t=!0:s.push(`import type ${u} from ${a};`):r.push(`import ${u} from ${a};`)}if(p&&i.isNamespaceImport(p)){const u=p.name.text;this.isTypeOnly(u)?this.isUselessImport(p.name)?t=!0:s.push(`import type * as ${u} from ${a};`):r.push(`import * as ${u} from ${a};`)}if(p&&i.isNamedImports(p)){const u=[],l=[];for(const f of p.elements)this.isTypeOnly(f.name.text)?this.isUselessImport(f.name)?t=!0:u.push(f.getText()):l.push(f.getText());u.length&&s.push(`import type { ${u.join(", ")} } from ${a};`),l.length&&r.push(`import { ${l.join(", ")} } from ${a};`)}(s.length||t)&&this.code.overwrite(e.getStart(),e.getEnd(),[...r,...s].join(`
|
|
15
|
+
${ee(e)}`))}fixTypeOnlyExport(e){const t=[],s=[],r=e.moduleSpecifier?.getText();if(i.isNamespaceExport(e.exportClause)){const a=e.exportClause.name.text;this.isReExportTypeOnly(a)?t.push(`export type * as ${a} from ${r};`):s.push(`export * as ${a} from ${r};`)}if(i.isNamedExports(e.exportClause)){const a=[],c=[];for(const p of e.exportClause.elements){const u=p.propertyName?.text||p.name.text;(e.moduleSpecifier?this.isReExportTypeOnly(p.name.text):this.isTypeOnly(u))?a.push(p.getText()):c.push(p.getText())}a.length&&t.push(`export type { ${a.join(", ")} }${r?` from ${r}`:""};`),c.length&&s.push(`export { ${c.join(", ")} }${r?` from ${r}`:""};`)}t.length&&this.code.overwrite(e.getStart(),e.getEnd(),[...s,...t].join(`
|
|
16
|
+
${ee(e)}`))}analyze(e){for(const t of e){if(this.DEBUG&&console.log(t.getText(),t.kind),i.isImportDeclaration(t)&&t.importClause){this.importNodes.push(t);continue}if(i.isExportDeclaration(t)&&t.exportClause){this.exportNodes.push(t);continue}if(i.isInterfaceDeclaration(t)){this.DEBUG&&console.log(`${t.name.getFullText()} is a type`),this.types.add(t.name.text);continue}if(i.isTypeAliasDeclaration(t)){const s=t.name.text;this.DEBUG&&console.log(`${t.name.getFullText()} is a type`),this.types.add(s);continue}if(i.isEnumDeclaration(t)||i.isFunctionDeclaration(t)||i.isClassDeclaration(t)||i.isVariableStatement(t)){if(i.isVariableStatement(t))for(const s of t.declarationList.declarations)i.isIdentifier(s.name)&&(this.DEBUG&&console.log(`${s.name.getFullText()} is a value (from var statement)`),this.values.add(s.name.text));else t.name&&(this.DEBUG&&console.log(`${t.name.getFullText()} is a value (from declaration)`),this.values.add(t.name.text));continue}if(i.isModuleBlock(t)){this.analyze(t.statements);continue}if(i.isModuleDeclaration(t)){t.name&&i.isIdentifier(t.name)&&(this.DEBUG&&console.log(`${t.name.getFullText()} is a value (from module declaration)`),this.values.add(t.name.text)),this.analyze(t.getChildren());continue}this.DEBUG&&console.log("unhandled statement",t.getFullText(),t.kind)}}isUselessImport(e){const t=this.service.findReferenceCount(e),s=this.typeHints.get(e.text);return s&&s+1>=t}isTypeOnly(e){return this.typeHints.has(e)||this.types.has(e)&&!this.values.has(e)}isReExportTypeOnly(e){return this.reExportTypeHints.has(e)}}function ee(n){const e=n.getFullText().match(/^(?:\n*)([ ]*)/);return" ".repeat(e?.[1]?.length||0)}m(ee,"getNodeIndent");function te(n,e,t){for(const s of n.statements)G(e,s),i.isModuleDeclaration(s)&&ie(e,s),i.isModuleDeclaration(s)&&s.body&&i.isModuleBlock(s.body)&&te(s.body,e)}m(te,"preProcessNamespaceBody");function Ce({sourceFile:n,isEntry:e,isJSON:t}){const s=new j(n.getFullText()),r=!e&&we(n),a=new Set,c=new Set;let p="";const u=new Map,l=new Map;for(const o of n.statements){if(i.isEmptyStatement(o)){s.remove(o.getStart(),o.getEnd());continue}if(i.isImportDeclaration(o)){if(!o.importClause)continue;o.importClause.name&&a.add(o.importClause.name.text),o.importClause.namedBindings&&(i.isNamespaceImport(o.importClause.namedBindings)?a.add(o.importClause.namedBindings.name.text):o.importClause.namedBindings.elements.forEach(d=>a.add(d.name.text)))}else if(i.isEnumDeclaration(o)||i.isFunctionDeclaration(o)||i.isInterfaceDeclaration(o)||i.isClassDeclaration(o)||i.isTypeAliasDeclaration(o)||i.isModuleDeclaration(o)){if(o.name){const d=o.name.getText();a.add(d),B(o,i.ModifierFlags.ExportDefault)?p=d:(r&&i.isIdentifier(o.name)||B(o,i.ModifierFlags.Export))&&c.add(d),o.flags&i.NodeFlags.GlobalAugmentation||O(d,[H(o),se(o)])}i.isModuleDeclaration(o)&&(o.body&&i.isModuleBlock(o.body)&&te(o.body,s),ie(s,o)),G(s,o)}else if(i.isVariableStatement(o)){const{declarations:d}=o.declarationList,S=B(o,i.ModifierFlags.Export);for(const N of o.declarationList.declarations)if(i.isIdentifier(N.name)){const C=N.name.getText();a.add(C),(r||S)&&c.add(C)}if(G(s,o),d.length===1){const N=d[0];i.isIdentifier(N.name)&&O(N.name.getText(),[H(o),se(o)])}else{const N=d.slice(),C=N.shift();O(C.name.getText(),[H(o),C.getEnd()]);for(const M of N)i.isIdentifier(M.name)&&O(M.name.getText(),[M.getFullStart(),M.getEnd()])}const{flags:y}=o.declarationList,P=`declare ${y&i.NodeFlags.Let?"let":y&i.NodeFlags.Const?"const":"var"} `,A=o.declarationList.getChildren().find(N=>N.kind===i.SyntaxKind.SyntaxList).getChildren();let F=0;for(const N of A)if(N.kind===i.SyntaxKind.CommaToken)F=N.getStart(),s.remove(F,N.getEnd());else if(F){s.appendLeft(F,`;
|
|
17
|
+
`);const C=N.getFullStart(),M=s.slice(C,N.getStart()),W=M.length-M.trimStart().length;W?s.overwrite(C,C+W,P):s.appendLeft(C,P)}}}for(const o of n.statements){if(D(o),i.isExportAssignment(o)&&!o.isExportEquals&&(i.isObjectLiteralExpression(o.expression)||i.isArrayLiteralExpression(o.expression))){p||(p=b("export_default")),s.overwrite(o.getStart(),o.expression.getStart(),`declare var ${p} = `);continue}if(B(o,i.ModifierFlags.ExportDefault)&&(i.isFunctionDeclaration(o)||i.isClassDeclaration(o))){if(o.name)continue;p||(p=b("export_default"));const d=o.getChildren(),S=d.findIndex(A=>A.kind===i.SyntaxKind.ClassKeyword||A.kind===i.SyntaxKind.FunctionKeyword),y=d[S],$=d[S+1];if($.kind>=i.SyntaxKind.FirstPunctuation&&$.kind<=i.SyntaxKind.LastPunctuation){const A=s.slice(y.getEnd(),$.getStart())!=" ";s.appendLeft($.getStart(),`${A?" ":""}${p}`)}else s.appendRight(y.getEnd(),` ${p}`)}}for(const o of l.values()){const S=o.pop()[0];for(const y of o)s.move(y[0],y[1],S)}p&&s.append(`
|
|
18
|
+
export default ${p};
|
|
19
|
+
`),c.size&&s.append(`
|
|
20
|
+
export { ${[...c].join(", ")} };
|
|
21
|
+
`),t&&c.size&&(p=b("export_default"),s.append([`
|
|
22
|
+
declare const ${p}: {`,[...c].map(o=>` ${o}: typeof ${o};`).join(`
|
|
23
|
+
`),"};",`export default ${p};
|
|
24
|
+
`].join(`
|
|
25
|
+
`)));for(const[o,d]of u.entries())s.prepend(`import * as ${d} from "${o}";
|
|
26
|
+
`);const f=n.getLineStarts(),h=new Set;for(const o of n.typeReferenceDirectives){h.add(o.fileName);const{line:d}=n.getLineAndCharacterOfPosition(o.pos),S=f[d];let y=n.getLineEndOfPosition(o.pos);s.slice(y,y+1)===`
|
|
27
|
+
`&&(y+=1),s.remove(S,y)}const T=new Set;for(const o of n.referencedFiles){T.add(o.fileName);const{line:d}=n.getLineAndCharacterOfPosition(o.pos),S=f[d];let y=n.getLineEndOfPosition(o.pos);s.slice(y,y+1)===`
|
|
28
|
+
`&&(y+=1),s.remove(S,y)}return{code:s,typeReferences:h,fileReferences:T};function D(o){if(i.forEachChild(o,D),i.isImportTypeNode(o)){if(!i.isLiteralTypeNode(o.argument)||!i.isStringLiteral(o.argument.literal))throw new g(o,"inline imports should have a literal argument");const d=o.argument.literal.text,S=o.getChildren(),y=S.find(F=>F.kind===i.SyntaxKind.ImportKeyword).getStart();let $=o.getEnd();const P=S.find(F=>F.kind===i.SyntaxKind.DotToken||F.kind===i.SyntaxKind.LessThanToken);P&&($=P.getStart());const A=I(d);s.overwrite(y,$,A)}}function I(o){let d=u.get(o);return d||(d=b(Fe(o)),u.set(o,d)),d}function b(o){let d=o;for(;a.has(d);)d=`_${d}`;return a.add(d),d}function O(o,d){let S=l.get(o);if(!S)S=[d],l.set(o,S);else{const y=S[S.length-1];y[1]===d[0]?y[1]=d[1]:S.push(d)}}}m(Ce,"preProcess");function we(n){let e=!1;for(const t of n.statements){if(i.isExportDeclaration(t)||i.isExportAssignment(t))return!1;(e||i.isImportDeclaration(t)||B(t,i.ModifierFlags.Export))&&(e=!0)}return e}m(we,"isGlobalModule");function G(n,e){if(!i.canHaveModifiers(e))return;if(e.parent.kind===i.SyntaxKind.SourceFile){let s=!1;const r=i.isEnumDeclaration(e)||i.isClassDeclaration(e)||i.isFunctionDeclaration(e)||i.isModuleDeclaration(e)||i.isVariableStatement(e);for(const a of e.modifiers??[])switch(a.kind){case i.SyntaxKind.ExportKeyword:case i.SyntaxKind.DefaultKeyword:n.remove(a.getStart(),a.getEnd()+1);break;case i.SyntaxKind.DeclareKeyword:s=!0}r&&!s&&n.appendRight(e.getStart(),"declare ")}else if(i.isModuleDeclaration(e)){const s=e.modifiers?.find(r=>r.kind===i.SyntaxKind.ExportKeyword);s&&n.remove(s.getStart(),s.getEnd()+1)}}m(G,"fixModifiers");function ie(n,e){if(!(!e.body||!i.isModuleBlock(e.body))){for(const t of e.body.statements)if(i.isExportDeclaration(t)&&t.exportClause){if(i.isNamespaceExport(t.exportClause))continue;for(const s of t.exportClause.elements)s.propertyName||n.appendLeft(s.name.getEnd(),` as ${s.name.getText()}`)}}}m(ie,"duplicateExports");function Fe(n){return n.replace(/[^a-zA-Z0-9_$]/g,()=>"_")}m(Fe,"getSafeName");function H(n){const e=n.getFullStart();return e+(re(n,e)?1:0)}m(H,"getStart");function se(n){const e=n.getEnd();return e+(re(n,e)?1:0)}m(se,"getEnd");function re(n,e){return n.getSourceFile().getFullText()[e]===`
|
|
29
|
+
`}m(re,"newlineAt");const $e=new Set([i.SyntaxKind.LiteralType,i.SyntaxKind.VoidKeyword,i.SyntaxKind.UnknownKeyword,i.SyntaxKind.AnyKeyword,i.SyntaxKind.BooleanKeyword,i.SyntaxKind.NumberKeyword,i.SyntaxKind.StringKeyword,i.SyntaxKind.ObjectKeyword,i.SyntaxKind.NullKeyword,i.SyntaxKind.UndefinedKeyword,i.SyntaxKind.SymbolKeyword,i.SyntaxKind.NeverKeyword,i.SyntaxKind.ThisKeyword,i.SyntaxKind.ThisType,i.SyntaxKind.BigIntKeyword]);class ne{static{m(this,"DeclarationScope")}constructor({id:e,range:t}){if(this.scopes=[],e)this.declaration=De(e,t);else{const{iife:r,fn:a}=Te(t);this.iife=r,this.declaration=a}const s=Ne();this.declaration.body.body.push(s.stmt),this.returnExpr=s.expr}pushScope(){this.scopes.push(new Set)}popScope(e=1){for(let t=0;t<e;t++)this.scopes.pop()}pushTypeVariable(e){const t=e.getText();this.scopes[this.scopes.length-1]?.add(t)}pushReference(e){let t;if(e.type==="Identifier"?t=e.name:e.type==="MemberExpression"&&e.object.type==="Identifier"&&(t=e.object.name),t){for(const a of this.scopes)if(a.has(t))return}if(t==="this")return;const{ident:s,expr:r}=ve(e);this.declaration.params.push(r),this.returnExpr.elements.push(s)}pushIdentifierReference(e){this.pushReference(v(e))}convertEntityName(e){return i.isIdentifier(e)?v(e):E({type:"MemberExpression",computed:!1,optional:!1,object:this.convertEntityName(e.left),property:v(e.right)},e)}convertPropertyAccess(e){if(!i.isIdentifier(e.expression)&&!i.isPropertyAccessExpression(e.expression))throw new g(e.expression);if(i.isPrivateIdentifier(e.name))throw new g(e.name);const t=i.isIdentifier(e.expression)?v(e.expression):this.convertPropertyAccess(e.expression);return E({type:"MemberExpression",computed:!1,optional:!1,object:t,property:v(e.name)},e)}convertComputedPropertyName(e){if(!e.name||!i.isComputedPropertyName(e.name))return;const{expression:t}=e.name;if(!(i.isLiteralExpression(t)||i.isPrefixUnaryExpression(t))){if(i.isIdentifier(t))return this.pushReference(v(t));if(i.isPropertyAccessExpression(t))return this.pushReference(this.convertPropertyAccess(t));throw new g(t)}}convertParametersAndType(e){this.convertComputedPropertyName(e);const t=this.convertTypeParameters(e.typeParameters);for(const s of e.parameters)this.convertTypeNode(s.type);this.convertTypeNode(e.type),this.popScope(t)}convertHeritageClauses(e){for(const t of e.heritageClauses||[])for(const s of t.types)this.pushReference(w(s.expression)),this.convertTypeArguments(s)}convertTypeArguments(e){if(e.typeArguments)for(const t of e.typeArguments)this.convertTypeNode(t)}convertMembers(e){for(const t of e){if(i.isPropertyDeclaration(t)||i.isPropertySignature(t)||i.isIndexSignatureDeclaration(t)){i.isPropertyDeclaration(t)&&t.initializer&&i.isPropertyAccessExpression(t.initializer)&&this.pushReference(this.convertPropertyAccess(t.initializer)),this.convertComputedPropertyName(t),this.convertTypeNode(t.type);continue}if(i.isMethodDeclaration(t)||i.isMethodSignature(t)||i.isConstructorDeclaration(t)||i.isConstructSignatureDeclaration(t)||i.isCallSignatureDeclaration(t)||i.isGetAccessorDeclaration(t)||i.isSetAccessorDeclaration(t))this.convertParametersAndType(t);else throw new g(t)}}convertTypeParameters(e){if(!e)return 0;for(const t of e)this.convertTypeNode(t.constraint),this.convertTypeNode(t.default),this.pushScope(),this.pushTypeVariable(t.name);return e.length}convertTypeNode(e){if(e&&!$e.has(e.kind)){if(i.isTypeReferenceNode(e)){this.pushReference(this.convertEntityName(e.typeName)),this.convertTypeArguments(e);return}if(i.isTypeLiteralNode(e)){this.convertMembers(e.members);return}if(i.isArrayTypeNode(e)){this.convertTypeNode(e.elementType);return}if(i.isTupleTypeNode(e)){for(const t of e.elements)this.convertTypeNode(t);return}if(i.isNamedTupleMember(e)||i.isParenthesizedTypeNode(e)||i.isTypeOperatorNode(e)||i.isTypePredicateNode(e)){this.convertTypeNode(e.type);return}if(i.isUnionTypeNode(e)||i.isIntersectionTypeNode(e)){for(const t of e.types)this.convertTypeNode(t);return}if(i.isMappedTypeNode(e)){const{typeParameter:t,type:s,nameType:r}=e;this.convertTypeNode(t.constraint),this.pushScope(),this.pushTypeVariable(t.name),this.convertTypeNode(s),r&&this.convertTypeNode(r),this.popScope();return}if(i.isConditionalTypeNode(e)){this.convertTypeNode(e.checkType),this.pushScope(),this.convertTypeNode(e.extendsType),this.convertTypeNode(e.trueType),this.convertTypeNode(e.falseType),this.popScope();return}if(i.isIndexedAccessTypeNode(e)){this.convertTypeNode(e.objectType),this.convertTypeNode(e.indexType);return}if(i.isFunctionOrConstructorTypeNode(e)){this.convertParametersAndType(e);return}if(i.isTypeQueryNode(e)){const t=this.convertEntityName(e.exprName);this.pushReference(t),this.convertTypeArguments(e);return}if(i.isRestTypeNode(e)){this.convertTypeNode(e.type);return}if(i.isOptionalTypeNode(e)){this.convertTypeNode(e.type);return}if(i.isTemplateLiteralTypeNode(e)){for(const t of e.templateSpans)this.convertTypeNode(t.type);return}if(i.isInferTypeNode(e)){const{typeParameter:t}=e;this.convertTypeNode(t.constraint),this.pushTypeVariable(t.name);return}else throw new g(e)}}convertNamespace(e,t=!1){if(this.pushScope(),t&&e.body&&i.isModuleDeclaration(e.body)){this.convertNamespace(e.body,!0);return}if(!e.body||!i.isModuleBlock(e.body))throw new g(e,'namespace must have a "ModuleBlock" body.');const{statements:s}=e.body;for(const r of s){if(i.isEnumDeclaration(r)||i.isFunctionDeclaration(r)||i.isClassDeclaration(r)||i.isInterfaceDeclaration(r)||i.isTypeAliasDeclaration(r)||i.isModuleDeclaration(r)){if(r.name&&i.isIdentifier(r.name))this.pushTypeVariable(r.name);else throw new g(r,"non-Identifier name not supported");continue}if(i.isVariableStatement(r)){for(const a of r.declarationList.declarations)if(i.isIdentifier(a.name))this.pushTypeVariable(a.name);else throw new g(a,"non-Identifier name not supported");continue}if(i.isImportDeclaration(r)){if(r.importClause&&(r.importClause.name&&this.pushTypeVariable(r.importClause.name),r.importClause.namedBindings))if(i.isNamespaceImport(r.importClause.namedBindings))this.pushTypeVariable(r.importClause.namedBindings.name);else for(const a of r.importClause.namedBindings.elements)this.pushTypeVariable(a.name);continue}if(i.isImportEqualsDeclaration(r)){this.pushTypeVariable(r.name);continue}if(!i.isExportDeclaration(r))throw new g(r,"namespace child (hoisting) not supported yet")}for(const r of s){if(i.isVariableStatement(r)){for(const a of r.declarationList.declarations)a.type&&this.convertTypeNode(a.type);continue}if(i.isFunctionDeclaration(r)){this.convertParametersAndType(r);continue}if(i.isInterfaceDeclaration(r)||i.isClassDeclaration(r)){const a=this.convertTypeParameters(r.typeParameters);this.convertHeritageClauses(r),this.convertMembers(r.members),this.popScope(a);continue}if(i.isTypeAliasDeclaration(r)){const a=this.convertTypeParameters(r.typeParameters);this.convertTypeNode(r.type),this.popScope(a);continue}if(i.isModuleDeclaration(r)){this.convertNamespace(r,t);continue}if(!i.isEnumDeclaration(r)&&!i.isImportDeclaration(r)){if(i.isImportEqualsDeclaration(r)){i.isEntityName(r.moduleReference)&&this.pushReference(this.convertEntityName(r.moduleReference));continue}if(i.isExportDeclaration(r)){if(r.exportClause){if(i.isNamespaceExport(r.exportClause))throw new g(r.exportClause);for(const a of r.exportClause.elements){const c=a.propertyName||a.name;this.pushIdentifierReference(c)}}}else throw new g(r,"namespace child (walking) not supported yet")}}this.popScope()}}function Ae({sourceFile:n}){return new Me(n).transform()}m(Ae,"convert");class Me{static{m(this,"Transformer")}constructor(e){this.sourceFile=e,this.declarations=new Map,this.ast=Ee(e);for(const t of e.statements)this.convertStatement(t)}transform(){return{ast:this.ast}}pushStatement(e){this.ast.body.push(e)}createDeclaration(e,t){const s={start:e.getFullStart(),end:e.getEnd()};if(!t){const p=new ne({range:s});return this.pushStatement(p.iife),p}const r=t.getText(),a=new ne({id:t,range:s}),c=this.declarations.get(r);if(c){c.pushIdentifierReference(t),c.declaration.end=s.end;const p=this.ast.body.findIndex(u=>u==c.declaration);for(let u=p+1;u<this.ast.body.length;u++){const l=this.ast.body[u];l.start=l.end=s.end}}else this.pushStatement(a.declaration),this.declarations.set(r,a);return c||a}convertStatement(e){if(i.isEnumDeclaration(e))return this.convertEnumDeclaration(e);if(i.isFunctionDeclaration(e))return this.convertFunctionDeclaration(e);if(i.isInterfaceDeclaration(e)||i.isClassDeclaration(e))return this.convertClassOrInterfaceDeclaration(e);if(i.isTypeAliasDeclaration(e))return this.convertTypeAliasDeclaration(e);if(i.isVariableStatement(e))return this.convertVariableStatement(e);if(i.isExportDeclaration(e)||i.isExportAssignment(e))return this.convertExportDeclaration(e);if(i.isModuleDeclaration(e))return this.convertNamespaceDeclaration(e);if(e.kind===i.SyntaxKind.NamespaceExportDeclaration)return this.removeStatement(e);if(i.isImportDeclaration(e)||i.isImportEqualsDeclaration(e))return this.convertImportDeclaration(e);throw new g(e)}removeStatement(e){this.pushStatement(E({type:"ExpressionStatement",expression:{type:"Literal",value:"pls remove me"}},e))}convertNamespaceDeclaration(e){if(e.flags&i.NodeFlags.GlobalAugmentation||!i.isIdentifier(e.name)){this.createDeclaration(e).convertNamespace(e,!0);return}const s=this.createDeclaration(e,e.name);s.pushIdentifierReference(e.name),s.convertNamespace(e)}convertEnumDeclaration(e){this.createDeclaration(e,e.name).pushIdentifierReference(e.name)}convertFunctionDeclaration(e){if(!e.name)throw new g(e,"FunctionDeclaration should have a name");const t=this.createDeclaration(e,e.name);t.pushIdentifierReference(e.name),t.convertParametersAndType(e)}convertClassOrInterfaceDeclaration(e){if(!e.name)throw new g(e,"ClassDeclaration / InterfaceDeclaration should have a name");const t=this.createDeclaration(e,e.name),s=t.convertTypeParameters(e.typeParameters);t.convertHeritageClauses(e),t.convertMembers(e.members),t.popScope(s)}convertTypeAliasDeclaration(e){const t=this.createDeclaration(e,e.name),s=t.convertTypeParameters(e.typeParameters);t.convertTypeNode(e.type),t.popScope(s)}convertVariableStatement(e){const{declarations:t}=e.declarationList;if(t.length!==1)throw new g(e,"VariableStatement with more than one declaration not yet supported");for(const s of t){if(!i.isIdentifier(s.name))throw new g(e,"VariableDeclaration must have a name");const r=this.createDeclaration(e,s.name);r.convertTypeNode(s.type),s.initializer&&this.trackExpressionReferences(s.initializer,r)}}trackExpressionReferences(e,t){if(i.isIdentifier(e))t.pushIdentifierReference(e);else if(i.isObjectLiteralExpression(e))for(const s of e.properties)i.isShorthandPropertyAssignment(s)?t.pushIdentifierReference(s.name):i.isPropertyAssignment(s)&&this.trackExpressionReferences(s.initializer,t);else if(i.isArrayLiteralExpression(e))for(const s of e.elements)i.isExpression(s)&&this.trackExpressionReferences(s,t);else i.isPropertyAccessExpression(e)&&this.trackExpressionReferences(e.expression,t)}convertExportDeclaration(e){if(i.isExportAssignment(e)){this.pushStatement(E({type:"ExportDefaultDeclaration",declaration:w(e.expression)},e));return}const t=e.moduleSpecifier?w(e.moduleSpecifier):void 0;if(!e.exportClause)this.pushStatement(E({type:"ExportAllDeclaration",source:t,exported:null,attributes:[]},e));else if(i.isNamespaceExport(e.exportClause))this.pushStatement(E({type:"ExportAllDeclaration",source:t,exported:v(e.exportClause.name),attributes:[]},e));else{const s=[];for(const r of e.exportClause.elements)s.push(this.convertExportSpecifier(r));this.pushStatement(E({type:"ExportNamedDeclaration",declaration:null,specifiers:s,source:t,attributes:[]},e))}}convertImportDeclaration(e){if(i.isImportEqualsDeclaration(e)){if(i.isEntityName(e.moduleReference)){const r=this.createDeclaration(e,e.name);r.pushReference(r.convertEntityName(e.moduleReference));return}if(!i.isExternalModuleReference(e.moduleReference))throw new g(e,"ImportEquals should have a literal source.");this.pushStatement(E({type:"ImportDeclaration",specifiers:[{type:"ImportDefaultSpecifier",local:v(e.name)}],source:w(e.moduleReference.expression),attributes:[]},e));return}const t=w(e.moduleSpecifier),s=e.importClause&&e.importClause.namedBindings?this.convertNamedImportBindings(e.importClause.namedBindings):[];e.importClause&&e.importClause.name&&s.push({type:"ImportDefaultSpecifier",local:v(e.importClause.name)}),this.pushStatement(E({type:"ImportDeclaration",specifiers:s,source:t,attributes:[]},e))}convertNamedImportBindings(e){return i.isNamedImports(e)?e.elements.map(t=>{const s=v(t.name),r=t.propertyName?v(t.propertyName):s;return{type:"ImportSpecifier",local:s,imported:r}}):[{type:"ImportNamespaceSpecifier",local:v(e.name)}]}convertExportSpecifier(e){const t=v(e.name);return{type:"ExportSpecifier",exported:t,local:e.propertyName?v(e.propertyName):t}}}class Oe{static{m(this,"RelativeModuleDeclarationFixer")}constructor(e,t,s,r){this.sourcemap=s,this.DEBUG=!!process.env.DTS_EXPORTS_FIXER_DEBUG,this.relativeModuleDeclarations=[],this.source=L(e,t.toString()),this.code=t,this.name=r||"./index"}fix(){this.analyze(this.source.statements);for(const e of this.relativeModuleDeclarations){const t=e.getStart(),s=e.getEnd(),r=e.name.kind===i.SyntaxKind.StringLiteral&&"singleQuote"in e.name&&e.name.singleQuote?"'":'"',a=`declare module ${r}${this.name}${r} ${e.body.getText()}`;this.code.overwrite(t,s,a)}return{code:this.code.toString(),map:this.relativeModuleDeclarations.length&&this.sourcemap?this.code.generateMap():null}}analyze(e){for(const t of e)i.isModuleDeclaration(t)&&t.body&&i.isModuleBlock(t.body)&&/^\.\.?\//.test(t.name.text)&&(this.DEBUG&&console.log(`Found relative module declaration: ${t.name.text} in ${this.source.fileName}`),this.relativeModuleDeclarations.push(t))}}const Pe=m(()=>{const n=new Map,e=new Map;return{name:"dts-transform",options({onLog:t,...s}){return{...s,onLog(r,a,c){r==="warn"&&a.code==="CIRCULAR_DEPENDENCY"||(t?t(r,a,c):c(r,a))},treeshake:{moduleSideEffects:"no-external",propertyReadSideEffects:!0,unknownGlobalSideEffects:!1}}},outputOptions(t){return{...t,chunkFileNames:t.chunkFileNames||"[name]-[hash].d.ts",entryFileNames:t.entryFileNames||"[name].d.ts",format:"es",exports:"named",compact:!1,freeze:!0,interop:"esModule",generatedCode:Object.assign({symbols:!1},t.generatedCode),strict:!1}},transform(t,s){const r=z(s),a=this.getModuleIds(),c=Array.from(a).find(T=>z(T)===r),p=!!(c&&this.getModuleInfo(c)?.isEntry),u=!!(c&&_.test(c));let l=L(s,t);const f=Ce({sourceFile:l,isEntry:p,isJSON:u});n.set(l.fileName,f.typeReferences),e.set(l.fileName,f.fileReferences),t=f.code.toString(),l=L(s,t);const h=Ae({sourceFile:l});return process.env.DTS_DUMP_AST&&(console.log(s),console.log(t),console.log(JSON.stringify(h.ast.body,void 0,2))),{code:t,ast:h.ast,map:f.code.generateMap()}},renderChunk(t,s,r){const a=L(s.fileName,t),c=new Se(a),p=new Set,u=new Set;for(const D of Object.keys(s.modules)){for(const I of n.get(D.split("\\").join("/"))||[])p.add(I);for(const I of e.get(D.split("\\").join("/"))||[])if(I.startsWith(".")){const b=x.join(x.dirname(D),I),O=r.file&&x.dirname(r.file)||s.facadeModuleId&&x.dirname(s.facadeModuleId)||".";let o=x.relative(O,b).split("\\").join("/");o[0]!=="."&&(o="./"+o),u.add(o)}else u.add(I)}let l=oe(Array.from(u,D=>`/// <reference path="${D}" />`));l+=oe(Array.from(p,D=>`/// <reference types="${D}" />`)),l+=c.fix(),l||(l+=`
|
|
30
|
+
export { };`);const h=new be(s.fileName,l).fix();return new Oe(s.fileName,"magicCode"in h&&h.magicCode?h.magicCode:new j(l),!!r.sourcemap,"./"+(r.file&&r.file!=="-"?x.basename(r.file,".d.ts"):"index")).fix()}}},"transform");function oe(n){return n.length?n.join(`
|
|
31
|
+
`)+`
|
|
32
|
+
`:""}m(oe,"writeBlock");const Re=/\.([cm]ts|[tj]sx?)$/;function q({entries:n,programs:e,resolvedOptions:t},s,r){const{compilerOptions:a,tsconfig:c}=t;if(!e.length&&k.test(s))return{code:r};const p=n.includes(s),u=e.find(l=>{if(p)return l.getRootFileNames().includes(s);{const f=l.getSourceFile(s);return f&&l.isSourceFileFromExternalLibrary(f)?!1:!!f}});if(u){const l=u.getSourceFile(s);return{code:l?.getFullText(),source:l,program:u}}else if(i.sys.fileExists(s)){if(e.length>0&&k.test(s)&&(t.includeExternal.length>0||t.respectExternal))return{code:r};const l=de(s,a,c);e.push(l);const f=l.getSourceFile(s);return{code:f?.getFullText(),source:f,program:l}}else return null}m(q,"getModule");const ae=m((n={})=>{const e=Pe(),t={entries:[],programs:[],resolvedOptions:me(n)};return{name:"dts",outputOptions:e.outputOptions,renderChunk:e.renderChunk,options(s){let{input:r=[]}=s;if(!Array.isArray(r))r=typeof r=="string"?[r]:Object.values(r);else if(r.length>1){s.input={};for(const a of r){let c=z(a);x.isAbsolute(a)?c=x.basename(c):c=x.normalize(c),s.input[c]=a}}return t.programs=he(Object.values(r),t.resolvedOptions.compilerOptions,t.resolvedOptions.tsconfig),e.options.call(this,s)},transform(s,r){if(!Re.test(r)&&!_.test(r))return null;const a=m(l=>{if(l.program){const f=x.dirname(r);l.program.getSourceFiles().map(T=>T.fileName).filter(T=>T.startsWith(f)).forEach(this.addWatchFile)}},"watchFiles"),c=m(()=>{const l=q(t,r,s);return l?(a(l),e.transform.call(this,l.code,r)):null},"handleDtsFile"),p=m(()=>{const l=J(r),f=q(t,l,s);return f?(a(f),e.transform.call(this,f.code,l)):null},"treatTsAsDts"),u=m(()=>{const l=q(t,r,s);if(!l||!l.source||!l.program)return null;a(l);const f=J(r);let h;const{emitSkipped:T,diagnostics:D}=l.program.emit(l.source,(I,b)=>{h=e.transform.call(this,b,f)},void 0,!0,void 0,!0);if(T){const I=D.filter(b=>b.category===i.DiagnosticCategory.Error);I.length&&(console.error(i.formatDiagnostics(I,V)),this.error("Failed to compile. Check the logs above."))}return h},"generateDts");return k.test(r)?c():_.test(r)?u():p()??u()},resolveId(s,r){if(!r){t.entries.push(x.resolve(s));return}r=r.split("\\").join("/");let a=t.resolvedOptions.compilerOptions;if(t.resolvedOptions.tsconfig){const p=s.startsWith(".")?x.resolve(x.dirname(r),s):s;a=U(p,t.resolvedOptions.compilerOptions,t.resolvedOptions.tsconfig).compilerOptions}const{resolvedModule:c}=i.resolveModuleName(s,r,a,i.sys);if(c)return c.isExternalLibraryImport&&c.packageId&&t.resolvedOptions.includeExternal.includes(c.packageId.name)?{id:x.resolve(c.resolvedFileName)}:!t.resolvedOptions.respectExternal&&c.isExternalLibraryImport?{id:s,external:!0}:{id:x.resolve(c.resolvedFileName)}}}},"plugin");export{ae as default,ae as dts};
|
package/package.json
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
var oe=Object.defineProperty;var m=(n,e)=>oe(n,"name",{value:e,configurable:!0});import{createRequire as ae}from"node:module";const ce=ae(import.meta.url);import*as T from"node:path";import r from"typescript";import{createRequire as le}from"node:module";import q from"magic-string";function pe(n){return{...n,compilerOptions:n.compilerOptions??{},respectExternal:n.respectExternal??!1}}m(pe,"resolveDefaultOptions");const k=/\.d\.(c|m)?tsx?$/,_=/\.json$/,W=/((\.d)?\.(c|m)?(t|j)sx?|\.json)$/;function B(n){return n.replace(W,"")}m(B,"trimExtension");function J(n){return n.replace(W,".d.ts")}m(J,"getDeclarationId");function j(n,e){return r.createSourceFile(n,e,r.ScriptTarget.Latest,!0)}m(j,"parse");const V={getCurrentDirectory:m(()=>r.sys.getCurrentDirectory(),"getCurrentDirectory"),getNewLine:m(()=>r.sys.newLine,"getNewLine"),getCanonicalFileName:r.sys.useCaseSensitiveFileNames?n=>n:n=>n.toLowerCase()},fe={declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!0,target:r.ScriptTarget.ESNext,resolveJsonModule:!0},R=new Map,M=m((...n)=>process.env.DTS_LOG_CACHE?console.log("[cache]",...n):null,"logCache");function X([n,e],t){for(M(n),R.set(n,t);n!==e&&n!==T.dirname(n);){if(n=T.dirname(n),M("up",n),R.has(n))return M("has",n);R.set(n,t)}}m(X,"cacheConfig");function z(n,e,t){const s={...fe,...e};let i=T.dirname(n),o=[];const c=t||i;if(R.has(c))M("HIT",c);else{M("miss",c);const u=t?T.resolve(process.cwd(),t):r.findConfigFile(i,r.sys.fileExists);if(!u)return{dtsFiles:o,dirName:i,compilerOptions:s};const h=i;i=T.dirname(u);const{config:g,error:w}=r.readConfigFile(u,r.sys.readFile);if(w)return console.error(r.formatDiagnostic(w,V)),{dtsFiles:o,dirName:i,compilerOptions:s};M("tsconfig",g);const C=r.parseJsonConfigFileContent(g,r.sys,i);X(t?[t,t]:[h,i],C)}const{fileNames:l,options:p,errors:f}=R.get(c);return o=l.filter(u=>k.test(u)),f.length?(console.error(r.formatDiagnostics(f,V)),{dtsFiles:o,dirName:i,compilerOptions:s}):{dtsFiles:o,dirName:i,compilerOptions:{...p,...s}}}m(z,"getCompilerOptions");function me(n,e,t){const{dtsFiles:s,compilerOptions:i}=z(n,e,t);return r.createProgram([n].concat(Array.from(s)),i,r.createCompilerHost(i,!0))}m(me,"createProgram$1");function ue(n,e,t){const s=[],i=new Set;let o=[],c="",l={};for(let p of n){if(k.test(p))continue;p=T.resolve(p);const f=z(p,e,t);if(f.dtsFiles.forEach(i.add,i),!o.length){o.push(p),{dirName:c,compilerOptions:l}=f;continue}if(f.dirName===c)o.push(p);else{const u=r.createCompilerHost(l,!0),h=r.createProgram(o.concat(Array.from(i)),l,u);s.push(h),o=[p],{dirName:c,compilerOptions:l}=f}}if(o.length){const p=r.createCompilerHost(l,!0),f=r.createProgram(o.concat(Array.from(i)),l,p);s.push(f)}return s}m(ue,"createPrograms");function de(){let n;try{return{codeFrameColumns:n}=ce("@babel/code-frame"),n}catch{try{return{codeFrameColumns:n}=le(import.meta.url)("@babel/code-frame"),n}catch{}}}m(de,"getCodeFrame");function he(n){const e=n.getSourceFile(),t=e.getLineAndCharacterOfPosition(n.getStart()),s=e.getLineAndCharacterOfPosition(n.getEnd());return{start:{line:t.line+1,column:t.character+1},end:{line:s.line+1,column:s.character+1}}}m(he,"getLocation");function ye(n){const e=de(),s=n.getSourceFile().getFullText(),i=he(n);return e?`
|
|
2
|
-
`+e(s,i,{highlightCode:!0}):`
|
|
3
|
-
${i.start.line}:${i.start.column}: \`${n.getFullText().trim()}\``}m(ye,"frameNode");class x extends Error{static{m(this,"UnsupportedSyntaxError")}constructor(e,t="Syntax not yet supported"){super(`${t}
|
|
4
|
-
${ye(e)}`)}}class ge{static{m(this,"NamespaceFixer")}constructor(e){this.sourceFile=e}findNamespaces(){const e=[],t={};for(const s of this.sourceFile.statements){const i={start:s.getStart(),end:s.getEnd()};if(r.isEmptyStatement(s)){e.unshift({name:"",exports:[],location:i});continue}if((r.isImportDeclaration(s)||r.isExportDeclaration(s))&&s.moduleSpecifier&&r.isStringLiteral(s.moduleSpecifier)){const{text:u}=s.moduleSpecifier;if(u.startsWith(".")&&(u.endsWith(".d.ts")||u.endsWith(".d.cts")||u.endsWith(".d.mts"))){const h=s.moduleSpecifier.getStart()+1,g=s.moduleSpecifier.getEnd()-1;e.unshift({name:"",exports:[],location:{start:h,end:g},textBeforeCodeAfter:u.replace(/\.d\.ts$/,".js").replace(/\.d\.cts$/,".cjs").replace(/\.d\.mts$/,".mjs")})}}if(r.isModuleDeclaration(s)&&s.body&&r.isModuleBlock(s.body)){for(const u of s.body.statements)if(r.isExportDeclaration(u)&&u.exportClause){if(r.isNamespaceExport(u.exportClause))continue;for(const h of u.exportClause.elements)h.propertyName&&h.propertyName.getText()==h.name.getText()&&e.unshift({name:"",exports:[],location:{start:h.propertyName.getEnd(),end:h.name.getEnd()}})}}if(r.isClassDeclaration(s)?t[s.name.getText()]={type:"class",generics:s.typeParameters}:r.isFunctionDeclaration(s)?t[s.name.getText()]={type:"function"}:r.isInterfaceDeclaration(s)?t[s.name.getText()]={type:"interface",generics:s.typeParameters}:r.isTypeAliasDeclaration(s)?t[s.name.getText()]={type:"type",generics:s.typeParameters}:r.isModuleDeclaration(s)&&r.isIdentifier(s.name)?t[s.name.getText()]={type:"namespace"}:r.isEnumDeclaration(s)&&(t[s.name.getText()]={type:"enum"}),!r.isVariableStatement(s))continue;const{declarations:o}=s.declarationList;if(o.length!==1)continue;const c=o[0],l=c.name.getText();if(!c.initializer||!r.isCallExpression(c.initializer)){t[l]={type:"var"};continue}const p=c.initializer.arguments[0];if(!c.initializer.expression.getFullText().includes("/*#__PURE__*/Object.freeze")||!r.isObjectLiteralExpression(p))continue;const f=[];for(const u of p.properties){if(!r.isPropertyAssignment(u)||!(r.isIdentifier(u.name)||r.isStringLiteral(u.name))||u.name.text!=="__proto__"&&!r.isIdentifier(u.initializer))throw new x(u,"Expected a property assignment");u.name.text!=="__proto__"&&f.push({exportedName:u.name.text,localName:u.initializer.getText()})}e.unshift({name:l,exports:f,location:i})}return{namespaces:e,itemTypes:t}}fix(){let e=this.sourceFile.getFullText();const{namespaces:t,itemTypes:s}=this.findNamespaces();for(const i of t){const o=e.slice(i.location.end);e=e.slice(0,i.location.start);for(const{exportedName:c,localName:l}of i.exports)if(c===l){const{type:p,generics:f}=s[l]||{};if(p==="interface"||p==="type"){const u=Y(f);e+=`type ${i.name}_${c}${u.in} = ${l}${u.out};
|
|
5
|
-
`}else if(p==="enum"||p==="class"){const u=Y(f);e+=`type ${i.name}_${c}${u.in} = ${l}${u.out};
|
|
6
|
-
`,e+=`declare const ${i.name}_${c}: typeof ${l};
|
|
7
|
-
`}else p==="namespace"?e+=`import ${i.name}_${c} = ${l};
|
|
8
|
-
`:e+=`declare const ${i.name}_${c}: typeof ${l};
|
|
9
|
-
`}if(i.name){e+=`declare namespace ${i.name} {
|
|
10
|
-
`,e+=` export {
|
|
11
|
-
`;for(const{exportedName:c,localName:l}of i.exports)c===l?e+=` ${i.name}_${c} as ${c},
|
|
12
|
-
`:e+=` ${l} as ${c},
|
|
13
|
-
`;e+=` };
|
|
14
|
-
`,e+="}"}e+=i.textBeforeCodeAfter??"",e+=o}return e}}function Y(n){return!n||!n.length?{in:"",out:""}:{in:`<${n.map(e=>e.getText()).join(", ")}>`,out:`<${n.map(e=>e.name.getText()).join(", ")}>`}}m(Y,"renderTypeParams");let Q=1;function xe(n){return E({type:"Program",sourceType:"module",body:[]},{start:n.getFullStart(),end:n.getEnd()})}m(xe,"createProgram");function Se(n){const e={type:"Identifier",name:String(Q++)};return{ident:e,expr:{type:"AssignmentPattern",left:e,right:n}}}m(Se,"createReference");function N(n){return E({type:"Identifier",name:n.getText()},n)}m(N,"createIdentifier");function Te(n){const e=E({type:"FunctionExpression",id:null,params:[],body:{type:"BlockStatement",body:[]}},n),t=E({type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:String(Q++)},arguments:[e],optional:!1}},n);return{fn:e,iife:t}}m(Te,"createIIFE");function ve(){const n={type:"ArrayExpression",elements:[]};return{expr:n,stmt:{type:"ReturnStatement",argument:n}}}m(ve,"createReturn");function Ee(n,e){return E({type:"FunctionDeclaration",id:E({type:"Identifier",name:r.idText(n)},n),params:[],body:{type:"BlockStatement",body:[]}},e)}m(Ee,"createDeclaration");function A(n){if(r.isLiteralExpression(n))return{type:"Literal",value:n.text};if(r.isPropertyAccessExpression(n)){if(r.isPrivateIdentifier(n.name))throw new x(n.name);return E({type:"MemberExpression",computed:!1,optional:!1,object:A(n.expression),property:A(n.name)},{start:n.expression.getStart(),end:n.name.getEnd()})}if(r.isIdentifier(n))return N(n);if(n.kind==r.SyntaxKind.NullKeyword)return{type:"Literal",value:null};throw new x(n)}m(A,"convertExpression");function E(n,e){const t="start"in e?e:{start:e.getStart(),end:e.getEnd()};return Object.assign(n,t)}m(E,"withStartEnd");function L(n,e){return(r.getCombinedModifierFlags(n)&e)===e}m(L,"matchesModifier");class Ne{static{m(this,"LanguageService")}constructor(e){this.fileName="index.d.ts";const t={getCompilationSettings:m(()=>({noEmit:!0,noResolve:!0,skipLibCheck:!0,declaration:!1,checkJs:!1,declarationMap:!1,target:r.ScriptTarget.ESNext}),"getCompilationSettings"),getScriptFileNames:m(()=>[this.fileName],"getScriptFileNames"),getScriptVersion:m(()=>"1","getScriptVersion"),getScriptSnapshot:m(s=>s===this.fileName?r.ScriptSnapshot.fromString(e):void 0,"getScriptSnapshot"),getCurrentDirectory:m(()=>"","getCurrentDirectory"),getDefaultLibFileName:m(()=>"","getDefaultLibFileName"),fileExists:m(s=>s===this.fileName,"fileExists"),readFile:m(s=>s===this.fileName?e:void 0,"readFile")};this.service=r.createLanguageService(t,r.createDocumentRegistry(void 0,""),r.LanguageServiceMode.PartialSemantic)}findReferenceCount(e){const t=this.service.findReferences(this.fileName,e.getStart());return t?.length?t.reduce((s,i)=>s+i.references.length,0):0}}class De{static{m(this,"TypeOnlyFixer")}constructor(e,t,s){this.sourcemap=s,this.DEBUG=!!process.env.DTS_EXPORTS_FIXER_DEBUG,this.types=new Set,this.values=new Set,this.typeHints=new Map,this.reExportTypeHints=new Map,this.importNodes=[],this.exportNodes=[],this.rawCode=t,this.source=j(e,t),this.code=new q(t)}fix(){return this.analyze(this.source.statements),(this.typeHints.size||this.reExportTypeHints.size)&&(this.service=new Ne(this.rawCode),this.importNodes.forEach(e=>this.fixTypeOnlyImport(e))),this.types.size&&this.exportNodes.forEach(e=>this.fixTypeOnlyExport(e)),this.types.size?{code:this.code.toString(),map:this.sourcemap?this.code.generateMap():null}:{code:this.rawCode,map:null}}fixTypeOnlyImport(e){let t=!1;const s=[],i=[],o=e.moduleSpecifier.getText(),c=e.importClause.name,l=e.importClause.namedBindings;if(c){const p=c.text;this.isTypeOnly(p)?this.isUselessImport(c)?t=!0:s.push(`import type ${p} from ${o};`):i.push(`import ${p} from ${o};`)}if(l&&r.isNamespaceImport(l)){const p=l.name.text;this.isTypeOnly(p)?this.isUselessImport(l.name)?t=!0:s.push(`import type * as ${p} from ${o};`):i.push(`import * as ${p} from ${o};`)}if(l&&r.isNamedImports(l)){const p=[],f=[];for(const u of l.elements)this.isTypeOnly(u.name.text)?this.isUselessImport(u.name)?t=!0:p.push(u.getText()):f.push(u.getText());p.length&&s.push(`import type { ${p.join(", ")} } from ${o};`),f.length&&i.push(`import { ${f.join(", ")} } from ${o};`)}(s.length||t)&&this.code.overwrite(e.getStart(),e.getEnd(),[...i,...s].join(`
|
|
15
|
-
${Z(e)}`))}fixTypeOnlyExport(e){const t=[],s=[],i=e.moduleSpecifier?.getText();if(r.isNamespaceExport(e.exportClause)){const o=e.exportClause.name.text;this.isReExportTypeOnly(o)?t.push(`export type * as ${o} from ${i};`):s.push(`export * as ${o} from ${i};`)}if(r.isNamedExports(e.exportClause)){const o=[],c=[];for(const l of e.exportClause.elements){const p=l.propertyName?.text||l.name.text;(e.moduleSpecifier?this.isReExportTypeOnly(l.name.text):this.isTypeOnly(p))?o.push(l.getText()):c.push(l.getText())}o.length&&t.push(`export type { ${o.join(", ")} }${i?` from ${i}`:""};`),c.length&&s.push(`export { ${c.join(", ")} }${i?` from ${i}`:""};`)}t.length&&this.code.overwrite(e.getStart(),e.getEnd(),[...s,...t].join(`
|
|
16
|
-
${Z(e)}`))}analyze(e){for(const t of e){if(this.DEBUG&&console.log(t.getText(),t.kind),r.isImportDeclaration(t)&&t.importClause){this.importNodes.push(t);continue}if(r.isExportDeclaration(t)&&t.exportClause){this.exportNodes.push(t);continue}if(r.isInterfaceDeclaration(t)){this.DEBUG&&console.log(`${t.name.getFullText()} is a type`),this.types.add(t.name.text);continue}if(r.isTypeAliasDeclaration(t)){const s=t.name.text;this.DEBUG&&console.log(`${t.name.getFullText()} is a type`),this.types.add(s);continue}if(r.isEnumDeclaration(t)||r.isFunctionDeclaration(t)||r.isClassDeclaration(t)||r.isVariableStatement(t)){if(r.isVariableStatement(t))for(const s of t.declarationList.declarations)r.isIdentifier(s.name)&&(this.DEBUG&&console.log(`${s.name.getFullText()} is a value (from var statement)`),this.values.add(s.name.text));else t.name&&(this.DEBUG&&console.log(`${t.name.getFullText()} is a value (from declaration)`),this.values.add(t.name.text));continue}if(r.isModuleBlock(t)){this.analyze(t.statements);continue}if(r.isModuleDeclaration(t)){t.name&&r.isIdentifier(t.name)&&(this.DEBUG&&console.log(`${t.name.getFullText()} is a value (from module declaration)`),this.values.add(t.name.text)),this.analyze(t.getChildren());continue}this.DEBUG&&console.log("unhandled statement",t.getFullText(),t.kind)}}isUselessImport(e){const t=this.service.findReferenceCount(e),s=this.typeHints.get(e.text);return s&&s+1>=t}isTypeOnly(e){return this.typeHints.has(e)||this.types.has(e)&&!this.values.has(e)}isReExportTypeOnly(e){return this.reExportTypeHints.has(e)}}function Z(n){const e=n.getFullText().match(/^(?:\n*)([ ]*)/);return" ".repeat(e?.[1]?.length||0)}m(Z,"getNodeIndent");function Ce({sourceFile:n,isEntry:e,isJSON:t}){const s=new q(n.getFullText()),i=!e&&Ie(n),o=new Set,c=new Set;let l="";const p=new Map,f=new Map;for(const a of n.statements){if(r.isEmptyStatement(a)){s.remove(a.getStart(),a.getEnd());continue}if(r.isImportDeclaration(a)){if(!a.importClause)continue;a.importClause.name&&o.add(a.importClause.name.text),a.importClause.namedBindings&&(r.isNamespaceImport(a.importClause.namedBindings)?o.add(a.importClause.namedBindings.name.text):a.importClause.namedBindings.elements.forEach(d=>o.add(d.name.text)))}else if(r.isEnumDeclaration(a)||r.isFunctionDeclaration(a)||r.isInterfaceDeclaration(a)||r.isClassDeclaration(a)||r.isTypeAliasDeclaration(a)||r.isModuleDeclaration(a)){if(a.name){const d=a.name.getText();o.add(d),L(a,r.ModifierFlags.ExportDefault)?l=d:(i&&r.isIdentifier(a.name)||L(a,r.ModifierFlags.Export))&&c.add(d),a.flags&r.NodeFlags.GlobalAugmentation||K(d,[U(a),te(a)])}r.isModuleDeclaration(a)&&we(s,a),ee(s,a)}else if(r.isVariableStatement(a)){const{declarations:d}=a.declarationList,S=L(a,r.ModifierFlags.Export);for(const v of a.declarationList.declarations)if(r.isIdentifier(v.name)){const I=v.name.getText();o.add(I),(i||S)&&c.add(I)}if(ee(s,a),d.length===1){const v=d[0];r.isIdentifier(v.name)&&K(v.name.getText(),[U(a),te(a)])}else{const v=d.slice(),I=v.shift();K(I.name.getText(),[U(a),I.getEnd()]);for(const O of v)r.isIdentifier(O.name)&&K(O.name.getText(),[O.getFullStart(),O.getEnd()])}const{flags:y}=a.declarationList,P=`declare ${y&r.NodeFlags.Let?"let":y&r.NodeFlags.Const?"const":"var"} `,$=a.declarationList.getChildren().find(v=>v.kind===r.SyntaxKind.SyntaxList).getChildren();let b=0;for(const v of $)if(v.kind===r.SyntaxKind.CommaToken)b=v.getStart(),s.remove(b,v.getEnd());else if(b){s.appendLeft(b,`;
|
|
17
|
-
`);const I=v.getFullStart(),O=s.slice(I,v.getStart()),H=O.length-O.trimStart().length;H?s.overwrite(I,I+H,P):s.appendLeft(I,P)}}}for(const a of n.statements)if(w(a),!!L(a,r.ModifierFlags.ExportDefault)&&(r.isFunctionDeclaration(a)||r.isClassDeclaration(a))){if(a.name)continue;l||(l=D("export_default"));const d=a.getChildren(),S=d.findIndex($=>$.kind===r.SyntaxKind.ClassKeyword||$.kind===r.SyntaxKind.FunctionKeyword),y=d[S],F=d[S+1];if(F.kind>=r.SyntaxKind.FirstPunctuation&&F.kind<=r.SyntaxKind.LastPunctuation){const $=s.slice(y.getEnd(),F.getStart())!=" ";s.appendLeft(F.getStart(),`${$?" ":""}${l}`)}else s.appendRight(y.getEnd(),` ${l}`)}for(const a of f.values()){const S=a.pop()[0];for(const y of a)s.move(y[0],y[1],S)}l&&s.append(`
|
|
18
|
-
export default ${l};
|
|
19
|
-
`),c.size&&s.append(`
|
|
20
|
-
export { ${[...c].join(", ")} };
|
|
21
|
-
`),t&&c.size&&(l=D("export_default"),s.append([`
|
|
22
|
-
declare const ${l}: {`,[...c].map(a=>` ${a}: typeof ${a};`).join(`
|
|
23
|
-
`),"};",`export default ${l};
|
|
24
|
-
`].join(`
|
|
25
|
-
`)));for(const[a,d]of p.entries())s.prepend(`import * as ${d} from "${a}";
|
|
26
|
-
`);const u=n.getLineStarts(),h=new Set;for(const a of n.typeReferenceDirectives){h.add(a.fileName);const{line:d}=n.getLineAndCharacterOfPosition(a.pos),S=u[d];let y=n.getLineEndOfPosition(a.pos);s.slice(y,y+1)===`
|
|
27
|
-
`&&(y+=1),s.remove(S,y)}const g=new Set;for(const a of n.referencedFiles){g.add(a.fileName);const{line:d}=n.getLineAndCharacterOfPosition(a.pos),S=u[d];let y=n.getLineEndOfPosition(a.pos);s.slice(y,y+1)===`
|
|
28
|
-
`&&(y+=1),s.remove(S,y)}return{code:s,typeReferences:h,fileReferences:g};function w(a){if(r.forEachChild(a,w),r.isImportTypeNode(a)){if(!r.isLiteralTypeNode(a.argument)||!r.isStringLiteral(a.argument.literal))throw new x(a,"inline imports should have a literal argument");const d=a.argument.literal.text,S=a.getChildren(),y=S.find(b=>b.kind===r.SyntaxKind.ImportKeyword).getStart();let F=a.getEnd();const P=S.find(b=>b.kind===r.SyntaxKind.DotToken||b.kind===r.SyntaxKind.LessThanToken);P&&(F=P.getStart());const $=C(d);s.overwrite(y,F,$)}}function C(a){let d=p.get(a);return d||(d=D(be(a)),p.set(a,d)),d}function D(a){let d=a;for(;o.has(d);)d=`_${d}`;return o.add(d),d}function K(a,d){let S=f.get(a);if(!S)S=[d],f.set(a,S);else{const y=S[S.length-1];y[1]===d[0]?y[1]=d[1]:S.push(d)}}}m(Ce,"preProcess");function Ie(n){let e=!1;for(const t of n.statements){if(r.isExportDeclaration(t)||r.isExportAssignment(t))return!1;(e||r.isImportDeclaration(t)||L(t,r.ModifierFlags.Export))&&(e=!0)}return e}m(Ie,"isGlobalModule");function ee(n,e){if(!r.canHaveModifiers(e))return;let t=!1;const s=r.isEnumDeclaration(e)||r.isClassDeclaration(e)||r.isFunctionDeclaration(e)||r.isModuleDeclaration(e)||r.isVariableStatement(e);for(const i of e.modifiers??[])switch(i.kind){case r.SyntaxKind.ExportKeyword:case r.SyntaxKind.DefaultKeyword:n.remove(i.getStart(),i.getEnd()+1);break;case r.SyntaxKind.DeclareKeyword:t=!0}s&&!t&&n.appendRight(e.getStart(),"declare ")}m(ee,"fixModifiers");function we(n,e){if(!(!e.body||!r.isModuleBlock(e.body))){for(const t of e.body.statements)if(r.isExportDeclaration(t)&&t.exportClause){if(r.isNamespaceExport(t.exportClause))continue;for(const s of t.exportClause.elements)s.propertyName||n.appendLeft(s.name.getEnd(),` as ${s.name.getText()}`)}}}m(we,"duplicateExports");function be(n){return n.replace(/[^a-zA-Z0-9_$]/g,()=>"_")}m(be,"getSafeName");function U(n){const e=n.getFullStart();return e+(re(n,e)?1:0)}m(U,"getStart");function te(n){const e=n.getEnd();return e+(re(n,e)?1:0)}m(te,"getEnd");function re(n,e){return n.getSourceFile().getFullText()[e]===`
|
|
29
|
-
`}m(re,"newlineAt");const Fe=new Set([r.SyntaxKind.LiteralType,r.SyntaxKind.VoidKeyword,r.SyntaxKind.UnknownKeyword,r.SyntaxKind.AnyKeyword,r.SyntaxKind.BooleanKeyword,r.SyntaxKind.NumberKeyword,r.SyntaxKind.StringKeyword,r.SyntaxKind.ObjectKeyword,r.SyntaxKind.NullKeyword,r.SyntaxKind.UndefinedKeyword,r.SyntaxKind.SymbolKeyword,r.SyntaxKind.NeverKeyword,r.SyntaxKind.ThisKeyword,r.SyntaxKind.ThisType,r.SyntaxKind.BigIntKeyword]);class se{static{m(this,"DeclarationScope")}constructor({id:e,range:t}){if(this.scopes=[],e)this.declaration=Ee(e,t);else{const{iife:i,fn:o}=Te(t);this.iife=i,this.declaration=o}const s=ve();this.declaration.body.body.push(s.stmt),this.returnExpr=s.expr}pushScope(){this.scopes.push(new Set)}popScope(e=1){for(let t=0;t<e;t++)this.scopes.pop()}pushTypeVariable(e){const t=e.getText();this.scopes[this.scopes.length-1]?.add(t)}pushReference(e){let t;if(e.type==="Identifier"?t=e.name:e.type==="MemberExpression"&&e.object.type==="Identifier"&&(t=e.object.name),t){for(const o of this.scopes)if(o.has(t))return}if(t==="this")return;const{ident:s,expr:i}=Se(e);this.declaration.params.push(i),this.returnExpr.elements.push(s)}pushIdentifierReference(e){this.pushReference(N(e))}convertEntityName(e){return r.isIdentifier(e)?N(e):E({type:"MemberExpression",computed:!1,optional:!1,object:this.convertEntityName(e.left),property:N(e.right)},e)}convertPropertyAccess(e){if(!r.isIdentifier(e.expression)&&!r.isPropertyAccessExpression(e.expression))throw new x(e.expression);if(r.isPrivateIdentifier(e.name))throw new x(e.name);const t=r.isIdentifier(e.expression)?N(e.expression):this.convertPropertyAccess(e.expression);return E({type:"MemberExpression",computed:!1,optional:!1,object:t,property:N(e.name)},e)}convertComputedPropertyName(e){if(!e.name||!r.isComputedPropertyName(e.name))return;const{expression:t}=e.name;if(!(r.isLiteralExpression(t)||r.isPrefixUnaryExpression(t))){if(r.isIdentifier(t))return this.pushReference(N(t));if(r.isPropertyAccessExpression(t))return this.pushReference(this.convertPropertyAccess(t));throw new x(t)}}convertParametersAndType(e){this.convertComputedPropertyName(e);const t=this.convertTypeParameters(e.typeParameters);for(const s of e.parameters)this.convertTypeNode(s.type);this.convertTypeNode(e.type),this.popScope(t)}convertHeritageClauses(e){for(const t of e.heritageClauses||[])for(const s of t.types)this.pushReference(A(s.expression)),this.convertTypeArguments(s)}convertTypeArguments(e){if(e.typeArguments)for(const t of e.typeArguments)this.convertTypeNode(t)}convertMembers(e){for(const t of e){if(r.isPropertyDeclaration(t)||r.isPropertySignature(t)||r.isIndexSignatureDeclaration(t)){r.isPropertyDeclaration(t)&&t.initializer&&r.isPropertyAccessExpression(t.initializer)&&this.pushReference(this.convertPropertyAccess(t.initializer)),this.convertComputedPropertyName(t),this.convertTypeNode(t.type);continue}if(r.isMethodDeclaration(t)||r.isMethodSignature(t)||r.isConstructorDeclaration(t)||r.isConstructSignatureDeclaration(t)||r.isCallSignatureDeclaration(t)||r.isGetAccessorDeclaration(t)||r.isSetAccessorDeclaration(t))this.convertParametersAndType(t);else throw new x(t)}}convertTypeParameters(e){if(!e)return 0;for(const t of e)this.convertTypeNode(t.constraint),this.convertTypeNode(t.default),this.pushScope(),this.pushTypeVariable(t.name);return e.length}convertTypeNode(e){if(e&&!Fe.has(e.kind)){if(r.isTypeReferenceNode(e)){this.pushReference(this.convertEntityName(e.typeName)),this.convertTypeArguments(e);return}if(r.isTypeLiteralNode(e)){this.convertMembers(e.members);return}if(r.isArrayTypeNode(e)){this.convertTypeNode(e.elementType);return}if(r.isTupleTypeNode(e)){for(const t of e.elements)this.convertTypeNode(t);return}if(r.isNamedTupleMember(e)||r.isParenthesizedTypeNode(e)||r.isTypeOperatorNode(e)||r.isTypePredicateNode(e)){this.convertTypeNode(e.type);return}if(r.isUnionTypeNode(e)||r.isIntersectionTypeNode(e)){for(const t of e.types)this.convertTypeNode(t);return}if(r.isMappedTypeNode(e)){const{typeParameter:t,type:s,nameType:i}=e;this.convertTypeNode(t.constraint),this.pushScope(),this.pushTypeVariable(t.name),this.convertTypeNode(s),i&&this.convertTypeNode(i),this.popScope();return}if(r.isConditionalTypeNode(e)){this.convertTypeNode(e.checkType),this.pushScope(),this.convertTypeNode(e.extendsType),this.convertTypeNode(e.trueType),this.convertTypeNode(e.falseType),this.popScope();return}if(r.isIndexedAccessTypeNode(e)){this.convertTypeNode(e.objectType),this.convertTypeNode(e.indexType);return}if(r.isFunctionOrConstructorTypeNode(e)){this.convertParametersAndType(e);return}if(r.isTypeQueryNode(e)){this.pushReference(this.convertEntityName(e.exprName));return}if(r.isRestTypeNode(e)){this.convertTypeNode(e.type);return}if(r.isOptionalTypeNode(e)){this.convertTypeNode(e.type);return}if(r.isTemplateLiteralTypeNode(e)){for(const t of e.templateSpans)this.convertTypeNode(t.type);return}if(r.isInferTypeNode(e)){const{typeParameter:t}=e;this.convertTypeNode(t.constraint),this.pushTypeVariable(t.name);return}else throw new x(e)}}convertNamespace(e,t=!1){if(this.pushScope(),t&&e.body&&r.isModuleDeclaration(e.body)){this.convertNamespace(e.body,!0);return}if(!e.body||!r.isModuleBlock(e.body))throw new x(e,'namespace must have a "ModuleBlock" body.');const{statements:s}=e.body;for(const i of s){if(r.isEnumDeclaration(i)||r.isFunctionDeclaration(i)||r.isClassDeclaration(i)||r.isInterfaceDeclaration(i)||r.isTypeAliasDeclaration(i)||r.isModuleDeclaration(i)){if(i.name&&r.isIdentifier(i.name))this.pushTypeVariable(i.name);else throw new x(i,"non-Identifier name not supported");continue}if(r.isVariableStatement(i)){for(const o of i.declarationList.declarations)if(r.isIdentifier(o.name))this.pushTypeVariable(o.name);else throw new x(o,"non-Identifier name not supported");continue}if(!r.isExportDeclaration(i))throw new x(i,"namespace child (hoisting) not supported yet")}for(const i of s){if(r.isVariableStatement(i)){for(const o of i.declarationList.declarations)o.type&&this.convertTypeNode(o.type);continue}if(r.isFunctionDeclaration(i)){this.convertParametersAndType(i);continue}if(r.isInterfaceDeclaration(i)||r.isClassDeclaration(i)){const o=this.convertTypeParameters(i.typeParameters);this.convertHeritageClauses(i),this.convertMembers(i.members),this.popScope(o);continue}if(r.isTypeAliasDeclaration(i)){const o=this.convertTypeParameters(i.typeParameters);this.convertTypeNode(i.type),this.popScope(o);continue}if(r.isModuleDeclaration(i)){this.convertNamespace(i,t);continue}if(!r.isEnumDeclaration(i))if(r.isExportDeclaration(i)){if(i.exportClause){if(r.isNamespaceExport(i.exportClause))throw new x(i.exportClause);for(const o of i.exportClause.elements){const c=o.propertyName||o.name;this.pushIdentifierReference(c)}}}else throw new x(i,"namespace child (walking) not supported yet")}this.popScope()}}function $e({sourceFile:n}){return new Oe(n).transform()}m($e,"convert");class Oe{static{m(this,"Transformer")}constructor(e){this.sourceFile=e,this.declarations=new Map,this.ast=xe(e);for(const t of e.statements)this.convertStatement(t)}transform(){return{ast:this.ast}}pushStatement(e){this.ast.body.push(e)}createDeclaration(e,t){const s={start:e.getFullStart(),end:e.getEnd()};if(!t){const l=new se({range:s});return this.pushStatement(l.iife),l}const i=t.getText(),o=new se({id:t,range:s}),c=this.declarations.get(i);if(c){c.pushIdentifierReference(t),c.declaration.end=s.end;const l=this.ast.body.findIndex(p=>p==c.declaration);for(let p=l+1;p<this.ast.body.length;p++){const f=this.ast.body[p];f.start=f.end=s.end}}else this.pushStatement(o.declaration),this.declarations.set(i,o);return c||o}convertStatement(e){if(r.isEnumDeclaration(e))return this.convertEnumDeclaration(e);if(r.isFunctionDeclaration(e))return this.convertFunctionDeclaration(e);if(r.isInterfaceDeclaration(e)||r.isClassDeclaration(e))return this.convertClassOrInterfaceDeclaration(e);if(r.isTypeAliasDeclaration(e))return this.convertTypeAliasDeclaration(e);if(r.isVariableStatement(e))return this.convertVariableStatement(e);if(r.isExportDeclaration(e)||r.isExportAssignment(e))return this.convertExportDeclaration(e);if(r.isModuleDeclaration(e))return this.convertNamespaceDeclaration(e);if(e.kind===r.SyntaxKind.NamespaceExportDeclaration)return this.removeStatement(e);if(r.isImportDeclaration(e)||r.isImportEqualsDeclaration(e))return this.convertImportDeclaration(e);throw new x(e)}removeStatement(e){this.pushStatement(E({type:"ExpressionStatement",expression:{type:"Literal",value:"pls remove me"}},e))}convertNamespaceDeclaration(e){if(e.flags&r.NodeFlags.GlobalAugmentation||!r.isIdentifier(e.name)){this.createDeclaration(e).convertNamespace(e,!0);return}const s=this.createDeclaration(e,e.name);s.pushIdentifierReference(e.name),s.convertNamespace(e)}convertEnumDeclaration(e){this.createDeclaration(e,e.name).pushIdentifierReference(e.name)}convertFunctionDeclaration(e){if(!e.name)throw new x(e,"FunctionDeclaration should have a name");const t=this.createDeclaration(e,e.name);t.pushIdentifierReference(e.name),t.convertParametersAndType(e)}convertClassOrInterfaceDeclaration(e){if(!e.name)throw new x(e,"ClassDeclaration / InterfaceDeclaration should have a name");const t=this.createDeclaration(e,e.name),s=t.convertTypeParameters(e.typeParameters);t.convertHeritageClauses(e),t.convertMembers(e.members),t.popScope(s)}convertTypeAliasDeclaration(e){const t=this.createDeclaration(e,e.name),s=t.convertTypeParameters(e.typeParameters);t.convertTypeNode(e.type),t.popScope(s)}convertVariableStatement(e){const{declarations:t}=e.declarationList;if(t.length!==1)throw new x(e,"VariableStatement with more than one declaration not yet supported");for(const s of t){if(!r.isIdentifier(s.name))throw new x(e,"VariableDeclaration must have a name");this.createDeclaration(e,s.name).convertTypeNode(s.type)}}convertExportDeclaration(e){if(r.isExportAssignment(e)){this.pushStatement(E({type:"ExportDefaultDeclaration",declaration:A(e.expression)},e));return}const t=e.moduleSpecifier?A(e.moduleSpecifier):void 0;if(!e.exportClause)this.pushStatement(E({type:"ExportAllDeclaration",source:t,exported:null},e));else if(r.isNamespaceExport(e.exportClause))this.pushStatement(E({type:"ExportAllDeclaration",source:t,exported:N(e.exportClause.name)},e));else{const s=[];for(const i of e.exportClause.elements)s.push(this.convertExportSpecifier(i));this.pushStatement(E({type:"ExportNamedDeclaration",declaration:null,specifiers:s,source:t},e))}}convertImportDeclaration(e){if(r.isImportEqualsDeclaration(e)){if(r.isEntityName(e.moduleReference)){const i=this.createDeclaration(e,e.name);i.pushReference(i.convertEntityName(e.moduleReference));return}if(!r.isExternalModuleReference(e.moduleReference))throw new x(e,"ImportEquals should have a literal source.");this.pushStatement(E({type:"ImportDeclaration",specifiers:[{type:"ImportDefaultSpecifier",local:N(e.name)}],source:A(e.moduleReference.expression)},e));return}const t=A(e.moduleSpecifier),s=e.importClause&&e.importClause.namedBindings?this.convertNamedImportBindings(e.importClause.namedBindings):[];e.importClause&&e.importClause.name&&s.push({type:"ImportDefaultSpecifier",local:N(e.importClause.name)}),this.pushStatement(E({type:"ImportDeclaration",specifiers:s,source:t},e))}convertNamedImportBindings(e){return r.isNamedImports(e)?e.elements.map(t=>{const s=N(t.name),i=t.propertyName?N(t.propertyName):s;return{type:"ImportSpecifier",local:s,imported:i}}):[{type:"ImportNamespaceSpecifier",local:N(e.name)}]}convertExportSpecifier(e){const t=N(e.name);return{type:"ExportSpecifier",exported:t,local:e.propertyName?N(e.propertyName):t}}}const Ae=m(()=>{const n=new Map,e=new Map;return{name:"dts-transform",options({onLog:t,...s}){return{...s,onLog(i,o,c){i==="warn"&&o.code==="CIRCULAR_DEPENDENCY"||(t?t(i,o,c):c(i,o))},treeshake:{moduleSideEffects:"no-external",propertyReadSideEffects:!0,unknownGlobalSideEffects:!1}}},outputOptions(t){return{...t,chunkFileNames:t.chunkFileNames||"[name]-[hash].d.ts",entryFileNames:t.entryFileNames||"[name].d.ts",format:"es",exports:"named",compact:!1,freeze:!0,interop:"esModule",generatedCode:Object.assign({symbols:!1},t.generatedCode),strict:!1}},transform(t,s){const i=B(s),o=this.getModuleIds(),c=Array.from(o).find(g=>B(g)===i),l=!!(c&&this.getModuleInfo(c)?.isEntry),p=!!(c&&_.test(c));let f=j(s,t);const u=Ce({sourceFile:f,isEntry:l,isJSON:p});n.set(f.fileName,u.typeReferences),e.set(f.fileName,u.fileReferences),t=u.code.toString(),f=j(s,t);const h=$e({sourceFile:f});return process.env.DTS_DUMP_AST&&(console.log(s),console.log(t),console.log(JSON.stringify(h.ast.body,void 0,2))),{code:t,ast:h.ast,map:u.code.generateMap()}},renderChunk(t,s,i){const o=j(s.fileName,t),c=new ge(o),l=new Set,p=new Set;for(const h of Object.keys(s.modules)){for(const g of n.get(h.split("\\").join("/"))||[])l.add(g);for(const g of e.get(h.split("\\").join("/"))||[])if(g.startsWith(".")){const w=T.join(T.dirname(h),g),C=i.file&&T.dirname(i.file)||s.facadeModuleId&&T.dirname(s.facadeModuleId)||".";let D=T.relative(C,w).split("\\").join("/");D[0]!=="."&&(D="./"+D),p.add(D)}else p.add(g)}let f=ie(Array.from(p,h=>`/// <reference path="${h}" />`));return f+=ie(Array.from(l,h=>`/// <reference types="${h}" />`)),f+=c.fix(),f||(f+=`
|
|
30
|
-
export { };`),new De(s.fileName,f,!!i.sourcemap).fix()}}},"transform");function ie(n){return n.length?n.join(`
|
|
31
|
-
`)+`
|
|
32
|
-
`:""}m(ie,"writeBlock");const Pe=/\.([cm]ts|[tj]sx?)$/;function G({entries:n,programs:e,resolvedOptions:{compilerOptions:t,tsconfig:s}},i,o){if(!e.length&&k.test(i))return{code:o};const c=n.includes(i),l=e.find(p=>{if(c)return p.getRootFileNames().includes(i);{const f=p.getSourceFile(i);return f&&p.isSourceFileFromExternalLibrary(f)?!1:!!f}});if(l){const p=l.getSourceFile(i);return{code:p?.getFullText(),source:p,program:l}}else if(r.sys.fileExists(i)){const p=me(i,t,s);e.push(p);const f=p.getSourceFile(i);return{code:f?.getFullText(),source:f,program:p}}else return null}m(G,"getModule");const ne=m((n={})=>{const e=Ae(),t={entries:[],programs:[],resolvedOptions:pe(n)};return{name:"dts",outputOptions:e.outputOptions,renderChunk:e.renderChunk,options(s){let{input:i=[]}=s;if(!Array.isArray(i))i=typeof i=="string"?[i]:Object.values(i);else if(i.length>1){s.input={};for(const o of i){let c=B(o);T.isAbsolute(o)?c=T.basename(c):c=T.normalize(c),s.input[c]=o}}return t.programs=ue(Object.values(i),t.resolvedOptions.compilerOptions,t.resolvedOptions.tsconfig),e.options.call(this,s)},transform(s,i){if(!Pe.test(i)&&!_.test(i))return null;const o=m(f=>{if(f.program){const u=T.dirname(i);f.program.getSourceFiles().map(g=>g.fileName).filter(g=>g.startsWith(u)).forEach(this.addWatchFile)}},"watchFiles"),c=m(()=>{const f=G(t,i,s);return f?(o(f),e.transform.call(this,f.code,i)):null},"handleDtsFile"),l=m(()=>{const f=J(i),u=G(t,f,s);return u?(o(u),e.transform.call(this,u.code,f)):null},"treatTsAsDts"),p=m(()=>{const f=G(t,i,s);if(!f||!f.source||!f.program)return null;o(f);const u=J(i);let h;const{emitSkipped:g,diagnostics:w}=f.program.emit(f.source,(C,D)=>{h=e.transform.call(this,D,u)},void 0,!0,void 0,!0);if(g){const C=w.filter(D=>D.category===r.DiagnosticCategory.Error);C.length&&(console.error(r.formatDiagnostics(C,V)),this.error("Failed to compile. Check the logs above."))}return h},"generateDts");return k.test(i)?c():_.test(i)?p():l()??p()},resolveId(s,i){if(!i){t.entries.push(T.resolve(s));return}i=i.split("\\").join("/");let o=t.resolvedOptions.compilerOptions;if(t.resolvedOptions.tsconfig){const l=s.startsWith(".")?T.resolve(T.dirname(i),s):s;o=z(l,t.resolvedOptions.compilerOptions,t.resolvedOptions.tsconfig).compilerOptions}const{resolvedModule:c}=r.resolveModuleName(s,i,o,r.sys);if(c)return!t.resolvedOptions.respectExternal&&c.isExternalLibraryImport?{id:s,external:!0}:{id:T.resolve(c.resolvedFileName)}}}},"plugin");export{ne as default,ne as dts};
|