azure-pipelines-task-lib 4.5.0 → 5.0.0-preview.0

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.
@@ -0,0 +1,17 @@
1
+ export interface MockOptions {
2
+ useCleanCache?: boolean;
3
+ warnOnReplace?: boolean;
4
+ warnOnUnregistered?: boolean;
5
+ }
6
+ export declare function enable(opts: MockOptions): void;
7
+ export declare function disable(): void;
8
+ export declare function resetCache(): void;
9
+ export declare function warnOnReplace(enable: boolean): void;
10
+ export declare function warnOnUnregistered(enable: boolean): void;
11
+ export declare function registerMock(mod: string, mock: any): void;
12
+ export declare function deregisterMock(mod: string): void;
13
+ export declare function deregisterAll(): void;
14
+ export declare function registerAllowable(mod: string): void;
15
+ export declare function registerAllowables(mods: string[]): void;
16
+ export declare function deregisterAllowable(mod: string): void;
17
+ export declare function deregisterAllowables(mods: any): void;
package/lib-mocker.js ADDED
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deregisterAllowables = exports.deregisterAllowable = exports.registerAllowables = exports.registerAllowable = exports.deregisterAll = exports.deregisterMock = exports.registerMock = exports.warnOnUnregistered = exports.warnOnReplace = exports.resetCache = exports.disable = exports.enable = void 0;
4
+ var m = require('module');
5
+ ;
6
+ var registeredMocks = {};
7
+ var registeredAllowables = new Set();
8
+ var originalLoader = null;
9
+ var originalCache = {};
10
+ var options = {};
11
+ var defaultOptions = {
12
+ useCleanCache: false,
13
+ warnOnReplace: true,
14
+ warnOnUnregistered: true
15
+ };
16
+ function _getEffectiveOptions(opts) {
17
+ var options = {};
18
+ Object.keys(defaultOptions).forEach(function (key) {
19
+ if (opts && opts.hasOwnProperty(key)) {
20
+ options[key] = opts[key];
21
+ }
22
+ else {
23
+ options[key] = defaultOptions[key];
24
+ }
25
+ });
26
+ return options;
27
+ }
28
+ /*
29
+ * Loader function that used when hooking is enabled.
30
+ * if the requested module is registered as a mock, return the mock.
31
+ * otherwise, invoke the original loader + put warning in the output.
32
+ */
33
+ function _hookedLoader(request, parent, isMain) {
34
+ if (!originalLoader) {
35
+ throw new Error("Loader has not been hooked");
36
+ }
37
+ if (registeredMocks.hasOwnProperty(request)) {
38
+ return registeredMocks[request];
39
+ }
40
+ if (!registeredAllowables.has(request) && options.warnOnUnregistered) {
41
+ console.warn("WARNING: loading non-allowed module: " + request);
42
+ }
43
+ return originalLoader(request, parent, isMain);
44
+ }
45
+ /**
46
+ * Remove references to modules in the cache from
47
+ * their parents' children.
48
+ */
49
+ function _removeParentReferences() {
50
+ Object.keys(m._cache).forEach(function (k) {
51
+ var _a;
52
+ if (k.indexOf('\.node') === -1) {
53
+ // don't touch native modules, because they're special
54
+ var mod = m._cache[k];
55
+ var idx = (_a = mod === null || mod === void 0 ? void 0 : mod.parent) === null || _a === void 0 ? void 0 : _a.children.indexOf(mod);
56
+ if (idx > -1) {
57
+ mod.parent.children.splice(idx, 1);
58
+ }
59
+ }
60
+ });
61
+ }
62
+ /*
63
+ * Starting in node 0.12 node won't reload native modules
64
+ * The reason is that native modules can register themselves to be loaded automatically
65
+ * This will re-populate the cache with the native modules that have not been mocked
66
+ */
67
+ function _repopulateNative() {
68
+ Object.keys(originalCache).forEach(function (k) {
69
+ if (k.indexOf('\.node') > -1 && !m._cache[k]) {
70
+ m._cache[k] = originalCache[k];
71
+ }
72
+ });
73
+ }
74
+ /*
75
+ * Enable function, hooking the Node loader with options.
76
+ */
77
+ function enable(opts) {
78
+ if (originalLoader) {
79
+ // Already hooked
80
+ return;
81
+ }
82
+ options = _getEffectiveOptions(opts);
83
+ if (options.useCleanCache) {
84
+ originalCache = m._cache;
85
+ m._cache = {};
86
+ _repopulateNative();
87
+ }
88
+ originalLoader = m._load;
89
+ m._load = _hookedLoader;
90
+ }
91
+ exports.enable = enable;
92
+ /*
93
+ * Disables mock loading, reverting to normal 'require' behaviour.
94
+ */
95
+ function disable() {
96
+ if (!originalLoader)
97
+ return;
98
+ if (options.useCleanCache) {
99
+ Object.keys(m._cache).forEach(function (k) {
100
+ if (k.indexOf('\.node') > -1 && !originalCache[k]) {
101
+ originalCache[k] = m._cache[k];
102
+ }
103
+ });
104
+ _removeParentReferences();
105
+ m._cache = originalCache;
106
+ originalCache = {};
107
+ }
108
+ m._load = originalLoader;
109
+ originalLoader = null;
110
+ }
111
+ exports.disable = disable;
112
+ /*
113
+ * If the clean cache option is in effect, reset the module cache to an empty
114
+ * state. Calling this function when the clean cache option is not in effect
115
+ * will have no ill effects, but will do nothing.
116
+ */
117
+ function resetCache() {
118
+ if (options.useCleanCache && originalCache) {
119
+ _removeParentReferences();
120
+ m._cache = {};
121
+ _repopulateNative();
122
+ }
123
+ }
124
+ exports.resetCache = resetCache;
125
+ /*
126
+ * Enable or disable warnings to the console when previously registered mocks are replaced.
127
+ */
128
+ function warnOnReplace(enable) {
129
+ options.warnOnReplace = enable;
130
+ }
131
+ exports.warnOnReplace = warnOnReplace;
132
+ /*
133
+ * Enable or disable warnings to the console when modules are loaded that have
134
+ * not been registered as a mock.
135
+ */
136
+ function warnOnUnregistered(enable) {
137
+ options.warnOnUnregistered = enable;
138
+ }
139
+ exports.warnOnUnregistered = warnOnUnregistered;
140
+ /*
141
+ * Register a mock object for the specified module.
142
+ */
143
+ function registerMock(mod, mock) {
144
+ if (options.warnOnReplace && registeredMocks.hasOwnProperty(mod)) {
145
+ console.warn("WARNING: Replacing existing mock for module: " + mod);
146
+ }
147
+ registeredMocks[mod] = mock;
148
+ }
149
+ exports.registerMock = registerMock;
150
+ /*
151
+ * Deregister a mock object for the specified module.
152
+ */
153
+ function deregisterMock(mod) {
154
+ if (registeredMocks.hasOwnProperty(mod)) {
155
+ delete registeredMocks[mod];
156
+ }
157
+ }
158
+ exports.deregisterMock = deregisterMock;
159
+ /*
160
+ * Deregister all mocks.
161
+ */
162
+ function deregisterAll() {
163
+ registeredMocks = {};
164
+ registeredAllowables = new Set();
165
+ }
166
+ exports.deregisterAll = deregisterAll;
167
+ /*
168
+ Register a module as 'allowed'.
169
+ This will allow the module to be loaded without mock otherwise a warning would be thrown.
170
+ */
171
+ function registerAllowable(mod) {
172
+ registeredAllowables.add(mod);
173
+ }
174
+ exports.registerAllowable = registerAllowable;
175
+ /*
176
+ * Register an array of 'allowed' modules.
177
+ */
178
+ function registerAllowables(mods) {
179
+ mods.forEach(function (mod) { return registerAllowable(mod); });
180
+ }
181
+ exports.registerAllowables = registerAllowables;
182
+ /*
183
+ * Deregister a module as 'allowed'.
184
+ */
185
+ function deregisterAllowable(mod) {
186
+ if (registeredAllowables.hasOwnProperty(mod)) {
187
+ registeredAllowables.delete(mod);
188
+ }
189
+ }
190
+ exports.deregisterAllowable = deregisterAllowable;
191
+ /*
192
+ * Deregister an array of modules as 'allowed'.
193
+ */
194
+ function deregisterAllowables(mods) {
195
+ mods.forEach(function (mod) {
196
+ deregisterAllowable(mod);
197
+ });
198
+ }
199
+ exports.deregisterAllowables = deregisterAllowables;
package/mock-run.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TaskMockRunner = void 0;
4
- var mockery = require("mockery");
5
4
  var im = require("./internal");
