@@ -48,14 +48,21 @@ function getFileRegistryKey(
48
48
return JSON . stringify ( values ) ;
49
49
}
50
50
51
+ interface _Plugin extends LanguagePlugin < VueGeneratedCode > {
52
+ getCanonicalFileName : ( fileName : string ) => string ;
53
+ pluginContext : Parameters < VueLanguagePlugin > [ 0 ] ;
54
+ }
55
+
51
56
export function createVueLanguagePlugin (
52
57
ts : typeof import ( 'typescript' ) ,
53
58
getFileName : ( fileId : string ) => string ,
54
- isValidGlobalTypesHolder : ( fileName : string ) => boolean ,
59
+ useCaseSensitiveFileNames : boolean ,
60
+ getProjectVersion : ( ) => string ,
61
+ getScriptFileNames : ( ) => string [ ] | Set < string > ,
55
62
compilerOptions : ts . CompilerOptions ,
56
63
vueCompilerOptions : VueCompilerOptions ,
57
64
codegenStack : boolean = false ,
58
- ) : LanguagePlugin < VueGeneratedCode > {
65
+ ) : _Plugin {
59
66
const allowLanguageIds = new Set ( [ 'vue' ] ) ;
60
67
const pluginContext : Parameters < VueLanguagePlugin > [ 0 ] = {
61
68
modules : {
@@ -81,11 +88,24 @@ export function createVueLanguagePlugin(
81
88
allowLanguageIds . add ( 'html' ) ;
82
89
}
83
90
91
+ const getCanonicalFileName = useCaseSensitiveFileNames
92
+ ? ( fileName : string ) => fileName
93
+ : ( fileName : string ) => fileName . toLowerCase ( ) ;
94
+ let canonicalRootFileNames = new Set < string > ( ) ;
95
+ let canonicalRootFileNamesVersion : string | undefined ;
96
+
84
97
return {
98
+ getCanonicalFileName,
99
+ pluginContext,
85
100
createVirtualCode ( fileId , languageId , snapshot ) {
86
101
if ( allowLanguageIds . has ( languageId ) ) {
87
102
const fileName = getFileName ( fileId ) ;
88
- if ( ! pluginContext . globalTypesHolder && isValidGlobalTypesHolder ( fileName ) ) {
103
+ const projectVersion = getProjectVersion ( ) ;
104
+ if ( projectVersion !== canonicalRootFileNamesVersion ) {
105
+ canonicalRootFileNames = new Set ( [ ...getScriptFileNames ( ) ] . map ( getCanonicalFileName ) ) ;
106
+ canonicalRootFileNamesVersion = projectVersion ;
107
+ }
108
+ if ( ! pluginContext . globalTypesHolder && canonicalRootFileNames . has ( getCanonicalFileName ( fileName ) ) ) {
89
109
pluginContext . globalTypesHolder = fileName ;
90
110
}
91
111
const fileRegistry = getFileRegistry ( pluginContext . globalTypesHolder === fileName ) ;
0 commit comments