@@ -3,12 +3,13 @@ import { createDebug } from 'obug'
33import type { TscOptions } from './types.ts'
44import type Ts from 'typescript'
55
6- function loadVueLanguageTools ( ) {
7- const debug = createDebug ( 'rolldown-plugin-dts:vue' )
6+ const debug = createDebug ( 'rolldown-plugin-dts:volar' )
7+
8+ export function loadVueLanguageTools ( ) {
89 debug ( 'loading vue language tools' )
910 try {
1011 const vueTscPath = require . resolve ( 'vue-tsc' )
11- const { proxyCreateProgram } = require (
12+ const volarTs = require (
1213 require . resolve ( '@volar/typescript' , {
1314 paths : [ vueTscPath ] ,
1415 } ) ,
@@ -18,27 +19,7 @@ function loadVueLanguageTools() {
1819 paths : [ vueTscPath ] ,
1920 } ) ,
2021 ) as typeof import ( '@vue/language-core' )
21- const getLanguagePlugin = (
22- ts : typeof Ts ,
23- options : Ts . CreateProgramOptions ,
24- ) => {
25- const $rootDir = options . options . $rootDir as string
26- const $configRaw = options . options . $configRaw as
27- | ( Ts . TsConfigSourceFile & { vueCompilerOptions ?: any } )
28- | undefined
29-
30- const resolver = new vue . CompilerOptionsResolver ( ts , ts . sys . readFile )
31- resolver . addConfig ( $configRaw ?. vueCompilerOptions ?? { } , $rootDir )
32- const vueOptions = resolver . build ( )
33-
34- return vue . createVueLanguagePlugin < string > (
35- ts ,
36- options . options ,
37- vueOptions ,
38- ( id ) => id ,
39- )
40- }
41- return { proxyCreateProgram, getLanguagePlugin }
22+ return { volarTs, vue }
4223 } catch ( error ) {
4324 debug ( 'vue language tools not found' , error )
4425 throw new Error (
@@ -47,7 +28,36 @@ function loadVueLanguageTools() {
4728 }
4829}
4930
50- function loadTsMacro ( ) {
31+ function initVueLanguageTools ( ) {
32+ const {
33+ vue,
34+ volarTs : { proxyCreateProgram } ,
35+ } = loadVueLanguageTools ( )
36+
37+ const getLanguagePlugin = (
38+ ts : typeof Ts ,
39+ options : Ts . CreateProgramOptions ,
40+ ) => {
41+ const $rootDir = options . options . $rootDir as string
42+ const $configRaw = options . options . $configRaw as
43+ | ( Ts . TsConfigSourceFile & { vueCompilerOptions ?: any } )
44+ | undefined
45+
46+ const resolver = new vue . CompilerOptionsResolver ( ts , ts . sys . readFile )
47+ resolver . addConfig ( $configRaw ?. vueCompilerOptions ?? { } , $rootDir )
48+ const vueOptions = resolver . build ( )
49+
50+ return vue . createVueLanguagePlugin < string > (
51+ ts ,
52+ options . options ,
53+ vueOptions ,
54+ ( id ) => id ,
55+ )
56+ }
57+ return { proxyCreateProgram, getLanguagePlugin }
58+ }
59+
60+ function initTsMacro ( ) {
5161 const debug = createDebug ( 'rolldown-plugin-dts:ts-macro' )
5262 debug ( 'loading ts-macro language tools' )
5363 try {
@@ -93,8 +103,8 @@ export function createProgramFactory(
93103 ts : typeof Ts ,
94104 options : Pick < TscOptions , 'vue' | 'tsMacro' > ,
95105) : typeof Ts . createProgram {
96- const vueLanguageTools = options . vue ? loadVueLanguageTools ( ) : undefined
97- const tsMacroLanguageTools = options . tsMacro ? loadTsMacro ( ) : undefined
106+ const vueLanguageTools = options . vue ? initVueLanguageTools ( ) : undefined
107+ const tsMacroLanguageTools = options . tsMacro ? initTsMacro ( ) : undefined
98108 const proxyCreateProgram =
99109 vueLanguageTools ?. proxyCreateProgram ||
100110 tsMacroLanguageTools ?. proxyCreateProgram
0 commit comments