@visulima/rollup-plugin-dts 1.0.0-alpha.33 → 1.0.0-alpha.35

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/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## @visulima/rollup-plugin-dts [1.0.0-alpha.35](https://github.com/visulima/packem/compare/@visulima/rollup-plugin-dts@1.0.0-alpha.34...@visulima/rollup-plugin-dts@1.0.0-alpha.35) (2026-06-16)
2
+
3
+ ### Features
4
+
5
+ * **rollup-plugin-dts:** sync upstream fixes ([#208](https://github.com/visulima/packem/issues/208)/[#238](https://github.com/visulima/packem/issues/238)/[#254](https://github.com/visulima/packem/issues/254)/[#259](https://github.com/visulima/packem/issues/259)) + js-sibling skip ([190e045](https://github.com/visulima/packem/commit/190e04502f9ed331e230f93e3c318afae1ef0196)), closes [#92](https://github.com/visulima/packem/issues/92)
6
+
7
+ ### Bug Fixes
8
+
9
+ * **rollup-plugin-dts:** build-mode dts sourcemaps and JSDoc .js re-exports ([#255](https://github.com/visulima/packem/issues/255)) ([e34f3da](https://github.com/visulima/packem/commit/e34f3daab981b9319c5884eace871f6f1116cf39))
10
+ * **rollup-plugin-dts:** rewrite inferred re-export specifiers to the imported dependency ([#227](https://github.com/visulima/packem/issues/227)) ([36e5c49](https://github.com/visulima/packem/commit/36e5c49ec4c1b300741b09d3d1757ede7965df09))
11
+
12
+ ## @visulima/rollup-plugin-dts [1.0.0-alpha.34](https://github.com/visulima/packem/compare/@visulima/rollup-plugin-dts@1.0.0-alpha.33...@visulima/rollup-plugin-dts@1.0.0-alpha.34) (2026-06-12)
13
+
14
+ ### Features
15
+
16
+ * **rollup-plugin-dts:** support rolldown via virtual-module guard and a rolldown test lane ([8e2b95d](https://github.com/visulima/packem/commit/8e2b95d7b1b45dfa14803dd2830948d52a7f3153))
17
+
18
+ ### Bug Fixes
19
+
20
+ * resolve package audit findings across the monorepo ([2800d68](https://github.com/visulima/packem/commit/2800d68c00de2ff488b51ad90179731b929b9642))
21
+ * **rollup-plugin-dts:** fail fast when the tsc worker fork or tsgo run fails ([e40c119](https://github.com/visulima/packem/commit/e40c119d89583eb0bb9ab3c2d53ba0e260c55b6e))
22
+
23
+ ### Tests
24
+
25
+ * **rollup-plugin-dts:** satisfy eslint rules in tsgo spawn tests ([d816d6c](https://github.com/visulima/packem/commit/d816d6c363804d8c50becf2754bfab8873f2d79f))
26
+
1
27
  ## @visulima/rollup-plugin-dts [1.0.0-alpha.33](https://github.com/visulima/packem/compare/@visulima/rollup-plugin-dts@1.0.0-alpha.32...@visulima/rollup-plugin-dts@1.0.0-alpha.33) (2026-06-04)
2
28
 
3
29
  ### Bug Fixes
@@ -1,2 +1,2 @@
1
- export { a as RE_CSS, b as RE_DTS, c as RE_DTS_MAP, d as RE_JS, e as RE_JSON, f as RE_NODE_MODULES, g as RE_TS, h as RE_VUE, i as filenameDtsTo, j as filenameJsToDts, k as filenameToDts, r as replaceTemplateName, l as resolveTemplateFunction } from "./packem_shared/filename.d-BqANlmrG.js";
1
+ export { a as RE_CSS, b as RE_DTS, c as RE_DTS_MAP, d as RE_JS, e as RE_JSON, f as RE_NODE_MODULES, g as RE_TS, h as RE_VUE, i as dtsEntryFileName, j as filenameDtsTo, k as filenameJsToDts, l as filenameToDts, r as replaceTemplateName, m as resolveTemplateFunction } from "./packem_shared/filename.d-CMm5yggz.js";
2
2
  import 'estree';
package/dist/filename.js CHANGED
@@ -1 +1 @@
1
- var c=Object.defineProperty;var a=(e,s)=>c(e,"name",{value:s,configurable:!0});var m=Object.defineProperty,t=a((e,s)=>m(e,"name",{value:s,configurable:!0}),"t");const l=/\.([cm]?)jsx?$/,n=/\.([cm]?)tsx?$/,o=/\.d\.([cm]?)ts$/,$=/\.d\.([cm]?)ts\.map$/,i=/[\\/]node_modules[\\/]/,E=/\.(?:css|scss|sass|less|styl|stylus)$/,r=/\.vue$/,p=/\.json$/,_=t(e=>e.replace(l,".d.$1ts"),"filenameJsToDts"),f=t(e=>e.replace(r,".vue.ts").replace(n,".d.$1ts").replace(l,".d.$1ts").replace(p,".json.d.ts"),"filenameToDts"),u=t((e,s)=>e.replace(o,`.$1${s}`),"filenameDtsTo"),D=t((e,s)=>typeof e=="function"?e(s):e,"resolveTemplateFunction"),d=t((e,s)=>e.replaceAll("[name]",s),"replaceTemplateName");export{E as RE_CSS,o as RE_DTS,$ as RE_DTS_MAP,l as RE_JS,p as RE_JSON,i as RE_NODE_MODULES,n as RE_TS,r as RE_VUE,u as filenameDtsTo,_ as filenameJsToDts,f as filenameToDts,d as replaceTemplateName,D as resolveTemplateFunction};
1
+ var r=Object.defineProperty;var n=(e,s)=>r(e,"name",{value:s,configurable:!0});var m=Object.defineProperty,t=n((e,s)=>m(e,"name",{value:s,configurable:!0}),"t");const l=/\.([cm]?)jsx?$/,o=/\.([cm]?)tsx?$/,c=/\.d\.([cm]?)ts$/,$=/\.d\.([cm]?)ts\.map$/,d=/[\\/]node_modules[\\/]/,f=/\.(?:css|scss|sass|less|styl|stylus)$/,p=/\.vue$/,i=/\.json$/,u=t(e=>e.replace(l,".d.$1ts"),"filenameJsToDts"),_=t(e=>e.replace(p,".vue.ts").replace(o,".d.$1ts").replace(l,".d.$1ts").replace(i,".json.d.ts"),"filenameToDts"),D=t((e,s)=>e.replace(c,`.$1${s}`),"filenameDtsTo"),R=t((e,s)=>typeof e=="function"?e(s):e,"resolveTemplateFunction"),E=t((e,s)=>e.replaceAll("[name]",s),"replaceTemplateName"),S=t((e,s,a)=>{if(c.test(e))return E(e,a?s.slice(0,-2):s);if(l.test(e))return a&&e.includes("[name]")?e.replace(l,".$1ts"):u(e)},"dtsEntryFileName");export{f as RE_CSS,c as RE_DTS,$ as RE_DTS_MAP,l as RE_JS,i as RE_JSON,d as RE_NODE_MODULES,o as RE_TS,p as RE_VUE,S as dtsEntryFileName,D as filenameDtsTo,u as filenameJsToDts,_ as filenameToDts,E as replaceTemplateName,R as resolveTemplateFunction};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RenderedChunk, P as Plugin } from "./packem_shared/filename.d-BqANlmrG.js";
2
- export { a as RE_CSS, b as RE_DTS, c as RE_DTS_MAP, d as RE_JS, e as RE_JSON, f as RE_NODE_MODULES, g as RE_TS, h as RE_VUE } from "./packem_shared/filename.d-BqANlmrG.js";
1
+ import { R as RenderedChunk, P as Plugin } from "./packem_shared/filename.d-CMm5yggz.js";
2
+ export { a as RE_CSS, b as RE_DTS, c as RE_DTS_MAP, d as RE_JS, e as RE_JSON, f as RE_NODE_MODULES, g as RE_TS, h as RE_VUE } from "./packem_shared/filename.d-CMm5yggz.js";
3
3
  import { TsConfigJson } from '@visulima/tsconfig';
4
4
  import { IsolatedDeclarationsOptions } from 'oxc-transform';
5
5
  import 'estree';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- var T=Object.defineProperty;var p=(t,e)=>T(t,"name",{value:e,configurable:!0});import{createDebug as j}from"obug";import I from"magic-string";import{RE_DTS as g,resolveTemplateFunction as J,replaceTemplateName as _,RE_TS as A,RE_VUE as C,RE_JSON as M,RE_CSS as W,filenameToDts as D,RE_NODE_MODULES as P,RE_JS as B,filenameJsToDts as U}from"./filename.js";import{RE_DTS_MAP as ye}from"./filename.js";import q from"./packem_shared/createFakeJsPlugin-B3ze2uTd.js";import{c as z}from"./packem_shared/generate-BTUIV9zv.js";import{resolveOptions as G}from"./packem_shared/resolveOptions-xvkhsYiy.js";import{existsSync as $,readFileSync as L}from"node:fs";import h from"node:path";import{ResolverFactory as V}from"oxc-resolver";var H=Object.defineProperty,K=p((t,e)=>H(t,"name",{value:e,configurable:!0}),"o$2");const Q=K(({banner:t,footer:e})=>({name:"rollup-plugin-dts:banner",async renderChunk(n,i){if(!g.test(i.fileName))return;const a=new I(n);if(t){const l=await(typeof t=="function"?t(i):t);l&&a.prepend(`${l}
2
- `)}if(e){const l=await(typeof e=="function"?e(i):e);l&&a.append(`
3
- ${l}`)}return{code:a.toString(),get map(){return a.generateMap({hires:"boundary",includeContent:!0,source:i.fileName})}}}}),"createBannerPlugin");var X=Object.defineProperty,Y=p((t,e)=>X(t,"name",{value:e,configurable:!0}),"o$1");const Z=Y(({entry:t,sideEffects:e})=>({buildStart(){t&&this.warn("The `entry` option has no effect in `dtsInput` mode; control which declaration files are emitted via the plugin's input list instead.")},name:"rollup-plugin-dts:dts-input",options:e?void 0:n=>({...n,treeshake:n.treeshake===!1?!1:{...typeof n.treeshake=="object"?n.treeshake:{},moduleSideEffects:!1}}),outputOptions(n){return{...n,entryFileNames(i){const{entryFileNames:a}=n;if(a){const l=J(a,i),b=_(l,i.name);if(g.test(b))return l;const m=_(l,`${i.name}.d`);if(g.test(m))return m}return g.test(i.name)?i.name:i.name.endsWith(".d")?"[name].ts":"[name].d.ts"}}}}),"createDtsInputPlugin");var ee=Object.defineProperty,E=p((t,e)=>ee(t,"name",{value:e,configurable:!0}),"c");const v=E(t=>A.test(t)||C.test(t)||M.test(t),"isSourceFile"),te=E(({cwd:t,resolve:e,resolver:n,sideEffects:i,tsconfig:a,tsconfigRaw:l})=>{const b=new V({conditionNames:["types","typings","import","require"],mainFields:["types","typings","module","main"],tsconfig:a?{configFile:a,references:"auto"}:void 0}),m=i?!0:null;return{name:"rollup-plugin-dts:resolver",resolveId:{async handler(s,o,c){if(!o||!g.test(o))return;const r={external:!0,id:s,moduleSideEffects:i};if(W.test(s))return r;if(!y(s)&&w(s)){const u=await F(s,o,null);if(u&&g.test(u))return{id:u,moduleSideEffects:m};if(u&&v(u))return await this.load({id:u}),{id:D(u),moduleSideEffects:m}}const f=await this.resolve(s,o,c);if(f?.external)return r;const d=await F(s,o,f);return d?P.test(d)&&!w(s)&&!(y(s)&&P.test(o)&&k(o))?r:g.test(d)?{id:d,moduleSideEffects:m}:v(d)?(await this.load({id:d}),{id:D(d),moduleSideEffects:m}):null:y(s)?null:r},order:"pre"}};function w(s){return typeof e=="boolean"?e:e.some(o=>typeof o=="string"?s===o:o.test(s))}function k(s){const o=s.replaceAll("\\","/"),c="/node_modules/",r=o.lastIndexOf(c);if(r===-1)return!1;const f=o.slice(r+c.length),d=f.indexOf("/");let u=d===-1?f:f.slice(0,d);if(u.startsWith("@")){const O=f.slice(u.length+1),R=O.indexOf("/"),N=R===-1?O:O.slice(0,R);u=`${u}/${N}`}return w(u)}async function F(s,o,c){let r;if(n==="tsc"){const{default:f}=await import("./packem_chunks/resolver.js");r=f(s,o,t,a,l)}else r=b.resolveDtsSync(o,s).path;if(r&&(r=h.normalize(r)),r&&B.test(r)&&ne(r)){const f=U(r);if($(f))return f}return!r||!v(r)?c&&y(c.id)&&v(c.id)&&!c.external?c.id:null:r}},"createDtsResolvePlugin"),y=E(t=>t.startsWith(".")||h.isAbsolute(t),"isFilePath"),S=new Map,ne=E(t=>{const e=h.dirname(t);if(S.has(e))return S.get(e);let n=e;for(;n!==h.dirname(n);){const i=h.join(n,"package.json");if($(i)){let a=!1;try{const{exports:l}=JSON.parse(L(i,"utf8"));a=l===void 0||typeof l=="string"}catch{}return S.set(e,a),a}n=h.dirname(n)}return S.set(e,!1),!1},"canFallBackToSiblingDts");var re=Object.defineProperty,se=p((t,e)=>re(t,"name",{value:e,configurable:!0}),"o");const x=j("rollup-plugin-dts:options"),ge=se((t={})=>{x("resolving dts options");const e=G(t);x("resolved dts options %o",e);const n=[];return t.dtsInput?n.push(Z(e)):n.push(z(e)),n.push(te(e),q(e)),(t.banner||t.footer)&&n.push(Q(e)),n},"dts");export{W as RE_CSS,g as RE_DTS,ye as RE_DTS_MAP,B as RE_JS,M as RE_JSON,P as RE_NODE_MODULES,A as RE_TS,C as RE_VUE,q as createFakeJsPlugin,z as createGeneratePlugin,ge as dts,G as resolveOptions};
1
+ var I=Object.defineProperty;var p=(e,t)=>I(e,"name",{value:t,configurable:!0});import{createDebug as C}from"obug";import A from"magic-string";import{RE_DTS as m,resolveTemplateFunction as M,replaceTemplateName as _,RE_TS as W,RE_VUE as q,RE_JSON as z,RE_JS as $,RE_NODE_MODULES as R,RE_CSS as B,filenameToDts as F,filenameJsToDts as U}from"./filename.js";import{RE_DTS_MAP as be}from"./filename.js";import G from"./packem_shared/createFakeJsPlugin-DeA0eOgM.js";import{c as L}from"./packem_shared/generate-B50-mrCC.js";import{resolveOptions as V}from"./packem_shared/resolveOptions-CH0xNcZj.js";import{existsSync as k,readFileSync as H}from"node:fs";import h from"node:path";import{ResolverFactory as K}from"oxc-resolver";var Q=Object.defineProperty,X=p((e,t)=>Q(e,"name",{value:t,configurable:!0}),"o$2");const Y=X(({banner:e,footer:t})=>({name:"rollup-plugin-dts:banner",async renderChunk(n,o){if(!m.test(o.fileName))return;const l=new A(n);if(e){const a=await(typeof e=="function"?e(o):e);a&&l.prepend(`${a}
2
+ `)}if(t){const a=await(typeof t=="function"?t(o):t);a&&l.append(`
3
+ ${a}`)}return{code:l.toString(),get map(){return l.generateMap({hires:"boundary",includeContent:!0,source:o.fileName})}}}}),"createBannerPlugin");var Z=Object.defineProperty,ee=p((e,t)=>Z(e,"name",{value:t,configurable:!0}),"o$1");const te=ee(({entry:e,sideEffects:t})=>({buildStart(){e&&this.warn("The `entry` option has no effect in `dtsInput` mode; control which declaration files are emitted via the plugin's input list instead.")},name:"rollup-plugin-dts:dts-input",options:t?void 0:n=>({...n,treeshake:n.treeshake===!1?!1:{...typeof n.treeshake=="object"?n.treeshake:{},moduleSideEffects:!1}}),outputOptions(n){return{...n,entryFileNames(o){const{entryFileNames:l}=n;if(l){const a=M(l,o),w=_(a,o.name);if(m.test(w))return a;const g=_(a,`${o.name}.d`);if(m.test(g))return g}return m.test(o.name)?o.name:o.name.endsWith(".d")?"[name].ts":"[name].d.ts"}}}}),"createDtsInputPlugin");var ne=Object.defineProperty,y=p((e,t)=>ne(e,"name",{value:t,configurable:!0}),"f");const b=y(e=>W.test(e)||q.test(e)||z.test(e),"isSourceFile"),re=y(({cwd:e,emitJs:t,resolve:n,resolver:o,sideEffects:l,tsconfig:a,tsconfigRaw:w})=>{const g=y(r=>t&&$.test(r)&&!R.test(r),"isRedirectableJs"),T=new K({conditionNames:["types","typings","import","require"],mainFields:["types","typings","module","main"],tsconfig:a?{configFile:a,references:"auto"}:void 0}),S=l?!0:null;return{name:"rollup-plugin-dts:resolver",resolveId:{async handler(r,s,c){if(!s||!m.test(s))return;const i={external:!0,id:r,moduleSideEffects:l};if(B.test(r))return i;if(!v(r)&&x(r)){const f=await D(r,s,null);if(f&&m.test(f))return{id:f,moduleSideEffects:S};if(f&&b(f))return await this.load({id:f}),{id:F(f),moduleSideEffects:S};this.warn(`Could not resolve declaration (.d.ts) types for "${r}" (requested via the \`resolve\` option, imported from ${s}); it will be left external. Ensure the package ships types or provides a \`types\` condition in its exports.`)}const u=await this.resolve(r,s,c);if(u?.external)return i;const d=await D(r,s,u);return d?R.test(d)&&!x(r)&&!(v(r)&&R.test(s)&&J(s))?i:m.test(d)?{id:d,moduleSideEffects:S}:b(d)||g(d)?(await this.load({id:d}),{id:F(d),moduleSideEffects:S}):null:(v(r)||this.warn(`Could not resolve declaration (.d.ts) types for bare specifier "${r}" (imported from ${s}); leaving it external.`),v(r)?null:i)},order:"pre"}};function x(r){return typeof n=="boolean"?n:n.some(s=>typeof s=="string"?r===s:s.test(r))}function J(r){const s=r.replaceAll("\\","/"),c="/node_modules/",i=s.lastIndexOf(c);if(i===-1)return!1;const u=s.slice(i+c.length),d=u.indexOf("/");let f=d===-1?u:u.slice(0,d);if(f.startsWith("@")){const O=u.slice(f.length+1),P=O.indexOf("/"),j=P===-1?O:O.slice(0,P);f=`${f}/${j}`}return x(f)}async function D(r,s,c){let i;if(o==="tsc"){const{default:u}=await import("./packem_chunks/resolver.js");i=u(r,s,e,a,w)}else i=T.resolveDtsSync(s,r).path;if(i&&(i=h.normalize(i)),i&&$.test(i)&&ie(i)){const u=U(i);if(k(u))return u}return!i||!(b(i)||g(i))?c&&v(c.id)&&(b(c.id)||g(c.id))&&!c.external?c.id:null:i}},"createDtsResolvePlugin"),v=y(e=>e.startsWith(".")||h.isAbsolute(e),"isFilePath"),E=new Map,ie=y(e=>{const t=h.dirname(e);if(E.has(t))return E.get(t);let n=t;for(;n!==h.dirname(n);){const o=h.join(n,"package.json");if(k(o)){let l=!1;try{const{exports:a}=JSON.parse(H(o,"utf8"));l=a===void 0||typeof a=="string"}catch{}return E.set(t,l),l}n=h.dirname(n)}return E.set(t,!1),!1},"canFallBackToSiblingDts");var se=Object.defineProperty,oe=p((e,t)=>se(e,"name",{value:t,configurable:!0}),"o");const N=C("rollup-plugin-dts:options"),ve=oe((e={})=>{N("resolving dts options");const t=V(e);N("resolved dts options %o",t);const n=[];return e.dtsInput?n.push(te(t)):n.push(L(t)),n.push(re(t),G(t)),(e.banner||e.footer)&&n.push(Y(t)),n},"dts");export{B as RE_CSS,m as RE_DTS,be as RE_DTS_MAP,$ as RE_JS,z as RE_JSON,R as RE_NODE_MODULES,W as RE_TS,q as RE_VUE,G as createFakeJsPlugin,L as createGeneratePlugin,ve as dts,V as resolveOptions};
@@ -1 +1 @@
1
- var N=Object.defineProperty;var h=(e,t)=>N(e,"name",{value:t,configurable:!0});import{createDebug as P}from"obug";import u from"typescript";import{g as F}from"../packem_shared/generate-BTUIV9zv.js";import{posix as w}from"node:path";import{pathToFileURL as S}from"node:url";import{dirname as T}from"@visulima/path";var U=Object.defineProperty,R=h((e,t)=>U(e,"name",{value:t,configurable:!0}),"i");const B=P("rollup-plugin-dts:tsc-system"),x=R(e=>({...u.sys,deleteFile(t,...r){e.delete(t),u.sys.deleteFile?.(t,...r)},directoryExists(t){return[...e.keys()].some(r=>r.startsWith(t))?!0:u.sys.directoryExists(t)},fileExists(t){return e.has(t)?!0:u.sys.fileExists(t)},readFile(t,...r){return e.has(t)?e.get(t):u.sys.readFile(t,...r)},resolvePath(t){return e.has(t)?t:u.sys.resolvePath(t)},write(t){B(t)},writeFile(t,r,...o){e.set(t,r),u.sys.writeFile(t,r,...o)}}),"createFsSystem"),W=R(e=>({...x(e),deleteFile(t){e.delete(t)},writeFile(t,r){e.set(t,r)}}),"createMemorySystem");var J=Object.defineProperty,$=h((e,t)=>J(e,"name",{value:t,configurable:!0}),"o$1");const z=$(e=>{const t=$(r=>u.isPropertySignature(r)&&u.isPrivateIdentifier(r.name)?e.factory.updatePropertySignature(r,r.modifiers,e.factory.createStringLiteral(r.name.text),r.questionToken,r.type):u.visitEachChild(r,t,e),"visitor");return r=>u.visitNode(r,t,u.isSourceFile)},"stripPrivateFields"),M={getCanonicalFileName:u.sys.useCaseSensitiveFileNames?e=>e:e=>e.toLowerCase(),getCurrentDirectory:$(()=>u.sys.getCurrentDirectory(),"getCurrentDirectory"),getNewLine:$(()=>u.sys.newLine,"getNewLine")},O={afterDeclarations:[z]},D=$((e,t,r)=>{if(!e||e.sourceRoot)return;const o=w.dirname(S(t).pathname),s=w.dirname(S(r).pathname);o!==s&&(e.sourceRoot=w.relative(s,o))},"setSourceMapRoot");var H=Object.defineProperty,m=h((e,t)=>H(e,"name",{value:t,configurable:!0}),"f$1");const g=P("rollup-plugin-dts:tsc-build"),G=m((e,t,r,o,s)=>{let i=e.projects.get(r);return i?(g(`skip building projects for ${r}`),i):(i=V(t,r,o,s),e.projects.set(r,i),i)},"getOrBuildProjects"),V=m((e,t,r,o)=>{g(`start building projects for ${t}`);const s=A(t,e,r,o);g("collected %d projects: %j",s.length,s.map(n=>n.tsconfigPath));const i=u.createSolutionBuilderHost(e,K),l=u.createSolutionBuilder(i,[t],{force:r,verbose:!0}).build(void 0,void 0,void 0,n=>(g(`transforming project ${n}`),O));g(`built solution for ${t} with exit status ${l}`);const a=new Map;for(const n of s)for(const c of n.parsedConfig.fileNames)a.set(e.resolvePath(c),n);return a},"buildProjects"),A=m((e,t,r,o)=>{const s=new Set,i=[],l=[t.resolvePath(e)];for(;;){const a=l.pop();if(!a)break;if(s.has(a))continue;s.add(a);const n=I(a,t);if(n){n.options=L(n.options,{force:r,sourcemap:o,tsconfigPath:a}),i.push({parsedConfig:n,tsconfigPath:a});for(const c of n.projectReferences??[])l.push(u.resolveProjectReferencePath(c))}}return i},"collectProjectGraph"),I=m((e,t)=>{const r=[],o=u.getParsedCommandLineOfConfigFile(e,void 0,{...t,onUnRecoverableConfigFileDiagnostic:m(s=>{r.push(s)},"onUnRecoverableConfigFileDiagnostic")});if(r.length>0)throw new Error(`[rollup-plugin-dts] Unable to read ${e}: ${u.formatDiagnostics(r,M)}`);return o},"parseTsconfig"),L=m((e,t)=>{const r=e.noEmit??!1,o=e.declaration??!!e.composite,s=e.declarationMap??!1,i=t?.tsconfigPath&&!t.force;return r&&(e={...e,noEmit:!1},i&&console.warn(`[rollup-plugin-dts] ${t.tsconfigPath} has "noEmit" set to true. Please set it to false to generate declaration files.`)),o||(e={...e,declaration:!0},i&&console.warn(`[rollup-plugin-dts] ${t.tsconfigPath} has "declaration" set to false. Please set it to true to generate declaration files.`)),!s&&t?.sourcemap&&(e={...e,declarationMap:!0},i&&console.warn(`[rollup-plugin-dts] ${t.tsconfigPath} has "declarationMap" set to false. Please set it to true if you want to generate source maps for declaration files.`)),e},"patchCompilerOptions"),K=m((e,t,...r)=>u.createEmitAndSemanticDiagnosticsBuilderProgram(e,L(t??{},null),...r),"createProgramWithPatchedCompilerOptions"),k=m(e=>{const{context:t=F,id:r,incremental:o,sourcemap:s,tsconfig:i}=e;if(g(`running tscEmitBuild id: ${r}, tsconfig: ${i}, incremental: ${o}`),!i)return{error:"[rollup-plugin-dts] build mode requires a tsconfig path"};const l=(o?x:W)(t.files),a=l.resolvePath(r);a!==r&&g(`resolved id from ${r} to ${a}`);const n=G(t,l,i,!o,s).get(a);if(!n)return g(`unable to locate a project containing ${a}`),{error:`Unable to locate ${r} from the given tsconfig file ${i}`};g(`loaded project ${n.tsconfigPath} for ${r}`);const c=!l.useCaseSensitiveFileNames,f=u.getOutputFileNames(n.parsedConfig,a,c);let v,y;for(const d of f){if(d.endsWith(".d.ts")){if(!l.fileExists(d)){console.warn(`[rollup-plugin-dts] Unable to read file ${d}`);continue}v=l.readFile(d);continue}if(d.endsWith(".d.ts.map")){if(!l.fileExists(d))continue;const E=l.readFile(d);if(!E){console.warn(`[rollup-plugin-dts] Unexpected sourcemap ${d}`);continue}y=JSON.parse(E),D(y,d,a)}}return v?{code:v,map:y}:o?(g("incremental build failed"),k({...e,incremental:!1})):(g(`unable to build .d.ts file for ${r}`),n.parsedConfig.options.declaration!==!0?{error:`Unable to build .d.ts file for ${r}; Make sure the "declaration" option is set to true in ${n.tsconfigPath}`}:{error:`Unable to build .d.ts file for ${r}; This seems like a bug of rollup-plugin-dts. Please report this issue to https://github.com/sxzz/rollup-plugin-dts/issues`})},"tscEmitBuild");var Y=Object.defineProperty,b=h((e,t)=>Y(e,"name",{value:t,configurable:!0}),"g");const Q=b(()=>{const e=P("rollup-plugin-dts:vue");e("loading vue language tools");try{const t=require.resolve("vue-tsc"),{proxyCreateProgram:r}=require(require.resolve("@volar/typescript",{paths:[t]})),o=require(require.resolve("@vue/language-core",{paths:[t]}));return{getLanguagePlugin:b((s,i)=>{const l=i.options.$rootDir,a=i.options.$configRaw,n=new o.CompilerOptionsResolver(s,s.sys.readFile);n.addConfig(a?.vueCompilerOptions??{},l);const c=n.build();return o.createVueLanguagePlugin(s,i.options,c,f=>f)},"getLanguagePlugin"),proxyCreateProgram:r}}catch(t){throw e("vue language tools not found",t),new Error("Failed to load vue language tools. Please manually install vue-tsc.")}},"loadVueLanguageTools"),X=b(()=>{const e=P("rollup-plugin-dts:ts-macro");e("loading ts-macro language tools");try{const t=require.resolve("@ts-macro/tsc"),{proxyCreateProgram:r}=require(require.resolve("@volar/typescript",{paths:[t]})),o=require(require.resolve("@ts-macro/language-plugin",{paths:[t]})),{getOptions:s}=require(require.resolve("@ts-macro/language-plugin/options",{paths:[t]}));return{getLanguagePlugin:b((i,l)=>{const a=l.options.$rootDir;return o.getLanguagePlugins(i,l.options,s(i,a))[0]},"getLanguagePlugin"),proxyCreateProgram:r}}catch(t){throw e("ts-macro language tools not found",t),new Error("Failed to load ts-macro language tools. Please manually install @ts-macro/tsc.")}},"loadTsMacro"),Z=b((e,t)=>{const r=t.vue?Q():void 0,o=t.tsMacro?X():void 0,s=r?.proxyCreateProgram||o?.proxyCreateProgram;return s?s(e,e.createProgram,(i,l)=>{const a=[];return r&&a.push(r.getLanguagePlugin(i,l)),o&&a.push(o.getLanguagePlugin(i,l)),{languagePlugins:a}}):e.createProgram},"createProgramFactory");var _=Object.defineProperty,C=h((e,t)=>_(e,"name",{value:t,configurable:!0}),"m");const p=P("rollup-plugin-dts:tsc-compiler"),ee={checkJs:!1,declaration:!0,declarationMap:!1,emitDeclarationOnly:!0,moduleResolution:u.ModuleResolutionKind.Bundler,noEmit:!1,noEmitOnError:!0,resolveJsonModule:!0,skipLibCheck:!0,target:99},te=C(({baseDirectory:e,entries:t,fsSystem:r,id:o,parsedConfig:s,tsMacro:i,vue:l})=>{const a={...ee,...s.options,$configRaw:s.raw,$rootDir:e},n=[...new Set([o,...t??s.fileNames].map(y=>r.resolvePath(y)))],c=u.createCompilerHost(a,!0),f=Z(u,{tsMacro:i,vue:l})({host:c,options:a,projectReferences:s.projectReferences,rootNames:n}),v=f.getSourceFile(o);if(!v)throw p(`source file not found in program: ${o}`),s.projectReferences?.length?new Error(`[rollup-plugin-dts] Unable to load ${o}; You have "references" in your tsconfig file. Perhaps you want to add \`dts: { build: true }\` in your config?`):r.fileExists(o)?(p(`File ${o} exists on disk.`),new Error(`Unable to load file ${o} from the program. This seems like a bug of rollup-plugin-dts. Please report this issue to https://github.com/sxzz/rollup-plugin-dts/issues`)):(p(`File ${o} does not exist on disk.`),new Error(`Source file not found: ${o}`));return{file:v,program:f}},"createTsProgramFromParsedConfig"),re=C(({context:e=F,cwd:t,entries:r,id:o,tsconfig:s,tsconfigRaw:i,tsMacro:l,vue:a})=>{const n=x(e.files),c=s?T(s):t,f=u.parseJsonConfigFileContent(i,n,c);return p(`Creating program for root project: ${c}`),te({baseDirectory:c,entries:r,fsSystem:n,id:o,parsedConfig:f,tsMacro:l,vue:a})},"createTsProgram"),j=new WeakMap,oe=C(e=>{let t=j.get(e);return t||(t=new Set(e.getRootFileNames()),j.set(e,t)),t},"getProgramRoots"),se=C(e=>{const{context:t=F,entries:r,id:o}=e,s=t.programs.find(l=>{const a=oe(l);return r?r.every(n=>a.has(n)):a.has(o)});if(s){const l=s.getSourceFile(o);if(l)return{file:l,program:s}}p(`create program for module: ${o}`);const i=re(e);return p(`created program for module: ${o}`),t.programs.push(i.program),i},"createOrGetTsModule"),ie=C(e=>{p(`running tscEmitCompiler ${e.id}`);const t=se(e),{file:r,program:o}=t;p(`got source file: ${r.fileName}`);let s,i;const{diagnostics:l,emitSkipped:a}=o.emit(r,(n,c)=>{n.endsWith(".map")?(p(`emit dts sourcemap: ${n}`),i=JSON.parse(c),D(i,n,e.id)):(p(`emit dts: ${n}`),s=c)},void 0,!0,O,!0);return a&&l.length>0?{error:u.formatDiagnostics(l,M)}:(!s&&r.isDeclarationFile&&(p("nothing was emitted. fallback to sourceFile text."),s=r.getFullText()),{code:s,map:i})},"tscEmitCompiler");var ae=Object.defineProperty,ne=h((e,t)=>ae(e,"name",{value:t,configurable:!0}),"r");const q=P("rollup-plugin-dts:tsc");q(`loaded typescript: ${u.version}`);const me=ne(e=>(q(`running tscEmit ${e.id}`),e.build?k(e):ie(e)),"tscEmit");export{me as tscEmit};
1
+ var U=Object.defineProperty;var h=(e,t)=>U(e,"name",{value:t,configurable:!0});import{createDebug as y}from"obug";import c from"typescript";import{g as x}from"../packem_shared/generate-B50-mrCC.js";import{posix as F}from"node:path";import{pathToFileURL as E}from"node:url";import{dirname as B}from"@visulima/path";var J=Object.defineProperty,$=h((e,t)=>J(e,"name",{value:t,configurable:!0}),"c$1");const W=y("rollup-plugin-dts:tsc-system"),j=$(e=>{const t=e.replaceAll("\\","/"),o=[];let s=t.slice(0,Math.max(0,t.lastIndexOf("/")));for(;s.includes("/");)o.push(s),s=s.slice(0,s.lastIndexOf("/"));return s&&o.push(s),o},"ancestorDirectories"),M=$((e,t)=>{const o=new Set;for(const r of e.keys())for(const i of j(r))o.add(i);const s=$(r=>{for(const i of j(r))o.add(i)},"trackDirectories");return{...c.sys,deleteFile(r,...i){e.delete(r),t&&c.sys.deleteFile?.(r,...i)},directoryExists(r){return o.has(r.replaceAll("\\","/"))?!0:c.sys.directoryExists(r)},fileExists(r){return e.has(r)?!0:c.sys.fileExists(r)},readFile(r,...i){return e.has(r)?e.get(r):c.sys.readFile(r,...i)},resolvePath(r){return e.has(r)?r:c.sys.resolvePath(r)},write(r){W(r)},writeFile(r,i,...l){e.set(r,i),s(r),t&&c.sys.writeFile(r,i,...l)}}},"createSystem"),O=$(e=>M(e,!0),"createFsSystem"),A=$(e=>M(e,!1),"createMemorySystem");var H=Object.defineProperty,b=h((e,t)=>H(e,"name",{value:t,configurable:!0}),"o$1");const I=b(e=>{const t=b(o=>c.isPropertySignature(o)&&c.isPrivateIdentifier(o.name)?e.factory.updatePropertySignature(o,o.modifiers,e.factory.createStringLiteral(o.name.text),o.questionToken,o.type):c.visitEachChild(o,t,void 0),"visitor");return o=>c.visitNode(o,t,c.isSourceFile)},"stripPrivateFields"),R={getCanonicalFileName:c.sys.useCaseSensitiveFileNames?e=>e:e=>e.toLowerCase(),getCurrentDirectory:b(()=>c.sys.getCurrentDirectory(),"getCurrentDirectory"),getNewLine:b(()=>c.sys.newLine,"getNewLine")},k={afterDeclarations:[I]},L=b((e,t,o)=>{if(!e||e.sourceRoot)return;const s=F.dirname(E(t).pathname),r=F.dirname(E(o).pathname);s!==r&&(e.sourceRoot=F.relative(r,s))},"setSourceMapRoot");var G=Object.defineProperty,m=h((e,t)=>G(e,"name",{value:t,configurable:!0}),"d");const g=y("rollup-plugin-dts:tsc-build"),V=m((e,t,o,s,r)=>{let i=e.projects.get(o);return i?(g(`skip building projects for ${o}`),i):(i=K(t,o,s,r),e.projects.set(o,i),i)},"getOrBuildProjects"),K=m((e,t,o,s)=>{g(`start building projects for ${t}`);const r=Y(t,e,o,s);g("collected %d projects: %j",r.length,r.map(a=>a.tsconfigPath));const i=c.createSolutionBuilderHost(e,Q(s)),l=c.createSolutionBuilder(i,[t],{force:o,verbose:!0}).build(void 0,void 0,void 0,a=>(g(`transforming project ${a}`),k));g(`built solution for ${t} with exit status ${l}`);const n=new Map;for(const a of r)for(const u of a.parsedConfig.fileNames)n.set(e.resolvePath(u),a);return n},"buildProjects"),Y=m((e,t,o,s)=>{const r=new Set,i=[],l=[t.resolvePath(e)];for(;;){const n=l.pop();if(!n)break;if(r.has(n))continue;r.add(n);const a=z(n,t);if(a){a.options=q(a.options,{force:o,sourcemap:s,tsconfigPath:n}),i.push({parsedConfig:a,tsconfigPath:n});for(const u of a.projectReferences??[])l.push(c.resolveProjectReferencePath(u))}}return i},"collectProjectGraph"),z=m((e,t)=>{const o=[],s=c.getParsedCommandLineOfConfigFile(e,void 0,{...t,onUnRecoverableConfigFileDiagnostic:m(r=>{o.push(r)},"onUnRecoverableConfigFileDiagnostic")});if(o.length>0)throw new Error(`[rollup-plugin-dts] Unable to read ${e}: ${c.formatDiagnostics(o,R)}`);return s},"parseTsconfig"),q=m((e,t)=>{const o=e.noEmit??!1,s=e.declaration??!!e.composite,r=e.declarationMap??!1,i=t?.tsconfigPath&&!t.force;return o&&(e={...e,noEmit:!1},i&&console.warn(`[rollup-plugin-dts] ${t.tsconfigPath} has "noEmit" set to true. Please set it to false to generate declaration files.`)),s||(e={...e,declaration:!0},i&&console.warn(`[rollup-plugin-dts] ${t.tsconfigPath} has "declaration" set to false. Please set it to true to generate declaration files.`)),!r&&t?.sourcemap&&(e={...e,declarationMap:!0},i&&console.warn(`[rollup-plugin-dts] ${t.tsconfigPath} has "declarationMap" set to false. Please set it to true if you want to generate source maps for declaration files.`)),e},"patchCompilerOptions"),Q=m(e=>(t,o,...s)=>c.createEmitAndSemanticDiagnosticsBuilderProgram(t,q(o??{},{force:!0,sourcemap:e,tsconfigPath:""}),...s),"createProgramFactory"),N=m(e=>{const{context:t=x,id:o,incremental:s,sourcemap:r,tsconfig:i}=e;if(g(`running tscEmitBuild id: ${o}, tsconfig: ${i}, incremental: ${s}`),!i)return{error:"[rollup-plugin-dts] build mode requires a tsconfig path"};const l=(s?O:A)(t.files),n=l.resolvePath(o);n!==o&&g(`resolved id from ${o} to ${n}`);const a=V(t,l,i,!s,r).get(n);if(!a)return g(`unable to locate a project containing ${n}`),{error:`Unable to locate ${o} from the given tsconfig file ${i}`};g(`loaded project ${a.tsconfigPath} for ${o}`);const u=!l.useCaseSensitiveFileNames,f=c.getOutputFileNames(a.parsedConfig,n,u);let v,P;for(const d of f){if(d.endsWith(".d.ts")){if(!l.fileExists(d)){console.warn(`[rollup-plugin-dts] Unable to read file ${d}`);continue}v=l.readFile(d);continue}if(d.endsWith(".d.ts.map")){if(!l.fileExists(d))continue;const S=l.readFile(d);if(!S){console.warn(`[rollup-plugin-dts] Unexpected sourcemap ${d}`);continue}P=JSON.parse(S),L(P,d,n)}}return v?{code:v,map:P}:s?(g("incremental build failed"),N({...e,incremental:!1})):(g(`unable to build .d.ts file for ${o}`),a.parsedConfig.options.declaration!==!0?{error:`Unable to build .d.ts file for ${o}; Make sure the "declaration" option is set to true in ${a.tsconfigPath}`}:{error:`Unable to build .d.ts file for ${o}; This seems like a bug of rollup-plugin-dts. Please report this issue to https://github.com/visulima/packem/issues`})},"tscEmitBuild");var X=Object.defineProperty,w=h((e,t)=>X(e,"name",{value:t,configurable:!0}),"g");const Z=w(()=>{const e=y("rollup-plugin-dts:vue");e("loading vue language tools");try{const t=require.resolve("vue-tsc"),{proxyCreateProgram:o}=require(require.resolve("@volar/typescript",{paths:[t]})),s=require(require.resolve("@vue/language-core",{paths:[t]}));return{getLanguagePlugin:w((r,i)=>{const l=i.options.$rootDir,n=i.options.$configRaw,a=new s.CompilerOptionsResolver(r,r.sys.readFile);a.addConfig(n?.vueCompilerOptions??{},l);const u=a.build();return s.createVueLanguagePlugin(r,i.options,u,f=>f)},"getLanguagePlugin"),proxyCreateProgram:o}}catch(t){throw e("vue language tools not found",t),new Error("Failed to load vue language tools. Please manually install vue-tsc.")}},"loadVueLanguageTools"),_=w(()=>{const e=y("rollup-plugin-dts:ts-macro");e("loading ts-macro language tools");try{const t=require.resolve("@ts-macro/tsc"),{proxyCreateProgram:o}=require(require.resolve("@volar/typescript",{paths:[t]})),s=require(require.resolve("@ts-macro/language-plugin",{paths:[t]})),{getOptions:r}=require(require.resolve("@ts-macro/language-plugin/options",{paths:[t]}));return{getLanguagePlugin:w((i,l)=>{const n=l.options.$rootDir;return s.getLanguagePlugins(i,l.options,r(i,n))[0]},"getLanguagePlugin"),proxyCreateProgram:o}}catch(t){throw e("ts-macro language tools not found",t),new Error("Failed to load ts-macro language tools. Please manually install @ts-macro/tsc.")}},"loadTsMacro"),ee=w((e,t)=>{const o=t.vue?Z():void 0,s=t.tsMacro?_():void 0,r=o?.proxyCreateProgram||s?.proxyCreateProgram;return r?r(e,e.createProgram,(i,l)=>{const n=[];return o&&n.push(o.getLanguagePlugin(i,l)),s&&n.push(s.getLanguagePlugin(i,l)),{languagePlugins:n}}):e.createProgram},"createProgramFactory");var te=Object.defineProperty,C=h((e,t)=>te(e,"name",{value:t,configurable:!0}),"u");const p=y("rollup-plugin-dts:tsc-compiler"),re={checkJs:!1,declaration:!0,declarationMap:!1,emitDeclarationOnly:!0,moduleResolution:c.ModuleResolutionKind.Bundler,noEmit:!1,noEmitOnError:!0,resolveJsonModule:!0,skipLibCheck:!0,target:99},oe=C(({baseDirectory:e,entries:t,fsSystem:o,id:s,parsedConfig:r,tsMacro:i,vue:l})=>{const n={...re,...r.options,$configRaw:r.raw,$rootDir:e,declaration:!0,emitDeclarationOnly:!0},a=[...new Set([s,...t??r.fileNames].map(P=>o.resolvePath(P)))],u=c.createCompilerHost(n,!0),f=ee(c,{tsMacro:i,vue:l})({host:u,options:n,projectReferences:r.projectReferences,rootNames:a}),v=f.getSourceFile(s);if(!v)throw p(`source file not found in program: ${s}`),r.projectReferences?.length?new Error(`[rollup-plugin-dts] Unable to load ${s}; You have "references" in your tsconfig file. Perhaps you want to add \`dts: { build: true }\` in your config?`):o.fileExists(s)?(p(`File ${s} exists on disk.`),new Error(`Unable to load file ${s} from the program. This seems like a bug of rollup-plugin-dts. Please report this issue to https://github.com/visulima/packem/issues`)):(p(`File ${s} does not exist on disk.`),new Error(`Source file not found: ${s}`));return{file:v,program:f}},"createTsProgramFromParsedConfig"),se=C(({context:e=x,cwd:t,entries:o,id:s,tsconfig:r,tsconfigRaw:i,tsMacro:l,vue:n})=>{const a=O(e.files),u=r?B(r):t,f=c.parseJsonConfigFileContent(i,a,u);return p(`Creating program for root project: ${u}`),oe({baseDirectory:u,entries:o,fsSystem:a,id:s,parsedConfig:f,tsMacro:l,vue:n})},"createTsProgram"),D=new WeakMap,ie=C(e=>{let t=D.get(e);return t||(t=new Set(e.getRootFileNames()),D.set(e,t)),t},"getProgramRoots"),ae=C(e=>{const{context:t=x,entries:o,id:s}=e,r=t.programs.find(l=>{const n=ie(l);return o?o.every(a=>n.has(a)):n.has(s)});if(r){const l=r.getSourceFile(s);if(l)return{file:l,program:r}}p(`create program for module: ${s}`);const i=se(e);return p(`created program for module: ${s}`),t.programs.push(i.program),i},"createOrGetTsModule"),ne=C(e=>{p(`running tscEmitCompiler ${e.id}`);const t=ae(e),{file:o,program:s}=t;p(`got source file: ${o.fileName}`);let r,i;const{diagnostics:l,emitSkipped:n}=s.emit(o,(a,u)=>{a.endsWith(".map")?(p(`emit dts sourcemap: ${a}`),i=JSON.parse(u),L(i,a,e.id)):(p(`emit dts: ${a}`),r=u)},void 0,!0,k,!0);if(n){const a=l.filter(u=>u.category===c.DiagnosticCategory.Error);if(a.length>0)return{error:c.formatDiagnostics(a,R)}}return!r&&o.isDeclarationFile&&(p("nothing was emitted. fallback to sourceFile text."),r=o.getFullText()),{code:r,map:i}},"tscEmitCompiler");var le=Object.defineProperty,ce=h((e,t)=>le(e,"name",{value:t,configurable:!0}),"r");const T=y("rollup-plugin-dts:tsc");T(`loaded typescript: ${c.version}`);const ve=ce(e=>(T(`running tscEmit ${e.id}`),e.build?N(e):ne(e)),"tscEmit");export{ve as tscEmit};
@@ -1 +1 @@
1
- var v=Object.defineProperty;var n=(e,o)=>v(e,"name",{value:o,configurable:!0});import g from"node:path";import{createDebug as m}from"obug";import s from"typescript";var c=Object.defineProperty,a=n((e,o)=>c(e,"name",{value:o,configurable:!0}),"r");const C=m("rollup-plugin-dts:tsc-resolver"),i=new WeakMap,b=a((e,o)=>{if(typeof e!="object"||e===null)return s.parseJsonConfigFileContent(e,s.sys,o);let r=i.get(e);r||(r=new Map,i.set(e,r));let t=r.get(o);return t||(t=s.parseJsonConfigFileContent(e,s.sys,o),r.set(o,t)),t},"getParsedConfig"),w=a((e,o,r,t,p,d)=>{const u=t?g.dirname(t):r,f=b(p,u),l=s.bundlerModuleNameResolver(e,o,f.options,s.sys,void 0,d);return C('tsc resolving id "%s" from "%s" -> %O',e,o,l.resolvedModule),l.resolvedModule?.resolvedFileName},"tscResolve");export{w as default};
1
+ var v=Object.defineProperty;var n=(e,o)=>v(e,"name",{value:o,configurable:!0});import g from"node:path";import{createDebug as m}from"obug";import s from"typescript";var c=Object.defineProperty,a=n((e,o)=>c(e,"name",{value:o,configurable:!0}),"r");const C=m("rollup-plugin-dts:tsc-resolver"),i=new WeakMap,b=a((e,o)=>{if(typeof e!="object"||e===null)return s.parseJsonConfigFileContent(e,s.sys,o);let r=i.get(e);r||(r=new Map,i.set(e,r));let t=r.get(o);return t||(t=s.parseJsonConfigFileContent(e,s.sys,o),r.set(o,t)),t},"getParsedConfig"),w=a((e,o,r,t,d,p)=>{const u=t?g.dirname(t):r,f=b(d,u),l=s.bundlerModuleNameResolver(e,o,f.options,s.sys,void 0,p);return C('tsc resolving id "%s" from "%s" -> %O',e,o,l.resolvedModule),l.resolvedModule?.resolvedFileName},"tscResolve");export{w as default};
@@ -0,0 +1,3 @@
1
+ var Te=Object.defineProperty;var A=(e,t)=>Te(e,"name",{value:t,configurable:!0});import F from"node:path";import{generate as se}from"@babel/generator";import{isIdentifierName as Ie}from"@babel/helper-validator-identifier";import{parse as le}from"@babel/parser";import u from"@babel/types";import{isTypeOf as q,isDeclarationType as Ne,walkAST as Z,walkASTAsync as we,isIdentifierOf as oe,resolveString as G,extractIdentifiers as Oe}from"ast-kit";import{RE_DTS as J,resolveTemplateFunction as Ce,filenameJsToDts as pe,replaceTemplateName as ce,filenameDtsTo as ye,RE_DTS_MAP as Me,RE_NODE_MODULES as Ae,filenameToDts as _e}from"../filename.js";var ke=Object.defineProperty,f=A((e,t)=>ke(e,"name",{value:t,configurable:!0}),"o");const te="__rollup_dts_resolve__:",ct=f(({cjsDefault:e,sideEffects:t,sourcemap:i})=>{let r=0;const y=new Map,g=new Map,E=new Map,I=new Set;let v;return{generateBundle(m,a){const S=new Map;for(const s of Object.values(a))if(s.type==="chunk")for(const l of s.moduleIds)S.set(l,s.fileName);const h=new RegExp(`"${te}(.+?)"`,"g");for(const s of Object.values(a))s.type!=="chunk"||!J.test(s.fileName)||s.code.includes(te)&&(s.code=s.code.replaceAll(h,(l,_)=>{const k=S.get(_);if(!k)return l;let D=F.posix.relative(F.posix.dirname(s.fileName),k);return D.startsWith(".")||(D=`./${D}`),D=ye(D,"js"),JSON.stringify(D)}));for(const s of Object.values(a))if(Me.test(s.fileName))if(i){if(s.type==="chunk"||typeof s.source!="string")continue;const l=JSON.parse(s.source);l.sourcesContent=void 0,s.source=JSON.stringify(l)}else delete a[s.fileName]},name:"rollup-plugin-dts:fake-js",outputOptions(m){const{chunkFileNames:a,entryFileNames:S}=m;return(m.format==="cjs"||m.format==="commonjs")&&(m={...m,format:"es"}),{...m,chunkFileNames(h){const s=Ce(h.isEntry?S||"[name].js":a||"[name]-[hash].js",h);if(h.name.endsWith(".d")){const l=pe(ce(s,h.name.slice(0,-2)));if(J.test(l))return l;const _=pe(ce(s,h.name));if(J.test(_))return _}return s},sourcemap:m.sourcemap||i}},renderChunk:$,renderStart(){v=void 0},async transform(m,a){if(J.test(a))return V.call(this,m,a)}};async function V(m,a){const S=Object.create(null);let h;try{h=le(m,{createParenthesizedExpressions:!0,errorRecovery:!0,plugins:[["typescript",{dts:!0}],"decoratorAutoAccessors"],sourceType:"module"})}catch(x){throw new Error(`Failed to parse ${a}. This may be caused by a syntax error in the declaration file or a bug in the plugin. Please report this issue to https://github.com/visulima/packem
2
+ ${x}`,{cause:x})}const{comments:s,program:l}=h;if(!I.has(a)&&l.body.some(x=>Re(x))&&(I.add(a),this.warn(Ae.test(a)?`${a} uses CommonJS dts syntax. CommonJS dts modules cannot be reliably bundled by @visulima/rollup-plugin-dts. Please mark this module as external in your Rollup config.`:`${a} uses CommonJS dts syntax. @visulima/rollup-plugin-dts does not support reliably bundling CommonJS dts input.`)),E.set(a,await Le(this,l.body,a)),s){const x=xe(s);g.set(a,x)}const _=[],k=new Map,D=new Map,j=new Set,K=new Map;for(const[x,n]of l.body.entries())n.type==="TSImportEqualsDeclaration"&&n.moduleReference.type!=="TSExternalModuleReference"?l.body[x]=u.tsTypeAliasDeclaration(n.id,void 0,u.tsTypeReference(n.moduleReference)):n.type==="TSExportAssignment"&&n.expression.type!=="Identifier"&&(l.body[x]=u.exportDefaultDeclaration(n.expression));for(const[x,n]of l.body.entries()){const o=f(d=>l.body[x]=d,"setStmt");if(et(n,o))continue;if(n.type==="TSNamespaceExportDeclaration"){j.add(x);continue}const M=n.type==="TSModuleDeclaration"&&n.kind!=="namespace";let w;if(M&&n.id.type==="StringLiteral"){const d=await this.resolve(n.id.value,a);d&&!d.external?w=J.test(d.id)?d.id:_e(d.id):n.id.value[0]==="."&&this.warn(`\`declare module ${JSON.stringify(n.id.value)}\` will be kept as-is in the output. Relative module declaration may cause unexpected issues. Found in ${a}.`)}if(M&&a.endsWith(".vue.d.ts")&&m.slice(n.start,n.end).includes("__VLS_"))continue;const P=n.type==="ExportDefaultDeclaration",R=q(n,["ExportNamedDeclaration","ExportDefaultDeclaration"])&&n.declaration,p=R?n.declaration:n,ee=R?d=>n.declaration=d:o;if(p.type!=="TSDeclareFunction"&&!Ne(p))continue;q(p,["TSEnumDeclaration","ClassDeclaration","FunctionDeclaration","TSDeclareFunction","TSModuleDeclaration","VariableDeclaration"])&&(p.declare=!0);const C=[];if(p.type==="VariableDeclaration")C.push(...p.declarations.map(d=>d.id));else if("id"in p&&p.id){let d=p.id;d.type==="TSQualifiedName"&&(d=Y(d)),d=M&&d.type!=="Identifier"?u.identifier(`_${X(S,"")}`):d,C.push(d)}else{const d=u.identifier("export_default");C.push(d),p.id=d}const W=Se(p),U=new Set,L=await be(this,p,a,k,U,S,K),B=[...U].filter(d=>C.every(O=>d!==O));if(p!==n&&(p.leadingComments=n.leadingComments),C.length===1&&D.has(C[0].name)){const d=D.get(C[0].name),O=ie(d);O.overloads||(O.overloads=[],O.primaryDepsCount=O.deps.length,O.primaryParamsCount=O.params.length,O.primaryChildrenCount=O.children.length),O.overloads.push({children:B,childrenOffset:O.children.length,decl:p,deps:L,depsOffset:O.deps.length,params:W,paramsOffset:O.params.length}),O.deps.push(...L),O.params.push(...W),O.children.push(...B),j.add(x);continue}const c=ge({bindings:C,children:B,decl:p,deps:L,params:W,resolvedModuleId:w});C.length===1&&D.set(C[0].name,c);const T=u.numericLiteral(c),b=u.arrowFunctionExpression(W.map(({name:d})=>u.identifier(d)),u.arrayExpression(L)),N=u.arrayExpression(B.map(d=>({end:d.end,loc:d.loc,start:d.start,type:"StringLiteral",value:""}))),H=M&&u.callExpression(u.identifier("sideEffect"),[C[0]]),De=Ue(H?[T,b,N,H]:[T,b,N]),ae={declarations:[{id:{...C[0],typeAnnotation:null},init:De,type:"VariableDeclarator"},...C.slice(1).map(d=>({id:{...d,typeAnnotation:null},type:"VariableDeclarator"}))],kind:"var",type:"VariableDeclaration"};P?(_.push(u.exportNamedDeclaration(null,[u.exportSpecifier(C[0],u.identifier("default"))])),o(ae)):ee(ae)}return t&&_.push(u.expressionStatement(u.callExpression(u.identifier("sideEffect"),[]))),l.body=[...Array.from(k.values(),({stmt:x})=>x),...l.body.filter((x,n)=>!j.has(n)),..._],se(h,{comments:!1,sourceFileName:a,sourceMaps:i})}function $(m,a,S){if(!J.test(a.fileName))return;v??=Je(E);const h=We(a,E,v);let s;try{s=le(m,{sourceType:"module"})}catch(n){throw new Error(`Failed to parse generated code for chunk ${a.fileName}. This may be caused by a bug in the plugin. Please report this issue to https://github.com/visulima/packem
3
+ ${n}`,{cause:n})}const{program:l}=s;if(l.body=Ze(l.body),l.body=Ye(l.body),l.body=l.body.flatMap(n=>{if(Xe(n))return[];if(n.type==="ExpressionStatement")return[];const o=He(n,h,e);if(o===!1)return[];if(o)return[o];if(n.type!=="VariableDeclaration")return[n];if(!Qe(n))return[];const[M,w,P]=n.declarations[0].init.elements,R=M.value,p=ie(R);Z(p.decl,{enter(c){c.type!=="CommentBlock"&&(c.leadingComments?.length||delete c.loc)}});for(const[c,T]of n.declarations.entries()){const b={...T.id,typeAnnotation:p.bindings[c].typeAnnotation};z(p.bindings[c],b)}const ee=p.primaryChildrenCount??p.children.length,C=p.primaryParamsCount??p.params.length,W=p.primaryDepsCount??p.deps.length;for(let c=0;c<ee;c++){const T=P.elements[c];Object.assign(p.children[c],{loc:T.loc})}const U=w.params;for(let c=0;c<C;c++){const T=U[c].name;for(const b of p.params[c].typeParams)b.name=T}const L=w.body.elements;for(let c=0;c<W;c++){const T=p.deps[c];let b=L[c];b&&b.type==="UnaryExpression"&&b.operator==="void"?b={...u.identifier("undefined"),end:b.end,loc:b.loc,start:b.start}:ne(b)&&(b.name="__Infer"),T.replace?T.replace(b):Object.assign(T,b)}p.decl.type==="TSModuleDeclaration"&&p.resolvedModuleId&&(p.decl.id.value=te+p.resolvedModuleId);const B=[];if(p.overloads)for(const c of p.overloads){Z(c.decl,{enter(T){T.type!=="CommentBlock"&&delete T.loc}}),"id"in c.decl&&c.decl.id&&z(c.decl.id,{...p.bindings[0]});for(const[T,b]of c.children.entries()){const N=P.elements[c.childrenOffset+T];N&&Object.assign(b,{loc:N.loc})}for(const[T,b]of c.params.entries()){const N=U[c.paramsOffset+T];if(N)for(const H of b.typeParams)H.name=N.name}for(const[T,b]of c.deps.entries()){let N=L[c.depsOffset+T];N&&(N.type==="UnaryExpression"&&N.operator==="void"?N={...u.identifier("undefined"),end:N.end,loc:N.loc,start:N.start}:ne(N)&&(N.name="__Infer"),b.replace?b.replace(N):Object.assign(b,N))}B.push(c.decl)}return[tt(n,p.decl),...B]}).filter(n=>!!n),l.body.length===0)return"export { };";const _=l.body.some(n=>n.type==="ExportNamedDeclaration"||n.type==="ExportDefaultDeclaration"||n.type==="ExportAllDeclaration"),k=l.body.some(n=>n.type==="TSModuleDeclaration"&&n.id.type==="StringLiteral");!_&&k&&l.body.push(u.exportNamedDeclaration(null,[],null));const D=new Set,j=new Set,K=S.dir??(S.file?F.dirname(S.file):process.cwd()),x=F.resolve(K,F.dirname(a.fileName));for(const n of a.moduleIds){const o=g.get(n);if(o){const M=F.dirname(n);o.forEach(w=>{const P=Pe(w,M,x),R=P.type+P.value;j.has(R)||(j.add(R),D.add(P))}),g.delete(n)}}return D.size>0&&(l.body[0].leadingComments||=[],l.body[0].leadingComments.unshift(...D)),se(s,{comments:!0,sourceFileName:a.fileName,sourceMaps:i})}function X(m,a){return a in m?m[a]++:m[a]=0}function ge(m){const a=r++;return y.set(a,m),a}function ie(m){return y.get(m)}function Se(m){const a=[];Z(m,{leave(h){"typeParameters"in h&&h.typeParameters?.type==="TSTypeParameterDeclaration"&&a.push(...h.typeParameters.params)}});const S=new Map;for(const h of a){const{name:s}=h,l=S.get(s);l?l.push(h):S.set(s,[h])}return Array.from(S.entries(),([h,s])=>({name:h,typeParams:s}))}function Ee(m){const a=[];return Z(m,{enter(S){S.type==="TSInferType"&&S.typeParameter&&a.push(S.typeParameter.name)}}),a}async function be(m,a,S,h,s,l,_){const k=new Set,D=new Set,j=[];let K=new Set;function x(o){return o.type==="Identifier"&&K.has(o.name)}return A(x,"w"),f(x,"isInferred"),await we(a,{enter(o){if(o.type==="TSConditionalType"){const M=Ee(o.extendsType);j.push(M)}return Promise.resolve()},async leave(o,M){if(o.type==="TSConditionalType")j.pop();else if(M?.type==="TSConditionalType"){const w=M.trueType===o;K=new Set((w?j:j.slice(0,-1)).flat())}else K=new Set;if(o.type==="ExportNamedDeclaration")for(const w of o.specifiers)w.type==="ExportSpecifier"&&n(w.local);else if(o.type==="TSInterfaceDeclaration"&&o.extends)for(const w of o.extends||[])n(Q(w.expression));else if(o.type==="ClassDeclaration"){if(o.superClass&&n(o.superClass),o.implements)for(const w of o.implements)w.type!=="ClassImplements"&&n(Q(w.expression))}else if(q(o,["ObjectMethod","ObjectProperty","ClassProperty","TSPropertySignature","TSDeclareMethod","TSMethodSignature"]))o.computed&&ue(o.key)&&n(o.key),"value"in o&&ue(o.value)&&n(o.value);else switch(o.type){case"TSImportType":{D.add(o);const w=o.argument,P=o.qualifier,R=await ve(m,S,o,P,w,h,l,_);R&&n(R);break}case"TSTypeQuery":{if(D.has(o.exprName))return;if(o.exprName.type==="TSImportType")break;n(Q(o.exprName));break}case"TSTypeReference":{n(Q(o.typeName));break}}M&&!k.has(o)&&me(o,M)&&s.add(o)}}),[...k];function n(o){he(o)||x(o)||k.add(o)}A(n,"y")}async function ve(m,a,S,h,s,l,_,k){let D=k.get(s.value);if(D===void 0){const o=await m.resolve(s.value,a);D=!o||!!o.external,k.set(s.value,D)}if(D)return;const j=s.value.replaceAll(/\W/g,"_"),K=`_$${Ie(s.value)?s.value:`${j}${X(_,j)}`}`;let x=u.identifier(K);if(l.has(s.value)?x=l.get(s.value).local:l.set(s.value,{local:x,stmt:u.importDeclaration([u.importNamespaceSpecifier(x)],s)}),h){const o=Y(h);z(o,u.tsQualifiedName(x,{...o})),x=h}let n=S;return S.typeParameters?(z(S,u.tsTypeReference(x,S.typeParameters)),n=x):z(S,x),{...Q(x),replace(o){z(n,o)}}}},"createFakeJsPlugin");function me(e,t){return!!(e.type==="Identifier"||q(t,["TSPropertySignature","TSMethodSignature"])&&t.key===e)}A(me,"we");f(me,"isChildSymbol");const je=/\/\s*<reference\s+(?:path|types)=/,xe=f((e,t=!1)=>e.filter(i=>je.test(i.value)!==t),"collectReferenceDirectives"),de=/(\/\s*<reference\s+path=)(["'])(.+?)\2/,Pe=f((e,t,i)=>{const r=de.exec(e.value);if(!r)return e;const[,y,g,E]=r;if(F.isAbsolute(E))return e;const I=F.resolve(t,E);let v=F.relative(i,I).replaceAll("\\","/");return v.startsWith(".")||(v=`./${v}`),v===E?e:{...e,value:e.value.replace(de,`${y}${g}${v}${g}`)}},"rebaseReferencePath"),Re=f(e=>e.type==="TSExportAssignment"||e.type==="TSImportEqualsDeclaration"&&e.moduleReference.type==="TSExternalModuleReference","isCjsDtsInputSyntax"),$e=f((e,t)=>{if(e.type==="ImportDeclaration")for(const i of e.specifiers)(e.importKind==="type"||"importKind"in i&&i.importKind==="type")&&t.add(i.local.name)},"collectTypeOnlyLocals"),Ke=f(e=>{if(e.type==="VariableDeclaration")return e.declarations.flatMap(t=>Oe(t.id).map(i=>i.name));if("id"in e&&e.id){const t=e.id;if(t.type!=="Identifier"&&t.type!=="TSQualifiedName")return[];const i=Y(t);return i.type==="Identifier"?[i.name]:[]}return[]},"collectDeclarationNames"),Fe=f((e,t)=>e.exportKind==="type"||"exportKind"in t&&t.exportKind==="type","isTypeOnlyExport"),fe=f(async(e,t,i)=>{if(!t)return;const r=await e.resolve(t.value,i);if(!(!r||r.external))return r.id},"resolveExportSource"),Ve=f(async(e,t,i,r)=>{if(t.type==="ExportNamedDeclaration"){if(t.declaration){for(const g of Ke(t.declaration))r.exports.set(g,!1);return}const y=await fe(e,t.source,i);for(const g of t.specifiers){const E=Fe(t,g);if(g.type==="ExportSpecifier"){const I=G(g.exported),v=G(g.local);y?r.reExports.push({exported:I,local:v,source:y,typeOnly:E}):r.exports.set(I,E||r.typeOnlyLocals.has(v))}else r.exports.set(G(g.exported),E)}return}if(t.type==="ExportDefaultDeclaration"){r.exports.set("default",!1);return}t.type==="ExportAllDeclaration"&&r.exportAlls.push({rawSource:t.source.value,source:await fe(e,t.source,i),typeOnly:t.exportKind==="type"})},"collectExportInfo"),Le=f(async(e,t,i)=>{const r={exportAlls:[],exports:new Map,reExports:[],typeOnlyLocals:new Set};for(const y of t)$e(y,r.typeOnlyLocals);for(const y of t)await Ve(e,y,i,r);return r},"collectModuleExports"),re=f((e,t,i)=>{const r=e.get(t);return r===!1||r===i?!1:r===void 0||!i?(e.set(t,i),!0):!1},"setExportTypeOnly"),Be=f((e,t)=>{if(e.size!==t.size)return!1;for(const[i,r]of e)if(t.get(i)!==r)return!1;return!0},"exportsEqual"),Je=f(e=>{const t=new Map;for(const[r,y]of e)t.set(r,new Map(y.exports));let i=!0;for(;i;){i=!1;for(const[r,y]of e){const g=new Map(y.exports);for(const E of y.reExports){const I=(E.source?t.get(E.source):void 0)?.get(E.local)??!1;re(g,E.exported,E.typeOnly||I)}for(const E of y.exportAlls){if(!E.source)continue;const I=t.get(E.source);if(I)for(const[v,V]of I)v!=="default"&&re(g,v,E.typeOnly||V)}Be(t.get(r),g)||(t.set(r,g),i=!0)}}return t},"resolveAllModuleExports"),We=f((e,t,i)=>{const r=e.facadeModuleId&&t.has(e.facadeModuleId)?[e.facadeModuleId]:e.moduleIds,y=new Map,g=new Set;for(const I of r){const v=i.get(I);if(v)for(const[$,X]of v)re(y,$,X);const V=t.get(I);if(V)for(const $ of V.exportAlls)!$.typeOnly||$.source||g.add($.rawSource)}const E=new Set;for(const[I,v]of y)v&&E.add(I);return{typeOnlyExportAllSources:g,typeOnlyNames:E}},"collectChunkExportInfo"),ze=f(e=>{if(!(e.declaration||e.specifiers.length===0)){for(const t of e.specifiers)if(t.type!=="ExportSpecifier"||t.exportKind!=="type")return;e.exportKind="type";for(const t of e.specifiers)t.type==="ExportSpecifier"&&(t.exportKind="value")}},"normalizeTypeOnlyExport"),Qe=f(e=>u.isVariableDeclaration(e)&&e.declarations.length>0&&u.isVariableDeclarator(e.declarations[0])&&qe(e.declarations[0].init),"isRuntimeBindingVariableDeclaration"),qe=f(e=>u.isArrayExpression(e)&&Ge(e.elements),"isRuntimeBindingArrayExpression"),Ue=f(e=>u.arrayExpression(e),"runtimeBindingArrayExpression"),Ge=f(e=>{const[t,i,r,y]=e;return t?.type==="NumericLiteral"&&i?.type==="ArrowFunctionExpression"&&r?.type==="ArrayExpression"&&(!y||y.type==="CallExpression")},"isRuntimeBindingArrayElements"),ne=f(e=>oe(e,"infer"),"isInfer"),he=f(e=>oe(e,"this")||e.type==="ThisExpression"||e.type==="MemberExpression"&&he(e.object),"isThisExpression"),Q=f(e=>{if(e.type==="Identifier")return e;const t=Q(e.left);return Object.assign(e,u.memberExpression(t,e.right))},"TSEntityNameToRuntime"),Y=f(e=>e.type==="Identifier"?e:Y(e.left),"getIdFromTSEntityName"),ue=f(e=>q(e,["Identifier","MemberExpression"]),"isReferenceId"),Xe=f(e=>e.type==="ImportDeclaration"&&e.specifiers.length===1&&e.specifiers.every(t=>t.type==="ImportSpecifier"&&t.imported.type==="Identifier"&&["__export","__reExport"].includes(t.imported.name)),"isHelperImport"),He=f((e,t,i)=>{if(e.type==="ExportNamedDeclaration"&&!e.declaration&&!e.source&&e.specifiers.length===0&&!e.attributes?.length)return!1;if(e.type==="ImportDeclaration"&&e.specifiers.length>0)for(const r of e.specifiers)ne(r.local)&&(r.local.name="__Infer");if(q(e,["ImportDeclaration","ExportAllDeclaration","ExportNamedDeclaration"])){if(e.type==="ExportAllDeclaration"&&e.source&&t.typeOnlyExportAllSources.has(e.source.value)&&(e.exportKind="type"),e.type==="ExportNamedDeclaration"&&t.typeOnlyNames.size>0){for(const r of e.specifiers){const y=G(r.exported);t.typeOnlyNames.has(y)&&(r.type==="ExportSpecifier"?r.exportKind="type":e.exportKind="type")}ze(e)}if(e.source?.value&&J.test(e.source.value))return e.source.value=ye(e.source.value,"js"),e;if(i&&e.type==="ExportNamedDeclaration"&&!e.source&&e.specifiers.length===1&&e.specifiers[0].type==="ExportSpecifier"&&G(e.specifiers[0].exported)==="default")return{expression:e.specifiers[0].local,type:"TSExportAssignment"}}},"patchImportExport"),Ze=f(e=>{const t=new Set;for(const[r,y]of e.entries()){const g=i(y);if(!g)continue;const[E,I]=g;I.properties.length!==0&&(e[r]={body:{body:[{declaration:null,source:null,specifiers:I.properties.filter(v=>v.type==="ObjectProperty").map(v=>{const V=v.value.body,$=v.key;return u.exportSpecifier(V,$)}),type:"ExportNamedDeclaration"}],type:"TSModuleBlock"},declare:!0,id:E,kind:"namespace",type:"TSModuleDeclaration"})}return e.filter(r=>!t.has(r));function i(r){if(r.type!=="VariableDeclaration"||r.declarations.length!==1||r.declarations[0].id.type!=="Identifier"||r.declarations[0].init?.type!=="CallExpression"||r.declarations[0].init.callee.type!=="Identifier"||r.declarations[0].init.callee.name!=="__export"||r.declarations[0].init.arguments.length!==1||r.declarations[0].init.arguments[0].type!=="ObjectExpression")return!1;const y=r.declarations[0].id,g=r.declarations[0].init.arguments[0];return[y,g]}},"patchTsNamespace"),Ye=f(e=>{const t=new Map;for(const[i,r]of e.entries())if(r.type==="ImportDeclaration"&&r.specifiers.length===1&&r.specifiers[0].type==="ImportSpecifier"&&r.specifiers[0].local.type==="Identifier"&&r.specifiers[0].local.name.endsWith("_exports"))t.set(r.specifiers[0].local.name,r.specifiers[0].local.name);else if(r.type==="ExpressionStatement"&&r.expression.type==="CallExpression"&&oe(r.expression.callee,"__reExport")){const y=r.expression.arguments;t.set(y[0].name,y[1].name)}else r.type==="VariableDeclaration"&&r.declarations.length===1&&r.declarations[0].init?.type==="MemberExpression"&&r.declarations[0].init.object.type==="Identifier"&&t.has(r.declarations[0].init.object.name)?e[i]={id:{name:r.declarations[0].id.name,type:"Identifier"},type:"TSTypeAliasDeclaration",typeAnnotation:{type:"TSTypeReference",typeName:{left:{name:t.get(r.declarations[0].init.object.name),type:"Identifier"},right:{name:r.declarations[0].init.property.name,type:"Identifier"},type:"TSQualifiedName"}}}:r.type==="ExportNamedDeclaration"&&r.specifiers.length===1&&r.specifiers[0].type==="ExportSpecifier"&&r.specifiers[0].local.type==="Identifier"&&t.has(r.specifiers[0].local.name)&&(r.specifiers[0].local.name=t.get(r.specifiers[0].local.name));return e},"patchReExport"),et=f((e,t)=>{if(e.type==="ImportDeclaration"||e.type==="ExportNamedDeclaration"&&!e.declaration){for(const i of e.specifiers)i.type==="ImportSpecifier"?i.importKind="value":i.type==="ExportSpecifier"&&(i.exportKind="value");return e.type==="ImportDeclaration"?e.importKind="value":e.type==="ExportNamedDeclaration"&&(e.exportKind="value"),!0}return e.type==="ExportAllDeclaration"?(e.exportKind="value",!0):e.type==="TSImportEqualsDeclaration"?e.moduleReference.type==="TSExternalModuleReference"?(t({source:e.moduleReference.expression,specifiers:[{local:e.id,type:"ImportDefaultSpecifier"}],type:"ImportDeclaration"}),!0):!1:e.type==="TSExportAssignment"&&e.expression.type==="Identifier"?(t({specifiers:[{exported:{name:"default",type:"Identifier"},local:e.expression,type:"ExportSpecifier"}],type:"ExportNamedDeclaration"}),!0):e.type==="ExportDefaultDeclaration"&&e.declaration.type==="Identifier"?(t({specifiers:[{exported:u.identifier("default"),local:e.declaration,type:"ExportSpecifier"}],type:"ExportNamedDeclaration"}),!0):!1},"rewriteImportExport"),z=f((e,t)=>{const i=e;for(const r of Object.keys(e))delete i[r];return Object.assign(e,t),e},"overwriteNode"),tt=f((e,t)=>{t.leadingComments||=[];const i=e.leadingComments?.filter(r=>r.value.startsWith("#"));return i&&t.leadingComments.unshift(...i),t.leadingComments=xe(t.leadingComments,!0),t},"inheritNodeComments");export{ct as default};
@@ -1 +1 @@
1
- import"node:child_process";import"node:fs";import"node:fs/promises";import"node:path";import"@babel/parser";import"@rollup/pluginutils";import"obug";import"oxc-transform";import"../filename.js";import{c as g}from"./generate-BTUIV9zv.js";export{g as createGeneratePlugin};
1
+ import"node:child_process";import"node:fs";import"node:fs/promises";import"node:path";import"@babel/parser";import"@rollup/pluginutils";import"obug";import"oxc-transform";import"../filename.js";import{c as g}from"./generate-B50-mrCC.js";export{g as createGeneratePlugin};
@@ -830,4 +830,5 @@ declare const filenameToDts: (id: string) => string;
830
830
  declare const filenameDtsTo: (id: string, extension: "js" | "ts") => string;
831
831
  declare const resolveTemplateFunction: (function_: ((chunk: PreRenderedChunk) => string) | string, chunk: PreRenderedChunk) => string;
832
832
  declare const replaceTemplateName: (template: string, name: string) => string;
833
- export { Plugin as P, RenderedChunk as R, RE_CSS as a, RE_DTS as b, RE_DTS_MAP as c, RE_JS as d, RE_JSON as e, RE_NODE_MODULES as f, RE_TS as g, RE_VUE as h, filenameDtsTo as i, filenameJsToDts as j, filenameToDts as k, resolveTemplateFunction as l, replaceTemplateName as r };
833
+ declare const dtsEntryFileName: (template: string, name: string, hasDExtension: boolean) => string | undefined;
834
+ export { Plugin as P, RenderedChunk as R, RE_CSS as a, RE_DTS as b, RE_DTS_MAP as c, RE_JS as d, RE_JSON as e, RE_NODE_MODULES as f, RE_TS as g, RE_VUE as h, dtsEntryFileName as i, filenameDtsTo as j, filenameJsToDts as k, filenameToDts as l, resolveTemplateFunction as m, replaceTemplateName as r };
@@ -0,0 +1,14 @@
1
+ var Se=Object.defineProperty;var J=(o,e)=>Se(o,"name",{value:e,configurable:!0});import{spawn as Ee,fork as je}from"node:child_process";import{readFileSync as me,existsSync as U}from"node:fs";import{mkdtemp as _e,writeFile as Me,rm as ue,readFile as oe}from"node:fs/promises";import g from"node:path";import{parse as ge}from"@babel/parser";import{createFilter as Oe}from"@rollup/pluginutils";import{createDebug as Y}from"obug";import{transformSync as Te,isolatedDeclarationSync as Ae}from"oxc-transform";import{RE_DTS as _,RE_NODE_MODULES as H,filenameToDts as se,RE_JSON as ne,RE_TS as K,RE_VUE as Q,RE_JS as X,resolveTemplateFunction as Re,dtsEntryFileName as ie,replaceTemplateName as Fe,RE_DTS_MAP as ae}from"../filename.js";import{ResolverFactory as ke}from"oxc-resolver";import{resolve as De}from"@visulima/path";import{createRequire as Ie}from"node:module";import{tmpdir as Ne}from"node:os";var Pe=Object.defineProperty,M=J((o,e)=>Pe(o,"name",{value:e,configurable:!0}),"p");const le=/\bimport\(\s*["']([^"']+)["']\s*\)\.(\w+)/g,ce=/\bimport\b([^'"]*)["']([^"']+)["']/g,Ce=/\{([^}]*)\}/,ye=/\s+as\s+/,he=/^type\s+/,pe=/\bexport\s+\*\s+from\s*["']([^"']+)["']/g,de=/\bexport\s+(?:type\s+)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g,Je=M(o=>o.length>0&&!o.startsWith(".")&&!g.isAbsolute(o),"isBareSpecifier"),fe=M(o=>{const e=new Map,p=M((n,a)=>{if(!Je(n))return;let c=e.get(n);c||(c=new Set,e.set(n,c)),a&&c.add(a)},"add");let r;for(le.lastIndex=0;r=le.exec(o);)p(r[1],r[2]);for(ce.lastIndex=0;r=ce.exec(o);){const n=r[1],a=r[2],c=Ce.exec(n);if(c)for(const u of c[1].split(",")){const m=u.trim().split(ye).pop();m&&p(a,m.replace(he,"").trim())}else p(a)}return e},"collectReferencedSpecifiers"),We=M(o=>{const e=new Map,p=M(n=>{let a=e.get(n);return a||(a={all:!1,names:new Set},e.set(n,a)),a},"get");let r;for(pe.lastIndex=0;r=pe.exec(o);)p(r[1]).all=!0;for(de.lastIndex=0;r=de.exec(o);){const n=p(r[2]);for(const a of r[1].split(",")){const c=a.trim().replace(he,"");c&&(ye.test(c)||n.names.add(c))}}return e},"parseReexports"),Ge=M((o,e,p)=>o.replaceAll(`import("${e}")`,`import("${p}")`).replaceAll(`import('${e}')`,`import('${p}')`).replaceAll(`from "${e}"`,`from "${p}"`).replaceAll(`from '${e}'`,`from '${p}'`),"replaceSpecifier"),Le=M(o=>{const e=new ke({conditionNames:["types","typings","import","require"],mainFields:["types","typings","module","main"],tsconfig:o?{configFile:o,references:"auto"}:void 0}),p=new Map,r=new Map,n=M((c,u)=>{const m=`${g.dirname(u)}\0${c}`;if(r.has(m))return r.get(m);let h;try{const w=e.resolveDtsSync(u,c);w.path&&_.test(w.path)&&(h=w.path)}catch{}return r.set(m,h),h},"resolveDts"),a=M((c,u)=>{const m=n(c,u);if(!m)return;let h=p.get(m);if(!h){let w;try{w=me(m,"utf8")}catch{return}h=We(w),p.set(m,h)}return h},"getReexports");return(c,u,m)=>{const h=fe(c);if(h.size===0)return c;const w=fe(m);if(w.size===0)return c;let b=c;for(const[S,E]of h){if(w.has(S))continue;const R=[];for(const F of w.keys()){const I=a(F,u)?.get(S);I&&(I.all||[...E].every(q=>I.names.has(q)))&&R.push(F)}R.length===1&&(b=Ge(b,S,R[0]))}return b}},"createReexportSpecifierRewriter");var Ue=Object.defineProperty,we=J((o,e)=>Ue(o,"name",{value:e,configurable:!0}),"o");const ze=Y("rollup-plugin-dts:tsc-context"),ve=we(()=>({files:new Map,programs:[],projects:new Map}),"createContext"),qe=we((o,e)=>{const p=De(e).replaceAll("\\","/");ze(`invalidating context file: ${p}`),o.files.delete(p),o.programs=o.programs.filter(r=>!r.getSourceFiles().some(n=>n.fileName===p)),o.projects.clear()},"invalidateContextFile"),Ve=ve();var Be=Object.defineProperty,z=J((o,e)=>Be(o,"name",{value:e,configurable:!0}),"m$1");const D=Y("rollup-plugin-dts:tsgo"),He=z(async(...o)=>{await new Promise((e,p)=>{const r=Ee(...o);let n="";r.stderr?.on("data",a=>{n+=a.toString()}),r.on("close",(a,c)=>{if(a===0){e();return}const u=`tsgo ${a===null?`was terminated by signal ${String(c)}`:`exited with code ${String(a)}`}${n.trim()?`
2
+ ${n.trim()}`:""}`;p(new Error(u))}),r.on("error",a=>{p(a)})})},"spawnAsync"),Ke=z(()=>{const o=Ie(import.meta.url),e=o.resolve("@typescript/native-preview/package.json"),p=g.dirname(e),r=o(g.join(p,"lib","getExePath.js")),n=typeof r=="function"?r:r.default;if(!n)throw new Error("Failed to resolve getExePath from @typescript/native-preview");return n()},"getTsgoPathFromNodeModules"),Qe=z((o,e,p,r)=>["--noEmit","false","--declaration","--emitDeclarationOnly",...o?["-p",o]:[],"--outDir",e,"--rootDir",p,"--noCheck",...r?["--declarationMap"]:[]],"buildTsgoArgs"),Xe=z(async(o,e,p,r,n)=>{D("[tsgo] rootDir",o);let a;r?(a=r,D("[tsgo] using custom path",a)):(a=Ke(),D("[tsgo] using tsgo from node_modules",a));const c=await _e(g.join(Ne(),"rollup-plugin-dts-"));D("[tsgo] tsgoDist",c);let u=e,m;if(n&&Object.keys(n.compilerOptions??{}).length>0){const w=e?g.dirname(e):o,{compilerOptions:b,...S}=n;m=g.join(w,`tsconfig.tsgo-${g.basename(c)}.json`);const E=e?{compilerOptions:b,extends:e}:{...S,compilerOptions:b};await Me(m,JSON.stringify(E),"utf8"),D("[tsgo] wrote temp project %s",m),u=m}const h=Qe(u,c,o,p);D("[tsgo] args %o",h);try{await He(a,h,{stdio:"inherit"})}finally{m&&await ue(m,{force:!0}).catch(()=>{})}return c},"runTsgo");var Ye=Object.defineProperty,W=J((o,e)=>Ye(o,"name",{value:e,configurable:!0}),"T");const $=Y("rollup-plugin-dts:generate"),Ze=import.meta.WORKER_URL??"./tsc/worker.js",yt=W(({build:o,cwd:e,eager:p,emitDtsOnly:r,emitJs:n,entry:a,exclude:c,include:u,incremental:m,newContext:h,oxc:w,parallel:b,sourcemap:S,tsconfig:E,tsconfigRaw:R,tsgo:F,tsMacro:I,vue:q})=>{const Z=u||c?Oe(u,c):null,xe=a?.filter(i=>i[0]!=="!"),$e=a?.filter(i=>i[0]==="!").map(i=>i.slice(1)),ee=a?i=>{const s=i.split(g.sep).join("/");return xe.some(t=>g.posix.matchesGlob(s,t))&&!$e.some(t=>g.posix.matchesGlob(s,t))}:void 0,T=new Map,G=new Set,te=new Map,be=Le(E);let k,V,B,L,N;const re=E?g.dirname(E):e;return{async buildEnd(){k?.kill(),!$.enabled&&N&&await ue(N,{force:!0,recursive:!0}).catch(()=>{}),N=void 0,h&&(L=void 0)},async buildStart(i){F?N=await Xe(re,E,S,F.path,R):w||(b?(k=je(new URL(Ze,import.meta.url),{stdio:"inherit"}),await new Promise((t,l)=>{k.once("spawn",()=>{t()}),k.once("error",d=>{l(new Error(`Failed to start the parallel tsc worker: ${d.message}`,{cause:d}))})}),V=(await import("birpc")).createBirpc({},{on:W(t=>k.on("message",t),"on"),post:W(t=>k.send(t),"post")})):(B=await import("../packem_chunks/index.js"),h&&(L=ve())));const s=Array.isArray(i.input)?i.input.map(t=>[void 0,t]):Object.entries(i.input).map(([t,l])=>[t,l]);for(const[t,l]of s){$("resolving input %s (alias %s)",l,t??"<derived>");let d=await this.resolve(l);l.startsWith("./")||(d||=await this.resolve(`./${l}`));const y=d?.id||l,f=t??g.basename(y).replace(K,"").replace(X,"");$("resolved input %s -> %s (%s)",l,y,f),te.set(y,f)}},generateBundle(i,s){for(const t of Object.keys(s)){const l=s[t];if(l){if(l.type==="asset"&&ae.test(t)&&typeof l.source=="string"){const d=JSON.parse(l.source);d.names=[],delete d.sourcesContent,l.source=JSON.stringify(d)}r&&l.type==="chunk"&&!_.test(t)&&!ae.test(t)&&delete s[t]}}},load:{filter:{id:{exclude:[H],include:[_]}},async handler(i){if(!T.has(i))return;const{code:s,id:t,jsFile:l}=T.get(i);let d,y;if($("generate dts %s from %s",i,t),l&&U(i)){$("dts file already exists for %s, skipping generation",t);return}if(F){if(Q.test(t))throw new Error("tsgo does not support Vue files.");const f=g.resolve(N,g.relative(re,se(t)));if(U(f)){if(d=await oe(f,"utf8"),S){const O=`${f}.map`;if(U(O)){const v=JSON.parse(await oe(O,"utf8"));if(Array.isArray(v.sources)){const A=g.dirname(O);v.sources=v.sources.map(x=>x==null?x:g.resolve(A,x))}y=v}}}else throw $("[tsgo]",f,"is missing"),new Error(`tsgo did not generate dts file for ${t}, please check your tsconfig.`)}else if(w&&!Q.test(t)){const f=Ae(t,s,w);if(f.errors.length>0){const[O]=f.errors,v=f.errors.length,A=v===1?"isolated declarations error":`${v} isolated declarations errors`,x=f.errors.map((j,P)=>{const C=j?.message??"Unknown error";return j?.codeframe?`${P+1}. ${C}
3
+ ${j.codeframe}`:`${P+1}. ${C}`}).join(`
4
+
5
+ `);return this.error({frame:O?.codeframe||void 0,message:`${A} in ${t}:
6
+
7
+ ${x}`})}d=f.code,f.map&&(f.map.sourcesContent=void 0,f.map.names=[],y=f.map)}else{const f=p?void 0:[...G],O={build:o,context:L,cwd:e,entries:f,id:t,incremental:m,sourcemap:S,tsconfig:E,tsconfigRaw:R,tsMacro:I,vue:q};let v;if(b){if(!V)return this.error(new Error("Parallel tsc worker is not initialized"));v=await V.tscEmit(O)}else v=B.tscEmit(O);if(v.error)return this.error(v.error);if(d=v.code,y=v.map,d&&ne.test(t))if(d.includes("declare const _exports")){if(d.includes("declare const _exports: {")&&!d.includes(`
8
+ }[];`)){const A=tt(d);let x=0;d+=A.map(j=>{const P=`_${j.replaceAll(/[^\w$]/g,"_")}${x++}`,C=JSON.stringify(j);return`declare let ${P}: typeof _exports[${C}]
9
+ export { ${P} as ${C} }`}).join(`
10
+ `)}}else{const A=et(d);d+=`
11
+ declare namespace __json_default_export {
12
+ export { ${Array.from(A.entries(),([x,j])=>x===j?x:`${j} as ${x}`).join(", ")} }
13
+ }
14
+ export { __json_default_export as default }`}}return d&&!l&&(d=be(d,t,s)),{code:d||"",map:y}}},name:"rollup-plugin-dts:generate",outputOptions(i){return{...i,entryFileNames(s){const{entryFileNames:t}=i,l=Re(t||"[name].js",s);if(s.name.endsWith(".d"))return ie(l,s.name,!0)??l;if(r){if(s.facadeModuleId&&_.test(s.facadeModuleId)){const d=ie(l,s.name,!1);if(d!==void 0)return d}return Fe("[name].js",s.name)}return l}}},async resolveId(i,s){if(T.has(i))return $("resolve dts id %s",i),{id:i};if(!s&&_.test(i)&&!H.test(i)){const t=g.isAbsolute(i)?i:g.resolve(e,i),l=t.replace(_,""),d=[t.replace(_,".$1ts"),`${l}.tsx`,`${l}.ts`,`${l}.mts`,`${l}.cts`];if(!T.has(t)){for(const y of d)if(U(y)){const f=me(y,"utf8");T.set(t,{code:f,id:y,isEntry:!0,jsFile:X.test(y)}),G.add(y),$("populated dtsMap from source for cached re-resolution: %s (via %s)",t,y);break}}return T.has(t)?($("resolve dts id %s (from cache re-resolution)",t),{id:t}):null}if(s&&K.test(s)&&(i.startsWith("./")||i.startsWith("../"))&&!g.extname(i))for(const t of[".ts",".tsx",".mts",".cts"]){const l=await this.resolve(i+t,s,{skipSelf:!0});if(l)return l}return null},shouldTransformCachedModule({id:i}){return _.test(i)},transform:{handler(i,s){if(s.startsWith("\0")||_.test(s)||H.test(s)||Z&&!Z(s))return;const t=X.test(s);if(!t||n){const l=!!this.getModuleInfo(s)?.isEntry,d=ee?l&&ee(g.relative(e,s)):l,y=se(s);if(T.set(y,{code:i,id:s,isEntry:d,jsFile:t}),$("register dts source: %s",s),d){G.add(s);const f=te.get(s);this.emitFile({id:y,name:f?`${f}.d`:void 0,type:"chunk"})}else G.delete(s)}return r?ne.test(s)?"{}":"export { }":K.test(s)||Q.test(s)?Te(s,i,{}).code:null},order:"pre"},watchChange(i){B&&qe(L||Ve,i)}}},"createGeneratePlugin"),et=W(o=>{const e=new Map,{program:p}=ge(o,{errorRecovery:!0,plugins:[["typescript",{dts:!0}]],sourceType:"module"});for(const r of p.body)if(r.type==="ExportNamedDeclaration"){if(r.declaration)if(r.declaration.type==="VariableDeclaration")for(const n of r.declaration.declarations)n.id.type==="Identifier"&&e.set(n.id.name,n.id.name);else r.declaration.type==="TSModuleDeclaration"&&r.declaration.id.type==="Identifier"&&e.set(r.declaration.id.name,r.declaration.id.name);else if(r.specifiers.length>0)for(const n of r.specifiers)n.type==="ExportSpecifier"&&n.exported.type==="Identifier"&&e.set(n.exported.name,n.local.type==="Identifier"?n.local.name:n.exported.name)}return e},"collectJsonExportMap"),tt=W(o=>{const e=[],{program:p}=ge(o,{plugins:[["typescript",{dts:!0}]],sourceType:"module"}),[r]=p.body,n=r?.type==="VariableDeclaration"?r.declarations[0]:void 0,a=n?.id.type==="Identifier"?n.id.typeAnnotation:void 0,c=(a?.type==="TSTypeAnnotation"&&a.typeAnnotation.type==="TSTypeLiteral"?a.typeAnnotation:void 0)?.members;if(!Array.isArray(c))throw new TypeError("rollup-plugin-dts: unexpected JSON declaration shape — expected `declare const _exports: { ... }` with an object type literal. The emitted dts may have changed; cannot extract named exports.");for(const u of c)u.key.type==="Identifier"?e.push(u.key.name):u.key.type==="StringLiteral"&&e.push(u.key.value);return e},"collectJsonExports");export{yt as c,Ve as g};
@@ -1 +1 @@
1
- var X=Object.defineProperty;var O=(e,t)=>X(e,"name",{value:t,configurable:!0});import{existsSync as Y}from"node:fs";import{createRequire as Z}from"node:module";import m from"node:path";import I from"node:process";import{findTsConfigSync as _,readTsConfig as H}from"@visulima/tsconfig";import C from"typescript";var K=Object.defineProperty,r=O((e,t)=>K(e,"name",{value:t,configurable:!0}),"i");let E=!1;const N=r(e=>e?e.incremental===!1?-1:e.incremental===!0||typeof e.tsBuildInfoFile=="string"?1:0:0,"checkCompilerOptionsIncremental"),Q=r((e,t)=>{if(e.startsWith("."))return m.resolve(t,e.endsWith(".json")?e:`${e}.json`);try{return Z(m.join(t,"package.json")).resolve(e)}catch{return}},"resolveExtendedTsconfigPath"),U=r(e=>{if(Y(e))return C.sys.readFile(e)},"readTsconfigFile"),P=r((e,t=new Set)=>{if(t.has(e))return!1;t.add(e);const o=C.readConfigFile(e,U);if(o.error||!o.config)return!1;const i=o.config,n=N(i.compilerOptions);if(n!==0)return n===1;if(!i.extends)return!1;const s=Array.isArray(i.extends)?i.extends:[i.extends],g=m.dirname(e);for(const a of s){if(typeof a!="string")continue;const f=Q(a,g);if(f&&P(f,t))return!0}return!1},"hasExplicitIncrementalInTsconfig"),ee=r((e,t)=>{if(e===!0||e===void 0)try{const o=_(t);return{resolvedTsconfig:o.config,tsconfig:o.path}}catch{return{resolvedTsconfig:void 0,tsconfig:void 0}}if(typeof e=="string"){const o=m.resolve(t||I.cwd(),e);return{resolvedTsconfig:H(o),tsconfig:o}}return{resolvedTsconfig:void 0,tsconfig:void 0}},"resolveTsconfigPath"),te=r((e,t,o,i)=>{if(e){if(t)throw new Error("[@visulima/rollup-plugin-dts] The `tsgo` option is not compatible with the `vue` option. Please disable one of them.");if(o)throw new Error("[@visulima/rollup-plugin-dts] The `tsgo` option is not compatible with the `tsMacro` option. Please disable one of them.");if(i)throw new Error("[@visulima/rollup-plugin-dts] The `tsgo` option is not compatible with the `oxc` option. Please disable one of them.")}},"validateTsgoCompatibility"),oe=r((e,t,o)=>{if(e){if(t)throw new Error("[@visulima/rollup-plugin-dts] The `oxc` option is not compatible with the `vue` option. Please disable one of them.");if(o)throw new Error("[@visulima/rollup-plugin-dts] The `oxc` option is not compatible with the `tsMacro` option. Please disable one of them.")}},"validateOxcCompatibility"),ie=r(e=>e===!1?!1:e===!0?{}:e.enabled===!1?!1:{path:e.path},"normalizeTsgo"),se=r((e,t,o,i,n)=>{let s;switch(e){case!1:{s=!1;break}case!0:{s={};break}case void 0:{s=t.isolatedDeclarations&&!o&&!i&&!n?{}:!1;break}default:s=e}return s&&(s.stripInternal??=t.stripInternal??!1,s.sourcemap=t.declarationMap??!1),s},"normalizeOxc"),ue=r(({banner:e,build:t=!1,cjsDefault:o=!1,compilerOptions:i={},cwd:n=I.cwd(),dtsInput:s=!1,eager:g=!1,emitDtsOnly:a=!1,emitJs:f,entry:c,exclude:j,footer:k,include:M,incremental:D=!1,newContext:F=!1,oxc:A,parallel:J=!1,resolve:R=!1,resolver:z="oxc",sideEffects:S=!1,sourcemap:W,tsconfig:B,tsconfigRaw:$={},tsgo:q=!1,tsMacro:p=!1,vue:u=!1})=>{const{resolvedTsconfig:w,tsconfig:h}=ee(B,n),b=i,l={...w?.compilerOptions,...i},G=D||b.incremental===!0||typeof b.tsBuildInfoFile=="string"||typeof h=="string"&&P(h),y=W??!!l.declarationMap;l.declarationMap=y;let x;if(c!==void 0){const T=Array.isArray(c)?c:[c];x=T.length>0?T:void 0}const L={...w,...$,compilerOptions:l},d=ie(q),v=se(A,l,u,d,p),V=f??!!(l.checkJs||l.allowJs);return te(d,u,p,v),oe(v,u,p),d&&!E&&(console.warn("The `tsgo` option is experimental and may change in the future."),E=!0),{banner:e,build:t,cjsDefault:o,cwd:n,dtsInput:s,eager:g,emitDtsOnly:a,emitJs:V,entry:x,exclude:j,footer:k,include:M,incremental:G,newContext:F,oxc:v,parallel:J,resolve:R,resolver:z,sideEffects:S,sourcemap:y,tsconfig:h,tsconfigRaw:L,tsgo:d,tsMacro:p,vue:u}},"resolveOptions");export{ue as resolveOptions};
1
+ var Y=Object.defineProperty;var O=(e,t)=>Y(e,"name",{value:t,configurable:!0});import{existsSync as Z}from"node:fs";import{createRequire as _}from"node:module";import m from"node:path";import I from"node:process";import{findTsConfigSync as $,readTsConfig as H}from"@visulima/tsconfig";import C from"typescript";var K=Object.defineProperty,r=O((e,t)=>K(e,"name",{value:t,configurable:!0}),"i");let E=!1;const N=r(e=>e?e.incremental===!1?-1:e.incremental===!0||typeof e.tsBuildInfoFile=="string"?1:0:0,"checkCompilerOptionsIncremental"),Q=r((e,t)=>{if(e.startsWith("."))return m.resolve(t,e.endsWith(".json")?e:`${e}.json`);try{return _(m.join(t,"package.json")).resolve(e)}catch{return}},"resolveExtendedTsconfigPath"),U=r(e=>{if(Z(e))return C.sys.readFile(e)},"readTsconfigFile"),P=r((e,t=new Set)=>{if(t.has(e))return!1;t.add(e);const o=C.readConfigFile(e,U);if(o.error||!o.config)return!1;const i=o.config,n=N(i.compilerOptions);if(n!==0)return n===1;if(!i.extends)return!1;const s=Array.isArray(i.extends)?i.extends:[i.extends],g=m.dirname(e);for(const a of s){if(typeof a!="string")continue;const f=Q(a,g);if(f&&P(f,t))return!0}return!1},"hasExplicitIncrementalInTsconfig"),ee=r((e,t)=>{if(e===!0||e===void 0)try{const o=$(t);return{resolvedTsconfig:o.config,tsconfig:o.path}}catch{return{resolvedTsconfig:void 0,tsconfig:void 0}}if(typeof e=="string"){const o=m.resolve(t||I.cwd(),e);return{resolvedTsconfig:H(o),tsconfig:o}}return{resolvedTsconfig:void 0,tsconfig:void 0}},"resolveTsconfigPath"),te=r((e,t,o,i)=>{if(e){if(t)throw new Error("[@visulima/rollup-plugin-dts] The `tsgo` option is not compatible with the `vue` option. Please disable one of them.");if(o)throw new Error("[@visulima/rollup-plugin-dts] The `tsgo` option is not compatible with the `tsMacro` option. Please disable one of them.");if(i)throw new Error("[@visulima/rollup-plugin-dts] The `tsgo` option is not compatible with the `oxc` option. Please disable one of them.")}},"validateTsgoCompatibility"),oe=r((e,t,o)=>{if(e){if(t)throw new Error("[@visulima/rollup-plugin-dts] The `oxc` option is not compatible with the `vue` option. Please disable one of them.");if(o)throw new Error("[@visulima/rollup-plugin-dts] The `oxc` option is not compatible with the `tsMacro` option. Please disable one of them.")}},"validateOxcCompatibility"),ie=r(e=>e===!1?!1:e===!0?{}:e.enabled===!1?!1:{path:e.path},"normalizeTsgo"),se=r((e,t,o,i,n)=>{let s;switch(e){case!1:{s=!1;break}case!0:{s={};break}case void 0:{s=t.isolatedDeclarations&&!o&&!i&&!n?{}:!1;break}default:s=e}return s&&(s.stripInternal??=t.stripInternal??!1,s.sourcemap=t.declarationMap??!1),s},"normalizeOxc"),ue=r(({banner:e,build:t=!1,cjsDefault:o=!1,compilerOptions:i={},cwd:n=I.cwd(),dtsInput:s=!1,eager:g=!1,emitDtsOnly:a=!1,emitJs:f,entry:c,exclude:j,footer:k,include:M,incremental:D=!1,newContext:F=!1,oxc:A,parallel:J=!1,resolve:R=!1,resolver:z="oxc",sideEffects:S=!1,sourcemap:W,tsconfig:B,tsconfigRaw:q={},tsgo:G=!1,tsMacro:p=!1,vue:u=!1})=>{const{resolvedTsconfig:w,tsconfig:h}=ee(B,n),b=i,l={...w?.compilerOptions,...i},L=D||b.incremental===!0||typeof b.tsBuildInfoFile=="string"||typeof h=="string"&&P(h),y=W??!!l.declarationMap;l.declarationMap=y;let x;if(c!==void 0){const T=Array.isArray(c)?c:[c];x=T.length>0?T:void 0}const V={...w,...q,compilerOptions:l},d=ie(G),v=se(A,l,u,d,p),X=f??!!(l.checkJs||l.allowJs);return te(d,u,p,v),oe(v,u,p),d&&!E&&(console.warn("The `tsgo` option is experimental and may change in the future."),E=!0),{banner:e,build:t,cjsDefault:o,cwd:n,dtsInput:s,eager:g,emitDtsOnly:a,emitJs:X,entry:x,exclude:j,footer:k,include:M,incremental:L,newContext:F,oxc:v,parallel:J,resolve:R,resolver:z,sideEffects:S,sourcemap:y,tsconfig:h,tsconfigRaw:V,tsgo:d,tsMacro:p,vue:u}},"resolveOptions");export{ue as resolveOptions};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/rollup-plugin-dts",
3
- "version": "1.0.0-alpha.33",
3
+ "version": "1.0.0-alpha.35",
4
4
  "description": "A Rollup plugin to bundle dts files",
5
5
  "homepage": "https://github.com/visulima/packem/tree/main/packages/rollup-plugin-dts",
6
6
  "bugs": {
@@ -69,6 +69,7 @@
69
69
  "peerDependencies": {
70
70
  "@ts-macro/tsc": "0.3.7",
71
71
  "@typescript/native-preview": ">=7.0.0-dev.20250601.1",
72
+ "rolldown": ">=1.0.3",
72
73
  "rollup": ">=4.61.0",
73
74
  "typescript": "^6.0.3",
74
75
  "vue-tsc": "3.3.3"
@@ -77,6 +78,9 @@
77
78
  "@typescript/native-preview": {
78
79
  "optional": true
79
80
  },
81
+ "rolldown": {
82
+ "optional": true
83
+ },
80
84
  "rollup": {
81
85
  "optional": true
82
86
  },
@@ -1,3 +0,0 @@
1
- var De=Object.defineProperty;var j=(e,t)=>De(e,"name",{value:t,configurable:!0});import ie from"node:path";import{generate as ae}from"@babel/generator";import{isIdentifierName as ve}from"@babel/helper-validator-identifier";import{parse as se}from"@babel/parser";import x from"@babel/types";import{isTypeOf as J,isDeclarationType as Te,walkAST as q,walkASTAsync as Ie,isIdentifierOf as ee,resolveString as Q,extractIdentifiers as Ne}from"ast-kit";import{RE_DTS as $,resolveTemplateFunction as we,filenameJsToDts as le,replaceTemplateName as pe,filenameDtsTo as de,RE_DTS_MAP as Oe,RE_NODE_MODULES as Ce,filenameToDts as Me}from"../filename.js";var Ae=Object.defineProperty,d=j((e,t)=>Ae(e,"name",{value:t,configurable:!0}),"o");const X="__rollup_dts_resolve__:",st=d(({cjsDefault:e,sideEffects:t,sourcemap:i})=>{let r=0;const m=new Map,b=new Map,v=new Map,C=new Set;let O;return{generateBundle(u,a){const S=new Map;for(const o of Object.values(a))if(o.type==="chunk")for(const h of o.moduleIds)S.set(h,o.fileName);const y=new RegExp(`"${X}(.+?)"`,"g");for(const o of Object.values(a))o.type!=="chunk"||!$.test(o.fileName)||o.code.includes(X)&&(o.code=o.code.replaceAll(y,(h,_)=>{const k=S.get(_);if(!k)return h;let N=ie.posix.relative(ie.posix.dirname(o.fileName),k);return N.startsWith(".")||(N=`./${N}`),N=de(N,"js"),JSON.stringify(N)}));for(const o of Object.values(a))if(Oe.test(o.fileName))if(i){if(o.type==="chunk"||typeof o.source!="string")continue;const h=JSON.parse(o.source);h.sourcesContent=void 0,o.source=JSON.stringify(h)}else delete a[o.fileName]},name:"rollup-plugin-dts:fake-js",outputOptions(u){const{chunkFileNames:a,entryFileNames:S}=u;return(u.format==="cjs"||u.format==="commonjs")&&(u={...u,format:"es"}),{...u,chunkFileNames(y){const o=we(y.isEntry?S||"[name].js":a||"[name]-[hash].js",y);if(y.name.endsWith(".d")){const h=le(pe(o,y.name.slice(0,-2)));if($.test(h))return h;const _=le(pe(o,y.name));if($.test(_))return _}return o},sourcemap:u.sourcemap||i}},renderChunk:P,renderStart(){O=void 0},async transform(u,a){if($.test(a))return F.call(this,u,a)}};async function F(u,a){const S=Object.create(null);let y;try{y=se(u,{createParenthesizedExpressions:!0,errorRecovery:!0,plugins:[["typescript",{dts:!0}],"decoratorAutoAccessors"],sourceType:"module"})}catch(g){throw new Error(`Failed to parse ${a}. This may be caused by a syntax error in the declaration file or a bug in the plugin. Please report this issue to https://github.com/visulima/packem
2
- ${g}`,{cause:g})}const{comments:o,program:h}=y;if(!C.has(a)&&h.body.some(g=>ke(g))&&(C.add(a),this.warn(Ce.test(a)?`${a} uses CommonJS dts syntax. CommonJS dts modules cannot be reliably bundled by @visulima/rollup-plugin-dts. Please mark this module as external in your Rollup config.`:`${a} uses CommonJS dts syntax. @visulima/rollup-plugin-dts does not support reliably bundling CommonJS dts input.`)),v.set(a,await Ke(this,h.body,a)),o){const g=ye(o);b.set(a,g)}const _=[],k=new Map,N=new Map,p=new Set;for(const[g,s]of h.body.entries()){const T=d(f=>h.body[g]=f,"setStmt");if(Xe(s,T))continue;if(s.type==="TSNamespaceExportDeclaration"){p.add(g);continue}const n=s.type==="TSModuleDeclaration"&&s.kind!=="namespace";let R;if(n&&s.id.type==="StringLiteral"){const f=await this.resolve(s.id.value,a);f&&!f.external?R=$.test(f.id)?f.id:Me(f.id):s.id.value[0]==="."&&this.warn(`\`declare module ${JSON.stringify(s.id.value)}\` will be kept as-is in the output. Relative module declaration may cause unexpected issues. Found in ${a}.`)}if(n&&a.endsWith(".vue.d.ts")&&u.slice(s.start,s.end).includes("__VLS_"))continue;const c=s.type==="ExportDefaultDeclaration",L=J(s,["ExportNamedDeclaration","ExportDefaultDeclaration"])&&s.declaration,I=L?s.declaration:s,H=L?f=>s.declaration=f:T;if(I.type!=="TSDeclareFunction"&&!Te(I))continue;J(I,["TSEnumDeclaration","ClassDeclaration","FunctionDeclaration","TSDeclareFunction","TSModuleDeclaration","VariableDeclaration"])&&(I.declare=!0);const M=[];if(I.type==="VariableDeclaration")M.push(...I.declarations.map(f=>f.id));else if("id"in I&&I.id){let f=I.id;f.type==="TSQualifiedName"&&(f=G(f)),f=n&&f.type!=="Identifier"?x.identifier(`_${W(S,"")}`):f,M.push(f)}else{const f=x.identifier("export_default");M.push(f),I.id=f}const K=he(I),z=new Set,l=await Ee(this,I,a,k,z,S),D=[...z].filter(f=>M.every(A=>f!==A));if(I!==s&&(I.leadingComments=s.leadingComments),M.length===1&&N.has(M[0].name)){const f=N.get(M[0].name),A=te(f);A.overloads||(A.overloads=[],A.primaryDepsCount=A.deps.length,A.primaryParamsCount=A.params.length,A.primaryChildrenCount=A.children.length),A.overloads.push({children:D,childrenOffset:A.children.length,decl:I,deps:l,depsOffset:A.deps.length,params:K,paramsOffset:A.params.length}),A.deps.push(...l),A.params.push(...K),A.children.push(...D),p.add(g);continue}const E=xe({bindings:M,children:D,decl:I,deps:l,params:K,resolvedModuleId:R});M.length===1&&N.set(M[0].name,E);const w=x.numericLiteral(E),U=x.arrowFunctionExpression(K.map(({name:f})=>x.identifier(f)),x.arrayExpression(l)),re=x.arrayExpression(D.map(f=>({end:f.end,loc:f.loc,start:f.start,type:"StringLiteral",value:""}))),ne=n&&x.callExpression(x.identifier("sideEffect"),[M[0]]),be=Qe(ne?[w,U,re,ne]:[w,U,re]),oe={declarations:[{id:{...M[0],typeAnnotation:null},init:be,type:"VariableDeclarator"},...M.slice(1).map(f=>({id:{...f,typeAnnotation:null},type:"VariableDeclarator"}))],kind:"var",type:"VariableDeclaration"};c?(_.push(x.exportNamedDeclaration(null,[x.exportSpecifier(M[0],x.identifier("default"))])),T(oe)):H(oe)}return t&&_.push(x.expressionStatement(x.callExpression(x.identifier("sideEffect"),[]))),h.body=[...Array.from(k.values(),({stmt:g})=>g),...h.body.filter((g,s)=>!p.has(s)),..._],ae(y,{comments:!1,sourceFileName:a,sourceMaps:i})}function P(u,a){if(!$.test(a.fileName))return;O??=Le(v);const S=Ve(a,v,O);let y;try{y=se(u,{sourceType:"module"})}catch(p){throw new Error(`Failed to parse generated code for chunk ${a.fileName}. This may be caused by a bug in the plugin. Please report this issue to https://github.com/visulima/packem
3
- ${p}`,{cause:p})}const{program:o}=y;if(o.body=Ge(o.body),o.body=He(o.body),o.body=o.body.flatMap(p=>{if(Ue(p))return[];if(p.type==="ExpressionStatement")return[];const g=qe(p,S,e);if(g===!1)return[];if(g)return[g];if(p.type!=="VariableDeclaration")return[p];if(!Je(p))return[];const[s,T,n]=p.declarations[0].init.elements,R=s.value,c=te(R);q(c.decl,{enter(l){l.type!=="CommentBlock"&&(l.leadingComments?.length||delete l.loc)}});for(const[l,D]of p.declarations.entries()){const E={...D.id,typeAnnotation:c.bindings[l].typeAnnotation};V(c.bindings[l],E)}const L=c.primaryChildrenCount??c.children.length,I=c.primaryParamsCount??c.params.length,H=c.primaryDepsCount??c.deps.length;for(let l=0;l<L;l++){const D=n.elements[l];Object.assign(c.children[l],{loc:D.loc})}const M=T.params;for(let l=0;l<I;l++){const D=M[l].name;for(const E of c.params[l].typeParams)E.name=D}const K=T.body.elements;for(let l=0;l<H;l++){const D=c.deps[l];let E=K[l];E&&E.type==="UnaryExpression"&&E.operator==="void"?E={...x.identifier("undefined"),end:E.end,loc:E.loc,start:E.start}:Z(E)&&(E.name="__Infer"),D.replace?D.replace(E):Object.assign(D,E)}c.decl.type==="TSModuleDeclaration"&&c.resolvedModuleId&&(c.decl.id.value=X+c.resolvedModuleId);const z=[];if(c.overloads)for(const l of c.overloads){q(l.decl,{enter(D){D.type!=="CommentBlock"&&delete D.loc}}),"id"in l.decl&&l.decl.id&&V(l.decl.id,{...c.bindings[0]});for(const[D,E]of l.children.entries()){const w=n.elements[l.childrenOffset+D];w&&Object.assign(E,{loc:w.loc})}for(const[D,E]of l.params.entries()){const w=M[l.paramsOffset+D];if(w)for(const U of E.typeParams)U.name=w.name}for(const[D,E]of l.deps.entries()){let w=K[l.depsOffset+D];w&&(w.type==="UnaryExpression"&&w.operator==="void"?w={...x.identifier("undefined"),end:w.end,loc:w.loc,start:w.start}:Z(w)&&(w.name="__Infer"),E.replace?E.replace(w):Object.assign(E,w))}z.push(l.decl)}return[Ye(p,c.decl),...z]}).filter(p=>!!p),o.body.length===0)return"export { };";const h=o.body.some(p=>p.type==="ExportNamedDeclaration"||p.type==="ExportDefaultDeclaration"||p.type==="ExportAllDeclaration"),_=o.body.some(p=>p.type==="TSModuleDeclaration"&&p.id.type==="StringLiteral");!h&&_&&o.body.push(x.exportNamedDeclaration(null,[],null));const k=new Set,N=new Set;for(const p of a.moduleIds){const g=b.get(p);g&&(g.forEach(s=>{const T=s.type+s.value;N.has(T)||(N.add(T),k.add(s))}),b.delete(p))}return k.size>0&&(o.body[0].leadingComments||=[],o.body[0].leadingComments.unshift(...k)),ae(y,{comments:!0,sourceFileName:a.fileName,sourceMaps:i})}function W(u,a){return a in u?u[a]++:u[a]=0}function xe(u){const a=r++;return m.set(a,u),a}function te(u){return m.get(u)}function he(u){const a=[];q(u,{leave(y){"typeParameters"in y&&y.typeParameters?.type==="TSTypeParameterDeclaration"&&a.push(...y.typeParameters.params)}});const S=new Map;for(const y of a){const{name:o}=y,h=S.get(o);h?h.push(y):S.set(o,[y])}return Array.from(S.entries(),([y,o])=>({name:y,typeParams:o}))}function ge(u){const a=[];return q(u,{enter(S){S.type==="TSInferType"&&S.typeParameter&&a.push(S.typeParameter.name)}}),a}async function Ee(u,a,S,y,o,h){const _=new Set,k=new Set,N=new Map,p=[];let g=new Set;function s(n){return n.type==="Identifier"&&g.has(n.name)}return j(s,"f"),d(s,"isInferred"),await Ie(a,{enter(n){if(n.type==="TSConditionalType"){const R=ge(n.extendsType);p.push(R)}return Promise.resolve()},async leave(n,R){if(n.type==="TSConditionalType")p.pop();else if(R?.type==="TSConditionalType"){const c=R.trueType===n;g=new Set((c?p:p.slice(0,-1)).flat())}else g=new Set;if(n.type==="ExportNamedDeclaration")for(const c of n.specifiers)c.type==="ExportSpecifier"&&T(c.local);else if(n.type==="TSInterfaceDeclaration"&&n.extends)for(const c of n.extends||[])T(B(c.expression));else if(n.type==="ClassDeclaration"){if(n.superClass&&T(n.superClass),n.implements)for(const c of n.implements)c.type!=="ClassImplements"&&T(B(c.expression))}else if(J(n,["ObjectMethod","ObjectProperty","ClassProperty","TSPropertySignature","TSDeclareMethod","TSMethodSignature"]))n.computed&&fe(n.key)&&T(n.key),"value"in n&&fe(n.value)&&T(n.value);else switch(n.type){case"TSImportType":{k.add(n);const c=n.argument,L=n.qualifier,I=await Se(u,S,n,L,c,y,h,N);I&&T(I);break}case"TSTypeQuery":{if(k.has(n.exprName))return;if(n.exprName.type==="TSImportType")break;T(B(n.exprName));break}case"TSTypeReference":{T(B(n.typeName));break}}R&&!_.has(n)&&ue(n,R)&&o.add(n)}}),[..._];function T(n){me(n)||s(n)||_.add(n)}j(T,"l")}async function Se(u,a,S,y,o,h,_,k){let N=k.get(o.value);if(N===void 0){const n=await u.resolve(o.value,a);N=!n||!!n.external,k.set(o.value,N)}if(N)return;const p=o.value.replaceAll(/\W/g,"_"),g=`_$${ve(o.value)?o.value:`${p}${W(_,p)}`}`;let s=x.identifier(g);if(h.has(o.value)?s=h.get(o.value).local:h.set(o.value,{local:s,stmt:x.importDeclaration([x.importNamespaceSpecifier(s)],o)}),y){const n=G(y);V(n,x.tsQualifiedName(s,{...n})),s=y}let T=S;return S.typeParameters?(V(S,x.tsTypeReference(s,S.typeParameters)),T=s):V(S,s),{...B(s),replace(n){V(T,n)}}}},"createFakeJsPlugin");function ue(e,t){return!!(e.type==="Identifier"||J(t,["TSPropertySignature","TSMethodSignature"])&&t.key===e)}j(ue,"Pe");d(ue,"isChildSymbol");const _e=/\/\s*<reference\s+(?:path|types)=/,ye=d((e,t=!1)=>e.filter(i=>_e.test(i.value)!==t),"collectReferenceDirectives"),ke=d(e=>e.type==="TSExportAssignment"||e.type==="TSImportEqualsDeclaration"&&e.moduleReference.type==="TSExternalModuleReference","isCjsDtsInputSyntax"),je=d((e,t)=>{if(e.type==="ImportDeclaration")for(const i of e.specifiers)(e.importKind==="type"||"importKind"in i&&i.importKind==="type")&&t.add(i.local.name)},"collectTypeOnlyLocals"),Re=d(e=>{if(e.type==="VariableDeclaration")return e.declarations.flatMap(t=>Ne(t.id).map(i=>i.name));if("id"in e&&e.id){const t=e.id;if(t.type!=="Identifier"&&t.type!=="TSQualifiedName")return[];const i=G(t);return i.type==="Identifier"?[i.name]:[]}return[]},"collectDeclarationNames"),Pe=d((e,t)=>e.exportKind==="type"||"exportKind"in t&&t.exportKind==="type","isTypeOnlyExport"),ce=d(async(e,t,i)=>{if(!t)return;const r=await e.resolve(t.value,i);if(!(!r||r.external))return r.id},"resolveExportSource"),Fe=d(async(e,t,i,r)=>{if(t.type==="ExportNamedDeclaration"){if(t.declaration){for(const b of Re(t.declaration))r.exports.set(b,!1);return}const m=await ce(e,t.source,i);for(const b of t.specifiers){const v=Pe(t,b);if(b.type==="ExportSpecifier"){const C=Q(b.exported),O=Q(b.local);m?r.reExports.push({exported:C,local:O,source:m,typeOnly:v}):r.exports.set(C,v||r.typeOnlyLocals.has(O))}else r.exports.set(Q(b.exported),v)}return}if(t.type==="ExportDefaultDeclaration"){r.exports.set("default",!1);return}t.type==="ExportAllDeclaration"&&r.exportAlls.push({rawSource:t.source.value,source:await ce(e,t.source,i),typeOnly:t.exportKind==="type"})},"collectExportInfo"),Ke=d(async(e,t,i)=>{const r={exportAlls:[],exports:new Map,reExports:[],typeOnlyLocals:new Set};for(const m of t)je(m,r.typeOnlyLocals);for(const m of t)await Fe(e,m,i,r);return r},"collectModuleExports"),Y=d((e,t,i)=>{const r=e.get(t);return r===!1||r===i?!1:r===void 0||!i?(e.set(t,i),!0):!1},"setExportTypeOnly"),$e=d((e,t)=>{if(e.size!==t.size)return!1;for(const[i,r]of e)if(t.get(i)!==r)return!1;return!0},"exportsEqual"),Le=d(e=>{const t=new Map;for(const[r,m]of e)t.set(r,new Map(m.exports));let i=!0;for(;i;){i=!1;for(const[r,m]of e){const b=new Map(m.exports);for(const v of m.reExports){const C=(v.source?t.get(v.source):void 0)?.get(v.local)??!1;Y(b,v.exported,v.typeOnly||C)}for(const v of m.exportAlls){if(!v.source)continue;const C=t.get(v.source);if(C)for(const[O,F]of C)O!=="default"&&Y(b,O,v.typeOnly||F)}$e(t.get(r),b)||(t.set(r,b),i=!0)}}return t},"resolveAllModuleExports"),Ve=d((e,t,i)=>{const r=e.facadeModuleId&&t.has(e.facadeModuleId)?[e.facadeModuleId]:e.moduleIds,m=new Map,b=new Set;for(const C of r){const O=i.get(C);if(O)for(const[P,W]of O)Y(m,P,W);const F=t.get(C);if(F)for(const P of F.exportAlls)!P.typeOnly||P.source||b.add(P.rawSource)}const v=new Set;for(const[C,O]of m)O&&v.add(C);return{typeOnlyExportAllSources:b,typeOnlyNames:v}},"collectChunkExportInfo"),Be=d(e=>{if(!(e.declaration||e.specifiers.length===0)){for(const t of e.specifiers)if(t.type!=="ExportSpecifier"||t.exportKind!=="type")return;e.exportKind="type";for(const t of e.specifiers)t.type==="ExportSpecifier"&&(t.exportKind="value")}},"normalizeTypeOnlyExport"),Je=d(e=>x.isVariableDeclaration(e)&&e.declarations.length>0&&x.isVariableDeclarator(e.declarations[0])&&ze(e.declarations[0].init),"isRuntimeBindingVariableDeclaration"),ze=d(e=>x.isArrayExpression(e)&&We(e.elements),"isRuntimeBindingArrayExpression"),Qe=d(e=>x.arrayExpression(e),"runtimeBindingArrayExpression"),We=d(e=>{const[t,i,r,m]=e;return t?.type==="NumericLiteral"&&i?.type==="ArrowFunctionExpression"&&r?.type==="ArrayExpression"&&(!m||m.type==="CallExpression")},"isRuntimeBindingArrayElements"),Z=d(e=>ee(e,"infer"),"isInfer"),me=d(e=>ee(e,"this")||e.type==="ThisExpression"||e.type==="MemberExpression"&&me(e.object),"isThisExpression"),B=d(e=>{if(e.type==="Identifier")return e;const t=B(e.left);return Object.assign(e,x.memberExpression(t,e.right))},"TSEntityNameToRuntime"),G=d(e=>e.type==="Identifier"?e:G(e.left),"getIdFromTSEntityName"),fe=d(e=>J(e,["Identifier","MemberExpression"]),"isReferenceId"),Ue=d(e=>e.type==="ImportDeclaration"&&e.specifiers.length===1&&e.specifiers.every(t=>t.type==="ImportSpecifier"&&t.imported.type==="Identifier"&&["__export","__reExport"].includes(t.local.name)),"isHelperImport"),qe=d((e,t,i)=>{if(e.type==="ExportNamedDeclaration"&&!e.declaration&&!e.source&&e.specifiers.length===0&&!e.attributes?.length)return!1;if(e.type==="ImportDeclaration"&&e.specifiers.length>0)for(const r of e.specifiers)Z(r.local)&&(r.local.name="__Infer");if(J(e,["ImportDeclaration","ExportAllDeclaration","ExportNamedDeclaration"])){if(e.type==="ExportAllDeclaration"&&e.source&&t.typeOnlyExportAllSources.has(e.source.value)&&(e.exportKind="type"),e.type==="ExportNamedDeclaration"&&t.typeOnlyNames.size>0){for(const r of e.specifiers){const m=Q(r.exported);t.typeOnlyNames.has(m)&&(r.type==="ExportSpecifier"?r.exportKind="type":e.exportKind="type")}Be(e)}if(e.source?.value&&$.test(e.source.value))return e.source.value=de(e.source.value,"js"),e;if(i&&e.type==="ExportNamedDeclaration"&&!e.source&&e.specifiers.length===1&&e.specifiers[0].type==="ExportSpecifier"&&Q(e.specifiers[0].exported)==="default")return{expression:e.specifiers[0].local,type:"TSExportAssignment"}}},"patchImportExport"),Ge=d(e=>{const t=new Set;for(const[r,m]of e.entries()){const b=i(m);if(!b)continue;const[v,C]=b;C.properties.length!==0&&(e[r]={body:{body:[{declaration:null,source:null,specifiers:C.properties.filter(O=>O.type==="ObjectProperty").map(O=>{const F=O.value.body,P=O.key;return x.exportSpecifier(F,P)}),type:"ExportNamedDeclaration"}],type:"TSModuleBlock"},declare:!0,id:v,kind:"namespace",type:"TSModuleDeclaration"})}return e.filter(r=>!t.has(r));function i(r){if(r.type!=="VariableDeclaration"||r.declarations.length!==1||r.declarations[0].id.type!=="Identifier"||r.declarations[0].init?.type!=="CallExpression"||r.declarations[0].init.callee.type!=="Identifier"||r.declarations[0].init.callee.name!=="__export"||r.declarations[0].init.arguments.length!==1||r.declarations[0].init.arguments[0].type!=="ObjectExpression")return!1;const m=r.declarations[0].id,b=r.declarations[0].init.arguments[0];return[m,b]}},"patchTsNamespace"),He=d(e=>{const t=new Map;for(const[i,r]of e.entries())if(r.type==="ImportDeclaration"&&r.specifiers.length===1&&r.specifiers[0].type==="ImportSpecifier"&&r.specifiers[0].local.type==="Identifier"&&r.specifiers[0].local.name.endsWith("_exports"))t.set(r.specifiers[0].local.name,r.specifiers[0].local.name);else if(r.type==="ExpressionStatement"&&r.expression.type==="CallExpression"&&ee(r.expression.callee,"__reExport")){const m=r.expression.arguments;t.set(m[0].name,m[1].name)}else r.type==="VariableDeclaration"&&r.declarations.length===1&&r.declarations[0].init?.type==="MemberExpression"&&r.declarations[0].init.object.type==="Identifier"&&t.has(r.declarations[0].init.object.name)?e[i]={id:{name:r.declarations[0].id.name,type:"Identifier"},type:"TSTypeAliasDeclaration",typeAnnotation:{type:"TSTypeReference",typeName:{left:{name:t.get(r.declarations[0].init.object.name),type:"Identifier"},right:{name:r.declarations[0].init.property.name,type:"Identifier"},type:"TSQualifiedName"}}}:r.type==="ExportNamedDeclaration"&&r.specifiers.length===1&&r.specifiers[0].type==="ExportSpecifier"&&r.specifiers[0].local.type==="Identifier"&&t.has(r.specifiers[0].local.name)&&(r.specifiers[0].local.name=t.get(r.specifiers[0].local.name));return e},"patchReExport"),Xe=d((e,t)=>{if(e.type==="ImportDeclaration"||e.type==="ExportNamedDeclaration"&&!e.declaration){for(const i of e.specifiers)i.type==="ImportSpecifier"?i.importKind="value":i.type==="ExportSpecifier"&&(i.exportKind="value");return e.type==="ImportDeclaration"?e.importKind="value":e.type==="ExportNamedDeclaration"&&(e.exportKind="value"),!0}return e.type==="ExportAllDeclaration"?(e.exportKind="value",!0):e.type==="TSImportEqualsDeclaration"?(e.moduleReference.type==="TSExternalModuleReference"&&t({source:e.moduleReference.expression,specifiers:[{local:e.id,type:"ImportDefaultSpecifier"}],type:"ImportDeclaration"}),!0):e.type==="TSExportAssignment"&&e.expression.type==="Identifier"?(t({specifiers:[{exported:{name:"default",type:"Identifier"},local:e.expression,type:"ExportSpecifier"}],type:"ExportNamedDeclaration"}),!0):e.type==="ExportDefaultDeclaration"&&e.declaration.type==="Identifier"?(t({specifiers:[{exported:x.identifier("default"),local:e.declaration,type:"ExportSpecifier"}],type:"ExportNamedDeclaration"}),!0):!1},"rewriteImportExport"),V=d((e,t)=>{const i=e;for(const r of Object.keys(e))delete i[r];return Object.assign(e,t),e},"overwriteNode"),Ye=d((e,t)=>{t.leadingComments||=[];const i=e.leadingComments?.filter(r=>r.value.startsWith("#"));return i&&t.leadingComments.unshift(...i),t.leadingComments=ye(t.leadingComments,!0),t},"inheritNodeComments");export{st as default};
@@ -1,9 +0,0 @@
1
- var de=Object.defineProperty;var D=(a,s)=>de(a,"name",{value:s,configurable:!0});import{spawn as ue,fork as me}from"node:child_process";import{existsSync as I,readFileSync as fe}from"node:fs";import{mkdtemp as ge,readFile as X,rm as ye}from"node:fs/promises";import d from"node:path";import{parse as re}from"@babel/parser";import{createFilter as he}from"@rollup/pluginutils";import{createDebug as U}from"obug";import{transformSync as ve,isolatedDeclarationSync as xe}from"oxc-transform";import{RE_DTS as g,RE_NODE_MODULES as P,RE_JS as S,filenameToDts as Y,RE_JSON as Z,RE_TS as ee,RE_VUE as C,resolveTemplateFunction as we,replaceTemplateName as J,RE_DTS_MAP as te}from"../filename.js";import{resolve as Ee}from"@visulima/path";import{createRequire as $e}from"node:module";import{tmpdir as be}from"node:os";var Se=Object.defineProperty,oe=D((a,s)=>Se(a,"name",{value:s,configurable:!0}),"o");const _e=U("rollup-plugin-dts:tsc-context"),se=oe(()=>({files:new Map,programs:[],projects:new Map}),"createContext"),je=oe((a,s)=>{const p=Ee(s).replaceAll("\\","/");_e(`invalidating context file: ${p}`),a.files.delete(p),a.programs=a.programs.filter(n=>!n.getSourceFiles().some(i=>i.fileName===p)),a.projects.clear()},"invalidateContextFile"),Me=se();var Te=Object.defineProperty,W=D((a,s)=>Te(a,"name",{value:s,configurable:!0}),"n");const _=U("rollup-plugin-dts:tsgo"),ke=W(async(...a)=>{await new Promise((s,p)=>{const n=ue(...a);n.on("close",()=>{s()}),n.on("error",i=>{p(i)})})},"spawnAsync"),Oe=W(()=>{const a=$e(import.meta.url),s=a.resolve("@typescript/native-preview/package.json"),p=d.dirname(s),n=a(d.join(p,"lib","getExePath.js")),i=typeof n=="function"?n:n.default;if(!i)throw new Error("Failed to resolve getExePath from @typescript/native-preview");return i()},"getTsgoPathFromNodeModules"),De=W(async(a,s,p,n)=>{_("[tsgo] rootDir",a);let i;n?(i=n,_("[tsgo] using custom path",i)):(i=Oe(),_("[tsgo] using tsgo from node_modules",i));const m=await ge(d.join(be(),"rollup-plugin-dts-"));_("[tsgo] tsgoDist",m);const v=["--noEmit","false","--declaration","--emitDeclarationOnly",...s?["-p",s]:[],"--outDir",m,"--rootDir",a,"--noCheck",...p?["--declarationMap"]:[]];return _("[tsgo] args %o",v),await ke(i,v,{stdio:"inherit"}),m},"runTsgo");var Ae=Object.defineProperty,j=D((a,s)=>Ae(a,"name",{value:s,configurable:!0}),"M");const h=U("rollup-plugin-dts:generate"),Ne=import.meta.WORKER_URL??"./tsc/worker.js",He=j(({build:a,cwd:s,eager:p,emitDtsOnly:n,emitJs:i,entry:m,exclude:v,include:x,incremental:ne,newContext:G,oxc:A,parallel:V,sourcemap:N,tsconfig:M,tsconfigRaw:ie,tsgo:F,tsMacro:ae,vue:le})=>{const L=x||v?he(x,v):null,ce=m?.filter(o=>o[0]!=="!"),pe=m?.filter(o=>o[0]==="!").map(o=>o.slice(1)),B=m?o=>{const e=o.split(d.sep).join("/");return ce.some(r=>d.posix.matchesGlob(e,r))&&!pe.some(r=>d.posix.matchesGlob(e,r))}:void 0,w=new Map,T=new Set,K=new Map;let k,q,R,O,E;const z=M?d.dirname(M):s;return{async buildEnd(){k?.kill(),!h.enabled&&E&&await ye(E,{force:!0,recursive:!0}).catch(()=>{}),E=void 0,G&&(O=void 0)},async buildStart(o){if(F?E=await De(z,M,N,F.path):A||(V?(k=me(new URL(Ne,import.meta.url),{stdio:"inherit"}),q=(await import("birpc")).createBirpc({},{on:j(e=>k.on("message",e),"on"),post:j(e=>k.send(e),"post")})):(R=await import("../packem_chunks/index.js"),G&&(O=se()))),!Array.isArray(o.input))for(const[e,r]of Object.entries(o.input)){h("resolving input alias %s -> %s",e,r);let t=await this.resolve(r);r.startsWith("./")||(t||=await this.resolve(`./${r}`));const c=t?.id||r;h("resolved input alias %s -> %s",r,c),K.set(c,e)}},generateBundle(o,e){for(const r of Object.keys(e)){const t=e[r];if(t){if(t.type==="asset"&&te.test(r)&&typeof t.source=="string"){const c=JSON.parse(t.source);c.names=[],delete c.sourcesContent,t.source=JSON.stringify(c)}n&&t.type==="chunk"&&!g.test(r)&&!te.test(r)&&delete e[r]}}},load:{filter:{id:{exclude:[P],include:[g]}},async handler(o){if(!w.has(o))return;const{code:e,id:r}=w.get(o);let t,c;if(h("generate dts %s from %s",o,r),F){if(C.test(r))throw new Error("tsgo does not support Vue files.");const l=d.resolve(E,d.relative(z,Y(r)));if(I(l)){if(t=await X(l,"utf8"),N){const u=`${l}.map`;if(I(u)){const f=JSON.parse(await X(u,"utf8"));if(Array.isArray(f.sources)){const $=d.dirname(u);f.sources=f.sources.map(y=>y==null?y:d.resolve($,y))}c=f}}}else throw h("[tsgo]",l,"is missing"),new Error(`tsgo did not generate dts file for ${r}, please check your tsconfig.`)}else if(A&&!C.test(r)){const l=xe(r,e,A);if(l.errors.length>0){const[u]=l.errors;return this.error({frame:u?.codeframe||void 0,message:u?.codeframe?`${u.message}
2
- ${u.codeframe}`:u?.message??"Unknown error"})}t=l.code,l.map&&(l.map.sourcesContent=void 0,l.map.names=[],c=l.map)}else{const l=p?void 0:[...T],u={build:a,context:O,cwd:s,entries:l,id:r,incremental:ne,sourcemap:N,tsconfig:M,tsconfigRaw:ie,tsMacro:ae,vue:le};let f;if(f=V?await q.tscEmit(u):R.tscEmit(u),f.error)return this.error(f.error);if(t=f.code,c=f.map,t&&Z.test(r))if(t.includes("declare const _exports")){if(t.includes("declare const _exports: {")&&!t.includes(`
3
- }[];`)){const $=Re(t);let y=0;t+=$.map(b=>{const H=`_${b.replaceAll(/[^\w$]/g,"_")}${y++}`,Q=JSON.stringify(b);return`declare let ${H}: typeof _exports[${Q}]
4
- export { ${H} as ${Q} }`}).join(`
5
- `)}}else{const $=Fe(t);t+=`
6
- declare namespace __json_default_export {
7
- export { ${Array.from($.entries(),([y,b])=>y===b?y:`${b} as ${y}`).join(", ")} }
8
- }
9
- export { __json_default_export as default }`}}return{code:t||"",map:c}}},name:"rollup-plugin-dts:generate",outputOptions(o){return{...o,entryFileNames(e){const{entryFileNames:r}=o,t=we(r||"[name].js",e);if(e.name.endsWith(".d")){if(g.test(t))return J(t,e.name.slice(0,-2));if(S.test(t))return t.replace(S,".$1ts")}else if(n){if(e.facadeModuleId&&g.test(e.facadeModuleId)){if(g.test(t))return J(t,e.name);if(S.test(t))return t.replace(S,".$1ts")}return J("[name].js",e.name)}return t}}},async resolveId(o,e){if(w.has(o))return h("resolve dts id %s",o),{id:o};if(!e&&g.test(o)&&!P.test(o)){const r=d.isAbsolute(o)?o:d.resolve(s,o),t=r.replace(g,""),c=[r.replace(g,".$1ts"),`${t}.tsx`,`${t}.ts`,`${t}.mts`,`${t}.cts`];if(!w.has(r)){for(const l of c)if(I(l)){const u=fe(l,"utf8");w.set(r,{code:u,id:l,isEntry:!0}),T.add(l),h("populated dtsMap from source for cached re-resolution: %s (via %s)",r,l);break}}return w.has(r)?(h("resolve dts id %s (from cache re-resolution)",r),{id:r}):null}if(e&&ee.test(e)&&(o.startsWith("./")||o.startsWith("../"))&&!d.extname(o))for(const r of[".ts",".tsx",".mts",".cts"]){const t=await this.resolve(o+r,e,{skipSelf:!0});if(t)return t}return null},shouldTransformCachedModule({id:o}){return g.test(o)},transform:{handler(o,e){if(!(g.test(e)||P.test(e)||L&&!L(e))){if(!S.test(e)||i){const r=!!this.getModuleInfo(e)?.isEntry,t=B?r&&B(d.relative(s,e)):r,c=Y(e);if(w.set(c,{code:o,id:e,isEntry:t}),h("register dts source: %s",e),t){T.add(e);const l=K.get(e);this.emitFile({id:c,name:l?`${l}.d`:void 0,type:"chunk"})}else T.delete(e)}return n?Z.test(e)?"{}":"export { }":ee.test(e)||C.test(e)?ve(e,o,{}).code:null}},order:"pre"},watchChange(o){R&&je(O||Me,o)}}},"createGeneratePlugin"),Fe=j(a=>{const s=new Map,{program:p}=re(a,{errorRecovery:!0,plugins:[["typescript",{dts:!0}]],sourceType:"module"});for(const n of p.body)if(n.type==="ExportNamedDeclaration"){if(n.declaration)if(n.declaration.type==="VariableDeclaration")for(const i of n.declaration.declarations)i.id.type==="Identifier"&&s.set(i.id.name,i.id.name);else n.declaration.type==="TSModuleDeclaration"&&n.declaration.id.type==="Identifier"&&s.set(n.declaration.id.name,n.declaration.id.name);else if(n.specifiers.length>0)for(const i of n.specifiers)i.type==="ExportSpecifier"&&i.exported.type==="Identifier"&&s.set(i.exported.name,i.local.type==="Identifier"?i.local.name:i.exported.name)}return s},"collectJsonExportMap"),Re=j(a=>{const s=[],{program:p}=re(a,{plugins:[["typescript",{dts:!0}]],sourceType:"module"}),[n]=p.body,i=n?.type==="VariableDeclaration"?n.declarations[0]:void 0,m=i?.id.type==="Identifier"?i.id.typeAnnotation:void 0,v=(m?.type==="TSTypeAnnotation"&&m.typeAnnotation.type==="TSTypeLiteral"?m.typeAnnotation:void 0)?.members;if(!Array.isArray(v))throw new TypeError("rollup-plugin-dts: unexpected JSON declaration shape — expected `declare const _exports: { ... }` with an object type literal. The emitted dts may have changed; cannot extract named exports.");for(const x of v)x.key.type==="Identifier"?s.push(x.key.name):x.key.type==="StringLiteral"&&s.push(x.key.value);return s},"collectJsonExports");export{He as c,Me as g};