From 453facfa6b1c521f09efc7a910351e4bac23ea34 Mon Sep 17 00:00:00 2001 From: Kevin Deng Date: Mon, 26 Oct 2026 13:46:17 +0900 Subject: [PATCH] fix: support deprecated top-level tsc options --- README.md | 3 ++ __snapshots__/tsnapi/index.snapshot.d.ts | 14 ++++-- src/options.ts | 57 +++++++++++++++++++++++- 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9108474..087b7b2 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,9 @@ CommonJS-style declaration input. | `tsc.vue` | Register the built-in Vue integration using `vue-tsc`. | `false` | | `emitJs` | Generate declarations for JavaScript files with JSDoc types. | `allowJs` or `checkJs` | +Top-level `build`, `incremental`, `parallel`, `eager`, `newContext`, and `vue` are +deprecated. Use `tsc.*` instead. + `tsc.incremental` applies to build mode. When disabled, build outputs stay in memory. diff --git a/__snapshots__/tsnapi/index.snapshot.d.ts b/__snapshots__/tsnapi/index.snapshot.d.ts index 148f621..15add14 100644 --- a/__snapshots__/tsnapi/index.snapshot.d.ts +++ b/__snapshots__/tsnapi/index.snapshot.d.ts @@ -26,7 +26,7 @@ export interface Logger { warn: (..._: any[]) => void; error: (..._: any[]) => void; } -export interface Options { +export interface Options extends DeprecatedOptions { generator?: "tsc" | "oxc" | "tsgo" | Generator; entry?: string | string[]; cwd?: string; @@ -60,11 +60,19 @@ export interface TscOptions { export declare function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }: Pick): Plugin; export declare function createGeneratePlugin(_: Pick): Plugin; export declare function dts(_?: Options): Plugin[]; -export declare function resolveOptions({ generator, entry, cwd, dtsInput, emitDtsOnly, tsconfig, tsconfigRaw: overriddenTsconfigRaw, compilerOptions, sourcemap, resolver, cjsDefault, sideEffects, logger, customLanguages, tsc, emitJs, oxc, tsgo }: Options): OptionsResolved; +export declare function resolveOptions({ generator, entry, cwd, dtsInput, emitDtsOnly, tsconfig, tsconfigRaw: overriddenTsconfigRaw, compilerOptions, sourcemap, resolver, cjsDefault, sideEffects, logger, customLanguages, tsc, emitJs, oxc, tsgo, ...deprecated }: Options): OptionsResolved; // #endregion // #region Referenced (internal) -type OptionsResolved = Overwrite>, { +interface DeprecatedOptions { + build?: TscOptions["build"]; + incremental?: TscOptions["incremental"]; + parallel?: TscOptions["parallel"]; + eager?: TscOptions["eager"]; + newContext?: TscOptions["newContext"]; + vue?: TscOptions["vue"]; +} +type OptionsResolved = Overwrite>, { entry?: string[]; tsconfig?: string; oxc: IsolatedDeclarationsOptions; diff --git a/src/options.ts b/src/options.ts index b2b0e32..15814f6 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,5 +1,6 @@ import path from 'node:path' import process from 'node:process' +import { isDeepStrictEqual } from 'node:util' import { getTsconfig, readTsconfig, @@ -27,7 +28,7 @@ export interface Logger { error: (...args: any[]) => void } -export interface Options { +export interface Options extends DeprecatedOptions { /** * The generator used to produce declaration files. * @@ -181,6 +182,26 @@ export interface Options { customLanguages?: CustomLanguage[] } +interface DeprecatedOptions { + /** @deprecated Use `tsc.build` instead. */ + build?: TscOptions['build'] + + /** @deprecated Use `tsc.incremental` instead. */ + incremental?: TscOptions['incremental'] + + /** @deprecated Use `tsc.parallel` instead. */ + parallel?: TscOptions['parallel'] + + /** @deprecated Use `tsc.eager` instead. */ + eager?: TscOptions['eager'] + + /** @deprecated Use `tsc.newContext` instead. */ + newContext?: TscOptions['newContext'] + + /** @deprecated Use `tsc.vue` instead. */ + vue?: TscOptions['vue'] +} + export interface TscOptions { /** * Registers the built-in Vue language integration using `vue-tsc`. @@ -269,7 +290,12 @@ export interface TsgoOptions { type Overwrite = Pick> & U export type OptionsResolved = Overwrite< - Required>, + Required< + Omit< + Options, + 'compilerOptions' | 'customLanguages' | 'tsc' | keyof DeprecatedOptions + > + >, { entry?: string[] tsconfig?: string @@ -304,7 +330,34 @@ export function resolveOptions({ oxc, tsgo, + ...deprecated }: Options): OptionsResolved { + for (const key of [ + 'build', + 'incremental', + 'parallel', + 'eager', + 'newContext', + 'vue', + ] as const) { + const value = deprecated[key] + if (value === undefined) continue + + if (tsc?.[key] !== undefined && !isDeepStrictEqual(value, tsc[key])) { + throw new Error( + `The deprecated \`${key}\` option conflicts with \`tsc.${key}\`. Remove the top-level \`${key}\` option.`, + ) + } + logger.warn( + `The top-level \`${key}\` option is deprecated. Use \`tsc.${key}\` instead.`, + ) + + // Legacy incremental: false follows tsconfig instead of disabling it. + if (tsc?.[key] === undefined && (key !== 'incremental' || value)) { + tsc = { ...tsc, [key]: value } + } + } + let resolvedTsconfig: TsconfigJsonResolved | undefined if (tsconfig === true || tsconfig == null) { const { config, path } = getTsconfig(cwd) || {} -- knotmirror 0.0.1