rolldown-plugin-dts 0.26.0 → 0.27.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,4 @@
1
1
  import ts from "typescript";
2
-
3
2
  //#region src/tsc/context.d.ts
4
3
  interface ParsedProject {
5
4
  tsconfigPath: string;
@@ -1,8 +1,7 @@
1
- import { r as TscContext } from "./context-_3g_7Eca.mjs";
1
+ import { r as TscContext } from "./context-CcXGRVeM.mjs";
2
2
  import { SourceMapInput } from "rolldown";
3
3
  import { TsconfigJson } from "get-tsconfig";
4
4
  import ts from "typescript";
5
-
6
5
  //#region src/tsc/types.d.ts
7
6
  interface TscModule {
8
7
  program: ts.Program;
package/dist/index.d.mts CHANGED
@@ -1,205 +1,204 @@
1
1
  import { Plugin } from "rolldown";
2
2
  import { IsolatedDeclarationsOptions } from "rolldown/experimental";
3
3
  import { TsconfigJson } from "get-tsconfig";
4
-
5
4
  //#region src/options.d.ts
6
5
  interface GeneralOptions {
7
6
  /**
8
- * Glob pattern(s) to filter which entry files get `.d.ts` generation.
9
- *
10
- * When specified, only entry files matching these patterns will emit `.d.ts` chunks.
11
- * When not specified, all entries get `.d.ts` generation.
12
- *
13
- * Supports negation patterns (e.g., `['**', '!src/icons/**']`) for exclusion.
14
- * Patterns are matched against file paths relative to `cwd`.
15
- *
16
- * @example
17
- * entry: 'src/index.ts'
18
- * entry: ['src/*.ts', '!src/internal/**']
19
- */
7
+ * Glob pattern(s) to filter which entry files get `.d.ts` generation.
8
+ *
9
+ * When specified, only entry files matching these patterns will emit `.d.ts` chunks.
10
+ * When not specified, all entries get `.d.ts` generation.
11
+ *
12
+ * Supports negation patterns (e.g., `['**', '!src/icons/**']`) for exclusion.
13
+ * Patterns are matched against file paths relative to `cwd`.
14
+ *
15
+ * @example
16
+ * entry: 'src/index.ts'
17
+ * entry: ['src/*.ts', '!src/internal/**']
18
+ */
20
19
  entry?: string | string[];
21
20
  /**
22
- * The directory in which the plugin will search for the `tsconfig.json` file.
23
- */
21
+ * The directory in which the plugin will search for the `tsconfig.json` file.
22
+ */
24
23
  cwd?: string;
25
24
  /**
26
- * Set to `true` if your entry files are `.d.ts` files instead of `.ts` files.
27
- *
28
- * When enabled, the plugin will skip generating a `.d.ts` file for the entry point.
29
- */
25
+ * Set to `true` if your entry files are `.d.ts` files instead of `.ts` files.
26
+ *
27
+ * When enabled, the plugin will skip generating a `.d.ts` file for the entry point.
28
+ */
30
29
  dtsInput?: boolean;
31
30
  /**
32
- * If `true`, the plugin will emit only `.d.ts` files and remove all other output chunks.
33
- *
34
- * This is especially useful when generating `.d.ts` files for the CommonJS format as part of a separate build step.
35
- */
31
+ * If `true`, the plugin will emit only `.d.ts` files and remove all other output chunks.
32
+ *
33
+ * This is especially useful when generating `.d.ts` files for the CommonJS format as part of a separate build step.
34
+ */
36
35
  emitDtsOnly?: boolean;
37
36
  /**
38
- * The path to the `tsconfig.json` file.
39
- *
40
- * If set to `false`, the plugin will ignore any `tsconfig.json` file.
41
- * You can still specify `compilerOptions` directly in the options.
42
- *
43
- * @default 'tsconfig.json'
44
- */
37
+ * The path to the `tsconfig.json` file.
38
+ *
39
+ * If set to `false`, the plugin will ignore any `tsconfig.json` file.
40
+ * You can still specify `compilerOptions` directly in the options.
41
+ *
42
+ * @default 'tsconfig.json'
43
+ */
45
44
  tsconfig?: string | boolean;
46
45
  /**
47
- * Pass a raw `tsconfig.json` object directly to the plugin.
48
- *
49
- * @see https://www.typescriptlang.org/tsconfig
50
- */
46
+ * Pass a raw `tsconfig.json` object directly to the plugin.
47
+ *
48
+ * @see https://www.typescriptlang.org/tsconfig
49
+ */
51
50
  tsconfigRaw?: Omit<TsconfigJson, "compilerOptions">;
52
51
  /**
53
- * Override the `compilerOptions` specified in `tsconfig.json`.
54
- *
55
- * @see https://www.typescriptlang.org/tsconfig/#compilerOptions
56
- */
52
+ * Override the `compilerOptions` specified in `tsconfig.json`.
53
+ *
54
+ * @see https://www.typescriptlang.org/tsconfig/#compilerOptions
55
+ */
57
56
  compilerOptions?: TsconfigJson.CompilerOptions;
58
57
  /**
59
- * If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
60
- */
58
+ * If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
59
+ */
61
60
  sourcemap?: boolean;
62
61
  /**
63
- * Specifies a resolver to resolve type definitions, especially for `node_modules`.
64
- *
65
- * - `'oxc'`: Uses Oxc's module resolution, which is faster and more efficient.
66
- * - `'tsc'`: Uses TypeScript's native module resolution, which may be more compatible with complex setups, but slower.
67
- *
68
- * @default 'oxc'
69
- */
62
+ * Specifies a resolver to resolve type definitions, especially for `node_modules`.
63
+ *
64
+ * - `'oxc'`: Uses Oxc's module resolution, which is faster and more efficient.
65
+ * - `'tsc'`: Uses TypeScript's native module resolution, which may be more compatible with complex setups, but slower.
66
+ *
67
+ * @default 'oxc'
68
+ */
70
69
  resolver?: "oxc" | "tsc";
71
70
  /**
72
- * Determines how the default export is emitted.
73
- *
74
- * If set to `true`, and you are only exporting a single item using `export default ...`,
75
- * the output will use `export = ...` instead of the standard ES module syntax.
76
- * This is useful for compatibility with CommonJS.
77
- * This only controls the output format and does not enable support for
78
- * CommonJS-style `.d.ts` input.
79
- */
71
+ * Determines how the default export is emitted.
72
+ *
73
+ * If set to `true`, and you are only exporting a single item using `export default ...`,
74
+ * the output will use `export = ...` instead of the standard ES module syntax.
75
+ * This is useful for compatibility with CommonJS.
76
+ * This only controls the output format and does not enable support for
77
+ * CommonJS-style `.d.ts` input.
78
+ */
80
79
  cjsDefault?: boolean;
81
80
  /**
82
- * Indicates whether the generated `.d.ts` files have side effects.
83
- * - If set to `true`, Rolldown will treat the `.d.ts` files as having side effects during tree-shaking.
84
- * - If set to `false`, Rolldown may consider the `.d.ts` files as side-effect-free, potentially removing them if they are not imported.
85
- *
86
- * @default false
87
- */
81
+ * Indicates whether the generated `.d.ts` files have side effects.
82
+ * - If set to `true`, Rolldown will treat the `.d.ts` files as having side effects during tree-shaking.
83
+ * - If set to `false`, Rolldown may consider the `.d.ts` files as side-effect-free, potentially removing them if they are not imported.
84
+ *
85
+ * @default false
86
+ */
88
87
  sideEffects?: boolean;
89
88
  }
90
89
  interface TscOptions {
91
90
  /**
92
- * Build mode for the TypeScript compiler:
93
- *
94
- * - If `true`, 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.
95
- * - If `false`, the plugin will use [`tsc`](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to emit `.d.ts` files without building referenced projects.
96
- *
97
- * @default false
98
- */
91
+ * Build mode for the TypeScript compiler:
92
+ *
93
+ * - If `true`, 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.
94
+ * - If `false`, the plugin will use [`tsc`](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to emit `.d.ts` files without building referenced projects.
95
+ *
96
+ * @default false
97
+ */
99
98
  build?: boolean;
100
99
  /**
101
- * If your tsconfig.json has
102
- * [`references`](https://www.typescriptlang.org/tsconfig/#references) option,
103
- * `rolldown-plugin-dts` will use [`tsc
104
- * -b`](https://www.typescriptlang.org/docs/handbook/project-references.html#build-mode-for-typescript)
105
- * to build the project and all referenced projects before emitting `.d.ts`
106
- * files.
107
- *
108
- * In such case, if this option is `true`, `rolldown-plugin-dts` will write
109
- * down all built files into your disk, including
110
- * [`.tsbuildinfo`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
111
- * and other built files. This is equivalent to running `tsc -b` in your
112
- * project.
113
- *
114
- * Otherwise, if this option is `false`, `rolldown-plugin-dts` will write
115
- * built files only into memory and leave a small footprint in your disk.
116
- *
117
- * Enabling this option will decrease the build time by caching previous build
118
- * results. This is helpful when you have a large project with multiple
119
- * referenced projects.
120
- *
121
- * By default, `incremental` is `true` if your tsconfig has
122
- * [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or
123
- * [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
124
- * enabled.
125
- *
126
- * This option is only used when {@link Options.oxc} is
127
- * `false`.
128
- */
100
+ * If your tsconfig.json has
101
+ * [`references`](https://www.typescriptlang.org/tsconfig/#references) option,
102
+ * `rolldown-plugin-dts` will use [`tsc
103
+ * -b`](https://www.typescriptlang.org/docs/handbook/project-references.html#build-mode-for-typescript)
104
+ * to build the project and all referenced projects before emitting `.d.ts`
105
+ * files.
106
+ *
107
+ * In such case, if this option is `true`, `rolldown-plugin-dts` will write
108
+ * down all built files into your disk, including
109
+ * [`.tsbuildinfo`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
110
+ * and other built files. This is equivalent to running `tsc -b` in your
111
+ * project.
112
+ *
113
+ * Otherwise, if this option is `false`, `rolldown-plugin-dts` will write
114
+ * built files only into memory and leave a small footprint in your disk.
115
+ *
116
+ * Enabling this option will decrease the build time by caching previous build
117
+ * results. This is helpful when you have a large project with multiple
118
+ * referenced projects.
119
+ *
120
+ * By default, `incremental` is `true` if your tsconfig has
121
+ * [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) or
122
+ * [`tsBuildInfoFile`](https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile)
123
+ * enabled.
124
+ *
125
+ * This option is only used when {@link Options.oxc} is
126
+ * `false`.
127
+ */
129
128
  incremental?: boolean;
130
129
  /**
131
- * If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
132
- */
130
+ * If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
131
+ */
133
132
  vue?: boolean;
134
133
  /**
135
- * If `true`, the plugin will generate `.d.ts` files using `@ts-macro/tsc`.
136
- */
134
+ * If `true`, the plugin will generate `.d.ts` files using `@ts-macro/tsc`.
135
+ */
137
136
  tsMacro?: boolean;
138
137
  /**
139
- * If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`.
140
- * This enables processing multiple projects in parallel.
141
- */
138
+ * If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`.
139
+ * This enables processing multiple projects in parallel.
140
+ */
142
141
  parallel?: boolean;
143
142
  /**
144
- * If `true`, the plugin will prepare all files listed in `tsconfig.json` for `tsc` or `vue-tsc`.
145
- *
146
- * This is especially useful when you have a single `tsconfig.json` for multiple projects in a monorepo.
147
- */
143
+ * If `true`, the plugin will prepare all files listed in `tsconfig.json` for `tsc` or `vue-tsc`.
144
+ *
145
+ * This is especially useful when you have a single `tsconfig.json` for multiple projects in a monorepo.
146
+ */
148
147
  eager?: boolean;
149
148
  /**
150
- * If `true`, the plugin will create a new isolated context for each build,
151
- * ensuring that previously generated `.d.ts` code and caches are not reused.
152
- *
153
- * By default, the plugin may reuse internal caches or incremental build artifacts
154
- * to speed up repeated builds. Enabling this option forces a clean context,
155
- * guaranteeing that all type definitions are generated from scratch.
156
- *
157
- * @default false
158
- */
149
+ * If `true`, the plugin will create a new isolated context for each build,
150
+ * ensuring that previously generated `.d.ts` code and caches are not reused.
151
+ *
152
+ * By default, the plugin may reuse internal caches or incremental build artifacts
153
+ * to speed up repeated builds. Enabling this option forces a clean context,
154
+ * guaranteeing that all type definitions are generated from scratch.
155
+ *
156
+ * @default false
157
+ */
159
158
  newContext?: boolean;
160
159
  /**
161
- * If `true`, the plugin will emit `.d.ts` files for `.js` files as well.
162
- * This is useful when you want to generate type definitions for JavaScript files with JSDoc comments.
163
- *
164
- * Enabled by default when `allowJs` in compilerOptions is `true`.
165
- * This option is only used when {@link Options.oxc} is
166
- * `false`.
167
- */
160
+ * If `true`, the plugin will emit `.d.ts` files for `.js` files as well.
161
+ * This is useful when you want to generate type definitions for JavaScript files with JSDoc comments.
162
+ *
163
+ * Enabled by default when `allowJs` in compilerOptions is `true`.
164
+ * This option is only used when {@link Options.oxc} is
165
+ * `false`.
166
+ */
168
167
  emitJs?: boolean;
169
168
  }
170
169
  interface Options extends GeneralOptions, TscOptions {
171
170
  /**
172
- * If `true`, the plugin will generate `.d.ts` files using Oxc,
173
- * which is significantly faster than the TypeScript compiler.
174
- *
175
- * This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
176
- */
171
+ * If `true`, the plugin will generate `.d.ts` files using Oxc,
172
+ * which is significantly faster than the TypeScript compiler.
173
+ *
174
+ * This option is automatically enabled when `isolatedDeclarations` in `compilerOptions` is set to `true`.
175
+ */
177
176
  oxc?: boolean | Omit<IsolatedDeclarationsOptions, "sourcemap">;
178
177
  /**
179
- * **[Experimental]** Enables DTS generation using `tsgo`.
180
- *
181
- * To use this option, make sure `@typescript/native-preview` is installed as a dependency,
182
- * or provide a custom path to the `tsgo` binary using the `path` option.
183
- *
184
- * **Note:** This option is not yet recommended for production environments.
185
- * `tsconfigRaw` and `isolatedDeclarations` options will be ignored when this option is enabled.
186
- *
187
- *
188
- * ```ts
189
- * // Use tsgo from `@typescript/native-preview` dependency
190
- * tsgo: true
191
- *
192
- * // Use custom tsgo path (e.g., managed by Nix)
193
- * tsgo: { path: '/path/to/tsgo' }
194
- * ```
195
- */
178
+ * **[Experimental]** Enables DTS generation using `tsgo`.
179
+ *
180
+ * To use this option, make sure `@typescript/native-preview` is installed as a dependency,
181
+ * or provide a custom path to the `tsgo` binary using the `path` option.
182
+ *
183
+ * **Note:** This option is not yet recommended for production environments.
184
+ * `tsconfigRaw` and `isolatedDeclarations` options will be ignored when this option is enabled.
185
+ *
186
+ *
187
+ * ```ts
188
+ * // Use tsgo from `@typescript/native-preview` dependency
189
+ * tsgo: true
190
+ *
191
+ * // Use custom tsgo path (e.g., managed by Nix)
192
+ * tsgo: { path: '/path/to/tsgo' }
193
+ * ```
194
+ */
196
195
  tsgo?: boolean | TsgoOptions;
197
196
  }
198
197
  interface TsgoOptions {
199
198
  enabled?: boolean;
200
199
  /**
201
- * Custom path to the `tsgo` binary.
202
- */
200
+ * Custom path to the `tsgo` binary.
201
+ */
203
202
  path?: string;
204
203
  }
205
204
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
@@ -210,56 +209,13 @@ type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
210
209
  tsconfigRaw: TsconfigJson;
211
210
  tsgo: Omit<TsgoOptions, "enabled"> | false;
212
211
  }>;
213
- declare function resolveOptions({
214
- entry,
215
- cwd,
216
- dtsInput,
217
- emitDtsOnly,
218
- tsconfig,
219
- tsconfigRaw: overriddenTsconfigRaw,
220
- compilerOptions,
221
- sourcemap,
222
- resolver,
223
- cjsDefault,
224
- sideEffects,
225
- build,
226
- incremental,
227
- vue,
228
- tsMacro,
229
- parallel,
230
- eager,
231
- newContext,
232
- emitJs,
233
- oxc,
234
- tsgo
235
- }: Options): OptionsResolved;
212
+ declare function resolveOptions({ entry, cwd, dtsInput, emitDtsOnly, tsconfig, tsconfigRaw: overriddenTsconfigRaw, compilerOptions, sourcemap, resolver, cjsDefault, sideEffects, build, incremental, vue, tsMacro, parallel, eager, newContext, emitJs, oxc, tsgo }: Options): OptionsResolved;
236
213
  //#endregion
237
214
  //#region src/fake-js.d.ts
238
- declare function createFakeJsPlugin({
239
- sourcemap,
240
- cjsDefault,
241
- sideEffects
242
- }: Pick<OptionsResolved, "sourcemap" | "cjsDefault" | "sideEffects">): Plugin;
215
+ declare function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }: Pick<OptionsResolved, "sourcemap" | "cjsDefault" | "sideEffects">): Plugin;
243
216
  //#endregion
244
217
  //#region src/generate.d.ts
245
- declare function createGeneratePlugin({
246
- entry,
247
- tsconfig,
248
- tsconfigRaw,
249
- build,
250
- incremental,
251
- cwd,
252
- oxc,
253
- emitDtsOnly,
254
- vue,
255
- tsMacro,
256
- parallel,
257
- eager,
258
- tsgo,
259
- newContext,
260
- emitJs,
261
- sourcemap
262
- }: Pick<OptionsResolved, "entry" | "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "tsMacro" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap">): Plugin;
218
+ declare function createGeneratePlugin({ entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap }: Pick<OptionsResolved, "entry" | "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "tsMacro" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap">): Plugin;
263
219
  //#endregion
264
220
  //#region src/index.d.ts
265
221
  declare function dts(options?: Options): Plugin[];