From 25c7a84c5c82feb8762fa18094657138a607c42e Mon Sep 17 00:00:00 2001 From: Blake Newman Date: Thu, 23 Nov 2023 11:23:43 +0000 Subject: [PATCH] perf(tsc): support vue files with project reference delcaration Support vue files with project reference output, so that typescript resolves the project reference vue file as the output `vue.d.ts` file rather than the source. This drastically improves performance in large projects that have vue files imported from project references. As much as 50% performance improvements as ts no longer recompiles vue files from source. Setup the real path to pass back the real path of vue files, as they are virtual files the inbuilt realpath always returns the non symlinked version (node_modules), which affects DX with vue-tsc as errors originating from upstream project reference packages are returned with the node modules path rather than the source. This change is also required to power the usage of `d.ts` files. --- packages/tsc/src/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/tsc/src/index.ts b/packages/tsc/src/index.ts index 5f6be90e49..e56d3da07b 100644 --- a/packages/tsc/src/index.ts +++ b/packages/tsc/src/index.ts @@ -77,6 +77,20 @@ export function createProgram(options: ts.CreateProgramOptions) { }, getProjectReferences: () => ctx.options.projectReferences, getCancellationToken: ctx.options.host!.getCancellationToken ? () => ctx.options.host!.getCancellationToken!() : undefined, + realpath(path) { + const { realpath } = ctx.host ?? ts.sys + const match = /^(?.+\.vue)\.(?.+)$/.exec(path) + return match?.groups ? `${realpath(match.groups.path)}.${match.groups.extension}` : realpath(path) + }, + getParsedCommandLine: (path) => { + const possibleExtensions = ['ts', 'tsx'] + const commandLine = ts.getParsedCommandLineOfConfigFile(path, undefined, sys) + if (!commandLine) return undefined + return { + ...commandLine, + fileNames: commandLine.fileNames.flatMap(name => name.endsWith('.vue') ? possibleExtensions.map(ext => `${name}.${ext}`) : [name]) + } + }, }; const languageContext = vue.createLanguageContext( languageHost,