|
1 | 1 | import path from 'node:path' |
2 | 2 | import process from 'node:process' |
| 3 | +import { isDeepStrictEqual } from 'node:util' |
3 | 4 | import { |
4 | 5 | getTsconfig, |
5 | 6 | readTsconfig, |
@@ -27,7 +28,7 @@ export interface Logger { |
27 | 28 | error: (...args: any[]) => void |
28 | 29 | } |
29 | 30 |
|
30 | | -export interface Options { |
| 31 | +export interface Options extends DeprecatedOptions { |
31 | 32 | /** |
32 | 33 | * The generator used to produce declaration files. |
33 | 34 | * |
@@ -181,6 +182,26 @@ export interface Options { |
181 | 182 | customLanguages?: CustomLanguage[] |
182 | 183 | } |
183 | 184 |
|
| 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 | + |
184 | 205 | export interface TscOptions { |
185 | 206 | /** |
186 | 207 | * Registers the built-in Vue language integration using `vue-tsc`. |
@@ -269,7 +290,12 @@ export interface TsgoOptions { |
269 | 290 | type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U |
270 | 291 |
|
271 | 292 | 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 | + >, |
273 | 299 | { |
274 | 300 | entry?: string[] |
275 | 301 | tsconfig?: string |
@@ -304,7 +330,34 @@ export function resolveOptions({ |
304 | 330 |
|
305 | 331 | oxc, |
306 | 332 | tsgo, |
| 333 | + ...deprecated |
307 | 334 | }: 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 | + |
308 | 361 | let resolvedTsconfig: TsconfigJsonResolved | undefined |
309 | 362 | if (tsconfig === true || tsconfig == null) { |
310 | 363 | const { config, path } = getTsconfig(cwd) || {} |
|
0 commit comments