Skip to content

Commit

Permalink
perf(tsc): re-introduce global types removal check (#4245)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
blake-newman and johnsoncodehk authored Apr 12, 2024
1 parent 5216e74 commit cc9b9d0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/tsc/index.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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,
Expand Down

0 comments on commit cc9b9d0

Please sign in to comment.