rolldown-plugin-dts 0.14.2 → 0.15.0

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
@@ -36,31 +36,25 @@ You can find an example in [here](./rolldown.config.ts).
36
36
 
37
37
  Configuration options for the plugin.
38
38
 
39
- ---
39
+ ### General Options
40
40
 
41
- ### cwd
41
+ #### `cwd`
42
42
 
43
43
  The directory in which the plugin will search for the `tsconfig.json` file.
44
44
 
45
- ---
46
-
47
- ### dtsInput
45
+ #### `dtsInput`
48
46
 
49
47
  Set to `true` if your entry files are `.d.ts` files instead of `.ts` files.
50
48
 
51
49
  When enabled, the plugin will skip generating a `.d.ts` file for the entry point.
52
50
 
53
- ---
54
-
55
- ### emitDtsOnly
51
+ #### `emitDtsOnly`
56
52
 
57
53
  If `true`, the plugin will emit only `.d.ts` files and remove all other output chunks.
58
54
 
59
55
  This is especially useful when generating `.d.ts` files for the CommonJS format as part of a separate build step.
60
56
 
61
- ---
62
-
63
- ### tsconfig
57
+ #### `tsconfig`
64
58
 
65
59
  The path to the `tsconfig.json` file.
66
60
 
@@ -69,85 +63,61 @@ The path to the `tsconfig.json` file.
69
63
 
70
64
  **Default:** `'tsconfig.json'`
71
65
 
72
- ---
73
-
74
- ### tsconfigRaw
66
+ #### `tsconfigRaw`
75
67
 
76
68
  Pass a raw `tsconfig.json` object directly to the plugin.
77
69
 
