rolldown-plugin-dts 0.13.7 → 0.13.8

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/README.md CHANGED
@@ -6,7 +6,7 @@ A Rolldown plugin to generate and bundle dts files.
6
6
 
7
7
  ## Install
8
8
 
9
- ⚠️ Requires `rolldown@1.0.0-beta.9` or later.
9
+ Requires **`rolldown@1.0.0-beta.9`** or later.
10
10
 
11
11
  ```bash
12
12
  npm i rolldown-plugin-dts
@@ -31,90 +31,132 @@ You can find an example in [here](./rolldown.config.ts).
31
31
 
32
32
  ## Options
33
33
 
34
- ```ts
35
- export interface Options {
36
- /**
37
- * The directory in which the plugin will search for the `tsconfig.json` file.
38
- */
39
- cwd?: string
40
-
41
- /**
42
- * Set to `true` if your entry files are `.d.ts` files instead of `.ts` files.
43
- *
44
- * When enabled, the plugin will skip generating a `.d.ts` file for the entry point.
45
- */
46
- dtsInput?: boolean
47
-
48
- /**
49
- * If `true`, the plugin will emit only `.d.ts` files and remove all other output chunks.
50
- *
51
- * This is especially useful when generating `.d.ts` files for the CommonJS format as part of a separate build step.
52
- */
53
- emitDtsOnly?: boolean
54
-
55
- /**
56
- * The path to the `tsconfig.json` file.
57
- *
58
- * If set to `false`, the plugin will ignore any `tsconfig.json` file.
59
- * You can still specify `compilerOptions` directly in the options.
60
- *
61
- * @default 'tsconfig.json'
62
- */
63
- tsconfig?: string | boolean
64
-
65
- /**
66
- * Pass a raw `tsconfig.json` object directly to the plugin.
67
- *
68
- * @see https://www.typescriptlang.org/tsconfig
69
- */
70
- tsconfigRaw?: Omit<TsConfigJson, 'compilerOptions'>
71
-
72
- /**
73
- * Override the `compilerOptions` specified in `tsconfig.json`.
74
- *
75
- * @see https://www.typescriptlang.org/tsconfig/#compilerOptions
76
- */
77
- compilerOptions?: TsConfigJson.CompilerOptions
78
-
79
- /**
80
- * If `true`, the plugin will generate `.d.ts` files using Oxc,
81
- * which is significantly faster than the TypeScript compiler.
82
- *
83
- * This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
84
- */
85
- isolatedDeclarations?:
86
- | boolean
87
- | Omit<IsolatedDeclarationsOptions, 'sourcemap'>
88
-
89
- /**
90
- * If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
91
- */
92
- sourcemap?: boolean
93
-
94
- /**
95
- * Resolve external types used in `.d.ts` files from `node_modules`.
96
- */
97
- resolve?: boolean | (string | RegExp)[]
98
-
99
- /**
100
- * If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
101
- */
102
- vue?: boolean
103
-
104
- /**
105
- * If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`.
106
- * This enables processing multiple projects in parallel.
107
- */
108
- parallel?: boolean
109
-
110
- /**
111
- * If `true`, the plugin will prepare all files listed in `tsconfig.json` for `tsc` or `vue-tsc`.
112
- *
113
- * This is especially useful when you have a single `tsconfig.json` for multiple projects in a monorepo.
114
- */
115
- eager?: boolean
116
- }
117
- ```
34
+ Configuration options for the plugin.
35
+ Certainly! Here’s your documentation with simplified section titles (just the option name, no type annotation):
36
+
37
+ ---
38
+
39
+ ### cwd
40
+
41
+ The directory in which the plugin will search for the `tsconfig.json` file.
42
+
43
+ ---
44
+
45
+ ### dtsInput
46
+
47
+ Set to `true` if your entry files are `.d.ts` files instead of `.ts` files.
48
+
49
+ When enabled, the plugin will skip generating a `.d.ts` file for the entry point.
50
+
51
+ ---
52
+
53
+ ### emitDtsOnly
54
+
55
+ If `true`, the plugin will emit only `.d.ts` files and remove all other output chunks.
56
+
57
+ This is especially useful when generating `.d.ts` files for the CommonJS format as part of a separate build step.
58
+
59
+ ---
60
+
61
+ ### tsconfig
62
+
63
+ The path to the `tsconfig.json` file.
64
+
65
+ - If set to `false`, the plugin will ignore any `tsconfig.json` file.
66
+ - You can still specify `compilerOptions` directly in the options.
67
+
68
+ **Default:** `'tsconfig.json'`
69
+
70
+ ---
71
+
72
+ ### tsconfigRaw
73
+
74
+ Pass a raw `tsconfig.json` object directly to the plugin.
75
+
76
+ See: [TypeScript tsconfig documentation](https://www.typescriptlang.org/tsconfig)
77
+
78
+ ---
79
+
80
+ ### incremental
81
+
82
+ Controls how project references and incremental builds are handled:
83
+
84
+ - If your `tsconfig.json` uses [`references`](https://www.typescriptlang.org/tsconfig/#references), the plugin will use [`tsc -b`](https://www.typescriptlang.org/docs/handbook/project-references.html#build-mode-for-typescript) to build the project and all referenced projects before emitting `.d.ts` files.
85
+ - If `incremental` is `true`, all built files (including [`.tsbuildinfo`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)) will be written to disk, similar to running `tsc -b` in your project.
86
+ - If `incremental` is `false`, built files are kept in memory, minimizing disk usage.
87
+
88
+ Enabling this option can speed up builds by caching previous results, which is helpful for large projects with multiple references.
89
+
90
+ **Default:** `true` if your `tsconfig` has [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile) enabled.
91
+
92
+ > [!NOTE]
93
+ > This option is only used when [`isolatedDeclarations`](#isolateddeclarations) is `false`.
94
+
95
+ ---
96
+
97
+ ### compilerOptions
98
+
99
+ Override the `compilerOptions` specified in `tsconfig.json`.
100
+
101
+ See: [TypeScript compilerOptions documentation](https://www.typescriptlang.org/tsconfig/#compilerOptions)
102
+
103
+ ---
104
+
105
+ ### isolatedDeclarations
106
+
107
+ If `true`, the plugin will generate `.d.ts` files using [Oxc](https://oxc.rs/docs/guide/usage/transformer.html), which is significantly faster than the TypeScript compiler.
108
+
109
+ This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
110
+
111
+ ---
112
+
113
+ ### sourcemap
114
+
115
+ If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
116
+
117
+ ---
118
+
119
+ ### resolve
120
+
121
+ Resolve external types used in `.d.ts` files from `node_modules`.
122
+
123
+ - If `true`, all external types are resolved.
124
+ - If an array, only types matching the provided strings or regular expressions are resolved.
125
+
126
+ ---
127
+
128
+ ### vue
129
+
130
+ If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
131
+
132
+ ---
133
+
134
+ ### parallel
135
+
136
+ If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`, enabling parallel processing of multiple projects.
137
+
138
+ ---
139
+
140
+ ### eager
141
+
142
+ If `true`, the plugin will prepare all files listed in `tsconfig.json` for `tsc` or `vue-tsc`.
143
+
144
+ This is especially useful when you have a single `tsconfig.json` for multiple projects in a monorepo.
145
+
146
+ ---
147
+
148
+ ### tsgo
149
+
150
+ **[Experimental]** Enables DTS generation using [`tsgo`](https://github.com/microsoft/typescript-go).
151
+
152
+ - To use this option, ensure that `@typescript/native-preview` is installed as a dependency.
153
+ - Set to `true` to enable `tsgo` for the current project.
154
+ - If a string is provided, it should be the root path of your source files.
155
+
156
+ > [!WARNING]
157
+ > This option is experimental and not yet recommended for production environments.
158
+
159
+ ---
118
160
 
119
161
  ## Differences from `rollup-plugin-dts`
120
162
 
@@ -11,4 +11,4 @@ declare function filename_ts_to_dts(id: string): string;
11
11
  declare function filename_dts_to(id: string, ext: "js" | "ts"): string;
12
12
  declare function isRelative(id: string): boolean;
13
13
  //#endregion
14
- export { RE_CSS as RE_CSS$1, RE_DTS as RE_DTS$1, RE_DTS_MAP as RE_DTS_MAP$1, RE_JS as RE_JS$1, RE_NODE_MODULES as RE_NODE_MODULES$1, RE_TS as RE_TS$1, RE_VUE as RE_VUE$1, filename_dts_to as filename_dts_to$1, filename_js_to_dts as filename_js_to_dts$1, filename_ts_to_dts as filename_ts_to_dts$1, isRelative as isRelative$1 };
14
+ export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_ts_to_dts, isRelative };
@@ -1,2 +1,2 @@
1
- import { RE_CSS$1 as RE_CSS, RE_DTS$1 as RE_DTS, RE_DTS_MAP$1 as RE_DTS_MAP, RE_JS$1 as RE_JS, RE_NODE_MODULES$1 as RE_NODE_MODULES, RE_TS$1 as RE_TS, RE_VUE$1 as RE_VUE, filename_dts_to$1 as filename_dts_to, filename_js_to_dts$1 as filename_js_to_dts, filename_ts_to_dts$1 as filename_ts_to_dts, isRelative$1 as isRelative } from "./filename-B0ey8LZi.js";
1
+ import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_ts_to_dts, isRelative } from "./filename-TbnZq0n4.js";
2
2
  export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_ts_to_dts, isRelative };
