From 630c74e447f66bd226bdc241d30535a1b439b8b1 Mon Sep 17 00:00:00 2001 From: Blake Newman Date: Wed, 10 Apr 2024 10:24:24 +0100 Subject: [PATCH] fix(tsc): re-introduce global types removal check The issue with the guard clause prior was that the out directory for the .d.ts file is likely to be a different place from the global types holder file. This meant the clause was not accurately detecting if it should remove the global types. The guard clause is needed to some degree as large projects with many emitted files would run this removal which is fairly slow. vue-tsc is unusable without this guard clause. Instead just get the file name from the file being written and the global types holder, if the dts file starts with the global types holder then perform the global types removal logic. This allows for the output and source paths to be different. The removal may run more than once if similar names are present but it won't run on every file to be emitted. --- packages/tsc/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/tsc/index.ts b/packages/tsc/index.ts index 21c98d8253..fe62066b49 100644 --- a/packages/tsc/index.ts +++ b/packages/tsc/index.ts @@ -1,5 +1,6 @@ import { runTsc } from '@volar/typescript/lib/quickstart/runTsc'; import * as vue from '@vue/language-core'; +import * as path from 'path'; const windowsPathReg = /\\/g; @@ -22,8 +23,13 @@ export function run() { ) { const writeFile = options.host!.writeFile.bind(options.host); options.host!.writeFile = (fileName, contents, ...args) => { - contents = removeEmitGlobalTypes(contents); - return writeFile(fileName, contents, ...args); + if (!vueLanguagePlugin.pluginContext.globalTypesHolder) { + return writeFile(fileName, contents, ...args); + } + + const writeFileName = path.basename(vueLanguagePlugin.getCanonicalFileName(fileName)); + const globalTypesFileName = path.basename(vueLanguagePlugin.getCanonicalFileName(vueLanguagePlugin.pluginContext.globalTypesHolder)); + return writeFile(fileName, writeFileName.startsWith(globalTypesFileName) ? removeEmitGlobalTypes(contents) : contents, ...args); }; const vueLanguagePlugin = vue.createVueLanguagePlugin( ts,