Alternatives to the old createProgram?
Vue - Official extension or vue-tsc version
2.0.0
VSCode version
Vue version
TypeScript version
=5.0.0
System Info
No response
Steps to reproduce
Try to use the createProgram API, available in version 1.
What is expected?
On module federation, we used to use the createProgram API of vue-tsc in order to create a TypeScript program to generate the federated modules: https://github.com/module-federation/core/blob/main/packages/native-federation-typescript/src/lib/typeScriptCompiler.ts#L108.
As I can see in this PR: https://github.com/vuejs/language-tools/pull/3795, the API has been removed without a clear alternative to invoke the compiler programmatically.
I don't want to invoke the CLI to do basic operations I was doing before without any issue. Is there an alternative route I can take, or is there a chance to bring back the old API?
What is actually happening?
Can't programmatically create a vue-tsc program anymore
Link to minimal reproduction
No response
Any additional comments?
No response
Could you please check: https://github.com/fi3ework/vite-plugin-checker/pull/327, https://github.com/fi3ework/vite-plugin-checker/blob/main/packages/vite-plugin-checker/src/checkers/vueTsc/main.ts? I thought they might be helpful.
@so1ve if I got it correctly, the function that should cover my scenario is the getLanguagePlugins, isn't it?
Perhaps no? I'm not familiar with volar.js but I guess you may use proxyCreateProgram and getLanguagePlugins together?
I have the same problem. I have a rule for betterer similar to its native typescript rule
prepareVueTsc doesn't feel right. When vue-tsc is changing we need maybe update the script again. Would love to see createProgram back.
This is an example modified based on vue-tsc:
import * as ts from 'typescript';
import * as vue from '@vue/language-core';
import { proxyCreateProgram } from '@volar/typescript';
const createProgram = proxyCreateProgram(ts, ts.createProgram, (ts, options) => {
const { configFilePath } = options.options;
const vueOptions = typeof configFilePath === 'string'
? vue.createParsedCommandLine(ts, ts.sys, configFilePath.replace(/\\/g, '/')).vueOptions
: vue.createParsedCommandLineByJson(ts, ts.sys, (options.host ?? ts.sys).getCurrentDirectory(), {})
.vueOptions;
vueOptions.globalTypesPath = vue.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
const vueLanguagePlugin = vue.createVueLanguagePlugin<string>(
ts,
options.options,
vueOptions,
id => id,
);
return { languagePlugins: [vueLanguagePlugin] };
});
createProgram({
// ...
});