rolldown-plugin-dts 0.27.9 → 0.27.11

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
@@ -182,6 +182,20 @@ Enabling this option can speed up builds by caching previous results, which is h
182
182
 
183
183
  If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
184
184
 
185
+ This is a shortcut that registers the built-in Vue [Volar](https://volarjs.dev/) plugin.
186
+
187
+ #### `volarPlugins`
188
+
189
+ > [!WARNING]
190
+ > Experimental. The API may change in future versions.
191
+
192
+ Registers custom [Volar](https://volarjs.dev/) language plugins, allowing the
193
+ `tsc` generator to process non-standard file types (such as `.vue`) when
194
+ generating `.d.ts` files.
195
+
196
+ Enabling this option forces the `tsc` generator and is not supported with
197
+ TypeScript 7.0. The `vue` option is a preconfigured shortcut for the Vue plugin.
198
+
185
199
  #### `parallel`
186
200
 
187
201
  If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`, enabling parallel processing of multiple projects.
@@ -204,7 +218,10 @@ guaranteeing that all type definitions are generated from scratch.
204
218
  `invalidateContextFile` API can be used to clear invalidated files from the context.
205
219
 
206
220
  ```ts
207
- import { globalContext, invalidateContextFile } from 'rolldown-plugin-dts/tsc-context'
221
+ import {
222
+ globalContext,
223
+ invalidateContextFile,
224
+ } from 'rolldown-plugin-dts/tsc-context'
208
225
  invalidateContextFile(globalContext, 'src/foo.ts')
209
226
  ```
210
227
 
@@ -1,12 +1,12 @@
1
- import ts from "typescript";
1
+ import { ParsedCommandLine, Program } from "typescript";
2
2
  //#region src/tsc/context.d.ts
3
3
  interface ParsedProject {
4
4
  tsconfigPath: string;
5
- parsedConfig: ts.ParsedCommandLine;
5
+ parsedConfig: ParsedCommandLine;
6
6
  }
7
7
  type SourceFileToProjectMap = Map<string, ParsedProject>;
8
8
  interface TscContext {
9
- programs: ts.Program[];
9
+ programs: Program[];
10
10
  files: Map<string, string>;
11
11
  projects: Map<string, SourceFileToProjectMap>;
12
12
  }
@@ -7,14 +7,14 @@ const RE_DTS = /\.d\.([cm]?)ts$/;
7
7
  const RE_DTS_MAP = /\.d\.([cm]?)ts\.map$/;
8
8
  const RE_NODE_MODULES = /[\\/]node_modules[\\/]/;
9
9
  const RE_CSS = /\.(?:css|scss|sass|less|styl|stylus)$/;
10
- const RE_VUE = /\.vue$/;
11
10
  const RE_JSON = /\.json$/;
12
11
  const RE_ROLLDOWN_RUNTIME = exactRegex(RUNTIME_MODULE_ID);
13
12
  function filename_js_to_dts(id) {
14
13
  return id.replace(RE_JS, ".d.$1ts");
15
14
  }
16
- function filename_to_dts(id) {
17
- return id.replace(RE_VUE, ".vue.ts").replace(RE_TS, ".d.$1ts").replace(RE_JS, ".d.$1ts").replace(RE_JSON, ".json.d.ts");
15
+ function filename_to_dts(id, volarContext) {
16
+ id = volarContext?.toTsFilename?.(id) ?? id;
17
+ return id.replace(RE_TS, ".d.$1ts").replace(RE_JS, ".d.$1ts").replace(RE_JSON, ".json.d.ts");
18
18
  }
19
19
  function filename_dts_to(id, ext) {
20
20
  return id.replace(RE_DTS, `.$1${ext}`);
@@ -26,4 +26,4 @@ function replaceTemplateName(template, name) {
26
26
  return template.replaceAll("[name]", name);
27
27
  }
28
28
  //#endregion
29
- export { RE_JSON as a, RE_TS as c, filename_js_to_dts as d, filename_to_dts as f, RE_JS as i, RE_VUE as l, resolveTemplateFn as m, RE_DTS as n, RE_NODE_MODULES as o, replaceTemplateName as p, RE_DTS_MAP as r, RE_ROLLDOWN_RUNTIME as s, RE_CSS as t, filename_dts_to as u };
29
+ export { RE_JSON as a, RE_TS as c, filename_to_dts as d, replaceTemplateName as f, RE_JS as i, filename_dts_to as l, RE_DTS as n, RE_NODE_MODULES as o, resolveTemplateFn as p, RE_DTS_MAP as r, RE_ROLLDOWN_RUNTIME as s, RE_CSS as t, filename_js_to_dts as u };
@@ -1,7 +1,8 @@
1
- import { r as TscContext } from "./context-CcXGRVeM.mjs";
1
+ import { t as VolarContext } from "./volar-ynbQeQZt.mjs";
2
+ import { r as TscContext } from "./context-CxNQgl9o.mjs";
2
3
  import { SourceMapInput } from "rolldown";
3
4
  import { TsconfigJson } from "get-tsconfig";
4
- import ts from "typescript";
5
+ import * as ts from "typescript";
5
6
  //#region src/tsc/types.d.ts
6
7
  interface TscModule {
7
8
  program: ts.Program;
@@ -16,8 +17,7 @@ interface TscOptions {
16
17
  entries?: string[];
17
18
  id: string;
18
19
  sourcemap: boolean;
19
- vue?: boolean;
20
- tsMacro?: boolean;
20
+ volarContext: VolarContext;
21
21
  context?: TscContext;
22
22
  }
23
23
  interface TscResult {
package/dist/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import { n as VolarPlugin, t as VolarContext } from "./volar-ynbQeQZt.mjs";
1
2
  import { Plugin } from "rolldown";
2
3
  import { IsolatedDeclarationsOptions } from "rolldown/experimental";
3
4
  import { TsconfigJson } from "get-tsconfig";
@@ -24,8 +25,7 @@ interface GeneralOptions {
24
25
  * `isolatedDeclarations` is enabled in `compilerOptions`.
25
26
  * - `'tsgo'` if TypeScript 7.0 (or `@typescript/native-preview`) is installed,
26
27
  * or {@link Options.tsgo tsgo} options are provided.
27
- * - `'tsc'` otherwise, and always when {@link TscOptions.vue vue} or
28
- * {@link TscOptions.tsMacro tsMacro} is enabled.
28
+ * - `'tsc'` otherwise, and always when {@link TscOptions.vue vue} is enabled.
29
29
  *
30
30
  * @default 'tsc'
31
31
  */
@@ -158,10 +158,6 @@ interface TscOptions {
158
158
  * If `true`, the plugin will generate `.d.ts` files using `vue-tsc`.
159
159
  */
160
160
  vue?: boolean;
161
- /**
162
- * If `true`, the plugin will generate `.d.ts` files using `@ts-macro/tsc`.
163
- */
164
- tsMacro?: boolean;
165
161
  /**
166
162
  * If `true`, the plugin will launch a separate process for `tsc` or `vue-tsc`.
167
163
  * This enables processing multiple projects in parallel.
@@ -225,6 +221,18 @@ interface Options extends GeneralOptions, TscOptions {
225
221
  * ```
226
222
  */
227
223
  tsgo?: boolean | TsgoOptions;
224
+ /**
225
+ * Registers custom {@link https://volarjs.dev Volar} language plugins,
226
+ * allowing the `tsc` generator to process non-standard file types (such as
227
+ * `.vue`) when generating `.d.ts` files. Multiple plugins can be provided and
228
+ * are applied together.
229
+ *
230
+ * Enabling this option forces the `tsc` generator and is not supported with
231
+ * TypeScript 7.0.
232
+ *
233
+ * @experimental The API may change in future versions.
234
+ */
235
+ volarPlugins?: VolarPlugin[];
228
236
  }
229
237
  interface TsgoOptions {
230
238
  /**
@@ -233,20 +241,21 @@ interface TsgoOptions {
233
241
  path?: string;
234
242
  }
235
243
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
236
- type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions">>, {
244
+ type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions" | "vue" | "volarPlugins">>, {
237
245
  entry?: string[];
238
246
  tsconfig?: string;
239
247
  oxc: IsolatedDeclarationsOptions;
240
248
  tsconfigRaw: TsconfigJson;
241
249
  tsgo: TsgoOptions;
250
+ volarContext: VolarContext;
242
251
  }>;
243
- declare function resolveOptions({ generator, entry, cwd, dtsInput, emitDtsOnly, tsconfig, tsconfigRaw: overriddenTsconfigRaw, compilerOptions, sourcemap, resolver, cjsDefault, sideEffects, logger, build, incremental, vue, tsMacro, parallel, eager, newContext, emitJs, oxc, tsgo }: Options): OptionsResolved;
252
+ declare function resolveOptions({ generator, entry, cwd, dtsInput, emitDtsOnly, tsconfig, tsconfigRaw: overriddenTsconfigRaw, compilerOptions, sourcemap, resolver, cjsDefault, sideEffects, logger, volarPlugins, build, incremental, vue, parallel, eager, newContext, emitJs, oxc, tsgo }: Options): OptionsResolved;
244
253
  //#endregion
245
254
  //#region src/fake-js.d.ts
246
255
  declare function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }: Pick<OptionsResolved, "sourcemap" | "cjsDefault" | "sideEffects">): Plugin;
247
256
  //#endregion
248
257
  //#region src/generate.d.ts
249
- declare function createGeneratePlugin({ generator, entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap, logger }: Pick<OptionsResolved, "generator" | "entry" | "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "vue" | "tsMacro" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap" | "logger">): Plugin;
258
+ declare function createGeneratePlugin({ generator, entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, volarContext, parallel, eager, tsgo, newContext, emitJs, sourcemap, logger }: Pick<OptionsResolved, "generator" | "entry" | "cwd" | "tsconfig" | "tsconfigRaw" | "build" | "incremental" | "oxc" | "emitDtsOnly" | "volarContext" | "parallel" | "eager" | "tsgo" | "newContext" | "emitJs" | "sourcemap" | "logger">): Plugin;
250
259
  //#endregion
251
260
  //#region src/index.d.ts
252
261
  declare function dts(options?: Options): Plugin[];