@@ -6,7 +6,7 @@ import split2 from "split2";
66import { Utils } from "./utils.js" ;
77import { WriteStreams } from "./write-streams.js" ;
88import { GitData } from "./git-data.js" ;
9- import assert , { AssertionError } from "assert" ;
9+ import assert , { AssertionError } from "node: assert" ;
1010import { Mutex } from "./mutex.js" ;
1111import { Argv } from "./argv.js" ;
1212import execa from "execa" ;
@@ -418,10 +418,10 @@ If you know what you're doing and would like to suppress this warning, use one o
418418 }
419419 break ;
420420 case "object" :
421- if ( ! Array . isArray ( allowFailure . exit_codes ) ) {
422- allowedExitCodes = [ allowFailure . exit_codes ] ;
423- } else {
421+ if ( Array . isArray ( allowFailure . exit_codes ) ) {
424422 allowedExitCodes = allowFailure . exit_codes ;
423+ } else {
424+ allowedExitCodes = [ allowFailure . exit_codes ] ;
425425 }
426426 break ;
427427 default :
@@ -685,12 +685,11 @@ If you know what you're doing and would like to suppress this warning, use one o
685685 const tmpVolumeName = this . tmpVolumeName ;
686686 const fileVariablesDir = this . fileVariablesDir ;
687687
688- const volumePromises = [ ] ;
689- volumePromises . push ( Utils . spawn ( [ this . argv . containerExecutable , "volume" , "create" , `${ buildVolumeName } ` ] , argv . cwd ) ) ;
690- volumePromises . push ( Utils . spawn ( [ this . argv . containerExecutable , "volume" , "create" , `${ tmpVolumeName } ` ] , argv . cwd ) ) ;
691- this . _containerVolumeNames . push ( buildVolumeName ) ;
692- this . _containerVolumeNames . push ( tmpVolumeName ) ;
693- await Promise . all ( volumePromises ) ;
688+ this . _containerVolumeNames . push ( buildVolumeName , tmpVolumeName ) ;
689+ await Promise . all ( [
690+ Utils . spawn ( [ this . argv . containerExecutable , "volume" , "create" , `${ buildVolumeName } ` ] , argv . cwd ) ,
691+ Utils . spawn ( [ this . argv . containerExecutable , "volume" , "create" , `${ tmpVolumeName } ` ] , argv . cwd ) ,
692+ ] ) ;
694693
695694 const time = process . hrtime ( ) ;
696695 this . refreshLongRunningSilentTimeout ( writeStreams ) ;
@@ -762,7 +761,7 @@ If you know what you're doing and would like to suppress this warning, use one o
762761 }
763762
764763 await this . execPreScripts ( expanded ) ;
765- if ( this . _prescriptsExitCode == null ) throw Error ( "this._prescriptsExitCode must be defined!" ) ;
764+ if ( this . _prescriptsExitCode == null ) throw new Error ( "this._prescriptsExitCode must be defined!" ) ;
766765
767766 await this . execAfterScripts ( expanded ) ;
768767
@@ -844,7 +843,7 @@ If you know what you're doing and would like to suppress this warning, use one o
844843 scripts . forEach ( ( script ) => {
845844 const split = script . split ( / \r ? \n / ) ;
846845 const multilineText = split . length > 1 ? " # collapsed multi-line command" : "" ;
847- const text = split [ 0 ] ?. replace ( / \\ / g , "\\\\" ) . replace ( / " / g , "\\\"" ) . replace ( / [ $ ] / g , "\\$" ) ;
846+ const text = split [ 0 ] ?. replaceAll ( "\\" , String . raw `\\` ) . replaceAll ( "\"" , String . raw `\"` ) . replaceAll ( "$" , String . raw `\$` ) ;
848847 if ( this . interactive ) {
849848 cmd += chalk `echo "{green $ ${ text } ${ multilineText } }"\n` ;
850849 } else {
@@ -1035,7 +1034,8 @@ If you know what you're doing and would like to suppress this warning, use one o
10351034
10361035 for ( const [ key , val ] of Object . entries ( expanded ) ) {
10371036 // Replacing `'` with `'\''` to correctly handle single quotes(if `val` contains `'`) in shell commands
1038- dockerCmd += ` -e '${ key } =${ val . toString ( ) . replaceAll ( "'" , String . raw `'\''` ) } ' \\\n` ;
1037+ const escaped = val . toString ( ) . replaceAll ( "'" , String . raw `'\''` ) ;
1038+ dockerCmd += ` -e '${ key } =${ escaped } ' \\\n` ;
10391039 }
10401040
10411041 if ( this . imageEntrypoint ) {
@@ -1594,7 +1594,8 @@ If you know what you're doing and would like to suppress this warning, use one o
15941594
15951595 for ( const [ key , val ] of Object . entries ( expanded ) ) {
15961596 // Replacing `'` with `'\''` to correctly handle single quotes(if `val` contains `'`) in shell commands
1597- dockerCmd += ` -e '${ key } =${ val . toString ( ) . replaceAll ( "'" , String . raw `'\''` ) } ' \\\n` ;
1597+ const escaped = val . toString ( ) . replaceAll ( "'" , String . raw `'\''` ) ;
1598+ dockerCmd += ` -e '${ key } =${ escaped } ' \\\n` ;
15981599 }
15991600
16001601 const serviceEntrypoint = service . entrypoint ;
@@ -1621,7 +1622,10 @@ If you know what you're doing and would like to suppress this warning, use one o
16211622 dockerCmd += `${ Utils . safeBashString ( e ) } ` ;
16221623 } ) ;
16231624 }
1624- ( service . command ?? [ ] ) . forEach ( ( e ) => dockerCmd += `"${ e . replace ( / \$ / g, "\\$" ) } " ` ) ;
1625+ for ( const e of service . command ?? [ ] ) {
1626+ const escaped = e . replaceAll ( "$" , String . raw `\$` ) ;
1627+ dockerCmd += `"${ escaped } " ` ;
1628+ }
16251629
16261630 const time = process . hrtime ( ) ;
16271631
@@ -1656,14 +1660,15 @@ If you know what you're doing and would like to suppress this warning, use one o
16561660 const time = process . hrtime ( ) ;
16571661 try {
16581662 // Iterate over each port defined in the image, and try to connect to the alias
1659- await Promise . any ( Object . keys ( imageInspect [ 0 ] . Config . ExposedPorts ) . map ( ( port ) => {
1660- if ( ! port . endsWith ( "/tcp" ) ) return ;
1661- const portNum = parseInt ( port . replace ( "/tcp" , "" ) ) ;
1662- const containerName = `gcl-wait-for-it-${ this . jobId } -${ serviceIndex } -${ portNum } ` ;
1663- const spawnCmd = [ this . argv . containerExecutable , "run" , "--rm" , `--name=${ containerName } ` , "--network" , `${ this . _serviceNetworkId } ` , `${ waitImageName } ` , `${ serviceAlias } :${ portNum } ` , "-t" , `${ waitForServicesTimeout } ` ] ;
1664- this . _containersToClean . push ( containerName ) ;
1665- return Utils . spawn ( spawnCmd ) ;
1666- } ) ) ;
1663+ await Promise . any ( Object . keys ( imageInspect [ 0 ] . Config . ExposedPorts )
1664+ . filter ( ( port ) => port . endsWith ( "/tcp" ) )
1665+ . map ( ( port ) => {
1666+ const portNum = Number . parseInt ( port . replace ( "/tcp" , "" ) ) ;
1667+ const containerName = `gcl-wait-for-it-${ this . jobId } -${ serviceIndex } -${ portNum } ` ;
1668+ const spawnCmd = [ this . argv . containerExecutable , "run" , "--rm" , `--name=${ containerName } ` , "--network" , `${ this . _serviceNetworkId } ` , `${ waitImageName } ` , `${ serviceAlias } :${ portNum } ` , "-t" , `${ waitForServicesTimeout } ` ] ;
1669+ this . _containersToClean . push ( containerName ) ;
1670+ return Utils . spawn ( spawnCmd ) ;
1671+ } ) ) ;
16671672 const endTime = process . hrtime ( time ) ;
16681673 writeStreams . stdout ( chalk `${ this . formattedJobName } {greenBright service image: ${ serviceName } healthcheck passed in {green ${ prettyHrtime ( endTime ) } }}\n` ) ;
16691674 } catch ( e : any ) {
0 commit comments