Skip to content

Commit cb5b6cb

Browse files
committed
feat!: move vue option under tsc
1 parent e538a4b commit cb5b6cb

7 files changed

Lines changed: 55 additions & 61 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ CommonJS-style declaration input.
112112
| `tsc.parallel` | Run `tsc` or `vue-tsc` in a separate process. | `false` |
113113
| `tsc.eager` | Load every file listed by `tsconfig.json`. | `false` |
114114
| `tsc.newContext` | Use an isolated compiler cache instead of the shared context. | `false` |
115-
| `vue` | Register the built-in Vue integration using `vue-tsc`. | `false` |
115+
| `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

118118
`tsc.incremental` applies to build mode. When disabled, build outputs stay in
@@ -133,7 +133,7 @@ invalidateContextFile(globalContext, 'src/foo.ts')
133133

134134
`customLanguages` registers non-standard source files such as Vue or Astro.
135135
Volar integrations must provide both `volarTypeScript` and
136-
`createVolarPlugins`; they require the `tsc` generator. `vue: true` is the
136+
`createVolarPlugins`; they require the `tsc` generator. `tsc.vue: true` is the
137137
preconfigured Vue shortcut.
138138

139139
This API is experimental and may change.

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ export interface Options {
4040
cjsDefault?: boolean;
4141
sideEffects?: boolean;
4242
logger?: Logger;
43-
vue?: boolean | VueLanguageOptions;
4443
emitJs?: boolean;
4544
tsc?: TscOptions;
4645
oxc?: Omit<IsolatedDeclarationsOptions, "sourcemap">;
4746
tsgo?: TsgoOptions;
4847
customLanguages?: CustomLanguage[];
4948
}
5049
export interface TscOptions {
50+
vue?: boolean | VueLanguageOptions;
5151
build?: boolean;
5252
incremental?: boolean;
5353
parallel?: boolean;
@@ -58,21 +58,22 @@ export interface TscOptions {
5858

5959
// #region Functions
6060
export declare function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }: Pick<OptionsResolved, "sourcemap" | "cjsDefault" | "sideEffects">): Plugin;
61-
export declare function createGeneratePlugin(_: Pick<OptionsResolved, "generator" | "entry" | "cwd" | "tsconfig" | "tsconfigRaw" | "oxc" | "emitDtsOnly" | "languageContext" | "vue" | "tsc" | "tsgo" | "emitJs" | "sourcemap">): Plugin;
61+
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, vue, 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 }: Options): OptionsResolved;
6464
// #endregion
6565

6666
// #region Referenced (internal)
67-
type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions" | "vue" | "customLanguages" | "tsc">>, {
67+
type OptionsResolved = Overwrite<Required<Omit<Options, "compilerOptions" | "customLanguages" | "tsc">>, {
6868
entry?: string[];
6969
tsconfig?: string;
7070
oxc: IsolatedDeclarationsOptions;
7171
tsconfigRaw: TsconfigJson;
7272
tsgo: TsgoOptions;
7373
languageContext: LanguageContext;
74-
vue: false | VueLanguageOptions;
75-
tsc: Required<TscOptions>;
74+
tsc: Overwrite<Required<TscOptions>, {
75+
vue: false | VueLanguageOptions;
76+
}>;
7677
}>;
7778
interface TsgoOptions {
7879
moduleUrl?: string;

‎src/generate.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export function createGeneratePlugin(
4343
| 'oxc'
4444
| 'emitDtsOnly'
4545
| 'languageContext'
46-
| 'vue'
4746
| 'tsc'
4847
| 'tsgo'
4948
| 'emitJs'

‎src/generator/index.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export function createGenerator(
3838
cwd,
3939
oxc,
4040
languageContext,
41-
vue,
4241
tsc,
4342
tsgo,
4443
sourcemap,
@@ -50,7 +49,6 @@ export function createGenerator(
5049
| 'cwd'
5150
| 'oxc'
5251
| 'languageContext'
53-
| 'vue'
5452
| 'tsc'
5553
| 'tsgo'
5654
| 'sourcemap'
@@ -84,7 +82,7 @@ export function createGenerator(
8482
cwd,
8583
sourcemap,
8684
languageContext,
87-
vue,
85+
vue: tsc.vue,
8886
parallel: tsc.parallel,
8987
newContext: tsc.newContext,
9088
getEntries,

‎src/options.ts‎

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,6 @@ export interface Options {
143143
*/
144144
logger?: Logger
145145

146-
/**
147-
* Registers the built-in Vue language integration using `vue-tsc`.
148-
*
149-
* This is a shortcut for a preconfigured {@link Options.customLanguages}
150-
* entry and requires the `tsc` generator.
151-
*
152-
* @default false
153-
*/
154-
vue?: boolean | VueLanguageOptions
155-
156146
/**
157147
* Generates declarations for JavaScript files with JSDoc types.
158148
*
@@ -191,6 +181,16 @@ export interface Options {
191181
}
192182

193183
export interface TscOptions {
184+
/**
185+
* Registers the built-in Vue language integration using `vue-tsc`.
186+
*
187+
* This is a shortcut for a preconfigured {@link Options.customLanguages}
188+
* entry and requires the `tsc` generator.
189+
*
190+
* @default false
191+
*/
192+
vue?: boolean | VueLanguageOptions
193+
194194
/**
195195
* Uses TypeScript build mode (`tsc -b`) and follows project references.
196196
*
@@ -260,18 +260,15 @@ export interface TsgoOptions {
260260
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U
261261

262262
export type OptionsResolved = Overwrite<
263-
Required<
264-
Omit<Options, 'compilerOptions' | 'vue' | 'customLanguages' | 'tsc'>
265-
>,
263+
Required<Omit<Options, 'compilerOptions' | 'customLanguages' | 'tsc'>>,
266264
{
267265
entry?: string[]
268266
tsconfig?: string
269267
oxc: IsolatedDeclarationsOptions
270268
tsconfigRaw: TsconfigJson
271269
tsgo: TsgoOptions
272270
languageContext: LanguageContext
273-
vue: false | VueLanguageOptions
274-
tsc: Required<TscOptions>
271+
tsc: Overwrite<Required<TscOptions>, { vue: false | VueLanguageOptions }>
275272
}
276273
>
277274

@@ -294,7 +291,6 @@ export function resolveOptions({
294291
customLanguages,
295292
tsc,
296293

297-
vue = false,
298294
emitJs,
299295

300296
oxc,
@@ -326,7 +322,14 @@ export function resolveOptions({
326322
compilerOptions,
327323
}
328324

329-
const tscOptions: Required<TscOptions> = {
325+
const vue = tsc?.vue
326+
const vueOptions: false | VueLanguageOptions = vue
327+
? typeof vue === 'object'
328+
? vue
329+
: {}
330+
: false
331+
const tscOptions: OptionsResolved['tsc'] = {
332+
vue: vueOptions,
330333
build: tsc?.build ?? false,
331334
incremental:
332335
tsc?.incremental ??
@@ -338,15 +341,10 @@ export function resolveOptions({
338341

339342
const hasCustomLanguages = !!customLanguages?.length
340343
customLanguages = [...(customLanguages || [])]
341-
const vueOptions: false | VueLanguageOptions = vue
342-
? typeof vue === 'object'
343-
? vue
344-
: {}
345-
: false
346344
if (vueOptions) {
347345
if (generator && generator !== 'tsc') {
348346
throw new Error(
349-
'Volar-based custom languages (including the `vue` option) require the `tsc` generator.',
347+
'Volar-based custom languages (including the `tsc.vue` option) require the `tsc` generator.',
350348
)
351349
}
352350
customLanguages.push(
@@ -368,7 +366,7 @@ export function resolveOptions({
368366
if (isUsingVolar) {
369367
if (generator && generator !== 'tsc') {
370368
throw new Error(
371-
'Volar-based custom languages (including the `vue` option) require the `tsc` generator.',
369+
'Volar-based custom languages (including the `tsc.vue` option) require the `tsc` generator.',
372370
)
373371
}
374372
generator = 'tsc'
@@ -384,7 +382,7 @@ export function resolveOptions({
384382

385383
if (generator === 'tsc' && tscOptions.parallel && hasCustomLanguages) {
386384
throw new Error(
387-
'The `tsc.parallel` option does not support `customLanguages`. Disable `tsc.parallel` or use the built-in `vue` option for Vue.',
385+
'The `tsc.parallel` option does not support `customLanguages`. Disable `tsc.parallel` or use the built-in `tsc.vue` option for Vue.',
388386
)
389387
}
390388

@@ -455,7 +453,6 @@ export function resolveOptions({
455453
cjsDefault,
456454
sideEffects,
457455

458-
vue: vueOptions,
459456
tsc: tscOptions,
460457
emitJs,
461458
languageContext,

‎tests/custom-language.test.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('volar', () => {
2121
[
2222
dts({
2323
emitDtsOnly: true,
24-
vue: true,
24+
tsc: { vue: true },
2525
compilerOptions: {
2626
isolatedDeclarations: false,
2727
},
@@ -39,10 +39,10 @@ describe('volar', () => {
3939
[
4040
dts({
4141
emitDtsOnly: true,
42-
vue: {
43-
vueCompilerOptions: { fallthroughAttributes: false },
42+
tsc: {
43+
vue: { vueCompilerOptions: { fallthroughAttributes: false } },
44+
parallel: true,
4445
},
45-
tsc: { parallel: true },
4646
compilerOptions: {
4747
isolatedDeclarations: false,
4848
},
@@ -61,7 +61,7 @@ describe('volar', () => {
6161
dts({
6262
tsconfig: path.resolve(root, 'tsconfig.json'),
6363
emitDtsOnly: true,
64-
vue: true,
64+
tsc: { vue: true },
6565
}),
6666
],
6767
{ external },
@@ -76,7 +76,7 @@ describe('volar', () => {
7676
[
7777
dts({
7878
emitDtsOnly: true,
79-
vue: true,
79+
tsc: { vue: true },
8080
compilerOptions: {
8181
isolatedDeclarations: false,
8282
},
@@ -111,7 +111,7 @@ describe('volar', () => {
111111
dts({
112112
emitDtsOnly: true,
113113
tsconfig: path.resolve(root, 'tsconfig.json'),
114-
vue: true,
114+
tsc: { vue: true },
115115
customLanguages: [tsMacro],
116116
}),
117117
],

‎tests/generator.test.ts‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ interface Fixture {
127127
installed?: Installed
128128
isolatedDecl?: boolean
129129
oxc?: Options['oxc']
130-
vue?: boolean
131130
tsc?: Options['tsc']
132131
customLanguages?: Options['customLanguages']
133132
tsgo?: Options['tsgo']
@@ -147,7 +146,6 @@ function formatTitle(fixture: Fixture): string {
147146
if (fixture.isolatedDecl) parts.push('isolatedDecl')
148147
if (fixture.oxc !== undefined)
149148
parts.push(`oxc=${JSON.stringify(fixture.oxc)}`)
150-
if (fixture.vue) parts.push('vue')
151149
if (fixture.tsc !== undefined)
152150
parts.push(`tsc=${JSON.stringify(fixture.tsc)}`)
153151
if (fixture.customLanguages)
@@ -379,43 +377,43 @@ describe('resolve generator', () => {
379377
//#endregion
380378

381379
//#region vue (Volar-based, requires tsc)
382-
{ vue: true, expected: 'tsc' },
380+
{ tsc: { vue: true }, expected: 'tsc' },
383381
{
384382
installed: [false, false],
385-
vue: true,
383+
tsc: { vue: true },
386384
expected: 'TypeScript is not installed',
387385
isThrow: true,
388386
},
389387
{
390388
installed: [7, false],
391-
vue: true,
389+
tsc: { vue: true },
392390
expected: 'does not provide the classic TypeScript API required by Vue',
393391
isThrow: true,
394392
},
395393
{
396-
vue: true,
394+
tsc: { vue: true },
397395
generator: 'oxc',
398396
expected: 'require the `tsc` generator',
399397
isThrow: true,
400398
},
401399
{
402-
vue: true,
400+
tsc: { vue: true },
403401
generator: 'tsgo',
404402
expected: 'require the `tsc` generator',
405403
isThrow: true,
406404
},
407405
{
408406
installed: ['next', false],
409-
vue: true,
407+
tsc: { vue: true },
410408
generator: 'tsgo',
411409
expected: 'require the `tsc` generator',
412410
isThrow: true,
413411
},
414-
{ vue: true, generator: 'tsc', expected: 'tsc' },
415-
{ vue: true, tsc: { parallel: true }, expected: 'tsc' },
416-
{ vue: true, isolatedDecl: true, expected: 'tsc' },
412+
{ tsc: { vue: true }, generator: 'tsc', expected: 'tsc' },
413+
{ tsc: { vue: true, parallel: true }, expected: 'tsc' },
414+
{ tsc: { vue: true }, isolatedDecl: true, expected: 'tsc' },
417415
// tsgo settings are ignored when tsc is selected
418-
{ installed: [6, 'next'], vue: true, tsgo: {}, expected: 'tsc' },
416+
{ installed: [6, 'next'], tsc: { vue: true }, tsgo: {}, expected: 'tsc' },
419417
//#endregion
420418

421419
//#region Volar-based custom language (requires tsc)
@@ -454,7 +452,7 @@ describe('resolve generator', () => {
454452
{ customLanguages: [volarLanguage], isolatedDecl: true, expected: 'tsc' },
455453
{
456454
customLanguages: [volarLanguage, plainLanguage],
457-
vue: true,
455+
tsc: { vue: true },
458456
expected: 'tsc',
459457
},
460458
//#endregion
@@ -527,7 +525,6 @@ describe('resolve generator', () => {
527525
installed = [6, false],
528526
isolatedDecl,
529527
oxc,
530-
vue,
531528
tsc,
532529
customLanguages,
533530
tsgo,
@@ -545,7 +542,6 @@ describe('resolve generator', () => {
545542
isolatedDeclarations: isolatedDecl,
546543
},
547544
oxc,
548-
vue,
549545
tsc: tsc && { ...tsc },
550546
// resolveOptions may push into the array (e.g. vue), so avoid
551547
// sharing the same array between fixtures
@@ -568,14 +564,17 @@ describe('resolve generator', () => {
568564
)
569565
expect(resolved.tsgo.vfs).toBe(tsgo?.vfs ?? false)
570566
expect(resolved.tsc).toStrictEqual({
567+
vue: typeof tsc?.vue === 'object' ? tsc.vue : tsc?.vue ? {} : false,
571568
build: tsc?.build ?? false,
572569
incremental: tsc?.incremental ?? false,
573570
parallel: tsc?.parallel ?? false,
574571
eager: tsc?.eager ?? false,
575572
newContext: tsc?.newContext ?? false,
576573
})
577574
if (resolved.generator === 'tsgo') {
578-
expect(logger.info).toHaveBeenCalledWith('Emit types with TypeScript Go')
575+
expect(logger.info).toHaveBeenCalledWith(
576+
'Emit types with TypeScript Go',
577+
)
579578
}
580579
},
581580
)

0 commit comments

Comments
 (0)