Skip to content

Commit cc9b9d0

Browse files
perf(tsc): re-introduce global types removal check (#4245)
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. Co-authored-by: Johnson Chu <johnsoncodehk@gmail.com>
1 parent 5216e74 commit cc9b9d0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/tsc/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { runTsc } from '@volar/typescript/lib/quickstart/runTsc';
22
import * as vue from '@vue/language-core';
3+
import * as path from 'path';
34

45
const windowsPathReg = /\\/g;
56

@@ -22,8 +23,13 @@ export function run() {
2223
) {
2324
const writeFile = options.host!.writeFile.bind(options.host);
2425
options.host!.writeFile = (fileName, contents, ...args) => {
25-
contents = removeEmitGlobalTypes(contents);
26-
return writeFile(fileName, contents, ...args);
26+
if (!vueLanguagePlugin.pluginContext.globalTypesHolder) {
27+
return writeFile(fileName, contents, ...args);
28+
}
29+
30+
const writeFileName = path.basename(vueLanguagePlugin.getCanonicalFileName(fileName));
31+
const globalTypesFileName = path.basename(vueLanguagePlugin.getCanonicalFileName(vueLanguagePlugin.pluginContext.globalTypesHolder));
32+
return writeFile(fileName, writeFileName.startsWith(globalTypesFileName) ? removeEmitGlobalTypes(contents) : contents, ...args);
2733
};
2834
const vueLanguagePlugin = vue.createVueLanguagePlugin(
2935
ts,

0 commit comments

Comments
 (0)