package/dist/index.d.ts CHANGED
@@ -1,26 +1,9 @@
1
- import { RE_CSS$1 as RE_CSS, RE_DTS$1 as RE_DTS, RE_DTS_MAP$1 as RE_DTS_MAP, RE_JS$1 as RE_JS, RE_NODE_MODULES$1 as RE_NODE_MODULES, RE_TS$1 as RE_TS, RE_VUE$1 as RE_VUE } from "./filename-B0ey8LZi.js";
2
- import { TsConfigJson } from "get-tsconfig";
1
+ import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE } from "./filename-TbnZq0n4.js";
3
2
  import { IsolatedDeclarationsOptions } from "rolldown/experimental";
3
+ import { TsConfigJson } from "get-tsconfig";
4
4
  import { Plugin } from "rolldown";
5
5
 
6
- //#region src/fake-js.d.ts
7
- declare function createFakeJsPlugin({
8
- dtsInput,
9
- sourcemap
10
- }: Pick<OptionsResolved, "dtsInput" | "sourcemap">): Plugin;
11
- //#endregion
12
- //#region src/generate.d.ts
13
- declare function createGeneratePlugin({
14
- tsconfigRaw,
15
- tsconfigDir,
16
- isolatedDeclarations,
17
- emitDtsOnly,
18
- vue,
19
- parallel,
20
- eager
21
- }: Pick<OptionsResolved, "tsconfigRaw" | "tsconfigDir" | "isolatedDeclarations" | "emitDtsOnly" | "vue" | "parallel" | "eager">): Plugin;
22
- //#endregion
23
- //#region src/index.d.ts
6
+ //#region src/options.d.ts
24
7
  interface Options {
25
8
  /**
26
9
  * The directory in which the plugin will search for the `tsconfig.json` file.
@@ -54,6 +37,36 @@ interface Options {
54
37
  */
55
38
  tsconfigRaw?: Omit<TsConfigJson, "compilerOptions">;
56
39
  /**
40
+ * If your tsconfig.json has
41
+ * [`references`](https://www.typescriptlang.org/tsconfig/#references) option,
42
+ * `rolldown-plugin-dts` will use [`tsc
43
+ * -b`](https://www.typescriptlang.org/docs/handbook/project-references.html#build-mode-for-typescript)
44
+ * to build the project and all referenced projects before emitting `.d.ts`
45
+ * files.
46
+ *
47
+ * In such case, if this option is `true`, `rolldown-plugin-dts` will write
48
+ * down all built files into your disk, including
49
+ * [`.tsbuildinfo`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
50
+ * and other built files. This is equivalent to running `tsc -b` in your
51
+ * project.
52
+ *
53
+ * Otherwise, if this option is `false`, `rolldown-plugin-dts` will write
54
+ * built files only into memory and leave a small footprint in your disk.
55
+ *
56
+ * Enabling this option will decrease the build time by caching previous build
57
+ * results. This is helpful when you have a large project with multiple
58
+ * referenced projects.
59
+ *
60
+ * By default, `incremental` is `true` if your tsconfig has
61
+ * [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or
62
+ * [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
63
+ * enabled.
64
+ *
65
+ * This option is only used when {@link Options.isolatedDeclarations} is
66
+ * `false`.
67
+ */
68
+ incremental?: boolean;
69
+ /**
57
70
  * Override the `compilerOptions` specified in `tsconfig.json`.
58
71
  *
59
72
  * @see https://www.typescriptlang.org/tsconfig/#compilerOptions
@@ -89,18 +102,25 @@ interface Options {
89
102
  * This is especially useful when you have a single `tsconfig.json` for multiple projects in a monorepo.
90
103
  */
91
104
  eager?: boolean;
105
+ /**
106
+ * **[Experimental]** Enables DTS generation using `tsgo`.
107
+ *
108
+ * To use this option, make sure `@typescript/native-preview` is installed as a dependency.
109
+ *
110
+ * **Note:** This option is not yet recommended for production environments.
111
+ */
112
+ tsgo?: boolean | string;
92
113
  }
