File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,21 @@ const errorToString = err => {
2525 else return err
2626}
2727
28+ /**
29+ * Write a large string or buffer to stdout and wait for the drain event
30+ *
31+ * This is needed to avoid truncating buffered output when piped
32+ * @param {string } data
33+ * @param {function } cb
34+ */
35+ const writeStdout = ( data , cb ) => {
36+ if ( ! process . stdout . write ( data ) ) {
37+ process . stdout . once ( 'drain' , cb )
38+ } else {
39+ process . nextTick ( cb )
40+ }
41+ }
42+
2843export default function ( dir , options ) {
2944 process . on ( 'unhandledRejection' , err => {
3045 console . log (
@@ -39,8 +54,9 @@ export default function(dir, options) {
3954 if ( fs . existsSync ( dir ) ) {
4055 if ( options . json ) {
4156 validate . BIDS ( dir , options , function ( issues , summary ) {
42- console . log ( JSON . stringify ( { issues, summary } ) )
43- exitProcess ( issues )
57+ writeStdout ( JSON . stringify ( { issues, summary } ) , ( ) =>
58+ exitProcess ( issues ) ,
59+ )
4460 } )
4561 } else {
4662 validate . BIDS ( dir , options , function ( issues , summary ) {
You can’t perform that action at this time.
0 commit comments