@@ -51,20 +51,14 @@ function getFileRegistryKey(
5151 return JSON . stringify ( values ) ;
5252}
5353
54- export interface _Plugin < T > extends LanguagePlugin < T , VueVirtualCode > {
55- getCanonicalFileName : ( fileName : string ) => string ;
56- pluginContext : Parameters < VueLanguagePlugin > [ 0 ] ;
57- }
58-
5954export function createVueLanguagePlugin < T > (
6055 ts : typeof import ( 'typescript' ) ,
6156 asFileName : ( scriptId : T ) => string ,
62- useCaseSensitiveFileNames : boolean ,
6357 getProjectVersion : ( ) => string ,
64- getScriptFileNames : ( ) => string [ ] | Set < string > ,
58+ isRootFile : ( fileName : string ) => boolean ,
6559 compilerOptions : ts . CompilerOptions ,
6660 vueCompilerOptions : VueCompilerOptions
67- ) : _Plugin < T > {
61+ ) : LanguagePlugin < T , VueVirtualCode > {
6862 const pluginContext : Parameters < VueLanguagePlugin > [ 0 ] = {
6963 modules : {
7064 '@vue/compiler-dom' : vueCompilerOptions . target < 3
@@ -83,16 +77,10 @@ export function createVueLanguagePlugin<T>(
8377 const vueSfcPlugin = useVueFilePlugin ( pluginContext ) ;
8478 const vitePressSfcPlugin = useMdFilePlugin ( pluginContext ) ;
8579 const petiteVueSfcPlugin = useHtmlFilePlugin ( pluginContext ) ;
86- const getCanonicalFileName = useCaseSensitiveFileNames
87- ? ( fileName : string ) => fileName
88- : ( fileName : string ) => fileName . toLowerCase ( ) ;
8980
90- let canonicalRootFileNames = new Set < string > ( ) ;
9181 let canonicalRootFileNamesVersion : string | undefined ;
9282
9383 return {
94- getCanonicalFileName,
95- pluginContext,
9684 getLanguageId ( scriptId ) {
9785 if ( vueCompilerOptions . extensions . some ( ext => asFileName ( scriptId ) . endsWith ( ext ) ) ) {
9886 return 'vue' ;
@@ -107,13 +95,11 @@ export function createVueLanguagePlugin<T>(
10795 createVirtualCode ( scriptId , languageId , snapshot ) {
10896 if ( languageId === 'vue' || languageId === 'markdown' || languageId === 'html' ) {
10997 const fileName = asFileName ( scriptId ) ;
110- const projectVersion = getProjectVersion ( ) ;
111- if ( projectVersion !== canonicalRootFileNamesVersion ) {
112- canonicalRootFileNames = new Set ( [ ...getScriptFileNames ( ) ] . map ( getCanonicalFileName ) ) ;
113- canonicalRootFileNamesVersion = projectVersion ;
114- }
115- if ( ! pluginContext . globalTypesHolder && canonicalRootFileNames . has ( getCanonicalFileName ( fileName ) ) ) {
116- pluginContext . globalTypesHolder = fileName ;
98+ if ( ! pluginContext . globalTypesHolder && getProjectVersion ( ) !== canonicalRootFileNamesVersion ) {
99+ canonicalRootFileNamesVersion = getProjectVersion ( ) ;
100+ if ( isRootFile ( fileName ) ) {
101+ pluginContext . globalTypesHolder = fileName ;
102+ }
117103 }
118104 const fileRegistry = getFileRegistry ( pluginContext . globalTypesHolder === fileName ) ;
119105 const code = fileRegistry . get ( fileName ) ;
0 commit comments