language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Alternatives to the old createProgram?

Open ilteoood opened this issue 1 year ago • 4 comments

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

ilteoood avatar Jul 27 '24 13:07 ilteoood

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 avatar Jul 28 '24 06:07 so1ve

@so1ve if I got it correctly, the function that should cover my scenario is the getLanguagePlugins, isn't it?

ilteoood avatar Jul 28 '24 08:07 ilteoood

Perhaps no? I'm not familiar with volar.js but I guess you may use proxyCreateProgram and getLanguagePlugins together?

so1ve avatar Jul 29 '24 10:07 so1ve

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.

Sysix avatar Jul 31 '24 16:07 Sysix

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({
	// ...
});

johnsoncodehk avatar Nov 24 '25 09:11 johnsoncodehk