@@ -39,8 +39,9 @@ export function createParsedCommandLineByJson(
3939 resolvedVueOptions . __setupedGlobalTypes = true ;
4040 }
4141 else {
42- resolvedVueOptions . __setupedGlobalTypes = setupGlobalTypes ( rootDir , resolvedVueOptions , parseConfigHost ) ;
43- resolvedVueOptions . __setupedGlobalTypesAbsolutePath = getSetupedGlobalTypesAbsolutePath ( rootDir , resolvedVueOptions , parseConfigHost ) ;
42+ const setupResult = setupGlobalTypes ( rootDir , resolvedVueOptions , parseConfigHost ) ;
43+ resolvedVueOptions . __setupedGlobalTypes = setupResult . done ;
44+ resolvedVueOptions . __setupedGlobalTypesAbsolutePath = setupResult . absolutePath ;
4445 }
4546 const parsed = ts . parseJsonConfigFileContent (
4647 json ,
@@ -95,8 +96,9 @@ export function createParsedCommandLine(
9596 resolvedVueOptions . __setupedGlobalTypes = true ;
9697 }
9798 else {
98- resolvedVueOptions . __setupedGlobalTypes = setupGlobalTypes ( path . dirname ( tsConfigPath ) , resolvedVueOptions , parseConfigHost ) ;
99- resolvedVueOptions . __setupedGlobalTypesAbsolutePath = getSetupedGlobalTypesAbsolutePath ( path . dirname ( tsConfigPath ) , resolvedVueOptions , parseConfigHost ) ;
99+ const setupResult = setupGlobalTypes ( path . dirname ( tsConfigPath ) , resolvedVueOptions , parseConfigHost ) ;
100+ resolvedVueOptions . __setupedGlobalTypes = setupResult . done ;
101+ resolvedVueOptions . __setupedGlobalTypesAbsolutePath = setupResult . absolutePath ;
100102 }
101103 const parsed = ts . parseJsonSourceFileConfigFileContent (
102104 config ,
@@ -283,9 +285,9 @@ export function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions
283285export function setupGlobalTypes ( rootDir : string , vueOptions : VueCompilerOptions , host : {
284286 fileExists ( path : string ) : boolean ;
285287 writeFile ?( path : string , data : string ) : void ;
286- } ) {
288+ } ) : { done : boolean ; absolutePath ?: string ; } {
287289 if ( ! host . writeFile ) {
288- return false ;
290+ return { done : false } ;
289291 }
290292 try {
291293 let dir = rootDir ;
@@ -299,32 +301,8 @@ export function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions
299301 const globalTypesPath = path . join ( dir , 'node_modules' , '.vue-global-types' , `${ vueOptions . lib } _${ vueOptions . target } _${ vueOptions . strictTemplates } .d.ts` ) ;
300302 const globalTypesContents = `// @ts-nocheck\nexport {};\n` + generateGlobalTypes ( vueOptions . lib , vueOptions . target , vueOptions . strictTemplates ) ;
301303 host . writeFile ( globalTypesPath , globalTypesContents ) ;
302- return true ;
304+ return { done : true , absolutePath : globalTypesPath } ;
303305 } catch {
304- return false ;
305- }
306- }
307-
308- function getSetupedGlobalTypesAbsolutePath ( rootDir : string , vueOptions : VueCompilerOptions , host : {
309- fileExists ( path : string ) : boolean ;
310- writeFile ?( path : string , data : string ) : void ;
311- } ) {
312- try {
313- let dir = rootDir ;
314-
315- while ( ! host . fileExists ( path . posix . join ( dir , 'node_modules' , vueOptions . lib , 'package.json' ) ) ) {
316-
317- const parentDir = path . posix . dirname ( dir ) ;
318- if ( dir === parentDir ) {
319- throw 0 ;
320- }
321- dir = parentDir ;
322- }
323- const globalTypesPath = path . posix . join ( dir , 'node_modules' , '.vue-global-types' , `${ vueOptions . lib } _${ vueOptions . target } _${ vueOptions . strictTemplates } .d.ts` ) ;
324-
325- return globalTypesPath ;
326- }
327- catch {
328- return '' ;
306+ return { done : false } ;
329307 }
330308}
0 commit comments