@@ -2,18 +2,20 @@ const fs = require('fs');
22const readline = require ( 'readline' ) ;
33
44const readInterface = readline . createInterface ( {
5- input : fs . createReadStream ( 'file' ) ,
5+ input : fs . createReadStream ( process . argv [ 2 ] ) ,
66 output : process . stdout ,
77 terminal : false
88} ) ;
99
1010const stripQuotes = ( str ) => str . startsWith ( '"' ) || str . startsWith ( "'" ) ? str . slice ( 1 , - 1 ) : str ;
1111
1212const replaceEnvVars = ( str ) => {
13- return str . replace ( / ( : ? ) \$ \{ ( [ ^ } ] + ) \} / g, ( match , precedingColon , varName ) => {
14- const envValue = process . env [ varName ] ;
15- return envValue ? `${ precedingColon } ${ envValue } ` : ( precedingColon ? '' : envValue ) ;
16- } ) ;
13+ const value = str
14+ . replaceAll ( / \$ \{ ( [ a - z A - Z 0 - 9 _ ] + ) : \+ : \$ [ a - z A - Z 0 - 9 _ ] + \} / g, ( _ , key ) => ( v => v ? `:${ v } ` : '' ) ( process . env [ key ] ) )
15+ . replaceAll ( / \$ \{ ( [ a - z A - Z 0 - 9 _ ] + ) \} / g, ( _ , key ) => process . env [ key ] ?? '' )
16+ . replaceAll ( / \$ ( [ a - z A - Z 0 - 9 _ ] + ) / g, ( _ , key ) => process . env [ key ] ?? '' )
17+ console . error ( "FOO" , str , value )
18+ return value
1719} ;
1820
1921readInterface . on ( 'line' , ( line ) => {
@@ -22,10 +24,12 @@ readInterface.on('line', (line) => {
2224 const [ _ , key , value_ ] = match ;
2325 const value = stripQuotes ( value_ ) ;
2426 if ( key === 'PATH' ) {
25- value . split ( ':' ) . forEach ( ( path ) => {
26- if ( ! path . startsWith ( "$" ) ) {
27- fs . appendFileSync ( process . env [ 'GITHUB_PATH' ] , `${ path } \n` ) ;
28- }
27+ value
28+ . replaceAll ( '${PATH:+:$PATH}' , '' )
29+ . replaceAll ( '$PATH' , '' )
30+ . replaceAll ( '${PATH}' , '' )
31+ . split ( ':' ) . forEach ( path => {
32+ fs . appendFileSync ( process . env [ 'GITHUB_PATH' ] , `${ path } \n` ) ;
2933 } ) ;
3034 } else {
3135 let v = replaceEnvVars ( value ) ;
0 commit comments