@@ -98,9 +98,39 @@ const LINTERS = [{
98
98
test : filename => filename . endsWith ( '.js' ) || filename . endsWith ( '.ts' ) ,
99
99
run : ( opts , filenames ) => {
100
100
const cmd = path . join ( SOURCE_ROOT , 'node_modules' , '.bin' , 'eslint' ) ;
101
- const args = [ '--cache' , '--ext' , '.js,.ts' , ... filenames ] ;
101
+ const args = [ '--cache' , '--ext' , '.js,.ts' ] ;
102
102
if ( opts . fix ) args . unshift ( '--fix' ) ;
103
- spawnAndCheckExitCode ( cmd , args , { cwd : SOURCE_ROOT } ) ;
103
+ // Windows has a max command line length of 2047 characters, so we can't provide
104
+ // all of the filenames without going over that. To work around it, run eslint
105
+ // multiple times and chunk the filenames so that each run is under that limit.
106
+ // Use a much higher limit on other platforms which will effectively be a no-op.
107
+ const MAX_FILENAME_ARGS_LENGTH = IS_WINDOWS ? 1900 : 100 * 1024 ;
108
+ const cmdOpts = { stdio : 'inherit' , shell : IS_WINDOWS , cwd : SOURCE_ROOT } ;
109
+ if ( IS_WINDOWS ) {
110
+ // When running with shell spaces in filenames are problematic
111
+ filenames = filenames . map ( filename => `"${ filename } "` ) ;
112
+ }
113
+ const chunkedFilenames = filenames . reduce ( ( chunkedFilenames , filename ) => {
114
+ const currentChunk = chunkedFilenames [ chunkedFilenames . length - 1 ] ;
115
+ const currentChunkLength = currentChunk . reduce ( ( totalLength , _filename ) => totalLength + _filename . length , 0 ) ;
116
+ if ( currentChunkLength + filename . length > MAX_FILENAME_ARGS_LENGTH ) {
117
+ chunkedFilenames . push ( [ filename ] ) ;
118
+ } else {
119
+ currentChunk . push ( filename ) ;
120
+ }
121
+ return chunkedFilenames ;
122
+ } , [ [ ] ] ) ;
123
+ const allOk = chunkedFilenames . map ( filenames => {
124
+ const result = childProcess . spawnSync ( cmd , [ ...args , ...filenames ] , cmdOpts ) ;
125
+ if ( result . error ) {
126
+ console . error ( result . error ) ;
127
+ process . exit ( result . status || 1 ) ;
128
+ }
129
+ return result . status === 0 ;
130
+ } ) . every ( x => x ) ;
131
+ if ( ! allOk ) {
132
+ process . exit ( 1 ) ;
133
+ }
104
134
}
105
135
} , {
106
136
key : 'gn' ,
0 commit comments