Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/language-core/lib/codegen/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
const ctx = createScriptCodegenContext(options);

if (options.vueCompilerOptions.__setupedGlobalTypes) {
yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${newLine}`;
const globalTypes = options.vueCompilerOptions.__setupedGlobalTypes;
if (typeof globalTypes === 'object') {
yield `/// <reference types="${globalTypes.absolutePath}" />${newLine}`;
}
else {
yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${newLine}`;
}
}
else {
yield `/* placeholder */`;
Expand Down
4 changes: 3 additions & 1 deletion packages/language-core/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export interface VueCompilerOptions {
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;

// internal
__setupedGlobalTypes?: boolean;
__setupedGlobalTypes?: true | {
absolutePath: string;
};
__test?: boolean;
}

Expand Down
12 changes: 5 additions & 7 deletions packages/language-core/lib/utils/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ export function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions
export function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
fileExists(path: string): boolean;
writeFile?(path: string, data: string): void;
}) {
}): VueCompilerOptions['__setupedGlobalTypes'] {
if (!host.writeFile) {
return false;
return;
}
try {
let dir = rootDir;
Expand All @@ -297,8 +297,6 @@ export function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions
const globalTypesPath = path.join(dir, 'node_modules', '.vue-global-types', `${vueOptions.lib}_${vueOptions.target}_${vueOptions.strictTemplates}.d.ts`);
const globalTypesContents = `// @ts-nocheck\nexport {};\n` + generateGlobalTypes(vueOptions.lib, vueOptions.target, vueOptions.strictTemplates);
host.writeFile(globalTypesPath, globalTypesContents);
return true;
} catch {
return false;
}
}
return { absolutePath: globalTypesPath };
} catch { }
}