5
+ var mocker = require("./lib-mocker");
6
6
  var TaskMockRunner = /** @class */ (function () {
7
7
  function TaskMockRunner(taskPath) {
8
8
  this._exports = {};
@@ -40,7 +40,7 @@ var TaskMockRunner = /** @class */ (function () {
40
40
  */
41
41
  TaskMockRunner.prototype.registerMock = function (modName, mod) {
42
42
  this._moduleCount++;
43
- mockery.registerMock(modName, mod);
43
+ mocker.registerMock(modName, mod);
44
44
  };
45
45
  /**
46
46
  * Registers an override for a specific function on the mock "azure-pipelines-task-lib/task" instance.
@@ -62,9 +62,9 @@ var TaskMockRunner = /** @class */ (function () {
62
62
  */
63
63
  TaskMockRunner.prototype.run = function (noMockTask) {
64
64
  var _this = this;
65
- // determine whether to enable mockery
65
+ // determine whether to enable mocker
66
66
  if (!noMockTask || this._moduleCount) {
67
- mockery.enable({ warnOnUnregistered: false });
67
+ mocker.enable({ warnOnUnregistered: false });
68
68
  }
69
69
  // answers and exports not compatible with "noMockTask" mode
70
70
  if (noMockTask) {
@@ -82,7 +82,7 @@ var TaskMockRunner = /** @class */ (function () {
82
82
  .forEach(function (key) {
83
83
  tlm[key] = _this._exports[key];
84
84
  });
85
- mockery.registerMock('azure-pipelines-task-lib/task', tlm);
85
+ mocker.registerMock('azure-pipelines-task-lib/task', tlm);
86
86
  }
87
87
  // run it
88
88
  require(this._taskPath);
package/mock-task.d.ts CHANGED
@@ -74,7 +74,6 @@ export declare function find(findPath: string): string[];
74
74
  export declare function rmRF(path: string): void;
75
75
  export declare function mv(source: string, dest: string, force: boolean, continueOnError?: boolean): boolean;
76
76
  export declare function exec(tool: string, args: any, options?: trm.IExecOptions): Q.Promise<number>;
77
- export declare function execAsync(tool: string, args: any, options?: trm.IExecOptions): Promise<number>;
78
77
  export declare function execSync(tool: string, args: any, options?: trm.IExecSyncOptions): trm.IExecSyncResult;
79
78
  export declare function tool(tool: string): trm.ToolRunner;
80
79
  export interface MatchOptions {
package/mock-task.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHttpCertConfiguration = exports.getHttpProxyConfiguration = exports.CodeCoverageEnabler = exports.CodeCoveragePublisher = exports.TestPublisher = exports.legacyFindFiles = exports.findMatch = exports.tool = exports.execSync = exports.execAsync = exports.exec = exports.mv = exports.rmRF = exports.find = exports.retry = exports.cp = exports.ls = exports.which = exports.resolve = exports.mkdirP = exports.checkPath = exports.popd = exports.pushd = exports.cd = exports.cwd = exports.getAgentMode = exports.getPlatform = exports.osType = exports.writeFile = exports.exist = exports.stats = exports.FsStats = exports.loc = exports.setResourcePath = exports.setAnswers = void 0;
3
+ exports.getHttpCertConfiguration = exports.getHttpProxyConfiguration = exports.CodeCoverageEnabler = exports.CodeCoveragePublisher = exports.TestPublisher = exports.legacyFindFiles = exports.findMatch = exports.tool = exports.execSync = exports.exec = exports.mv = exports.rmRF = exports.find = exports.retry = exports.cp = exports.ls = exports.which = exports.resolve = exports.mkdirP = exports.checkPath = exports.popd = exports.pushd = exports.cd = exports.cwd = exports.getAgentMode = exports.getPlatform = exports.osType = exports.writeFile = exports.exist = exports.stats = exports.FsStats = exports.loc = exports.setResourcePath = exports.setAnswers = void 0;
4
4
  var path = require("path");
5
5
  var task = require("./task");
6
6
  var tcm = require("./taskcommand");
@@ -299,18 +299,6 @@ function exec(tool, args, options) {
299
299
  return tr.exec(options);
300
300
  }
301
301
  exports.exec = exec;
302
- //-----------------------------------------------------
303
- // Exec convenience wrapper
304
- //-----------------------------------------------------
305
- function execAsync(tool, args, options) {
306
- var toolPath = which(tool, true);
307
- var tr = this.tool(toolPath);
308
- if (args) {
309
- tr.arg(args);
310
- }
311
- return tr.execAsync(options);
312
- }
313
- exports.execAsync = execAsync;
314
302
  function execSync(tool, args, options) {
315
303
  var toolPath = which(tool, true);
316
304
  var tr = this.tool(toolPath);
@@ -36,12 +36,6 @@ export declare class ToolRunner extends events.EventEmitter {
36
36
  line(val: string): ToolRunner;
37
37
  pipeExecOutputToTool(tool: ToolRunner): ToolRunner;
38
38
  private ignoreTempPath;
39
- execAsync(options?: IExecOptions): Promise<number>;
40
- /**
41
- * Exec - use for long running tools where you need to stream live output as it runs
42
- * @deprecated use `execAsync` instead
43
- * @returns a promise with return code.
44
- */
45
39
  exec(options?: IExecOptions): Q.Promise<number>;
46
40
  execSync(options?: IExecSyncOptions): IExecSyncResult;
47
41
  }
@@ -130,99 +130,6 @@ var ToolRunner = /** @class */ (function (_super) {
130
130
  // Exec - use for long running tools where you need to stream live output as it runs
131
131
  // returns a promise with return code.
132
132
  //
133
- ToolRunner.prototype.execAsync = function (options) {
134
- var _this = this;
135
- this._debug('exec tool: ' + this.toolPath);
136
- this._debug('Arguments:');
137
- this.args.forEach(function (arg) {
138
- _this._debug(' ' + arg);
139
- });
140
- var success = true;
141
- options = options || {};
142
- var ops = {
143
- cwd: options.cwd || process.cwd(),
144
- env: options.env || process.env,
145
- silent: options.silent || false,
146
- outStream: options.outStream || process.stdout,
147
- errStream: options.errStream || process.stderr,
148
- failOnStdErr: options.failOnStdErr || false,
149
- ignoreReturnCode: options.ignoreReturnCode || false,
150
- windowsVerbatimArguments: options.windowsVerbatimArguments
151
- };
152
- var argString = this.args.join(' ') || '';
153
- var cmdString = this.toolPath;
154
- if (argString) {
155
- cmdString += (' ' + argString);
156
- }
157
- // Using split/join to replace the temp path
158
- cmdString = this.ignoreTempPath(cmdString);
159
- if (!ops.silent) {
160
- if (this.pipeOutputToTool) {
161
- var pipeToolArgString = this.pipeOutputToTool.args.join(' ') || '';
162
- var pipeToolCmdString = this.ignoreTempPath(this.pipeOutputToTool.toolPath);
163
- if (pipeToolArgString) {
164
- pipeToolCmdString += (' ' + pipeToolArgString);
165
- }
166
- cmdString += ' | ' + pipeToolCmdString;
167
- }
168
- ops.outStream.write('[command]' + cmdString + os.EOL);
169
- }
170
- // TODO: filter process.env
171
- var res = mock.getResponse('exec', cmdString, debug);
172
- if (res.stdout) {
173
- this.emit('stdout', res.stdout);
174
- if (!ops.silent) {
175
- ops.outStream.write(res.stdout + os.EOL);
176
- }
177
- var stdLineArray = res.stdout.split(os.EOL);
178
- for (var _i = 0, _a = stdLineArray.slice(0, -1); _i < _a.length; _i++) {
179
- var line = _a[_i];
180
- this.emit('stdline', line);
181
- }
182
- if (stdLineArray.length > 0 && stdLineArray[stdLineArray.length - 1].length > 0) {
183
- this.emit('stdline', stdLineArray[stdLineArray.length - 1]);
184
- }
185
- }
186
- if (res.stderr) {
187
- this.emit('stderr', res.stderr);
188
- success = !ops.failOnStdErr;
189
- if (!ops.silent) {
190
- var s = ops.failOnStdErr ? ops.errStream : ops.outStream;
191
- s.write(res.stderr + os.EOL);
192
- }
193
- var stdErrArray = res.stderr.split(os.EOL);
194
- for (var _b = 0, _c = stdErrArray.slice(0, -1); _b < _c.length; _b++) {
195
- var line = _c[_b];
196
- this.emit('errline', line);
197
- }
198
- if (stdErrArray.length > 0 && stdErrArray[stdErrArray.length - 1].length > 0) {
199
- this.emit('errline', stdErrArray[stdErrArray.length - 1]);
200
- }
201
- }
202
- var code = res.code;
203
- if (!ops.silent) {
204
- ops.outStream.write('rc:' + res.code + os.EOL);
205
- }
206
- if (code != 0 && !ops.ignoreReturnCode) {
207
- success = false;
208
- }
209
- if (!ops.silent) {
210
- ops.outStream.write('success:' + success + os.EOL);
211
- }
212
- return new Promise(function (resolve, reject) {
213
- if (success) {
214
- resolve(code);
215
- }
216
- else {
217
- reject(new Error(_this.toolPath + ' failed with return code: ' + code));
218
- }
219
- });
220
- };
221
- /**
222
- * Exec - use for long running tools where you need to stream live output as it runs
223
- * @deprecated use `execAsync` instead
224
- * @returns a promise with return code.
225
- */
226
133
  ToolRunner.prototype.exec = function (options) {
227
134
  var _this = this;
228
135
  var defer = Q.defer();
@@ -317,6 +224,7 @@ var ToolRunner = /** @class */ (function (_super) {
317
224
  //
318
225
  ToolRunner.prototype.execSync = function (options) {
319
226
  var _this = this;
227
+ var defer = Q.defer();
320
228
  this._debug('exec tool: ' + this.toolPath);
321
229
  this._debug('Arguments:');
322
230
  this.args.forEach(function (arg) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azure-pipelines-task-lib",
3
- "version": "4.5.0",
3
+ "version": "5.0.0-preview.0",
4
4
  "description": "Azure Pipelines Task SDK",
5
5
  "main": "./task.js",
6
6
  "typings": "./task.d.ts",
@@ -28,7 +28,6 @@
28
28
  "homepage": "https://github.com/Microsoft/azure-pipelines-task-lib",
29
29
  "dependencies": {
30
30
  "minimatch": "3.0.5",
31
- "mockery": "^2.1.0",
32
31
  "q": "^1.5.1",
33
32
  "semver": "^5.1.0",
34
33
  "shelljs": "^0.8.5",
@@ -38,8 +37,7 @@
38
37
  "devDependencies": {
39
38
  "@types/minimatch": "3.0.3",
40
39
  "@types/mocha": "^9.1.1",
41
- "@types/mockery": "^1.4.29",
42
- "@types/node": "^10.17.0",
40
+ "@types/node": "^16.11.39",
43
41
  "@types/q": "^1.5.4",
44
42
  "@types/semver": "^7.3.4",
45
43
  "@types/shelljs": "^0.8.8",
package/task.d.ts CHANGED
@@ -486,18 +486,6 @@ export declare function rmRF(inputPath: string): void;
486
486
  * @param options optional exec options. See IExecOptions
487
487
  * @returns number
488
488
  */
489
- export declare function execAsync(tool: string, args: any, options?: trm.IExecOptions): Promise<number>;
490
- /**
491
- * Exec a tool. Convenience wrapper over ToolRunner to exec with args in one call.
492
- * Output will be streamed to the live console.
493
- * Returns promise with return code
494
- *
495
- * @deprecated Use the {@link execAsync} method that returns a native Javascript Promise instead
496
- * @param tool path to tool to exec
497
- * @param args an arg string or array of args
498
- * @param options optional exec options. See IExecOptions
499
- * @returns number
500
- */
501
489
  export declare function exec(tool: string, args: any, options?: trm.IExecOptions): Q.Promise<number>;
502
490
  /**
503
491
  * Exec a tool synchronously. Convenience wrapper over ToolRunner to execSync with args in one call.
package/task.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateReleaseName = exports.addBuildTag = exports.updateBuildNumber = exports.uploadBuildLog = exports.associateArtifact = exports.uploadArtifact = exports.logIssue = exports.logDetail = exports.setProgress = exports.setEndpoint = exports.addAttachment = exports.uploadSummary = exports.prependPath = exports.uploadFile = exports.CodeCoverageEnabler = exports.CodeCoveragePublisher = exports.TestPublisher = exports.getHttpCertConfiguration = exports.getHttpProxyConfiguration = exports.findMatch = exports.filter = exports.match = exports.tool = exports.execSync = exports.exec = exports.execAsync = exports.rmRF = exports.legacyFindFiles = exports.find = exports.retry = exports.mv = exports.cp = exports.ls = exports.which = exports.resolve = exports.mkdirP = exports.popd = exports.pushd = exports.cd = exports.checkPath = exports.cwd = exports.getAgentMode = exports.getPlatform = exports.osType = exports.writeFile = exports.exist = exports.stats = exports.debug = exports.error = exports.warning = exports.command = exports.setTaskVariable = exports.getTaskVariable = exports.getSecureFileTicket = exports.getSecureFileName = exports.getEndpointAuthorization = exports.getEndpointAuthorizationParameterRequired = exports.getEndpointAuthorizationParameter = exports.getEndpointAuthorizationSchemeRequired = exports.getEndpointAuthorizationScheme = exports.getEndpointDataParameterRequired = exports.getEndpointDataParameter = exports.getEndpointUrlRequired = exports.getEndpointUrl = exports.getPathInputRequired = exports.getPathInput = exports.filePathSupplied = exports.getDelimitedInput = exports.getBoolFeatureFlag = exports.getBoolInput = exports.getInputRequired = exports.getInput = exports.setSecret = exports.setVariable = exports.getVariables = exports.assertAgent = exports.getVariable = exports.loc = exports.setResourcePath = exports.setResult = exports.setErrStream = exports.setStdStream = exports.AgentHostedMode = exports.Platform = exports.FieldType = exports.ArtifactType = exports.IssueType = exports.TaskState = exports.TaskResult = void 0;
3
+ exports.updateReleaseName = exports.addBuildTag = exports.updateBuildNumber = exports.uploadBuildLog = exports.associateArtifact = exports.uploadArtifact = exports.logIssue = exports.logDetail = exports.setProgress = exports.setEndpoint = exports.addAttachment = exports.uploadSummary = exports.prependPath = exports.uploadFile = exports.CodeCoverageEnabler = exports.CodeCoveragePublisher = exports.TestPublisher = exports.getHttpCertConfiguration = exports.getHttpProxyConfiguration = exports.findMatch = exports.filter = exports.match = exports.tool = exports.execSync = exports.exec = exports.rmRF = exports.legacyFindFiles = exports.find = exports.retry = exports.mv = exports.cp = exports.ls = exports.which = exports.resolve = exports.mkdirP = exports.popd = exports.pushd = exports.cd = exports.checkPath = exports.cwd = exports.getAgentMode = exports.getPlatform = exports.osType = exports.writeFile = exports.exist = exports.stats = exports.debug = exports.error = exports.warning = exports.command = exports.setTaskVariable = exports.getTaskVariable = exports.getSecureFileTicket = exports.getSecureFileName = exports.getEndpointAuthorization = exports.getEndpointAuthorizationParameterRequired = exports.getEndpointAuthorizationParameter = exports.getEndpointAuthorizationSchemeRequired = exports.getEndpointAuthorizationScheme = exports.getEndpointDataParameterRequired = exports.getEndpointDataParameter = exports.getEndpointUrlRequired = exports.getEndpointUrl = exports.getPathInputRequired = exports.getPathInput = exports.filePathSupplied = exports.getDelimitedInput = exports.getBoolFeatureFlag = exports.getBoolInput = exports.getInputRequired = exports.getInput = exports.setSecret = exports.setVariable = exports.getVariables = exports.assertAgent = exports.getVariable = exports.loc = exports.setResourcePath = exports.setResult = exports.setErrStream = exports.setStdStream = exports.AgentHostedMode = exports.Platform = exports.FieldType = exports.ArtifactType = exports.IssueType = exports.TaskState = exports.TaskResult = void 0;
4
4
  var shell = require("shelljs");
5
5
  var childProcess = require("child_process");
6
6
  var fs = require("fs");
@@ -1264,33 +1264,6 @@ exports.rmRF = rmRF;
1264
1264
  * @param options optional exec options. See IExecOptions
1265
1265
  * @returns number
1266
1266
  */
1267
- function execAsync(tool, args, options) {
1268
- var tr = this.tool(tool);
1269
- tr.on('debug', function (data) {
1270
- exports.debug(data);
1271
- });
1272
- if (args) {
1273
- if (args instanceof Array) {
1274
- tr.arg(args);
1275
- }
1276
- else if (typeof (args) === 'string') {
1277
- tr.line(args);
1278
- }
1279
- }
1280
- return tr.execAsync(options);
1281
- }
1282
- exports.execAsync = execAsync;
1283
- /**
1284
- * Exec a tool. Convenience wrapper over ToolRunner to exec with args in one call.
1285
- * Output will be streamed to the live console.
1286
- * Returns promise with return code
1287
- *
1288
- * @deprecated Use the {@link execAsync} method that returns a native Javascript Promise instead
1289
- * @param tool path to tool to exec
1290
- * @param args an arg string or array of args
1291
- * @param options optional exec options. See IExecOptions
1292
- * @returns number
1293
- */
1294
1267
  function exec(tool, args, options) {
1295
1268
  var tr = this.tool(tool);
1296
1269
  tr.on('debug', function (data) {
package/toolrunner.d.ts CHANGED
@@ -94,7 +94,6 @@ export declare class ToolRunner extends events.EventEmitter {
94
94
  private _cloneExecOptions;
95
95
  private _getSpawnOptions;
96
96
  private _getSpawnSyncOptions;
97
- private execWithPipingAsync;
98
97
  private execWithPiping;
99
98
  /**
100
99
  * Add argument
@@ -140,17 +139,6 @@ export declare class ToolRunner extends events.EventEmitter {
140
139
  * @param options optional exec options. See IExecOptions
141
140
  * @returns number
142
141
  */
143
- execAsync(options?: IExecOptions): Promise<number>;
144
- /**
145
- * Exec a tool.
146
- * Output will be streamed to the live console.
147
- * Returns promise with return code
148
- *
149
- * @deprecated Use the `execAsync` method that returns a native Javascript promise instead
150
- * @param tool path to tool to exec
151
- * @param options optional exec options. See IExecOptions
152
- * @returns number
153
- */
154
142
  exec(options?: IExecOptions): Q.Promise<number>;
155
143
  /**
156
144
  * Exec a tool synchronously.
package/toolrunner.js CHANGED
@@ -516,184 +516,6 @@ var ToolRunner = /** @class */ (function (_super) {
516
516
  result['windowsVerbatimArguments'] = options.windowsVerbatimArguments || this._isCmdFile();
517
517
  return result;
518
518
  };
519
- ToolRunner.prototype.execWithPipingAsync = function (pipeOutputToTool, options) {
520
- var _this = this;
521
- this._debug('exec tool: ' + this.toolPath);
522
- this._debug('arguments:');
523
- this.args.forEach(function (arg) {
524
- _this._debug(' ' + arg);
525
- });
526
- var success = true;
527
- var optionsNonNull = this._cloneExecOptions(options);
528
- if (!optionsNonNull.silent) {
529
- optionsNonNull.outStream.write(this._getCommandString(optionsNonNull) + os.EOL);
530
- }
531
- var cp;
532
- var toolPath = pipeOutputToTool.toolPath;
533
- var toolPathFirst;
534
- var successFirst = true;
535
- var returnCodeFirst;
536
- var fileStream;
537
- var waitingEvents = 0; // number of process or stream events we are waiting on to complete
538
- var returnCode = 0;
539
- var error;
540
- toolPathFirst = this.toolPath;
541
- // Following node documentation example from this link on how to pipe output of one process to another
542
- // https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
543
- //start the child process for both tools
544
- waitingEvents++;
545
- var cpFirst = child.spawn(this._getSpawnFileName(optionsNonNull), this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(optionsNonNull));
546
- waitingEvents++;
547
- cp = child.spawn(pipeOutputToTool._getSpawnFileName(optionsNonNull), pipeOutputToTool._getSpawnArgs(optionsNonNull), pipeOutputToTool._getSpawnOptions(optionsNonNull));
548
- fileStream = this.pipeOutputToFile ? fs.createWriteStream(this.pipeOutputToFile) : null;
549
- return new Promise(function (resolve, reject) {
550
- var _a, _b, _c, _d;
551
- if (fileStream) {
552
- waitingEvents++;
553
- fileStream.on('finish', function () {
554
- waitingEvents--; //file write is complete
555
- fileStream = null;
556
- if (waitingEvents == 0) {
557
- if (error) {
558
- reject(error);
559
- }
560
- else {
561
- resolve(returnCode);
562
- }
563
- }
564
- });
565
- fileStream.on('error', function (err) {
566
- 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);
568
- fileStream = null;
569
- if (waitingEvents == 0) {
570
- if (error) {
571
- reject(error);
572
- }
573
- else {
574
- resolve(returnCode);
575
- }
576
- }
577
- });
578
- }
579
- //pipe stdout of first tool to stdin of second tool
580
- (_a = cpFirst.stdout) === null || _a === void 0 ? void 0 : _a.on('data', function (data) {
581
- var _a;
582
- try {
583
- if (fileStream) {
584
- fileStream.write(data);
585
- }
586
- (_a = cp.stdin) === null || _a === void 0 ? void 0 : _a.write(data);
587
- }
588
- catch (err) {
589
- _this._debug('Failed to pipe output of ' + toolPathFirst + ' to ' + toolPath);
590
- _this._debug(toolPath + ' might have exited due to errors prematurely. Verify the arguments passed are valid.');
591
- }
592
- });
593
- (_b = cpFirst.stderr) === null || _b === void 0 ? void 0 : _b.on('data', function (data) {
594
- if (fileStream) {
595
- fileStream.write(data);
596
- }
597
- successFirst = !optionsNonNull.failOnStdErr;
598
- if (!optionsNonNull.silent) {
599
- var s = optionsNonNull.failOnStdErr ? optionsNonNull.errStream : optionsNonNull.outStream;
600
- s.write(data);
601
- }
602
- });
603
- cpFirst.on('error', function (err) {
604
- var _a;
605
- waitingEvents--; //first process is complete with errors
606
- if (fileStream) {
607
- fileStream.end();
608
- }
609
- (_a = cp.stdin) === null || _a === void 0 ? void 0 : _a.end();
610
- error = new Error(toolPathFirst + ' failed. ' + err.message);
611
- if (waitingEvents == 0) {
612
- reject(error);
613
- }
614
- });
615
- cpFirst.on('close', function (code, signal) {
616
- var _a;
617
- waitingEvents--; //first process is complete
618
- if (code != 0 && !optionsNonNull.ignoreReturnCode) {
619
- successFirst = false;
620
- returnCodeFirst = code;
621
- returnCode = returnCodeFirst;
622
- }
623
- _this._debug('success of first tool:' + successFirst);
624
- if (fileStream) {
625
- fileStream.end();
626
- }
627
- (_a = cp.stdin) === null || _a === void 0 ? void 0 : _a.end();
628
- if (waitingEvents == 0) {
629
- if (error) {
630
- reject(error);
631
- }
632
- else {
633
- resolve(returnCode);
634
- }
635
- }
636
- });
637
- var stdbuffer = '';
638
- (_c = cp.stdout) === null || _c === void 0 ? void 0 : _c.on('data', function (data) {
639
- _this.emit('stdout', data);
640
- if (!optionsNonNull.silent) {
641
- optionsNonNull.outStream.write(data);
642
- }
643
- _this._processLineBuffer(data, stdbuffer, function (line) {
644
- _this.emit('stdline', line);
645
- });
646
- });
647
- var errbuffer = '';
648
- (_d = cp.stderr) === null || _d === void 0 ? void 0 : _d.on('data', function (data) {
649
- _this.emit('stderr', data);
650
- success = !optionsNonNull.failOnStdErr;
651
- if (!optionsNonNull.silent) {
652
- var s = optionsNonNull.failOnStdErr ? optionsNonNull.errStream : optionsNonNull.outStream;
653
- s.write(data);
654
- }
655
- _this._processLineBuffer(data, errbuffer, function (line) {
656
- _this.emit('errline', line);
657
- });
658
- });
659
- cp.on('error', function (err) {
660
- waitingEvents--; //process is done with errors
661
- error = new Error(toolPath + ' failed. ' + err.message);
662
- if (waitingEvents == 0) {
663
- reject(error);
664
- }
665
- });
666
- cp.on('close', function (code, signal) {
667
- waitingEvents--; //process is complete
668
- _this._debug('rc:' + code);
669
- returnCode = code;
670
- if (stdbuffer.length > 0) {
671
- _this.emit('stdline', stdbuffer);
672
- }
673
- if (errbuffer.length > 0) {
674
- _this.emit('errline', errbuffer);
675
- }
676
- if (code != 0 && !optionsNonNull.ignoreReturnCode) {
677
- success = false;
678
- }
679
- _this._debug('success:' + success);
680
- if (!successFirst) { //in the case output is piped to another tool, check exit code of both tools
681
- error = new Error(toolPathFirst + ' failed with return code: ' + returnCodeFirst);
682
- }
683
- else if (!success) {
684
- error = new Error(toolPath + ' failed with return code: ' + code);
685
- }
686
- if (waitingEvents == 0) {
687
- if (error) {
688
- reject(error);
689
- }
690
- else {
691
- resolve(returnCode);
692
- }
693
- }
694
- });
695
- });
696
- };
697
519
  ToolRunner.prototype.execWithPiping = function (pipeOutputToTool, options) {
698
520
  var _this = this;
699
521
  var _a, _b, _c, _d;
@@ -945,104 +767,6 @@ var ToolRunner = /** @class */ (function (_super) {
945
767
  * @param options optional exec options. See IExecOptions
946
768
  * @returns number
947
769
  */
948
- ToolRunner.prototype.execAsync = function (options) {
949
- var _this = this;
950
- var _a, _b, _c;
951
- if (this.pipeOutputToTool) {
952
- return this.execWithPipingAsync(this.pipeOutputToTool, options);
953
- }
954
- this._debug('exec tool: ' + this.toolPath);
955
- this._debug('arguments:');
956
- this.args.forEach(function (arg) {
957
- _this._debug(' ' + arg);
958
- });
959
- var optionsNonNull = this._cloneExecOptions(options);
960
- if (!optionsNonNull.silent) {
961
- optionsNonNull.outStream.write(this._getCommandString(optionsNonNull) + os.EOL);
962
- }
963
- var state = new ExecState(optionsNonNull, this.toolPath);
964
- state.on('debug', function (message) {
965
- _this._debug(message);
966
- });
967
- var cp = child.spawn(this._getSpawnFileName(options), this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(options));
968
- this.childProcess = cp;
969
- // it is possible for the child process to end its last line without a new line.
970
- // because stdout is buffered, this causes the last line to not get sent to the parent
971
- // stream. Adding this event forces a flush before the child streams are closed.
972
- (_a = cp.stdout) === null || _a === void 0 ? void 0 : _a.on('finish', function () {
973
- if (!optionsNonNull.silent) {
974
- optionsNonNull.outStream.write(os.EOL);
975
- }
976
- });
977
- var stdbuffer = '';
978
- (_b = cp.stdout) === null || _b === void 0 ? void 0 : _b.on('data', function (data) {
979
- _this.emit('stdout', data);
980
- if (!optionsNonNull.silent) {
981
- optionsNonNull.outStream.write(data);
982
- }
983
- _this._processLineBuffer(data, stdbuffer, function (line) {
984
- _this.emit('stdline', line);
985
- });
986
- });
987
- var errbuffer = '';
988
- (_c = cp.stderr) === null || _c === void 0 ? void 0 : _c.on('data', function (data) {
989
- state.processStderr = true;
990
- _this.emit('stderr', data);
991
- if (!optionsNonNull.silent) {
992
- var s = optionsNonNull.failOnStdErr ? optionsNonNull.errStream : optionsNonNull.outStream;
993
- s.write(data);
994
- }
995
- _this._processLineBuffer(data, errbuffer, function (line) {
996
- _this.emit('errline', line);
997
- });
998
- });
999
- cp.on('error', function (err) {
1000
- state.processError = err.message;
1001
- state.processExited = true;
1002
- state.processClosed = true;
1003
- state.CheckComplete();
1004
- });
1005
- cp.on('exit', function (code, signal) {
1006
- state.processExitCode = code;
1007
- state.processExited = true;
1008
- _this._debug("Exit code " + code + " received from tool '" + _this.toolPath + "'");
1009
- state.CheckComplete();
1010
- });
1011
- cp.on('close', function (code, signal) {
1012
- state.processExitCode = code;
1013
- state.processExited = true;
1014
- state.processClosed = true;
1015
- _this._debug("STDIO streams have closed for tool '" + _this.toolPath + "'");
1016
- state.CheckComplete();
1017
- });
1018
- return new Promise(function (resolve, reject) {
1019
- state.on('done', function (error, exitCode) {
1020
- if (stdbuffer.length > 0) {
1021
- _this.emit('stdline', stdbuffer);
1022
- }
1023
- if (errbuffer.length > 0) {
1024
- _this.emit('errline', errbuffer);
1025
- }
1026
- cp.removeAllListeners();
1027
- if (error) {
1028
- reject(error);
1029
- }
1030
- else {
1031
- resolve(exitCode);
1032
- }
1033
- });
1034
- });
1035
- };
1036
- /**
1037
- * Exec a tool.
1038
- * Output will be streamed to the live console.
1039
- * Returns promise with return code
1040
- *
1041
- * @deprecated Use the `execAsync` method that returns a native Javascript promise instead
1042
- * @param tool path to tool to exec
1043
- * @param options optional exec options. See IExecOptions
1044
- * @returns number
1045
- */
1046
770
  ToolRunner.prototype.exec = function (options) {
1047
771
  var _this = this;
1048
772
  var _a, _b, _c;