78
70
  See: [TypeScript tsconfig documentation](https://www.typescriptlang.org/tsconfig)
79
71
 
80
- ---
81
-
82
- ### incremental
83
-
84
- Controls how project references and incremental builds are handled:
85
-
86
- - 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.
87
- - 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.
88
- - If `incremental` is `false`, built files are kept in memory, minimizing disk usage.
89
-
90
- Enabling this option can speed up builds by caching previous results, which is helpful for large projects with multiple references.
91
-
92
- **Default:** `true` if your `tsconfig` has [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile) enabled.
93
-
94
- > [!NOTE]
95
- > This option is only used when [`isolatedDeclarations`](#isolateddeclarations) is `false`.
96
-
97
- ---
98
-
99
- ### compilerOptions
72
+ #### `compilerOptions`
100
73
 
101
74
  Override the `compilerOptions` specified in `tsconfig.json`.
102
75
 
103
76
  See: [TypeScript compilerOptions documentation](https://www.typescriptlang.org/tsconfig/#compilerOptions)
104
77
 
105
- ---
78
+ #### `sourcemap`
106
79
 
107
- ### isolatedDeclarations
80
+ If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
108
81
 
109
- 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.
82
+ #### `resolve`
110
83
 
111
- This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
84
+ Resolve external types used in `.d.ts` files from `node_modules`.
112
85
 
113
- ---
86
+ - If `true`, all external types are resolved.
87
+ - If an array, only types matching the provided strings or regular expressions are resolved.
114
88
 
115
- ### sourcemap
89
+ ### `tsc` Options
116
90
 
117
- If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
91
+ > [!NOTE]
92
+ > These options are only applicable when `oxc` and `tsgo` are not enabled.
118
93
 
119
- ---
94
+ #### `incremental`
120
95
 
121
- ### resolve
96
+ Controls how project references and incremental builds are handled:
122
97
 
123
- Resolve external types used in `.d.ts` files from `node_modules`.
98
+ - 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.
99
+ - 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.
100
+ - If `incremental` is `false`, built files are kept in memory, minimizing disk usage.
124
101
 
125
- - If `true`, all external types are resolved.
126
- - If an array, only types matching the provided strings or regular expressions are resolved.
102
+ Enabling this option can speed up builds by caching previous results, which is helpful for large projects with multiple references.
127
103
 
128
- ---
104
+ **Default:** `true` if your `tsconfig` has [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile) enabled.
129
105
 
130
- ### vue
106
+ #### `vue`
131
107
 
132
108
  If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
133
109
 
134
- ---
135
-
136
- ### parallel
110
+ #### `parallel`
137
111
 
138
112
  If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`, enabling parallel processing of multiple projects.
139
113
 
140
- ---
141
-
142
- ### eager
114
+ #### `eager`
143
115
 
144
116
  If `true`, the plugin will prepare all files listed in `tsconfig.json` for `tsc` or `vue-tsc`.
145
117
 
146
118
  This is especially useful when you have a single `tsconfig.json` for multiple projects in a monorepo.
147
119
 
148
- ---
149
-
150
- ### newContext
120
+ #### `newContext`
151
121
 
152
122
  If `true`, the plugin will create a new isolated context for each build,
153
123
  ensuring that previously generated `.d.ts` code and caches are not reused.
@@ -156,20 +126,40 @@ By default, the plugin may reuse internal caches or incremental build artifacts
156
126
  to speed up repeated builds. Enabling this option forces a clean context,
157
127
  guaranteeing that all type definitions are generated from scratch.
158
128
 
159
- ---
129
+ `invalidateContextFile` API can be used to clear invalidated files from the context.
160
130
 
161
- ### tsgo
131
+ ```ts
132
+ import { globalContext, invalidateContextFile } from 'rolldown-plugin-dts/tsc'
133
+ invalidateContextFile(globalContext, 'src/foo.ts')
134
+ ```
162
135
 
163
- **[Experimental]** Enables DTS generation using [`tsgo`](https://github.com/microsoft/typescript-go).
136
+ #### `emitJs`
164
137
 
165
- To use this option, ensure that `@typescript/native-preview` is installed as a dependency.
138
+ If `true`, the plugin will emit `.d.ts` files for `.js` files as well.
139
+ This is useful when you want to generate type definitions for JavaScript files with JSDoc comments.
140
+
141
+ Enabled by default when `allowJs` in compilerOptions is `true`.
142
+
143
+ ### Oxc
144
+
145
+ #### `oxc`
166
146
 
167
- `tsconfigRaw` and `isolatedDeclarations` options will be ignored when this option is enabled.
147
+ 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.
148
+
149
+ This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
150
+
151
+ ### TypeScript Go
168
152
 
169
153
  > [!WARNING]
170
- > This option is experimental and not yet recommended for production environments.
154
+ > This feature is experimental and not yet recommended for production environments.
155
+
156
+ #### `tsgo`
157
+
158
+ **[Experimental]** Enables DTS generation using [`tsgo`](https://github.com/microsoft/typescript-go).
159
+
160
+ To use this option, ensure that `@typescript/native-preview` is installed as a dependency.
171
161
 
172
- ---
162
+ `tsconfigRaw` option will be ignored when this option is enabled.
173
163
 
174
164
  ## Differences from `rollup-plugin-dts`
175
165
 
@@ -0,0 +1,23 @@
1
+ import Debug from "debug";
2
+
3
+ //#region src/tsc/context.ts
4
+ const debug = Debug("rolldown-plugin-dts:tsc-context");
5
+ function createContext() {
6
+ const programs = [];
7
+ const files = /* @__PURE__ */ new Map();
8
+ return {
9
+ programs,
10
+ files
11
+ };
12
+ }
13
+ function invalidateContextFile(context, file) {
14
+ debug(`invalidating context file: ${file}`);
15
+ context.files.delete(file);
16
+ context.programs = context.programs.filter((program) => {
17
+ return !program.getSourceFiles().some((sourceFile) => sourceFile.fileName === file);
18
+ });
19
+ }
20
+ const globalContext = createContext();
21
+
22
+ //#endregion
23
+ export { createContext, globalContext, invalidateContextFile };
@@ -0,0 +1,12 @@
1
+ import ts from "typescript";
2
+
3
+ //#region src/tsc/context.d.ts
4
+ interface TscContext {
5
+ programs: ts.Program[];
6
+ files: Map<string, string>;
7
+ }
8
+ declare function createContext(): TscContext;
9
+ declare function invalidateContextFile(context: TscContext, file: string): void;
10
+ declare const globalContext: TscContext;
11
+ //#endregion
12
+ export { TscContext, createContext, globalContext, invalidateContextFile };
@@ -7,8 +7,8 @@ declare const RE_NODE_MODULES: RegExp;
7
7
  declare const RE_CSS: RegExp;
8
8
  declare const RE_VUE: RegExp;
9
9
  declare function filename_js_to_dts(id: string): string;
10
- declare function filename_ts_to_dts(id: string): string;
10
+ declare function filename_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, 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 };
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_to_dts, isRelative };
@@ -11,8 +11,8 @@ const RE_VUE = /\.vue$/;
11
11
  function filename_js_to_dts(id) {
12
12
  return id.replace(RE_JS, ".d.$1ts");
13
13
  }
14
- function filename_ts_to_dts(id) {
15
- return id.replace(RE_VUE, ".vue.ts").replace(RE_TS, ".d.$1ts");
14
+ function filename_to_dts(id) {
15
+ return id.replace(RE_VUE, ".vue.ts").replace(RE_TS, ".d.$1ts").replace(RE_JS, ".d.$1ts");
16
16
  }
17
17
  function filename_dts_to(id, ext) {
18
18
  return id.replace(RE_DTS, `.$1${ext}`);
@@ -22,4 +22,4 @@ function isRelative(id) {
22
22
  }
23
23
 
24
24
  //#endregion
25
- 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 };
25
+ 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_to_dts, isRelative };
@@ -1,2 +1,2 @@
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
- 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
+ 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_to_dts, isRelative } from "./filename-4MoswV50.js";
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_to_dts, isRelative };
package/dist/filename.js CHANGED
@@ -1,3 +1,3 @@
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-Dpr2dKWZ.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_to_dts, isRelative } from "./filename-Dz6Li3gj.js";
2
2
 
3
- 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 };
3
+ 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_to_dts, isRelative };
@@ -1,11 +1,12 @@
1
+ import { TscContext } from "./context-DIRjVfC4.js";
1
2
  import { TsConfigJson } from "get-tsconfig";
2
3
  import ts from "typescript";
3
4
  import { SourceMapInput } from "rolldown";
4
5
 
5
6
  //#region src/tsc/index.d.ts
6
- interface TscContext {
7
- programs: ts.Program[];
8
- files: Map<string, string>;
7
+ interface TscModule {
8
+ program: ts.Program;
9
+ file: ts.SourceFile;
9
10
  }
10
11
  interface TscOptions {
11
12
  tsconfig?: string;
@@ -17,7 +18,6 @@ interface TscOptions {
17
18
  vue?: boolean;
18
19
  context?: TscContext;
19
20
  }
20
- declare function createContext(): TscContext;
21
21
  interface TscResult {
22
22
  code?: string;
23
23
  map?: SourceMapInput;
@@ -25,4 +25,4 @@ interface TscResult {
25
25
  }
26
26
  declare function tscEmit(tscOptions: TscOptions): TscResult;
27
27
  //#endregion
28
- export { TscContext, createContext, tscEmit };
28
+ export { TscModule, TscOptions, TscResult, tscEmit };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE } from "./filename-TbnZq0n4.js";
2
- import { TscContext, createContext } from "./index-B4kTNEjT.js";
1
+ import { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE } from "./filename-4MoswV50.js";
3
2
  import { IsolatedDeclarationsOptions } from "rolldown/experimental";
4
3
  import { TsConfigJson } from "get-tsconfig";
5
4
  import { Plugin } from "rolldown";
@@ -63,7 +62,7 @@ interface Options {
63
62
  * [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
64
63
  * enabled.
65
64
  *
66
- * This option is only used when {@link Options.isolatedDeclarations} is
65
+ * This option is only used when {@link Options.oxc} is
67
66
  * `false`.
68
67
  */
69
68
  incremental?: boolean;
@@ -79,7 +78,7 @@ interface Options {
79
78
  *
80
79
  * This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
81
80
  */
82
- isolatedDeclarations?: boolean | Omit<IsolatedDeclarationsOptions, "sourcemap">;
81
+ oxc?: boolean | Omit<IsolatedDeclarationsOptions, "sourcemap">;
83
82
  /**
84
83
  * If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
85
84
  */
@@ -120,14 +119,23 @@ interface Options {
120
119
  * to speed up repeated builds. Enabling this option forces a clean context,
121
120
  * guaranteeing that all type definitions are generated from scratch.
122
121
  *
123
- * **Default:** `false`
122
+ * @default false
124
123
  */
125
124
  newContext?: boolean;
125
+ /**
126
+ * If `true`, the plugin will emit `.d.ts` files for `.js` files as well.
127
+ * This is useful when you want to generate type definitions for JavaScript files with JSDoc comments.
128
+ *
129
+ * Enabled by default when `allowJs` in compilerOptions is `true`.
130
+ * This option is only used when {@link Options.oxc} is
131
+ * `false`.
132
+ */
133
+ emitJs?: boolean;
126
134
  }
127
135
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
128
136
  type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
129
137
  tsconfig: string | undefined;
130
- isolatedDeclarations: IsolatedDeclarationsOptions | false;
138
+ oxc: IsolatedDeclarationsOptions | false;
131
139
  tsconfigRaw: TsConfigJson;
132
140
  }>;
133
141
  declare function resolveOptions({
@@ -136,7 +144,7 @@ declare function resolveOptions({
136
144
  incremental,
137
145
  compilerOptions,
138
146
  tsconfigRaw: overriddenTsconfigRaw,
139
- isolatedDeclarations,
147
+ oxc,
140
148
  sourcemap,
141
149
  dtsInput,
142
150
  emitDtsOnly,
@@ -145,7 +153,8 @@ declare function resolveOptions({
145
153
  parallel,
146
154
  eager,
147
155
  tsgo,
148
- newContext
156
+ newContext,
157
+ emitJs
149
158
  }: Options): OptionsResolved;
150
159
  //#endregion
151
160
  //#region src/fake-js.d.ts
@@ -160,16 +169,17 @@ declare function createGeneratePlugin({
160
169
  tsconfigRaw,
161
170
  incremental,
162
171
  cwd,
163
- isolatedDeclarations,
172
+ oxc,
164
173
  emitDtsOnly,
165
174
  vue,
166
175
  parallel,
167
176
  eager,
168
177
  tsgo,
169
- newContext
170
- }: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "incremental" | "isolatedDeclarations" | "emitDtsOnly" | "vue" | "parallel" | "eager" | "tsgo" | "newContext">): Plugin;
178
+ newContext,
179
+ emitJs
180
+ }: Pick<OptionsResolved, "cwd" | "tsconfig" | "tsconfigRaw" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs">): Plugin;
171
181
  //#endregion
172
182
  //#region src/index.d.ts
173
183
  declare function dts(options?: Options): Plugin[];
174
184
  //#endregion
175
- export { type Options, RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, type TscContext, createContext, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
185
+ export { type 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,16 +1,15 @@
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
- import { createContext } from "./tsc-Czx4mPt7.js";
3
- import path from "node:path";
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_to_dts } from "./filename-Dz6Li3gj.js";
2
+ import { createContext, globalContext, invalidateContextFile } from "./context-BG0dlajy.js";
4
3
  import Debug from "debug";
5
4
  import _generate from "@babel/generator";
6
5
  import { parse } from "@babel/parser";
7
6
  import * as t from "@babel/types";
8
7
  import { isDeclarationType, isTypeOf, resolveString } from "ast-kit";
8
+ import path from "node:path";
9
9
  import { fork, spawn } from "node:child_process";
10
10
  import { existsSync } from "node:fs";
11
11
  import { mkdtemp, readFile, rm } from "node:fs/promises";
12
12
  import { tmpdir } from "node:os";
13
- import { createBirpc } from "birpc";
14
13
  import { ResolverFactory, isolatedDeclaration } from "rolldown/experimental";
15
14
  import process from "node:process";
16
15
  import { getTsconfig, parseTsconfig } from "get-tsconfig";
@@ -243,7 +242,7 @@ function createFakeJsPlugin({ dtsInput, sourcemap }) {
243
242
  if (options.format === "cjs" || options.format === "commonjs") throw new Error("[rolldown-plugin-dts] Cannot bundle dts files with `cjs` format.");
244
243
  return {
245
244
  ...options,
246
- sourcemap: sourcemap ? true : options.sourcemap,
245
+ sourcemap: options.sourcemap || sourcemap,
247
246
  entryFileNames: options.entryFileNames ?? (dtsInput ? "[name].ts" : void 0),
248
247
  chunkFileNames(chunk) {
249
248
  const original = (typeof options.chunkFileNames === "function" ? options.chunkFileNames(chunk) : options.chunkFileNames) || "[name]-[hash].js";
@@ -634,13 +633,13 @@ function inheritNodeComments(oldNode, newNode) {
634
633
  //#endregion
635
634
  //#region src/generate.ts
636
635
  const debug$1 = Debug("rolldown-plugin-dts:generate");
637
- const WORKER_URL = "./tsc/worker.js";
636
+ const WORKER_URL = "./tsc-worker.js";
638
637
  const spawnAsync = (...args) => new Promise((resolve, reject) => {
639
638
  const child = spawn(...args);
640
639
  child.on("close", () => resolve());
641
640
  child.on("error", (error) => reject(error));
642
641
  });
643
- function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolatedDeclarations, emitDtsOnly, vue, parallel, eager, tsgo, newContext }) {
642
+ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, oxc, emitDtsOnly, vue, parallel, eager, tsgo, newContext, emitJs }) {
644
643
  const dtsMap = /* @__PURE__ */ new Map();
645
644
  /**
646
645
  * A map of input id to output file name
@@ -657,20 +656,19 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
657
656
  let tscModule;
658
657
  let tscContext;
659
658
  let tsgoDist;
660
- if (!tsgo && parallel) {
661
- childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
662
- rpc = createBirpc({}, {
663
- post: (data) => childProcess.send(data),
664
- on: (fn) => childProcess.on("message", fn)
665
- });
666
- }
667
659
  return {
668
660
  name: "rolldown-plugin-dts:generate",
669
661
  async buildStart(options) {
670
662
  if (tsgo) tsgoDist = await runTsgo(cwd, tsconfig);
671
- else if (!parallel && (!isolatedDeclarations || vue)) {
672
- tscModule = await import("./tsc-HJvJZNLs.js");
673
- if (newContext) tscContext = tscModule.createContext();
663
+ else if (!oxc) if (parallel) {
664
+ childProcess = fork(new URL(WORKER_URL, import.meta.url), { stdio: "inherit" });
665
+ rpc = (await import("birpc")).createBirpc({}, {
666
+ post: (data) => childProcess.send(data),
667
+ on: (fn) => childProcess.on("message", fn)
668
+ });
669
+ } else {
670
+ tscModule = await import("./tsc.js");
671
+ if (newContext) tscContext = createContext();
674
672
  }
675
673
  if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
676
674
  debug$1("resolving input alias %s -> %s", name, id);
@@ -701,13 +699,17 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
701
699
  transform: {
702
700
  order: "pre",
703
701
  filter: { id: {
704
- include: [RE_TS, RE_VUE],
702
+ include: [
703
+ RE_TS,
704
+ RE_VUE,
705
+ ...emitJs ? [RE_JS] : []
706
+ ],
705
707
  exclude: [RE_DTS, RE_NODE_MODULES]
706
708
  } },
707
709
  handler(code, id) {
708
710
  const mod = this.getModuleInfo(id);
709
711
  const isEntry = !!mod?.isEntry;
710
- const dtsId = filename_ts_to_dts(id);
712
+ const dtsId = filename_to_dts(id);
711
713
  dtsMap.set(dtsId, {
712
714
  code,
713
715
  id,
@@ -738,14 +740,14 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
738
740
  debug$1("generate dts %s from %s", dtsId, id);
739
741
  if (tsgo) {
740
742
  if (RE_VUE.test(id)) throw new Error("tsgo does not support Vue files.");
741
- const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(cwd), filename_ts_to_dts(id)));
743
+ const dtsPath = path.resolve(tsgoDist, path.relative(path.resolve(cwd), filename_to_dts(id)));
742
744
  if (existsSync(dtsPath)) dtsCode = await readFile(dtsPath, "utf8");
743
745
  else {
744
746
  debug$1("[tsgo]", dtsPath, "is missing");
745
747
  throw new Error(`tsgo did not generate dts file for ${id}, please check your tsconfig.`);
746
748
  }
747
- } else if (isolatedDeclarations && !RE_VUE.test(id)) {
748
- const result = isolatedDeclaration(id, code, isolatedDeclarations);
749
+ } else if (oxc && !RE_VUE.test(id)) {
750
+ const result = isolatedDeclaration(id, code, oxc);
749
751
  if (result.errors.length) {
750
752
  const [error] = result.errors;
751
753
  return this.error({
@@ -795,6 +797,9 @@ function createGeneratePlugin({ tsconfig, tsconfigRaw, incremental, cwd, isolate
795
797
  }).catch(() => {});
796
798
  tsgoDist = void 0;
797
799
  if (newContext) tscContext = void 0;
800
+ },
801
+ watchChange(id) {
802
+ if (tscModule) invalidateContextFile(tscContext || globalContext, id);
798
803
  }
799
804
  };
800
805
  }
@@ -822,7 +827,7 @@ async function runTsgo(root, tsconfig) {
822
827
  //#endregion
823
828
  //#region src/options.ts
824
829
  let warnedTsgo = false;
825
- 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, newContext = false }) {
830
+ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, compilerOptions = {}, tsconfigRaw: overriddenTsconfigRaw = {}, oxc, sourcemap, dtsInput = false, emitDtsOnly = false, resolve = false, vue = false, parallel = false, eager = false, tsgo = false, newContext = false, emitJs }) {
826
831
  let resolvedTsconfig;
827
832
  if (tsconfig === true || tsconfig == null) {
828
833
  const { config, path: path$1 } = getTsconfig(cwd) || {};
@@ -844,12 +849,18 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, co
844
849
  ...overriddenTsconfigRaw,
845
850
  compilerOptions
846
851
  };
847
- if (isolatedDeclarations == null) isolatedDeclarations = !!compilerOptions?.isolatedDeclarations;
848
- if (isolatedDeclarations === true) isolatedDeclarations = {};
849
- if (isolatedDeclarations) {
850
- isolatedDeclarations.stripInternal ??= !!compilerOptions?.stripInternal;
851
- isolatedDeclarations.sourcemap = !!compilerOptions.declarationMap;
852
+ oxc ??= !!(compilerOptions?.isolatedDeclarations && !vue && !tsgo);
853
+ if (oxc === true) oxc = {};
854
+ if (oxc) {
855
+ oxc.stripInternal ??= !!compilerOptions?.stripInternal;
856
+ oxc.sourcemap = !!compilerOptions.declarationMap;
857
+ }
858
+ emitJs ??= !!(compilerOptions.checkJs || compilerOptions.allowJs);
859
+ if (tsgo) {
860
+ if (vue) throw new Error("[rolldown-plugin-dts] The `tsgo` option is not compatible with the `vue` option. Please disable one of them.");
861
+ if (oxc) throw new Error("[rolldown-plugin-dts] The `tsgo` option is not compatible with the `oxc` option. Please disable one of them.");
852
862
  }
863
+ if (oxc && vue) throw new Error("[rolldown-plugin-dts] The `oxc` option is not compatible with the `vue` option. Please disable one of them.");
853
864
  if (tsgo && !warnedTsgo) {
854
865
  console.warn("The `tsgo` option is experimental and may change in the future.");
855
866
  warnedTsgo = true;
@@ -859,7 +870,7 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, co
859
870
  tsconfig,
860
871
  tsconfigRaw,
861
872
  incremental,
862
- isolatedDeclarations,
873
+ oxc,
863
874
  sourcemap,
864
875
  dtsInput,
865
876
  emitDtsOnly,
@@ -868,7 +879,8 @@ function resolveOptions({ cwd = process.cwd(), tsconfig, incremental = false, co
868
879
  parallel,
869
880
  eager,
870
881
  tsgo,
871
- newContext
882
+ newContext,
883
+ emitJs
872
884
  };
873
885
  }
874
886
 
@@ -911,7 +923,7 @@ function createDtsResolvePlugin({ tsconfig, resolve }) {
911
923
  }
912
924
  if (RE_TS.test(resolution) && !RE_DTS.test(resolution) || RE_VUE.test(resolution)) {
913
925
  await this.load({ id: resolution });
914
- resolution = filename_ts_to_dts(resolution);
926
+ resolution = filename_to_dts(resolution);
915
927
  }
916
928
  if (RE_DTS.test(resolution)) return resolution;
917
929
  }
@@ -934,4 +946,4 @@ function dts(options = {}) {
934
946
  }
935
947
 
936
948
  //#endregion
937
- export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createContext, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
949
+ export { RE_CSS, RE_DTS, RE_DTS_MAP, RE_JS, RE_NODE_MODULES, RE_TS, RE_VUE, createFakeJsPlugin, createGeneratePlugin, dts, resolveOptions };
@@ -1,6 +1,7 @@
1
+ import { globalContext } from "./context-BG0dlajy.js";
1
2
  import { createRequire } from "node:module";
2
- import path from "node:path";
3
3
  import Debug from "debug";
4
+ import path from "node:path";
4
5
  import ts from "typescript";
5
6
 
6
7
  //#region src/tsc/system.ts
@@ -92,15 +93,6 @@ function createVueProgramFactory(ts$1) {
92
93
  //#region src/tsc/index.ts
93
94
  const debug = Debug("rolldown-plugin-dts:tsc");
94
95
  debug(`loaded typescript: ${ts.version}`);
95
- function createContext() {
96
- const programs = [];
97
- const files = /* @__PURE__ */ new Map();
98
- return {
99
- programs,
100
- files
101
- };
102
- }
103
- const globalContext = createContext();
104
96
  const formatHost = {
105
97
  getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
106
98
  getNewLine: () => ts.sys.newLine,
@@ -277,4 +269,4 @@ function tscEmit(tscOptions) {
277
269
  }
278
270
 
279
271
  //#endregion
280
- export { createContext, tscEmit };
272
+ export { tscEmit };
@@ -0,0 +1,2 @@
1
+ import { TscContext, createContext, globalContext, invalidateContextFile } from "./context-DIRjVfC4.js";
2
+ export { TscContext, createContext, globalContext, invalidateContextFile };
@@ -0,0 +1,3 @@
1
+ import { createContext, globalContext, invalidateContextFile } from "./context-BG0dlajy.js";
2
+
3
+ export { createContext, globalContext, invalidateContextFile };
@@ -1,4 +1,5 @@
1
- import { tscEmit } from "../index-B4kTNEjT.js";
1
+ import "./context-DIRjVfC4.js";
2
+ import { tscEmit } from "./index-D_X_vGiL.js";
2
3
 
3
4
  //#region src/tsc/worker.d.ts
4
5
  declare const functions: {
@@ -1,6 +1,7 @@
1
- import { tscEmit } from "../tsc-Czx4mPt7.js";
2
- import { createBirpc } from "birpc";
1
+ import "./context-BG0dlajy.js";
2
+ import { tscEmit } from "./tsc-BjWJCGE1.js";
3
3
  import process from "node:process";
4
+ import { createBirpc } from "birpc";
4
5
 
5
6
  //#region src/tsc/worker.ts
6
7
  const functions = { tscEmit };
package/dist/tsc.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import "./context-DIRjVfC4.js";
2
+ import { TscModule, TscOptions, TscResult, tscEmit } from "./index-D_X_vGiL.js";
3
+ export { TscModule, TscOptions, TscResult, tscEmit };
package/dist/tsc.js ADDED
@@ -0,0 +1,4 @@
1
+ import "./context-BG0dlajy.js";
2
+ import { tscEmit } from "./tsc-BjWJCGE1.js";
3
+
4
+ export { tscEmit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-plugin-dts",
3
- "version": "0.14.2",
3
+ "version": "0.15.0",
4
4
  "description": "A Rolldown plugin to bundle dts files",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -23,6 +23,9 @@
23
23
  "exports": {
24
24
  ".": "./dist/index.js",
25
25
  "./filename": "./dist/filename.js",
26
+ "./tsc": "./dist/tsc.js",
27
+ "./tsc-context": "./dist/tsc-context.js",
28
+ "./tsc-worker": "./dist/tsc-worker.js",
26
29
  "./package.json": "./package.json"
27
30
  },
28
31
  "publishConfig": {
@@ -56,13 +59,13 @@
56
59
  "get-tsconfig": "^4.10.1"
57
60
  },
58
61
  "devDependencies": {
59
- "@sxzz/eslint-config": "^7.1.0",
62
+ "@sxzz/eslint-config": "^7.1.2",
60
63
  "@sxzz/prettier-config": "^2.2.3",
61
- "@sxzz/test-utils": "^0.5.7",
64
+ "@sxzz/test-utils": "^0.5.9",
62
65
  "@types/babel__generator": "^7.27.0",
63
66
  "@types/debug": "^4.1.12",
64
67
  "@types/node": "^24.1.0",
65
- "@typescript/native-preview": "7.0.0-dev.20250728.1",
68
+ "@typescript/native-preview": "7.0.0-dev.20250731.1",
66
69
  "@volar/typescript": "^2.4.22",
67
70
  "@vue/language-core": "^3.0.4",
68
71
  "bumpp": "^10.2.1",
@@ -70,11 +73,10 @@
70
73
  "eslint": "^9.32.0",
71
74
  "estree-walker": "^3.0.3",
72
75
  "prettier": "^3.6.2",
73
- "rolldown": "^1.0.0-beta.29",
76
+ "rolldown": "^1.0.0-beta.30",
74
77
  "rollup-plugin-dts": "^6.2.1",
75
78
  "tinyglobby": "^0.2.14",
76
79
  "tsdown": "^0.13.0",
77
- "tsx": "^4.20.3",
78
80
  "typescript": "^5.8.3",
79
81
  "vitest": "^3.2.4",
80
82
  "vue": "^3.5.18",
@@ -1,3 +0,0 @@
1
- import { createContext, tscEmit } from "./tsc-Czx4mPt7.js";
2
-
3
- export { createContext, tscEmit };