Skip to content

Commit

Permalink
fix(tsc): re-introduce global types removal check
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.
  • Loading branch information
blake-newman committed Apr 10, 2024
1 parent cc52990 commit 630c74e
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 630c74e

Please sign in to comment.