Skip to content

Commit df7bf53

Browse files
committed
React to changes in toolrunner
1 parent b284022 commit df7bf53

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

node/toolrunner.ts

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface IExecOptions extends IExecSyncOptions {
1717

1818
/** optional. defaults to failing on non zero. ignore will not fail leaving it up to the caller */
1919
ignoreReturnCode: boolean;
20-
};
20+
}
2121

2222
/**
2323
* Interface for execSync options
@@ -38,7 +38,7 @@ export interface IExecSyncOptions {
3838

3939
/** optional. foo.whether to skip quoting/escaping arguments if needed. defaults to false. */
4040
windowsVerbatimArguments: boolean;
41-
};
41+
}
4242

4343
/**
4444
* Interface for exec results returned from synchronous exec functions
@@ -479,7 +479,8 @@ export class ToolRunner extends events.EventEmitter {
479479
return result;
480480
}
481481

482-
private _getSpawnOptions(options: IExecOptions): child.SpawnOptions {
482+
private _getSpawnOptions(options?: IExecOptions): child.SpawnOptions {
483+
options = options || <IExecOptions>{};
483484
let result = <child.SpawnOptions>{};
484485
result.cwd = options.cwd;
485486
result.env = options.env;
@@ -504,24 +505,29 @@ export class ToolRunner extends events.EventEmitter {
504505
this._debug(' ' + arg);
505506
});
506507

508+
// This is a private method, and must be called only when `this.pipeOutputToTool` is set
509+
if (!this.pipeOutputToTool) {
510+
throw new Error('You must call pipeExecOutputToTool before calling execWithPiping');
511+
}
512+
const pipeOutputToTool = this.pipeOutputToTool;
513+
507514
let success = true;
508-
options = this._cloneExecOptions(options);
515+
const optionsNonNull = this._cloneExecOptions(options);
509516

510-
if (!options.silent) {
511-
options.outStream.write(this._getCommandString(options) + os.EOL);
517+
if (!optionsNonNull.silent) {
518+
optionsNonNull.outStream.write(this._getCommandString(optionsNonNull) + os.EOL);
512519
}
513520

514-
let cp;
515-
let toolPath: string = this.toolPath;
521+
let cp: child.ChildProcess;
522+
let toolPath: string = pipeOutputToTool.toolPath;
516523
let toolPathFirst: string;
517524
let successFirst = true;
518525
let returnCodeFirst: number;
519-
let fileStream: fs.WriteStream;
526+
let fileStream: fs.WriteStream | null;
520527
let waitingEvents: number = 0; // number of process or stream events we are waiting on to complete
521528
let returnCode: number = 0;
522-
let error;
529+
let error: any;
523530

524-
toolPath = this.pipeOutputToTool.toolPath;
525531
toolPathFirst = this.toolPath;
526532

527533
// Following node documentation example from this link on how to pipe output of one process to another
@@ -531,18 +537,18 @@ export class ToolRunner extends events.EventEmitter {
531537
waitingEvents++;
532538
var cpFirst = child.spawn(
533539
this._getSpawnFileName(),
534-
this._getSpawnArgs(options),
535-
this._getSpawnOptions(options));
536-
540+
this._getSpawnArgs(optionsNonNull),
541+
this._getSpawnOptions(optionsNonNull));
542+
537543
waitingEvents ++;
538544
cp = child.spawn(
539-
this.pipeOutputToTool._getSpawnFileName(),
540-
this.pipeOutputToTool._getSpawnArgs(options),
541-
this.pipeOutputToTool._getSpawnOptions(options));
545+
pipeOutputToTool._getSpawnFileName(),
546+
pipeOutputToTool._getSpawnArgs(optionsNonNull),
547+
pipeOutputToTool._getSpawnOptions(optionsNonNull));
542548

543549
fileStream = this.pipeOutputToFile ? fs.createWriteStream(this.pipeOutputToFile) : null;
544550
if (fileStream) {
545-
waitingEvents ++;
551+
waitingEvents++;
546552
fileStream.on('finish', () => {
547553
waitingEvents--; //file write is complete
548554
fileStream = null;
@@ -554,7 +560,7 @@ export class ToolRunner extends events.EventEmitter {
554560
}
555561
}
556562
});
557-
fileStream.on('error', (err) => {
563+
fileStream.on('error', (err: Error) => {
558564
waitingEvents--; //there were errors writing to the file, write is done
559565
this._debug(`Failed to pipe output of ${toolPathFirst} to file ${this.pipeOutputToFile}. Error = ${err}`);
560566
fileStream = null;
@@ -565,7 +571,7 @@ export class ToolRunner extends events.EventEmitter {
565571
defer.resolve(returnCode);
566572
}
567573
}
568-
})
574+
});
569575
}
570576

571577
//pipe stdout of first tool to stdin of second tool
@@ -584,13 +590,13 @@ export class ToolRunner extends events.EventEmitter {
584590
if (fileStream) {
585591
fileStream.write(data);
586592
}
587-
successFirst = !options.failOnStdErr;
588-
if (!options.silent) {
589-
var s = options.failOnStdErr ? options.errStream : options.outStream;
593+
successFirst = !optionsNonNull.failOnStdErr;
594+
if (!optionsNonNull.silent) {
595+
var s = optionsNonNull.failOnStdErr ? optionsNonNull.errStream : optionsNonNull.outStream;
590596
s.write(data);
591597
}
592598
});
593-
cpFirst.on('error', (err) => {
599+
cpFirst.on('error', (err: Error) => {
594600
waitingEvents--; //first process is complete with errors
595601
if (fileStream) {
596602
fileStream.end();
@@ -601,9 +607,9 @@ export class ToolRunner extends events.EventEmitter {
601607
defer.reject(error);
602608
}
603609
});
604-
cpFirst.on('close', (code, signal) => {
610+
cpFirst.on('close', (code: number, signal: any) => {
605611
waitingEvents--; //first process is complete
606-
if (code != 0 && !options.ignoreReturnCode) {
612+
if (code != 0 && !optionsNonNull.ignoreReturnCode) {
607613
successFirst = false;
608614
returnCodeFirst = code;
609615
returnCode = returnCodeFirst;
@@ -626,8 +632,8 @@ export class ToolRunner extends events.EventEmitter {
626632
cp.stdout.on('data', (data: Buffer) => {
627633
this.emit('stdout', data);
628634

629-
if (!options.silent) {
630-
options.outStream.write(data);
635+
if (!optionsNonNull.silent) {
636+
optionsNonNull.outStream.write(data);
631637
}
632638

633639
this._processLineBuffer(data, stdbuffer, (line: string) => {
@@ -639,9 +645,9 @@ export class ToolRunner extends events.EventEmitter {
639645
cp.stderr.on('data', (data: Buffer) => {
640646
this.emit('stderr', data);
641647

642-
success = !options.failOnStdErr;
643-
if (!options.silent) {
644-
var s = options.failOnStdErr ? options.errStream : options.outStream;
648+
success = !optionsNonNull.failOnStdErr;
649+
if (!optionsNonNull.silent) {
650+
var s = optionsNonNull.failOnStdErr ? optionsNonNull.errStream : optionsNonNull.outStream;
645651
s.write(data);
646652
}
647653

@@ -650,15 +656,15 @@ export class ToolRunner extends events.EventEmitter {
650656
});
651657
});
652658

653-
cp.on('error', (err) => {
659+
cp.on('error', (err: Error) => {
654660
waitingEvents--; //process is done with errors
655661
error = new Error(toolPath + ' failed. ' + err.message);
656662
if(waitingEvents == 0) {
657663
defer.reject(error);
658664
}
659665
});
660666

661-
cp.on('close', (code, signal) => {
667+
cp.on('close', (code: number, signal: any) => {
662668
waitingEvents--; //process is complete
663669
this._debug('rc:' + code);
664670
returnCode = code;
@@ -671,12 +677,12 @@ export class ToolRunner extends events.EventEmitter {
671677
this.emit('errline', errbuffer);
672678
}
673679

674-
if (code != 0 && !options.ignoreReturnCode) {
680+
if (code != 0 && !optionsNonNull.ignoreReturnCode) {
675681
success = false;
676682
}
677683

678684
this._debug('success:' + success);
679-
685+
680686
if (!successFirst) { //in the case output is piped to another tool, check exit code of both tools
681687
error = new Error(toolPathFirst + ' failed with return code: ' + returnCodeFirst);
682688
} else if (!success) {
@@ -788,26 +794,22 @@ export class ToolRunner extends events.EventEmitter {
788794
this._debug(' ' + arg);
789795
});
790796

791-
options = this._cloneExecOptions(options);
792-
if (!options.silent) {
793-
options.outStream.write(this._getCommandString(options) + os.EOL);
797+
const optionsNonNull = this._cloneExecOptions(options);
798+
if (!optionsNonNull.silent) {
799+
optionsNonNull.outStream.write(this._getCommandString(optionsNonNull) + os.EOL);
794800
}
795801

796-
let state = new ExecState(options, this.toolPath);
797-
state.on('debug', (message) => {
802+
let state = new ExecState(optionsNonNull, this.toolPath);
803+
state.on('debug', (message: string) => {
798804
this._debug(message);
799805
});
800806

801-
let cp = child.spawn(this._getSpawnFileName(), this._getSpawnArgs(options), this._getSpawnOptions(options));
807+
let cp = child.spawn(this._getSpawnFileName(), this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(options));
802808

803809
var stdbuffer: string = '';
804810
cp.stdout.on('data', (data: Buffer) => {
805811
this.emit('stdout', data);
806812

807-
if (!clonedOptions.silent) {
808-
clonedOptions.outStream.write(data);
809-
}
810-
811813
this._processLineBuffer(data, stdbuffer, (line: string) => {
812814
this.emit('stdline', line);
813815
});
@@ -818,8 +820,8 @@ export class ToolRunner extends events.EventEmitter {
818820
state.processStderr = true;
819821
this.emit('stderr', data);
820822

821-
if (!options.silent) {
822-
var s = options.failOnStdErr ? options.errStream : options.outStream;
823+
if (!optionsNonNull.silent) {
824+
var s = optionsNonNull.failOnStdErr ? optionsNonNull.errStream : optionsNonNull.outStream;
823825
s.write(data);
824826
}
825827

@@ -828,29 +830,29 @@ export class ToolRunner extends events.EventEmitter {
828830
});
829831
});
830832

831-
cp.on('error', (err) => {
833+
cp.on('error', (err: Error) => {
832834
state.processError = err.message;
833835
state.processExited = true;
834836
state.processClosed = true;
835837
state.CheckComplete();
836838
});
837839

838-
cp.on('exit', (code, signal) => {
840+
cp.on('exit', (code: number, signal: any) => {
839841
state.processExitCode = code;
840842
state.processExited = true;
841843
this._debug(`Exit code ${code} received from tool '${this.toolPath}'`);
842844
state.CheckComplete()
843845
});
844846

845-
cp.on('close', (code, signal) => {
847+
cp.on('close', (code: number, signal: any) => {
846848
state.processExitCode = code;
847849
state.processExited = true;
848850
state.processClosed = true;
849851
this._debug(`STDIO streams have closed for tool '${this.toolPath}'`)
850852
state.CheckComplete();
851853
});
852854

853-
state.on('done', (error, exitCode) => {
855+
state.on('done', (error: Error, exitCode: number) => {
854856
if (stdbuffer.length > 0) {
855857
this.emit('stdline', stdbuffer);
856858
}
@@ -869,7 +871,7 @@ export class ToolRunner extends events.EventEmitter {
869871
}
870872
});
871873

872-
return <Q.Promise<number>>defer.promise;
874+
return defer.promise;
873875
}
874876

875877
/**
@@ -883,8 +885,6 @@ export class ToolRunner extends events.EventEmitter {
883885
* @returns IExecSyncResult
884886
*/
885887
public execSync(options?: IExecSyncOptions): IExecSyncResult {
886-
var defer = Q.defer();
887-
888888
this._debug('exec tool: ' + this.toolPath);
889889
this._debug('arguments:');
890890
this.args.forEach((arg) => {
@@ -942,7 +942,7 @@ class ExecState extends events.EventEmitter {
942942
private delay = 10000; // 10 seconds
943943
private done: boolean;
944944
private options: IExecOptions;
945-
private timeout;
945+
private timeout: NodeJS.Timer | null = null;
946946
private toolPath: string;
947947

948948
public CheckComplete(): void {
@@ -958,13 +958,13 @@ class ExecState extends events.EventEmitter {
958958
}
959959
}
960960

961-
private _debug(message): void {
961+
private _debug(message: any): void {
962962
this.emit('debug', message);
963963
}
964964

965965
private _setResult(): void {
966966
// determine whether there is an error
967-
let error: Error;
967+
let error: Error | undefined;
968968
if (this.processExited) {
969969
if (this.processError) {
970970
error = new Error(im._loc('LIB_ProcessError', this.toolPath, this.processError));

node/vault.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ export class Vault {
8585

8686
private genKey(): void {
8787
fs.writeFileSync(this._keyFile, uuidV4(), {encoding: 'utf8'});
88-
}
88+
}
8989
}

0 commit comments

Comments
 (0)