93
114
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
94
115
  type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
95
116
  tsconfig: string | undefined;
96
117
  isolatedDeclarations: IsolatedDeclarationsOptions | false;
97
118
  tsconfigRaw: TsConfigJson;
98
- tsconfigDir: string;
99
119
  }>;
100
- declare function dts(options?: Options): Plugin[];
101
120
  declare function resolveOptions({
102
121
  cwd,
103
122
  tsconfig,
123
+ incremental,
104
124
  compilerOptions,
105
125
  tsconfigRaw: overriddenTsconfigRaw,
106
126
  isolatedDeclarations,
@@ -110,7 +130,31 @@ declare function resolveOptions({
110
130
  resolve,
111
131
  vue,
112
132
  parallel,
113
- eager
133
+ eager,
134
+ tsgo
114
135
  }: Options): OptionsResolved;
115
136
  //#endregion
116
- export { Options, OptionsResolved, RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
137
+ //#region src/fake-js.d.ts
138
+ declare function createFakeJsPlugin({
139
+ dtsInput,
140
+ sourcemap
141
+ }: Pick<OptionsResolved, "dtsInput" | "sourcemap">): Plugin;
142
+ //#endregion
143
+ //#region src/generate.d.ts
144
+ declare function createGeneratePlugin({
145
+ tsconfig,
146
+ tsconfigRaw,
147
+ incremental,
148
+ cwd,
149
+ isolatedDeclarations,
150
+ emitDtsOnly,
151
+ vue,
152
+ parallel,
153
+ eager,
154
+ tsgo
155
+ }: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "incremental" | "isolatedDeclarations" | "emitDtsOnly" | "vue" | "parallel" | "eager" | "tsgo">): Plugin;
156
+ //#endregion
157
+ //#region src/index.d.ts
158
+ declare function dts(options?: Options): Plugin[];
159
+ //#endregion
160
+ export { Options, RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
package/dist/index.js CHANGED
@@ -1,15 +1,18 @@
1
1
  import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, filename_dts_to, filename_js_to_dts, filename_ts_to_dts } from "./filename-Dpr2dKWZ.js";
2
2
  import path from "node:path";
3
- import process from "node:process";
4
3
  import Debug from "debug";
5
- import { getTsconfig, parseTsconfig } from "get-tsconfig";
6
4
  import _generate from "@babel/generator";
7
5
  import { parse } from "@babel/parser";
8
6
  import * as t from "@babel/types";
9
7
  import { isDeclarationType, isTypeOf } from "ast-kit";
10
- import { fork } from "node:child_process";
8
+ import { fork, spawn } from "node:child_process";
9
+ import { existsSync } from "node:fs";
10
+ import { mkdtemp, readFile, rm } from "node:fs/promises";
11
+ import { tmpdir } from "node:os";
11
12
  import { createBirpc } from "birpc";
12
13
  import { ResolverFactory, isolatedDeclaration } from "rolldown/experimental";
14
+ import process from "node:process";
15
+ import { getTsconfig, parseTsconfig } from "get-tsconfig";
13
16
  import { createResolver } from "dts-resolver";
14
17
 
15
18
  //#region src/dts-input.ts
@@ -230,8 +233,8 @@ const generate = _generate.default || _generate;
230
233
  function createFakeJsPlugin({ dtsInput, sourcemap }) {
231
234
  let symbolIdx = 0;
232
235
  let identifierIdx = 0;
233
- const symbolMap = new Map();
234
- const commentsMap = new Map();
236
+ const symbolMap = /* @__PURE__ */ new Map();
237
+ const commentsMap = /* @__PURE__ */ new Map();
235
238
  return {
236
239
  name: "rolldown-plugin-dts:fake-js",
237
240
  outputOptions(options) {
@@ -270,7 +273,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
270
273
  commentsMap.set(id, directives);
271
274
  }
272
275
  const appendStmts = [];
273
- const namespaceStmts = new Map();
276
+ const namespaceStmts = /* @__PURE__ */ new Map();
274
277
  for (const [i, stmt] of program.body.entries()) {
275
278
  const setStmt = (node) => program.body[i] = node;
276
279
  if (rewriteImportExport(stmt, setStmt)) continue;
@@ -383,8 +386,8 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
383
386
  return inheritNodeComments(node, original.decl);
384
387
  }).filter((node) => !!node);
385
388
  if (program.body.length === 0) return "export { };";
386
- const comments = new Set();
387
- const commentsValue = new Set();
389
+ const comments = /* @__PURE__ */ new Set();
390
+ const commentsValue = /* @__PURE__ */ new Set();
388
391
  for (const id of chunk.moduleIds) {
389
392
  const preserveComments = commentsMap.get(id);
390
393
  if (preserveComments) {
@@ -420,8 +423,8 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
420
423
  return symbolMap.get(symbolId);
421
424
  }
422
425
  function collectDependencies(node, namespaceStmts) {
423
- const deps = new Set();
424
- const seen = new Set();
426
+ const deps = /* @__PURE__ */ new Set();
427
+ const seen = /* @__PURE__ */ new Set();
425
428
  walk(node, { leave(node$1) {
426
429
  if (node$1.type === "ExportNamedDeclaration") {
427
430
  for (const specifier of node$1.specifiers) if (specifier.type === "ExportSpecifier") addDependency(specifier.local);
@@ -510,8 +513,8 @@ function patchImportSource(node) {
510
513
  }
511
514
  }
512
515
  function patchTsNamespace(nodes) {
513
- const emptyObjectAssignments = new Map();
514
- const removed = new Set();
516
+ const emptyObjectAssignments = /* @__PURE__ */ new Map();
517
+ const removed = /* @__PURE__ */ new Set();
515
518
  for (const [i, node] of nodes.entries()) {
516
519
  if (node.type === "VariableDeclaration" && node.declarations.length === 1 && node.declarations[0].id.type === "Identifier" && node.declarations[0].init?.type === "ObjectExpression" && node.declarations[0].init.properties.length === 0) emptyObjectAssignments.set(node.declarations[0].id.name, node);
517
520
  if (node.type !== "ExpressionStatement" || node.expression.type !== "CallExpression" || node.expression.callee.type !== "Identifier" || !node.expression.callee.name.startsWith("__export")) continue;
@@ -608,8 +611,13 @@ function inheritNodeComments(oldNode, newNode) {
608
611
  //#region src/generate.ts
609
612
  const debug$1 = Debug("rolldown-plugin-dts:generate");
610
613
  const WORKER_URL = "./utils/tsc-worker.js";
611
- function createGeneratePlugin({ tsconfigRaw, tsconfigDir, isolatedDeclarations, emitDtsOnly, vue, parallel, eager }) {
612
- const dtsMap = new Map();
614
+ const spawnAsync = (...args) => new Promise((resolve, reject) => {
615
+ const child = spawn(...args);
616
+ child.on("close", () => resolve());
617
+ child.on("error", (error) => reject(error));
618
+ });
619
+ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolatedDeclarations, emitDtsOnly, vue, parallel, eager, tsgo }) {
620
+ const dtsMap = /* @__PURE__ */ new Map();
613
621
  /**
614
622
  * A map of input id to output file name
615
623
  *
@@ -619,11 +627,12 @@ function createGeneratePlugin({ tsconfigRaw, tsconfigDir, isolatedDeclarations,
619
627
  * ['/absolute/path/to/src/source_file.ts', 'dist/foo/index'],
620
628
  * ])
621
629
  */
622
- const inputAliasMap = new Map();
630
+ const inputAliasMap = /* @__PURE__ */ new Map();
623
631
  let childProcess;
624
632
  let rpc;
625
633
  let tscEmit;
626
- if (parallel) {
634
+ let tsgoDist;
635
+ if (!tsgo && parallel) {
627
636
  childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
628
637
  rpc = createBirpc({}, {
629
638
  post: (data) => childProcess.send(data),
@@ -633,7 +642,21 @@ function createGeneratePlugin({ tsconfigRaw, tsconfigDir, isolatedDeclarations,
633
642
  return {
634
643
  name: "rolldown-plugin-dts:generate",
635
644
  async buildStart(options) {
636
- if (!parallel && (!isolatedDeclarations || vue)) ({tscEmit} = await import("./tsc-CN7vXGIS.js"));
645
+ if (tsgo) {
646
+ const tsgoPkg = import.meta.resolve("@typescript/native-preview/package.json");
647
+ const { default: getExePath } = await import(new URL("./lib/getExePath.js", tsgoPkg).href);
648
+ const tsgo$1 = getExePath();
649
+ tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
650
+ await spawnAsync(tsgo$1, [
651
+ "--noEmit",
652
+ "false",
653
+ "--declaration",
654
+ "--emitDeclarationOnly",
655
+ ...tsconfig ? ["-p", tsconfig] : [],
656
+ "--outDir",
657
+ tsgoDist
658
+ ], { stdio: "inherit" });
659
+ } else if (!parallel && (!isolatedDeclarations || vue)) ({tscEmit} = await import("./tsc-sXJZixaR.js"));
637
660
  if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
638
661
  debug$1("resolving input alias %s -> %s", name, id);
639
662
  let resolved = await this.resolve(id);
@@ -698,7 +721,12 @@ function createGeneratePlugin({ tsconfigRaw, tsconfigDir, isolatedDeclarations,
698
721
  let dtsCode;
699
722
  let map;
700
723
  debug$1("generate dts %s from %s", dtsId, id);
701
- if (isolatedDeclarations && !RE_VUE.test(id)) {
724
+ if (tsgo) {
725
+ if (RE_VUE.test(id)) throw new Error("tsgo does not support Vue files.");
726
+ const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(typeof tsgo === "string" ? tsgo : "src"), filename_ts_to_dts(id)));
727
+ if (existsSync(dtsPath)) dtsCode = await readFile(dtsPath, "utf8");
728
+ else throw new Error(`tsgo did not generate dts file for ${id}, please check your tsconfig.`);
729
+ } else if (isolatedDeclarations && !RE_VUE.test(id)) {
702
730
  const result = isolatedDeclaration(id, code, isolatedDeclarations);
703
731
  if (result.errors.length) {
704
732
  const [error] = result.errors;
@@ -715,8 +743,10 @@ function createGeneratePlugin({ tsconfigRaw, tsconfigDir, isolatedDeclarations,
715
743
  } else {
716
744
  const entries = eager ? void 0 : Array.from(dtsMap.values()).filter((v) => v.isEntry).map((v) => v.id);
717
745
  const options = {
746
+ tsconfig,
718
747
  tsconfigRaw,
719
- tsconfigDir,
748
+ incremental,
749
+ cwd,
720
750
  entries,
721
751
  id,
722
752
  vue
@@ -738,12 +768,71 @@ function createGeneratePlugin({ tsconfigRaw, tsconfigDir, isolatedDeclarations,
738
768
  generateBundle: emitDtsOnly ? (options, bundle) => {
739
769
  for (const fileName of Object.keys(bundle)) if (bundle[fileName].type === "chunk" && !RE_DTS.test(fileName) && !RE_DTS_MAP.test(fileName)) delete bundle[fileName];
740
770
  } : void 0,
741
- buildEnd() {
771
+ async buildEnd() {
742
772
  childProcess?.kill();
773
+ if (tsgoDist) {
774
+ await rm(tsgoDist, {
775
+ recursive: true,
776
+ force: true
777
+ }).catch(() => {});
778
+ tsgoDist = void 0;
779
+ }
743
780
  }
744
781
  };
745
782
  }
746
783
 
784
+ //#endregion
785
+ //#region src/options.ts
786
+ let warnedTsgo = false;
787
+ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, compilerOptions = {}, tsconfigRaw: overriddenTsconfigRaw = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, vue = false, parallel = false, eager = false, tsgo = false }) {
788
+ let resolvedTsconfig;
789
+ if (tsconfig === true || tsconfig == null) {
790
+ const { config, path: path$1 } = getTsconfig(cwd) || {};
791
+ tsconfig = path$1;
792
+ resolvedTsconfig = config;
793
+ } else if (typeof tsconfig === "string") {
794
+ tsconfig = path.resolve(cwd || process.cwd(), tsconfig);
795
+ resolvedTsconfig = parseTsconfig(tsconfig);
796
+ } else tsconfig = void 0;
797
+ compilerOptions = {
798
+ ...resolvedTsconfig?.compilerOptions,
799
+ ...compilerOptions
800
+ };
801
+ incremental ||= compilerOptions.incremental || !!compilerOptions.tsBuildInfoFile;
802
+ sourcemap ??= !!compilerOptions.declarationMap;
803
+ compilerOptions.declarationMap = sourcemap;
804
+ const tsconfigRaw = {
805
+ ...resolvedTsconfig,
806
+ ...overriddenTsconfigRaw,
807
+ compilerOptions
808
+ };
809
+ if (isolatedDeclarations == null) isolatedDeclarations = !!compilerOptions?.isolatedDeclarations;
810
+ if (isolatedDeclarations === true) isolatedDeclarations = {};
811
+ if (isolatedDeclarations) {
812
+ isolatedDeclarations.stripInternal ??= !!compilerOptions?.stripInternal;
813
+ isolatedDeclarations.sourcemap = !!compilerOptions.declarationMap;
814
+ }
815
+ if (tsgo && !warnedTsgo) {
816
+ console.warn("The `tsgo` option is experimental and may change in the future.");
817
+ warnedTsgo = true;
818
+ }
819
+ return {
820
+ cwd,
821
+ tsconfig,
822
+ tsconfigRaw,
823
+ incremental,
824
+ isolatedDeclarations,
825
+ sourcemap,
826
+ dtsInput,
827
+ emitDtsOnly,
828
+ resolve,
829
+ vue,
830
+ parallel,
831
+ eager,
832
+ tsgo
833
+ };
834
+ }
835
+
747
836
  //#endregion
748
837
  //#region src/resolve.ts
749
838
  function createDtsResolvePlugin({ tsconfig, resolve }) {
@@ -804,49 +893,6 @@ function dts(options = {}) {
804
893
  plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
805
894
  return plugins;
806
895
  }
807
- function resolveOptions({ cwd = process.cwd(), tsconfig, compilerOptions = {}, tsconfigRaw: overriddenTsconfigRaw = {}, isolatedDeclarations, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, vue = false, parallel = false, eager = false }) {
808
- let resolvedTsconfig;
809
- if (tsconfig === true || tsconfig == null) {
810
- const { config, path: path$1 } = getTsconfig(cwd) || {};
811
- tsconfig = path$1;
812
- resolvedTsconfig = config;
813
- } else if (typeof tsconfig === "string") {
814
- tsconfig = path.resolve(cwd || process.cwd(), tsconfig);
815
- resolvedTsconfig = parseTsconfig(tsconfig);
816
- } else tsconfig = void 0;
817
- compilerOptions = {
818
- ...resolvedTsconfig?.compilerOptions,
819
- ...compilerOptions
820
- };
821
- sourcemap ??= !!compilerOptions.declarationMap;
822
- compilerOptions.declarationMap = sourcemap;
823
- const tsconfigRaw = {
824
- ...resolvedTsconfig,
825
- ...overriddenTsconfigRaw,
826
- compilerOptions
827
- };
828
- const tsconfigDir = tsconfig ? path.dirname(tsconfig) : cwd;
829
- if (isolatedDeclarations == null) isolatedDeclarations = !!compilerOptions?.isolatedDeclarations;
830
- if (isolatedDeclarations === true) isolatedDeclarations = {};
831
- if (isolatedDeclarations) {
832
- isolatedDeclarations.stripInternal ??= !!compilerOptions?.stripInternal;
833
- isolatedDeclarations.sourcemap = !!compilerOptions.declarationMap;
834
- }
835
- return {
836
- cwd,
837
- tsconfig,
838
- tsconfigDir,
839
- tsconfigRaw,
840
- isolatedDeclarations,
841
- sourcemap,
842
- dtsInput,
843
- emitDtsOnly,
844
- resolve,
845
- vue,
846
- parallel,
847
- eager
848
- };
849
- }
850
896
 
851
897
  //#endregion
852
898
  export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
@@ -1,7 +1,52 @@
1
1
  import { createRequire } from "node:module";
2
+ import path from "node:path";
2
3
  import Debug from "debug";
3
4
  import ts from "typescript";
4
5
 
6
+ //#region src/utils/tsc-system.ts
7
+ const debug$2 = Debug("rolldown-plugin-dts:tsc-system");
8
+ const files = /* @__PURE__ */ new Map();
9
+ const fsSystem = {
10
+ ...ts.sys,
11
+ write(message) {
12
+ debug$2(message);
13
+ },
14
+ resolvePath(path$1) {
15
+ if (files.has(path$1)) return path$1;
16
+ return ts.sys.resolvePath(path$1);
17
+ },
18
+ directoryExists(directory) {
19
+ if (Array.from(files.keys()).some((path$1) => path$1.startsWith(directory))) return true;
20
+ return ts.sys.directoryExists(directory);
21
+ },
22
+ fileExists(fileName) {
23
+ if (files.has(fileName)) return true;
24
+ return ts.sys.fileExists(fileName);
25
+ },
26
+ readFile(fileName, ...args) {
27
+ if (files.has(fileName)) return files.get(fileName);
28
+ return ts.sys.readFile(fileName, ...args);
29
+ },
30
+ writeFile(path$1, data, ...args) {
31
+ files.set(path$1, data);
32
+ ts.sys.writeFile(path$1, data, ...args);
33
+ },
34
+ deleteFile(fileName, ...args) {
35
+ files.delete(fileName);
36
+ ts.sys.deleteFile?.(fileName, ...args);
37
+ }
38
+ };
39
+ const memorySystem = {
40
+ ...fsSystem,
41
+ writeFile(path$1, data) {
42
+ files.set(path$1, data);
43
+ },
44
+ deleteFile(fileName) {
45
+ files.delete(fileName);
46
+ }
47
+ };
48
+
49
+ //#endregion
5
50
  //#region src/utils/vue.ts
6
51
  const debug$1 = Debug("rolldown-plugin-dts:vue");
7
52
  let createVueProgram;
@@ -74,14 +119,38 @@ function createOrGetTsModule(options) {
74
119
  programs.push(module.program);
75
120
  return module;
76
121
  }
77
- function createTsProgram({ entries, id, tsconfigRaw, tsconfigDir, vue }) {
78
- const parsedCmd = ts.parseJsonConfigFileContent(tsconfigRaw, ts.sys, tsconfigDir);
122
+ /**
123
+ * Build the root project and all its dependencies projects.
124
+ * This is designed for a project (e.g. tsconfig.json) that has "references" to
125
+ * other composite projects (e.g., tsconfig.node.json and tsconfig.app.json).
126
+ * If `incremental` is `true`, the build result will be cached in the
127
+ * `.tsbuildinfo` file so that the next time the project is built (without
128
+ * changes) the build will be super fast. If `incremental` is `false`, the
129
+ * `.tsbuildinfo` file will only be written to the memory.
130
+ */
131
+ function buildSolution(tsconfig, incremental) {
132
+ debug(`building projects for ${tsconfig} with incremental: ${incremental}`);
133
+ const system = incremental ? fsSystem : memorySystem;
134
+ const host = ts.createSolutionBuilderHost(system);
135
+ const builder = ts.createSolutionBuilder(host, [tsconfig], {
136
+ force: !incremental,
137
+ verbose: true
138
+ });
139
+ const exitStatus = builder.build();
140
+ debug(`built solution for ${tsconfig} with exit status ${exitStatus}`);
141
+ }
142
+ function createTsProgram({ entries, id, tsconfig, tsconfigRaw, incremental, vue, cwd }) {
143
+ const parsedCmd = ts.parseJsonConfigFileContent(tsconfigRaw, fsSystem, tsconfig ? path.dirname(tsconfig) : cwd);
144
+ if (tsconfig && parsedCmd.projectReferences?.length) buildSolution(tsconfig, incremental);
79
145
  const compilerOptions = {
80
146
  ...defaultCompilerOptions,
81
147
  ...parsedCmd.options
82
148
  };
83
- const rootNames = [...new Set([id, ...entries || parsedCmd.fileNames].map((f) => ts.sys.resolvePath(f)))];
149
+ const rootNames = [...new Set([id, ...entries || parsedCmd.fileNames].map((f) => fsSystem.resolvePath(f)))];
84
150
  const host = ts.createCompilerHost(compilerOptions, true);
151
+ host.readFile = fsSystem.readFile;
152
+ host.fileExists = fsSystem.fileExists;
153
+ host.directoryExists = fsSystem.directoryExists;
85
154
  const createProgram = vue ? createVueProgramFactory(ts) : ts.createProgram;
86
155
  const program = createProgram({
87
156
  rootNames,
@@ -90,15 +159,26 @@ function createTsProgram({ entries, id, tsconfigRaw, tsconfigDir, vue }) {
90
159
  projectReferences: parsedCmd.projectReferences
91
160
  });
92
161
  const sourceFile = program.getSourceFile(id);
93
- if (!sourceFile) throw new Error(`Source file not found: ${id}`);
162
+ if (!sourceFile) {
163
+ debug(`source file not found in program: ${id}`);
164
+ if (!fsSystem.fileExists(id)) {
165
+ debug(`File ${id} does not exist on disk.`);
166
+ throw new Error(`Source file not found: ${id}`);
167
+ } else {
168
+ debug(`File ${id} exists on disk.`);
169
+ throw new Error(`Unable to load file ${id} from the program. This seems like a bug of rolldown-plugin-dts. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts/issues`);
170
+ }
171
+ }
94
172
  return {
95
173
  program,
96
174
  file: sourceFile
97
175
  };
98
176
  }
99
177
  function tscEmit(tscOptions) {
178
+ debug(`running tscEmit ${tscOptions.id}`);
100
179
  const module = createOrGetTsModule(tscOptions);
101
180
  const { program, file } = module;
181
+ debug(`got source file: ${file.fileName}`);
102
182
  let dtsCode;
103
183
  let map;
104
184
  const { emitSkipped, diagnostics } = program.emit(file, (fileName, code) => {
@@ -111,6 +191,10 @@ function tscEmit(tscOptions) {
111
191
  }
112
192
  }, void 0, true, void 0, true);
113
193
  if (emitSkipped && diagnostics.length) return { error: ts.formatDiagnostics(diagnostics, formatHost) };
194
+ if (!dtsCode && file.isDeclarationFile) {
195
+ debug("nothing was emitted. fallback to sourceFile text.");
196
+ dtsCode = file.getFullText();
197
+ }
114
198
  return {
115
199
  code: dtsCode,
116
200
  map
@@ -0,0 +1,3 @@
1
+ import { tscEmit } from "./tsc-BjgfmUbK.js";
2
+
3
+ export { tscEmit };
@@ -1,18 +1,21 @@
1
1
  import { TsConfigJson } from "get-tsconfig";
2
2
  import ts from "typescript";
3
+ import { SourceMapInput } from "rolldown";
3
4
 
4
5
  //#region src/utils/tsc.d.ts
5
6
 
6
7
  interface TscOptions {
8
+ tsconfig?: string;
7
9
  tsconfigRaw: TsConfigJson;
8
- tsconfigDir: string;
10
+ cwd: string;
11
+ incremental: boolean;
9
12
  entries?: string[];
10
13
  id: string;
11
14
  vue?: boolean;
12
15
  }
13
16
  interface TscResult {
14
17
  code?: string;
15
- map?: any;
18
+ map?: SourceMapInput;
16
19
  error?: string;
17
20
  }
18
21
  declare function tscEmit(tscOptions: TscOptions): TscResult;
@@ -1,6 +1,6 @@
1
- import { tscEmit } from "../tsc-DSR26k5c.js";
2
- import process from "node:process";
1
+ import { tscEmit } from "../tsc-BjgfmUbK.js";
3
2
  import { createBirpc } from "birpc";
3
+ import process from "node:process";
4
4
 
5
5
  //#region src/utils/tsc-worker.ts
6
6
  const functions = { tscEmit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.13.7",
3
+ "version": "0.13.8",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -29,11 +29,15 @@
29
29
  "access": "public"
30
30
  },
31
31
  "peerDependencies": {
32
+ "@typescript/native-preview": ">=7.0.0-dev.20250601.1",
32
33
  "rolldown": "^1.0.0-beta.9",
33
34
  "typescript": "^5.0.0",
34
35
  "vue-tsc": "~2.2.0"
35
36
  },
36
37
  "peerDependenciesMeta": {
38
+ "@typescript/native-preview": {
39
+ "optional": true
40
+ },
37
41
  "typescript": {
38
42
  "optional": true
39
43
  },
@@ -42,42 +46,46 @@
42
46
  }
43
47
  },
44
48
  "dependencies": {
45
- "@babel/generator": "^7.27.3",
46
- "@babel/parser": "^7.27.3",
49
+ "@babel/generator": "^7.27.5",
50
+ "@babel/parser": "^7.27.5",
47
51
  "@babel/types": "^7.27.3",
48
- "ast-kit": "^2.0.0",
52
+ "ast-kit": "^2.1.0",
49
53
  "birpc": "^2.3.0",
50
54
  "debug": "^4.4.1",
51
- "dts-resolver": "^2.0.1",
55
+ "dts-resolver": "^2.1.1",
52
56
  "get-tsconfig": "^4.10.1"
53
57
  },
54
58
  "devDependencies": {
55
- "@sxzz/eslint-config": "^7.0.1",
59
+ "@sxzz/eslint-config": "^7.0.2",
56
60
  "@sxzz/prettier-config": "^2.2.1",
57
61
  "@sxzz/test-utils": "^0.5.6",
58
62
  "@types/babel__generator": "^7.27.0",
59
63
  "@types/debug": "^4.1.12",
60
- "@types/node": "^22.15.21",
64
+ "@types/node": "^22.15.29",
65
+ "@typescript/native-preview": "7.0.0-dev.20250604.1",
61
66
  "@volar/typescript": "^2.4.14",
62
67
  "@vue/language-core": "^2.2.10",
63
68
  "bumpp": "^10.1.1",
64
69
  "diff": "^8.0.2",
65
- "eslint": "^9.27.0",
70
+ "eslint": "^9.28.0",
66
71
  "estree-walker": "^3.0.3",
67
72
  "prettier": "^3.5.3",
68
- "rolldown": "1.0.0-beta.9",
73
+ "rolldown": "1.0.0-beta.11-commit.f051675",
69
74
  "rollup-plugin-dts": "^6.2.1",
70
75
  "tinyglobby": "^0.2.14",
71
- "tsdown": "^0.12.3",
76
+ "tsdown": "^0.12.6",
72
77
  "tsx": "^4.19.4",
73
78
  "typescript": "^5.8.3",
74
- "vitest": "^3.1.4",
75
- "vue": "^3.5.15",
79
+ "vitest": "^3.2.1",
80
+ "vue": "^3.5.16",
76
81
  "vue-tsc": "^2.2.10"
77
82
  },
78
83
  "engines": {
79
84
  "node": ">=20.18.0"
80
85
  },
86
+ "resolutions": {
87
+ "rolldown": "1.0.0-beta.11-commit.f051675"
88
+ },
81
89
  "prettier": "@sxzz/prettier-config",
82
90
  "scripts": {
83
91
  "lint": "eslint --cache .",
@@ -1,3 +0,0 @@
1
- import { tscEmit } from "./tsc-DSR26k5c.js";
2
-
3
- export { tscEmit };