Skip to content

Commit 25c7a84

Browse files
committed
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.
1 parent a03aae4 commit 25c7a84

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/tsc/src/index.ts

+14
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ export function createProgram(options: ts.CreateProgramOptions) {
7777
},
7878
getProjectReferences: () => ctx.options.projectReferences,
7979
getCancellationToken: ctx.options.host!.getCancellationToken ? () => ctx.options.host!.getCancellationToken!() : undefined,
80+
realpath(path) {
81+
const { realpath } = ctx.host ?? ts.sys
82+
const match = /^(?<path>.+\.vue)\.(?<extension>.+)$/.exec(path)
83+
return match?.groups ? `${realpath(match.groups.path)}.${match.groups.extension}` : realpath(path)
84+
},
85+
getParsedCommandLine: (path) => {
86+
const possibleExtensions = ['ts', 'tsx']
87+
const commandLine = ts.getParsedCommandLineOfConfigFile(path, undefined, sys)
88+
if (!commandLine) return undefined
89+
return {
90+
...commandLine,
91+
fileNames: commandLine.fileNames.flatMap(name => name.endsWith('.vue') ? possibleExtensions.map(ext => `${name}.${ext}`) : [name])
92+
}
93+
},
8094
};
8195
const languageContext = vue.createLanguageContext(
8296
languageHost,

0 commit comments

Comments
 (0)