azure-pipelines-task-lib 4.12.0 → 4.13.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.
package/mock-test.d.ts CHANGED
@@ -10,7 +10,7 @@ export declare class MockTestRunner {
10
10
  succeeded: boolean;
11
11
  errorIssues: string[];
12
12
  warningIssues: string[];
13
- LoadAsync(testPath: string, taskJsonPath?: string): Promise<MockTestRunner>;
13
+ LoadAsync(testPath?: string, taskJsonPath?: string): Promise<MockTestRunner>;
14
14
  get failed(): boolean;
15
15
  ran(cmdline: string): boolean;
16
16
  createdErrorIssue(message: string): boolean;
@@ -18,12 +18,7 @@ export declare class MockTestRunner {
18
18
  stdOutContained(message: string): boolean;
19
19
  stdErrContained(message: string): boolean;
20
20
  runAsync(nodeVersion?: number): Promise<void>;
21
- /**
22
- * @deprecated This method uses library which is not prefered to use on production
23
- */
24
- run(nodeVersion?: number): void;
25
21
  private getNodePath;
26
- private getNodePathSync;
27
22
  private getNodeVersion;
28
23
  private getTaskJsonPath;
29
24
  private downloadNode;
package/mock-test.js CHANGED
@@ -39,12 +39,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.MockTestRunner = void 0;
40
40
  var cp = require("child_process");
41
41
  var fs = require("fs");
42
- var ncp = require("child_process");
43
42
  var os = require("os");
44
43
  var path = require("path");
45
44
  var cmdm = require("./taskcommand");
46
45
  var shelljs = require("shelljs");
47
- var deasync = require("deasync");
48
46
  var Downloader = require("nodejs-file-downloader");
49
47
  var COMMAND_TAG = '[command]';
50
48
  var COMMAND_LENGTH = COMMAND_TAG.length;
@@ -65,7 +63,6 @@ var MockTestRunner = /** @class */ (function () {
65
63
  return;
66
64
  this._taskJsonPath = taskJsonPath || '';
67
65
  this._testPath = testPath;
68
- this.nodePath = this.getNodePathSync();
69
66
  }
70
67
  MockTestRunner.prototype.LoadAsync = function (testPath, taskJsonPath) {
71
68
  return __awaiter(this, void 0, void 0, function () {
@@ -80,8 +77,12 @@ var MockTestRunner = /** @class */ (function () {
80
77
  resolve(this);
81
78
  return [2 /*return*/];
82
79
  }
83
- this._taskJsonPath = taskJsonPath || '';
84
- this._testPath = testPath;
80
+ if (testPath) {
81
+ this._testPath = testPath;
82
+ }
83
+ if (taskJsonPath) {
84
+ this._taskJsonPath = taskJsonPath;
85
+ }
85
86
  _a = this;
86
87
  return [4 /*yield*/, this.getNodePath()];
87
88
  case 1:
@@ -133,8 +134,15 @@ var MockTestRunner = /** @class */ (function () {
133
134
  return [4 /*yield*/, this.getNodePath(nodeVersion)];
134
135
  case 1:
135
136
  nodePath = _a.sent();
136
- _a.label = 2;
137
+ return [3 /*break*/, 4];
137
138
  case 2:
139
+ if (!!nodePath) return [3 /*break*/, 4];
140
+ return [4 /*yield*/, this.getNodePath()];
141
+ case 3:
142
+ nodePath = _a.sent();
143
+ this.nodePath = nodePath;
144
+ _a.label = 4;
145
+ case 4:
138
146
  spawn = cp.spawnSync(nodePath, [this._testPath]);
139
147
  // Clean environment
140
148
  Object.keys(process.env)
@@ -199,34 +207,23 @@ var MockTestRunner = /** @class */ (function () {
199
207
  });
200
208
  });
201
209
  };
202
- /**
203
- * @deprecated This method uses library which is not prefered to use on production
204
- */
205
- MockTestRunner.prototype.run = function (nodeVersion) {
206
- var completeExecution = false;
207
- this.runAsync(nodeVersion).then(function (t) { return completeExecution = true; });
208
- deasync.loopWhile(function () { return !completeExecution; });
209
- };
210
210
  // Returns a path to node.exe with the correct version for this task (based on if its node10 or node)
211
211
  MockTestRunner.prototype.getNodePath = function (nodeVersion) {
212
212
  return __awaiter(this, void 0, void 0, function () {
213
- var version, downloadVersion, downloadDestination, pathToExe, result;
213
+ var version, versions, downloadVersion, downloadDestination, pathToExe, result;
214
214
  return __generator(this, function (_a) {
215
215
  switch (_a.label) {
216
216
  case 0:
217
217
  version = nodeVersion || this.getNodeVersion();
218
- switch (version) {
219
- case 6:
220
- downloadVersion = 'v6.17.1';
221
- break;
222
- case 10:
223
- downloadVersion = 'v10.21.0';
224
- break;
225
- case 16:
226
- downloadVersion = 'v16.13.0';
227
- break;
228
- default:
229
- throw new Error('Invalid node version, must be 6, 10, or 16 (received ' + version + ')');
218
+ versions = {
219
+ 20: 'v20.13.1',
220
+ 16: 'v16.20.2',
221
+ 10: 'v10.24.1',
222
+ 6: 'v6.17.1',
223
+ };
224
+ downloadVersion = versions[version];
225
+ if (!downloadVersion) {
226
+ throw new Error('Invalid node version, must be 6, 10, 16 or 20 (received ' + version + ')');
230
227
  }
231
228
  downloadDestination = path.join(downloadDirectory, 'node' + version);
232
229
  pathToExe = this.getPathToNodeExe(downloadVersion, downloadDestination);
@@ -240,12 +237,6 @@ var MockTestRunner = /** @class */ (function () {
240
237
  });
241
238
  });
242
239
  };
243
- MockTestRunner.prototype.getNodePathSync = function (nodeVersion) {
244
- var nodePath = '';
245
- this.getNodePath(nodeVersion).then(function (t) { return nodePath = t; });
246
- deasync.loopWhile(function () { return nodePath == ''; });
247
- return nodePath;
248
- };
249
240
  // Determines the correct version of node to use based on the contents of the task's task.json. Defaults to Node 16.
250
241
  MockTestRunner.prototype.getNodeVersion = function () {
251
242
  var taskJsonPath = this.getTaskJsonPath();
@@ -255,29 +246,27 @@ var MockTestRunner = /** @class */ (function () {
255
246
  }
256
247
  var taskJsonContents = fs.readFileSync(taskJsonPath, { encoding: 'utf-8' });
257
248
  var taskJson = JSON.parse(taskJsonContents);
258
- var nodeVersionFound = false;
259
- var execution = (taskJson['execution']
260
- || taskJson['prejobexecution']
261
- || taskJson['postjobexecution']);
262
- var keys = Object.keys(execution);
263
- for (var i = 0; i < keys.length; i++) {
264
- if (keys[i].toLowerCase() == 'node16') {
265
- // Prefer node 16 and return immediately.
266
- return 16;
267
- }
268
- else if (keys[i].toLowerCase() == 'node10') {
269
- // Prefer node 10 and return immediately.
270
- return 10;
271
- }
272
- else if (keys[i].toLowerCase() == 'node') {
273
- nodeVersionFound = true;
249
+ var nodeVersion = 0;
250
+ var executors = ['execution', 'prejobexecution', 'postjobexecution'];
251
+ for (var _i = 0, executors_1 = executors; _i < executors_1.length; _i++) {
252
+ var executor = executors_1[_i];
253
+ if (!taskJson[executor])
254
+ continue;
255
+ for (var _a = 0, _b = Object.keys(taskJson[executor]); _a < _b.length; _a++) {
256
+ var key = _b[_a];
257
+ var currExecutor = key.toLocaleLowerCase();
258
+ if (!currExecutor.startsWith('node'))
259
+ continue;
260
+ var version = currExecutor.replace('node', '');
261
+ var intVersion = parseInt(version) || 6; // node handler is node v6 by default
262
+ nodeVersion = Math.max(intVersion, nodeVersion);
274
263
  }
275
264
  }
276
- if (!nodeVersionFound) {
265
+ if (nodeVersion === 0) {
277
266
  console.warn('Unable to determine execution type from task.json, defaulting to use Node 16');
278
267
  return 16;
279
268
  }
280
- return 6;
269
+ return nodeVersion;
281
270
  };
282
271
  // Returns the path to the task.json for the task being tested. Returns null if unable to find it.
283
272
  // Searches by moving up the directory structure from the initial starting point and checking at each level.
@@ -389,7 +378,7 @@ var MockTestRunner = /** @class */ (function () {
389
378
  originalCwd = process.cwd();
390
379
  process.chdir(downloadDestination);
391
380
  try {
392
- ncp.execSync("tar -xzf \"" + path.join(downloadDestination, tarGzName) + "\"");
381
+ cp.execSync("tar -xzf \"" + path.join(downloadDestination, tarGzName) + "\"");
393
382
  }
394
383
  catch (_b) {
395
384
  throw new Error('Failed to unzip node tar.gz from ' + url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azure-pipelines-task-lib",
3
- "version": "4.12.0",
3
+ "version": "4.13.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
  "adm-zip": "^0.5.10",
31
- "deasync": "^0.1.28",
32
31
  "minimatch": "3.0.5",
33
32
  "nodejs-file-downloader": "^4.11.1",
34
33
  "q": "^1.5.1",