Skip to content

Commit 78fcfdd

Browse files
committed
fix(language-core): avoid clearing global types path when local compiler options is present
1 parent 2d02b29 commit 78fcfdd

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

packages/language-core/lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type Code = Segment<VueCodeInformation>;
2626
export interface VueCompilerOptions {
2727
target: number;
2828
lib: string;
29-
globalTypesPath: (fileName: string) => string | undefined;
29+
globalTypesPath: (fileName: string) => string | void;
3030
extensions: string[];
3131
vitePressExtensions: string[];
3232
petiteVueExtensions: string[];

packages/language-core/lib/utils/ts.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { camelize } from '@vue/shared';
1+
import { camelize, NOOP as noop } from '@vue/shared';
22
import { posix as path } from 'path-browserify';
33
import type * as ts from 'typescript';
44
import { generateGlobalTypes, getGlobalTypesFileName } from '../codegen/globalTypes';
@@ -232,30 +232,32 @@ export class CompilerOptionsResolver {
232232
),
233233
};
234234

235-
if (this.fileExists && this.globalTypesPath === undefined) {
236-
const fileDirToGlobalTypesPath = new Map<string, string | undefined>();
237-
resolvedOptions.globalTypesPath = fileName => {
238-
const fileDir = path.dirname(fileName);
239-
if (fileDirToGlobalTypesPath.has(fileDir)) {
240-
return fileDirToGlobalTypesPath.get(fileDir);
241-
}
235+
if (resolvedOptions.globalTypesPath === noop) {
236+
if (this.fileExists && this.globalTypesPath === undefined) {
237+
const fileDirToGlobalTypesPath = new Map<string, string | undefined>();
238+
resolvedOptions.globalTypesPath = fileName => {
239+
const fileDir = path.dirname(fileName);
240+
if (fileDirToGlobalTypesPath.has(fileDir)) {
241+
return fileDirToGlobalTypesPath.get(fileDir);
242+
}
242243

243-
const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
244-
const result = root
245-
? path.join(
246-
root,
247-
'node_modules',
248-
'.vue-global-types',
249-
getGlobalTypesFileName(resolvedOptions),
250-
)
251-
: undefined;
244+
const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
245+
const result = root
246+
? path.join(
247+
root,
248+
'node_modules',
249+
'.vue-global-types',
250+
getGlobalTypesFileName(resolvedOptions),
251+
)
252+
: undefined;
252253

253-
fileDirToGlobalTypesPath.set(fileDir, result);
254-
return result;
255-
};
256-
}
257-
else {
258-
resolvedOptions.globalTypesPath = () => this.globalTypesPath;
254+
fileDirToGlobalTypesPath.set(fileDir, result);
255+
return result;
256+
};
257+
}
258+
else {
259+
resolvedOptions.globalTypesPath = () => this.globalTypesPath;
260+
}
259261
}
260262

261263
return resolvedOptions;
@@ -303,7 +305,7 @@ export function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTempla
303305
return {
304306
target,
305307
lib,
306-
globalTypesPath: () => undefined,
308+
globalTypesPath: noop,
307309
extensions: ['.vue'],
308310
vitePressExtensions: [],
309311
petiteVueExtensions: [],

0 commit comments

Comments
 (0)