@@ -21,6 +21,7 @@ function processToPromise(process) {
2121class DartFormatter implements DiffingBroccoliPlugin {
2222 private DARTFMT : string ;
2323 private verbose : boolean ;
24+ private firstBuild : boolean = true ;
2425
2526 constructor ( public inputPath : string , public cachePath : string , options ) {
2627 if ( ! options . dartSDK ) throw new Error ( "Missing Dart SDK" ) ;
@@ -30,34 +31,58 @@ class DartFormatter implements DiffingBroccoliPlugin {
3031
3132 rebuild ( treeDiff : DiffResult ) : Promise < any > {
3233 let args = [ '-w' ] ;
34+ let argsLength = 2 ;
35+ let argPackages = [ ] ;
36+ let firstBuild = this . firstBuild ;
3337 treeDiff . addedPaths . concat ( treeDiff . changedPaths )
3438 . forEach ( ( changedFile ) => {
3539 let sourcePath = path . join ( this . inputPath , changedFile ) ;
3640 let destPath = path . join ( this . cachePath , changedFile ) ;
37- if ( / \. d a r t $ / . test ( changedFile ) ) args . push ( destPath ) ;
41+ if ( ! firstBuild && / \. d a r t $ / . test ( changedFile ) ) {
42+ if ( ( argsLength + destPath . length + 2 ) >= 0x2000 ) {
43+ // Win32 command line arguments length
44+ argPackages . push ( args ) ;
45+ args = [ '-w' ] ;
46+ argsLength = 2 ;
47+ }
48+ args . push ( destPath ) ;
49+ argsLength += destPath . length + 2 ;
50+ }
3851 fse . copySync ( sourcePath , destPath ) ;
3952 } ) ;
4053 treeDiff . removedPaths . forEach ( ( removedFile ) => {
4154 let destPath = path . join ( this . cachePath , removedFile ) ;
4255 fse . removeSync ( destPath ) ;
4356 } ) ;
4457
45- if ( args . length < 1 ) {
46- return Promise . resolve ( ) ;
58+ if ( ! firstBuild && args . length > 1 ) {
59+ argPackages . push ( args ) ;
4760 }
48- return new Promise ( ( resolve , reject ) => {
49- exec ( this . DARTFMT + ' ' + args . join ( ' ' ) , ( err , stdout , stderr ) => {
50- if ( this . verbose ) {
51- console . log ( stdout ) ;
52- }
53- if ( err ) {
54- console . error ( shortenFormatterOutput ( stderr ) ) ;
55- reject ( 'Formatting failed.' ) ;
56- } else {
57- resolve ( ) ;
58- }
61+
62+ let execute = ( args ) => {
63+ if ( args . length < 2 ) return Promise . resolve ( ) ;
64+ return new Promise ( ( resolve , reject ) => {
65+ exec ( this . DARTFMT + ' ' + args . join ( ' ' ) , ( err , stdout , stderr ) => {
66+ if ( this . verbose ) {
67+ console . log ( stdout ) ;
68+ }
69+ if ( err ) {
70+ console . error ( shortenFormatterOutput ( stderr ) ) ;
71+ reject ( 'Formatting failed.' ) ;
72+ } else {
73+ resolve ( ) ;
74+ }
75+ } ) ;
5976 } ) ;
60- } ) ;
77+ } ;
78+
79+ if ( firstBuild ) {
80+ // On firstBuild, format the entire cachePath
81+ this . firstBuild = false ;
82+ return execute ( [ '-w' , this . cachePath ] ) ;
83+ }
84+
85+ return Promise . all ( argPackages . map ( execute ) ) ;
6186 }
6287}
6388
0 commit comments