@@ -46,7 +46,7 @@ function sanitizeFilePath(filePath) {
4646 throw new Error ( `File outside VueApp directory: ${ filePath } ` ) ;
4747 }
4848
49- // Ensure it's a Vue, JS, or TS file
49+ // Ensure it's a Vue, JS, TS, JSX, or TSX file
5050 const allowedExtensions = [ '.vue' , '.js' , '.ts' , '.jsx' , '.tsx' ] ;
5151 const ext = path . extname ( resolvedPath ) . toLowerCase ( ) ;
5252 if ( ! allowedExtensions . includes ( ext ) ) {
@@ -109,11 +109,43 @@ try {
109109 const tsFiles = files . filter ( file => / \. ( t s | t s x | v u e ) $ / . test ( file ) ) ;
110110
111111 if ( tsFiles . length > 0 ) {
112- // Use vue-tsc for type checking since this is a Vue project
113- const tscArgs = [ '--noEmit' , ...tsFiles ] ;
112+ // Create a temporary tsconfig for only the changed files
113+ const tempTsConfig = path . join ( vueAppDir , 'tsconfig.lint-staged.json' ) ;
114+ const baseTsConfig = path . join ( vueAppDir , 'tsconfig.app.json' ) ;
114115
115- if ( ! runCommand ( 'vue-tsc' , tscArgs , 'TypeScript type checking' ) ) {
116+ try {
117+ // Read the base tsconfig
118+ const baseConfig = JSON . parse ( fs . readFileSync ( baseTsConfig , 'utf8' ) ) ;
119+
120+ // Create a temporary config that includes only the changed files
121+ const tempConfig = {
122+ ...baseConfig ,
123+ include : tsFiles . map ( file => `./${ file } ` ) ,
124+ exclude : [ ] // Don't exclude anything for lint-staged
125+ } ;
126+
127+ // Write temporary config
128+ fs . writeFileSync ( tempTsConfig , JSON . stringify ( tempConfig , null , 2 ) ) ;
129+
130+ // Run vue-tsc with the temporary config
131+ const tscArgs = [ '--noEmit' , '--project' , tempTsConfig ] ;
132+
133+ if ( ! runCommand ( 'vue-tsc' , tscArgs , 'TypeScript type checking (changed files only)' ) ) {
134+ success = false ;
135+ }
136+
137+ } catch ( configError ) {
138+ console . error ( 'Failed to create temporary tsconfig:' , configError ) ;
116139 success = false ;
140+ } finally {
141+ // Clean up temporary config file
142+ try {
143+ if ( fs . existsSync ( tempTsConfig ) ) {
144+ fs . unlinkSync ( tempTsConfig ) ;
145+ }
146+ } catch ( cleanupError ) {
147+ console . warn ( 'Failed to clean up temporary tsconfig:' , cleanupError ) ;
148+ }
117149 }
118150 }
119151
0 commit comments