11#!/usr/bin/env node
22
3- const { spawnSync } = require ( 'child_process' )
43const fs = require ( 'fs' )
4+ const { spawnSync } = require ( 'child_process' )
55const { dirname, join } = require ( 'path' )
66
7+ const { minimatch } = require ( 'minimatch' )
8+
79const randomChars = ( ) => {
810 return Math . random ( ) . toString ( 36 ) . slice ( 2 )
911}
@@ -29,24 +31,32 @@ const argsProjectValue =
2931const argsLeaveIncludesUntouched =
3032 args . findIndex ( arg => [ '-i' ] . includes ( arg ) ) !== - 1
3133
32- const files = args . filter ( file => / \. ( t s | t s x ) $ / . test ( file ) )
34+ // Load existing config
35+ const tsconfigPath = argsProjectValue || resolveFromRoot ( 'tsconfig.json' )
36+ const tsconfigContent = fs . readFileSync ( tsconfigPath ) . toString ( )
37+ // Use 'eval' to read the JSON as regular JavaScript syntax so that comments are allowed
38+ let tsconfig = { }
39+ eval ( `tsconfig = ${ tsconfigContent } ` )
40+
41+ const isExcluded = file =>
42+ ( tsconfig ?. exclude ?? [ ] ) . some ( pattern => minimatch ( file , pattern ) )
43+
44+ const filesInArgs = args . filter ( file => / \. ( t s | t s x ) $ / . test ( file ) )
45+
46+ const files = filesInArgs . filter ( file => ! isExcluded ( file ) )
47+
3348if ( files . length === 0 ) {
3449 process . exit ( 0 )
3550}
3651
37- const remainingArgsToForward = args . slice ( ) . filter ( arg => ! files . includes ( arg ) )
52+ const remainingArgsToForward = args
53+ . slice ( )
54+ . filter ( arg => ! filesInArgs . includes ( arg ) )
3855
3956if ( argsProjectIndex !== - 1 ) {
4057 remainingArgsToForward . splice ( argsProjectIndex , 2 )
4158}
4259
43- // Load existing config
44- const tsconfigPath = argsProjectValue || resolveFromRoot ( 'tsconfig.json' )
45- const tsconfigContent = fs . readFileSync ( tsconfigPath ) . toString ( )
46- // Use 'eval' to read the JSON as regular JavaScript syntax so that comments are allowed
47- let tsconfig = { }
48- eval ( `tsconfig = ${ tsconfigContent } ` )
49-
5060// Write a temp config file
5161const tmpTsconfigPath = resolveFromRoot ( `tsconfig.${ randomChars ( ) } .json` )
5262const tmpTsconfig = {
0 commit comments