Skip to content

Commit 453facf

Browse files
committed
fix: support deprecated top-level tsc options
1 parent b860282 commit 453facf

3 files changed

Lines changed: 69 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ CommonJS-style declaration input.
115115
| `tsc.vue` | Register the built-in Vue integration using `vue-tsc`. | `false` |
116116
| `emitJs` | Generate declarations for JavaScript files with JSDoc types. | `allowJs` or `checkJs` |
117117

118+
Top-level `build`, `incremental`, `parallel`, `eager`, `newContext`, and `vue` are
119+
deprecated. Use `tsc.*` instead.
120+
118121
`tsc.incremental` applies to build mode. When disabled, build outputs stay in
119122
memory.
120123

‎__snapshots__/tsnapi/index.snapshot.d.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface Logger {
2626
warn: (..._: any[]) => void;
2727
error: (..._: any[]) => void;
2828
}
29-
export interface Options {
29+
export interface Options extends DeprecatedOptions {
3030
generator?: "tsc" | "oxc" | "tsgo" | Generator;
3131
entry?: string | string[];
3232
cwd?: string;
@@ -60,11 +60,19 @@ export interface TscOptions {
6060
export declare function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }: Pick<OptionsResolved, "sourcemap" | "cjsDefault" | "sideEffects">): Plugin;
6161
export declare function createGeneratePlugin(_: Pick<OptionsResolved, "generator" | "entry" | "cwd" | "tsconfig" | "tsconfigRaw" | "oxc" | "emitDtsOnly" | "languageContext" | "tsc" | "tsgo" | "emitJs" | "sourcemap">): Plugin;
6262
export declare function dts(_?: Options): Plugin[];
63-
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;
63+
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;
6464
// #endregion
6565

6666
// #region Referenced (internal)
67-
type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions" | "customLanguages" | "tsc">>, {
67+
interface DeprecatedOptions {
68+
build?: TscOptions["build"];
69+
incremental?: TscOptions["incremental"];
70+
parallel?: TscOptions["parallel"];
71+
eager?: TscOptions["eager"];
72+
newContext?: TscOptions["newContext"];
73+
vue?: TscOptions["vue"];
74+
}
75+
type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions" | "customLanguages" | "tsc" | keyof DeprecatedOptions>>, {
6876
entry?: string[];
6977
tsconfig?: string;
7078
oxc: IsolatedDeclarationsOptions;

‎src/options.ts‎

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'node:path'
22
import process from 'node:process'
3+
import { isDeepStrictEqual } from 'node:util'
34
import {
45
getTsconfig,
56
readTsconfig,
@@ -27,7 +28,7 @@ export interface Logger {
2728
error: (...args: any[]) => void
2829
}
2930

30-
export interface Options {
31+
export interface Options extends DeprecatedOptions {
3132
/**
3233
* The generator used to produce declaration files.
3334
*
@@ -181,6 +182,26 @@ export interface Options {
181182
customLanguages?: CustomLanguage[]
182183
}
183184

185+
interface DeprecatedOptions {
186+
/** @deprecated Use `tsc.build` instead. */
187+
build?: TscOptions['build']
188+
189+
/** @deprecated Use `tsc.incremental` instead. */
190+
incremental?: TscOptions['incremental']
191+
192+
/** @deprecated Use `tsc.parallel` instead. */
193+
parallel?: TscOptions['parallel']
194+
195+
/** @deprecated Use `tsc.eager` instead. */
196+
eager?: TscOptions['eager']
197+
198+
/** @deprecated Use `tsc.newContext` instead. */
199+
newContext?: TscOptions['newContext']
200+
201+
/** @deprecated Use `tsc.vue` instead. */
202+
vue?: TscOptions['vue']
203+
}
204+
184205
export interface TscOptions {
185206
/**
186207
* Registers the built-in Vue language integration using `vue-tsc`.
@@ -269,7 +290,12 @@ export interface TsgoOptions {
269290
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U
270291

271292
export type OptionsResolved = Overwrite<
272-
Required<Omit<Options, 'compilerOptions' | 'customLanguages' | 'tsc'>>,
293+
Required<
294+
Omit<
295+
Options,
296+
'compilerOptions' | 'customLanguages' | 'tsc' | keyof DeprecatedOptions
297+
>
298+
>,
273299
{
274300
entry?: string[]
275301
tsconfig?: string
@@ -304,7 +330,34 @@ export function resolveOptions({
304330

305331
oxc,
306332
tsgo,
333+
...deprecated
307334
}: Options): OptionsResolved {
335+
for (const key of [
336+
'build',
337+
'incremental',
338+
'parallel',
339+
'eager',
340+
'newContext',
341+
'vue',
342+
] as const) {
343+
const value = deprecated[key]
344+
if (value === undefined) continue
345+
346+
if (tsc?.[key] !== undefined && !isDeepStrictEqual(value, tsc[key])) {
347+
throw new Error(
348+
`The deprecated \`${key}\` option conflicts with \`tsc.${key}\`. Remove the top-level \`${key}\` option.`,
349+
)
350+
}
351+
logger.warn(
352+
`The top-level \`${key}\` option is deprecated. Use \`tsc.${key}\` instead.`,
353+
)
354+
355+
// Legacy incremental: false follows tsconfig instead of disabling it.
356+
if (tsc?.[key] === undefined && (key !== 'incremental' || value)) {
357+
tsc = { ...tsc, [key]: value }
358+
}
359+
}
360+
308361
let resolvedTsconfig: TsconfigJsonResolved | undefined
309362
if (tsconfig === true || tsconfig == null) {
310363
const { config, path } = getTsconfig(cwd) || {}

0 commit comments

Comments
 (0)