@@ -11,6 +11,10 @@ import { RunnerConfig } from "../ci/runner"
1111
1212const d = debug ( "runDangerSubprocess" )
1313
14+ // If a sub-process passes this to stdout then danger-js will pass
15+ // the DSL back to the process
16+ const messageToSendDSL = "danger://send-dsl"
17+
1418// Sanitizes the DSL so for sending via STDOUT
1519export const prepareDangerDSL = ( dangerDSL : DangerDSLJSONType ) => {
1620 if ( dangerDSL . github && dangerDSL . github . api ) {
@@ -38,25 +42,39 @@ export const runDangerSubprocess = (
3842 d ( `Running subprocess: ${ processDisplayName } - ${ args } ` )
3943 const child = spawn ( processName , args , { env : { ...process . env , ...config . additionalEnvVars } } )
4044
41- d ( `Started passing in STDIN` )
42- child . stdin . write ( dslJSONString )
43- child . stdin . end ( )
44- d ( `Passed in STDIN` )
45+ const sendDSLToSubprocess = ( ) => {
46+ d ( `Started passing in STDIN` )
47+ child . stdin . write ( dslJSONString )
48+ child . stdin . end ( )
49+ d ( `Passed in STDIN` )
50+ }
51+
52+ // Initial sending of the DSL
53+ sendDSLToSubprocess ( )
4554
4655 let allLogs = ""
4756 child . stdout . on ( "data" , async data => {
48- const stdout = data . toString ( )
57+ const stdout : string = data . toString ( )
4958 allLogs += stdout
5059
51- // There are two checks
60+ // Provide a way for a process to request the DSL
61+ // if they missed the first go.
62+ if ( stdout . includes ( messageToSendDSL ) ) {
63+ sendDSLToSubprocess ( )
64+ }
65+
66+ // There are two checks for a response
5267 const maybeJSON = getJSONFromSTDOUT ( stdout )
5368 const maybeJSONURL = getJSONURLFromSTDOUT ( stdout )
5469
5570 // Remove message sent back to danger-js
5671 const withoutURLs : string = data
5772 . toString ( )
5873 . replace ( maybeJSON , "" )
74+ . replace ( maybeJSONURL + "\n" , "" )
5975 . replace ( maybeJSONURL , "" )
76+ . replace ( messageToSendDSL + "\n" , "" )
77+ . replace ( messageToSendDSL , "" )
6078
6179 console . log ( withoutURLs )
6280
0 commit comments