@@ -752,4 +752,63 @@ describe('framework shim', () => {
752752 expect ( report . frameworkShimAdded ) . toBe ( true ) ;
753753 } ) ;
754754 } ) ;
755+
756+ describe ( 'create flow integration' , ( ) => {
757+ it ( 'does not add duplicate shim when template already wrote env.d.ts' , ( ) => {
758+ // Simulate create-vue having already written a shim into src/env.d.ts
759+ const srcDir = path . join ( tmpDir , 'src' ) ;
760+ fs . mkdirSync ( srcDir ) ;
761+ const existingShim = "declare module '*.vue' {\n import type { DefineComponent } from 'vue';\n const component: DefineComponent;\n export default component;\n}\n" ;
762+ fs . writeFileSync ( path . join ( srcDir , 'env.d.ts' ) , existingShim ) ;
763+
764+ const framework = detectFramework (
765+ ( ( ) => {
766+ fs . writeFileSync (
767+ path . join ( tmpDir , 'package.json' ) ,
768+ JSON . stringify ( { devDependencies : { vue : '^3.0.0' } } ) ,
769+ ) ;
770+ return tmpDir ;
771+ } ) ( ) ,
772+ ) ;
773+ expect ( framework ) . toBe ( 'vue' ) ;
774+ // Gate check: shim already present, so addFrameworkShim should NOT be called
775+ expect ( hasFrameworkShim ( tmpDir , 'vue' ) ) . toBe ( true ) ;
776+ // Verify content is unchanged if caller respects the gate
777+ const contentBefore = fs . readFileSync ( path . join ( srcDir , 'env.d.ts' ) , 'utf-8' ) ;
778+ if ( ! hasFrameworkShim ( tmpDir , 'vue' ) ) {
779+ addFrameworkShim ( tmpDir , 'vue' ) ;
780+ }
781+ const contentAfter = fs . readFileSync ( path . join ( srcDir , 'env.d.ts' ) , 'utf-8' ) ;
782+ expect ( contentAfter ) . toBe ( contentBefore ) ;
783+ } ) ;
784+
785+ it ( 'adds shim for vue project created without env.d.ts' , ( ) => {
786+ fs . mkdirSync ( path . join ( tmpDir , 'src' ) ) ;
787+ fs . writeFileSync (
788+ path . join ( tmpDir , 'package.json' ) ,
789+ JSON . stringify ( { devDependencies : { vue : '^3.0.0' } } ) ,
790+ ) ;
791+ const framework = detectFramework ( tmpDir ) ;
792+ expect ( framework ) . toBe ( 'vue' ) ;
793+ if ( framework && ! hasFrameworkShim ( tmpDir , framework ) ) {
794+ addFrameworkShim ( tmpDir , framework ) ;
795+ }
796+ const content = fs . readFileSync ( path . join ( tmpDir , 'src' , 'env.d.ts' ) , 'utf-8' ) ;
797+ expect ( content ) . toContain ( "declare module '*.vue'" ) ;
798+ } ) ;
799+
800+ it ( 'adds astro shim for astro project without env.d.ts' , ( ) => {
801+ fs . writeFileSync (
802+ path . join ( tmpDir , 'package.json' ) ,
803+ JSON . stringify ( { devDependencies : { astro : '^4.0.0' } } ) ,
804+ ) ;
805+ const framework = detectFramework ( tmpDir ) ;
806+ expect ( framework ) . toBe ( 'astro' ) ;
807+ if ( framework && ! hasFrameworkShim ( tmpDir , framework ) ) {
808+ addFrameworkShim ( tmpDir , framework ) ;
809+ }
810+ const content = fs . readFileSync ( path . join ( tmpDir , 'env.d.ts' ) , 'utf-8' ) ;
811+ expect ( content ) . toContain ( '/// <reference types="astro/client" />' ) ;
812+ } ) ;
813+ } ) ;
755814} ) ;
0 commit comments