@visulima/rollup-plugin-dts 1.0.0-alpha.27 → 1.0.0-alpha.29
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 +17 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.js +3 -3
- package/dist/packem_chunks/index.js +1 -1
- package/dist/packem_shared/createFakeJsPlugin-BmWTsDfe.js +3 -0
- package/dist/packem_shared/{createGeneratePlugin-1cL4kLNk.js → createGeneratePlugin-B0-c7yPx.js} +1 -1
- package/dist/packem_shared/generate-JArF6z_0.js +9 -0
- package/dist/packem_shared/resolveOptions-xvkhsYiy.js +1 -0
- package/package.json +4 -4
- package/dist/packem_shared/createFakeJsPlugin-BVCg2c5s.js +0 -3
- package/dist/packem_shared/generate-Dy7UEhz1.js +0 -9
- package/dist/packem_shared/resolveOptions-Dh02RM2W.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## @visulima/rollup-plugin-dts [1.0.0-alpha.29](https://github.com/visulima/packem/compare/@visulima/rollup-plugin-dts@1.0.0-alpha.28...@visulima/rollup-plugin-dts@1.0.0-alpha.29) (2026-06-02)
|
|
2
|
+
|
|
3
|
+
## @visulima/rollup-plugin-dts [1.0.0-alpha.28](https://github.com/visulima/packem/compare/@visulima/rollup-plugin-dts@1.0.0-alpha.27...@visulima/rollup-plugin-dts@1.0.0-alpha.28) (2026-06-01)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* **rollup-plugin-dts:** port missing features from rolldown-plugin-dts (≤ v0.25.2) ([f5185a4](https://github.com/visulima/packem/commit/f5185a4cb6f13ef8612cbcf3b520be66a25d144e)), closes [#242](https://github.com/visulima/packem/issues/242) [#243](https://github.com/visulima/packem/issues/243) [#246](https://github.com/visulima/packem/issues/246)
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **rollup-plugin-dts:** address code-review findings on the dts feature port ([64e4dab](https://github.com/visulima/packem/commit/64e4dabefba939d6a16067e4e3706ff7e5790373))
|
|
12
|
+
* **rollup-plugin-dts:** resolve remaining review findings ([7b60046](https://github.com/visulima/packem/commit/7b600469721655181677157e2c81d89910d7fb0a))
|
|
13
|
+
|
|
14
|
+
### Miscellaneous Chores
|
|
15
|
+
|
|
16
|
+
* **benchmarks:** port build-tool benchmark suite onto the 2.0 codebase ([#201](https://github.com/visulima/packem/issues/201)) ([8abdf09](https://github.com/visulima/packem/commit/8abdf0938bb7c5b2b7baabbb6d2698c73dba5d55))
|
|
17
|
+
|
|
1
18
|
## @visulima/rollup-plugin-dts [1.0.0-alpha.27](https://github.com/visulima/packem/compare/@visulima/rollup-plugin-dts@1.0.0-alpha.26...@visulima/rollup-plugin-dts@1.0.0-alpha.27) (2026-05-28)
|
|
2
19
|
|
|
3
20
|
### Features
|
package/dist/index.d.ts
CHANGED
|
@@ -5,12 +5,17 @@ import { IsolatedDeclarationsOptions } from 'oxc-transform';
|
|
|
5
5
|
import 'estree';
|
|
6
6
|
type AddonFunction = (chunk: RenderedChunk) => string | Promise<string>;
|
|
7
7
|
type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | undefined;
|
|
8
|
+
interface TsgoOptions {
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
path?: string;
|
|
11
|
+
}
|
|
8
12
|
interface GeneralOptions {
|
|
9
13
|
cjsDefault?: boolean;
|
|
10
14
|
compilerOptions?: TsConfigJson.CompilerOptions;
|
|
11
15
|
cwd?: string;
|
|
12
16
|
dtsInput?: boolean;
|
|
13
17
|
emitDtsOnly?: boolean;
|
|
18
|
+
entry?: string | string[];
|
|
14
19
|
exclude?: FilterPattern;
|
|
15
20
|
include?: FilterPattern;
|
|
16
21
|
resolve?: boolean | (string | RegExp)[];
|
|
@@ -34,13 +39,12 @@ interface TscOptions {
|
|
|
34
39
|
}
|
|
35
40
|
interface Options extends GeneralOptions, TscOptions {
|
|
36
41
|
oxc?: boolean | Omit<IsolatedDeclarationsOptions, "sourcemap">;
|
|
37
|
-
tsgo?: boolean |
|
|
38
|
-
path?: string;
|
|
39
|
-
};
|
|
42
|
+
tsgo?: boolean | TsgoOptions;
|
|
40
43
|
}
|
|
41
44
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
42
45
|
type MarkPartial<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
|
|
43
46
|
type OptionsResolved = Overwrite<MarkPartial<Omit<Options, "compilerOptions">, "banner" | "footer">, {
|
|
47
|
+
entry?: string[];
|
|
44
48
|
exclude: FilterPattern;
|
|
45
49
|
include: FilterPattern;
|
|
46
50
|
oxc: IsolatedDeclarationsOptions | false;
|
|
@@ -60,6 +64,7 @@ declare const resolveOptions: ({
|
|
|
60
64
|
eager,
|
|
61
65
|
emitDtsOnly,
|
|
62
66
|
emitJs: emitJsOption,
|
|
67
|
+
entry,
|
|
63
68
|
exclude,
|
|
64
69
|
footer,
|
|
65
70
|
include,
|
|
@@ -88,6 +93,7 @@ declare const createGeneratePlugin: ({
|
|
|
88
93
|
eager,
|
|
89
94
|
emitDtsOnly,
|
|
90
95
|
emitJs,
|
|
96
|
+
entry,
|
|
91
97
|
exclude,
|
|
92
98
|
include,
|
|
93
99
|
incremental,
|
|
@@ -100,6 +106,6 @@ declare const createGeneratePlugin: ({
|
|
|
100
106
|
tsgo,
|
|
101
107
|
tsMacro,
|
|
102
108
|
vue
|
|
103
|
-
}: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "tsMacro" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap" | "include" | "exclude">) => Plugin;
|
|
109
|
+
}: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "tsMacro" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap" | "include" | "exclude" | "entry">) => Plugin;
|
|
104
110
|
declare const dts: (options?: Options) => Plugin[];
|
|
105
111
|
export { type FilterPattern, type Options, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)}if(e){const
|
|
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-BmWTsDfe.js";import{c as z}from"./packem_shared/generate-JArF6z_0.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=>({treeshake:n.treeshake===!1?!1:{...typeof n.treeshake=="object"?n.treeshake:{},moduleSideEffects:!1},...n}),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 +1 @@
|
|
|
1
|
-
var q=Object.defineProperty;var h=(e,t)=>q(e,"name",{value:t,configurable:!0});import{createDebug as P}from"obug";import u from"typescript";import{g as F}from"../packem_shared/generate-
|
|
1
|
+
var q=Object.defineProperty;var h=(e,t)=>q(e,"name",{value:t,configurable:!0});import{createDebug as P}from"obug";import u from"typescript";import{g as F}from"../packem_shared/generate-JArF6z_0.js";import{posix as w}from"node:path";import{pathToFileURL as j}from"node:url";import{dirname as N}from"@visulima/path";var T=Object.defineProperty,S=h((e,t)=>T(e,"name",{value:t,configurable:!0}),"i");const U=P("rollup-plugin-dts:tsc-system"),x=S(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){U(t)},writeFile(t,r,...o){e.set(t,r),u.sys.writeFile(t,r,...o)}}),"createFsSystem"),B=S(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 W=$(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:[W]},R=$((e,t,r)=>{if(!e||e.sourceRoot)return;const o=w.dirname(j(t).pathname),s=w.dirname(j(r).pathname);o!==s&&(e.sourceRoot=w.relative(s,o))},"setSourceMapRoot");var z=Object.defineProperty,m=h((e,t)=>z(e,"name",{value:t,configurable:!0}),"f$1");const g=P("rollup-plugin-dts:tsc-build"),H=m((e,t,r,o,s)=>{let i=e.projects.get(r);return i?(g(`skip building projects for ${r}`),i):(i=G(t,r,o,s),e.projects.set(r,i),i)},"getOrBuildProjects"),G=m((e,t,r,o)=>{g(`start building projects for ${t}`);const s=V(t,e,r,o);g("collected %d projects: %j",s.length,s.map(n=>n.tsconfigPath));const i=u.createSolutionBuilderHost(e,I),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"),V=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=A(a,t);if(n){n.options=D(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"),A=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"),D=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"),I=m((e,t,...r)=>u.createEmitAndSemanticDiagnosticsBuilderProgram(e,D(t??{},null),...r),"createProgramWithPatchedCompilerOptions"),L=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:B)(t.files),a=l.resolvePath(r);a!==r&&g(`resolved id from ${r} to ${a}`);const n=H(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),R(y,d,a)}}return v?{code:v,map:y}:o?(g("incremental build failed"),L({...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 K=Object.defineProperty,b=h((e,t)=>K(e,"name",{value:t,configurable:!0}),"g");const Y=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"),Q=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"),X=b((e,t)=>{const r=t.vue?Y():void 0,o=t.tsMacro?Q():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 Z=Object.defineProperty,C=h((e,t)=>Z(e,"name",{value:t,configurable:!0}),"m");const p=P("rollup-plugin-dts:tsc-compiler"),_={checkJs:!1,declaration:!0,declarationMap:!1,emitDeclarationOnly:!0,moduleResolution:u.ModuleResolutionKind.Bundler,noEmit:!1,noEmitOnError:!0,resolveJsonModule:!0,skipLibCheck:!0,target:99},ee=C(({baseDirectory:e,entries:t,fsSystem:r,id:o,parsedConfig:s,tsMacro:i,vue:l})=>{const a={..._,...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=X(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"),te=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?N(s):t,f=u.parseJsonConfigFileContent(i,n,c);return p(`Creating program for root project: ${c}`),ee({baseDirectory:c,entries:r,fsSystem:n,id:o,parsedConfig:f,tsMacro:l,vue:a})},"createTsProgram"),re=C(e=>{const{context:t=F,entries:r,id:o}=e,s=t.programs.find(l=>{const a=l.getRootFileNames();return r?r.every(n=>a.includes(n)):a.includes(o)});if(s){const l=s.getSourceFile(o);if(l)return{file:l,program:s}}p(`create program for module: ${o}`);const i=te(e);return p(`created program for module: ${o}`),t.programs.push(i.program),i},"createOrGetTsModule"),oe=C(e=>{p(`running tscEmitCompiler ${e.id}`);const t=re(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),R(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 se=Object.defineProperty,ie=h((e,t)=>se(e,"name",{value:t,configurable:!0}),"r");const k=P("rollup-plugin-dts:tsc");k(`loaded typescript: ${u.version}`);const de=ie(e=>(k(`running tscEmit ${e.id}`),e.build?L(e):oe(e)),"tscEmit");export{de as tscEmit};
|
|
@@ -0,0 +1,3 @@
|
|
|
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({declaration:null,source:null,specifiers:[],type:"ExportNamedDeclaration"});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)=>{for(const i of Object.keys(e))delete e[i];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};
|
package/dist/packem_shared/{createGeneratePlugin-1cL4kLNk.js → createGeneratePlugin-B0-c7yPx.js}
RENAMED
|
@@ -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-
|
|
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-JArF6z_0.js";export{g as createGeneratePlugin};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var pe=Object.defineProperty;var O=(a,s)=>pe(a,"name",{value:s,configurable:!0});import{spawn as de,fork as ue}from"node:child_process";import{existsSync as A,readFileSync as fe}from"node:fs";import{mkdtemp as me,readFile as Q,rm as ge}from"node:fs/promises";import d from"node:path";import{parse as te}from"@babel/parser";import{createFilter as ye}from"@rollup/pluginutils";import{createDebug as J}from"obug";import{transformSync as he,isolatedDeclarationSync as ve}from"oxc-transform";import{RE_DTS as m,RE_NODE_MODULES as C,RE_JS as _,filenameToDts as X,RE_JSON as Y,RE_TS as Z,RE_VUE as P,resolveTemplateFunction as xe,replaceTemplateName as T,RE_DTS_MAP as ee}from"../filename.js";import{resolve as we}from"@visulima/path";import{createRequire as Ee}from"node:module";import{tmpdir as be}from"node:os";var _e=Object.defineProperty,re=O((a,s)=>_e(a,"name",{value:s,configurable:!0}),"o");const $e=J("rollup-plugin-dts:tsc-context"),oe=re(()=>({files:new Map,programs:[],projects:new Map}),"createContext"),Me=re((a,s)=>{const p=we(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"),Se=oe();var je=Object.defineProperty,I=O((a,s)=>je(a,"name",{value:s,configurable:!0}),"n");const $=J("rollup-plugin-dts:tsgo"),ke=I(async(...a)=>{await new Promise((s,p)=>{const n=de(...a);n.on("close",()=>{s()}),n.on("error",i=>{p(i)})})},"spawnAsync"),Oe=I(()=>{const a=Ee(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=I(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 x=await me(d.join(be(),"rollup-plugin-dts-"));$("[tsgo] tsgoDist",x);const w=["--noEmit","false","--declaration","--emitDeclarationOnly",...s?["-p",s]:[],"--outDir",x,"--rootDir",a,"--noCheck",...p?["--declarationMap"]:[]];return $("[tsgo] args %o",w),await ke(i,w,{stdio:"inherit"}),x},"runTsgo");var Re=Object.defineProperty,M=O((a,s)=>Re(a,"name",{value:s,configurable:!0}),"x");const h=J("rollup-plugin-dts:generate"),Fe=import.meta.WORKER_URL??"./tsc/worker.js",ze=M(({build:a,cwd:s,eager:p,emitDtsOnly:n,emitJs:i,entry:x,exclude:w,include:U,incremental:se,newContext:W,oxc:D,parallel:G,sourcemap:R,tsconfig:S,tsconfigRaw:ie,tsgo:F,tsMacro:ne,vue:ae})=>{const L=U||w?ye(U,w):null,le=x?.filter(o=>o[0]!=="!"),ce=x?.filter(o=>o[0]==="!").map(o=>o.slice(1)),B=x?o=>{const e=o.split(d.sep).join("/");return le.some(r=>d.posix.matchesGlob(e,r))&&!ce.some(r=>d.posix.matchesGlob(e,r))}:void 0,v=new Map,V=new Map;let j,K,N,k,E;const q=S?d.dirname(S):s;return{async buildEnd(){j?.kill(),!h.enabled&&E&&await ge(E,{force:!0,recursive:!0}).catch(()=>{}),E=void 0,W&&(k=void 0)},async buildStart(o){if(F?E=await De(q,S,R,F.path):D||(G?(j=ue(new URL(Fe,import.meta.url),{stdio:"inherit"}),K=(await import("birpc")).createBirpc({},{on:M(e=>j.on("message",e),"on"),post:M(e=>j.send(e),"post")})):(N=await import("../packem_chunks/index.js"),W&&(k=oe()))),!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),V.set(c,e)}},generateBundle(o,e){for(const r of Object.keys(e)){const t=e[r];if(t){if(t.type==="asset"&&ee.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"&&!m.test(r)&&!ee.test(r)&&delete e[r]}}},load:{filter:{id:{exclude:[C],include:[m]}},async handler(o){if(!v.has(o))return;const{code:e,id:r}=v.get(o);let t,c;if(h("generate dts %s from %s",o,r),F){if(P.test(r))throw new Error("tsgo does not support Vue files.");const l=d.resolve(E,d.relative(q,X(r)));if(A(l)){if(t=await Q(l,"utf8"),R){const u=`${l}.map`;if(A(u)){const f=JSON.parse(await Q(u,"utf8"));if(Array.isArray(f.sources)){const g=d.dirname(u);f.sources=f.sources.map(y=>y==null?y:d.resolve(g,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(D&&!P.test(r)){const l=ve(r,e,D);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&&(c=l.map,c.sourcesContent=void 0,c.names=[])}else{const l=p?void 0:[...v.values()].filter(g=>g.isEntry).map(g=>g.id),u={build:a,context:k,cwd:s,entries:l,id:r,incremental:se,sourcemap:R,tsconfig:S,tsconfigRaw:ie,tsMacro:ne,vue:ae};let f;if(f=G?await K.tscEmit(u):N.tscEmit(u),f.error)return this.error(f.error);if(t=f.code,c=f.map,t&&Y.test(r))if(t.includes("declare const _exports")){if(t.includes("declare const _exports: {")&&!t.includes(`
|
|
3
|
+
}[];`)){const g=Ae(t);let y=0;t+=g.map(b=>{const z=`_${b.replaceAll(/[^\w$]/g,"_")}${y++}`,H=JSON.stringify(b);return`declare let ${z}: typeof _exports[${H}]
|
|
4
|
+
export { ${z} as ${H} }`}).join(`
|
|
5
|
+
`)}}else{const g=Ne(t);t+=`
|
|
6
|
+
declare namespace __json_default_export {
|
|
7
|
+
export { ${Array.from(g.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=xe(r||"[name].js",e);if(e.name.endsWith(".d")){if(m.test(t))return T(t,e.name.slice(0,-2));if(_.test(t))return t.replace(_,".$1ts")}else if(n){if(e.facadeModuleId&&m.test(e.facadeModuleId)){if(m.test(t))return T(t,e.name);if(_.test(t))return t.replace(_,".$1ts")}return T("[name].js",e.name)}return t}}},async resolveId(o,e){if(v.has(o))return h("resolve dts id %s",o),{id:o};if(!e&&m.test(o)&&!C.test(o)){const r=d.isAbsolute(o)?o:d.resolve(s,o),t=r.replace(m,""),c=[r.replace(m,".$1ts"),`${t}.tsx`,`${t}.ts`,`${t}.mts`,`${t}.cts`];if(!v.has(r)){for(const l of c)if(A(l)){const u=fe(l,"utf8");v.set(r,{code:u,id:l,isEntry:!0}),h("populated dtsMap from source for cached re-resolution: %s (via %s)",r,l);break}}return v.has(r)?(h("resolve dts id %s (from cache re-resolution)",r),{id:r}):null}if(e&&Z.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 m.test(o)},transform:{handler(o,e){if(!(m.test(e)||C.test(e)||L&&!L(e))){if(!_.test(e)||i){const r=!!this.getModuleInfo(e)?.isEntry,t=B?r&&B(d.relative(s,e)):r,c=X(e);if(v.set(c,{code:o,id:e,isEntry:t}),h("register dts source: %s",e),t){const l=V.get(e);this.emitFile({id:c,name:l?`${l}.d`:void 0,type:"chunk"})}}return n?Y.test(e)?"{}":"export { }":Z.test(e)||P.test(e)?he(e,o,{}).code:null}},order:"pre"},watchChange(o){N&&Me(k||Se,o)}}},"createGeneratePlugin"),Ne=M(a=>{const s=new Map,{program:p}=te(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"),Ae=M(a=>{const s=[],{program:p}=te(a,{plugins:[["typescript",{dts:!0}]],sourceType:"module"}),n=p.body[0].declarations[0].id.typeAnnotation.typeAnnotation.members;for(const i of n)i.key.type==="Identifier"?s.push(i.key.name):i.key.type==="StringLiteral"&&s.push(i.key.value);return s},"collectJsonExports");export{ze as c,Se as g};
|
|
@@ -0,0 +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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/rollup-plugin-dts",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.29",
|
|
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": {
|
|
@@ -56,14 +56,14 @@
|
|
|
56
56
|
"@babel/helper-validator-identifier": "7.29.7",
|
|
57
57
|
"@babel/parser": "7.29.7",
|
|
58
58
|
"@babel/types": "7.29.7",
|
|
59
|
-
"@rollup/pluginutils": "5.
|
|
59
|
+
"@rollup/pluginutils": "5.4.0",
|
|
60
60
|
"@visulima/path": "3.0.0-alpha.10",
|
|
61
61
|
"@visulima/tsconfig": "3.0.0-alpha.24",
|
|
62
62
|
"ast-kit": "^2.2.0",
|
|
63
63
|
"birpc": "^4.0.0",
|
|
64
64
|
"magic-string": "0.30.21",
|
|
65
65
|
"obug": "2.1.1",
|
|
66
|
-
"oxc-resolver": "11.
|
|
66
|
+
"oxc-resolver": "11.20.0",
|
|
67
67
|
"oxc-transform": "0.133.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@typescript/native-preview": ">=7.0.0-dev.20250601.1",
|
|
72
72
|
"rollup": ">=4.60.4",
|
|
73
73
|
"typescript": "^6.0.3",
|
|
74
|
-
"vue-tsc": "3.3.
|
|
74
|
+
"vue-tsc": "3.3.3"
|
|
75
75
|
},
|
|
76
76
|
"peerDependenciesMeta": {
|
|
77
77
|
"@typescript/native-preview": {
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var Ee=Object.defineProperty;var w=(e,a)=>Ee(e,"name",{value:a,configurable:!0});import ne from"node:path";import{generate as ae}from"@babel/generator";import{isIdentifierName as be}from"@babel/helper-validator-identifier";import{parse as se}from"@babel/parser";import f from"@babel/types";import{isTypeOf as $,isDeclarationType as Se,walkAST as K,resolveString as H,isIdentifierOf as Z}from"ast-kit";import{RE_DTS as j,resolveTemplateFunction as De,filenameJsToDts as oe,replaceTemplateName as le,filenameDtsTo as ce,RE_DTS_MAP as Te,filenameToDts as ve}from"../filename.js";var Ie=Object.defineProperty,S=w((e,a)=>Ie(e,"name",{value:a,configurable:!0}),"c");const z="__rollup_dts_resolve__:",Qe=S(({cjsDefault:e,sideEffects:a,sourcemap:b})=>{let t=0;const M=new Map,O=new Map,V=new Map;return{generateBundle(p,s){const u=new Map;for(const i of Object.values(s))if(i.type==="chunk")for(const y of i.moduleIds)u.set(y,i.fileName);const d=new RegExp(`"${z}(.+?)"`,"g");for(const i of Object.values(s))i.type!=="chunk"||!j.test(i.fileName)||i.code.includes(z)&&(i.code=i.code.replaceAll(d,(y,C)=>{const h=u.get(C);if(!h)return y;let T=ne.posix.relative(ne.posix.dirname(i.fileName),h);return T.startsWith(".")||(T=`./${T}`),T=ce(T,"js"),JSON.stringify(T)}));for(const i of Object.values(s))if(Te.test(i.fileName))if(b){if(i.type==="chunk"||typeof i.source!="string")continue;const y=JSON.parse(i.source);y.sourcesContent=void 0,i.source=JSON.stringify(y)}else delete s[i.fileName]},name:"rollup-plugin-dts:fake-js",outputOptions(p){const{chunkFileNames:s,entryFileNames:u}=p;return(p.format==="cjs"||p.format==="commonjs")&&(p={...p,format:"es"}),{...p,chunkFileNames(d){const i=De(d.isEntry?u||"[name].js":s||"[name]-[hash].js",d);if(d.name.endsWith(".d")){const y=oe(le(i,d.name.slice(0,-2)));if(j.test(y))return y;const C=oe(le(i,d.name));if(j.test(C))return C}return i},sourcemap:p.sourcemap||b}},renderChunk:A,async transform(p,s){if(j.test(s))return B.call(this,p,s)}};async function B(p,s){const u=Object.create(null);let d;try{d=se(p,{createParenthesizedExpressions:!0,errorRecovery:!0,plugins:[["typescript",{dts:!0}],"decoratorAutoAccessors"],sourceType:"module"})}catch(x){throw new Error(`Failed to parse ${s}. 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:i,program:y}=d,C=[];if(i){const x=fe(i);O.set(s,x)}const h=[],T=new Map,n=new Map,r=new Set;for(const[x,o]of y.body.entries()){const _=S(c=>y.body[x]=c,"setStmt");if(Ae(o,_,C))continue;if(o.type==="TSNamespaceExportDeclaration"){r.add(x);continue}const k=o.type==="TSModuleDeclaration"&&o.kind!=="namespace";let g;if(k&&o.id.type==="StringLiteral"){const c=await this.resolve(o.id.value,s);c&&!c.external?g=j.test(c.id)?c.id:ve(c.id):o.id.value[0]==="."&&this.warn(`\`declare module ${JSON.stringify(o.id.value)}\` will be kept as-is in the output. Relative module declaration may cause unexpected issues. Found in ${s}.`)}if(k&&s.endsWith(".vue.d.ts")&&p.slice(o.start,o.end).includes("__VLS_"))continue;const U=o.type==="ExportDefaultDeclaration",L=$(o,["ExportNamedDeclaration","ExportDefaultDeclaration"])&&o.declaration,v=L?o.declaration:o,W=L?c=>o.declaration=c:_;if(v.type!=="TSDeclareFunction"&&!Se(v))continue;$(v,["TSEnumDeclaration","ClassDeclaration","FunctionDeclaration","TSDeclareFunction","TSModuleDeclaration","VariableDeclaration"])&&(v.declare=!0);const I=[];if(v.type==="VariableDeclaration")I.push(...v.declarations.map(c=>c.id));else if("id"in v&&v.id){let c=v.id;c.type==="TSQualifiedName"&&(c=X(c)),c=k&&c.type!=="Identifier"?f.identifier(`_${J(u,"")}`):c,I.push(c)}else{const c=f.identifier("export_default");I.push(c),v.id=c}const P=me(v),l=new Set,E=he(v,T,l,u),m=[...l].filter(c=>I.every(N=>c!==N));if(v!==o&&(v.leadingComments=o.leadingComments),I.length===1&&n.has(I[0].name)){const c=n.get(I[0].name),N=Y(c);N.overloads||(N.overloads=[],N.primaryDepsCount=N.deps.length,N.primaryParamsCount=N.params.length,N.primaryChildrenCount=N.children.length),N.overloads.push({children:m,childrenOffset:N.children.length,decl:v,deps:E,depsOffset:N.deps.length,params:P,paramsOffset:N.params.length}),N.deps.push(...E),N.params.push(...P),N.children.push(...m),r.add(x);continue}const D=q({bindings:I,children:m,decl:v,deps:E,params:P,resolvedModuleId:g});I.length===1&&n.set(I[0].name,D);const Q=f.numericLiteral(D),ee=f.arrowFunctionExpression(P.map(({name:c})=>f.identifier(c)),f.arrayExpression(E)),te=f.arrayExpression(m.map(c=>({end:c.end,loc:c.loc,start:c.start,type:"StringLiteral",value:""}))),re=k&&f.callExpression(f.identifier("sideEffect"),[I[0]]),ge=Me(re?[Q,ee,te,re]:[Q,ee,te]),ie={declarations:[{id:{...I[0],typeAnnotation:null},init:ge,type:"VariableDeclarator"},...I.slice(1).map(c=>({id:{...c,typeAnnotation:null},type:"VariableDeclarator"}))],kind:"var",type:"VariableDeclaration"};U?(h.push(f.exportNamedDeclaration(null,[f.exportSpecifier(I[0],f.identifier("default"))])),_(ie)):W(ie)}return a&&h.push(f.expressionStatement(f.callExpression(f.identifier("sideEffect"),[]))),y.body=[...Array.from(T.values(),({stmt:x})=>x),...y.body.filter((x,o)=>!r.has(o)),...h],V.set(s,C),ae(d,{comments:!1,sourceFileName:s,sourceMaps:b})}function A(p,s){if(!j.test(s.fileName))return;const u=[];for(const n of s.moduleIds){const r=V.get(n);r&&u.push(...r)}let d;try{d=se(p,{sourceType:"module"})}catch(n){throw new Error(`Failed to parse generated code for chunk ${s.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:i}=d;if(i.body=Pe(i.body),i.body=je(i.body),i.body=i.body.flatMap(n=>{if(_e(n))return[];if(n.type==="ExpressionStatement")return[];const r=ke(n,u,e);if(r===!1)return[];if(r)return[r];if(n.type!=="VariableDeclaration")return[n];if(!Ce(n))return[];const[x,o,_]=n.declarations[0].init.elements,k=x.value,g=Y(k);K(g.decl,{enter(l){l.type!=="CommentBlock"&&(l.leadingComments?.length||delete l.loc)}});for(const[l,E]of n.declarations.entries()){const m={...E.id,typeAnnotation:g.bindings[l].typeAnnotation};R(g.bindings[l],m)}const U=g.primaryChildrenCount??g.children.length,L=g.primaryParamsCount??g.params.length,v=g.primaryDepsCount??g.deps.length;for(let l=0;l<U;l++){const E=_.elements[l];Object.assign(g.children[l],{loc:E.loc})}const W=o.params;for(let l=0;l<L;l++){const E=W[l].name;for(const m of g.params[l].typeParams)m.name=E}const I=o.body.elements;for(let l=0;l<v;l++){const E=g.deps[l];let m=I[l];m&&m.type==="UnaryExpression"&&m.operator==="void"?m={...f.identifier("undefined"),end:m.end,loc:m.loc,start:m.start}:G(m)&&(m.name="__Infer"),E.replace?E.replace(m):Object.assign(E,m)}g.decl.type==="TSModuleDeclaration"&&g.resolvedModuleId&&(g.decl.id.value=z+g.resolvedModuleId);const P=[];if(g.overloads)for(const l of g.overloads){K(l.decl,{enter(E){E.type!=="CommentBlock"&&delete E.loc}}),"id"in l.decl&&l.decl.id&&R(l.decl.id,{...g.bindings[0]});for(const[E,m]of l.children.entries()){const D=_.elements[l.childrenOffset+E];D&&Object.assign(m,{loc:D.loc})}for(const[E,m]of l.params.entries()){const D=W[l.paramsOffset+E];if(D)for(const Q of m.typeParams)Q.name=D.name}for(const[E,m]of l.deps.entries()){let D=I[l.depsOffset+E];D&&(D.type==="UnaryExpression"&&D.operator==="void"?D={...f.identifier("undefined"),end:D.end,loc:D.loc,start:D.start}:G(D)&&(D.name="__Infer"),m.replace?m.replace(D):Object.assign(m,D))}P.push(l.decl)}return[Re(n,g.decl),...P]}).filter(n=>!!n),i.body.length===0)return"export { };";const y=i.body.some(n=>n.type==="ExportNamedDeclaration"||n.type==="ExportDefaultDeclaration"||n.type==="ExportAllDeclaration"),C=i.body.some(n=>n.type==="TSModuleDeclaration"&&n.id.type==="StringLiteral");!y&&C&&i.body.push({declaration:null,source:null,specifiers:[],type:"ExportNamedDeclaration"});const h=new Set,T=new Set;for(const n of s.moduleIds){const r=O.get(n);r&&(r.forEach(x=>{const o=x.type+x.value;T.has(o)||(T.add(o),h.add(x))}),O.delete(n))}return h.size>0&&(i.body[0].leadingComments||=[],i.body[0].leadingComments.unshift(...h)),ae(d,{comments:!0,sourceFileName:s.fileName,sourceMaps:b})}function J(p,s){return s in p?p[s]++:p[s]=0}function q(p){const s=t++;return M.set(s,p),s}function Y(p){return M.get(p)}function me(p){const s=[];K(p,{leave(d){"typeParameters"in d&&d.typeParameters?.type==="TSTypeParameterDeclaration"&&s.push(...d.typeParameters.params)}});const u=new Map;for(const d of s){const{name:i}=d,y=u.get(i);y?y.push(d):u.set(i,[d])}return Array.from(u.entries(),([d,i])=>({name:d,typeParams:i}))}function ye(p){const s=[];return K(p,{enter(u){u.type==="TSInferType"&&u.typeParameter&&s.push(u.typeParameter.name)}}),s}function he(p,s,u,d){const i=new Set,y=new Set,C=[];let h=new Set;function T(r){return r.type==="Identifier"&&h.has(r.name)}return w(T,"b"),S(T,"isInferred"),K(p,{enter(r){if(r.type==="TSConditionalType"){const x=ye(r.extendsType);C.push(x)}},leave(r,x){if(r.type==="TSConditionalType")C.pop();else if(x?.type==="TSConditionalType"){const o=x.trueType===r;h=new Set((o?C:C.slice(0,-1)).flat())}else h=new Set;if(r.type==="ExportNamedDeclaration")for(const o of r.specifiers)o.type==="ExportSpecifier"&&n(o.local);else if(r.type==="TSInterfaceDeclaration"&&r.extends)for(const o of r.extends||[])n(F(o.expression));else if(r.type==="ClassDeclaration"){if(r.superClass&&n(r.superClass),r.implements)for(const o of r.implements)o.type!=="ClassImplements"&&n(F(o.expression))}else if($(r,["ObjectMethod","ObjectProperty","ClassProperty","TSPropertySignature","TSDeclareMethod"]))r.computed&&pe(r.key)&&n(r.key),"value"in r&&pe(r.value)&&n(r.value);else switch(r.type){case"TSImportType":{y.add(r);const o=r.argument,_=r.qualifier,k=xe(r,_,o,s,d);n(k);break}case"TSTypeQuery":{if(y.has(r.exprName))return;if(r.exprName.type==="TSImportType")break;n(F(r.exprName));break}case"TSTypeReference":{n(F(r.typeName));break}}x&&!i.has(r)&&de(r,x)&&u.add(r)}}),[...i];function n(r){ue(r)||T(r)||i.add(r)}w(n,"R")}function xe(p,s,u,d,i){const y=u.value.replaceAll(/\W/g,"_"),C=`_$${be(u.value)?u.value:`${y}${J(i,y)}`}`;let h=f.identifier(C);if(d.has(u.value)?h=d.get(u.value).local:d.set(u.value,{local:h,stmt:f.importDeclaration([f.importNamespaceSpecifier(h)],u)}),s){const n=X(s);R(n,f.tsQualifiedName(h,{...n})),h=s}let T=p;return p.typeParameters?(R(p,f.tsTypeReference(h,p.typeParameters)),T=h):R(p,h),{...F(h),replace(n){R(T,n)}}}},"createFakeJsPlugin");function de(e,a){return!!(e.type==="Identifier"||$(a,["TSPropertySignature","TSMethodSignature"])&&a.key===e)}w(de,"Ie");S(de,"isChildSymbol");const Ne=/\/\s*<reference\s+(?:path|types)=/,fe=S((e,a=!1)=>e.filter(b=>Ne.test(b.value)!==a),"collectReferenceDirectives"),Ce=S(e=>f.isVariableDeclaration(e)&&e.declarations.length>0&&f.isVariableDeclarator(e.declarations[0])&&we(e.declarations[0].init),"isRuntimeBindingVariableDeclaration"),we=S(e=>f.isArrayExpression(e)&&Oe(e.elements),"isRuntimeBindingArrayExpression"),Me=S(e=>f.arrayExpression(e),"runtimeBindingArrayExpression"),Oe=S(e=>{const[a,b,t,M]=e;return a?.type==="NumericLiteral"&&b?.type==="ArrowFunctionExpression"&&t?.type==="ArrayExpression"&&(!M||M.type==="CallExpression")},"isRuntimeBindingArrayElements"),G=S(e=>Z(e,"infer"),"isInfer"),ue=S(e=>Z(e,"this")||e.type==="ThisExpression"||e.type==="MemberExpression"&&ue(e.object),"isThisExpression"),F=S(e=>{if(e.type==="Identifier")return e;const a=F(e.left);return Object.assign(e,f.memberExpression(a,e.right))},"TSEntityNameToRuntime"),X=S(e=>e.type==="Identifier"?e:X(e.left),"getIdFromTSEntityName"),pe=S(e=>$(e,["Identifier","MemberExpression"]),"isReferenceId"),_e=S(e=>e.type==="ImportDeclaration"&&e.specifiers.length===1&&e.specifiers.every(a=>a.type==="ImportSpecifier"&&a.imported.type==="Identifier"&&["__export","__reExport"].includes(a.local.name)),"isHelperImport"),ke=S((e,a,b)=>{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 t of e.specifiers)G(t.local)&&(t.local.name="__Infer");if($(e,["ImportDeclaration","ExportAllDeclaration","ExportNamedDeclaration"])){if(e.type==="ExportNamedDeclaration"&&a.length>0)for(const t of e.specifiers){const M=H(t.exported);a.includes(M)&&(t.type==="ExportSpecifier"?t.exportKind="type":e.exportKind="type")}if(e.source?.value&&j.test(e.source.value))return e.source.value=ce(e.source.value,"js"),e;if(b&&e.type==="ExportNamedDeclaration"&&!e.source&&e.specifiers.length===1&&e.specifiers[0].type==="ExportSpecifier"&&H(e.specifiers[0].exported)==="default")return{expression:e.specifiers[0].local,type:"TSExportAssignment"}}},"patchImportExport"),Pe=S(e=>{const a=new Set;for(const[t,M]of e.entries()){const O=b(M);if(!O)continue;const[V,B]=O;B.properties.length!==0&&(e[t]={body:{body:[{declaration:null,source:null,specifiers:B.properties.filter(A=>A.type==="ObjectProperty").map(A=>{const J=A.value.body,q=A.key;return f.exportSpecifier(J,q)}),type:"ExportNamedDeclaration"}],type:"TSModuleBlock"},declare:!0,id:V,kind:"namespace",type:"TSModuleDeclaration"})}return e.filter(t=>!a.has(t));function b(t){if(t.type!=="VariableDeclaration"||t.declarations.length!==1||t.declarations[0].id.type!=="Identifier"||t.declarations[0].init?.type!=="CallExpression"||t.declarations[0].init.callee.type!=="Identifier"||t.declarations[0].init.callee.name!=="__export"||t.declarations[0].init.arguments.length!==1||t.declarations[0].init.arguments[0].type!=="ObjectExpression")return!1;const M=t.declarations[0].id,O=t.declarations[0].init.arguments[0];return[M,O]}},"patchTsNamespace"),je=S(e=>{const a=new Map;for(const[b,t]of e.entries())if(t.type==="ImportDeclaration"&&t.specifiers.length===1&&t.specifiers[0].type==="ImportSpecifier"&&t.specifiers[0].local.type==="Identifier"&&t.specifiers[0].local.name.endsWith("_exports"))a.set(t.specifiers[0].local.name,t.specifiers[0].local.name);else if(t.type==="ExpressionStatement"&&t.expression.type==="CallExpression"&&Z(t.expression.callee,"__reExport")){const M=t.expression.arguments;a.set(M[0].name,M[1].name)}else t.type==="VariableDeclaration"&&t.declarations.length===1&&t.declarations[0].init?.type==="MemberExpression"&&t.declarations[0].init.object.type==="Identifier"&&a.has(t.declarations[0].init.object.name)?e[b]={id:{name:t.declarations[0].id.name,type:"Identifier"},type:"TSTypeAliasDeclaration",typeAnnotation:{type:"TSTypeReference",typeName:{left:{name:a.get(t.declarations[0].init.object.name),type:"Identifier"},right:{name:t.declarations[0].init.property.name,type:"Identifier"},type:"TSQualifiedName"}}}:t.type==="ExportNamedDeclaration"&&t.specifiers.length===1&&t.specifiers[0].type==="ExportSpecifier"&&t.specifiers[0].local.type==="Identifier"&&a.has(t.specifiers[0].local.name)&&(t.specifiers[0].local.name=a.get(t.specifiers[0].local.name));return e},"patchReExport"),Ae=S((e,a,b)=>{if(e.type==="ImportDeclaration"||e.type==="ExportNamedDeclaration"&&!e.declaration){for(const t of e.specifiers)("exportKind"in t&&t.exportKind==="type"||"exportKind"in e&&e.exportKind==="type")&&b.push(H(t.exported)),t.type==="ImportSpecifier"?t.importKind="value":t.type==="ExportSpecifier"&&(t.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"&&a({source:e.moduleReference.expression,specifiers:[{local:e.id,type:"ImportDefaultSpecifier"}],type:"ImportDeclaration"}),!0):e.type==="TSExportAssignment"&&e.expression.type==="Identifier"?(a({specifiers:[{exported:{name:"default",type:"Identifier"},local:e.expression,type:"ExportSpecifier"}],type:"ExportNamedDeclaration"}),!0):e.type==="ExportDefaultDeclaration"&&e.declaration.type==="Identifier"?(a({specifiers:[{exported:f.identifier("default"),local:e.declaration,type:"ExportSpecifier"}],type:"ExportNamedDeclaration"}),!0):!1},"rewriteImportExport"),R=S((e,a)=>{for(const b of Object.keys(e))delete e[b];return Object.assign(e,a),e},"overwriteNode"),Re=S((e,a)=>{a.leadingComments||=[];const b=e.leadingComments?.filter(t=>t.value.startsWith("#"));return b&&a.leadingComments.unshift(...b),a.leadingComments=fe(a.leadingComments,!0),a},"inheritNodeComments");export{Qe as default};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
var ie=Object.defineProperty;var S=(a,n)=>ie(a,"name",{value:n,configurable:!0});import{spawn as ae,fork as ce}from"node:child_process";import{existsSync as N,readFileSync as le}from"node:fs";import{mkdtemp as pe,readFile as z,rm as de}from"node:fs/promises";import u from"node:path";import{parse as Z}from"@babel/parser";import{createFilter as ue}from"@rollup/pluginutils";import{createDebug as P}from"obug";import{transformSync as fe,isolatedDeclarationSync as me}from"oxc-transform";import{RE_DTS as m,RE_NODE_MODULES as A,RE_JS as _,filenameToDts as H,RE_JSON as Q,RE_TS as X,RE_VUE as C,resolveTemplateFunction as ge,replaceTemplateName as J,RE_DTS_MAP as Y}from"../filename.js";import{resolve as ye}from"@visulima/path";import{createRequire as ve}from"node:module";import{tmpdir as he}from"node:os";var we=Object.defineProperty,ee=S((a,n)=>we(a,"name",{value:n,configurable:!0}),"o");const xe=P("rollup-plugin-dts:tsc-context"),te=ee(()=>({files:new Map,programs:[],projects:new Map}),"createContext"),Ee=ee((a,n)=>{const p=ye(n).replaceAll("\\","/");xe(`invalidating context file: ${p}`),a.files.delete(p),a.programs=a.programs.filter(i=>!i.getSourceFiles().some(o=>o.fileName===p)),a.projects.clear()},"invalidateContextFile"),$e=te();var _e=Object.defineProperty,I=S((a,n)=>_e(a,"name",{value:n,configurable:!0}),"n");const M=P("rollup-plugin-dts:tsgo"),Me=I(async(...a)=>{await new Promise((n,p)=>{const i=ae(...a);i.on("close",()=>{n()}),i.on("error",o=>{p(o)})})},"spawnAsync"),be=I(()=>{const a=ve(import.meta.url),n=a.resolve("@typescript/native-preview/package.json"),p=u.dirname(n),i=a(u.join(p,"lib","getExePath.js")),o=typeof i=="function"?i:i.default;if(!o)throw new Error("Failed to resolve getExePath from @typescript/native-preview");return o()},"getTsgoPathFromNodeModules"),je=I(async(a,n,p,i)=>{M("[tsgo] rootDir",a);let o;i?(o=i,M("[tsgo] using custom path",o)):(o=be(),M("[tsgo] using tsgo from node_modules",o));const w=await pe(u.join(he(),"rollup-plugin-dts-"));M("[tsgo] tsgoDist",w);const x=["--noEmit","false","--declaration","--emitDeclarationOnly",...n?["-p",n]:[],"--outDir",w,"--rootDir",a,"--noCheck",...p?["--declarationMap"]:[]];return M("[tsgo] args %o",x),await Me(o,x,{stdio:"inherit"}),w},"runTsgo");var ke=Object.defineProperty,b=S((a,n)=>ke(a,"name",{value:n,configurable:!0}),"x");const v=P("rollup-plugin-dts:generate"),Oe=import.meta.WORKER_URL??"./tsc/worker.js",Ve=b(({build:a,cwd:n,eager:p,emitDtsOnly:i,emitJs:o,exclude:w,include:x,incremental:re,newContext:U,oxc:D,parallel:W,sourcemap:T,tsconfig:j,tsconfigRaw:oe,tsgo:R,tsMacro:se,vue:ne})=>{const L=x||w?ue(x,w):null,h=new Map,B=new Map;let k,V,F,O,E;const G=j?u.dirname(j):n;return{async buildEnd(){k?.kill(),!v.enabled&&E&&await de(E,{force:!0,recursive:!0}).catch(()=>{}),E=void 0,U&&(O=void 0)},async buildStart(s){if(R?E=await je(G,j,T,R.path):D||(W?(k=ce(new URL(Oe,import.meta.url),{stdio:"inherit"}),V=(await import("birpc")).createBirpc({},{on:b(t=>k.on("message",t),"on"),post:b(t=>k.send(t),"post")})):(F=await import("../packem_chunks/index.js"),U&&(O=te()))),!Array.isArray(s.input))for(const[t,r]of Object.entries(s.input)){v("resolving input alias %s -> %s",t,r);let e=await this.resolve(r);r.startsWith("./")||(e||=await this.resolve(`./${r}`));const c=e?.id||r;v("resolved input alias %s -> %s",r,c),B.set(c,t)}},generateBundle(s,t){for(const r of Object.keys(t)){const e=t[r];if(e){if(e.type==="asset"&&Y.test(r)&&typeof e.source=="string"){const c=JSON.parse(e.source);c.names=[],delete c.sourcesContent,e.source=JSON.stringify(c)}i&&e.type==="chunk"&&!m.test(r)&&!Y.test(r)&&delete t[r]}}},load:{filter:{id:{exclude:[A],include:[m]}},async handler(s){if(!h.has(s))return;const{code:t,id:r}=h.get(s);let e,c;if(v("generate dts %s from %s",s,r),R){if(C.test(r))throw new Error("tsgo does not support Vue files.");const l=u.resolve(E,u.relative(G,H(r)));if(N(l)){if(e=await z(l,"utf8"),T){const d=`${l}.map`;if(N(d)){const f=JSON.parse(await z(d,"utf8"));if(Array.isArray(f.sources)){const g=u.dirname(d);f.sources=f.sources.map(y=>y==null?y:u.resolve(g,y))}c=f}}}else throw v("[tsgo]",l,"is missing"),new Error(`tsgo did not generate dts file for ${r}, please check your tsconfig.`)}else if(D&&!C.test(r)){const l=me(r,t,D);if(l.errors.length>0){const[d]=l.errors;return this.error({frame:d?.codeframe||void 0,message:d?.codeframe?`${d.message}
|
|
2
|
-
${d.codeframe}`:d?.message??"Unknown error"})}e=l.code,l.map&&(c=l.map,c.sourcesContent=void 0,c.names=[])}else{const l=p?void 0:[...h.values()].filter(g=>g.isEntry).map(g=>g.id),d={build:a,context:O,cwd:n,entries:l,id:r,incremental:re,sourcemap:T,tsconfig:j,tsconfigRaw:oe,tsMacro:se,vue:ne};let f;if(f=W?await V.tscEmit(d):F.tscEmit(d),f.error)return this.error(f.error);if(e=f.code,c=f.map,e&&Q.test(r))if(e.includes("declare const _exports")){if(e.includes("declare const _exports: {")&&!e.includes(`
|
|
3
|
-
}[];`)){const g=De(e);let y=0;e+=g.map($=>{const q=`_${$.replaceAll(/[^\w$]/g,"_")}${y++}`,K=JSON.stringify($);return`declare let ${q}: typeof _exports[${K}]
|
|
4
|
-
export { ${q} as ${K} }`}).join(`
|
|
5
|
-
`)}}else{const g=Se(e);e+=`
|
|
6
|
-
declare namespace __json_default_export {
|
|
7
|
-
export { ${Array.from(g.entries(),([y,$])=>y===$?y:`${$} as ${y}`).join(", ")} }
|
|
8
|
-
}
|
|
9
|
-
export { __json_default_export as default }`}}return{code:e||"",map:c}}},name:"rollup-plugin-dts:generate",outputOptions(s){return{...s,entryFileNames(t){const{entryFileNames:r}=s,e=ge(r||"[name].js",t);if(t.name.endsWith(".d")){if(m.test(e))return J(e,t.name.slice(0,-2));if(_.test(e))return e.replace(_,".$1ts")}else if(i){if(t.facadeModuleId&&m.test(t.facadeModuleId)){if(m.test(e))return J(e,t.name);if(_.test(e))return e.replace(_,".$1ts")}return J("[name].js",t.name)}return e}}},async resolveId(s,t){if(h.has(s))return v("resolve dts id %s",s),{id:s};if(!t&&m.test(s)&&!A.test(s)){const r=u.isAbsolute(s)?s:u.resolve(n,s),e=r.replace(m,""),c=[r.replace(m,".$1ts"),`${e}.tsx`,`${e}.ts`,`${e}.mts`,`${e}.cts`];if(!h.has(r)){for(const l of c)if(N(l)){const d=le(l,"utf8");h.set(r,{code:d,id:l,isEntry:!0}),v("populated dtsMap from source for cached re-resolution: %s (via %s)",r,l);break}}return h.has(r)?(v("resolve dts id %s (from cache re-resolution)",r),{id:r}):null}if(t&&X.test(t)&&(s.startsWith("./")||s.startsWith("../"))&&!u.extname(s))for(const r of[".ts",".tsx",".mts",".cts"]){const e=await this.resolve(s+r,t,{skipSelf:!0});if(e)return e}return null},shouldTransformCachedModule({id:s}){return m.test(s)},transform:{handler(s,t){if(!(m.test(t)||A.test(t)||L&&!L(t))){if(!_.test(t)||o){const r=!!this.getModuleInfo(t)?.isEntry,e=H(t);if(h.set(e,{code:s,id:t,isEntry:r}),v("register dts source: %s",t),r){const c=B.get(t);this.emitFile({id:e,name:c?`${c}.d`:void 0,type:"chunk"})}}return i?Q.test(t)?"{}":"export { }":X.test(t)||C.test(t)?fe(t,s,{}).code:null}},order:"pre"},watchChange(s){F&&Ee(O||$e,s)}}},"createGeneratePlugin"),Se=b(a=>{const n=new Map,{program:p}=Z(a,{errorRecovery:!0,plugins:[["typescript",{dts:!0}]],sourceType:"module"});for(const i of p.body)if(i.type==="ExportNamedDeclaration"){if(i.declaration)if(i.declaration.type==="VariableDeclaration")for(const o of i.declaration.declarations)o.id.type==="Identifier"&&n.set(o.id.name,o.id.name);else i.declaration.type==="TSModuleDeclaration"&&i.declaration.id.type==="Identifier"&&n.set(i.declaration.id.name,i.declaration.id.name);else if(i.specifiers.length>0)for(const o of i.specifiers)o.type==="ExportSpecifier"&&o.exported.type==="Identifier"&&n.set(o.exported.name,o.local.type==="Identifier"?o.local.name:o.exported.name)}return n},"collectJsonExportMap"),De=b(a=>{const n=[],{program:p}=Z(a,{plugins:[["typescript",{dts:!0}]],sourceType:"module"}),i=p.body[0].declarations[0].id.typeAnnotation.typeAnnotation.members;for(const o of i)o.key.type==="Identifier"?n.push(o.key.name):o.key.type==="StringLiteral"&&n.push(o.key.value);return n},"collectJsonExports");export{Ve as c,$e as g};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var H=Object.defineProperty;var x=(e,o)=>H(e,"name",{value:o,configurable:!0});import{existsSync as N}from"node:fs";import{createRequire as Q}from"node:module";import d from"node:path";import y from"node:process";import{findTsConfigSync as U,readTsConfig as V}from"@visulima/tsconfig";import O from"typescript";var X=Object.defineProperty,r=x((e,o)=>X(e,"name",{value:o,configurable:!0}),"i");let T=!1;const Y=r(e=>e?e.incremental===!1?-1:e.incremental===!0||typeof e.tsBuildInfoFile=="string"?1:0:0,"checkCompilerOptionsIncremental"),Z=r((e,o)=>{if(e.startsWith("."))return d.resolve(o,e.endsWith(".json")?e:`${e}.json`);try{return Q(d.join(o,"package.json")).resolve(e)}catch{return}},"resolveExtendedTsconfigPath"),_=r(e=>{if(N(e))return O.sys.readFile(e)},"readTsconfigFile"),E=r((e,o=new Set)=>{if(o.has(e))return!1;o.add(e);const t=O.readConfigFile(e,_);if(t.error||!t.config)return!1;const i=t.config,n=Y(i.compilerOptions);if(n!==0)return n===1;if(!i.extends)return!1;const s=Array.isArray(i.extends)?i.extends:[i.extends],m=d.dirname(e);for(const a of s){if(typeof a!="string")continue;const c=Z(a,m);if(c&&E(c,o))return!0}return!1},"hasExplicitIncrementalInTsconfig"),G=r((e,o)=>{if(e===!0||e===void 0)try{const t=U(o);return{resolvedTsconfig:t.config,tsconfig:t.path}}catch{return{resolvedTsconfig:void 0,tsconfig:void 0}}if(typeof e=="string"){const t=d.resolve(o||y.cwd(),e);return{resolvedTsconfig:V(t),tsconfig:t}}return{resolvedTsconfig:void 0,tsconfig:void 0}},"resolveTsconfigPath"),K=r((e,o,t,i)=>{if(e){if(o)throw new Error("[@visulima/rollup-plugin-dts] The `tsgo` option is not compatible with the `vue` option. Please disable one of them.");if(t)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"),L=r((e,o,t)=>{if(e){if(o)throw new Error("[@visulima/rollup-plugin-dts] The `oxc` option is not compatible with the `vue` option. Please disable one of them.");if(t)throw new Error("[@visulima/rollup-plugin-dts] The `oxc` option is not compatible with the `tsMacro` option. Please disable one of them.")}},"validateOxcCompatibility"),ee=r(e=>e===!1?!1:e===!0?{}:e,"normalizeTsgo"),oe=r((e,o,t,i,n)=>{let s;switch(e){case!1:{s=!1;break}case!0:{s={};break}case void 0:{s=o.isolatedDeclarations&&!t&&!i&&!n?{}:!1;break}default:s=e}return s&&(s.stripInternal??=o.stripInternal??!1,s.sourcemap=o.declarationMap??!1),s},"normalizeOxc"),ce=r(({banner:e,build:o=!1,cjsDefault:t=!1,compilerOptions:i={},cwd:n=y.cwd(),dtsInput:s=!1,eager:m=!1,emitDtsOnly:a=!1,emitJs:c,exclude:I,footer:C,include:P,incremental:j=!1,newContext:M=!1,oxc:k,parallel:D=!1,resolve:F=!1,resolver:J="oxc",sideEffects:S=!1,sourcemap:z,tsconfig:R,tsconfigRaw:q={},tsgo:A=!1,tsMacro:f=!1,vue:p=!1})=>{const{resolvedTsconfig:v,tsconfig:g}=G(R,n),w=i,l={...v?.compilerOptions,...i},B=j||w.incremental===!0||typeof w.tsBuildInfoFile=="string"||typeof g=="string"&&E(g),b=z??!!l.declarationMap;l.declarationMap=b;const W={...v,...q,compilerOptions:l},u=ee(A),h=oe(k,l,p,u,f),$=c??!!(l.checkJs||l.allowJs);return K(u,p,f,h),L(h,p,f),u&&!T&&(console.warn("The `tsgo` option is experimental and may change in the future."),T=!0),{banner:e,build:o,cjsDefault:t,cwd:n,dtsInput:s,eager:m,emitDtsOnly:a,emitJs:$,exclude:I,footer:C,include:P,incremental:B,newContext:M,oxc:h,parallel:D,resolve:F,resolver:J,sideEffects:S,sourcemap:b,tsconfig:g,tsconfigRaw:W,tsgo:u,tsMacro:f,vue:p}},"resolveOptions");export{ce as resolveOptions};
|