Skip to content

Commit d6ccd58

Browse files
fix(language-core): refer absolute path of global types file (#4924)
Co-authored-by: Johnson Chu <[email protected]>
1 parent df6780a commit d6ccd58

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

packages/language-core/lib/codegen/script/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
5656
const ctx = createScriptCodegenContext(options);
5757

5858
if (options.vueCompilerOptions.__setupedGlobalTypes) {
59-
yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${newLine}`;
59+
const globalTypes = options.vueCompilerOptions.__setupedGlobalTypes;
60+
if (typeof globalTypes === 'object') {
61+
yield `/// <reference types="${globalTypes.absolutePath}" />${newLine}`;
62+
}
63+
else {
64+
yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${newLine}`;
65+
}
6066
}
6167
else {
6268
yield `/* placeholder */`;

packages/language-core/lib/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ export interface VueCompilerOptions {
5555
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
5656

5757
// internal
58-
__setupedGlobalTypes?: boolean;
58+
__setupedGlobalTypes?: true | {
59+
absolutePath: string;
60+
};
5961
__test?: boolean;
6062
}
6163

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ export function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions
281281
export function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
282282
fileExists(path: string): boolean;
283283
writeFile?(path: string, data: string): void;
284-
}) {
284+
}): VueCompilerOptions['__setupedGlobalTypes'] {
285285
if (!host.writeFile) {
286-
return false;
286+
return;
287287
}
288288
try {
289289
let dir = rootDir;
@@ -297,8 +297,6 @@ export function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions
297297
const globalTypesPath = path.join(dir, 'node_modules', '.vue-global-types', `${vueOptions.lib}_${vueOptions.target}_${vueOptions.strictTemplates}.d.ts`);
298298
const globalTypesContents = `// @ts-nocheck\nexport {};\n` + generateGlobalTypes(vueOptions.lib, vueOptions.target, vueOptions.strictTemplates);
299299
host.writeFile(globalTypesPath, globalTypesContents);
300-
return true;
301-
} catch {
302-
return false;
303-
}
304-
}
300+
return { absolutePath: globalTypesPath };
301+
} catch { }
302+
}

0 commit comments

Comments
 (0)