pkgroll 2.23.1 → 2.24.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/LICENSE +379 -0
- package/README.md +25 -0
- package/dist/cli.mjs +39 -25
- package/dist/rollup-plugin-dts-BUQLp_V-.mjs +36 -0
- package/package.json +1 -1
- package/dist/rollup-plugin-dts-DArk-PDL.mjs +0 -35
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var Xe=Object.defineProperty;var c=(n,e)=>Xe(n,"name",{value:e,configurable:!0});import{createRequire as Qe}from"node:module";const Ye=Qe(import.meta.url);import*as T from"node:path";import i from"typescript";import{createRequire as Ze}from"node:module";import X from"magic-string";import ce from"node:fs/promises";var le=44,et=59,ue="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",pe=new Uint8Array(64),fe=new Uint8Array(128);for(let n=0;n<ue.length;n++){const e=ue.charCodeAt(n);pe[n]=e,fe[e]=n}function K(n,e){let t=0,r=0,s=0;do{const a=n.next();s=fe[a],t|=(s&31)<<r,r+=5}while(s&32);const o=t&1;return t>>>=1,o&&(t=-2147483648|-t),e+t}c(K,"decodeInteger");function z(n,e,t){let r=e-t;r=r<0?-r<<1|1:r<<1;do{let s=r&31;r>>>=5,r>0&&(s|=32),n.write(pe[s])}while(r>0);return e}c(z,"encodeInteger");function me(n,e){return n.pos>=e?!1:n.peek()!==le}c(me,"hasMoreVlq");var de=1024*16,he=typeof TextDecoder<"u"?new TextDecoder:typeof Buffer<"u"?{decode(n){return Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString()}}:{decode(n){let e="";for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return e}},tt=class{static{c(this,"StringWriter")}constructor(){this.pos=0,this.out="",this.buffer=new Uint8Array(de)}write(n){const{buffer:e}=this;e[this.pos++]=n,this.pos===de&&(this.out+=he.decode(e),this.pos=0)}flush(){const{buffer:n,out:e,pos:t}=this;return t>0?e+he.decode(n.subarray(0,t)):e}},nt=class{static{c(this,"StringReader")}constructor(n){this.pos=0,this.buffer=n}next(){return this.buffer.charCodeAt(this.pos++)}peek(){return this.buffer.charCodeAt(this.pos)}indexOf(n){const{buffer:e,pos:t}=this,r=e.indexOf(n,t);return r===-1?e.length:r}};function Q(n){const{length:e}=n,t=new nt(n),r=[];let s=0,o=0,a=0,l=0,m=0;do{const p=t.indexOf(";"),d=[];let h=!0,u=0;for(s=0;t.pos<p;){let g;s=K(t,s),s<u&&(h=!1),u=s,me(t,p)?(o=K(t,o),a=K(t,a),l=K(t,l),me(t,p)?(m=K(t,m),g=[s,o,a,l,m]):g=[s,o,a,l]):g=[s],d.push(g),t.pos++}h||rt(d),r.push(d),t.pos=p+1}while(t.pos<=e);return r}c(Q,"decode");function rt(n){n.sort(st)}c(rt,"sort");function st(n,e){return n[0]-e[0]}c(st,"sortComparator$1");function ge(n){const e=new tt;let t=0,r=0,s=0,o=0;for(let a=0;a<n.length;a++){const l=n[a];if(a>0&&e.write(et),l.length===0)continue;let m=0;for(let p=0;p<l.length;p++){const d=l[p];p>0&&e.write(le),m=z(e,d[0],m),d.length!==1&&(t=z(e,d[1],t),r=z(e,d[2],r),s=z(e,d[3],s),d.length!==4&&(o=z(e,d[4],o)))}}return e.flush()}c(ge,"encode");const it=/^[\w+.-]+:\/\//,ot=/^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/,at=/^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;function ct(n){return it.test(n)}c(ct,"isAbsoluteUrl");function lt(n){return n.startsWith("//")}c(lt,"isSchemeRelativeUrl");function ye(n){return n.startsWith("/")}c(ye,"isAbsolutePath");function ut(n){return n.startsWith("file:")}c(ut,"isFileUrl");function xe(n){return/^[.?#]/.test(n)}c(xe,"isRelative");function q(n){const e=ot.exec(n);return Se(e[1],e[2]||"",e[3],e[4]||"",e[5]||"/",e[6]||"",e[7]||"")}c(q,"parseAbsoluteUrl");function pt(n){const e=at.exec(n),t=e[2];return Se("file:","",e[1]||"","",ye(t)?t:"/"+t,e[3]||"",e[4]||"")}c(pt,"parseFileUrl");function Se(n,e,t,r,s,o,a){return{scheme:n,user:e,host:t,port:r,path:s,query:o,hash:a,type:7}}c(Se,"makeUrl");function ve(n){if(lt(n)){const t=q("http:"+n);return t.scheme="",t.type=6,t}if(ye(n)){const t=q("http://foo.com"+n);return t.scheme="",t.host="",t.type=5,t}if(ut(n))return pt(n);if(ct(n))return q(n);const e=q("http://foo.com/"+n);return e.scheme="",e.host="",e.type=n?n.startsWith("?")?3:n.startsWith("#")?2:4:1,e}c(ve,"parseUrl");function ft(n){if(n.endsWith("/.."))return n;const e=n.lastIndexOf("/");return n.slice(0,e+1)}c(ft,"stripPathFilename");function mt(n,e){Ee(e,e.type),n.path==="/"?n.path=e.path:n.path=ft(e.path)+n.path}c(mt,"mergePaths");function Ee(n,e){const t=e<=4,r=n.path.split("/");let s=1,o=0,a=!1;for(let m=1;m<r.length;m++){const p=r[m];if(!p){a=!0;continue}if(a=!1,p!=="."){if(p===".."){o?(a=!0,o--,s--):t&&(r[s++]=p);continue}r[s++]=p,o++}}let l="";for(let m=1;m<s;m++)l+="/"+r[m];(!l||a&&!l.endsWith("/.."))&&(l+="/"),n.path=l}c(Ee,"normalizePath");function dt(n,e){if(!n&&!e)return"";const t=ve(n);let r=t.type;if(e&&r!==7){const o=ve(e),a=o.type;switch(r){case 1:t.hash=o.hash;case 2:t.query=o.query;case 3:case 4:mt(t,o);case 5:t.user=o.user,t.host=o.host,t.port=o.port;case 6:t.scheme=o.scheme}a>r&&(r=a)}Ee(t,r);const s=t.query+t.hash;switch(r){case 2:case 3:return s;case 4:{const o=t.path.slice(1);return o?xe(e||n)&&!xe(o)?"./"+o+s:o+s:s||"."}case 5:return t.path+s;default:return t.scheme+"//"+t.user+t.host+t.port+t.path+s}}c(dt,"resolve");function ht(n){if(!n)return"";const e=n.lastIndexOf("/");return n.slice(0,e+1)}c(ht,"stripFilename");function gt(n,e){const t=ht(n),r=e?e+"/":"";return s=>dt(r+(s||""),t)}c(gt,"resolver");var k=0;function yt(n,e){const t=Te(n,0);if(t===n.length)return n;e||(n=n.slice());for(let r=t;r<n.length;r=Te(n,r+1))n[r]=St(n[r],e);return n}c(yt,"maybeSort");function Te(n,e){for(let t=e;t<n.length;t++)if(!xt(n[t]))return t;return n.length}c(Te,"nextUnsortedSegmentLine");function xt(n){for(let e=1;e<n.length;e++)if(n[e][k]<n[e-1][k])return!1;return!0}c(xt,"isSorted");function St(n,e){return e||(n=n.slice()),n.sort(vt)}c(St,"sortSegments");function vt(n,e){return n[k]-e[k]}c(vt,"sortComparator");var H=!1;function Et(n,e,t,r){for(;t<=r;){const s=t+(r-t>>1),o=n[s][k]-e;if(o===0)return H=!0,s;o<0?t=s+1:r=s-1}return H=!1,t-1}c(Et,"binarySearch");function Tt(n,e,t){for(let r=t-1;r>=0&&n[r][k]===e;t=r--);return t}c(Tt,"lowerBound");function Nt(){return{lastKey:-1,lastNeedle:-1,lastIndex:-1}}c(Nt,"memoizedState");function Ct(n,e,t,r){const{lastKey:s,lastNeedle:o,lastIndex:a}=t;let l=0,m=n.length-1;if(r===s){if(e===o)return H=a!==-1&&n[a][k]===e,a;e>=o?l=a===-1?0:a:m=a}return t.lastKey=r,t.lastNeedle=e,t.lastIndex=Et(n,e,l,m)}c(Ct,"memoizedBinarySearch");function wt(n){return typeof n=="string"?JSON.parse(n):n}c(wt,"parse$1");var Ne=class{static{c(this,"TraceMap")}constructor(n,e){const t=typeof n=="string";if(!t&&n._decodedMemo)return n;const r=wt(n),{version:s,file:o,names:a,sourceRoot:l,sources:m,sourcesContent:p}=r;this.version=s,this.file=o,this.names=a||[],this.sourceRoot=l,this.sources=m,this.sourcesContent=p,this.ignoreList=r.ignoreList||r.x_google_ignoreList||void 0;const d=gt(e,l);this.resolvedSources=m.map(d);const{mappings:h}=r;if(typeof h=="string")this._encoded=h,this._decoded=void 0;else if(Array.isArray(h))this._encoded=void 0,this._decoded=yt(h,t);else throw r.sections?new Error("TraceMap passed sectioned source map, please use FlattenMap export instead"):new Error(`invalid source map: ${JSON.stringify(r)}`);this._decodedMemo=Nt(),this._bySources=void 0,this._bySourceMemos=void 0}};function Ln(n){return n}c(Ln,"cast$1");function Ce(n){var e;return(e=n)._decoded||(e._decoded=Q(n._encoded))}c(Ce,"decodedMappings");function Dt(n,e,t){const r=Ce(n);if(e>=r.length)return null;const s=r[e],o=bt(s,n._decodedMemo,e,t);return o===-1?null:s[o]}c(Dt,"traceSegment");function bt(n,e,t,r,s){let o=Ct(n,r,e,t);return H&&(o=Tt(n,r,o)),o===-1||o===n.length?-1:o}c(bt,"traceSegmentInternal");var Y=class{static{c(this,"SetArray")}constructor(){this._indexes={__proto__:null},this.array=[]}};function _n(n){return n}c(_n,"cast");function we(n,e){return n._indexes[e]}c(we,"get");function V(n,e){const t=we(n,e);if(t!==void 0)return t;const{array:r,_indexes:s}=n,o=r.push(e);return s[e]=o-1}c(V,"put");function It(n,e){const t=we(n,e);if(t===void 0)return;const{array:r,_indexes:s}=n;for(let o=t+1;o<r.length;o++){const a=r[o];r[o-1]=a,s[a]--}s[e]=void 0,r.pop()}c(It,"remove");var Mt=0,Ft=1,Ot=2,Rt=3,At=4,De=-1,Pt=class{static{c(this,"GenMapping")}constructor({file:n,sourceRoot:e}={}){this._names=new Y,this._sources=new Y,this._sourcesContent=[],this._mappings=[],this.file=n,this.sourceRoot=e,this._ignoreList=new Y}};function $n(n){return n}c($n,"cast2");var Lt=c((n,e,t,r,s,o,a,l)=>kt(!0,n,e,t,r,s,o,a),"maybeAddSegment");function _t(n,e,t){const{_sources:r,_sourcesContent:s}=n,o=V(r,e);s[o]=t}c(_t,"setSourceContent");function $t(n,e,t=!0){const{_sources:r,_sourcesContent:s,_ignoreList:o}=n,a=V(r,e);a===s.length&&(s[a]=null),t?V(o,a):It(o,a)}c($t,"setIgnore");function be(n){const{_mappings:e,_sources:t,_sourcesContent:r,_names:s,_ignoreList:o}=n;return Kt(e),{version:3,file:n.file||void 0,names:s.array,sourceRoot:n.sourceRoot||void 0,sources:t.array,sourcesContent:r,mappings:e,ignoreList:o.array}}c(be,"toDecodedMap");function Bt(n){const e=be(n);return Object.assign({},e,{mappings:ge(e.mappings)})}c(Bt,"toEncodedMap");function kt(n,e,t,r,s,o,a,l,m){const{_mappings:p,_sources:d,_sourcesContent:h,_names:u}=e,g=jt(p,t),x=Ut(g,r);if(!s)return zt(g,x)?void 0:Ie(g,x,[r]);const S=V(d,s),E=l?V(u,l):De;if(S===h.length&&(h[S]=null),!Vt(g,x,S,o,a,E))return Ie(g,x,l?[r,S,o,a,E]:[r,S,o,a])}c(kt,"addSegmentInternal");function jt(n,e){for(let t=n.length;t<=e;t++)n[t]=[];return n[e]}c(jt,"getIndex");function Ut(n,e){let t=n.length;for(let r=t-1;r>=0;t=r--){const s=n[r];if(e>=s[Mt])break}return t}c(Ut,"getColumnIndex");function Ie(n,e,t){for(let r=n.length;r>e;r--)n[r]=n[r-1];n[e]=t}c(Ie,"insert");function Kt(n){const{length:e}=n;let t=e;for(let r=t-1;r>=0&&!(n[r].length>0);t=r,r--);t<e&&(n.length=t)}c(Kt,"removeEmptyFinalLines");function zt(n,e){return e===0?!0:n[e-1].length===1}c(zt,"skipSourceless");function Vt(n,e,t,r,s,o){if(e===0)return!1;const a=n[e-1];return a.length===1?!1:t===a[Ft]&&r===a[Ot]&&s===a[Rt]&&o===(a.length===5?a[At]:De)}c(Vt,"skipSource");var Me=Fe("",-1,-1,"",null,!1),Jt=[];function Fe(n,e,t,r,s,o){return{source:n,line:e,column:t,name:r,content:s,ignore:o}}c(Fe,"SegmentObject");function Oe(n,e,t,r,s){return{map:n,sources:e,source:t,content:r,ignore:s}}c(Oe,"Source");function Re(n,e){return Oe(n,e,"",null,!1)}c(Re,"MapSource");function Wt(n,e,t){return Oe(null,Jt,n,e,t)}c(Wt,"OriginalSource");function Gt(n){const e=new Pt({file:n.map.file}),{sources:t,map:r}=n,s=r.names,o=Ce(r);for(let a=0;a<o.length;a++){const l=o[a];for(let m=0;m<l.length;m++){const p=l[m],d=p[0];let h=Me;if(p.length!==1){const D=t[p[1]];if(h=Ae(D,p[2],p[3],p.length===5?s[p[4]]:""),h==null)continue}const{column:u,line:g,name:x,content:S,source:E,ignore:N}=h;Lt(e,a,d,E,g,u,x),E&&S!=null&&_t(e,E,S),N&&$t(e,E,!0)}}return e}c(Gt,"traceMappings");function Ae(n,e,t,r){if(!n.map)return Fe(n.source,e,t,r,n.content,n.ignore);const s=Dt(n.map,e,t);return s==null?null:s.length===1?Me:Ae(n.sources[s[1]],s[2],s[3],s.length===5?n.map.names[s[4]]:r)}c(Ae,"originalPositionFor");function qt(n){return Array.isArray(n)?n:[n]}c(qt,"asArray");function Ht(n,e){const t=qt(n).map(o=>new Ne(o,"")),r=t.pop();for(let o=0;o<t.length;o++)if(t[o].sources.length>1)throw new Error(`Transformation map ${o} must have exactly one source file.
|
|
2
|
+
Did you specify these with the most recent transformation maps first?`);let s=Pe(r,e,"",0);for(let o=t.length-1;o>=0;o--)s=Re(t[o],[s]);return s}c(Ht,"buildSourceMapTree");function Pe(n,e,t,r){const{resolvedSources:s,sourcesContent:o,ignoreList:a}=n,l=r+1,m=s.map((p,d)=>{const h={importer:t,depth:l,source:p||"",content:void 0,ignore:void 0},u=e(h.source,h),{source:g}=h;if(u)return Pe(new Ne(u,g),e,g,l);const x=o?o[d]:null,S=a?a.includes(d):!1;return Wt(g,x,S)});return Re(n,m)}c(Pe,"build");var Xt=class{static{c(this,"SourceMap")}constructor(n,e){const t=e.decodedMappings?be(n):Bt(n);this.version=t.version,this.file=t.file,this.mappings=t.mappings,this.names=t.names,this.ignoreList=t.ignoreList,this.sourceRoot=t.sourceRoot,this.sources=t.sources,e.excludeContent||(this.sourcesContent=t.sourcesContent)}toString(){return JSON.stringify(this)}};function Qt(n,e,t){const r={excludeContent:!1,decodedMappings:!1},s=Ht(n,e);return new Xt(Gt(s),r)}c(Qt,"remapping");function Yt(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}c(Yt,"getDefaultExportFromCjs");var Z={},Le;function Zt(){return Le||(Le=1,(function(n){Object.defineProperty(n,"commentRegex",{get:c(function(){return/^\s*?\/[\/\*][@#]\s+?sourceMappingURL=data:(((?:application|text)\/json)(?:;charset=([^;,]+?)?)?)?(?:;(base64))?,(.*?)$/mg},"getCommentRegex")}),Object.defineProperty(n,"mapFileCommentRegex",{get:c(function(){return/(?:\/\/[@#][ \t]+?sourceMappingURL=([^\s'"`]+?)[ \t]*?$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^*]+?)[ \t]*?(?:\*\/){1}[ \t]*?$)/mg},"getMapFileCommentRegex")});var e;typeof Buffer<"u"?typeof Buffer.from=="function"?e=t:e=r:e=s;function t(u){return Buffer.from(u,"base64").toString()}c(t,"decodeBase64WithBufferFrom");function r(u){if(typeof value=="number")throw new TypeError("The value to decode must not be of type number.");return new Buffer(u,"base64").toString()}c(r,"decodeBase64WithNewBuffer");function s(u){return decodeURIComponent(escape(atob(u)))}c(s,"decodeBase64WithAtob");function o(u){return u.split(",").pop()}c(o,"stripComment");function a(u,g){var x=n.mapFileCommentRegex.exec(u),S=x[1]||x[2];try{var u=g(S);return u!=null&&typeof u.catch=="function"?u.catch(E):u}catch(N){E(N)}function E(N){throw new Error("An error occurred while trying to read the map file at "+S+`
|
|
3
|
+
`+N.stack)}c(E,"throwError")}c(a,"readFromFileMap");function l(u,g){g=g||{},g.hasComment&&(u=o(u)),g.encoding==="base64"?u=e(u):g.encoding==="uri"&&(u=decodeURIComponent(u)),(g.isJSON||g.encoding)&&(u=JSON.parse(u)),this.sourcemap=u}c(l,"Converter"),l.prototype.toJSON=function(u){return JSON.stringify(this.sourcemap,null,u)},typeof Buffer<"u"?typeof Buffer.from=="function"?l.prototype.toBase64=m:l.prototype.toBase64=p:l.prototype.toBase64=d;function m(){var u=this.toJSON();return Buffer.from(u,"utf8").toString("base64")}c(m,"encodeBase64WithBufferFrom");function p(){var u=this.toJSON();if(typeof u=="number")throw new TypeError("The json to encode must not be of type number.");return new Buffer(u,"utf8").toString("base64")}c(p,"encodeBase64WithNewBuffer");function d(){var u=this.toJSON();return btoa(unescape(encodeURIComponent(u)))}c(d,"encodeBase64WithBtoa"),l.prototype.toURI=function(){var u=this.toJSON();return encodeURIComponent(u)},l.prototype.toComment=function(u){var g,x,S;return u!=null&&u.encoding==="uri"?(g="",x=this.toURI()):(g=";base64",x=this.toBase64()),S="sourceMappingURL=data:application/json;charset=utf-8"+g+","+x,u!=null&&u.multiline?"/*# "+S+" */":"//# "+S},l.prototype.toObject=function(){return JSON.parse(this.toJSON())},l.prototype.addProperty=function(u,g){if(this.sourcemap.hasOwnProperty(u))throw new Error('property "'+u+'" already exists on the sourcemap, use set property instead');return this.setProperty(u,g)},l.prototype.setProperty=function(u,g){return this.sourcemap[u]=g,this},l.prototype.getProperty=function(u){return this.sourcemap[u]},n.fromObject=function(u){return new l(u)},n.fromJSON=function(u){return new l(u,{isJSON:!0})},n.fromURI=function(u){return new l(u,{encoding:"uri"})},n.fromBase64=function(u){return new l(u,{encoding:"base64"})},n.fromComment=function(u){var g,x;return u=u.replace(/^\/\*/g,"//").replace(/\*\/$/g,""),g=n.commentRegex.exec(u),x=g&&g[4]||"uri",new l(u,{encoding:x,hasComment:!0})};function h(u){return new l(u,{isJSON:!0})}c(h,"makeConverter"),n.fromMapFileComment=function(u,g){if(typeof g=="string")throw new Error("String directory paths are no longer supported with `fromMapFileComment`\nPlease review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading");var x=a(u,g);return x!=null&&typeof x.then=="function"?x.then(h):h(x)},n.fromSource=function(u){var g=u.match(n.commentRegex);return g?n.fromComment(g.pop()):null},n.fromMapFileSource=function(u,g){if(typeof g=="string")throw new Error("String directory paths are no longer supported with `fromMapFileSource`\nPlease review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading");var x=u.match(n.mapFileCommentRegex);return x?n.fromMapFileComment(x.pop(),g):null},n.removeComments=function(u){return u.replace(n.commentRegex,"")},n.removeMapFileComments=function(u){return u.replace(n.mapFileCommentRegex,"")},n.generateMapFileComment=function(u,g){var x="sourceMappingURL="+u;return g&&g.multiline?"/*# "+x+" */":"//# "+x}})(Z)),Z}c(Zt,"requireConvertSourceMap");var en=Zt(),_e=Yt(en);function tn(n){return{...n,compilerOptions:n.compilerOptions??{},respectExternal:n.respectExternal??!1,includeExternal:n.includeExternal??[],sourcemap:n.sourcemap??!1}}c(tn,"resolveDefaultOptions");const j=/\.d\.(c|m)?tsx?$/,ee=/\.json$/,$e=/((\.d)?\.(c|m)?(t|j)sx?|\.json)$/;function te(n){return n.replace($e,"")}c(te,"trimExtension");function Be(n){return n.replace($e,".d.ts")}c(Be,"getDeclarationId");function J(n,e){return i.createSourceFile(n,e,i.ScriptTarget.Latest,!0)}c(J,"parse");const ne={getCurrentDirectory:c(()=>i.sys.getCurrentDirectory(),"getCurrentDirectory"),getNewLine:c(()=>i.sys.newLine,"getNewLine"),getCanonicalFileName:i.sys.useCaseSensitiveFileNames?n=>n:n=>n.toLowerCase()},nn={declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!0,target:i.ScriptTarget.ESNext,resolveJsonModule:!0},W=new Map,U=c((...n)=>process.env.DTS_LOG_CACHE?console.log("[cache]",...n):null,"logCache");function ke([n,e],t){for(U(n),W.set(n,t);n!==e&&n!==T.dirname(n);){if(n=T.dirname(n),U("up",n),W.has(n))return U("has",n);W.set(n,t)}}c(ke,"cacheConfig");function re(n,e,t,r){const s={...nn,...e,...r===!0&&{declarationMap:!0}};let o=T.dirname(n),a=[];const l=t||o;if(W.has(l))U("HIT",l);else{U("miss",l);const h=t?T.resolve(process.cwd(),t):i.findConfigFile(o,i.sys.fileExists);if(!h)return{dtsFiles:a,dirName:o,compilerOptions:s};const u=o;o=T.dirname(h);const{config:g,error:x}=i.readConfigFile(h,i.sys.readFile);if(x)return console.error(i.formatDiagnostic(x,ne)),{dtsFiles:a,dirName:o,compilerOptions:s};U("tsconfig",g);const S=i.parseJsonConfigFileContent(g,i.sys,o);ke(t?[t,t]:[u,o],S)}const{fileNames:m,options:p,errors:d}=W.get(l);return a=m.filter(h=>j.test(h)),d.length?(console.error(i.formatDiagnostics(d,ne)),{dtsFiles:a,dirName:o,compilerOptions:s}):{dtsFiles:a,dirName:o,compilerOptions:{...p,...s}}}c(re,"getCompilerOptions");function rn(n,e,t,r){const{dtsFiles:s,compilerOptions:o}=re(n,e,t,r);return i.createProgram([n].concat(Array.from(s)),o,i.createCompilerHost(o,!0))}c(rn,"createProgram$1");function sn(n,e,t,r){const s=[],o=new Set;let a=[],l="",m={};for(let p of n){if(j.test(p))continue;p=T.resolve(p);const d=re(p,e,t,r);if(d.dtsFiles.forEach(o.add,o),!a.length){a.push(p),{dirName:l,compilerOptions:m}=d;continue}if(d.dirName===l)a.push(p);else{const h=i.createCompilerHost(m,!0),u=i.createProgram(a.concat(Array.from(o)),m,h);s.push(u),a=[p],{dirName:l,compilerOptions:m}=d}}if(a.length){const p=i.createCompilerHost(m,!0),d=i.createProgram(a.concat(Array.from(o)),m,p);s.push(d)}return s}c(sn,"createPrograms");function on(){let n;try{return{codeFrameColumns:n}=Ye("@babel/code-frame"),n}catch{try{return{codeFrameColumns:n}=Ze(import.meta.url)("@babel/code-frame"),n}catch{}}}c(on,"getCodeFrame");function an(n){const e=n.getSourceFile(),t=e.getLineAndCharacterOfPosition(n.getStart()),r=e.getLineAndCharacterOfPosition(n.getEnd());return{start:{line:t.line+1,column:t.character+1},end:{line:r.line+1,column:r.character+1}}}c(an,"getLocation");function cn(n){const e=on(),r=n.getSourceFile().getFullText(),s=an(n);return e?`
|
|
4
|
+
`+e(r,s,{highlightCode:!0}):`
|
|
5
|
+
${s.start.line}:${s.start.column}: \`${n.getFullText().trim()}\``}c(cn,"frameNode");class w extends Error{static{c(this,"UnsupportedSyntaxError")}constructor(e,t="Syntax not yet supported"){super(`${t}
|
|
6
|
+
${cn(e)}`)}}class ln{static{c(this,"NamespaceFixer")}constructor(e){this.sourceFile=e}findNamespaces(){const e=[],t={};for(const r of this.sourceFile.statements){const s={start:r.getStart(),end:r.getEnd()};if(i.isEmptyStatement(r)){e.unshift({name:"",exports:[],location:s});continue}if((i.isImportDeclaration(r)||i.isExportDeclaration(r))&&r.moduleSpecifier&&i.isStringLiteral(r.moduleSpecifier)){const{text:d}=r.moduleSpecifier;if(d.startsWith(".")&&(d.endsWith(".d.ts")||d.endsWith(".d.cts")||d.endsWith(".d.mts"))){const h=r.moduleSpecifier.getStart()+1,u=r.moduleSpecifier.getEnd()-1;e.unshift({name:"",exports:[],location:{start:h,end:u},textBeforeCodeAfter:d.replace(/\.d\.ts$/,".js").replace(/\.d\.cts$/,".cjs").replace(/\.d\.mts$/,".mjs")})}}if(i.isModuleDeclaration(r)&&r.body&&i.isModuleBlock(r.body)){for(const d of r.body.statements)if(i.isExportDeclaration(d)&&d.exportClause){if(i.isNamespaceExport(d.exportClause))continue;for(const h of d.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(r)?t[r.name.getText()]={type:"class",generics:r.typeParameters}:i.isFunctionDeclaration(r)?t[r.name.getText()]={type:"function"}:i.isInterfaceDeclaration(r)?t[r.name.getText()]={type:"interface",generics:r.typeParameters}:i.isTypeAliasDeclaration(r)?t[r.name.getText()]={type:"type",generics:r.typeParameters}:i.isModuleDeclaration(r)&&i.isIdentifier(r.name)?t[r.name.getText()]={type:"namespace"}:i.isEnumDeclaration(r)&&(t[r.name.getText()]={type:"enum"}),!i.isVariableStatement(r))continue;const{declarations:o}=r.declarationList;if(o.length!==1)continue;const a=o[0],l=a.name.getText();if(!a.initializer||!i.isCallExpression(a.initializer)){t[l]={type:"var"};continue}const m=a.initializer.arguments[0];if(!a.initializer.expression.getFullText().includes("/*#__PURE__*/Object.freeze")||!i.isObjectLiteralExpression(m))continue;const p=[];for(const d of m.properties){if(!i.isPropertyAssignment(d)||!(i.isIdentifier(d.name)||i.isStringLiteral(d.name))||d.name.text!=="__proto__"&&!i.isIdentifier(d.initializer))throw new w(d,"Expected a property assignment");d.name.text!=="__proto__"&&p.push({exportedName:d.name.text,localName:d.initializer.getText()})}e.unshift({name:l,exports:p,location:s})}return{namespaces:e,itemTypes:t}}fix(){let e=this.sourceFile.getFullText();const{namespaces:t,itemTypes:r}=this.findNamespaces();for(const s of t){const o=e.slice(s.location.end);e=e.slice(0,s.location.start);for(const{exportedName:a,localName:l}of s.exports)if(a===l){const{type:m,generics:p}=r[l]||{};if(m==="interface"||m==="type"){const d=je(p);e+=`type ${s.name}_${a}${d.in} = ${l}${d.out};
|
|
7
|
+
`}else if(m==="enum"||m==="class"){const d=je(p);e+=`type ${s.name}_${a}${d.in} = ${l}${d.out};
|
|
8
|
+
`,e+=`declare const ${s.name}_${a}: typeof ${l};
|
|
9
|
+
`}else m==="namespace"?e+=`import ${s.name}_${a} = ${l};
|
|
10
|
+
`:e+=`declare const ${s.name}_${a}: typeof ${l};
|
|
11
|
+
`}if(s.name){e+=`declare namespace ${s.name} {
|
|
12
|
+
`,e+=` export {
|
|
13
|
+
`;for(const{exportedName:a,localName:l}of s.exports)a===l?e+=` ${s.name}_${a} as ${a},
|
|
14
|
+
`:e+=` ${l} as ${a},
|
|
15
|
+
`;e+=` };
|
|
16
|
+
`,e+="}"}e+=s.textBeforeCodeAfter??"",e+=o}return e}}function je(n){return!n||!n.length?{in:"",out:""}:{in:`<${n.map(e=>e.getText()).join(", ")}>`,out:`<${n.map(e=>e.name.getText()).join(", ")}>`}}c(je,"renderTypeParams");let Ue=1;function un(n){return I({type:"Program",sourceType:"module",body:[]},{start:n.getFullStart(),end:n.getEnd()})}c(un,"createProgram");function pn(n){const e={type:"Identifier",name:String(Ue++)};return{ident:e,expr:{type:"AssignmentPattern",left:e,right:n}}}c(pn,"createReference");function M(n){return I({type:"Identifier",name:n.getText()},n)}c(M,"createIdentifier");function fn(n){const e=I({type:"FunctionExpression",id:null,params:[],body:{type:"BlockStatement",body:[]}},n),t=I({type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:String(Ue++)},arguments:[e],optional:!1}},n);return{fn:e,iife:t}}c(fn,"createIIFE");function mn(){const n={type:"ArrayExpression",elements:[]};return{expr:n,stmt:{type:"ReturnStatement",argument:n}}}c(mn,"createReturn");function dn(n,e){return I({type:"FunctionDeclaration",id:I({type:"Identifier",name:i.idText(n)},n),params:[],body:{type:"BlockStatement",body:[]}},e)}c(dn,"createDeclaration");function A(n){if(i.isLiteralExpression(n))return{type:"Literal",value:n.text};if(i.isPropertyAccessExpression(n)){if(i.isPrivateIdentifier(n.name))throw new w(n.name);return I({type:"MemberExpression",computed:!1,optional:!1,object:A(n.expression),property:A(n.name)},{start:n.expression.getStart(),end:n.name.getEnd()})}if(i.isObjectLiteralExpression(n))return I({type:"ObjectExpression",properties:n.properties.map(e=>{if(i.isPropertyAssignment(e))return I({type:"Property",key:i.isIdentifier(e.name)?M(e.name):A(e.name),value:A(e.initializer),kind:"init",method:!1,shorthand:!1,computed:i.isComputedPropertyName(e.name)},e);if(i.isShorthandPropertyAssignment(e))return I({type:"Property",key:M(e.name),value:M(e.name),kind:"init",method:!1,shorthand:!0,computed:!1},e);throw new w(e,"Unsupported property type in object literal")})},n);if(i.isArrayLiteralExpression(n))return I({type:"ArrayExpression",elements:n.elements.map(e=>{if(i.isExpression(e))return A(e);throw new w(e,"Unsupported element type in array literal")})},n);if(i.isIdentifier(n))return M(n);if(n.kind==i.SyntaxKind.NullKeyword)return{type:"Literal",value:null};throw new w(n)}c(A,"convertExpression");function I(n,e){const t="start"in e?e:{start:e.getStart(),end:e.getEnd()};return Object.assign(n,t)}c(I,"withStartEnd");function G(n,e){return(i.getCombinedModifierFlags(n)&e)===e}c(G,"matchesModifier");class hn{static{c(this,"LanguageService")}constructor(e){this.fileName="index.d.ts";const t={getCompilationSettings:c(()=>({noEmit:!0,noResolve:!0,skipLibCheck:!0,declaration:!1,checkJs:!1,declarationMap:!1,target:i.ScriptTarget.ESNext}),"getCompilationSettings"),getScriptFileNames:c(()=>[this.fileName],"getScriptFileNames"),getScriptVersion:c(()=>"1","getScriptVersion"),getScriptSnapshot:c(r=>r===this.fileName?i.ScriptSnapshot.fromString(e):void 0,"getScriptSnapshot"),getCurrentDirectory:c(()=>"","getCurrentDirectory"),getDefaultLibFileName:c(()=>"","getDefaultLibFileName"),fileExists:c(r=>r===this.fileName,"fileExists"),readFile:c(r=>r===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((r,s)=>r+s.references.length,0):0}}class gn{static{c(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=J(e,t),this.code=new X(t)}fix(){return this.analyze(this.source.statements),(this.typeHints.size||this.reExportTypeHints.size)&&(this.service=new hn(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 r=[],s=[],o=e.moduleSpecifier.getText(),a=e.importClause.name,l=e.importClause.namedBindings;if(a){const m=a.text;this.isTypeOnly(m)?this.isUselessImport(a)?t=!0:r.push(`import type ${m} from ${o};`):s.push(`import ${m} from ${o};`)}if(l&&i.isNamespaceImport(l)){const m=l.name.text;this.isTypeOnly(m)?this.isUselessImport(l.name)?t=!0:r.push(`import type * as ${m} from ${o};`):s.push(`import * as ${m} from ${o};`)}if(l&&i.isNamedImports(l)){const m=[],p=[];for(const d of l.elements)this.isTypeOnly(d.name.text)?this.isUselessImport(d.name)?t=!0:m.push(d.getText()):p.push(d.getText());m.length&&r.push(`import type { ${m.join(", ")} } from ${o};`),p.length&&s.push(`import { ${p.join(", ")} } from ${o};`)}(r.length||t)&&this.code.overwrite(e.getStart(),e.getEnd(),[...s,...r].join(`
|
|
17
|
+
${Ke(e)}`))}fixTypeOnlyExport(e){const t=[],r=[],s=e.moduleSpecifier?.getText();if(i.isNamespaceExport(e.exportClause)){const o=e.exportClause.name.text;this.isReExportTypeOnly(o)?t.push(`export type * as ${o} from ${s};`):r.push(`export * as ${o} from ${s};`)}if(i.isNamedExports(e.exportClause)){const o=[],a=[];for(const l of e.exportClause.elements){const m=l.propertyName?.text||l.name.text;(e.moduleSpecifier?this.isReExportTypeOnly(l.name.text):this.isTypeOnly(m))?o.push(l.getText()):a.push(l.getText())}o.length&&t.push(`export type { ${o.join(", ")} }${s?` from ${s}`:""};`),a.length&&r.push(`export { ${a.join(", ")} }${s?` from ${s}`:""};`)}t.length&&this.code.overwrite(e.getStart(),e.getEnd(),[...r,...t].join(`
|
|
18
|
+
${Ke(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 r=t.name.text;this.DEBUG&&console.log(`${t.name.getFullText()} is a type`),this.types.add(r);continue}if(i.isEnumDeclaration(t)||i.isFunctionDeclaration(t)||i.isClassDeclaration(t)||i.isVariableStatement(t)){if(i.isVariableStatement(t))for(const r of t.declarationList.declarations)i.isIdentifier(r.name)&&(this.DEBUG&&console.log(`${r.name.getFullText()} is a value (from var statement)`),this.values.add(r.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),r=this.typeHints.get(e.text);return r&&r+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 Ke(n){const e=n.getFullText().match(/^(?:\n*)([ ]*)/);return" ".repeat(e?.[1]?.length||0)}c(Ke,"getNodeIndent");function ze(n,e,t){for(const r of n.statements)se(e,r),i.isModuleDeclaration(r)&&r.body&&i.isModuleBlock(r.body)&&ze(r.body,e)}c(ze,"preProcessNamespaceBody");function yn({sourceFile:n,isEntry:e,isJSON:t}){const r=new X(n.getFullText()),s=!e&&xn(n),o=new Set,a=new Set;let l="";const m=new Map,p=new Map;for(const f of n.statements){if(i.isEmptyStatement(f)){r.remove(f.getStart(),f.getEnd());continue}if(i.isImportDeclaration(f)){if(!f.importClause)continue;f.importClause.name&&o.add(f.importClause.name.text),f.importClause.namedBindings&&(i.isNamespaceImport(f.importClause.namedBindings)?o.add(f.importClause.namedBindings.name.text):f.importClause.namedBindings.elements.forEach(y=>o.add(y.name.text)))}else if(i.isEnumDeclaration(f)||i.isFunctionDeclaration(f)||i.isInterfaceDeclaration(f)||i.isClassDeclaration(f)||i.isTypeAliasDeclaration(f)||i.isModuleDeclaration(f)){if(f.name){const y=f.name.getText();o.add(y),G(f,i.ModifierFlags.ExportDefault)?l=y:(s&&i.isIdentifier(f.name)||G(f,i.ModifierFlags.Export))&&a.add(y),f.flags&i.NodeFlags.GlobalAugmentation||P(y,[ie(f),Ve(f)])}i.isModuleDeclaration(f)&&(f.body&&i.isModuleBlock(f.body)&&ze(f.body,r),Sn(r,f)),se(r,f)}else if(i.isVariableStatement(f)){const{declarations:y}=f.declarationList,v=G(f,i.ModifierFlags.Export);for(const F of f.declarationList.declarations)if(i.isIdentifier(F.name)){const R=F.name.getText();o.add(R),(s||v)&&a.add(R)}if(se(r,f),y.length===1){const F=y[0];i.isIdentifier(F.name)&&P(F.name.getText(),[ie(f),Ve(f)])}else{const F=y.slice(),R=F.shift();P(R.name.getText(),[ie(f),R.getEnd()]);for(const B of F)i.isIdentifier(B.name)&&P(B.name.getText(),[B.getFullStart(),B.getEnd()])}const{flags:C}=f.declarationList,L=`declare ${C&i.NodeFlags.Let?"let":C&i.NodeFlags.Const?"const":"var"} `,$=f.declarationList.getChildren().find(F=>F.kind===i.SyntaxKind.SyntaxList).getChildren();let _=0;for(const F of $)if(F.kind===i.SyntaxKind.CommaToken)_=F.getStart(),r.remove(_,F.getEnd());else if(_){r.appendLeft(_,`;
|
|
19
|
+
`);const R=F.getFullStart(),B=r.slice(R,F.getStart()),ae=B.length-B.trimStart().length;ae?r.overwrite(R,R+ae,L):r.appendLeft(R,L)}}}for(const f of n.statements){if(N(f),i.isExportAssignment(f)&&!f.isExportEquals&&(i.isObjectLiteralExpression(f.expression)||i.isArrayLiteralExpression(f.expression))){l||(l=b("export_default")),r.overwrite(f.getStart(),f.expression.getStart(),`declare var ${l} = `);continue}if(G(f,i.ModifierFlags.ExportDefault)&&(i.isFunctionDeclaration(f)||i.isClassDeclaration(f))){if(f.name)continue;l||(l=b("export_default"));const y=f.getChildren(),v=y.findIndex($=>$.kind===i.SyntaxKind.ClassKeyword||$.kind===i.SyntaxKind.FunctionKeyword),C=y[v],O=y[v+1];if(O.kind>=i.SyntaxKind.FirstPunctuation&&O.kind<=i.SyntaxKind.LastPunctuation){const $=r.slice(C.getEnd(),O.getStart())!=" ";r.appendLeft(O.getStart(),`${$?" ":""}${l}`)}else r.appendRight(C.getEnd(),` ${l}`)}}for(const f of p.values()){const v=f.pop()[0];for(const C of f)r.move(C[0],C[1],v)}l&&r.append(`
|
|
20
|
+
export default ${l};
|
|
21
|
+
`),a.size&&r.append(`
|
|
22
|
+
export { ${[...a].join(", ")} };
|
|
23
|
+
`),t&&a.size&&(l=b("export_default"),r.append([`
|
|
24
|
+
declare const ${l}: {`,[...a].map(f=>` ${f}: typeof ${f};`).join(`
|
|
25
|
+
`),"};",`export default ${l};
|
|
26
|
+
`].join(`
|
|
27
|
+
`)));for(const[f,y]of m.entries())r.prepend(`import * as ${y} from "${f}";
|
|
28
|
+
`);const d=n.getLineStarts(),h=new Set;for(const f of n.typeReferenceDirectives){h.add(f.fileName);const{line:y}=n.getLineAndCharacterOfPosition(f.pos),v=d[y];let C=n.getLineEndOfPosition(f.pos);r.slice(C,C+1)===`
|
|
29
|
+
`&&(C+=1),r.remove(v,C)}const u=new Set;for(const f of n.referencedFiles){u.add(f.fileName);const{line:y}=n.getLineAndCharacterOfPosition(f.pos),v=d[y];let C=n.getLineEndOfPosition(f.pos);r.slice(C,C+1)===`
|
|
30
|
+
`&&(C+=1),r.remove(v,C)}const g=n.getFullText(),x=i.getLeadingCommentRanges(g,n.endOfFileToken.getFullStart()),S=n.statements[n.statements.length-1],E=S?i.getTrailingCommentRanges(g,S.getEnd()):void 0;for(const f of[...x??[],...E??[]]){if(f.kind!==i.SyntaxKind.SingleLineCommentTrivia)continue;const y=g.slice(f.pos,f.end);if(!/\/\/[#@]\s*sourceMappingURL=/.test(y))continue;let v=f.pos;v>0&&g[v-1]===`
|
|
31
|
+
`&&(v-=1),r.remove(v,f.end);break}return{code:r,typeReferences:h,fileReferences:u};function N(f){if(i.forEachChild(f,N),i.isImportTypeNode(f)){if(!i.isLiteralTypeNode(f.argument)||!i.isStringLiteral(f.argument.literal))throw new w(f,"inline imports should have a literal argument");const y=f.argument.literal.text,v=f.getChildren(),C=v.find(_=>_.kind===i.SyntaxKind.ImportKeyword).getStart();let O=f.getEnd();const L=v.find(_=>_.kind===i.SyntaxKind.DotToken||_.kind===i.SyntaxKind.LessThanToken);L&&(O=L.getStart());const $=D(y);r.overwrite(C,O,$)}}function D(f){let y=m.get(f);return y||(y=b(vn(f)),m.set(f,y)),y}function b(f){let y=f;for(;o.has(y);)y=`_${y}`;return o.add(y),y}function P(f,y){let v=p.get(f);if(!v)v=[y],p.set(f,v);else{const C=v[v.length-1];C[1]===y[0]?C[1]=y[1]:v.push(y)}}}c(yn,"preProcess");function xn(n){let e=!1;for(const t of n.statements){if(i.isExportDeclaration(t)||i.isExportAssignment(t))return!1;(e||i.isImportDeclaration(t)||G(t,i.ModifierFlags.Export))&&(e=!0)}return e}c(xn,"isGlobalModule");function se(n,e){if(!i.canHaveModifiers(e))return;if(e.parent.kind===i.SyntaxKind.SourceFile){let r=!1;const s=i.isEnumDeclaration(e)||i.isClassDeclaration(e)||i.isFunctionDeclaration(e)||i.isModuleDeclaration(e)||i.isVariableStatement(e);for(const o of e.modifiers??[])switch(o.kind){case i.SyntaxKind.ExportKeyword:case i.SyntaxKind.DefaultKeyword:n.remove(o.getStart(),o.getEnd()+1);break;case i.SyntaxKind.DeclareKeyword:r=!0}s&&!r&&n.appendRight(e.getStart(),"declare ")}}c(se,"fixModifiers");function Sn(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 r of t.exportClause.elements)r.propertyName||n.appendLeft(r.name.getEnd(),` as ${r.name.getText()}`)}}}c(Sn,"duplicateExports");function vn(n){return n.replace(/[^a-zA-Z0-9_$]/g,()=>"_")}c(vn,"getSafeName");function ie(n){const e=n.getFullStart();return e+(Je(n,e)?1:0)}c(ie,"getStart");function Ve(n){const e=n.getEnd();return e+(Je(n,e)?1:0)}c(Ve,"getEnd");function Je(n,e){return n.getSourceFile().getFullText()[e]===`
|
|
32
|
+
`}c(Je,"newlineAt");const En=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 We{static{c(this,"DeclarationScope")}constructor({id:e,range:t}){if(this.scopes=[],e)this.declaration=dn(e,t);else{const{iife:s,fn:o}=fn(t);this.iife=s,this.declaration=o}const r=mn();this.declaration.body.body.push(r.stmt),this.returnExpr=r.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:r,expr:s}=pn(e);this.declaration.params.push(s),this.returnExpr.elements.push(r)}pushIdentifierReference(e){this.pushReference(M(e))}convertEntityName(e){return i.isIdentifier(e)?M(e):I({type:"MemberExpression",computed:!1,optional:!1,object:this.convertEntityName(e.left),property:M(e.right)},e)}convertPropertyAccess(e){if(!i.isIdentifier(e.expression)&&!i.isPropertyAccessExpression(e.expression))throw new w(e.expression);if(i.isPrivateIdentifier(e.name))throw new w(e.name);const t=i.isIdentifier(e.expression)?M(e.expression):this.convertPropertyAccess(e.expression);return I({type:"MemberExpression",computed:!1,optional:!1,object:t,property:M(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(M(t));if(i.isPropertyAccessExpression(t))return this.pushReference(this.convertPropertyAccess(t));throw new w(t)}}convertParametersAndType(e){this.convertComputedPropertyName(e);const t=this.convertTypeParameters(e.typeParameters);for(const r of e.parameters)this.convertTypeNode(r.type);this.convertTypeNode(e.type),this.popScope(t)}convertHeritageClauses(e){for(const t of e.heritageClauses||[])for(const r of t.types)this.pushReference(A(r.expression)),this.convertTypeArguments(r)}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 w(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&&!En.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:r,nameType:s}=e;this.convertTypeNode(t.constraint),this.pushScope(),this.pushTypeVariable(t.name),this.convertTypeNode(r),s&&this.convertTypeNode(s),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 w(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 w(e,'namespace must have a "ModuleBlock" body.');const{statements:r}=e.body;for(const s of r){if(i.isEnumDeclaration(s)||i.isFunctionDeclaration(s)||i.isClassDeclaration(s)||i.isInterfaceDeclaration(s)||i.isTypeAliasDeclaration(s)||i.isModuleDeclaration(s)){if(s.name&&i.isIdentifier(s.name))this.pushTypeVariable(s.name);else throw new w(s,"non-Identifier name not supported");continue}if(i.isVariableStatement(s)){for(const o of s.declarationList.declarations)if(i.isIdentifier(o.name))this.pushTypeVariable(o.name);else throw new w(o,"non-Identifier name not supported");continue}if(i.isImportDeclaration(s)){if(s.importClause&&(s.importClause.name&&this.pushTypeVariable(s.importClause.name),s.importClause.namedBindings))if(i.isNamespaceImport(s.importClause.namedBindings))this.pushTypeVariable(s.importClause.namedBindings.name);else for(const o of s.importClause.namedBindings.elements)this.pushTypeVariable(o.name);continue}if(i.isImportEqualsDeclaration(s)){this.pushTypeVariable(s.name);continue}if(!i.isExportDeclaration(s))throw new w(s,"namespace child (hoisting) not supported yet")}for(const s of r){if(i.isVariableStatement(s)){for(const o of s.declarationList.declarations)o.type&&this.convertTypeNode(o.type);continue}if(i.isFunctionDeclaration(s)){this.convertParametersAndType(s);continue}if(i.isInterfaceDeclaration(s)||i.isClassDeclaration(s)){const o=this.convertTypeParameters(s.typeParameters);this.convertHeritageClauses(s),this.convertMembers(s.members),this.popScope(o);continue}if(i.isTypeAliasDeclaration(s)){const o=this.convertTypeParameters(s.typeParameters);this.convertTypeNode(s.type),this.popScope(o);continue}if(i.isModuleDeclaration(s)){this.convertNamespace(s,t);continue}if(!i.isEnumDeclaration(s)&&!i.isImportDeclaration(s)){if(i.isImportEqualsDeclaration(s)){i.isEntityName(s.moduleReference)&&this.pushReference(this.convertEntityName(s.moduleReference));continue}if(i.isExportDeclaration(s)){if(s.exportClause){if(i.isNamespaceExport(s.exportClause))throw new w(s.exportClause);for(const o of s.exportClause.elements){const a=o.propertyName||o.name;this.pushIdentifierReference(a)}}}else throw new w(s,"namespace child (walking) not supported yet")}}this.popScope()}}function Tn({sourceFile:n}){return new Nn(n).transform()}c(Tn,"convert");class Nn{static{c(this,"Transformer")}constructor(e){this.sourceFile=e,this.declarations=new Map,this.ast=un(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 r={start:e.getFullStart(),end:e.getEnd()};if(!t){const l=new We({range:r});return this.pushStatement(l.iife),l}const s=t.getText(),o=new We({id:t,range:r}),a=this.declarations.get(s);if(a){a.pushIdentifierReference(t),a.declaration.end=r.end;const l=this.ast.body.findIndex(m=>m==a.declaration);for(let m=l+1;m<this.ast.body.length;m++){const p=this.ast.body[m];p.start=p.end=r.end}}else this.pushStatement(o.declaration),this.declarations.set(s,o);return a||o}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 w(e)}removeStatement(e){this.pushStatement(I({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 r=this.createDeclaration(e,e.name);r.pushIdentifierReference(e.name),r.convertNamespace(e)}convertEnumDeclaration(e){this.createDeclaration(e,e.name).pushIdentifierReference(e.name)}convertFunctionDeclaration(e){if(!e.name)throw new w(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 w(e,"ClassDeclaration / InterfaceDeclaration should have a name");const t=this.createDeclaration(e,e.name),r=t.convertTypeParameters(e.typeParameters);t.convertHeritageClauses(e),t.convertMembers(e.members),t.popScope(r)}convertTypeAliasDeclaration(e){const t=this.createDeclaration(e,e.name),r=t.convertTypeParameters(e.typeParameters);t.convertTypeNode(e.type),t.popScope(r)}convertVariableStatement(e){const{declarations:t}=e.declarationList;if(t.length!==1)throw new w(e,"VariableStatement with more than one declaration not yet supported");for(const r of t){if(!i.isIdentifier(r.name))throw new w(e,"VariableDeclaration must have a name");const s=this.createDeclaration(e,r.name);s.convertTypeNode(r.type),r.initializer&&this.trackExpressionReferences(r.initializer,s)}}trackExpressionReferences(e,t){if(i.isIdentifier(e))t.pushIdentifierReference(e);else if(i.isObjectLiteralExpression(e))for(const r of e.properties)i.isShorthandPropertyAssignment(r)?t.pushIdentifierReference(r.name):i.isPropertyAssignment(r)&&this.trackExpressionReferences(r.initializer,t);else if(i.isArrayLiteralExpression(e))for(const r of e.elements)i.isExpression(r)&&this.trackExpressionReferences(r,t);else i.isPropertyAccessExpression(e)&&this.trackExpressionReferences(e.expression,t)}convertExportDeclaration(e){if(i.isExportAssignment(e)){this.pushStatement(I({type:"ExportDefaultDeclaration",declaration:A(e.expression)},e));return}const t=e.moduleSpecifier?A(e.moduleSpecifier):void 0;if(!e.exportClause)this.pushStatement(I({type:"ExportAllDeclaration",source:t,exported:null,attributes:[]},e));else if(i.isNamespaceExport(e.exportClause))this.pushStatement(I({type:"ExportAllDeclaration",source:t,exported:M(e.exportClause.name),attributes:[]},e));else{const r=[];for(const s of e.exportClause.elements)r.push(this.convertExportSpecifier(s));this.pushStatement(I({type:"ExportNamedDeclaration",declaration:null,specifiers:r,source:t,attributes:[]},e))}}convertImportDeclaration(e){if(i.isImportEqualsDeclaration(e)){if(i.isEntityName(e.moduleReference)){const s=this.createDeclaration(e,e.name);s.pushReference(s.convertEntityName(e.moduleReference));return}if(!i.isExternalModuleReference(e.moduleReference))throw new w(e,"ImportEquals should have a literal source.");this.pushStatement(I({type:"ImportDeclaration",specifiers:[{type:"ImportDefaultSpecifier",local:M(e.name)}],source:A(e.moduleReference.expression),attributes:[]},e));return}const t=A(e.moduleSpecifier),r=e.importClause&&e.importClause.namedBindings?this.convertNamedImportBindings(e.importClause.namedBindings):[];e.importClause&&e.importClause.name&&r.push({type:"ImportDefaultSpecifier",local:M(e.importClause.name)}),this.pushStatement(I({type:"ImportDeclaration",specifiers:r,source:t,attributes:[]},e))}convertNamedImportBindings(e){return i.isNamedImports(e)?e.elements.map(t=>{const r=M(t.name),s=t.propertyName?M(t.propertyName):r;return{type:"ImportSpecifier",local:r,imported:s}}):[{type:"ImportNamespaceSpecifier",local:M(e.name)}]}convertExportSpecifier(e){const t=M(e.name);return{type:"ExportSpecifier",exported:t,local:e.propertyName?M(e.propertyName):t}}}class Cn{static{c(this,"RelativeModuleDeclarationFixer")}constructor(e,t,r,s){this.sourcemap=r,this.DEBUG=!!process.env.DTS_EXPORTS_FIXER_DEBUG,this.relativeModuleDeclarations=[],this.source=J(e,t.toString()),this.code=t,this.name=s||"./index"}fix(){this.analyze(this.source.statements);for(const e of this.relativeModuleDeclarations){const t=e.getStart(),r=e.getEnd(),s=e.name.kind===i.SyntaxKind.StringLiteral&&"singleQuote"in e.name&&e.name.singleQuote?"'":'"',o=`declare module ${s}${this.name}${s} ${e.body.getText()}`;this.code.overwrite(t,r,o)}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))}}function wn(n,e,t){const r=Q(n),s=Q(e.mappings),o=t.split(`
|
|
33
|
+
`),a=[];for(let l=0;l<r.length;l+=1){const m=r[l];if(!m||m.length===0){a.push([]);continue}const p=m.find(D=>D.length>=4);if(!p){a.push(m);continue}const[,d,h]=p;if(d!==0||h===void 0||h<0||h>=s.length){a.push(m);continue}const u=s[h];if(!u||u.length===0){a.push(m);continue}const g=p[0],x=p.length>=4?p[3]:0,S=g-(x??0),E=o[l]||"",N=[];for(const D of u){const b=D[0]+S;b<0||b>E.length||(D.length===5?N.push([b,D[1],D[2],D[3],D[4]]):D.length===4?N.push([b,D[1],D[2],D[3]]):N.push([b]))}N.sort((D,b)=>D[0]-b[0]),a.push(N)}return ge(a)}c(wn,"hydrateSourcemap");async function Dn(n){const{fileName:e,originalCode:t,inputMapText:r}=n;if(r)try{return JSON.parse(r)}catch{return null}const s=_e.fromSource(t);if(s)return s.toObject();const o=c(async a=>{const l=a.split(/[?#]/)[0],m=T.resolve(T.dirname(e),l);return ce.readFile(m,"utf8")},"readMap");try{const a=await _e.fromMapFileSource(t,o);if(a)return a.toObject()}catch{}try{const a=await ce.readFile(e+".map","utf8");return JSON.parse(a)}catch{return null}}c(Dn,"loadInputSourcemap");const bn=c(n=>{const e=new Map,t=new Map,r=new Map;return{name:"dts-transform",buildStart(){e.clear(),t.clear(),r.clear()},options({onLog:s,...o}){return{...o,onLog(a,l,m){a==="warn"&&l.code==="CIRCULAR_DEPENDENCY"||(s?s(a,l,m):m(a,l))},treeshake:{moduleSideEffects:"no-external",propertyReadSideEffects:!0,unknownGlobalSideEffects:!1}}},outputOptions(s){return{...s,chunkFileNames:s.chunkFileNames||"[name]-[hash].d.ts",entryFileNames:s.entryFileNames||"[name].d.ts",format:"es",exports:"named",compact:!1,freeze:!0,interop:"esModule",generatedCode:Object.assign({symbols:!1},s.generatedCode),strict:!1}},transform(s,o,a){const l=te(o),m=this.getModuleIds(),p=Array.from(m).find(N=>te(N)===l),d=!!(p&&this.getModuleInfo(p)?.isEntry),h=!!(p&&ee.test(p)),u=s;let g=J(o,s);const x=yn({sourceFile:g,isEntry:d,isJSON:h});e.set(g.fileName,x.typeReferences),t.set(g.fileName,x.fileReferences),s=x.code.toString(),g=J(o,s);const S=Tn({sourceFile:g});if(process.env.DTS_DUMP_AST&&(console.log(o),console.log(s),console.log(JSON.stringify(S.ast.body,void 0,2))),!n)return{code:s,ast:S.ast};const E=x.code.generateMap({hires:!0,source:o});return j.test(o)&&r.set(o,{fileName:o,originalCode:u,inputMapText:a}),{code:s,ast:S.ast,map:E}},renderChunk(s,o,a){const l=J(o.fileName,s),m=new ln(l),p=new Set,d=new Set;for(const S of Object.keys(o.modules)){for(const E of e.get(S.split("\\").join("/"))||[])p.add(E);for(const E of t.get(S.split("\\").join("/"))||[])if(E.startsWith(".")){const N=T.join(T.dirname(S),E),D=a.file&&T.dirname(a.file)||o.facadeModuleId&&T.dirname(o.facadeModuleId)||".";let b=T.relative(D,N).split("\\").join("/");b[0]!=="."&&(b="./"+b),d.add(b)}else d.add(E)}let h=Ge(Array.from(d,S=>`/// <reference path="${S}" />`));h+=Ge(Array.from(p,S=>`/// <reference types="${S}" />`)),h+=m.fix(),h||(h+=`
|
|
34
|
+
export { };`);const g=new gn(o.fileName,h).fix();return new Cn(o.fileName,"magicCode"in g&&g.magicCode?g.magicCode:new X(h),!!a.sourcemap,"./"+T.basename(o.fileName,".d.ts")).fix()},async generateBundle(s,o){if(!s.sourcemap)return;const a=new Map,l=Array.from(r.entries()),m=await Promise.all(l.map(async([h,u])=>({fileName:h,inputMap:await Dn(u)}))),p=c(h=>/^[a-z][a-z0-9+.-]*:\/\//i.test(h),"isUrl");for(const{fileName:h,inputMap:u}of m)if(u&&u.sources){const g=T.dirname(h);let x;u.sourceRoot?x=p(u.sourceRoot)?u.sourceRoot:T.resolve(g,u.sourceRoot):x=g;const S=p(x);a.set(h,{version:u.version??3,sources:u.sources.map(E=>{if(E===null)return null;if(p(E))return E;if(S){const N=x.endsWith("/")?x:x+"/";return new URL(E,N).toString()}return T.isAbsolute(E)?E:T.resolve(x,E)}),mappings:u.mappings,names:u.names})}const d=s.dir||(s.file?T.dirname(s.file):process.cwd());for(const h of Object.values(o)){if(h.type!=="chunk"||!h.map)continue;const u=T.join(d,T.dirname(h.fileName)),g=c(y=>p(y)?y:(T.isAbsolute(y)?T.relative(u,y):y).replaceAll("\\","/"),"toRelativeSourcePath"),x=c(y=>y===null?null:g(y),"toRelativeSourcePathOrNull"),S=new Map;for(const y of h.map.sources){if(!y||p(y))continue;const v=T.resolve(u,y);let C=a.get(v);if(!C&&/\.[cm]?[tj]sx?$/.test(v)&&!v.endsWith(".d.ts")){const O=v.replace(/\.[cm]?[tj]sx?$/,".d.ts");C=a.get(O)}C&&S.set(v,C)}if(S.size===0){if(delete h.map.sourcesContent,h.map.sources.length===0&&h.facadeModuleId){const y=a.get(h.facadeModuleId);if(y&&y.sources.length>0){const v=y.sources.map(x);h.map.sources=v}}qe(o,h.fileName,{sources:h.map.sources.map(x),mappings:h.map.mappings,names:h.map.names||[]});continue}const N=h.map.sources.length===1&&S.size===1?Array.from(S.values())[0]:null,D=N&&N.sources.length===1;let b,P,f;if(D&&N)b=N.sources.map(x),P=wn(h.map.mappings,N,h.code),f=N.names||[];else{const y=new Set,v=Qt(h.map,C=>{const O=T.resolve(u,C);if(y.has(O))return null;y.add(O);const L=S.get(O);return L||null});b=v.sources.map(x),P=typeof v.mappings=="string"?v.mappings:"",f=v.names||[]}h.map.sources=b,delete h.map.sourcesContent,h.map.mappings=P,h.map.names=f,qe(o,h.fileName,{sources:b,mappings:P,names:f})}}}},"transform");function Ge(n){return n.length?n.join(`
|
|
35
|
+
`)+`
|
|
36
|
+
`:""}c(Ge,"writeBlock");function qe(n,e,t){const r=`${e}.map`,s=n[r];s&&s.type==="asset"&&(s.source=JSON.stringify({version:3,file:T.basename(e),...t}))}c(qe,"updateSourcemapAsset");const In=/\.([cm]ts|[tj]sx?)$/;function oe({entries:n,programs:e,resolvedOptions:t},r,s){const{compilerOptions:o,tsconfig:a}=t;if(!e.length&&j.test(r))return{code:s};const l=n.includes(r),m=e.find(p=>{if(l)return p.getRootFileNames().includes(r);{const d=p.getSourceFile(r);return d&&p.isSourceFileFromExternalLibrary(d)?!1:!!d}});if(m){const p=m.getSourceFile(r);return{code:p?.getFullText(),source:p,program:m}}else if(i.sys.fileExists(r)){if(e.length>0&&j.test(r)&&(t.includeExternal.length>0||t.respectExternal))return{code:s};const p=rn(r,o,a,t.sourcemap);e.push(p);const d=p.getSourceFile(r);return{code:d?.getFullText(),source:d,program:p}}else return null}c(oe,"getModule");const He=c((n={})=>{const e={entries:[],programs:[],resolvedOptions:tn(n)},t=bn(e.resolvedOptions.sourcemap);return{name:"dts",outputOptions:t.outputOptions,renderChunk:t.renderChunk,generateBundle:t.generateBundle,options(r){let{input:s=[]}=r;if(!Array.isArray(s))s=typeof s=="string"?[s]:Object.values(s);else if(s.length>1){r.input={};for(const o of s){let a=te(o);T.isAbsolute(o)?a=T.basename(a):a=T.normalize(a),r.input[a]=o}}return e.programs=sn(Object.values(s),e.resolvedOptions.compilerOptions,e.resolvedOptions.tsconfig,e.resolvedOptions.sourcemap),t.options.call(this,r)},transform(r,s){if(!In.test(s)&&!ee.test(s))return null;const o=c(p=>{if(p.program){const d=T.dirname(s);p.program.getSourceFiles().map(u=>u.fileName).filter(u=>u.startsWith(d)).forEach(this.addWatchFile)}},"watchFiles"),a=c(()=>{const p=oe(e,s,r);return p?(o(p),t.transform.call(this,p.code,s)):null},"handleDtsFile"),l=c(()=>{const p=Be(s),d=oe(e,p,r);return d?(o(d),t.transform.call(this,d.code,p)):null},"treatTsAsDts"),m=c(()=>{const p=oe(e,s,r);if(!p||!p.source||!p.program)return null;o(p);const d=Be(s);let h,u;const{emitSkipped:g,diagnostics:x}=p.program.emit(p.source,(E,N)=>{E.endsWith(".map")?u=N:h=N},void 0,!0,void 0,!0);if(g){const E=x.filter(N=>N.category===i.DiagnosticCategory.Error);E.length&&(console.error(i.formatDiagnostics(E,ne)),this.error("Failed to compile. Check the logs above."))}if(!h)return null;const S=h.replace(/\n?\/\/# sourceMappingURL=[^\n]+/,"");return t.transform.call(this,S,d,u)},"generateDts");return j.test(s)?a():ee.test(s)?m():l()??m()},resolveId(r,s){if(!s){e.entries.push(T.resolve(r));return}s=s.split("\\").join("/");let o=e.resolvedOptions.compilerOptions;if(e.resolvedOptions.tsconfig){const l=r.startsWith(".")?T.resolve(T.dirname(s),r):r;o=re(l,e.resolvedOptions.compilerOptions,e.resolvedOptions.tsconfig,e.resolvedOptions.sourcemap).compilerOptions}const{resolvedModule:a}=i.resolveModuleName(r,s,o,i.sys);if(a)return a.isExternalLibraryImport&&a.packageId&&e.resolvedOptions.includeExternal.includes(a.packageId.name)?{id:T.resolve(a.resolvedFileName)}:!e.resolvedOptions.respectExternal&&a.isExternalLibraryImport?{id:r,external:!0}:{id:T.resolve(a.resolvedFileName)}}}},"plugin");export{He as default,He as dts};
|
package/package.json
CHANGED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
var Ge=Object.defineProperty;var c=(n,e)=>Ge(n,"name",{value:e,configurable:!0});import{createRequire as qe}from"node:module";const He=qe(import.meta.url);import*as N from"node:path";import i from"typescript";import{createRequire as Xe}from"node:module";import W from"magic-string";import ie from"node:fs/promises";var oe=44,Qe=59,ae="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ce=new Uint8Array(64),le=new Uint8Array(128);for(let n=0;n<ae.length;n++){const e=ae.charCodeAt(n);ce[n]=e,le[e]=n}function B(n,e){let t=0,r=0,s=0;do{const a=n.next();s=le[a],t|=(s&31)<<r,r+=5}while(s&32);const o=t&1;return t>>>=1,o&&(t=-2147483648|-t),e+t}c(B,"decodeInteger");function j(n,e,t){let r=e-t;r=r<0?-r<<1|1:r<<1;do{let s=r&31;r>>>=5,r>0&&(s|=32),n.write(ce[s])}while(r>0);return e}c(j,"encodeInteger");function ue(n,e){return n.pos>=e?!1:n.peek()!==oe}c(ue,"hasMoreVlq");var pe=1024*16,fe=typeof TextDecoder<"u"?new TextDecoder:typeof Buffer<"u"?{decode(n){return Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString()}}:{decode(n){let e="";for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return e}},Ye=class{static{c(this,"StringWriter")}constructor(){this.pos=0,this.out="",this.buffer=new Uint8Array(pe)}write(n){const{buffer:e}=this;e[this.pos++]=n,this.pos===pe&&(this.out+=fe.decode(e),this.pos=0)}flush(){const{buffer:n,out:e,pos:t}=this;return t>0?e+fe.decode(n.subarray(0,t)):e}},Ze=class{static{c(this,"StringReader")}constructor(n){this.pos=0,this.buffer=n}next(){return this.buffer.charCodeAt(this.pos++)}peek(){return this.buffer.charCodeAt(this.pos)}indexOf(n){const{buffer:e,pos:t}=this,r=e.indexOf(n,t);return r===-1?e.length:r}};function G(n){const{length:e}=n,t=new Ze(n),r=[];let s=0,o=0,a=0,u=0,m=0;do{const f=t.indexOf(";"),d=[];let h=!0,l=0;for(s=0;t.pos<f;){let y;s=B(t,s),s<l&&(h=!1),l=s,ue(t,f)?(o=B(t,o),a=B(t,a),u=B(t,u),ue(t,f)?(m=B(t,m),y=[s,o,a,u,m]):y=[s,o,a,u]):y=[s],d.push(y),t.pos++}h||et(d),r.push(d),t.pos=f+1}while(t.pos<=e);return r}c(G,"decode");function et(n){n.sort(tt)}c(et,"sort");function tt(n,e){return n[0]-e[0]}c(tt,"sortComparator$1");function me(n){const e=new Ye;let t=0,r=0,s=0,o=0;for(let a=0;a<n.length;a++){const u=n[a];if(a>0&&e.write(Qe),u.length===0)continue;let m=0;for(let f=0;f<u.length;f++){const d=u[f];f>0&&e.write(oe),m=j(e,d[0],m),d.length!==1&&(t=j(e,d[1],t),r=j(e,d[2],r),s=j(e,d[3],s),d.length!==4&&(o=j(e,d[4],o)))}}return e.flush()}c(me,"encode");const nt=/^[\w+.-]+:\/\//,rt=/^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/,st=/^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;function it(n){return nt.test(n)}c(it,"isAbsoluteUrl");function ot(n){return n.startsWith("//")}c(ot,"isSchemeRelativeUrl");function de(n){return n.startsWith("/")}c(de,"isAbsolutePath");function at(n){return n.startsWith("file:")}c(at,"isFileUrl");function he(n){return/^[.?#]/.test(n)}c(he,"isRelative");function V(n){const e=rt.exec(n);return ye(e[1],e[2]||"",e[3],e[4]||"",e[5]||"/",e[6]||"",e[7]||"")}c(V,"parseAbsoluteUrl");function ct(n){const e=st.exec(n),t=e[2];return ye("file:","",e[1]||"","",de(t)?t:"/"+t,e[3]||"",e[4]||"")}c(ct,"parseFileUrl");function ye(n,e,t,r,s,o,a){return{scheme:n,user:e,host:t,port:r,path:s,query:o,hash:a,type:7}}c(ye,"makeUrl");function ge(n){if(ot(n)){const t=V("http:"+n);return t.scheme="",t.type=6,t}if(de(n)){const t=V("http://foo.com"+n);return t.scheme="",t.host="",t.type=5,t}if(at(n))return ct(n);if(it(n))return V(n);const e=V("http://foo.com/"+n);return e.scheme="",e.host="",e.type=n?n.startsWith("?")?3:n.startsWith("#")?2:4:1,e}c(ge,"parseUrl");function lt(n){if(n.endsWith("/.."))return n;const e=n.lastIndexOf("/");return n.slice(0,e+1)}c(lt,"stripPathFilename");function ut(n,e){xe(e,e.type),n.path==="/"?n.path=e.path:n.path=lt(e.path)+n.path}c(ut,"mergePaths");function xe(n,e){const t=e<=4,r=n.path.split("/");let s=1,o=0,a=!1;for(let m=1;m<r.length;m++){const f=r[m];if(!f){a=!0;continue}if(a=!1,f!=="."){if(f===".."){o?(a=!0,o--,s--):t&&(r[s++]=f);continue}r[s++]=f,o++}}let u="";for(let m=1;m<s;m++)u+="/"+r[m];(!u||a&&!u.endsWith("/.."))&&(u+="/"),n.path=u}c(xe,"normalizePath");function pt(n,e){if(!n&&!e)return"";const t=ge(n);let r=t.type;if(e&&r!==7){const o=ge(e),a=o.type;switch(r){case 1:t.hash=o.hash;case 2:t.query=o.query;case 3:case 4:ut(t,o);case 5:t.user=o.user,t.host=o.host,t.port=o.port;case 6:t.scheme=o.scheme}a>r&&(r=a)}xe(t,r);const s=t.query+t.hash;switch(r){case 2:case 3:return s;case 4:{const o=t.path.slice(1);return o?he(e||n)&&!he(o)?"./"+o+s:o+s:s||"."}case 5:return t.path+s;default:return t.scheme+"//"+t.user+t.host+t.port+t.path+s}}c(pt,"resolve");function ft(n){if(!n)return"";const e=n.lastIndexOf("/");return n.slice(0,e+1)}c(ft,"stripFilename");function mt(n,e){const t=ft(n),r=e?e+"/":"";return s=>pt(r+(s||""),t)}c(mt,"resolver");var L=0;function dt(n,e){const t=Se(n,0);if(t===n.length)return n;e||(n=n.slice());for(let r=t;r<n.length;r=Se(n,r+1))n[r]=yt(n[r],e);return n}c(dt,"maybeSort");function Se(n,e){for(let t=e;t<n.length;t++)if(!ht(n[t]))return t;return n.length}c(Se,"nextUnsortedSegmentLine");function ht(n){for(let e=1;e<n.length;e++)if(n[e][L]<n[e-1][L])return!1;return!0}c(ht,"isSorted");function yt(n,e){return e||(n=n.slice()),n.sort(gt)}c(yt,"sortSegments");function gt(n,e){return n[L]-e[L]}c(gt,"sortComparator");var J=!1;function xt(n,e,t,r){for(;t<=r;){const s=t+(r-t>>1),o=n[s][L]-e;if(o===0)return J=!0,s;o<0?t=s+1:r=s-1}return J=!1,t-1}c(xt,"binarySearch");function St(n,e,t){for(let r=t-1;r>=0&&n[r][L]===e;t=r--);return t}c(St,"lowerBound");function vt(){return{lastKey:-1,lastNeedle:-1,lastIndex:-1}}c(vt,"memoizedState");function Et(n,e,t,r){const{lastKey:s,lastNeedle:o,lastIndex:a}=t;let u=0,m=n.length-1;if(r===s){if(e===o)return J=a!==-1&&n[a][L]===e,a;e>=o?u=a===-1?0:a:m=a}return t.lastKey=r,t.lastNeedle=e,t.lastIndex=xt(n,e,u,m)}c(Et,"memoizedBinarySearch");function Nt(n){return typeof n=="string"?JSON.parse(n):n}c(Nt,"parse$1");var ve=class{static{c(this,"TraceMap")}constructor(n,e){const t=typeof n=="string";if(!t&&n._decodedMemo)return n;const r=Nt(n),{version:s,file:o,names:a,sourceRoot:u,sources:m,sourcesContent:f}=r;this.version=s,this.file=o,this.names=a||[],this.sourceRoot=u,this.sources=m,this.sourcesContent=f,this.ignoreList=r.ignoreList||r.x_google_ignoreList||void 0;const d=mt(e,u);this.resolvedSources=m.map(d);const{mappings:h}=r;if(typeof h=="string")this._encoded=h,this._decoded=void 0;else if(Array.isArray(h))this._encoded=void 0,this._decoded=dt(h,t);else throw r.sections?new Error("TraceMap passed sectioned source map, please use FlattenMap export instead"):new Error(`invalid source map: ${JSON.stringify(r)}`);this._decodedMemo=vt(),this._bySources=void 0,this._bySourceMemos=void 0}};function On(n){return n}c(On,"cast$1");function Ee(n){var e;return(e=n)._decoded||(e._decoded=G(n._encoded))}c(Ee,"decodedMappings");function Tt(n,e,t){const r=Ee(n);if(e>=r.length)return null;const s=r[e],o=Ct(s,n._decodedMemo,e,t);return o===-1?null:s[o]}c(Tt,"traceSegment");function Ct(n,e,t,r,s){let o=Et(n,r,e,t);return J&&(o=St(n,r,o)),o===-1||o===n.length?-1:o}c(Ct,"traceSegmentInternal");var q=class{static{c(this,"SetArray")}constructor(){this._indexes={__proto__:null},this.array=[]}};function Rn(n){return n}c(Rn,"cast");function Ne(n,e){return n._indexes[e]}c(Ne,"get");function k(n,e){const t=Ne(n,e);if(t!==void 0)return t;const{array:r,_indexes:s}=n,o=r.push(e);return s[e]=o-1}c(k,"put");function wt(n,e){const t=Ne(n,e);if(t===void 0)return;const{array:r,_indexes:s}=n;for(let o=t+1;o<r.length;o++){const a=r[o];r[o-1]=a,s[a]--}s[e]=void 0,r.pop()}c(wt,"remove");var Dt=0,bt=1,It=2,Mt=3,Ft=4,Te=-1,Ot=class{static{c(this,"GenMapping")}constructor({file:n,sourceRoot:e}={}){this._names=new q,this._sources=new q,this._sourcesContent=[],this._mappings=[],this.file=n,this.sourceRoot=e,this._ignoreList=new q}};function An(n){return n}c(An,"cast2");var Rt=c((n,e,t,r,s,o,a,u)=>_t(!0,n,e,t,r,s,o,a),"maybeAddSegment");function At(n,e,t){const{_sources:r,_sourcesContent:s}=n,o=k(r,e);s[o]=t}c(At,"setSourceContent");function Pt(n,e,t=!0){const{_sources:r,_sourcesContent:s,_ignoreList:o}=n,a=k(r,e);a===s.length&&(s[a]=null),t?k(o,a):wt(o,a)}c(Pt,"setIgnore");function Ce(n){const{_mappings:e,_sources:t,_sourcesContent:r,_names:s,_ignoreList:o}=n;return jt(e),{version:3,file:n.file||void 0,names:s.array,sourceRoot:n.sourceRoot||void 0,sources:t.array,sourcesContent:r,mappings:e,ignoreList:o.array}}c(Ce,"toDecodedMap");function Lt(n){const e=Ce(n);return Object.assign({},e,{mappings:me(e.mappings)})}c(Lt,"toEncodedMap");function _t(n,e,t,r,s,o,a,u,m){const{_mappings:f,_sources:d,_sourcesContent:h,_names:l}=e,y=$t(f,t),x=Bt(y,r);if(!s)return kt(y,x)?void 0:we(y,x,[r]);const S=k(d,s),v=u?k(l,u):Te;if(S===h.length&&(h[S]=null),!Ut(y,x,S,o,a,v))return we(y,x,u?[r,S,o,a,v]:[r,S,o,a])}c(_t,"addSegmentInternal");function $t(n,e){for(let t=n.length;t<=e;t++)n[t]=[];return n[e]}c($t,"getIndex");function Bt(n,e){let t=n.length;for(let r=t-1;r>=0;t=r--){const s=n[r];if(e>=s[Dt])break}return t}c(Bt,"getColumnIndex");function we(n,e,t){for(let r=n.length;r>e;r--)n[r]=n[r-1];n[e]=t}c(we,"insert");function jt(n){const{length:e}=n;let t=e;for(let r=t-1;r>=0&&!(n[r].length>0);t=r,r--);t<e&&(n.length=t)}c(jt,"removeEmptyFinalLines");function kt(n,e){return e===0?!0:n[e-1].length===1}c(kt,"skipSourceless");function Ut(n,e,t,r,s,o){if(e===0)return!1;const a=n[e-1];return a.length===1?!1:t===a[bt]&&r===a[It]&&s===a[Mt]&&o===(a.length===5?a[Ft]:Te)}c(Ut,"skipSource");var De=be("",-1,-1,"",null,!1),Kt=[];function be(n,e,t,r,s,o){return{source:n,line:e,column:t,name:r,content:s,ignore:o}}c(be,"SegmentObject");function Ie(n,e,t,r,s){return{map:n,sources:e,source:t,content:r,ignore:s}}c(Ie,"Source");function Me(n,e){return Ie(n,e,"",null,!1)}c(Me,"MapSource");function zt(n,e,t){return Ie(null,Kt,n,e,t)}c(zt,"OriginalSource");function Vt(n){const e=new Ot({file:n.map.file}),{sources:t,map:r}=n,s=r.names,o=Ee(r);for(let a=0;a<o.length;a++){const u=o[a];for(let m=0;m<u.length;m++){const f=u[m],d=f[0];let h=De;if(f.length!==1){const g=t[f[1]];if(h=Fe(g,f[2],f[3],f.length===5?s[f[4]]:""),h==null)continue}const{column:l,line:y,name:x,content:S,source:v,ignore:p}=h;Rt(e,a,d,v,y,l,x),v&&S!=null&&At(e,v,S),p&&Pt(e,v,!0)}}return e}c(Vt,"traceMappings");function Fe(n,e,t,r){if(!n.map)return be(n.source,e,t,r,n.content,n.ignore);const s=Tt(n.map,e,t);return s==null?null:s.length===1?De:Fe(n.sources[s[1]],s[2],s[3],s.length===5?n.map.names[s[4]]:r)}c(Fe,"originalPositionFor");function Jt(n){return Array.isArray(n)?n:[n]}c(Jt,"asArray");function Wt(n,e){const t=Jt(n).map(o=>new ve(o,"")),r=t.pop();for(let o=0;o<t.length;o++)if(t[o].sources.length>1)throw new Error(`Transformation map ${o} must have exactly one source file.
|
|
2
|
-
Did you specify these with the most recent transformation maps first?`);let s=Oe(r,e,"",0);for(let o=t.length-1;o>=0;o--)s=Me(t[o],[s]);return s}c(Wt,"buildSourceMapTree");function Oe(n,e,t,r){const{resolvedSources:s,sourcesContent:o,ignoreList:a}=n,u=r+1,m=s.map((f,d)=>{const h={importer:t,depth:u,source:f||"",content:void 0,ignore:void 0},l=e(h.source,h),{source:y}=h;if(l)return Oe(new ve(l,y),e,y,u);const x=o?o[d]:null,S=a?a.includes(d):!1;return zt(y,x,S)});return Me(n,m)}c(Oe,"build");var Gt=class{static{c(this,"SourceMap")}constructor(n,e){const t=e.decodedMappings?Ce(n):Lt(n);this.version=t.version,this.file=t.file,this.mappings=t.mappings,this.names=t.names,this.ignoreList=t.ignoreList,this.sourceRoot=t.sourceRoot,this.sources=t.sources,e.excludeContent||(this.sourcesContent=t.sourcesContent)}toString(){return JSON.stringify(this)}};function qt(n,e,t){const r={excludeContent:!1,decodedMappings:!1},s=Wt(n,e);return new Gt(Vt(s),r)}c(qt,"remapping");function Ht(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}c(Ht,"getDefaultExportFromCjs");var H={},Re;function Xt(){return Re||(Re=1,(function(n){Object.defineProperty(n,"commentRegex",{get:c(function(){return/^\s*?\/[\/\*][@#]\s+?sourceMappingURL=data:(((?:application|text)\/json)(?:;charset=([^;,]+?)?)?)?(?:;(base64))?,(.*?)$/mg},"getCommentRegex")}),Object.defineProperty(n,"mapFileCommentRegex",{get:c(function(){return/(?:\/\/[@#][ \t]+?sourceMappingURL=([^\s'"`]+?)[ \t]*?$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^*]+?)[ \t]*?(?:\*\/){1}[ \t]*?$)/mg},"getMapFileCommentRegex")});var e;typeof Buffer<"u"?typeof Buffer.from=="function"?e=t:e=r:e=s;function t(l){return Buffer.from(l,"base64").toString()}c(t,"decodeBase64WithBufferFrom");function r(l){if(typeof value=="number")throw new TypeError("The value to decode must not be of type number.");return new Buffer(l,"base64").toString()}c(r,"decodeBase64WithNewBuffer");function s(l){return decodeURIComponent(escape(atob(l)))}c(s,"decodeBase64WithAtob");function o(l){return l.split(",").pop()}c(o,"stripComment");function a(l,y){var x=n.mapFileCommentRegex.exec(l),S=x[1]||x[2];try{var l=y(S);return l!=null&&typeof l.catch=="function"?l.catch(v):l}catch(p){v(p)}function v(p){throw new Error("An error occurred while trying to read the map file at "+S+`
|
|
3
|
-
`+p.stack)}c(v,"throwError")}c(a,"readFromFileMap");function u(l,y){y=y||{},y.hasComment&&(l=o(l)),y.encoding==="base64"?l=e(l):y.encoding==="uri"&&(l=decodeURIComponent(l)),(y.isJSON||y.encoding)&&(l=JSON.parse(l)),this.sourcemap=l}c(u,"Converter"),u.prototype.toJSON=function(l){return JSON.stringify(this.sourcemap,null,l)},typeof Buffer<"u"?typeof Buffer.from=="function"?u.prototype.toBase64=m:u.prototype.toBase64=f:u.prototype.toBase64=d;function m(){var l=this.toJSON();return Buffer.from(l,"utf8").toString("base64")}c(m,"encodeBase64WithBufferFrom");function f(){var l=this.toJSON();if(typeof l=="number")throw new TypeError("The json to encode must not be of type number.");return new Buffer(l,"utf8").toString("base64")}c(f,"encodeBase64WithNewBuffer");function d(){var l=this.toJSON();return btoa(unescape(encodeURIComponent(l)))}c(d,"encodeBase64WithBtoa"),u.prototype.toURI=function(){var l=this.toJSON();return encodeURIComponent(l)},u.prototype.toComment=function(l){var y,x,S;return l!=null&&l.encoding==="uri"?(y="",x=this.toURI()):(y=";base64",x=this.toBase64()),S="sourceMappingURL=data:application/json;charset=utf-8"+y+","+x,l!=null&&l.multiline?"/*# "+S+" */":"//# "+S},u.prototype.toObject=function(){return JSON.parse(this.toJSON())},u.prototype.addProperty=function(l,y){if(this.sourcemap.hasOwnProperty(l))throw new Error('property "'+l+'" already exists on the sourcemap, use set property instead');return this.setProperty(l,y)},u.prototype.setProperty=function(l,y){return this.sourcemap[l]=y,this},u.prototype.getProperty=function(l){return this.sourcemap[l]},n.fromObject=function(l){return new u(l)},n.fromJSON=function(l){return new u(l,{isJSON:!0})},n.fromURI=function(l){return new u(l,{encoding:"uri"})},n.fromBase64=function(l){return new u(l,{encoding:"base64"})},n.fromComment=function(l){var y,x;return l=l.replace(/^\/\*/g,"//").replace(/\*\/$/g,""),y=n.commentRegex.exec(l),x=y&&y[4]||"uri",new u(l,{encoding:x,hasComment:!0})};function h(l){return new u(l,{isJSON:!0})}c(h,"makeConverter"),n.fromMapFileComment=function(l,y){if(typeof y=="string")throw new Error("String directory paths are no longer supported with `fromMapFileComment`\nPlease review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading");var x=a(l,y);return x!=null&&typeof x.then=="function"?x.then(h):h(x)},n.fromSource=function(l){var y=l.match(n.commentRegex);return y?n.fromComment(y.pop()):null},n.fromMapFileSource=function(l,y){if(typeof y=="string")throw new Error("String directory paths are no longer supported with `fromMapFileSource`\nPlease review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading");var x=l.match(n.mapFileCommentRegex);return x?n.fromMapFileComment(x.pop(),y):null},n.removeComments=function(l){return l.replace(n.commentRegex,"")},n.removeMapFileComments=function(l){return l.replace(n.mapFileCommentRegex,"")},n.generateMapFileComment=function(l,y){var x="sourceMappingURL="+l;return y&&y.multiline?"/*# "+x+" */":"//# "+x}})(H)),H}c(Xt,"requireConvertSourceMap");var Qt=Xt(),Ae=Ht(Qt);function Yt(n){return{...n,compilerOptions:n.compilerOptions??{},respectExternal:n.respectExternal??!1,includeExternal:n.includeExternal??[],sourcemap:n.sourcemap??!1}}c(Yt,"resolveDefaultOptions");const _=/\.d\.(c|m)?tsx?$/,X=/\.json$/,Pe=/((\.d)?\.(c|m)?(t|j)sx?|\.json)$/;function Q(n){return n.replace(Pe,"")}c(Q,"trimExtension");function Le(n){return n.replace(Pe,".d.ts")}c(Le,"getDeclarationId");function U(n,e){return i.createSourceFile(n,e,i.ScriptTarget.Latest,!0)}c(U,"parse");const Y={getCurrentDirectory:c(()=>i.sys.getCurrentDirectory(),"getCurrentDirectory"),getNewLine:c(()=>i.sys.newLine,"getNewLine"),getCanonicalFileName:i.sys.useCaseSensitiveFileNames?n=>n:n=>n.toLowerCase()},Zt={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,$=c((...n)=>process.env.DTS_LOG_CACHE?console.log("[cache]",...n):null,"logCache");function _e([n,e],t){for($(n),K.set(n,t);n!==e&&n!==N.dirname(n);){if(n=N.dirname(n),$("up",n),K.has(n))return $("has",n);K.set(n,t)}}c(_e,"cacheConfig");function Z(n,e,t,r){const s={...Zt,...e,...r===!0&&{declarationMap:!0}};let o=N.dirname(n),a=[];const u=t||o;if(K.has(u))$("HIT",u);else{$("miss",u);const h=t?N.resolve(process.cwd(),t):i.findConfigFile(o,i.sys.fileExists);if(!h)return{dtsFiles:a,dirName:o,compilerOptions:s};const l=o;o=N.dirname(h);const{config:y,error:x}=i.readConfigFile(h,i.sys.readFile);if(x)return console.error(i.formatDiagnostic(x,Y)),{dtsFiles:a,dirName:o,compilerOptions:s};$("tsconfig",y);const S=i.parseJsonConfigFileContent(y,i.sys,o);_e(t?[t,t]:[l,o],S)}const{fileNames:m,options:f,errors:d}=K.get(u);return a=m.filter(h=>_.test(h)),d.length?(console.error(i.formatDiagnostics(d,Y)),{dtsFiles:a,dirName:o,compilerOptions:s}):{dtsFiles:a,dirName:o,compilerOptions:{...f,...s}}}c(Z,"getCompilerOptions");function en(n,e,t,r){const{dtsFiles:s,compilerOptions:o}=Z(n,e,t,r);return i.createProgram([n].concat(Array.from(s)),o,i.createCompilerHost(o,!0))}c(en,"createProgram$1");function tn(n,e,t,r){const s=[],o=new Set;let a=[],u="",m={};for(let f of n){if(_.test(f))continue;f=N.resolve(f);const d=Z(f,e,t,r);if(d.dtsFiles.forEach(o.add,o),!a.length){a.push(f),{dirName:u,compilerOptions:m}=d;continue}if(d.dirName===u)a.push(f);else{const h=i.createCompilerHost(m,!0),l=i.createProgram(a.concat(Array.from(o)),m,h);s.push(l),a=[f],{dirName:u,compilerOptions:m}=d}}if(a.length){const f=i.createCompilerHost(m,!0),d=i.createProgram(a.concat(Array.from(o)),m,f);s.push(d)}return s}c(tn,"createPrograms");function nn(){let n;try{return{codeFrameColumns:n}=He("@babel/code-frame"),n}catch{try{return{codeFrameColumns:n}=Xe(import.meta.url)("@babel/code-frame"),n}catch{}}}c(nn,"getCodeFrame");function rn(n){const e=n.getSourceFile(),t=e.getLineAndCharacterOfPosition(n.getStart()),r=e.getLineAndCharacterOfPosition(n.getEnd());return{start:{line:t.line+1,column:t.character+1},end:{line:r.line+1,column:r.character+1}}}c(rn,"getLocation");function sn(n){const e=nn(),r=n.getSourceFile().getFullText(),s=rn(n);return e?`
|
|
4
|
-
`+e(r,s,{highlightCode:!0}):`
|
|
5
|
-
${s.start.line}:${s.start.column}: \`${n.getFullText().trim()}\``}c(sn,"frameNode");class w extends Error{static{c(this,"UnsupportedSyntaxError")}constructor(e,t="Syntax not yet supported"){super(`${t}
|
|
6
|
-
${sn(e)}`)}}class on{static{c(this,"NamespaceFixer")}constructor(e){this.sourceFile=e}findNamespaces(){const e=[],t={};for(const r of this.sourceFile.statements){const s={start:r.getStart(),end:r.getEnd()};if(i.isEmptyStatement(r)){e.unshift({name:"",exports:[],location:s});continue}if((i.isImportDeclaration(r)||i.isExportDeclaration(r))&&r.moduleSpecifier&&i.isStringLiteral(r.moduleSpecifier)){const{text:d}=r.moduleSpecifier;if(d.startsWith(".")&&(d.endsWith(".d.ts")||d.endsWith(".d.cts")||d.endsWith(".d.mts"))){const h=r.moduleSpecifier.getStart()+1,l=r.moduleSpecifier.getEnd()-1;e.unshift({name:"",exports:[],location:{start:h,end:l},textBeforeCodeAfter:d.replace(/\.d\.ts$/,".js").replace(/\.d\.cts$/,".cjs").replace(/\.d\.mts$/,".mjs")})}}if(i.isModuleDeclaration(r)&&r.body){let d=r.body;for(;i.isModuleDeclaration(d)&&d.body;)d=d.body;if(!i.isModuleBlock(d))continue;for(const h of d.statements)if(i.isExportDeclaration(h)&&h.exportClause){if(i.isNamespaceExport(h.exportClause))continue;for(const l of h.exportClause.elements)l.propertyName&&l.propertyName.getText()==l.name.getText()&&e.unshift({name:"",exports:[],location:{start:l.propertyName.getEnd(),end:l.name.getEnd()}})}}if(i.isClassDeclaration(r)?t[r.name.getText()]={type:"class",generics:r.typeParameters}:i.isFunctionDeclaration(r)?t[r.name.getText()]={type:"function"}:i.isInterfaceDeclaration(r)?t[r.name.getText()]={type:"interface",generics:r.typeParameters}:i.isTypeAliasDeclaration(r)?t[r.name.getText()]={type:"type",generics:r.typeParameters}:i.isModuleDeclaration(r)&&i.isIdentifier(r.name)?t[r.name.getText()]={type:"namespace"}:i.isEnumDeclaration(r)&&(t[r.name.getText()]={type:"enum"}),!i.isVariableStatement(r))continue;const{declarations:o}=r.declarationList;if(o.length!==1)continue;const a=o[0],u=a.name.getText();if(!a.initializer||!i.isCallExpression(a.initializer)){t[u]={type:"var"};continue}const m=a.initializer.arguments[0];if(!a.initializer.expression.getFullText().includes("/*#__PURE__*/Object.freeze")||!i.isObjectLiteralExpression(m))continue;const f=[];for(const d of m.properties){if(!i.isPropertyAssignment(d)||!(i.isIdentifier(d.name)||i.isStringLiteral(d.name))||d.name.text!=="__proto__"&&!i.isIdentifier(d.initializer))throw new w(d,"Expected a property assignment");d.name.text!=="__proto__"&&f.push({exportedName:d.name.text,localName:d.initializer.getText()})}e.unshift({name:u,exports:f,location:s})}return{namespaces:e,itemTypes:t}}fix(){let e=this.sourceFile.getFullText();const{namespaces:t,itemTypes:r}=this.findNamespaces();for(const s of t){const o=e.slice(s.location.end);e=e.slice(0,s.location.start);for(const{exportedName:a,localName:u}of s.exports)if(a===u){const{type:m,generics:f}=r[u]||{};if(m==="interface"||m==="type"){const d=$e(f);e+=`type ${s.name}_${a}${d.in} = ${u}${d.out};
|
|
7
|
-
`}else if(m==="enum"||m==="class"){const d=$e(f);e+=`type ${s.name}_${a}${d.in} = ${u}${d.out};
|
|
8
|
-
`,e+=`declare const ${s.name}_${a}: typeof ${u};
|
|
9
|
-
`}else m==="namespace"?e+=`import ${s.name}_${a} = ${u};
|
|
10
|
-
`:e+=`declare const ${s.name}_${a}: typeof ${u};
|
|
11
|
-
`}if(s.name){e+=`declare namespace ${s.name} {
|
|
12
|
-
`,e+=` export {
|
|
13
|
-
`;for(const{exportedName:a,localName:u}of s.exports)a===u?e+=` ${s.name}_${a} as ${a},
|
|
14
|
-
`:e+=` ${u} as ${a},
|
|
15
|
-
`;e+=` };
|
|
16
|
-
`,e+="}"}e+=s.textBeforeCodeAfter??"",e+=o}return e}}function $e(n){return!n||!n.length?{in:"",out:""}:{in:`<${n.map(e=>e.getText()).join(", ")}>`,out:`<${n.map(e=>e.name.getText()).join(", ")}>`}}c($e,"renderTypeParams");let Be=1;function an(n){return I({type:"Program",sourceType:"module",body:[]},{start:n.getFullStart(),end:n.getEnd()})}c(an,"createProgram");function cn(n){const e={type:"Identifier",name:String(Be++)};return{ident:e,expr:{type:"AssignmentPattern",left:e,right:n}}}c(cn,"createReference");function M(n){return I({type:"Identifier",name:n.getText()},n)}c(M,"createIdentifier");function ln(n){const e=I({type:"FunctionExpression",id:null,params:[],body:{type:"BlockStatement",body:[]}},n),t=I({type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:String(Be++)},arguments:[e],optional:!1}},n);return{fn:e,iife:t}}c(ln,"createIIFE");function un(){const n={type:"ArrayExpression",elements:[]};return{expr:n,stmt:{type:"ReturnStatement",argument:n}}}c(un,"createReturn");function pn(n,e){return I({type:"FunctionDeclaration",id:I({type:"Identifier",name:i.idText(n)},n),params:[],body:{type:"BlockStatement",body:[]}},e)}c(pn,"createDeclaration");function A(n){if(i.isLiteralExpression(n))return{type:"Literal",value:n.text};if(i.isPropertyAccessExpression(n)){if(i.isPrivateIdentifier(n.name))throw new w(n.name);return I({type:"MemberExpression",computed:!1,optional:!1,object:A(n.expression),property:A(n.name)},{start:n.expression.getStart(),end:n.name.getEnd()})}if(i.isObjectLiteralExpression(n))return I({type:"ObjectExpression",properties:n.properties.map(e=>{if(i.isPropertyAssignment(e))return I({type:"Property",key:i.isIdentifier(e.name)?M(e.name):A(e.name),value:A(e.initializer),kind:"init",method:!1,shorthand:!1,computed:i.isComputedPropertyName(e.name)},e);if(i.isShorthandPropertyAssignment(e))return I({type:"Property",key:M(e.name),value:M(e.name),kind:"init",method:!1,shorthand:!0,computed:!1},e);throw new w(e,"Unsupported property type in object literal")})},n);if(i.isArrayLiteralExpression(n))return I({type:"ArrayExpression",elements:n.elements.map(e=>{if(i.isExpression(e))return A(e);throw new w(e,"Unsupported element type in array literal")})},n);if(i.isIdentifier(n))return M(n);if(n.kind==i.SyntaxKind.NullKeyword)return{type:"Literal",value:null};throw new w(n)}c(A,"convertExpression");function I(n,e){const t="start"in e?e:{start:e.getStart(),end:e.getEnd()};return Object.assign(n,t)}c(I,"withStartEnd");function z(n,e){return(i.getCombinedModifierFlags(n)&e)===e}c(z,"matchesModifier");class fn{static{c(this,"LanguageService")}constructor(e){this.fileName="index.d.ts";const t={getCompilationSettings:c(()=>({noEmit:!0,noResolve:!0,skipLibCheck:!0,declaration:!1,checkJs:!1,declarationMap:!1,target:i.ScriptTarget.ESNext}),"getCompilationSettings"),getScriptFileNames:c(()=>[this.fileName],"getScriptFileNames"),getScriptVersion:c(()=>"1","getScriptVersion"),getScriptSnapshot:c(r=>r===this.fileName?i.ScriptSnapshot.fromString(e):void 0,"getScriptSnapshot"),getCurrentDirectory:c(()=>"","getCurrentDirectory"),getDefaultLibFileName:c(()=>"","getDefaultLibFileName"),fileExists:c(r=>r===this.fileName,"fileExists"),readFile:c(r=>r===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((r,s)=>r+s.references.length,0):0}}class mn{static{c(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=U(e,t),this.code=new W(t)}fix(){return this.analyze(this.source.statements),(this.typeHints.size||this.reExportTypeHints.size)&&(this.service=new fn(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 r=[],s=[],o=e.moduleSpecifier.getText(),a=e.importClause.name,u=e.importClause.namedBindings;if(a){const m=a.text;this.isTypeOnly(m)?this.isUselessImport(a)?t=!0:r.push(`import type ${m} from ${o};`):s.push(`import ${m} from ${o};`)}if(u&&i.isNamespaceImport(u)){const m=u.name.text;this.isTypeOnly(m)?this.isUselessImport(u.name)?t=!0:r.push(`import type * as ${m} from ${o};`):s.push(`import * as ${m} from ${o};`)}if(u&&i.isNamedImports(u)){const m=[],f=[];for(const d of u.elements)this.isTypeOnly(d.name.text)?this.isUselessImport(d.name)?t=!0:m.push(d.getText()):f.push(d.getText());m.length&&r.push(`import type { ${m.join(", ")} } from ${o};`),f.length&&s.push(`import { ${f.join(", ")} } from ${o};`)}(r.length||t)&&this.code.overwrite(e.getStart(),e.getEnd(),[...s,...r].join(`
|
|
17
|
-
${je(e)}`))}fixTypeOnlyExport(e){const t=[],r=[],s=e.moduleSpecifier?.getText();if(i.isNamespaceExport(e.exportClause)){const o=e.exportClause.name.text;this.isReExportTypeOnly(o)?t.push(`export type * as ${o} from ${s};`):r.push(`export * as ${o} from ${s};`)}if(i.isNamedExports(e.exportClause)){const o=[],a=[];for(const u of e.exportClause.elements){const m=u.propertyName?.text||u.name.text;(e.moduleSpecifier?this.isReExportTypeOnly(u.name.text):this.isTypeOnly(m))?o.push(u.getText()):a.push(u.getText())}o.length&&t.push(`export type { ${o.join(", ")} }${s?` from ${s}`:""};`),a.length&&r.push(`export { ${a.join(", ")} }${s?` from ${s}`:""};`)}t.length&&this.code.overwrite(e.getStart(),e.getEnd(),[...r,...t].join(`
|
|
18
|
-
${je(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 r=t.name.text;this.DEBUG&&console.log(`${t.name.getFullText()} is a type`),this.types.add(r);continue}if(i.isEnumDeclaration(t)||i.isFunctionDeclaration(t)||i.isClassDeclaration(t)||i.isVariableStatement(t)){if(i.isVariableStatement(t))for(const r of t.declarationList.declarations)i.isIdentifier(r.name)&&(this.DEBUG&&console.log(`${r.name.getFullText()} is a value (from var statement)`),this.values.add(r.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),r=this.typeHints.get(e.text);return r&&r+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 je(n){const e=n.getFullText().match(/^(?:\n*)([ ]*)/);return" ".repeat(e?.[1]?.length||0)}c(je,"getNodeIndent");function ee(n,e,t){if(i.isModuleDeclaration(n)){n.body&&(i.isModuleBlock(n.body)||i.isModuleDeclaration(n.body))&&ee(n.body,e);return}for(const r of n.statements)te(e,r),i.isModuleDeclaration(r)&&r.body&&(i.isModuleBlock(r.body)||i.isModuleDeclaration(r.body))&&ee(r.body,e)}c(ee,"preProcessNamespaceBody");function dn({sourceFile:n,isEntry:e,isJSON:t}){const r=new W(n.getFullText()),s=!e&&hn(n),o=new Set,a=new Set;let u="";const m=new Map,f=new Map;for(const p of n.statements){if(i.isEmptyStatement(p)){r.remove(p.getStart(),p.getEnd());continue}if(i.isImportDeclaration(p)){if(!p.importClause)continue;p.importClause.name&&o.add(p.importClause.name.text),p.importClause.namedBindings&&(i.isNamespaceImport(p.importClause.namedBindings)?o.add(p.importClause.namedBindings.name.text):p.importClause.namedBindings.elements.forEach(g=>o.add(g.name.text)))}else if(i.isEnumDeclaration(p)||i.isFunctionDeclaration(p)||i.isInterfaceDeclaration(p)||i.isClassDeclaration(p)||i.isTypeAliasDeclaration(p)||i.isModuleDeclaration(p)){if(p.name){const g=p.name.getText();o.add(g),z(p,i.ModifierFlags.ExportDefault)?u=g:(s&&i.isIdentifier(p.name)||z(p,i.ModifierFlags.Export))&&a.add(g),p.flags&i.NodeFlags.GlobalAugmentation||v(g,[ne(p),Ue(p)])}i.isModuleDeclaration(p)&&(p.body&&(i.isModuleBlock(p.body)||i.isModuleDeclaration(p.body))&&ee(p.body,r),ke(r,p)),te(r,p)}else if(i.isVariableStatement(p)){const{declarations:g}=p.declarationList,E=z(p,i.ModifierFlags.Export);for(const b of p.declarationList.declarations)if(i.isIdentifier(b.name)){const R=b.name.getText();o.add(R),(s||E)&&a.add(R)}if(te(r,p),g.length===1){const b=g[0];i.isIdentifier(b.name)&&v(b.name.getText(),[ne(p),Ue(p)])}else{const b=g.slice(),R=b.shift();v(R.name.getText(),[ne(p),R.getEnd()]);for(const P of b)i.isIdentifier(P.name)&&v(P.name.getText(),[P.getFullStart(),P.getEnd()])}const{flags:T}=p.declarationList,C=`declare ${T&i.NodeFlags.Let?"let":T&i.NodeFlags.Const?"const":"var"} `,D=p.declarationList.getChildren().find(b=>b.kind===i.SyntaxKind.SyntaxList).getChildren();let F=0;for(const b of D)if(b.kind===i.SyntaxKind.CommaToken)F=b.getStart(),r.remove(F,b.getEnd());else if(F){r.appendLeft(F,`;
|
|
19
|
-
`);const R=b.getFullStart(),P=r.slice(R,b.getStart()),se=P.length-P.trimStart().length;se?r.overwrite(R,R+se,C):r.appendLeft(R,C)}}}for(const p of n.statements){if(y(p),i.isExportAssignment(p)&&!p.isExportEquals&&(i.isObjectLiteralExpression(p.expression)||i.isArrayLiteralExpression(p.expression))){u||(u=S("export_default")),r.overwrite(p.getStart(),p.expression.getStart(),`declare var ${u} = `);continue}if(z(p,i.ModifierFlags.ExportDefault)&&(i.isFunctionDeclaration(p)||i.isClassDeclaration(p))){if(p.name)continue;u||(u=S("export_default"));const g=p.getChildren(),E=g.findIndex(D=>D.kind===i.SyntaxKind.ClassKeyword||D.kind===i.SyntaxKind.FunctionKeyword),T=g[E],O=g[E+1];if(O.kind>=i.SyntaxKind.FirstPunctuation&&O.kind<=i.SyntaxKind.LastPunctuation){const D=r.slice(T.getEnd(),O.getStart())!=" ";r.appendLeft(O.getStart(),`${D?" ":""}${u}`)}else r.appendRight(T.getEnd(),` ${u}`)}}for(const p of f.values()){const E=p.pop()[0];for(const T of p)r.move(T[0],T[1],E)}u&&r.append(`
|
|
20
|
-
export default ${u};
|
|
21
|
-
`),a.size&&r.append(`
|
|
22
|
-
export { ${[...a].join(", ")} };
|
|
23
|
-
`),t&&a.size&&(u=S("export_default"),r.append([`
|
|
24
|
-
declare const ${u}: {`,[...a].map(p=>` ${p}: typeof ${p};`).join(`
|
|
25
|
-
`),"};",`export default ${u};
|
|
26
|
-
`].join(`
|
|
27
|
-
`)));for(const[p,g]of m.entries())r.prepend(`import * as ${g} from "${p}";
|
|
28
|
-
`);const d=n.getLineStarts(),h=new Set;for(const p of n.typeReferenceDirectives){h.add(p.fileName);const{line:g}=n.getLineAndCharacterOfPosition(p.pos),E=d[g];let T=n.getLineEndOfPosition(p.pos);r.slice(T,T+1)===`
|
|
29
|
-
`&&(T+=1),r.remove(E,T)}const l=new Set;for(const p of n.referencedFiles){l.add(p.fileName);const{line:g}=n.getLineAndCharacterOfPosition(p.pos),E=d[g];let T=n.getLineEndOfPosition(p.pos);r.slice(T,T+1)===`
|
|
30
|
-
`&&(T+=1),r.remove(E,T)}return{code:r,typeReferences:h,fileReferences:l};function y(p){if(i.forEachChild(p,y),i.isImportTypeNode(p)){if(!i.isLiteralTypeNode(p.argument)||!i.isStringLiteral(p.argument.literal))throw new w(p,"inline imports should have a literal argument");const g=p.argument.literal.text,E=p.getChildren(),T=E.find(F=>F.kind===i.SyntaxKind.ImportKeyword).getStart();let O=p.getEnd();const C=E.find(F=>F.kind===i.SyntaxKind.DotToken||F.kind===i.SyntaxKind.LessThanToken);C&&(O=C.getStart());const D=x(g);r.overwrite(T,O,D)}}function x(p){let g=m.get(p);return g||(g=S(yn(p)),m.set(p,g)),g}function S(p){let g=p;for(;o.has(g);)g=`_${g}`;return o.add(g),g}function v(p,g){let E=f.get(p);if(!E)E=[g],f.set(p,E);else{const T=E[E.length-1];T[1]===g[0]?T[1]=g[1]:E.push(g)}}}c(dn,"preProcess");function hn(n){let e=!1;for(const t of n.statements){if(i.isExportDeclaration(t)||i.isExportAssignment(t))return!1;(e||i.isImportDeclaration(t)||z(t,i.ModifierFlags.Export))&&(e=!0)}return e}c(hn,"isGlobalModule");function te(n,e){if(!i.canHaveModifiers(e))return;if(e.parent.kind===i.SyntaxKind.SourceFile){let r=!1;const s=i.isEnumDeclaration(e)||i.isClassDeclaration(e)||i.isFunctionDeclaration(e)||i.isModuleDeclaration(e)||i.isVariableStatement(e);for(const o of e.modifiers??[])switch(o.kind){case i.SyntaxKind.ExportKeyword:case i.SyntaxKind.DefaultKeyword:n.remove(o.getStart(),o.getEnd()+1);break;case i.SyntaxKind.DeclareKeyword:r=!0}s&&!r&&n.appendRight(e.getStart(),"declare ")}}c(te,"fixModifiers");function ke(n,e){if(e.body){if(i.isModuleDeclaration(e.body)){ke(n,e.body);return}if(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 r of t.exportClause.elements)r.propertyName||n.appendLeft(r.name.getEnd(),` as ${r.name.getText()}`)}}}}c(ke,"duplicateExports");function yn(n){return n.replace(/[^a-zA-Z0-9_$]/g,()=>"_")}c(yn,"getSafeName");function ne(n){const e=n.getFullStart();return e+(Ke(n,e)?1:0)}c(ne,"getStart");function Ue(n){const e=n.getEnd();return e+(Ke(n,e)?1:0)}c(Ue,"getEnd");function Ke(n,e){return n.getSourceFile().getFullText()[e]===`
|
|
31
|
-
`}c(Ke,"newlineAt");const gn=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 ze{static{c(this,"DeclarationScope")}constructor({id:e,range:t}){if(this.scopes=[],e)this.declaration=pn(e,t);else{const{iife:s,fn:o}=ln(t);this.iife=s,this.declaration=o}const r=un();this.declaration.body.body.push(r.stmt),this.returnExpr=r.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:r,expr:s}=cn(e);this.declaration.params.push(s),this.returnExpr.elements.push(r)}pushIdentifierReference(e){this.pushReference(M(e))}convertEntityName(e){return i.isIdentifier(e)?M(e):I({type:"MemberExpression",computed:!1,optional:!1,object:this.convertEntityName(e.left),property:M(e.right)},e)}convertPropertyAccess(e){if(!i.isIdentifier(e.expression)&&!i.isPropertyAccessExpression(e.expression))throw new w(e.expression);if(i.isPrivateIdentifier(e.name))throw new w(e.name);const t=i.isIdentifier(e.expression)?M(e.expression):this.convertPropertyAccess(e.expression);return I({type:"MemberExpression",computed:!1,optional:!1,object:t,property:M(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(M(t));if(i.isPropertyAccessExpression(t))return this.pushReference(this.convertPropertyAccess(t));throw new w(t)}}convertParametersAndType(e){this.convertComputedPropertyName(e);const t=this.convertTypeParameters(e.typeParameters);for(const r of e.parameters)this.convertTypeNode(r.type);this.convertTypeNode(e.type),this.popScope(t)}convertHeritageClauses(e){for(const t of e.heritageClauses||[])for(const r of t.types)this.pushReference(A(r.expression)),this.convertTypeArguments(r)}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 w(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&&!gn.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:r,nameType:s}=e;this.convertTypeNode(t.constraint),this.pushScope(),this.pushTypeVariable(t.name),this.convertTypeNode(r),s&&this.convertTypeNode(s),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 w(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 w(e,'namespace must have a "ModuleBlock" body.');const{statements:r}=e.body;for(const s of r){if(i.isEnumDeclaration(s)||i.isFunctionDeclaration(s)||i.isClassDeclaration(s)||i.isInterfaceDeclaration(s)||i.isTypeAliasDeclaration(s)||i.isModuleDeclaration(s)){if(s.name&&i.isIdentifier(s.name))this.pushTypeVariable(s.name);else throw new w(s,"non-Identifier name not supported");continue}if(i.isVariableStatement(s)){for(const o of s.declarationList.declarations)if(i.isIdentifier(o.name))this.pushTypeVariable(o.name);else throw new w(o,"non-Identifier name not supported");continue}if(i.isImportDeclaration(s)){if(s.importClause&&(s.importClause.name&&this.pushTypeVariable(s.importClause.name),s.importClause.namedBindings))if(i.isNamespaceImport(s.importClause.namedBindings))this.pushTypeVariable(s.importClause.namedBindings.name);else for(const o of s.importClause.namedBindings.elements)this.pushTypeVariable(o.name);continue}if(i.isImportEqualsDeclaration(s)){this.pushTypeVariable(s.name);continue}if(!i.isExportDeclaration(s))throw new w(s,"namespace child (hoisting) not supported yet")}for(const s of r){if(i.isVariableStatement(s)){for(const o of s.declarationList.declarations)o.type&&this.convertTypeNode(o.type);continue}if(i.isFunctionDeclaration(s)){this.convertParametersAndType(s);continue}if(i.isInterfaceDeclaration(s)||i.isClassDeclaration(s)){const o=this.convertTypeParameters(s.typeParameters);this.convertHeritageClauses(s),this.convertMembers(s.members),this.popScope(o);continue}if(i.isTypeAliasDeclaration(s)){const o=this.convertTypeParameters(s.typeParameters);this.convertTypeNode(s.type),this.popScope(o);continue}if(i.isModuleDeclaration(s)){this.convertNamespace(s,t);continue}if(!i.isEnumDeclaration(s)&&!i.isImportDeclaration(s)){if(i.isImportEqualsDeclaration(s)){i.isEntityName(s.moduleReference)&&this.pushReference(this.convertEntityName(s.moduleReference));continue}if(i.isExportDeclaration(s)){if(s.exportClause){if(i.isNamespaceExport(s.exportClause))throw new w(s.exportClause);for(const o of s.exportClause.elements){const a=o.propertyName||o.name;this.pushIdentifierReference(a)}}}else throw new w(s,"namespace child (walking) not supported yet")}}this.popScope()}}function xn({sourceFile:n}){return new Sn(n).transform()}c(xn,"convert");class Sn{static{c(this,"Transformer")}constructor(e){this.sourceFile=e,this.declarations=new Map,this.ast=an(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 r={start:e.getFullStart(),end:e.getEnd()};if(!t){const u=new ze({range:r});return this.pushStatement(u.iife),u}const s=t.getText(),o=new ze({id:t,range:r}),a=this.declarations.get(s);if(a){a.pushIdentifierReference(t),a.declaration.end=r.end;const u=this.ast.body.findIndex(m=>m==a.declaration);for(let m=u+1;m<this.ast.body.length;m++){const f=this.ast.body[m];f.start=f.end=r.end}}else this.pushStatement(o.declaration),this.declarations.set(s,o);return a||o}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 w(e)}removeStatement(e){this.pushStatement(I({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 r=this.createDeclaration(e,e.name);r.pushIdentifierReference(e.name),r.convertNamespace(e,!0)}convertEnumDeclaration(e){this.createDeclaration(e,e.name).pushIdentifierReference(e.name)}convertFunctionDeclaration(e){if(!e.name)throw new w(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 w(e,"ClassDeclaration / InterfaceDeclaration should have a name");const t=this.createDeclaration(e,e.name),r=t.convertTypeParameters(e.typeParameters);t.convertHeritageClauses(e),t.convertMembers(e.members),t.popScope(r)}convertTypeAliasDeclaration(e){const t=this.createDeclaration(e,e.name),r=t.convertTypeParameters(e.typeParameters);t.convertTypeNode(e.type),t.popScope(r)}convertVariableStatement(e){const{declarations:t}=e.declarationList;if(t.length!==1)throw new w(e,"VariableStatement with more than one declaration not yet supported");for(const r of t){if(!i.isIdentifier(r.name))throw new w(e,"VariableDeclaration must have a name");const s=this.createDeclaration(e,r.name);s.convertTypeNode(r.type),r.initializer&&this.trackExpressionReferences(r.initializer,s)}}trackExpressionReferences(e,t){if(i.isIdentifier(e))t.pushIdentifierReference(e);else if(i.isObjectLiteralExpression(e))for(const r of e.properties)i.isShorthandPropertyAssignment(r)?t.pushIdentifierReference(r.name):i.isPropertyAssignment(r)&&this.trackExpressionReferences(r.initializer,t);else if(i.isArrayLiteralExpression(e))for(const r of e.elements)i.isExpression(r)&&this.trackExpressionReferences(r,t);else i.isPropertyAccessExpression(e)&&this.trackExpressionReferences(e.expression,t)}convertExportDeclaration(e){if(i.isExportAssignment(e)){this.pushStatement(I({type:"ExportDefaultDeclaration",declaration:A(e.expression)},e));return}const t=e.moduleSpecifier?A(e.moduleSpecifier):void 0;if(!e.exportClause)this.pushStatement(I({type:"ExportAllDeclaration",source:t,exported:null,attributes:[]},e));else if(i.isNamespaceExport(e.exportClause))this.pushStatement(I({type:"ExportAllDeclaration",source:t,exported:M(e.exportClause.name),attributes:[]},e));else{const r=[];for(const s of e.exportClause.elements)r.push(this.convertExportSpecifier(s));this.pushStatement(I({type:"ExportNamedDeclaration",declaration:null,specifiers:r,source:t,attributes:[]},e))}}convertImportDeclaration(e){if(i.isImportEqualsDeclaration(e)){if(i.isEntityName(e.moduleReference)){const s=this.createDeclaration(e,e.name);s.pushReference(s.convertEntityName(e.moduleReference));return}if(!i.isExternalModuleReference(e.moduleReference))throw new w(e,"ImportEquals should have a literal source.");this.pushStatement(I({type:"ImportDeclaration",specifiers:[{type:"ImportDefaultSpecifier",local:M(e.name)}],source:A(e.moduleReference.expression),attributes:[]},e));return}const t=A(e.moduleSpecifier),r=e.importClause&&e.importClause.namedBindings?this.convertNamedImportBindings(e.importClause.namedBindings):[];e.importClause&&e.importClause.name&&r.push({type:"ImportDefaultSpecifier",local:M(e.importClause.name)}),this.pushStatement(I({type:"ImportDeclaration",specifiers:r,source:t,attributes:[]},e))}convertNamedImportBindings(e){return i.isNamedImports(e)?e.elements.map(t=>{const r=M(t.name),s=t.propertyName?M(t.propertyName):r;return{type:"ImportSpecifier",local:r,imported:s}}):[{type:"ImportNamespaceSpecifier",local:M(e.name)}]}convertExportSpecifier(e){const t=M(e.name);return{type:"ExportSpecifier",exported:t,local:e.propertyName?M(e.propertyName):t}}}class vn{static{c(this,"RelativeModuleDeclarationFixer")}constructor(e,t,r,s){this.sourcemap=r,this.DEBUG=!!process.env.DTS_EXPORTS_FIXER_DEBUG,this.relativeModuleDeclarations=[],this.source=U(e,t.toString()),this.code=t,this.name=s||"./index"}fix(){this.analyze(this.source.statements);for(const e of this.relativeModuleDeclarations){const t=e.getStart(),r=e.getEnd(),s=e.name.kind===i.SyntaxKind.StringLiteral&&"singleQuote"in e.name&&e.name.singleQuote?"'":'"',o=`declare module ${s}${this.name}${s} ${e.body.getText()}`;this.code.overwrite(t,r,o)}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))}}function En(n,e,t){const r=G(n),s=G(e.mappings),o=t.split(`
|
|
32
|
-
`),a=[];for(let u=0;u<r.length;u+=1){const m=r[u];if(!m||m.length===0){a.push([]);continue}const f=m.find(g=>g.length>=4);if(!f){a.push(m);continue}const[,d,h]=f;if(d!==0||h===void 0||h<0||h>=s.length){a.push(m);continue}const l=s[h];if(!l||l.length===0){a.push(m);continue}const y=f[0],x=f.length>=4?f[3]:0,S=y-(x??0),v=o[u]||"",p=[];for(const g of l){const E=g[0]+S;E<0||E>v.length||(g.length===5?p.push([E,g[1],g[2],g[3],g[4]]):g.length===4?p.push([E,g[1],g[2],g[3]]):p.push([E]))}p.sort((g,E)=>g[0]-E[0]),a.push(p)}return me(a)}c(En,"hydrateSourcemap");async function Nn(n){const{fileName:e,originalCode:t,inputMapText:r}=n;if(r)try{return JSON.parse(r)}catch{return null}const s=Ae.fromSource(t);if(s)return s.toObject();const o=c(async a=>{const u=a.split(/[?#]/)[0],m=N.resolve(N.dirname(e),u);return ie.readFile(m,"utf8")},"readMap");try{const a=await Ae.fromMapFileSource(t,o);if(a)return a.toObject()}catch{}try{const a=await ie.readFile(e+".map","utf8");return JSON.parse(a)}catch{return null}}c(Nn,"loadInputSourcemap");const Tn=c(n=>{const e=new Map,t=new Map,r=new Map;return{name:"dts-transform",buildStart(){e.clear(),t.clear(),r.clear()},options({onLog:s,...o}){return{...o,onLog(a,u,m){a==="warn"&&u.code==="CIRCULAR_DEPENDENCY"||(s?s(a,u,m):m(a,u))},treeshake:{moduleSideEffects:"no-external",propertyReadSideEffects:!0,unknownGlobalSideEffects:!1}}},outputOptions(s){return{...s,chunkFileNames:s.chunkFileNames||"[name]-[hash].d.ts",entryFileNames:s.entryFileNames||"[name].d.ts",format:"es",exports:"named",compact:!1,freeze:!0,interop:"esModule",generatedCode:Object.assign({symbols:!1},s.generatedCode),strict:!1}},transform(s,o,a){const u=Q(o),m=this.getModuleIds(),f=Array.from(m).find(v=>Q(v)===u),d=!!(f&&this.getModuleInfo(f)?.isEntry),h=!!(f&&X.test(f));let l=U(o,s);const y=dn({sourceFile:l,isEntry:d,isJSON:h});e.set(l.fileName,y.typeReferences),t.set(l.fileName,y.fileReferences),s=y.code.toString(),l=U(o,s);const x=xn({sourceFile:l});if(process.env.DTS_DUMP_AST&&(console.log(o),console.log(s),console.log(JSON.stringify(x.ast.body,void 0,2))),!n)return{code:s,ast:x.ast};const S=y.code.generateMap({hires:!0,source:o});return _.test(o)&&r.set(o,{fileName:o,originalCode:s,inputMapText:a}),{code:s,ast:x.ast,map:S}},renderChunk(s,o,a){const u=U(o.fileName,s),m=new on(u),f=new Set,d=new Set;for(const S of Object.keys(o.modules)){for(const v of e.get(S.split("\\").join("/"))||[])f.add(v);for(const v of t.get(S.split("\\").join("/"))||[])if(v.startsWith(".")){const p=N.join(N.dirname(S),v),g=a.file&&N.dirname(a.file)||o.facadeModuleId&&N.dirname(o.facadeModuleId)||".";let E=N.relative(g,p).split("\\").join("/");E[0]!=="."&&(E="./"+E),d.add(E)}else d.add(v)}let h=Ve(Array.from(d,S=>`/// <reference path="${S}" />`));h+=Ve(Array.from(f,S=>`/// <reference types="${S}" />`)),h+=m.fix(),h||(h+=`
|
|
33
|
-
export { };`);const y=new mn(o.fileName,h).fix();return new vn(o.fileName,"magicCode"in y&&y.magicCode?y.magicCode:new W(h),!!a.sourcemap,"./"+N.basename(o.fileName,".d.ts")).fix()},async generateBundle(s,o){if(!s.sourcemap)return;const a=new Map,u=Array.from(r.entries()),m=await Promise.all(u.map(async([h,l])=>({fileName:h,inputMap:await Nn(l)}))),f=c(h=>/^[a-z][a-z0-9+.-]*:\/\//i.test(h),"isUrl");for(const{fileName:h,inputMap:l}of m)if(l&&l.sources){const y=N.dirname(h);let x;l.sourceRoot?x=f(l.sourceRoot)?l.sourceRoot:N.resolve(y,l.sourceRoot):x=y;const S=f(x);a.set(h,{version:l.version??3,sources:l.sources.map(v=>{if(v===null)return null;if(f(v))return v;if(S){const p=x.endsWith("/")?x:x+"/";return new URL(v,p).toString()}return N.isAbsolute(v)?v:N.resolve(x,v)}),mappings:l.mappings,names:l.names})}const d=s.dir||(s.file?N.dirname(s.file):process.cwd());for(const h of Object.values(o)){if(h.type!=="chunk"||!h.map)continue;const l=N.join(d,N.dirname(h.fileName)),y=c(C=>f(C)?C:(N.isAbsolute(C)?N.relative(l,C):C).replaceAll("\\","/"),"toRelativeSourcePath"),x=c(C=>C===null?null:y(C),"toRelativeSourcePathOrNull"),S=new Map;for(const C of h.map.sources){if(!C||f(C))continue;const D=N.resolve(l,C);let F=a.get(D);if(!F&&/\.[cm]?[tj]sx?$/.test(D)&&!D.endsWith(".d.ts")){const b=D.replace(/\.[cm]?[tj]sx?$/,".d.ts");F=a.get(b)}F&&S.set(D,F)}if(S.size===0){if(delete h.map.sourcesContent,h.map.sources.length===0&&h.facadeModuleId){const C=a.get(h.facadeModuleId);if(C&&C.sources.length>0){const D=C.sources.map(x);h.map.sources=D}}Je(o,h.fileName,{sources:h.map.sources.map(x),mappings:h.map.mappings,names:h.map.names||[]});continue}const p=h.map.sources.length===1&&S.size===1?Array.from(S.values())[0]:null,g=p&&p.sources.length===1;let E,T,O;if(g&&p)E=p.sources.map(x),T=En(h.map.mappings,p,h.code),O=p.names||[];else{const C=new Set,D=qt(h.map,F=>{const b=N.resolve(l,F);if(C.has(b))return null;C.add(b);const R=S.get(b);return R||null});E=D.sources.map(x),T=typeof D.mappings=="string"?D.mappings:"",O=D.names||[]}h.map.sources=E,delete h.map.sourcesContent,h.map.mappings=T,h.map.names=O,Je(o,h.fileName,{sources:E,mappings:T,names:O})}}}},"transform");function Ve(n){return n.length?n.join(`
|
|
34
|
-
`)+`
|
|
35
|
-
`:""}c(Ve,"writeBlock");function Je(n,e,t){const r=`${e}.map`,s=n[r];s&&s.type==="asset"&&(s.source=JSON.stringify({version:3,file:N.basename(e),...t}))}c(Je,"updateSourcemapAsset");const Cn=/\.([cm]ts|[tj]sx?)$/;function re({entries:n,programs:e,resolvedOptions:t},r,s){const{compilerOptions:o,tsconfig:a}=t;if(!e.length&&_.test(r))return{code:s};const u=n.includes(r),m=e.find(f=>{if(u)return f.getRootFileNames().includes(r);{const d=f.getSourceFile(r);return d&&f.isSourceFileFromExternalLibrary(d)?!1:!!d}});if(m){const f=m.getSourceFile(r);return{code:f?.getFullText(),source:f,program:m}}else if(i.sys.fileExists(r)){if(e.length>0&&_.test(r)&&(t.includeExternal.length>0||t.respectExternal))return{code:s};const f=en(r,o,a,t.sourcemap);e.push(f);const d=f.getSourceFile(r);return{code:d?.getFullText(),source:d,program:f}}else return null}c(re,"getModule");const We=c((n={})=>{const e={entries:[],programs:[],resolvedOptions:Yt(n)},t=Tn(e.resolvedOptions.sourcemap);return{name:"dts",outputOptions:t.outputOptions,renderChunk:t.renderChunk,generateBundle:t.generateBundle,options(r){let{input:s=[]}=r;if(!Array.isArray(s))s=typeof s=="string"?[s]:Object.values(s);else if(s.length>1){r.input={};for(const o of s){let a=Q(o);N.isAbsolute(o)?a=N.basename(a):a=N.normalize(a),r.input[a]=o}}return e.programs=tn(Object.values(s),e.resolvedOptions.compilerOptions,e.resolvedOptions.tsconfig,e.resolvedOptions.sourcemap),t.options.call(this,r)},transform(r,s){if(!Cn.test(s)&&!X.test(s))return null;const o=c(f=>{if(f.program){const d=N.dirname(s);f.program.getSourceFiles().map(l=>l.fileName).filter(l=>l.startsWith(d)).forEach(this.addWatchFile)}},"watchFiles"),a=c(()=>{const f=re(e,s,r);return f?(o(f),t.transform.call(this,f.code,s)):null},"handleDtsFile"),u=c(()=>{const f=Le(s),d=re(e,f,r);return d?(o(d),t.transform.call(this,d.code,f)):null},"treatTsAsDts"),m=c(()=>{const f=re(e,s,r);if(!f||!f.source||!f.program)return null;o(f);const d=Le(s);let h,l;const{emitSkipped:y,diagnostics:x}=f.program.emit(f.source,(v,p)=>{v.endsWith(".map")?l=p:h=p},void 0,!0,void 0,!0);if(y){const v=x.filter(p=>p.category===i.DiagnosticCategory.Error);v.length&&(console.error(i.formatDiagnostics(v,Y)),this.error("Failed to compile. Check the logs above."))}if(!h)return null;const S=h.replace(/\n?\/\/# sourceMappingURL=[^\n]+/,"");return t.transform.call(this,S,d,l)},"generateDts");return _.test(s)?a():X.test(s)?m():u()??m()},resolveId(r,s){if(!s){e.entries.push(N.resolve(r));return}s=s.split("\\").join("/");let o=e.resolvedOptions.compilerOptions;if(e.resolvedOptions.tsconfig){const u=r.startsWith(".")?N.resolve(N.dirname(s),r):r;o=Z(u,e.resolvedOptions.compilerOptions,e.resolvedOptions.tsconfig,e.resolvedOptions.sourcemap).compilerOptions}const{resolvedModule:a}=i.resolveModuleName(r,s,o,i.sys);if(a)return a.isExternalLibraryImport&&a.packageId&&e.resolvedOptions.includeExternal.includes(a.packageId.name)?{id:N.resolve(a.resolvedFileName)}:!e.resolvedOptions.respectExternal&&a.isExternalLibraryImport?{id:r,external:!0}:{id:N.resolve(a.resolvedFileName)}}}},"plugin");export{We as default,We as dts};
|