2021-07-01 16:27:24 +02:00
/******/ ( ( ) => { // webpackBootstrap
/******/ var _ _webpack _modules _ _ = ( {
2020-10-08 00:52:52 +02:00
2021-07-01 16:27:24 +02:00
/***/ 295 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _nccwpck _require _ _ ) {
"use strict" ;
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . prototype . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
_ _setModuleDefault ( result , mod ) ;
return result ;
} ;
var _ _awaiter = ( this && this . _ _awaiter ) || function ( thisArg , _arguments , P , generator ) {
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
} ;
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
exports . parseVersion = exports . getVersion = exports . isAvailable = void 0 ;
const exec = _ _importStar ( _ _nccwpck _require _ _ ( 514 ) ) ;
function isAvailable ( ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
return yield exec
. getExecOutput ( 'docker' , [ 'buildx' ] , {
ignoreReturnCode : true ,
silent : true
} )
. then ( res => {
if ( res . stderr . length > 0 && res . exitCode != 0 ) {
return false ;
}
return res . exitCode == 0 ;
} ) ;
} ) ;
}
exports . isAvailable = isAvailable ;
function getVersion ( ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
return yield exec
. getExecOutput ( 'docker' , [ 'buildx' , 'version' ] , {
ignoreReturnCode : true ,
silent : true
} )
. then ( res => {
if ( res . stderr . length > 0 && res . exitCode != 0 ) {
throw new Error ( res . stderr ) ;
}
return parseVersion ( res . stdout ) ;
} ) ;
} ) ;
}
exports . getVersion = getVersion ;
function parseVersion ( stdout ) {
const matches = /\sv?([0-9a-f]{7}|[0-9.]+)/ . exec ( stdout ) ;
if ( ! matches ) {
throw new Error ( ` Cannot parse buildx version ` ) ;
}
return matches [ 1 ] ;
}
exports . parseVersion = parseVersion ;
//# sourceMappingURL=buildx.js.map
/***/ } ) ,
/***/ 842 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _nccwpck _require _ _ ) {
"use strict" ;
2020-10-08 00:52:52 +02:00
2021-07-01 16:27:24 +02:00
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . prototype . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
_ _setModuleDefault ( result , mod ) ;
return result ;
} ;
var _ _awaiter = ( this && this . _ _awaiter ) || function ( thisArg , _arguments , P , generator ) {
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
} ;
var _ _importDefault = ( this && this . _ _importDefault ) || function ( mod ) {
return ( mod && mod . _ _esModule ) ? mod : { "default" : mod } ;
} ;
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
exports . setOutput = exports . asyncForEach = exports . getInputList = exports . getArgs = exports . getInputs = void 0 ;
const sync _1 = _ _importDefault ( _ _nccwpck _require _ _ ( 750 ) ) ;
const core = _ _importStar ( _ _nccwpck _require _ _ ( 186 ) ) ;
const command _1 = _ _nccwpck _require _ _ ( 241 ) ;
function getInputs ( ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
return {
builder : core . getInput ( 'builder' ) ,
files : getInputList ( 'files' ) ,
targets : getInputList ( 'targets' ) ,
noCache : core . getBooleanInput ( 'no-cache' ) ,
pull : core . getBooleanInput ( 'pull' ) ,
load : core . getBooleanInput ( 'load' ) ,
push : core . getBooleanInput ( 'push' ) ,
set : getInputList ( 'set' , true )
} ;
} ) ;
}
exports . getInputs = getInputs ;
function getArgs ( inputs , buildxVersion ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
let args = [ 'buildx' ] ;
args . push . apply ( args , yield getBakeArgs ( inputs , buildxVersion ) ) ;
args . push . apply ( args , yield getCommonArgs ( inputs ) ) ;
args . push . apply ( args , inputs . targets ) ;
return args ;
} ) ;
}
exports . getArgs = getArgs ;
function getBakeArgs ( inputs , buildxVersion ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
let args = [ 'bake' ] ;
yield exports . asyncForEach ( inputs . files , ( file ) => _ _awaiter ( this , void 0 , void 0 , function * ( ) {
args . push ( '--file' , file ) ;
} ) ) ;
yield exports . asyncForEach ( inputs . set , ( set ) => _ _awaiter ( this , void 0 , void 0 , function * ( ) {
args . push ( '--set' , set ) ;
} ) ) ;
return args ;
} ) ;
}
function getCommonArgs ( inputs ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
let args = [ ] ;
if ( inputs . noCache ) {
args . push ( '--no-cache' ) ;
}
if ( inputs . builder ) {
args . push ( '--builder' , inputs . builder ) ;
}
if ( inputs . pull ) {
args . push ( '--pull' ) ;
}
if ( inputs . load ) {
args . push ( '--load' ) ;
}
if ( inputs . push ) {
args . push ( '--push' ) ;
}
return args ;
} ) ;
}
function getInputList ( name , ignoreComma ) {
let res = [ ] ;
const items = core . getInput ( name ) ;
if ( items == '' ) {
return res ;
}
for ( let output of sync _1 . default ( items , {
columns : false ,
relaxColumnCount : true ,
skipLinesWithEmptyValues : true
} ) ) {
if ( output . length == 1 ) {
res . push ( output [ 0 ] ) ;
continue ;
}
else if ( ! ignoreComma ) {
res . push ( ... output ) ;
continue ;
}
res . push ( output . join ( ',' ) ) ;
}
return res . filter ( item => item ) . map ( pat => pat . trim ( ) ) ;
}
exports . getInputList = getInputList ;
const asyncForEach = ( array , callback ) => _ _awaiter ( void 0 , void 0 , void 0 , function * ( ) {
for ( let index = 0 ; index < array . length ; index ++ ) {
yield callback ( array [ index ] , index , array ) ;
}
} ) ;
exports . asyncForEach = asyncForEach ;
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
function setOutput ( name , value ) {
command _1 . issueCommand ( 'set-output' , { name } , value ) ;
}
exports . setOutput = setOutput ;
//# sourceMappingURL=context.js.map
2020-10-08 00:52:52 +02:00
/***/ } ) ,
/***/ 109 :
2021-07-01 16:27:24 +02:00
/***/ ( function ( _ _unused _webpack _module , exports , _ _nccwpck _require _ _ ) {
2020-10-08 00:52:52 +02:00
"use strict" ;
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
2021-07-01 16:27:24 +02:00
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . prototype . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
2020-10-08 00:52:52 +02:00
_ _setModuleDefault ( result , mod ) ;
return result ;
} ;
var _ _awaiter = ( this && this . _ _awaiter ) || function ( thisArg , _arguments , P , generator ) {
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
} ;
2021-07-01 16:27:24 +02:00
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
const buildx = _ _importStar ( _ _nccwpck _require _ _ ( 295 ) ) ;
const context = _ _importStar ( _ _nccwpck _require _ _ ( 842 ) ) ;
const core = _ _importStar ( _ _nccwpck _require _ _ ( 186 ) ) ;
const exec = _ _importStar ( _ _nccwpck _require _ _ ( 514 ) ) ;
2020-10-08 00:52:52 +02:00
function run ( ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
try {
2021-04-27 15:47:00 +02:00
core . startGroup ( ` Docker info ` ) ;
yield exec . exec ( 'docker' , [ 'version' ] ) ;
yield exec . exec ( 'docker' , [ 'info' ] ) ;
core . endGroup ( ) ;
2020-10-08 00:52:52 +02:00
if ( ! ( yield buildx . isAvailable ( ) ) ) {
2021-04-27 15:47:00 +02:00
core . setFailed ( ` Docker buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx. ` ) ;
2020-10-08 00:52:52 +02:00
return ;
}
2021-05-14 02:10:53 +02:00
const bxVersion = yield buildx . getVersion ( ) ;
const inputs = yield context . getInputs ( ) ;
const args = yield context . getArgs ( inputs , bxVersion ) ;
2021-04-27 15:47:00 +02:00
core . startGroup ( ` Bake definition ` ) ;
2020-12-23 20:15:23 +01:00
yield exec . exec ( 'docker' , [ ... args , '--print' ] ) ;
core . endGroup ( ) ;
2021-06-08 20:40:23 +02:00
yield exec
. getExecOutput ( 'docker' , args , {
ignoreReturnCode : true
} )
. then ( res => {
if ( res . stderr . length > 0 && res . exitCode != 0 ) {
throw new Error ( ` buildx bake failed with: ${ res . stderr . match ( /(.*)\s*$/ ) [ 0 ] . trim ( ) } ` ) ;
2021-05-14 02:10:53 +02:00
}
} ) ;
2020-10-08 00:52:52 +02:00
}
catch ( error ) {
core . setFailed ( error . message ) ;
}
} ) ;
}
run ( ) ;
//# sourceMappingURL=main.js.map
/***/ } ) ,
2021-07-01 16:27:24 +02:00
/***/ 241 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _nccwpck _require _ _ ) {
2020-12-19 03:21:31 +01:00
"use strict" ;
2021-07-01 15:48:09 +02:00
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
_ _setModuleDefault ( result , mod ) ;
return result ;
} ;
2021-07-01 16:27:24 +02:00
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
exports . issue = exports . issueCommand = void 0 ;
const os = _ _importStar ( _ _nccwpck _require _ _ ( 87 ) ) ;
const utils _1 = _ _nccwpck _require _ _ ( 278 ) ;
/ * *
* Commands
*
* Command Format :
* : : name key = value , key = value : : message
*
* Examples :
* : : warning : : This is the message
* : : set - env name = MY _VAR : : some value
2021-07-01 15:48:09 +02:00
* /
2021-07-01 16:27:24 +02:00
function issueCommand ( command , properties , message ) {
const cmd = new Command ( command , properties , message ) ;
process . stdout . write ( cmd . toString ( ) + os . EOL ) ;
}
exports . issueCommand = issueCommand ;
function issue ( name , message = '' ) {
issueCommand ( name , { } , message ) ;
}
exports . issue = issue ;
const CMD _STRING = '::' ;
class Command {
constructor ( command , properties , message ) {
if ( ! command ) {
command = 'missing.command' ;
2021-07-01 15:48:09 +02:00
}
2021-07-01 16:27:24 +02:00
this . command = command ;
this . properties = properties ;
this . message = message ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
toString ( ) {
let cmdStr = CMD _STRING + this . command ;
if ( this . properties && Object . keys ( this . properties ) . length > 0 ) {
cmdStr += ' ' ;
let first = true ;
for ( const key in this . properties ) {
if ( this . properties . hasOwnProperty ( key ) ) {
const val = this . properties [ key ] ;
if ( val ) {
if ( first ) {
first = false ;
}
else {
cmdStr += ',' ;
}
cmdStr += ` ${ key } = ${ escapeProperty ( val ) } ` ;
}
2020-10-08 00:52:52 +02:00
}
}
}
2021-07-01 16:27:24 +02:00
cmdStr += ` ${ CMD _STRING } ${ escapeData ( this . message ) } ` ;
return cmdStr ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
}
function escapeData ( s ) {
return utils _1 . toCommandValue ( s )
. replace ( /%/g , '%25' )
. replace ( /\r/g , '%0D' )
. replace ( /\n/g , '%0A' ) ;
}
function escapeProperty ( s ) {
return utils _1 . toCommandValue ( s )
. replace ( /%/g , '%25' )
. replace ( /\r/g , '%0D' )
. replace ( /\n/g , '%0A' )
. replace ( /:/g , '%3A' )
. replace ( /,/g , '%2C' ) ;
}
//# sourceMappingURL=command.js.map
/***/ } ) ,
/***/ 186 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _nccwpck _require _ _ ) {
"use strict" ;
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
_ _setModuleDefault ( result , mod ) ;
return result ;
} ;
var _ _awaiter = ( this && this . _ _awaiter ) || function ( thisArg , _arguments , P , generator ) {
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
} ;
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
exports . getState = exports . saveState = exports . group = exports . endGroup = exports . startGroup = exports . info = exports . warning = exports . error = exports . debug = exports . isDebug = exports . setFailed = exports . setCommandEcho = exports . setOutput = exports . getBooleanInput = exports . getMultilineInput = exports . getInput = exports . addPath = exports . setSecret = exports . exportVariable = exports . ExitCode = void 0 ;
const command _1 = _ _nccwpck _require _ _ ( 241 ) ;
const file _command _1 = _ _nccwpck _require _ _ ( 717 ) ;
const utils _1 = _ _nccwpck _require _ _ ( 278 ) ;
const os = _ _importStar ( _ _nccwpck _require _ _ ( 87 ) ) ;
const path = _ _importStar ( _ _nccwpck _require _ _ ( 622 ) ) ;
/ * *
* The code to exit an action
* /
var ExitCode ;
( function ( ExitCode ) {
/ * *
* A code indicating that the action was successful
* /
ExitCode [ ExitCode [ "Success" ] = 0 ] = "Success" ;
/ * *
* A code indicating that the action was a failure
* /
ExitCode [ ExitCode [ "Failure" ] = 1 ] = "Failure" ;
} ) ( ExitCode = exports . ExitCode || ( exports . ExitCode = { } ) ) ;
//-----------------------------------------------------------------------
// Variables
//-----------------------------------------------------------------------
/ * *
* Sets env variable for this action and future actions in the job
* @ param name the name of the variable to set
* @ param val the value of the variable . Non - string values will be converted to a string via JSON . stringify
* /
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function exportVariable ( name , val ) {
const convertedVal = utils _1 . toCommandValue ( val ) ;
process . env [ name ] = convertedVal ;
const filePath = process . env [ 'GITHUB_ENV' ] || '' ;
if ( filePath ) {
const delimiter = '_GitHubActionsFileCommandDelimeter_' ;
const commandValue = ` ${ name } << ${ delimiter } ${ os . EOL } ${ convertedVal } ${ os . EOL } ${ delimiter } ` ;
file _command _1 . issueCommand ( 'ENV' , commandValue ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
else {
command _1 . issueCommand ( 'set-env' , { name } , convertedVal ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
}
exports . exportVariable = exportVariable ;
/ * *
* Registers a secret which will get masked from logs
* @ param secret value of the secret
* /
function setSecret ( secret ) {
command _1 . issueCommand ( 'add-mask' , { } , secret ) ;
}
exports . setSecret = setSecret ;
/ * *
* Prepends inputPath to the PATH ( for this action and future actions )
* @ param inputPath
* /
function addPath ( inputPath ) {
const filePath = process . env [ 'GITHUB_PATH' ] || '' ;
if ( filePath ) {
file _command _1 . issueCommand ( 'PATH' , inputPath ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
else {
command _1 . issueCommand ( 'add-path' , { } , inputPath ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
process . env [ 'PATH' ] = ` ${ inputPath } ${ path . delimiter } ${ process . env [ 'PATH' ] } ` ;
}
exports . addPath = addPath ;
/ * *
* Gets the value of an input .
* Unless trimWhitespace is set to false in InputOptions , the value is also trimmed .
* Returns an empty string if the value is not defined .
*
* @ param name name of the input to get
* @ param options optional . See InputOptions .
* @ returns string
* /
function getInput ( name , options ) {
const val = process . env [ ` INPUT_ ${ name . replace ( / /g , '_' ) . toUpperCase ( ) } ` ] || '' ;
if ( options && options . required && ! val ) {
throw new Error ( ` Input required and not supplied: ${ name } ` ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
if ( options && options . trimWhitespace === false ) {
return val ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
return val . trim ( ) ;
}
exports . getInput = getInput ;
/ * *
* Gets the values of an multiline input . Each value is also trimmed .
*
* @ param name name of the input to get
* @ param options optional . See InputOptions .
* @ returns string [ ]
*
* /
function getMultilineInput ( name , options ) {
const inputs = getInput ( name , options )
. split ( '\n' )
. filter ( x => x !== '' ) ;
return inputs ;
}
exports . getMultilineInput = getMultilineInput ;
/ * *
* Gets the input value of the boolean type in the YAML 1.2 "core schema" specification .
* Support boolean input list : ` true | True | TRUE | false | False | FALSE ` .
* The return value is also in boolean type .
* ref : https : //yaml.org/spec/1.2/spec.html#id2804923
*
* @ param name name of the input to get
* @ param options optional . See InputOptions .
* @ returns boolean
* /
function getBooleanInput ( name , options ) {
const trueValue = [ 'true' , 'True' , 'TRUE' ] ;
const falseValue = [ 'false' , 'False' , 'FALSE' ] ;
const val = getInput ( name , options ) ;
if ( trueValue . includes ( val ) )
return true ;
if ( falseValue . includes ( val ) )
return false ;
throw new TypeError ( ` Input does not meet YAML 1.2 "Core Schema" specification: ${ name } \n ` +
` Support boolean input list: \` true | True | TRUE | false | False | FALSE \` ` ) ;
}
exports . getBooleanInput = getBooleanInput ;
/ * *
* Sets the value of an output .
*
* @ param name name of the output to set
* @ param value value to store . Non - string values will be converted to a string via JSON . stringify
* /
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setOutput ( name , value ) {
process . stdout . write ( os . EOL ) ;
command _1 . issueCommand ( 'set-output' , { name } , value ) ;
}
exports . setOutput = setOutput ;
/ * *
* Enables or disables the echoing of commands into stdout for the rest of the step .
* Echoing is disabled by default if ACTIONS _STEP _DEBUG is not set .
*
* /
function setCommandEcho ( enabled ) {
command _1 . issue ( 'echo' , enabled ? 'on' : 'off' ) ;
}
exports . setCommandEcho = setCommandEcho ;
//-----------------------------------------------------------------------
// Results
//-----------------------------------------------------------------------
/ * *
* Sets the action status to failed .
* When the action exits it will be with an exit code of 1
* @ param message add error issue message
* /
function setFailed ( message ) {
process . exitCode = ExitCode . Failure ;
error ( message ) ;
}
exports . setFailed = setFailed ;
//-----------------------------------------------------------------------
// Logging Commands
//-----------------------------------------------------------------------
/ * *
* Gets whether Actions Step Debug is on or not
* /
function isDebug ( ) {
return process . env [ 'RUNNER_DEBUG' ] === '1' ;
}
exports . isDebug = isDebug ;
/ * *
* Writes debug message to user log
* @ param message debug message
* /
function debug ( message ) {
command _1 . issueCommand ( 'debug' , { } , message ) ;
}
exports . debug = debug ;
/ * *
* Adds an error issue
* @ param message error issue message . Errors will be converted to string via toString ( )
* /
function error ( message ) {
command _1 . issue ( 'error' , message instanceof Error ? message . toString ( ) : message ) ;
}
exports . error = error ;
/ * *
* Adds an warning issue
* @ param message warning issue message . Errors will be converted to string via toString ( )
* /
function warning ( message ) {
command _1 . issue ( 'warning' , message instanceof Error ? message . toString ( ) : message ) ;
}
exports . warning = warning ;
/ * *
* Writes info to log with console . log .
* @ param message info message
* /
function info ( message ) {
process . stdout . write ( message + os . EOL ) ;
}
exports . info = info ;
/ * *
* Begin an output group .
*
* Output until the next ` groupEnd ` will be foldable in this group
*
* @ param name The name of the output group
* /
function startGroup ( name ) {
command _1 . issue ( 'group' , name ) ;
}
exports . startGroup = startGroup ;
/ * *
* End an output group .
* /
function endGroup ( ) {
command _1 . issue ( 'endgroup' ) ;
}
exports . endGroup = endGroup ;
/ * *
* Wrap an asynchronous function call in a group .
*
* Returns the same type as the function itself .
*
* @ param name The name of the group
* @ param fn The function to wrap in the group
* /
function group ( name , fn ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
startGroup ( name ) ;
let result ;
try {
result = yield fn ( ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
finally {
endGroup ( ) ;
2020-10-08 00:52:52 +02:00
}
return result ;
2021-07-01 16:27:24 +02:00
} ) ;
}
exports . group = group ;
//-----------------------------------------------------------------------
// Wrapper action state
//-----------------------------------------------------------------------
/ * *
* Saves state for current action , the state can only be retrieved by this action ' s post job execution .
*
* @ param name name of the state to store
* @ param value value to store . Non - string values will be converted to a string via JSON . stringify
* /
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function saveState ( name , value ) {
command _1 . issueCommand ( 'save-state' , { name } , value ) ;
}
exports . saveState = saveState ;
/ * *
* Gets the value of an state set by this action ' s main execution .
*
* @ param name name of the state to get
* @ returns string
* /
function getState ( name ) {
return process . env [ ` STATE_ ${ name } ` ] || '' ;
}
exports . getState = getState ;
//# sourceMappingURL=core.js.map
/***/ } ) ,
/***/ 717 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _nccwpck _require _ _ ) {
"use strict" ;
// For internal use, subject to change.
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
_ _setModuleDefault ( result , mod ) ;
return result ;
} ;
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
exports . issueCommand = void 0 ;
// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
const fs = _ _importStar ( _ _nccwpck _require _ _ ( 747 ) ) ;
const os = _ _importStar ( _ _nccwpck _require _ _ ( 87 ) ) ;
const utils _1 = _ _nccwpck _require _ _ ( 278 ) ;
function issueCommand ( command , message ) {
const filePath = process . env [ ` GITHUB_ ${ command } ` ] ;
if ( ! filePath ) {
throw new Error ( ` Unable to find environment variable for file command ${ command } ` ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
if ( ! fs . existsSync ( filePath ) ) {
throw new Error ( ` Missing file at path: ${ filePath } ` ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
fs . appendFileSync ( filePath , ` ${ utils _1 . toCommandValue ( message ) } ${ os . EOL } ` , {
encoding : 'utf8'
} ) ;
}
exports . issueCommand = issueCommand ;
//# sourceMappingURL=file-command.js.map
/***/ } ) ,
/***/ 278 :
/***/ ( ( _ _unused _webpack _module , exports ) => {
"use strict" ;
// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
exports . toCommandValue = void 0 ;
/ * *
* Sanitizes an input into a string so it can be passed into issueCommand safely
* @ param input input to sanitize into a string
* /
function toCommandValue ( input ) {
if ( input === null || input === undefined ) {
return '' ;
}
else if ( typeof input === 'string' || input instanceof String ) {
return input ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
return JSON . stringify ( input ) ;
}
exports . toCommandValue = toCommandValue ;
//# sourceMappingURL=utils.js.map
/***/ } ) ,
/***/ 514 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _nccwpck _require _ _ ) {
"use strict" ;
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
_ _setModuleDefault ( result , mod ) ;
return result ;
} ;
var _ _awaiter = ( this && this . _ _awaiter ) || function ( thisArg , _arguments , P , generator ) {
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
} ;
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
exports . getExecOutput = exports . exec = void 0 ;
const string _decoder _1 = _ _nccwpck _require _ _ ( 304 ) ;
const tr = _ _importStar ( _ _nccwpck _require _ _ ( 159 ) ) ;
/ * *
* Exec a command .
* Output will be streamed to the live console .
* Returns promise with return code
*
* @ param commandLine command to execute ( can include additional args ) . Must be correctly escaped .
* @ param args optional arguments for tool . Escaping is handled by the lib .
* @ param options optional exec options . See ExecOptions
* @ returns Promise < number > exit code
* /
function exec ( commandLine , args , options ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
const commandArgs = tr . argStringToArray ( commandLine ) ;
if ( commandArgs . length === 0 ) {
throw new Error ( ` Parameter 'commandLine' cannot be null or empty. ` ) ;
}
// Path to tool to execute should be first arg
const toolPath = commandArgs [ 0 ] ;
args = commandArgs . slice ( 1 ) . concat ( args || [ ] ) ;
const runner = new tr . ToolRunner ( toolPath , args , options ) ;
return runner . exec ( ) ;
} ) ;
}
exports . exec = exec ;
/ * *
* Exec a command and get the output .
* Output will be streamed to the live console .
* Returns promise with the exit code and collected stdout and stderr
*
* @ param commandLine command to execute ( can include additional args ) . Must be correctly escaped .
* @ param args optional arguments for tool . Escaping is handled by the lib .
* @ param options optional exec options . See ExecOptions
* @ returns Promise < ExecOutput > exit code , stdout , and stderr
* /
function getExecOutput ( commandLine , args , options ) {
var _a , _b ;
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
let stdout = '' ;
let stderr = '' ;
//Using string decoder covers the case where a mult-byte character is split
const stdoutDecoder = new string _decoder _1 . StringDecoder ( 'utf8' ) ;
const stderrDecoder = new string _decoder _1 . StringDecoder ( 'utf8' ) ;
const originalStdoutListener = ( _a = options === null || options === void 0 ? void 0 : options . listeners ) === null || _a === void 0 ? void 0 : _a . stdout ;
const originalStdErrListener = ( _b = options === null || options === void 0 ? void 0 : options . listeners ) === null || _b === void 0 ? void 0 : _b . stderr ;
const stdErrListener = ( data ) => {
stderr += stderrDecoder . write ( data ) ;
if ( originalStdErrListener ) {
originalStdErrListener ( data ) ;
}
} ;
const stdOutListener = ( data ) => {
stdout += stdoutDecoder . write ( data ) ;
if ( originalStdoutListener ) {
originalStdoutListener ( data ) ;
}
} ;
const listeners = Object . assign ( Object . assign ( { } , options === null || options === void 0 ? void 0 : options . listeners ) , { stdout : stdOutListener , stderr : stdErrListener } ) ;
const exitCode = yield exec ( commandLine , args , Object . assign ( Object . assign ( { } , options ) , { listeners } ) ) ;
//flush any remaining characters
stdout += stdoutDecoder . end ( ) ;
stderr += stderrDecoder . end ( ) ;
return {
exitCode ,
stdout ,
stderr
} ;
} ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
exports . getExecOutput = getExecOutput ;
//# sourceMappingURL=exec.js.map
/***/ } ) ,
/***/ 159 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _nccwpck _require _ _ ) {
"use strict" ;
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
_ _setModuleDefault ( result , mod ) ;
return result ;
} ;
var _ _awaiter = ( this && this . _ _awaiter ) || function ( thisArg , _arguments , P , generator ) {
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
} ;
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
exports . argStringToArray = exports . ToolRunner = void 0 ;
const os = _ _importStar ( _ _nccwpck _require _ _ ( 87 ) ) ;
const events = _ _importStar ( _ _nccwpck _require _ _ ( 614 ) ) ;
const child = _ _importStar ( _ _nccwpck _require _ _ ( 129 ) ) ;
const path = _ _importStar ( _ _nccwpck _require _ _ ( 622 ) ) ;
const io = _ _importStar ( _ _nccwpck _require _ _ ( 351 ) ) ;
const ioUtil = _ _importStar ( _ _nccwpck _require _ _ ( 962 ) ) ;
const timers _1 = _ _nccwpck _require _ _ ( 213 ) ;
/* eslint-disable @typescript-eslint/unbound-method */
const IS _WINDOWS = process . platform === 'win32' ;
/ *
* Class for running command line tools . Handles quoting and arg parsing in a platform agnostic way .
2020-10-08 00:52:52 +02:00
* /
2021-07-01 16:27:24 +02:00
class ToolRunner extends events . EventEmitter {
constructor ( toolPath , args , options ) {
super ( ) ;
if ( ! toolPath ) {
throw new Error ( "Parameter 'toolPath' cannot be null or empty." ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
this . toolPath = toolPath ;
this . args = args || [ ] ;
this . options = options || { } ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
_debug ( message ) {
if ( this . options . listeners && this . options . listeners . debug ) {
this . options . listeners . debug ( message ) ;
}
}
_getCommandString ( options , noPrefix ) {
const toolPath = this . _getSpawnFileName ( ) ;
const args = this . _getSpawnArgs ( options ) ;
let cmd = noPrefix ? '' : '[command]' ; // omit prefix when piped to a second tool
if ( IS _WINDOWS ) {
// Windows + cmd file
if ( this . _isCmdFile ( ) ) {
cmd += toolPath ;
for ( const a of args ) {
cmd += ` ${ a } ` ;
}
}
// Windows + verbatim
else if ( options . windowsVerbatimArguments ) {
cmd += ` " ${ toolPath } " ` ;
for ( const a of args ) {
cmd += ` ${ a } ` ;
}
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
// Windows (regular)
2020-10-08 00:52:52 +02:00
else {
2021-07-01 16:27:24 +02:00
cmd += this . _windowsQuoteCmdArg ( toolPath ) ;
for ( const a of args ) {
cmd += ` ${ this . _windowsQuoteCmdArg ( a ) } ` ;
}
2020-10-08 00:52:52 +02:00
}
}
2021-07-01 16:27:24 +02:00
else {
// OSX/Linux - this can likely be improved with some form of quoting.
// creating processes on Unix is fundamentally different than Windows.
// on Unix, execvp() takes an arg array.
cmd += toolPath ;
for ( const a of args ) {
cmd += ` ${ a } ` ;
2020-10-08 00:52:52 +02:00
}
}
2021-07-01 16:27:24 +02:00
return cmd ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
_processLineBuffer ( data , strBuffer , onLine ) {
try {
let s = strBuffer + data . toString ( ) ;
let n = s . indexOf ( os . EOL ) ;
while ( n > - 1 ) {
const line = s . substring ( 0 , n ) ;
onLine ( line ) ;
// the rest of the string ...
s = s . substring ( n + os . EOL . length ) ;
n = s . indexOf ( os . EOL ) ;
}
return s ;
}
catch ( err ) {
// streaming lines to console is best effort. Don't fail a build.
this . _debug ( ` error processing line. Failed with error ${ err } ` ) ;
return '' ;
}
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
_getSpawnFileName ( ) {
if ( IS _WINDOWS ) {
if ( this . _isCmdFile ( ) ) {
return process . env [ 'COMSPEC' ] || 'cmd.exe' ;
}
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
return this . toolPath ;
}
_getSpawnArgs ( options ) {
if ( IS _WINDOWS ) {
if ( this . _isCmdFile ( ) ) {
let argline = ` /D /S /C " ${ this . _windowsQuoteCmdArg ( this . toolPath ) } ` ;
for ( const a of this . args ) {
argline += ' ' ;
argline += options . windowsVerbatimArguments
? a
: this . _windowsQuoteCmdArg ( a ) ;
}
argline += '"' ;
return [ argline ] ;
}
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
return this . args ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
_endsWith ( str , end ) {
return str . endsWith ( end ) ;
}
_isCmdFile ( ) {
const upperToolPath = this . toolPath . toUpperCase ( ) ;
return ( this . _endsWith ( upperToolPath , '.CMD' ) ||
this . _endsWith ( upperToolPath , '.BAT' ) ) ;
}
_windowsQuoteCmdArg ( arg ) {
// for .exe, apply the normal quoting rules that libuv applies
if ( ! this . _isCmdFile ( ) ) {
return this . _uvQuoteCmdArg ( arg ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
// otherwise apply quoting rules specific to the cmd.exe command line parser.
// the libuv rules are generic and are not designed specifically for cmd.exe
// command line parser.
//
// for a detailed description of the cmd.exe command line parser, refer to
// http://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts/7970912#7970912
// need quotes for empty arg
if ( ! arg ) {
return '""' ;
}
// determine whether the arg needs to be quoted
const cmdSpecialChars = [
' ' ,
'\t' ,
'&' ,
'(' ,
')' ,
'[' ,
']' ,
'{' ,
'}' ,
'^' ,
'=' ,
';' ,
'!' ,
"'" ,
'+' ,
',' ,
'`' ,
'~' ,
'|' ,
'<' ,
'>' ,
'"'
] ;
let needsQuotes = false ;
for ( const char of arg ) {
if ( cmdSpecialChars . some ( x => x === char ) ) {
needsQuotes = true ;
break ;
}
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
// short-circuit if quotes not needed
if ( ! needsQuotes ) {
return arg ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
// the following quoting rules are very similar to the rules that by libuv applies.
//
// 1) wrap the string in quotes
//
// 2) double-up quotes - i.e. " => ""
//
// this is different from the libuv quoting rules. libuv replaces " with \", which unfortunately
// doesn't work well with a cmd.exe command line.
//
// note, replacing " with "" also works well if the arg is passed to a downstream .NET console app.
// for example, the command line:
// foo.exe "myarg:""my val"""
// is parsed by a .NET console app into an arg array:
// [ "myarg:\"my val\"" ]
// which is the same end result when applying libuv quoting rules. although the actual
// command line from libuv quoting rules would look like:
// foo.exe "myarg:\"my val\""
//
// 3) double-up slashes that precede a quote,
// e.g. hello \world => "hello \world"
// hello\"world => "hello\\""world"
// hello\\"world => "hello\\\\""world"
// hello world\ => "hello world\\"
//
// technically this is not required for a cmd.exe command line, or the batch argument parser.
// the reasons for including this as a .cmd quoting rule are:
//
// a) this is optimized for the scenario where the argument is passed from the .cmd file to an
// external program. many programs (e.g. .NET console apps) rely on the slash-doubling rule.
//
// b) it's what we've been doing previously (by deferring to node default behavior) and we
// haven't heard any complaints about that aspect.
//
// note, a weakness of the quoting rules chosen here, is that % is not escaped. in fact, % cannot be
// escaped when used on the command line directly - even though within a .cmd file % can be escaped
// by using %%.
//
// the saving grace is, on the command line, %var% is left as-is if var is not defined. this contrasts
// the line parsing rules within a .cmd file, where if var is not defined it is replaced with nothing.
//
// one option that was explored was replacing % with ^% - i.e. %var% => ^%var^%. this hack would
// often work, since it is unlikely that var^ would exist, and the ^ character is removed when the
// variable is used. the problem, however, is that ^ is not removed when %* is used to pass the args
// to an external program.
//
// an unexplored potential solution for the % escaping problem, is to create a wrapper .cmd file.
// % can be escaped within a .cmd file.
let reverse = '"' ;
let quoteHit = true ;
for ( let i = arg . length ; i > 0 ; i -- ) {
// walk the string in reverse
reverse += arg [ i - 1 ] ;
if ( quoteHit && arg [ i - 1 ] === '\\' ) {
reverse += '\\' ; // double the slash
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
else if ( arg [ i - 1 ] === '"' ) {
quoteHit = true ;
reverse += '"' ; // double the quote
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
else {
quoteHit = false ;
2020-10-08 00:52:52 +02:00
}
}
2021-07-01 16:27:24 +02:00
reverse += '"' ;
return reverse
. split ( '' )
. reverse ( )
. join ( '' ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
_uvQuoteCmdArg ( arg ) {
// Tool runner wraps child_process.spawn() and needs to apply the same quoting as
// Node in certain cases where the undocumented spawn option windowsVerbatimArguments
// is used.
//
// Since this function is a port of quote_cmd_arg from Node 4.x (technically, lib UV,
// see https://github.com/nodejs/node/blob/v4.x/deps/uv/src/win/process.c for details),
// pasting copyright notice from Node within this function:
//
// Copyright Joyent, Inc. and other Node contributors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
if ( ! arg ) {
// Need double quotation for empty argument
return '""' ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
if ( ! arg . includes ( ' ' ) && ! arg . includes ( '\t' ) && ! arg . includes ( '"' ) ) {
// No quotation needed
return arg ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
if ( ! arg . includes ( '"' ) && ! arg . includes ( '\\' ) ) {
// No embedded double quotes or backslashes, so I can just wrap
// quote marks around the whole thing.
return ` " ${ arg } " ` ;
}
// Expected input/output:
// input : hello"world
// output: "hello\"world"
// input : hello""world
// output: "hello\"\"world"
// input : hello\world
// output: hello\world
// input : hello\\world
// output: hello\\world
// input : hello\"world
// output: "hello\\\"world"
// input : hello\\"world
// output: "hello\\\\\"world"
// input : hello world\
// output: "hello world\\" - note the comment in libuv actually reads "hello world\"
// but it appears the comment is wrong, it should be "hello world\\"
let reverse = '"' ;
let quoteHit = true ;
for ( let i = arg . length ; i > 0 ; i -- ) {
// walk the string in reverse
reverse += arg [ i - 1 ] ;
if ( quoteHit && arg [ i - 1 ] === '\\' ) {
reverse += '\\' ;
}
else if ( arg [ i - 1 ] === '"' ) {
quoteHit = true ;
reverse += '\\' ;
}
else {
quoteHit = false ;
}
}
reverse += '"' ;
return reverse
. split ( '' )
. reverse ( )
. join ( '' ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
_cloneExecOptions ( options ) {
options = options || { } ;
const result = {
cwd : options . cwd || process . cwd ( ) ,
env : options . env || process . env ,
silent : options . silent || false ,
windowsVerbatimArguments : options . windowsVerbatimArguments || false ,
failOnStdErr : options . failOnStdErr || false ,
ignoreReturnCode : options . ignoreReturnCode || false ,
delay : options . delay || 10000
} ;
result . outStream = options . outStream || process . stdout ;
result . errStream = options . errStream || process . stderr ;
return result ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
_getSpawnOptions ( options , toolPath ) {
options = options || { } ;
const result = { } ;
result . cwd = options . cwd ;
result . env = options . env ;
result [ 'windowsVerbatimArguments' ] =
options . windowsVerbatimArguments || this . _isCmdFile ( ) ;
if ( options . windowsVerbatimArguments ) {
result . argv0 = ` " ${ toolPath } " ` ;
}
return result ;
}
/ * *
* Exec a tool .
* Output will be streamed to the live console .
* Returns promise with return code
*
* @ param tool path to tool to exec
* @ param options optional exec options . See ExecOptions
* @ returns number
* /
exec ( ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
// root the tool path if it is unrooted and contains relative pathing
if ( ! ioUtil . isRooted ( this . toolPath ) &&
( this . toolPath . includes ( '/' ) ||
( IS _WINDOWS && this . toolPath . includes ( '\\' ) ) ) ) {
// prefer options.cwd if it is specified, however options.cwd may also need to be rooted
this . toolPath = path . resolve ( process . cwd ( ) , this . options . cwd || process . cwd ( ) , this . toolPath ) ;
}
// if the tool is only a file name, then resolve it from the PATH
// otherwise verify it exists (add extension on Windows if necessary)
this . toolPath = yield io . which ( this . toolPath , true ) ;
return new Promise ( ( resolve , reject ) => _ _awaiter ( this , void 0 , void 0 , function * ( ) {
this . _debug ( ` exec tool: ${ this . toolPath } ` ) ;
this . _debug ( 'arguments:' ) ;
for ( const arg of this . args ) {
this . _debug ( ` ${ arg } ` ) ;
}
const optionsNonNull = this . _cloneExecOptions ( this . options ) ;
if ( ! optionsNonNull . silent && optionsNonNull . outStream ) {
optionsNonNull . outStream . write ( this . _getCommandString ( optionsNonNull ) + os . EOL ) ;
}
const state = new ExecState ( optionsNonNull , this . toolPath ) ;
state . on ( 'debug' , ( message ) => {
this . _debug ( message ) ;
} ) ;
if ( this . options . cwd && ! ( yield ioUtil . exists ( this . options . cwd ) ) ) {
return reject ( new Error ( ` The cwd: ${ this . options . cwd } does not exist! ` ) ) ;
}
const fileName = this . _getSpawnFileName ( ) ;
const cp = child . spawn ( fileName , this . _getSpawnArgs ( optionsNonNull ) , this . _getSpawnOptions ( this . options , fileName ) ) ;
let stdbuffer = '' ;
if ( cp . stdout ) {
cp . stdout . on ( 'data' , ( data ) => {
if ( this . options . listeners && this . options . listeners . stdout ) {
this . options . listeners . stdout ( data ) ;
}
if ( ! optionsNonNull . silent && optionsNonNull . outStream ) {
optionsNonNull . outStream . write ( data ) ;
}
stdbuffer = this . _processLineBuffer ( data , stdbuffer , ( line ) => {
if ( this . options . listeners && this . options . listeners . stdline ) {
this . options . listeners . stdline ( line ) ;
}
} ) ;
} ) ;
}
let errbuffer = '' ;
if ( cp . stderr ) {
cp . stderr . on ( 'data' , ( data ) => {
state . processStderr = true ;
if ( this . options . listeners && this . options . listeners . stderr ) {
this . options . listeners . stderr ( data ) ;
}
if ( ! optionsNonNull . silent &&
optionsNonNull . errStream &&
optionsNonNull . outStream ) {
const s = optionsNonNull . failOnStdErr
? optionsNonNull . errStream
: optionsNonNull . outStream ;
s . write ( data ) ;
}
errbuffer = this . _processLineBuffer ( data , errbuffer , ( line ) => {
if ( this . options . listeners && this . options . listeners . errline ) {
this . options . listeners . errline ( line ) ;
}
} ) ;
} ) ;
}
cp . on ( 'error' , ( err ) => {
state . processError = err . message ;
state . processExited = true ;
state . processClosed = true ;
state . CheckComplete ( ) ;
} ) ;
cp . on ( 'exit' , ( code ) => {
state . processExitCode = code ;
state . processExited = true ;
this . _debug ( ` Exit code ${ code } received from tool ' ${ this . toolPath } ' ` ) ;
state . CheckComplete ( ) ;
} ) ;
cp . on ( 'close' , ( code ) => {
state . processExitCode = code ;
state . processExited = true ;
state . processClosed = true ;
this . _debug ( ` STDIO streams have closed for tool ' ${ this . toolPath } ' ` ) ;
state . CheckComplete ( ) ;
} ) ;
state . on ( 'done' , ( error , exitCode ) => {
if ( stdbuffer . length > 0 ) {
this . emit ( 'stdline' , stdbuffer ) ;
}
if ( errbuffer . length > 0 ) {
this . emit ( 'errline' , errbuffer ) ;
}
cp . removeAllListeners ( ) ;
if ( error ) {
reject ( error ) ;
}
else {
resolve ( exitCode ) ;
}
} ) ;
if ( this . options . input ) {
if ( ! cp . stdin ) {
throw new Error ( 'child process missing stdin' ) ;
}
cp . stdin . end ( this . options . input ) ;
}
} ) ) ;
} ) ;
2021-05-24 23:51:39 +02:00
}
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
exports . ToolRunner = ToolRunner ;
2020-10-08 00:52:52 +02:00
/ * *
2021-07-01 16:27:24 +02:00
* Convert an arg string to an array of args . Handles escaping
2020-10-08 00:52:52 +02:00
*
2021-07-01 16:27:24 +02:00
* @ param argString string of arguments
* @ returns string [ ] array of arguments
2020-10-08 00:52:52 +02:00
* /
2021-07-01 16:27:24 +02:00
function argStringToArray ( argString ) {
const args = [ ] ;
let inQuotes = false ;
let escaped = false ;
let arg = '' ;
function append ( c ) {
// we only escape double quotes.
if ( escaped && c !== '"' ) {
arg += '\\' ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
arg += c ;
escaped = false ;
}
for ( let i = 0 ; i < argString . length ; i ++ ) {
const c = argString . charAt ( i ) ;
if ( c === '"' ) {
if ( ! escaped ) {
inQuotes = ! inQuotes ;
}
else {
append ( c ) ;
}
continue ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
if ( c === '\\' && escaped ) {
append ( c ) ;
continue ;
}
if ( c === '\\' && inQuotes ) {
escaped = true ;
continue ;
}
if ( c === ' ' && ! inQuotes ) {
if ( arg . length > 0 ) {
args . push ( arg ) ;
arg = '' ;
}
continue ;
}
append ( c ) ;
}
if ( arg . length > 0 ) {
args . push ( arg . trim ( ) ) ;
}
return args ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
exports . argStringToArray = argStringToArray ;
class ExecState extends events . EventEmitter {
constructor ( options , toolPath ) {
super ( ) ;
this . processClosed = false ; // tracks whether the process has exited and stdio is closed
this . processError = '' ;
this . processExitCode = 0 ;
this . processExited = false ; // tracks whether the process has exited
this . processStderr = false ; // tracks whether stderr was written to
this . delay = 10000 ; // 10 seconds
this . done = false ;
this . timeout = null ;
if ( ! toolPath ) {
throw new Error ( 'toolPath must not be empty' ) ;
}
this . options = options ;
this . toolPath = toolPath ;
if ( options . delay ) {
this . delay = options . delay ;
2020-10-08 00:52:52 +02:00
}
}
2021-07-01 16:27:24 +02:00
CheckComplete ( ) {
if ( this . done ) {
return ;
}
if ( this . processClosed ) {
this . _setResult ( ) ;
}
else if ( this . processExited ) {
this . timeout = timers _1 . setTimeout ( ExecState . HandleTimeout , this . delay , this ) ;
2020-10-08 00:52:52 +02:00
}
}
2021-07-01 16:27:24 +02:00
_debug ( message ) {
this . emit ( 'debug' , message ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
_setResult ( ) {
// determine whether there is an error
let error ;
if ( this . processExited ) {
if ( this . processError ) {
error = new Error ( ` There was an error when attempting to execute the process ' ${ this . toolPath } '. This may indicate the process failed to start. Error: ${ this . processError } ` ) ;
}
else if ( this . processExitCode !== 0 && ! this . options . ignoreReturnCode ) {
error = new Error ( ` The process ' ${ this . toolPath } ' failed with exit code ${ this . processExitCode } ` ) ;
}
else if ( this . processStderr && this . options . failOnStdErr ) {
error = new Error ( ` The process ' ${ this . toolPath } ' failed because one or more lines were written to the STDERR stream ` ) ;
}
}
// clear the timeout
if ( this . timeout ) {
clearTimeout ( this . timeout ) ;
this . timeout = null ;
}
this . done = true ;
this . emit ( 'done' , error , this . processExitCode ) ;
}
static HandleTimeout ( state ) {
if ( state . done ) {
return ;
}
if ( ! state . processClosed && state . processExited ) {
const message = ` The STDIO streams did not close within ${ state . delay /
1000 } seconds of the exit event from process '${state.toolPath}' . This may indicate a child process inherited the STDIO streams and has not yet exited . ` ;
state . _debug ( message ) ;
}
state . _setResult ( ) ;
2020-10-08 00:52:52 +02:00
}
}
2021-07-01 16:27:24 +02:00
//# sourceMappingURL=toolrunner.js.map
2020-10-08 00:52:52 +02:00
/***/ } ) ,
2021-07-01 16:27:24 +02:00
/***/ 962 :
/***/ ( function ( _ _unused _webpack _module , exports , _ _nccwpck _require _ _ ) {
2020-10-08 00:52:52 +02:00
"use strict" ;
var _ _awaiter = ( this && this . _ _awaiter ) || function ( thisArg , _arguments , P , generator ) {
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
} ;
2021-07-01 16:27:24 +02:00
var _a ;
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
const assert _1 = _ _nccwpck _require _ _ ( 357 ) ;
const fs = _ _nccwpck _require _ _ ( 747 ) ;
const path = _ _nccwpck _require _ _ ( 622 ) ;
_a = fs . promises , exports . chmod = _a . chmod , exports . copyFile = _a . copyFile , exports . lstat = _a . lstat , exports . mkdir = _a . mkdir , exports . readdir = _a . readdir , exports . readlink = _a . readlink , exports . rename = _a . rename , exports . rmdir = _a . rmdir , exports . stat = _a . stat , exports . symlink = _a . symlink , exports . unlink = _a . unlink ;
exports . IS _WINDOWS = process . platform === 'win32' ;
function exists ( fsPath ) {
2020-10-08 00:52:52 +02:00
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
2021-07-01 16:27:24 +02:00
try {
yield exports . stat ( fsPath ) ;
}
catch ( err ) {
if ( err . code === 'ENOENT' ) {
2020-10-08 00:52:52 +02:00
return false ;
}
2021-07-01 16:27:24 +02:00
throw err ;
}
return true ;
2020-10-08 00:52:52 +02:00
} ) ;
}
2021-07-01 16:27:24 +02:00
exports . exists = exists ;
function isDirectory ( fsPath , useStat = false ) {
2020-10-08 00:52:52 +02:00
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
2021-07-01 16:27:24 +02:00
const stats = useStat ? yield exports . stat ( fsPath ) : yield exports . lstat ( fsPath ) ;
return stats . isDirectory ( ) ;
} ) ;
}
exports . isDirectory = isDirectory ;
/ * *
* On OSX / Linux , true if path starts with '/' . On Windows , true for paths like :
* \ , \ hello , \ \ hello \ share , C : , and C : \ hello ( and corresponding alternate separator cases ) .
* /
function isRooted ( p ) {
p = normalizeSeparators ( p ) ;
if ( ! p ) {
throw new Error ( 'isRooted() parameter "p" cannot be empty' ) ;
}
if ( exports . IS _WINDOWS ) {
return ( p . startsWith ( '\\' ) || /^[A-Z]:/i . test ( p ) // e.g. \ or \hello or \\hello
) ; // e.g. C: or C:\hello
}
return p . startsWith ( '/' ) ;
}
exports . isRooted = isRooted ;
/ * *
* Recursively create a directory at ` fsPath ` .
*
* This implementation is optimistic , meaning it attempts to create the full
* path first , and backs up the path stack from there .
*
* @ param fsPath The path to create
* @ param maxDepth The maximum recursion depth
* @ param depth The current recursion depth
* /
function mkdirP ( fsPath , maxDepth = 1000 , depth = 1 ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
assert _1 . ok ( fsPath , 'a path argument must be provided' ) ;
fsPath = path . resolve ( fsPath ) ;
if ( depth >= maxDepth )
return exports . mkdir ( fsPath ) ;
try {
yield exports . mkdir ( fsPath ) ;
return ;
}
catch ( err ) {
switch ( err . code ) {
case 'ENOENT' : {
yield mkdirP ( path . dirname ( fsPath ) , maxDepth , depth + 1 ) ;
yield exports . mkdir ( fsPath ) ;
return ;
}
default : {
let stats ;
try {
stats = yield exports . stat ( fsPath ) ;
}
catch ( err2 ) {
throw err ;
}
if ( ! stats . isDirectory ( ) )
throw err ;
}
}
}
} ) ;
}
exports . mkdirP = mkdirP ;
/ * *
* Best effort attempt to determine whether a file exists and is executable .
* @ param filePath file path to check
* @ param extensions additional file extensions to try
* @ return if file exists and is executable , returns the file path . otherwise empty string .
* /
function tryGetExecutablePath ( filePath , extensions ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
let stats = undefined ;
try {
// test file exists
stats = yield exports . stat ( filePath ) ;
}
catch ( err ) {
if ( err . code !== 'ENOENT' ) {
// eslint-disable-next-line no-console
console . log ( ` Unexpected error attempting to determine if executable file exists ' ${ filePath } ': ${ err } ` ) ;
}
}
if ( stats && stats . isFile ( ) ) {
if ( exports . IS _WINDOWS ) {
// on Windows, test for valid extension
const upperExt = path . extname ( filePath ) . toUpperCase ( ) ;
if ( extensions . some ( validExt => validExt . toUpperCase ( ) === upperExt ) ) {
return filePath ;
}
}
else {
if ( isUnixExecutable ( stats ) ) {
return filePath ;
}
}
}
// try each extension
const originalFilePath = filePath ;
for ( const extension of extensions ) {
filePath = originalFilePath + extension ;
stats = undefined ;
try {
stats = yield exports . stat ( filePath ) ;
}
catch ( err ) {
if ( err . code !== 'ENOENT' ) {
// eslint-disable-next-line no-console
console . log ( ` Unexpected error attempting to determine if executable file exists ' ${ filePath } ': ${ err } ` ) ;
}
}
if ( stats && stats . isFile ( ) ) {
if ( exports . IS _WINDOWS ) {
// preserve the case of the actual file (since an extension was appended)
try {
const directory = path . dirname ( filePath ) ;
const upperName = path . basename ( filePath ) . toUpperCase ( ) ;
for ( const actualName of yield exports . readdir ( directory ) ) {
if ( upperName === actualName . toUpperCase ( ) ) {
filePath = path . join ( directory , actualName ) ;
break ;
}
}
}
catch ( err ) {
// eslint-disable-next-line no-console
console . log ( ` Unexpected error attempting to determine the actual case of the file ' ${ filePath } ': ${ err } ` ) ;
}
return filePath ;
}
else {
if ( isUnixExecutable ( stats ) ) {
return filePath ;
}
}
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
}
return '' ;
2020-10-08 00:52:52 +02:00
} ) ;
}
2021-07-01 16:27:24 +02:00
exports . tryGetExecutablePath = tryGetExecutablePath ;
function normalizeSeparators ( p ) {
p = p || '' ;
if ( exports . IS _WINDOWS ) {
// convert slashes on Windows
p = p . replace ( /\//g , '\\' ) ;
// remove redundant slashes
return p . replace ( /\\\\+/g , '\\' ) ;
2021-07-01 15:48:09 +02:00
}
2021-07-01 16:27:24 +02:00
// remove redundant slashes
return p . replace ( /\/\/+/g , '/' ) ;
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
// on Mac/Linux, test the execute bit
// R W X R W X R W X
// 256 128 64 32 16 8 4 2 1
function isUnixExecutable ( stats ) {
return ( ( stats . mode & 1 ) > 0 ||
( ( stats . mode & 8 ) > 0 && stats . gid === process . getgid ( ) ) ||
( ( stats . mode & 64 ) > 0 && stats . uid === process . getuid ( ) ) ) ;
}
//# sourceMappingURL=io-util.js.map
2021-06-08 19:24:33 +02:00
2020-10-08 00:52:52 +02:00
/***/ } ) ,
/***/ 351 :
2021-07-01 16:27:24 +02:00
/***/ ( function ( _ _unused _webpack _module , exports , _ _nccwpck _require _ _ ) {
2020-10-08 00:52:52 +02:00
"use strict" ;
var _ _awaiter = ( this && this . _ _awaiter ) || function ( thisArg , _arguments , P , generator ) {
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
} ;
2021-07-01 16:27:24 +02:00
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
const childProcess = _ _nccwpck _require _ _ ( 129 ) ;
const path = _ _nccwpck _require _ _ ( 622 ) ;
const util _1 = _ _nccwpck _require _ _ ( 669 ) ;
const ioUtil = _ _nccwpck _require _ _ ( 962 ) ;
2020-10-08 00:52:52 +02:00
const exec = util _1 . promisify ( childProcess . exec ) ;
/ * *
* Copies a file or folder .
* Based off of shelljs - https : //github.com/shelljs/shelljs/blob/9237f66c52e5daa40458f94f9565e18e8132f5a6/src/cp.js
*
* @ param source source path
* @ param dest destination path
* @ param options optional . See CopyOptions .
* /
function cp ( source , dest , options = { } ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
const { force , recursive } = readCopyOptions ( options ) ;
const destStat = ( yield ioUtil . exists ( dest ) ) ? yield ioUtil . stat ( dest ) : null ;
// Dest is an existing file, but not forcing
if ( destStat && destStat . isFile ( ) && ! force ) {
return ;
}
// If dest is an existing directory, should copy inside.
const newDest = destStat && destStat . isDirectory ( )
? path . join ( dest , path . basename ( source ) )
: dest ;
if ( ! ( yield ioUtil . exists ( source ) ) ) {
throw new Error ( ` no such file or directory: ${ source } ` ) ;
}
const sourceStat = yield ioUtil . stat ( source ) ;
if ( sourceStat . isDirectory ( ) ) {
if ( ! recursive ) {
throw new Error ( ` Failed to copy. ${ source } is a directory, but tried to copy without recursive flag. ` ) ;
}
else {
yield cpDirRecursive ( source , newDest , 0 , force ) ;
}
}
else {
if ( path . relative ( source , newDest ) === '' ) {
// a file cannot be copied to itself
throw new Error ( ` ' ${ newDest } ' and ' ${ source } ' are the same file ` ) ;
}
yield copyFile ( source , newDest , force ) ;
}
} ) ;
}
exports . cp = cp ;
/ * *
* Moves a path .
*
* @ param source source path
* @ param dest destination path
* @ param options optional . See MoveOptions .
* /
function mv ( source , dest , options = { } ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
if ( yield ioUtil . exists ( dest ) ) {
let destExists = true ;
if ( yield ioUtil . isDirectory ( dest ) ) {
// If dest is directory copy src into dest
dest = path . join ( dest , path . basename ( source ) ) ;
destExists = yield ioUtil . exists ( dest ) ;
}
if ( destExists ) {
if ( options . force == null || options . force ) {
yield rmRF ( dest ) ;
}
else {
throw new Error ( 'Destination already exists' ) ;
}
}
}
yield mkdirP ( path . dirname ( dest ) ) ;
yield ioUtil . rename ( source , dest ) ;
} ) ;
}
exports . mv = mv ;
/ * *
* Remove a path recursively with force
*
* @ param inputPath path to remove
* /
function rmRF ( inputPath ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
if ( ioUtil . IS _WINDOWS ) {
// Node doesn't provide a delete operation, only an unlink function. This means that if the file is being used by another
// program (e.g. antivirus), it won't be deleted. To address this, we shell out the work to rd/del.
try {
if ( yield ioUtil . isDirectory ( inputPath , true ) ) {
yield exec ( ` rd /s /q " ${ inputPath } " ` ) ;
}
else {
yield exec ( ` del /f /a " ${ inputPath } " ` ) ;
}
}
catch ( err ) {
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid
if ( err . code !== 'ENOENT' )
throw err ;
}
// Shelling out fails to remove a symlink folder with missing source, this unlink catches that
try {
yield ioUtil . unlink ( inputPath ) ;
}
catch ( err ) {
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid
if ( err . code !== 'ENOENT' )
throw err ;
}
}
else {
let isDir = false ;
try {
isDir = yield ioUtil . isDirectory ( inputPath ) ;
}
catch ( err ) {
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid
if ( err . code !== 'ENOENT' )
throw err ;
return ;
}
if ( isDir ) {
yield exec ( ` rm -rf " ${ inputPath } " ` ) ;
}
else {
yield ioUtil . unlink ( inputPath ) ;
}
}
} ) ;
}
exports . rmRF = rmRF ;
/ * *
* Make a directory . Creates the full path with folders in between
* Will throw if it fails
*
* @ param fsPath path to create
* @ returns Promise < void >
* /
function mkdirP ( fsPath ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
yield ioUtil . mkdirP ( fsPath ) ;
} ) ;
}
exports . mkdirP = mkdirP ;
/ * *
* Returns path of a tool had the tool actually been invoked . Resolves via paths .
* If you check and the tool does not exist , it will throw .
*
* @ param tool name of the tool
* @ param check whether to check if tool exists
* @ returns Promise < string > path to tool
* /
function which ( tool , check ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
if ( ! tool ) {
throw new Error ( "parameter 'tool' is required" ) ;
}
// recursive when check=true
if ( check ) {
const result = yield which ( tool , false ) ;
if ( ! result ) {
if ( ioUtil . IS _WINDOWS ) {
throw new Error ( ` Unable to locate executable file: ${ tool } . Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file. ` ) ;
}
else {
throw new Error ( ` Unable to locate executable file: ${ tool } . Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable. ` ) ;
}
}
}
try {
// build the list of extensions to try
const extensions = [ ] ;
if ( ioUtil . IS _WINDOWS && process . env . PATHEXT ) {
for ( const extension of process . env . PATHEXT . split ( path . delimiter ) ) {
if ( extension ) {
extensions . push ( extension ) ;
}
}
}
// if it's rooted, return it if exists. otherwise return empty.
if ( ioUtil . isRooted ( tool ) ) {
const filePath = yield ioUtil . tryGetExecutablePath ( tool , extensions ) ;
if ( filePath ) {
return filePath ;
}
return '' ;
}
// if any path separators, return empty
if ( tool . includes ( '/' ) || ( ioUtil . IS _WINDOWS && tool . includes ( '\\' ) ) ) {
return '' ;
}
// build the list of directories
//
// Note, technically "where" checks the current directory on Windows. From a toolkit perspective,
// it feels like we should not do this. Checking the current directory seems like more of a use
// case of a shell, and the which() function exposed by the toolkit should strive for consistency
// across platforms.
const directories = [ ] ;
if ( process . env . PATH ) {
for ( const p of process . env . PATH . split ( path . delimiter ) ) {
if ( p ) {
directories . push ( p ) ;
}
}
}
// return the first match
for ( const directory of directories ) {
const filePath = yield ioUtil . tryGetExecutablePath ( directory + path . sep + tool , extensions ) ;
if ( filePath ) {
return filePath ;
}
}
return '' ;
}
catch ( err ) {
throw new Error ( ` which failed with message ${ err . message } ` ) ;
}
} ) ;
}
exports . which = which ;
function readCopyOptions ( options ) {
const force = options . force == null ? true : options . force ;
const recursive = Boolean ( options . recursive ) ;
return { force , recursive } ;
}
function cpDirRecursive ( sourceDir , destDir , currentDepth , force ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
// Ensure there is not a run away recursive copy
if ( currentDepth >= 255 )
return ;
currentDepth ++ ;
yield mkdirP ( destDir ) ;
const files = yield ioUtil . readdir ( sourceDir ) ;
for ( const fileName of files ) {
const srcFile = ` ${ sourceDir } / ${ fileName } ` ;
const destFile = ` ${ destDir } / ${ fileName } ` ;
const srcFileStat = yield ioUtil . lstat ( srcFile ) ;
if ( srcFileStat . isDirectory ( ) ) {
// Recurse
yield cpDirRecursive ( srcFile , destFile , currentDepth , force ) ;
}
else {
yield copyFile ( srcFile , destFile , force ) ;
}
}
// Change the mode for the newly created directory
yield ioUtil . chmod ( destDir , ( yield ioUtil . stat ( sourceDir ) ) . mode ) ;
} ) ;
}
// Buffered file copy
function copyFile ( srcFile , destFile , force ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
if ( ( yield ioUtil . lstat ( srcFile ) ) . isSymbolicLink ( ) ) {
// unlink/re-link it
try {
yield ioUtil . lstat ( destFile ) ;
yield ioUtil . unlink ( destFile ) ;
}
catch ( e ) {
// Try to override file permission
if ( e . code === 'EPERM' ) {
yield ioUtil . chmod ( destFile , '0666' ) ;
yield ioUtil . unlink ( destFile ) ;
}
// other errors = it doesn't exist, no work to do
}
// Copy over symlink
const symlinkFull = yield ioUtil . readlink ( srcFile ) ;
yield ioUtil . symlink ( symlinkFull , destFile , ioUtil . IS _WINDOWS ? 'junction' : null ) ;
}
else if ( ! ( yield ioUtil . exists ( destFile ) ) || force ) {
yield ioUtil . copyFile ( srcFile , destFile ) ;
}
} ) ;
}
//# sourceMappingURL=io.js.map
/***/ } ) ,
2021-07-01 16:27:24 +02:00
/***/ 942 :
/***/ ( ( module ) => {
2020-10-08 00:52:52 +02:00
2021-07-01 16:27:24 +02:00
class ResizeableBuffer {
constructor ( size = 100 ) {
this . size = size
this . length = 0
this . buf = Buffer . alloc ( size )
}
prepend ( val ) {
if ( Buffer . isBuffer ( val ) ) {
const length = this . length + val . length
if ( length >= this . size ) {
this . resize ( )
if ( length >= this . size ) {
throw Error ( 'INVALID_BUFFER_STATE' )
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
}
const buf = this . buf
this . buf = Buffer . alloc ( this . size )
val . copy ( this . buf , 0 )
buf . copy ( this . buf , val . length )
this . length += val . length
} else {
const length = this . length ++
if ( length === this . size ) {
this . resize ( )
}
const buf = this . clone ( )
this . buf [ 0 ] = val
buf . copy ( this . buf , 1 , 0 , length )
}
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
append ( val ) {
const length = this . length ++
if ( length === this . size ) {
this . resize ( )
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
this . buf [ length ] = val
}
clone ( ) {
return Buffer . from ( this . buf . slice ( 0 , this . length ) )
}
resize ( ) {
const length = this . length
this . size = this . size * 2
const buf = Buffer . alloc ( this . size )
this . buf . copy ( buf , 0 , 0 , length )
this . buf = buf
}
toString ( encoding ) {
if ( encoding ) {
return this . buf . slice ( 0 , this . length ) . toString ( encoding )
} else {
return Uint8Array . prototype . slice . call ( this . buf . slice ( 0 , this . length ) )
2020-10-08 00:52:52 +02:00
}
}
2021-07-01 16:27:24 +02:00
toJSON ( ) {
return this . toString ( 'utf8' )
}
reset ( ) {
this . length = 0
}
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
module . exports = ResizeableBuffer
2020-10-08 00:52:52 +02:00
2020-12-23 23:44:52 +01:00
/***/ } ) ,
/***/ 830 :
2021-07-01 16:27:24 +02:00
/***/ ( ( module , _ _unused _webpack _exports , _ _nccwpck _require _ _ ) => {
2020-12-23 23:44:52 +01:00
/ *
CSV Parse
Please look at the [ project documentation ] ( https : //csv.js.org/parse/) for
additional information .
* /
2021-07-01 16:27:24 +02:00
const { Transform } = _ _nccwpck _require _ _ ( 413 )
const ResizeableBuffer = _ _nccwpck _require _ _ ( 942 )
2020-12-23 23:44:52 +01:00
2021-01-28 19:31:41 +01:00
// white space characters
// https://en.wikipedia.org/wiki/Whitespace_character
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes#Types
// \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff
2020-12-23 23:44:52 +01:00
const tab = 9
2021-01-28 19:31:41 +01:00
const nl = 10 // \n, 0x0A in hexadecimal, 10 in decimal
2020-12-23 23:44:52 +01:00
const np = 12
2021-01-28 19:31:41 +01:00
const cr = 13 // \r, 0x0D in hexadécimal, 13 in decimal
2020-12-23 23:44:52 +01:00
const space = 32
const boms = {
// Note, the following are equals:
// Buffer.from("\ufeff")
// Buffer.from([239, 187, 191])
// Buffer.from('EFBBBF', 'hex')
'utf8' : Buffer . from ( [ 239 , 187 , 191 ] ) ,
// Note, the following are equals:
// Buffer.from "\ufeff", 'utf16le
// Buffer.from([255, 254])
'utf16le' : Buffer . from ( [ 255 , 254 ] )
}
class Parser extends Transform {
constructor ( opts = { } ) {
super ( { ... { readableObjectMode : true } , ... opts , encoding : null } )
this . _ _originalOptions = opts
this . _ _normalizeOptions ( opts )
}
_ _normalizeOptions ( opts ) {
const options = { }
// Merge with user options
for ( let opt in opts ) {
options [ underscore ( opt ) ] = opts [ opt ]
}
// Normalize option `encoding`
// Note: defined first because other options depends on it
// to convert chars/strings into buffers.
if ( options . encoding === undefined || options . encoding === true ) {
options . encoding = 'utf8'
} else if ( options . encoding === null || options . encoding === false ) {
options . encoding = null
} else if ( typeof options . encoding !== 'string' && options . encoding !== null ) {
throw new CsvError ( 'CSV_INVALID_OPTION_ENCODING' , [
'Invalid option encoding:' ,
'encoding must be a string or null to return a buffer,' ,
` got ${ JSON . stringify ( options . encoding ) } `
] , options )
}
// Normalize option `bom`
if ( options . bom === undefined || options . bom === null || options . bom === false ) {
options . bom = false
} else if ( options . bom !== true ) {
throw new CsvError ( 'CSV_INVALID_OPTION_BOM' , [
'Invalid option bom:' , 'bom must be true,' ,
` got ${ JSON . stringify ( options . bom ) } `
] , options )
}
// Normalize option `cast`
let fnCastField = null
if ( options . cast === undefined || options . cast === null || options . cast === false || options . cast === '' ) {
options . cast = undefined
} else if ( typeof options . cast === 'function' ) {
fnCastField = options . cast
options . cast = true
} else if ( options . cast !== true ) {
throw new CsvError ( 'CSV_INVALID_OPTION_CAST' , [
'Invalid option cast:' , 'cast must be true or a function,' ,
` got ${ JSON . stringify ( options . cast ) } `
] , options )
}
// Normalize option `cast_date`
if ( options . cast _date === undefined || options . cast _date === null || options . cast _date === false || options . cast _date === '' ) {
options . cast _date = false
} else if ( options . cast _date === true ) {
options . cast _date = function ( value ) {
const date = Date . parse ( value )
return ! isNaN ( date ) ? new Date ( date ) : value
}
} else if ( typeof options . cast _date !== 'function' ) {
throw new CsvError ( 'CSV_INVALID_OPTION_CAST_DATE' , [
'Invalid option cast_date:' , 'cast_date must be true or a function,' ,
` got ${ JSON . stringify ( options . cast _date ) } `
] , options )
}
// Normalize option `columns`
let fnFirstLineToHeaders = null
if ( options . columns === true ) {
// Fields in the first line are converted as-is to columns
fnFirstLineToHeaders = undefined
} else if ( typeof options . columns === 'function' ) {
fnFirstLineToHeaders = options . columns
options . columns = true
} else if ( Array . isArray ( options . columns ) ) {
options . columns = normalizeColumnsArray ( options . columns )
} else if ( options . columns === undefined || options . columns === null || options . columns === false ) {
options . columns = false
} else {
throw new CsvError ( 'CSV_INVALID_OPTION_COLUMNS' , [
'Invalid option columns:' ,
2021-06-23 09:43:36 +02:00
'expect an array, a function or true,' ,
2020-12-23 23:44:52 +01:00
` got ${ JSON . stringify ( options . columns ) } `
] , options )
}
// Normalize option `columns_duplicates_to_array`
if ( options . columns _duplicates _to _array === undefined || options . columns _duplicates _to _array === null || options . columns _duplicates _to _array === false ) {
options . columns _duplicates _to _array = false
} else if ( options . columns _duplicates _to _array !== true ) {
throw new CsvError ( 'CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY' , [
'Invalid option columns_duplicates_to_array:' ,
'expect an boolean,' ,
` got ${ JSON . stringify ( options . columns _duplicates _to _array ) } `
] , options )
2021-06-23 09:43:36 +02:00
} else if ( options . columns === false ) {
throw new CsvError ( 'CSV_INVALID_OPTION_COLUMNS_DUPLICATES_TO_ARRAY' , [
'Invalid option columns_duplicates_to_array:' ,
'the `columns` mode must be activated.'
] , options )
2020-12-23 23:44:52 +01:00
}
// Normalize option `comment`
if ( options . comment === undefined || options . comment === null || options . comment === false || options . comment === '' ) {
options . comment = null
} else {
if ( typeof options . comment === 'string' ) {
options . comment = Buffer . from ( options . comment , options . encoding )
}
if ( ! Buffer . isBuffer ( options . comment ) ) {
throw new CsvError ( 'CSV_INVALID_OPTION_COMMENT' , [
'Invalid option comment:' ,
'comment must be a buffer or a string,' ,
` got ${ JSON . stringify ( options . comment ) } `
] , options )
}
}
// Normalize option `delimiter`
const delimiter _json = JSON . stringify ( options . delimiter )
if ( ! Array . isArray ( options . delimiter ) ) options . delimiter = [ options . delimiter ]
if ( options . delimiter . length === 0 ) {
throw new CsvError ( 'CSV_INVALID_OPTION_DELIMITER' , [
'Invalid option delimiter:' ,
'delimiter must be a non empty string or buffer or array of string|buffer,' ,
` got ${ delimiter _json } `
] , options )
}
options . delimiter = options . delimiter . map ( function ( delimiter ) {
if ( delimiter === undefined || delimiter === null || delimiter === false ) {
return Buffer . from ( ',' , options . encoding )
}
if ( typeof delimiter === 'string' ) {
delimiter = Buffer . from ( delimiter , options . encoding )
}
if ( ! Buffer . isBuffer ( delimiter ) || delimiter . length === 0 ) {
throw new CsvError ( 'CSV_INVALID_OPTION_DELIMITER' , [
'Invalid option delimiter:' ,
'delimiter must be a non empty string or buffer or array of string|buffer,' ,
` got ${ delimiter _json } `
] , options )
}
return delimiter
} )
// Normalize option `escape`
if ( options . escape === undefined || options . escape === true ) {
options . escape = Buffer . from ( '"' , options . encoding )
} else if ( typeof options . escape === 'string' ) {
options . escape = Buffer . from ( options . escape , options . encoding )
} else if ( options . escape === null || options . escape === false ) {
options . escape = null
}
if ( options . escape !== null ) {
if ( ! Buffer . isBuffer ( options . escape ) ) {
throw new Error ( ` Invalid Option: escape must be a buffer, a string or a boolean, got ${ JSON . stringify ( options . escape ) } ` )
}
}
// Normalize option `from`
if ( options . from === undefined || options . from === null ) {
options . from = 1
} else {
if ( typeof options . from === 'string' && /\d+/ . test ( options . from ) ) {
options . from = parseInt ( options . from )
}
if ( Number . isInteger ( options . from ) ) {
if ( options . from < 0 ) {
throw new Error ( ` Invalid Option: from must be a positive integer, got ${ JSON . stringify ( opts . from ) } ` )
}
} else {
throw new Error ( ` Invalid Option: from must be an integer, got ${ JSON . stringify ( options . from ) } ` )
}
}
// Normalize option `from_line`
if ( options . from _line === undefined || options . from _line === null ) {
options . from _line = 1
} else {
if ( typeof options . from _line === 'string' && /\d+/ . test ( options . from _line ) ) {
options . from _line = parseInt ( options . from _line )
}
if ( Number . isInteger ( options . from _line ) ) {
if ( options . from _line <= 0 ) {
throw new Error ( ` Invalid Option: from_line must be a positive integer greater than 0, got ${ JSON . stringify ( opts . from _line ) } ` )
}
} else {
throw new Error ( ` Invalid Option: from_line must be an integer, got ${ JSON . stringify ( opts . from _line ) } ` )
}
}
2021-01-28 19:31:41 +01:00
// Normalize options `ignore_last_delimiters`
if ( options . ignore _last _delimiters === undefined || options . ignore _last _delimiters === null ) {
options . ignore _last _delimiters = false
} else if ( typeof options . ignore _last _delimiters === 'number' ) {
options . ignore _last _delimiters = Math . floor ( options . ignore _last _delimiters )
if ( options . ignore _last _delimiters === 0 ) {
options . ignore _last _delimiters = false
}
} else if ( typeof options . ignore _last _delimiters !== 'boolean' ) {
throw new CsvError ( 'CSV_INVALID_OPTION_IGNORE_LAST_DELIMITERS' , [
'Invalid option `ignore_last_delimiters`:' ,
'the value must be a boolean value or an integer,' ,
` got ${ JSON . stringify ( options . ignore _last _delimiters ) } `
] , options )
}
if ( options . ignore _last _delimiters === true && options . columns === false ) {
throw new CsvError ( 'CSV_IGNORE_LAST_DELIMITERS_REQUIRES_COLUMNS' , [
'The option `ignore_last_delimiters`' ,
'requires the activation of the `columns` option'
] , options )
}
2020-12-23 23:44:52 +01:00
// Normalize option `info`
if ( options . info === undefined || options . info === null || options . info === false ) {
options . info = false
} else if ( options . info !== true ) {
throw new Error ( ` Invalid Option: info must be true, got ${ JSON . stringify ( options . info ) } ` )
}
// Normalize option `max_record_size`
if ( options . max _record _size === undefined || options . max _record _size === null || options . max _record _size === false ) {
options . max _record _size = 0
} else if ( Number . isInteger ( options . max _record _size ) && options . max _record _size >= 0 ) {
// Great, nothing to do
} else if ( typeof options . max _record _size === 'string' && /\d+/ . test ( options . max _record _size ) ) {
options . max _record _size = parseInt ( options . max _record _size )
} else {
throw new Error ( ` Invalid Option: max_record_size must be a positive integer, got ${ JSON . stringify ( options . max _record _size ) } ` )
}
// Normalize option `objname`
if ( options . objname === undefined || options . objname === null || options . objname === false ) {
options . objname = undefined
} else if ( Buffer . isBuffer ( options . objname ) ) {
if ( options . objname . length === 0 ) {
throw new Error ( ` Invalid Option: objname must be a non empty buffer ` )
}
if ( options . encoding === null ) {
// Don't call `toString`, leave objname as a buffer
} else {
options . objname = options . objname . toString ( options . encoding )
}
} else if ( typeof options . objname === 'string' ) {
if ( options . objname . length === 0 ) {
throw new Error ( ` Invalid Option: objname must be a non empty string ` )
}
// Great, nothing to do
} else {
throw new Error ( ` Invalid Option: objname must be a string or a buffer, got ${ options . objname } ` )
}
// Normalize option `on_record`
if ( options . on _record === undefined || options . on _record === null ) {
options . on _record = undefined
} else if ( typeof options . on _record !== 'function' ) {
throw new CsvError ( 'CSV_INVALID_OPTION_ON_RECORD' , [
'Invalid option `on_record`:' ,
'expect a function,' ,
` got ${ JSON . stringify ( options . on _record ) } `
] , options )
}
// Normalize option `quote`
if ( options . quote === null || options . quote === false || options . quote === '' ) {
options . quote = null
} else {
if ( options . quote === undefined || options . quote === true ) {
options . quote = Buffer . from ( '"' , options . encoding )
} else if ( typeof options . quote === 'string' ) {
options . quote = Buffer . from ( options . quote , options . encoding )
}
if ( ! Buffer . isBuffer ( options . quote ) ) {
throw new Error ( ` Invalid Option: quote must be a buffer or a string, got ${ JSON . stringify ( options . quote ) } ` )
}
}
// Normalize option `raw`
if ( options . raw === undefined || options . raw === null || options . raw === false ) {
options . raw = false
} else if ( options . raw !== true ) {
throw new Error ( ` Invalid Option: raw must be true, got ${ JSON . stringify ( options . raw ) } ` )
}
// Normalize option `record_delimiter`
if ( ! options . record _delimiter ) {
options . record _delimiter = [ ]
} else if ( ! Array . isArray ( options . record _delimiter ) ) {
options . record _delimiter = [ options . record _delimiter ]
}
options . record _delimiter = options . record _delimiter . map ( function ( rd ) {
if ( typeof rd === 'string' ) {
rd = Buffer . from ( rd , options . encoding )
}
return rd
} )
// Normalize option `relax`
if ( typeof options . relax === 'boolean' ) {
// Great, nothing to do
} else if ( options . relax === undefined || options . relax === null ) {
options . relax = false
} else {
throw new Error ( ` Invalid Option: relax must be a boolean, got ${ JSON . stringify ( options . relax ) } ` )
}
// Normalize option `relax_column_count`
if ( typeof options . relax _column _count === 'boolean' ) {
// Great, nothing to do
} else if ( options . relax _column _count === undefined || options . relax _column _count === null ) {
options . relax _column _count = false
} else {
throw new Error ( ` Invalid Option: relax_column_count must be a boolean, got ${ JSON . stringify ( options . relax _column _count ) } ` )
}
if ( typeof options . relax _column _count _less === 'boolean' ) {
// Great, nothing to do
} else if ( options . relax _column _count _less === undefined || options . relax _column _count _less === null ) {
options . relax _column _count _less = false
} else {
throw new Error ( ` Invalid Option: relax_column_count_less must be a boolean, got ${ JSON . stringify ( options . relax _column _count _less ) } ` )
}
if ( typeof options . relax _column _count _more === 'boolean' ) {
// Great, nothing to do
} else if ( options . relax _column _count _more === undefined || options . relax _column _count _more === null ) {
options . relax _column _count _more = false
} else {
throw new Error ( ` Invalid Option: relax_column_count_more must be a boolean, got ${ JSON . stringify ( options . relax _column _count _more ) } ` )
}
// Normalize option `skip_empty_lines`
if ( typeof options . skip _empty _lines === 'boolean' ) {
// Great, nothing to do
} else if ( options . skip _empty _lines === undefined || options . skip _empty _lines === null ) {
options . skip _empty _lines = false
} else {
throw new Error ( ` Invalid Option: skip_empty_lines must be a boolean, got ${ JSON . stringify ( options . skip _empty _lines ) } ` )
}
// Normalize option `skip_lines_with_empty_values`
if ( typeof options . skip _lines _with _empty _values === 'boolean' ) {
// Great, nothing to do
} else if ( options . skip _lines _with _empty _values === undefined || options . skip _lines _with _empty _values === null ) {
options . skip _lines _with _empty _values = false
} else {
throw new Error ( ` Invalid Option: skip_lines_with_empty_values must be a boolean, got ${ JSON . stringify ( options . skip _lines _with _empty _values ) } ` )
}
// Normalize option `skip_lines_with_error`
if ( typeof options . skip _lines _with _error === 'boolean' ) {
// Great, nothing to do
} else if ( options . skip _lines _with _error === undefined || options . skip _lines _with _error === null ) {
options . skip _lines _with _error = false
} else {
throw new Error ( ` Invalid Option: skip_lines_with_error must be a boolean, got ${ JSON . stringify ( options . skip _lines _with _error ) } ` )
}
// Normalize option `rtrim`
if ( options . rtrim === undefined || options . rtrim === null || options . rtrim === false ) {
options . rtrim = false
} else if ( options . rtrim !== true ) {
throw new Error ( ` Invalid Option: rtrim must be a boolean, got ${ JSON . stringify ( options . rtrim ) } ` )
}
// Normalize option `ltrim`
if ( options . ltrim === undefined || options . ltrim === null || options . ltrim === false ) {
options . ltrim = false
} else if ( options . ltrim !== true ) {
throw new Error ( ` Invalid Option: ltrim must be a boolean, got ${ JSON . stringify ( options . ltrim ) } ` )
}
// Normalize option `trim`
if ( options . trim === undefined || options . trim === null || options . trim === false ) {
options . trim = false
} else if ( options . trim !== true ) {
throw new Error ( ` Invalid Option: trim must be a boolean, got ${ JSON . stringify ( options . trim ) } ` )
}
// Normalize options `trim`, `ltrim` and `rtrim`
if ( options . trim === true && opts . ltrim !== false ) {
options . ltrim = true
} else if ( options . ltrim !== true ) {
options . ltrim = false
}
if ( options . trim === true && opts . rtrim !== false ) {
options . rtrim = true
} else if ( options . rtrim !== true ) {
options . rtrim = false
}
// Normalize option `to`
if ( options . to === undefined || options . to === null ) {
options . to = - 1
} else {
if ( typeof options . to === 'string' && /\d+/ . test ( options . to ) ) {
options . to = parseInt ( options . to )
}
if ( Number . isInteger ( options . to ) ) {
if ( options . to <= 0 ) {
throw new Error ( ` Invalid Option: to must be a positive integer greater than 0, got ${ JSON . stringify ( opts . to ) } ` )
}
} else {
throw new Error ( ` Invalid Option: to must be an integer, got ${ JSON . stringify ( opts . to ) } ` )
}
}
// Normalize option `to_line`
if ( options . to _line === undefined || options . to _line === null ) {
options . to _line = - 1
} else {
if ( typeof options . to _line === 'string' && /\d+/ . test ( options . to _line ) ) {
options . to _line = parseInt ( options . to _line )
}
if ( Number . isInteger ( options . to _line ) ) {
if ( options . to _line <= 0 ) {
throw new Error ( ` Invalid Option: to_line must be a positive integer greater than 0, got ${ JSON . stringify ( opts . to _line ) } ` )
}
} else {
throw new Error ( ` Invalid Option: to_line must be an integer, got ${ JSON . stringify ( opts . to _line ) } ` )
}
}
this . info = {
comment _lines : 0 ,
empty _lines : 0 ,
invalid _field _length : 0 ,
lines : 1 ,
records : 0
}
this . options = options
this . state = {
bomSkipped : false ,
castField : fnCastField ,
commenting : false ,
// Current error encountered by a record
error : undefined ,
enabled : options . from _line === 1 ,
escaping : false ,
// escapeIsQuote: options.escape === options.quote,
escapeIsQuote : Buffer . isBuffer ( options . escape ) && Buffer . isBuffer ( options . quote ) && Buffer . compare ( options . escape , options . quote ) === 0 ,
2021-06-23 09:43:36 +02:00
// columns can be `false`, `true`, `Array`
expectedRecordLength : Array . isArray ( options . columns ) ? options . columns . length : undefined ,
2020-12-23 23:44:52 +01:00
field : new ResizeableBuffer ( 20 ) ,
firstLineToHeaders : fnFirstLineToHeaders ,
needMoreDataSize : Math . max (
// Skip if the remaining buffer smaller than comment
options . comment !== null ? options . comment . length : 0 ,
// Skip if the remaining buffer can be delimiter
... options . delimiter . map ( ( delimiter ) => delimiter . length ) ,
// Skip if the remaining buffer can be escape sequence
options . quote !== null ? options . quote . length : 0 ,
) ,
previousBuf : undefined ,
quoting : false ,
stop : false ,
rawBuffer : new ResizeableBuffer ( 100 ) ,
record : [ ] ,
recordHasError : false ,
record _length : 0 ,
recordDelimiterMaxLength : options . record _delimiter . length === 0 ? 2 : Math . max ( ... options . record _delimiter . map ( ( v ) => v . length ) ) ,
trimChars : [ Buffer . from ( ' ' , options . encoding ) [ 0 ] , Buffer . from ( '\t' , options . encoding ) [ 0 ] ] ,
wasQuoting : false ,
2021-03-18 20:21:57 +01:00
wasRowDelimiter : false
2020-12-23 23:44:52 +01:00
}
}
// Implementation of `Transform._transform`
_transform ( buf , encoding , callback ) {
if ( this . state . stop === true ) {
return
}
const err = this . _ _parse ( buf , false )
if ( err !== undefined ) {
this . state . stop = true
}
callback ( err )
}
// Implementation of `Transform._flush`
_flush ( callback ) {
if ( this . state . stop === true ) {
return
}
const err = this . _ _parse ( undefined , true )
callback ( err )
}
// Central parser implementation
_ _parse ( nextBuf , end ) {
2021-06-23 09:43:36 +02:00
const { bom , comment , escape , from _line , ltrim , max _record _size , quote , raw , relax , rtrim , skip _empty _lines , to , to _line } = this . options
2020-12-23 23:44:52 +01:00
let { record _delimiter } = this . options
const { bomSkipped , previousBuf , rawBuffer , escapeIsQuote } = this . state
let buf
if ( previousBuf === undefined ) {
if ( nextBuf === undefined ) {
// Handle empty string
this . push ( null )
return
} else {
buf = nextBuf
}
} else if ( previousBuf !== undefined && nextBuf === undefined ) {
buf = previousBuf
} else {
buf = Buffer . concat ( [ previousBuf , nextBuf ] )
}
// Handle UTF BOM
if ( bomSkipped === false ) {
if ( bom === false ) {
this . state . bomSkipped = true
} else if ( buf . length < 3 ) {
// No enough data
if ( end === false ) {
// Wait for more data
this . state . previousBuf = buf
return
}
} else {
for ( let encoding in boms ) {
if ( boms [ encoding ] . compare ( buf , 0 , boms [ encoding ] . length ) === 0 ) {
// Skip BOM
buf = buf . slice ( boms [ encoding ] . length )
// Renormalize original options with the new encoding
this . _ _normalizeOptions ( { ... this . _ _originalOptions , encoding : encoding } )
break
}
}
this . state . bomSkipped = true
}
}
const bufLen = buf . length
let pos
for ( pos = 0 ; pos < bufLen ; pos ++ ) {
// Ensure we get enough space to look ahead
// There should be a way to move this out of the loop
if ( this . _ _needMoreData ( pos , bufLen , end ) ) {
break
}
2021-03-18 20:21:57 +01:00
if ( this . state . wasRowDelimiter === true ) {
2020-12-23 23:44:52 +01:00
this . info . lines ++
2021-03-18 20:21:57 +01:00
this . state . wasRowDelimiter = false
2020-12-23 23:44:52 +01:00
}
if ( to _line !== - 1 && this . info . lines > to _line ) {
this . state . stop = true
this . push ( null )
return
}
// Auto discovery of record_delimiter, unix, mac and windows supported
if ( this . state . quoting === false && record _delimiter . length === 0 ) {
2021-01-28 19:31:41 +01:00
const record _delimiterCount = this . _ _autoDiscoverRecordDelimiter ( buf , pos )
2020-12-23 23:44:52 +01:00
if ( record _delimiterCount ) {
record _delimiter = this . options . record _delimiter
}
}
const chr = buf [ pos ]
if ( raw === true ) {
rawBuffer . append ( chr )
}
2021-03-18 20:21:57 +01:00
if ( ( chr === cr || chr === nl ) && this . state . wasRowDelimiter === false ) {
this . state . wasRowDelimiter = true
2020-12-23 23:44:52 +01:00
}
// Previous char was a valid escape char
// treat the current char as a regular char
if ( this . state . escaping === true ) {
this . state . escaping = false
} else {
// Escape is only active inside quoted fields
// We are quoting, the char is an escape chr and there is a chr to escape
// if(escape !== null && this.state.quoting === true && chr === escape && pos + 1 < bufLen){
if ( escape !== null && this . state . quoting === true && this . _ _isEscape ( buf , pos , chr ) && pos + escape . length < bufLen ) {
if ( escapeIsQuote ) {
if ( this . _ _isQuote ( buf , pos + escape . length ) ) {
this . state . escaping = true
pos += escape . length - 1
continue
}
} else {
this . state . escaping = true
pos += escape . length - 1
continue
}
}
// Not currently escaping and chr is a quote
// TODO: need to compare bytes instead of single char
if ( this . state . commenting === false && this . _ _isQuote ( buf , pos ) ) {
if ( this . state . quoting === true ) {
const nextChr = buf [ pos + quote . length ]
const isNextChrTrimable = rtrim && this . _ _isCharTrimable ( nextChr )
const isNextChrComment = comment !== null && this . _ _compareBytes ( comment , buf , pos + quote . length , nextChr )
const isNextChrDelimiter = this . _ _isDelimiter ( buf , pos + quote . length , nextChr )
2021-01-28 19:31:41 +01:00
const isNextChrRecordDelimiter = record _delimiter . length === 0 ? this . _ _autoDiscoverRecordDelimiter ( buf , pos + quote . length ) : this . _ _isRecordDelimiter ( nextChr , buf , pos + quote . length )
2020-12-23 23:44:52 +01:00
// Escape a quote
// Treat next char as a regular character
if ( escape !== null && this . _ _isEscape ( buf , pos , chr ) && this . _ _isQuote ( buf , pos + escape . length ) ) {
pos += escape . length - 1
2021-01-28 19:31:41 +01:00
} else if ( ! nextChr || isNextChrDelimiter || isNextChrRecordDelimiter || isNextChrComment || isNextChrTrimable ) {
2020-12-23 23:44:52 +01:00
this . state . quoting = false
this . state . wasQuoting = true
pos += quote . length - 1
continue
} else if ( relax === false ) {
const err = this . _ _error (
new CsvError ( 'CSV_INVALID_CLOSING_QUOTE' , [
'Invalid Closing Quote:' ,
` got " ${ String . fromCharCode ( nextChr ) } " ` ,
` at line ${ this . info . lines } ` ,
2021-01-28 19:31:41 +01:00
'instead of delimiter, record delimiter, trimable character' ,
2020-12-23 23:44:52 +01:00
'(if activated) or comment' ,
2021-06-23 09:43:36 +02:00
] , this . options , this . _ _infoField ( ) )
2020-12-23 23:44:52 +01:00
)
if ( err !== undefined ) return err
} else {
this . state . quoting = false
this . state . wasQuoting = true
this . state . field . prepend ( quote )
pos += quote . length - 1
}
} else {
if ( this . state . field . length !== 0 ) {
// In relax mode, treat opening quote preceded by chrs as regular
if ( relax === false ) {
const err = this . _ _error (
new CsvError ( 'INVALID_OPENING_QUOTE' , [
'Invalid Opening Quote:' ,
` a quote is found inside a field at line ${ this . info . lines } ` ,
2021-06-23 09:43:36 +02:00
] , this . options , this . _ _infoField ( ) , {
2020-12-23 23:44:52 +01:00
field : this . state . field ,
} )
)
if ( err !== undefined ) return err
}
} else {
this . state . quoting = true
pos += quote . length - 1
continue
}
}
}
if ( this . state . quoting === false ) {
let recordDelimiterLength = this . _ _isRecordDelimiter ( chr , buf , pos )
if ( recordDelimiterLength !== 0 ) {
// Do not emit comments which take a full line
const skipCommentLine = this . state . commenting && ( this . state . wasQuoting === false && this . state . record . length === 0 && this . state . field . length === 0 )
if ( skipCommentLine ) {
this . info . comment _lines ++
// Skip full comment line
} else {
// Activate records emition if above from_line
2021-03-18 20:21:57 +01:00
if ( this . state . enabled === false && this . info . lines + ( this . state . wasRowDelimiter === true ? 1 : 0 ) >= from _line ) {
2020-12-23 23:44:52 +01:00
this . state . enabled = true
this . _ _resetField ( )
2021-01-28 19:31:41 +01:00
this . _ _resetRecord ( )
2020-12-23 23:44:52 +01:00
pos += recordDelimiterLength - 1
continue
}
2021-03-18 20:21:57 +01:00
// Skip if line is empty and skip_empty_lines activated
if ( skip _empty _lines === true && this . state . wasQuoting === false && this . state . record . length === 0 && this . state . field . length === 0 ) {
this . info . empty _lines ++
pos += recordDelimiterLength - 1
continue
}
const errField = this . _ _onField ( )
if ( errField !== undefined ) return errField
const errRecord = this . _ _onRecord ( )
if ( errRecord !== undefined ) return errRecord
2020-12-23 23:44:52 +01:00
if ( to !== - 1 && this . info . records >= to ) {
this . state . stop = true
this . push ( null )
return
}
}
this . state . commenting = false
pos += recordDelimiterLength - 1
continue
}
if ( this . state . commenting ) {
continue
}
const commentCount = comment === null ? 0 : this . _ _compareBytes ( comment , buf , pos , chr )
if ( commentCount !== 0 ) {
this . state . commenting = true
continue
}
let delimiterLength = this . _ _isDelimiter ( buf , pos , chr )
if ( delimiterLength !== 0 ) {
const errField = this . _ _onField ( )
if ( errField !== undefined ) return errField
pos += delimiterLength - 1
continue
}
}
}
if ( this . state . commenting === false ) {
if ( max _record _size !== 0 && this . state . record _length + this . state . field . length > max _record _size ) {
const err = this . _ _error (
new CsvError ( 'CSV_MAX_RECORD_SIZE' , [
'Max Record Size:' ,
'record exceed the maximum number of tolerated bytes' ,
` of ${ max _record _size } ` ,
` at line ${ this . info . lines } ` ,
2021-06-23 09:43:36 +02:00
] , this . options , this . _ _infoField ( ) )
2020-12-23 23:44:52 +01:00
)
if ( err !== undefined ) return err
}
}
const lappend = ltrim === false || this . state . quoting === true || this . state . field . length !== 0 || ! this . _ _isCharTrimable ( chr )
// rtrim in non quoting is handle in __onField
const rappend = rtrim === false || this . state . wasQuoting === false
if ( lappend === true && rappend === true ) {
this . state . field . append ( chr )
} else if ( rtrim === true && ! this . _ _isCharTrimable ( chr ) ) {
const err = this . _ _error (
new CsvError ( 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE' , [
'Invalid Closing Quote:' ,
'found non trimable byte after quote' ,
` at line ${ this . info . lines } ` ,
2021-06-23 09:43:36 +02:00
] , this . options , this . _ _infoField ( ) )
2020-12-23 23:44:52 +01:00
)
if ( err !== undefined ) return err
}
}
if ( end === true ) {
// Ensure we are not ending in a quoting state
if ( this . state . quoting === true ) {
const err = this . _ _error (
new CsvError ( 'CSV_QUOTE_NOT_CLOSED' , [
'Quote Not Closed:' ,
` the parsing is finished with an opening quote at line ${ this . info . lines } ` ,
2021-06-23 09:43:36 +02:00
] , this . options , this . _ _infoField ( ) )
2020-12-23 23:44:52 +01:00
)
if ( err !== undefined ) return err
} else {
// Skip last line if it has no characters
if ( this . state . wasQuoting === true || this . state . record . length !== 0 || this . state . field . length !== 0 ) {
const errField = this . _ _onField ( )
if ( errField !== undefined ) return errField
2021-01-28 19:31:41 +01:00
const errRecord = this . _ _onRecord ( )
2020-12-23 23:44:52 +01:00
if ( errRecord !== undefined ) return errRecord
2021-03-18 20:21:57 +01:00
} else if ( this . state . wasRowDelimiter === true ) {
2020-12-23 23:44:52 +01:00
this . info . empty _lines ++
} else if ( this . state . commenting === true ) {
this . info . comment _lines ++
}
}
} else {
this . state . previousBuf = buf . slice ( pos )
}
2021-03-18 20:21:57 +01:00
if ( this . state . wasRowDelimiter === true ) {
2020-12-23 23:44:52 +01:00
this . info . lines ++
2021-03-18 20:21:57 +01:00
this . state . wasRowDelimiter = false
2020-12-23 23:44:52 +01:00
}
}
2021-01-28 19:31:41 +01:00
_ _onRecord ( ) {
2020-12-23 23:44:52 +01:00
const { columns , columns _duplicates _to _array , encoding , info , from , relax _column _count , relax _column _count _less , relax _column _count _more , raw , skip _lines _with _empty _values } = this . options
const { enabled , record } = this . state
if ( enabled === false ) {
2021-01-28 19:31:41 +01:00
return this . _ _resetRecord ( )
2020-12-23 23:44:52 +01:00
}
// Convert the first line into column names
const recordLength = record . length
if ( columns === true ) {
2021-06-23 09:43:36 +02:00
if ( skip _lines _with _empty _values === true && isRecordEmpty ( record ) ) {
2021-01-28 19:31:41 +01:00
this . _ _resetRecord ( )
2020-12-23 23:44:52 +01:00
return
}
return this . _ _firstLineToColumns ( record )
}
if ( columns === false && this . info . records === 0 ) {
this . state . expectedRecordLength = recordLength
}
if ( recordLength !== this . state . expectedRecordLength ) {
const err = columns === false ?
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
new CsvError ( 'CSV_INCONSISTENT_RECORD_LENGTH' , [
'Invalid Record Length:' ,
` expect ${ this . state . expectedRecordLength } , ` ,
` got ${ recordLength } on line ${ this . info . lines } ` ,
2021-06-23 09:43:36 +02:00
] , this . options , this . _ _infoField ( ) , {
2020-12-23 23:44:52 +01:00
record : record ,
} )
:
// Todo: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH to
// CSV_RECORD_INCONSISTENT_COLUMNS
new CsvError ( 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH' , [
'Invalid Record Length:' ,
` columns length is ${ columns . length } , ` , // rename columns
` got ${ recordLength } on line ${ this . info . lines } ` ,
2021-06-23 09:43:36 +02:00
] , this . options , this . _ _infoField ( ) , {
2020-12-23 23:44:52 +01:00
record : record ,
} )
2021-04-16 12:03:56 +02:00
if ( relax _column _count === true ||
2020-12-23 23:44:52 +01:00
( relax _column _count _less === true && recordLength < this . state . expectedRecordLength ) ||
( relax _column _count _more === true && recordLength > this . state . expectedRecordLength ) ) {
this . info . invalid _field _length ++
this . state . error = err
// Error is undefined with skip_lines_with_error
} else {
const finalErr = this . _ _error ( err )
if ( finalErr ) return finalErr
}
}
2021-06-23 09:43:36 +02:00
if ( skip _lines _with _empty _values === true && isRecordEmpty ( record ) ) {
this . _ _resetRecord ( )
return
2020-12-23 23:44:52 +01:00
}
if ( this . state . recordHasError === true ) {
2021-01-28 19:31:41 +01:00
this . _ _resetRecord ( )
2020-12-23 23:44:52 +01:00
this . state . recordHasError = false
return
}
this . info . records ++
if ( from === 1 || this . info . records >= from ) {
2021-06-23 09:43:36 +02:00
// With columns, records are object
2020-12-23 23:44:52 +01:00
if ( columns !== false ) {
const obj = { }
// Transform record array to an object
for ( let i = 0 , l = record . length ; i < l ; i ++ ) {
if ( columns [ i ] === undefined || columns [ i ] . disabled ) continue
// Turn duplicate columns into an array
2021-04-16 12:03:56 +02:00
if ( columns _duplicates _to _array === true && obj [ columns [ i ] . name ] !== undefined ) {
2020-12-23 23:44:52 +01:00
if ( Array . isArray ( obj [ columns [ i ] . name ] ) ) {
obj [ columns [ i ] . name ] = obj [ columns [ i ] . name ] . concat ( record [ i ] )
} else {
obj [ columns [ i ] . name ] = [ obj [ columns [ i ] . name ] , record [ i ] ]
}
} else {
obj [ columns [ i ] . name ] = record [ i ]
}
}
const { objname } = this . options
2021-06-23 09:43:36 +02:00
// Without objname (default)
2020-12-23 23:44:52 +01:00
if ( objname === undefined ) {
if ( raw === true || info === true ) {
const err = this . _ _push ( Object . assign (
{ record : obj } ,
( raw === true ? { raw : this . state . rawBuffer . toString ( encoding ) } : { } ) ,
2021-06-23 09:43:36 +02:00
( info === true ? { info : this . _ _infoRecord ( ) } : { } )
2020-12-23 23:44:52 +01:00
) )
if ( err ) {
return err
}
} else {
const err = this . _ _push ( obj )
if ( err ) {
return err
}
}
2021-06-23 09:43:36 +02:00
// With objname (default)
2020-12-23 23:44:52 +01:00
} else {
if ( raw === true || info === true ) {
const err = this . _ _push ( Object . assign (
{ record : [ obj [ objname ] , obj ] } ,
raw === true ? { raw : this . state . rawBuffer . toString ( encoding ) } : { } ,
2021-06-23 09:43:36 +02:00
info === true ? { info : this . _ _infoRecord ( ) } : { }
2020-12-23 23:44:52 +01:00
) )
if ( err ) {
return err
}
} else {
const err = this . _ _push ( [ obj [ objname ] , obj ] )
if ( err ) {
return err
}
}
}
2021-06-23 09:43:36 +02:00
// Without columns, records are array
2020-12-23 23:44:52 +01:00
} else {
if ( raw === true || info === true ) {
const err = this . _ _push ( Object . assign (
{ record : record } ,
raw === true ? { raw : this . state . rawBuffer . toString ( encoding ) } : { } ,
2021-06-23 09:43:36 +02:00
info === true ? { info : this . _ _infoRecord ( ) } : { }
2020-12-23 23:44:52 +01:00
) )
if ( err ) {
return err
}
} else {
const err = this . _ _push ( record )
if ( err ) {
return err
}
}
}
}
2021-01-28 19:31:41 +01:00
this . _ _resetRecord ( )
2020-12-23 23:44:52 +01:00
}
_ _firstLineToColumns ( record ) {
const { firstLineToHeaders } = this . state
try {
const headers = firstLineToHeaders === undefined ? record : firstLineToHeaders . call ( null , record )
if ( ! Array . isArray ( headers ) ) {
return this . _ _error (
new CsvError ( 'CSV_INVALID_COLUMN_MAPPING' , [
'Invalid Column Mapping:' ,
'expect an array from column function,' ,
` got ${ JSON . stringify ( headers ) } `
2021-06-23 09:43:36 +02:00
] , this . options , this . _ _infoField ( ) , {
2020-12-23 23:44:52 +01:00
headers : headers ,
} )
)
}
const normalizedHeaders = normalizeColumnsArray ( headers )
this . state . expectedRecordLength = normalizedHeaders . length
this . options . columns = normalizedHeaders
2021-01-28 19:31:41 +01:00
this . _ _resetRecord ( )
2020-12-23 23:44:52 +01:00
return
} catch ( err ) {
return err
}
}
2021-01-28 19:31:41 +01:00
_ _resetRecord ( ) {
2020-12-23 23:44:52 +01:00
if ( this . options . raw === true ) {
this . state . rawBuffer . reset ( )
}
this . state . error = undefined
this . state . record = [ ]
this . state . record _length = 0
}
_ _onField ( ) {
const { cast , encoding , rtrim , max _record _size } = this . options
const { enabled , wasQuoting } = this . state
// Short circuit for the from_line options
2021-06-23 09:43:36 +02:00
if ( enabled === false ) {
2020-12-23 23:44:52 +01:00
return this . _ _resetField ( )
}
let field = this . state . field . toString ( encoding )
if ( rtrim === true && wasQuoting === false ) {
field = field . trimRight ( )
}
if ( cast === true ) {
const [ err , f ] = this . _ _cast ( field )
if ( err !== undefined ) return err
field = f
}
this . state . record . push ( field )
// Increment record length if record size must not exceed a limit
if ( max _record _size !== 0 && typeof field === 'string' ) {
this . state . record _length += field . length
}
this . _ _resetField ( )
}
_ _resetField ( ) {
this . state . field . reset ( )
this . state . wasQuoting = false
}
_ _push ( record ) {
const { on _record } = this . options
if ( on _record !== undefined ) {
2021-06-23 09:43:36 +02:00
const info = this . _ _infoRecord ( )
2020-12-23 23:44:52 +01:00
try {
2021-06-23 09:43:36 +02:00
record = on _record . call ( null , record , info )
2020-12-23 23:44:52 +01:00
} catch ( err ) {
return err
}
if ( record === undefined || record === null ) { return }
}
this . push ( record )
}
// Return a tuple with the error and the casted value
_ _cast ( field ) {
const { columns , relax _column _count } = this . options
const isColumns = Array . isArray ( columns )
// Dont loose time calling cast
// because the final record is an object
// and this field can't be associated to a key present in columns
if ( isColumns === true && relax _column _count && this . options . columns . length <= this . state . record . length ) {
return [ undefined , undefined ]
}
if ( this . state . castField !== null ) {
try {
2021-06-23 09:43:36 +02:00
const info = this . _ _infoField ( )
return [ undefined , this . state . castField . call ( null , field , info ) ]
2020-12-23 23:44:52 +01:00
} catch ( err ) {
return [ err ]
}
}
if ( this . _ _isFloat ( field ) ) {
return [ undefined , parseFloat ( field ) ]
} else if ( this . options . cast _date !== false ) {
2021-06-23 09:43:36 +02:00
const info = this . _ _infoField ( )
return [ undefined , this . options . cast _date . call ( null , field , info ) ]
2020-12-23 23:44:52 +01:00
}
return [ undefined , field ]
}
2021-01-28 19:31:41 +01:00
// Helper to test if a character is a space or a line delimiter
_ _isCharTrimable ( chr ) {
return chr === space || chr === tab || chr === cr || chr === nl || chr === np
}
2020-12-23 23:44:52 +01:00
// Keep it in case we implement the `cast_int` option
// __isInt(value){
// // return Number.isInteger(parseInt(value))
// // return !isNaN( parseInt( obj ) );
// return /^(\-|\+)?[1-9][0-9]*$/.test(value)
// }
_ _isFloat ( value ) {
return ( value - parseFloat ( value ) + 1 ) >= 0 // Borrowed from jquery
}
_ _compareBytes ( sourceBuf , targetBuf , targetPos , firstByte ) {
if ( sourceBuf [ 0 ] !== firstByte ) return 0
const sourceLength = sourceBuf . length
for ( let i = 1 ; i < sourceLength ; i ++ ) {
if ( sourceBuf [ i ] !== targetBuf [ targetPos + i ] ) return 0
}
return sourceLength
}
_ _needMoreData ( i , bufLen , end ) {
if ( end ) return false
const { quote } = this . options
const { quoting , needMoreDataSize , recordDelimiterMaxLength } = this . state
const numOfCharLeft = bufLen - i - 1
const requiredLength = Math . max (
needMoreDataSize ,
// Skip if the remaining buffer smaller than record delimiter
recordDelimiterMaxLength ,
2021-01-28 19:31:41 +01:00
// Skip if the remaining buffer can be record delimiter following the closing quote
2020-12-23 23:44:52 +01:00
// 1 is for quote.length
quoting ? ( quote . length + recordDelimiterMaxLength ) : 0 ,
)
return numOfCharLeft < requiredLength
}
_ _isDelimiter ( buf , pos , chr ) {
2021-01-28 19:31:41 +01:00
const { delimiter , ignore _last _delimiters } = this . options
if ( ignore _last _delimiters === true && this . state . record . length === this . options . columns . length - 1 ) {
return 0
} else if ( ignore _last _delimiters !== false && typeof ignore _last _delimiters === 'number' && this . state . record . length === ignore _last _delimiters - 1 ) {
return 0
}
2020-12-23 23:44:52 +01:00
loop1 : for ( let i = 0 ; i < delimiter . length ; i ++ ) {
const del = delimiter [ i ]
if ( del [ 0 ] === chr ) {
for ( let j = 1 ; j < del . length ; j ++ ) {
if ( del [ j ] !== buf [ pos + j ] ) continue loop1
}
return del . length
}
}
return 0
}
_ _isRecordDelimiter ( chr , buf , pos ) {
const { record _delimiter } = this . options
const recordDelimiterLength = record _delimiter . length
loop1 : for ( let i = 0 ; i < recordDelimiterLength ; i ++ ) {
const rd = record _delimiter [ i ]
const rdLength = rd . length
if ( rd [ 0 ] !== chr ) {
continue
}
for ( let j = 1 ; j < rdLength ; j ++ ) {
if ( rd [ j ] !== buf [ pos + j ] ) {
continue loop1
}
}
return rd . length
}
return 0
}
_ _isEscape ( buf , pos , chr ) {
const { escape } = this . options
if ( escape === null ) return false
const l = escape . length
if ( escape [ 0 ] === chr ) {
for ( let i = 0 ; i < l ; i ++ ) {
if ( escape [ i ] !== buf [ pos + i ] ) {
return false
}
}
return true
}
return false
}
_ _isQuote ( buf , pos ) {
const { quote } = this . options
if ( quote === null ) return false
const l = quote . length
for ( let i = 0 ; i < l ; i ++ ) {
if ( quote [ i ] !== buf [ pos + i ] ) {
return false
}
}
return true
}
2021-01-28 19:31:41 +01:00
_ _autoDiscoverRecordDelimiter ( buf , pos ) {
2020-12-23 23:44:52 +01:00
const { encoding } = this . options
const chr = buf [ pos ]
if ( chr === cr ) {
if ( buf [ pos + 1 ] === nl ) {
this . options . record _delimiter . push ( Buffer . from ( '\r\n' , encoding ) )
this . state . recordDelimiterMaxLength = 2
return 2
} else {
this . options . record _delimiter . push ( Buffer . from ( '\r' , encoding ) )
this . state . recordDelimiterMaxLength = 1
return 1
}
} else if ( chr === nl ) {
this . options . record _delimiter . push ( Buffer . from ( '\n' , encoding ) )
this . state . recordDelimiterMaxLength = 1
return 1
}
return 0
}
_ _error ( msg ) {
const { skip _lines _with _error } = this . options
const err = typeof msg === 'string' ? new Error ( msg ) : msg
if ( skip _lines _with _error ) {
this . state . recordHasError = true
this . emit ( 'skip' , err )
return undefined
} else {
return err
}
}
2021-06-23 09:43:36 +02:00
_ _infoDataSet ( ) {
return {
... this . info ,
columns : this . options . columns
}
}
_ _infoRecord ( ) {
const { columns } = this . options
return {
... this . _ _infoDataSet ( ) ,
error : this . state . error ,
header : columns === true ,
index : this . state . record . length ,
}
}
_ _infoField ( ) {
2020-12-23 23:44:52 +01:00
const { columns } = this . options
const isColumns = Array . isArray ( columns )
return {
2021-06-23 09:43:36 +02:00
... this . _ _infoRecord ( ) ,
2020-12-23 23:44:52 +01:00
column : isColumns === true ?
( columns . length > this . state . record . length ?
columns [ this . state . record . length ] . name :
null
) :
this . state . record . length ,
quoting : this . state . wasQuoting ,
}
}
}
const parse = function ( ) {
let data , options , callback
for ( let i in arguments ) {
const argument = arguments [ i ]
const type = typeof argument
if ( data === undefined && ( typeof argument === 'string' || Buffer . isBuffer ( argument ) ) ) {
data = argument
} else if ( options === undefined && isObject ( argument ) ) {
options = argument
} else if ( callback === undefined && type === 'function' ) {
callback = argument
} else {
throw new CsvError ( 'CSV_INVALID_ARGUMENT' , [
'Invalid argument:' ,
` got ${ JSON . stringify ( argument ) } at index ${ i } `
] , this . options )
}
}
const parser = new Parser ( options )
if ( callback ) {
const records = options === undefined || options . objname === undefined ? [ ] : { }
parser . on ( 'readable' , function ( ) {
let record
while ( ( record = this . read ( ) ) !== null ) {
if ( options === undefined || options . objname === undefined ) {
records . push ( record )
} else {
records [ record [ 0 ] ] = record [ 1 ]
}
}
} )
parser . on ( 'error' , function ( err ) {
2021-06-23 09:43:36 +02:00
callback ( err , undefined , parser . _ _infoDataSet ( ) )
2020-12-23 23:44:52 +01:00
} )
parser . on ( 'end' , function ( ) {
2021-06-23 09:43:36 +02:00
callback ( undefined , records , parser . _ _infoDataSet ( ) )
2020-12-23 23:44:52 +01:00
} )
}
if ( data !== undefined ) {
// Give a chance for events to be registered later
if ( typeof setImmediate === 'function' ) {
setImmediate ( function ( ) {
parser . write ( data )
parser . end ( )
} )
} else {
parser . write ( data )
parser . end ( )
}
}
return parser
}
class CsvError extends Error {
constructor ( code , message , options , ... contexts ) {
if ( Array . isArray ( message ) ) message = message . join ( ' ' )
super ( message )
if ( Error . captureStackTrace !== undefined ) {
Error . captureStackTrace ( this , CsvError )
}
this . code = code
for ( const context of contexts ) {
for ( const key in context ) {
const value = context [ key ]
this [ key ] = Buffer . isBuffer ( value ) ? value . toString ( options . encoding ) : value == null ? value : JSON . parse ( JSON . stringify ( value ) )
}
}
}
}
parse . Parser = Parser
parse . CsvError = CsvError
module . exports = parse
const underscore = function ( str ) {
return str . replace ( /([A-Z])/g , function ( _ , match ) {
return '_' + match . toLowerCase ( )
} )
}
const isObject = function ( obj ) {
return ( typeof obj === 'object' && obj !== null && ! Array . isArray ( obj ) )
}
const isRecordEmpty = function ( record ) {
return record . every ( ( field ) => field == null || field . toString && field . toString ( ) . trim ( ) === '' )
}
const normalizeColumnsArray = function ( columns ) {
const normalizedColumns = [ ] ;
for ( let i = 0 , l = columns . length ; i < l ; i ++ ) {
const column = columns [ i ]
if ( column === undefined || column === null || column === false ) {
normalizedColumns [ i ] = { disabled : true }
} else if ( typeof column === 'string' ) {
normalizedColumns [ i ] = { name : column }
} else if ( isObject ( column ) ) {
if ( typeof column . name !== 'string' ) {
throw new CsvError ( 'CSV_OPTION_COLUMNS_MISSING_NAME' , [
'Option columns missing name:' ,
` property "name" is required at position ${ i } ` ,
'when column is an object literal'
] )
}
normalizedColumns [ i ] = column
} else {
throw new CsvError ( 'CSV_INVALID_COLUMN_DEFINITION' , [
'Invalid column definition:' ,
'expect a string or a literal object,' ,
` got ${ JSON . stringify ( column ) } at position ${ i } `
] )
}
}
return normalizedColumns ;
}
2020-10-08 00:52:52 +02:00
/***/ } ) ,
2021-07-01 16:27:24 +02:00
/***/ 750 :
/***/ ( ( module , _ _unused _webpack _exports , _ _nccwpck _require _ _ ) => {
2020-10-08 00:52:52 +02:00
2021-07-01 16:27:24 +02:00
const parse = _ _nccwpck _require _ _ ( 830 )
module . exports = function ( data , options = { } ) {
if ( typeof data === 'string' ) {
data = Buffer . from ( data )
}
const records = options && options . objname ? { } : [ ]
const parser = new parse . Parser ( options )
parser . push = function ( record ) {
if ( record === null ) {
return
2020-12-23 23:44:52 +01:00
}
2021-07-01 16:27:24 +02:00
if ( options . objname === undefined )
records . push ( record )
else {
records [ record [ 0 ] ] = record [ 1 ]
2020-10-08 00:52:52 +02:00
}
2021-07-01 16:27:24 +02:00
}
const err1 = parser . _ _parse ( data , false )
if ( err1 !== undefined ) throw err1
const err2 = parser . _ _parse ( undefined , true )
if ( err2 !== undefined ) throw err2
return records
2021-04-30 11:50:06 +02:00
}
2020-12-23 23:44:52 +01:00
2021-07-01 16:27:24 +02:00
/***/ } ) ,
2020-12-23 23:44:52 +01:00
2021-07-01 16:27:24 +02:00
/***/ 357 :
/***/ ( ( module ) => {
2020-12-23 23:44:52 +01:00
2021-07-01 16:27:24 +02:00
"use strict" ;
module . exports = require ( "assert" ) ; ;
2020-12-23 23:44:52 +01:00
2021-07-01 16:27:24 +02:00
/***/ } ) ,
/***/ 129 :
/***/ ( ( module ) => {
2020-12-23 23:44:52 +01:00
2021-07-01 16:27:24 +02:00
"use strict" ;
module . exports = require ( "child_process" ) ; ;
2020-12-23 23:44:52 +01:00
2020-10-08 00:52:52 +02:00
/***/ } ) ,
2021-07-01 16:27:24 +02:00
/***/ 614 :
/***/ ( ( module ) => {
2020-10-08 00:52:52 +02:00
"use strict" ;
2021-07-01 16:27:24 +02:00
module . exports = require ( "events" ) ; ;
2020-10-08 00:52:52 +02:00
2021-07-01 16:27:24 +02:00
/***/ } ) ,
/***/ 747 :
/***/ ( ( module ) => {
"use strict" ;
module . exports = require ( "fs" ) ; ;
/***/ } ) ,
/***/ 87 :
/***/ ( ( module ) => {
"use strict" ;
module . exports = require ( "os" ) ; ;
/***/ } ) ,
/***/ 622 :
/***/ ( ( module ) => {
"use strict" ;
module . exports = require ( "path" ) ; ;
/***/ } ) ,
/***/ 413 :
/***/ ( ( module ) => {
"use strict" ;
module . exports = require ( "stream" ) ; ;
/***/ } ) ,
/***/ 304 :
/***/ ( ( module ) => {
"use strict" ;
module . exports = require ( "string_decoder" ) ; ;
/***/ } ) ,
/***/ 213 :
/***/ ( ( module ) => {
"use strict" ;
module . exports = require ( "timers" ) ; ;
/***/ } ) ,
/***/ 669 :
/***/ ( ( module ) => {
"use strict" ;
module . exports = require ( "util" ) ; ;
2020-10-08 00:52:52 +02:00
/***/ } )
2021-07-01 16:27:24 +02:00
/******/ } ) ;
/************************************************************************/
/******/ // The module cache
/******/ var _ _webpack _module _cache _ _ = { } ;
/******/
/******/ // The require function
/******/ function _ _nccwpck _require _ _ ( moduleId ) {
/******/ // Check if module is in cache
/******/ var cachedModule = _ _webpack _module _cache _ _ [ moduleId ] ;
/******/ if ( cachedModule !== undefined ) {
/******/ return cachedModule . exports ;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = _ _webpack _module _cache _ _ [ moduleId ] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports : { }
/******/ } ;
/******/
/******/ // Execute the module function
/******/ var threw = true ;
/******/ try {
/******/ _ _webpack _modules _ _ [ moduleId ] . call ( module . exports , module , module . exports , _ _nccwpck _require _ _ ) ;
/******/ threw = false ;
/******/ } finally {
/******/ if ( threw ) delete _ _webpack _module _cache _ _ [ moduleId ] ;
/******/ }
/******/
/******/ // Return the exports of the module
/******/ return module . exports ;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat */
/******/
/******/ if ( typeof _ _nccwpck _require _ _ !== 'undefined' ) _ _nccwpck _require _ _ . ab = _ _dirname + "/" ; /************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var _ _webpack _exports _ _ = _ _nccwpck _require _ _ ( 109 ) ;
/******/ module . exports = _ _webpack _exports _ _ ;
/******/
/******/ } ) ( )
;