@@ -6,7 +6,7 @@ const os = require("os");
66const path = require ( "path" ) ;
77const resolve = require ( "resolve" ) . sync ;
88const spawn = require ( "child_process" ) . spawn ;
9- const glob = require ( "glob" ) ;
9+ const { globSync } = require ( "glob" ) ;
1010const async = require ( "async" ) ;
1111
1212const VERSION = require ( "./package.json" ) . version ;
@@ -82,52 +82,47 @@ function spawnGoogleJavaFormat(args, done, stdio) {
8282 // remove glob from arg list
8383 args = args . filter ( ( arg ) => arg . indexOf ( GLOB_OPTION ) === - 1 ) ;
8484
85- glob ( filesGlob , function ( err , files ) {
86- if ( err ) {
87- done ( err ) ;
88- return ;
89- }
90-
91- // split file array into chunks of 30
92- let i ,
93- j ,
94- chunks = [ ] ,
95- chunkSize = 30 ;
96-
97- for ( i = 0 , j = files . length ; i < j ; i += chunkSize ) {
98- chunks . push ( files . slice ( i , i + chunkSize ) ) ;
99- }
100-
101- // launch a new process for each chunk
102- async . series (
103- chunks . map ( function ( chunk ) {
104- return function ( callback ) {
105- const googlejavaFormatProcess = spawn (
106- nativeBinary ,
107- args . concat ( chunk ) ,
108- { stdio : stdio }
109- ) ;
110- googlejavaFormatProcess . on ( "close" , function ( exit ) {
111- if ( exit !== 0 ) callback ( errorFromExitCode ( exit ) ) ;
112- else callback ( ) ;
113- } ) ;
114- } ;
115- } ) ,
116- function ( err ) {
117- if ( err ) {
118- done ( err ) ;
119- return ;
120- }
121- console . log ( "\n" ) ;
122- console . log (
123- `ran google-java-format on ${ files . length } ${
124- files . length === 1 ? "file" : "files"
125- } `
85+ const files = globSync ( filesGlob ) ;
86+
87+ // split file array into chunks of 30
88+ let i ,
89+ j ,
90+ chunks = [ ] ,
91+ chunkSize = 30 ;
92+
93+ for ( i = 0 , j = files . length ; i < j ; i += chunkSize ) {
94+ chunks . push ( files . slice ( i , i + chunkSize ) ) ;
95+ }
96+
97+ // launch a new process for each chunk
98+ async . series (
99+ chunks . map ( function ( chunk ) {
100+ return function ( callback ) {
101+ const googlejavaFormatProcess = spawn (
102+ nativeBinary ,
103+ args . concat ( chunk ) ,
104+ { stdio : stdio }
126105 ) ;
127- done ( ) ;
106+ googlejavaFormatProcess . on ( "close" , function ( exit ) {
107+ if ( exit !== 0 ) callback ( errorFromExitCode ( exit ) ) ;
108+ else callback ( ) ;
109+ } ) ;
110+ } ;
111+ } ) ,
112+ function ( err ) {
113+ if ( err ) {
114+ done ( err ) ;
115+ return ;
128116 }
129- ) ;
130- } ) ;
117+ console . log ( "\n" ) ;
118+ console . log (
119+ `ran google-java-format on ${ files . length } ${
120+ files . length === 1 ? "file" : "files"
121+ } `
122+ ) ;
123+ done ( ) ;
124+ }
125+ ) ;
131126 } else {
132127 const googlejavaFormatProcess = spawn ( nativeBinary , args , { stdio : stdio } ) ;
133128 googlejavaFormatProcess . on ( "close" , function ( exit ) {
0 commit comments