azure-pipelines-task-lib 4.16.0 → 4.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/toolrunner.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
2
4
  import Q = require('q');
3
5
  import events = require('events');
4
6
  /**
@@ -167,5 +169,5 @@ export declare class ToolRunner extends events.EventEmitter {
167
169
  * Used to close child process by sending SIGNINT signal.
168
170
  * It allows executed script to have some additional logic on SIGINT, before exiting.
169
171
  */
170
- killChildProcess(): void;
172
+ killChildProcess(signal?: number | NodeJS.Signals): void;
171
173
  }
package/toolrunner.js CHANGED
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -107,7 +109,7 @@ var ToolRunner = /** @class */ (function (_super) {
107
109
  }
108
110
  // Windows + verbatim
109
111
  else if (options.windowsVerbatimArguments) {
110
- commandParts.push("\"" + toolPath + "\"");
112
+ commandParts.push("\"".concat(toolPath, "\""));
111
113
  commandParts = commandParts.concat(args);
112
114
  }
113
115
  else if (options.shell) {
@@ -160,7 +162,7 @@ var ToolRunner = /** @class */ (function (_super) {
160
162
  */
161
163
  ToolRunner.prototype._wrapArg = function (arg, wrapChar) {
162
164
  if (!this._isWrapped(arg, wrapChar)) {
163
- return "" + wrapChar + arg + wrapChar;
165
+ return "".concat(wrapChar).concat(arg).concat(wrapChar);
164
166
  }
165
167
  return arg;
166
168
  };
@@ -171,7 +173,7 @@ var ToolRunner = /** @class */ (function (_super) {
171
173
  */
172
174
  ToolRunner.prototype._unwrapArg = function (arg, wrapChar) {
173
175
  if (this._isWrapped(arg, wrapChar)) {
174
- var pattern = new RegExp("(^\\\\?" + wrapChar + ")|(\\\\?" + wrapChar + "$)", 'g');
176
+ var pattern = new RegExp("(^\\\\?".concat(wrapChar, ")|(\\\\?").concat(wrapChar, "$)"), 'g');
175
177
  return arg.trim().replace(pattern, '');
176
178
  }
177
179
  return arg;
@@ -181,7 +183,7 @@ var ToolRunner = /** @class */ (function (_super) {
181
183
  * @param arg Input arg string
182
184
  */
183
185
  ToolRunner.prototype._isWrapped = function (arg, wrapChar) {
184
- var pattern = new RegExp("^\\\\?" + wrapChar + ".+\\\\?" + wrapChar + "$");
186
+ var pattern = new RegExp("^\\\\?".concat(wrapChar, ".+\\\\?").concat(wrapChar, "$"));
185
187
  return pattern.test(arg.trim());
186
188
  };
187
189
  ToolRunner.prototype._getSpawnFileName = function (options) {
@@ -199,7 +201,7 @@ var ToolRunner = /** @class */ (function (_super) {
199
201
  var _this = this;
200
202
  if (process.platform == 'win32') {
201
203
  if (this._isCmdFile()) {
202
- var argline = "/D /S /C \"" + this._windowsQuoteCmdArg(this.toolPath);
204
+ var argline = "/D /S /C \"".concat(this._windowsQuoteCmdArg(this.toolPath));
203
205
  for (var i = 0; i < this.args.length; i++) {
204
206
  argline += ' ';
205
207
  argline += options.windowsVerbatimArguments ? this.args[i] : this._windowsQuoteCmdArg(this.args[i]);
@@ -243,7 +245,7 @@ var ToolRunner = /** @class */ (function (_super) {
243
245
  if (arguments.length != 1) {
244
246
  throw new Error('Unexpected arguments passed to args.unshift when windowsVerbatimArguments flag is set.');
245
247
  }
246
- return Array.prototype.unshift.call(args_1, "\"" + arguments[0] + "\""); // quote the file name
248
+ return Array.prototype.unshift.call(args_1, "\"".concat(arguments[0], "\"")); // quote the file name
247
249
  };
248
250
  return args_1;
249
251
  }
@@ -447,7 +449,7 @@ var ToolRunner = /** @class */ (function (_super) {
447
449
  if (arg.indexOf('"') < 0 && arg.indexOf('\\') < 0) {
448
450
  // No embedded double quotes or backslashes, so I can just wrap
449
451
  // quote marks around the whole thing.
450
- return "\"" + arg + "\"";
452
+ return "\"".concat(arg, "\"");
451
453
  }
452
454
  // Expected input/output:
453
455
  // input : hello"world
@@ -564,7 +566,7 @@ var ToolRunner = /** @class */ (function (_super) {
564
566
  });
565
567
  fileStream.on('error', function (err) {
566
568
  waitingEvents--; //there were errors writing to the file, write is done
567
- _this._debug("Failed to pipe output of " + toolPathFirst + " to file " + _this.pipeOutputToFile + ". Error = " + err);
569
+ _this._debug("Failed to pipe output of ".concat(toolPathFirst, " to file ").concat(_this.pipeOutputToFile, ". Error = ").concat(err));
568
570
  fileStream = null;
569
571
  if (waitingEvents == 0) {
570
572
  if (error) {
@@ -578,12 +580,14 @@ var ToolRunner = /** @class */ (function (_super) {
578
580
  }
579
581
  //pipe stdout of first tool to stdin of second tool
580
582
  (_a = cpFirst.stdout) === null || _a === void 0 ? void 0 : _a.on('data', function (data) {
581
- var _a;
583
+ var _a, _b;
582
584
  try {
583
585
  if (fileStream) {
584
586
  fileStream.write(data);
585
587
  }
586
- (_a = cp.stdin) === null || _a === void 0 ? void 0 : _a.write(data);
588
+ if (!((_a = cp.stdin) === null || _a === void 0 ? void 0 : _a.destroyed)) {
589
+ (_b = cp.stdin) === null || _b === void 0 ? void 0 : _b.write(data);
590
+ }
587
591
  }
588
592
  catch (err) {
589
593
  _this._debug('Failed to pipe output of ' + toolPathFirst + ' to ' + toolPath);
@@ -742,7 +746,7 @@ var ToolRunner = /** @class */ (function (_super) {
742
746
  });
743
747
  fileStream.on('error', function (err) {
744
748
  waitingEvents--; //there were errors writing to the file, write is done
745
- _this._debug("Failed to pipe output of " + toolPathFirst + " to file " + _this.pipeOutputToFile + ". Error = " + err);
749
+ _this._debug("Failed to pipe output of ".concat(toolPathFirst, " to file ").concat(_this.pipeOutputToFile, ". Error = ").concat(err));
746
750
  fileStream = null;
747
751
  if (waitingEvents == 0) {
748
752
  if (error) {
@@ -1035,17 +1039,18 @@ var ToolRunner = /** @class */ (function (_super) {
1035
1039
  state.processClosed = true;
1036
1040
  state.CheckComplete();
1037
1041
  });
1042
+ // Do not write debug logs here. Sometimes stdio not closed yet and you can damage user output commands.
1038
1043
  cp.on('exit', function (code, signal) {
1039
1044
  state.processExitCode = code;
1045
+ state.processExitSignal = signal;
1040
1046
  state.processExited = true;
1041
- _this._debug("Exit code " + code + " received from tool '" + _this.toolPath + "'");
1042
1047
  state.CheckComplete();
1043
1048
  });
1044
1049
  cp.on('close', function (code, signal) {
1045
- state.processExitCode = code;
1046
- state.processExited = true;
1050
+ state.processCloseCode = code;
1051
+ state.processCloseSignal = signal;
1047
1052
  state.processClosed = true;
1048
- _this._debug("STDIO streams have closed for tool '" + _this.toolPath + "'");
1053
+ state.processExited = true;
1049
1054
  state.CheckComplete();
1050
1055
  });
1051
1056
  return new Promise(emitDoneEvent);
@@ -1146,17 +1151,18 @@ var ToolRunner = /** @class */ (function (_super) {
1146
1151
  state.processClosed = true;
1147
1152
  state.CheckComplete();
1148
1153
  });
1154
+ // Do not write debug logs here. Sometimes stdio not closed yet and you can damage user output commands.
1149
1155
  cp.on('exit', function (code, signal) {
1150
1156
  state.processExitCode = code;
1157
+ state.processExitSignal = signal;
1151
1158
  state.processExited = true;
1152
- _this._debug("Exit code " + code + " received from tool '" + _this.toolPath + "'");
1153
1159
  state.CheckComplete();
1154
1160
  });
1155
1161
  cp.on('close', function (code, signal) {
1156
- state.processExitCode = code;
1157
- state.processExited = true;
1162
+ state.processCloseCode = code;
1163
+ state.processCloseSignal = signal;
1158
1164
  state.processClosed = true;
1159
- _this._debug("STDIO streams have closed for tool '" + _this.toolPath + "'");
1165
+ state.processExited = true;
1160
1166
  state.CheckComplete();
1161
1167
  });
1162
1168
  return defer.promise;
@@ -1199,9 +1205,11 @@ var ToolRunner = /** @class */ (function (_super) {
1199
1205
  * Used to close child process by sending SIGNINT signal.
1200
1206
  * It allows executed script to have some additional logic on SIGINT, before exiting.
1201
1207
  */
1202
- ToolRunner.prototype.killChildProcess = function () {
1208
+ ToolRunner.prototype.killChildProcess = function (signal) {
1209
+ if (signal === void 0) { signal = "SIGTERM"; }
1203
1210
  if (this.childProcess) {
1204
- this.childProcess.kill();
1211
+ this._debug("[killChildProcess] Signal ".concat(signal, " received"));
1212
+ this.childProcess.kill(signal);
1205
1213
  }
1206
1214
  };
1207
1215
  return ToolRunner;
@@ -1242,6 +1250,7 @@ var ExecState = /** @class */ (function (_super) {
1242
1250
  // determine whether there is an error
1243
1251
  var error;
1244
1252
  if (this.processExited) {
1253
+ this._debug("Process exited with code ".concat(this.processExitCode, " and signal ").concat(this.processExitSignal, " for tool '").concat(this.toolPath, "'"));
1245
1254
  if (this.processError) {
1246
1255
  error = new Error(im._loc('LIB_ProcessError', this.toolPath, this.processError));
1247
1256
  }
@@ -1252,6 +1261,9 @@ var ExecState = /** @class */ (function (_super) {
1252
1261
  error = new Error(im._loc('LIB_ProcessStderr', this.toolPath));
1253
1262
  }
1254
1263
  }
1264
+ if (this.processClosed) {
1265
+ this._debug("STDIO streams have closed and received exit code ".concat(this.processCloseCode, " and signal ").concat(this.processCloseSignal, " for tool '").concat(this.toolPath, "'"));
1266
+ }
1255
1267
  // clear the timeout
1256
1268
  if (this.timeout) {
1257
1269
  clearTimeout(this.timeout);