azure-pipelines-task-lib 5.0.0-preview.0 → 5.0.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.
@@ -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 __());
@@ -130,6 +132,99 @@ var ToolRunner = /** @class */ (function (_super) {
130
132
  // Exec - use for long running tools where you need to stream live output as it runs
131
133
  // returns a promise with return code.
132
134
  //
135
+ ToolRunner.prototype.execAsync = function (options) {
136
+ var _this = this;
137
+ this._debug('exec tool: ' + this.toolPath);
138
+ this._debug('Arguments:');
139
+ this.args.forEach(function (arg) {
140
+ _this._debug(' ' + arg);
141
+ });
142
+ var success = true;
143
+ options = options || {};
144
+ var ops = {
145
+ cwd: options.cwd || process.cwd(),
146
+ env: options.env || process.env,
147
+ silent: options.silent || false,
148
+ outStream: options.outStream || process.stdout,
149
+ errStream: options.errStream || process.stderr,
150
+ failOnStdErr: options.failOnStdErr || false,
151
+ ignoreReturnCode: options.ignoreReturnCode || false,
152
+ windowsVerbatimArguments: options.windowsVerbatimArguments
153
+ };
154
+ var argString = this.args.join(' ') || '';
155
+ var cmdString = this.toolPath;
156
+ if (argString) {
157
+ cmdString += (' ' + argString);
158
+ }
159
+ // Using split/join to replace the temp path
160
+ cmdString = this.ignoreTempPath(cmdString);
161
+ if (!ops.silent) {
162
+ if (this.pipeOutputToTool) {
163
+ var pipeToolArgString = this.pipeOutputToTool.args.join(' ') || '';
164
+ var pipeToolCmdString = this.ignoreTempPath(this.pipeOutputToTool.toolPath);
165
+ if (pipeToolArgString) {
166
+ pipeToolCmdString += (' ' + pipeToolArgString);
167
+ }
168
+ cmdString += ' | ' + pipeToolCmdString;
169
+ }
170
+ ops.outStream.write('[command]' + cmdString + os.EOL);
171
+ }
172
+ // TODO: filter process.env
173
+ var res = mock.getResponse('exec', cmdString, debug);
174
+ if (res.stdout) {
175
+ this.emit('stdout', res.stdout);
176
+ if (!ops.silent) {
177
+ ops.outStream.write(res.stdout + os.EOL);
178
+ }
179
+ var stdLineArray = res.stdout.split(os.EOL);
180
+ for (var _i = 0, _a = stdLineArray.slice(0, -1); _i < _a.length; _i++) {
181
+ var line = _a[_i];
182
+ this.emit('stdline', line);
183
+ }
184
+ if (stdLineArray.length > 0 && stdLineArray[stdLineArray.length - 1].length > 0) {
185
+ this.emit('stdline', stdLineArray[stdLineArray.length - 1]);
186
+ }
187
+ }
188
+ if (res.stderr) {
189
+ this.emit('stderr', res.stderr);
190
+ success = !ops.failOnStdErr;
191
+ if (!ops.silent) {
192
+ var s = ops.failOnStdErr ? ops.errStream : ops.outStream;
193
+ s.write(res.stderr + os.EOL);
194
+ }
195
+ var stdErrArray = res.stderr.split(os.EOL);
196
+ for (var _b = 0, _c = stdErrArray.slice(0, -1); _b < _c.length; _b++) {
197
+ var line = _c[_b];
198
+ this.emit('errline', line);
199
+ }
200
+ if (stdErrArray.length > 0 && stdErrArray[stdErrArray.length - 1].length > 0) {
201
+ this.emit('errline', stdErrArray[stdErrArray.length - 1]);
202
+ }
203
+ }
204
+ var code = res.code;
205
+ if (!ops.silent) {
206
+ ops.outStream.write('rc:' + res.code + os.EOL);
207
+ }
208
+ if (code != 0 && !ops.ignoreReturnCode) {
209
+ success = false;
210
+ }
211
+ if (!ops.silent) {
212
+ ops.outStream.write('success:' + success + os.EOL);
213
+ }
214
+ return new Promise(function (resolve, reject) {
215
+ if (success) {
216
+ resolve(code);
217
+ }
218
+ else {
219
+ reject(new Error(_this.toolPath + ' failed with return code: ' + code));
220
+ }
221
+ });
222
+ };
223
+ /**
224
+ * Exec - use for long running tools where you need to stream live output as it runs
225
+ * @deprecated use `execAsync` instead
226
+ * @returns a promise with return code.
227
+ */
133
228
  ToolRunner.prototype.exec = function (options) {
134
229
  var _this = this;
135
230
  var defer = Q.defer();
@@ -224,7 +319,6 @@ var ToolRunner = /** @class */ (function (_super) {
224
319
  //
225
320
  ToolRunner.prototype.execSync = function (options) {
226
321
  var _this = this;
227
- var defer = Q.defer();
228
322
  this._debug('exec tool: ' + this.toolPath);
229
323
  this._debug('Arguments:');
230
324
  this.args.forEach(function (arg) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azure-pipelines-task-lib",
3
- "version": "5.0.0-preview.0",
3
+ "version": "5.0.0",
4
4
  "description": "Azure Pipelines Task SDK",
5
5
  "main": "./task.js",
6
6
  "typings": "./task.d.ts",
@@ -27,11 +27,12 @@
27
27
  },
28
28
  "homepage": "https://github.com/Microsoft/azure-pipelines-task-lib",
29
29
  "dependencies": {
30
+ "adm-zip": "^0.5.10",
30
31
  "minimatch": "3.0.5",
32
+ "nodejs-file-downloader": "^4.11.1",
31
33
  "q": "^1.5.1",
32
- "semver": "^5.1.0",
34
+ "semver": "^5.7.2",
33
35
  "shelljs": "^0.8.5",
34
- "sync-request": "6.1.0",
35
36
  "uuid": "^3.0.1"
36
37
  },
37
38
  "devDependencies": {
package/task.d.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import Q = require('q');
3
4
  import fs = require('fs');
4
5
  import im = require('./internal');
5
6
  import trm = require('./toolrunner');
7
+ type OptionCases<T extends string> = `-${Uppercase<T> | Lowercase<T>}`;
8
+ type OptionsPermutations<T extends string, U extends string = ''> = T extends `${infer First}${infer Rest}` ? OptionCases<`${U}${First}`> | OptionCases<`${First}${U}`> | OptionsPermutations<Rest, `${U}${First}`> | OptionCases<First> : OptionCases<U> | '';
6
9
  export declare enum TaskResult {
7
10
  Succeeded = 0,
8
11
  SucceededWithIssues = 1,
@@ -32,6 +35,7 @@ export declare enum FieldType {
32
35
  DataParameter = 1,
33
36
  Url = 2
34
37
  }
38
+ export declare const IssueSource: typeof im.IssueSource;
35
39
  /** Platforms supported by our build agent */
36
40
  export declare enum Platform {
37
41
  Windows = 0,
@@ -60,6 +64,18 @@ export declare const setErrStream: typeof im._setErrStream;
60
64
  */
61
65
  export declare function setResult(result: TaskResult.Succeeded, message?: string, done?: boolean): void;
62
66
  export declare function setResult(result: Exclude<TaskResult, 'Succeeded'>, message: string, done?: boolean): void;
67
+ /**
68
+ * Sets the result of the task with sanitized message.
69
+ *
70
+ * @param result TaskResult enum of Succeeded, SucceededWithIssues, Failed, Cancelled or Skipped.
71
+ * @param message A message which will be logged as an error issue if the result is Failed. Message will be truncated
72
+ * before first occurence of wellknown sensitive keyword.
73
+ * @param done Optional. Instructs the agent the task is done. This is helpful when child processes
74
+ * may still be running and prevent node from fully exiting. This argument is supported
75
+ * from agent version 2.142.0 or higher (otherwise will no-op).
76
+ * @returns void
77
+ */
78
+ export declare function setSanitizedResult(result: TaskResult, message: string, done?: boolean): void;
63
79
  export declare const setResourcePath: typeof im._setResourcePath;
64
80
  export declare const loc: typeof im._loc;
65
81
  export declare const getVariable: typeof im._getVariable;
@@ -134,12 +150,20 @@ export declare function getInputRequired(name: string): string;
134
150
  export declare function getBoolInput(name: string, required?: boolean): boolean;
135
151
  /**
136
152
  * Gets the value of an feature flag and converts to a bool.
137
- *
153
+ * @IMPORTANT This method is only for internal Microsoft development. Do not use it for external tasks.
138
154
  * @param name name of the feature flag to get.
139
155
  * @param defaultValue default value of the feature flag in case it's not found in env. (optional. Default value = false)
140
156
  * @returns boolean
157
+ * @deprecated Don't use this for new development. Use getPipelineFeature instead.
141
158
  */
142
159
  export declare function getBoolFeatureFlag(ffName: string, defaultValue?: boolean): boolean;
160
+ /**
161
+ * Gets the value of an task feature and converts to a bool.
162
+ * @IMPORTANT This method is only for internal Microsoft development. Do not use it for external tasks.
163
+ * @param name name of the feature to get.
164
+ * @returns boolean
165
+ */
166
+ export declare function getPipelineFeature(featureName: string): boolean;
143
167
  /**
144
168
  * Gets the value of an input and splits the value using a delimiter (space, comma, etc).
145
169
  * Empty values are removed. This function is useful for splitting an input containing a simple
@@ -298,8 +322,6 @@ export declare const command: typeof im._command;
298
322
  export declare const warning: typeof im._warning;
299
323
  export declare const error: typeof im._error;
300
324
  export declare const debug: typeof im._debug;
301
- export interface FsStats extends fs.Stats {
302
- }
303
325
  /**
304
326
  * Get's stat on a path.
305
327
  * Useful for checking whether a file or directory. Also getting created, modified and accessed time.
@@ -308,7 +330,7 @@ export interface FsStats extends fs.Stats {
308
330
  * @param path path to check
309
331
  * @returns fsStat
310
332
  */
311
- export declare function stats(path: string): FsStats;
333
+ export declare function stats(path: string): fs.Stats;
312
334
  export declare const exist: typeof im._exist;
313
335
  export declare function writeFile(file: string, data: string | Buffer, options?: BufferEncoding | fs.WriteFileOptions): void;
314
336
  /**
@@ -325,6 +347,11 @@ export declare function osType(): string;
325
347
  * @throws {Error} Platform is not supported by our agent
326
348
  */
327
349
  export declare function getPlatform(): Platform;
350
+ /**
351
+ * Resolves major version of Node.js engine used by the agent.
352
+ * @returns {Number} Node's major version.
353
+ */
354
+ export declare function getNodeMajorVersion(): Number;
328
355
  /**
329
356
  * Return hosted type of Agent
330
357
  * @returns {AgentHostedMode}
@@ -341,29 +368,30 @@ export declare const checkPath: typeof im._checkPath;
341
368
  /**
342
369
  * Change working directory.
343
370
  *
344
- * @param path new working directory path
345
- * @returns void
371
+ * @param {string} path - New working directory path
372
+ * @returns {void}
346
373
  */
347
374
  export declare function cd(path: string): void;
348
375
  /**
349
376
  * Change working directory and push it on the stack
350
377
  *
351
- * @param path new working directory path
352
- * @returns void
378
+ * @param {string} dir - New working directory path
379
+ * @returns {void}
353
380
  */
354
- export declare function pushd(path: string): void;
381
+ export declare function pushd(dir?: string): string[];
355
382
  /**
356
383
  * Change working directory back to previously pushed directory
357
384
  *
358
- * @returns void
385
+ * @param {string} index - Index to remove from the stack
386
+ * @returns {void}
359
387
  */
360
- export declare function popd(): void;
388
+ export declare function popd(index?: string): string[];
361
389
  /**
362
- * Make a directory. Creates the full path with folders in between
390
+ * Make a directory. Creates the full path with folders in between
363
391
  * Will throw if it fails
364
392
  *
365
- * @param p path to create
366
- * @returns void
393
+ * @param {string} p - Path to create
394
+ * @returns {void}
367
395
  */
368
396
  export declare function mkdirP(p: string): void;
369
397
  /**
@@ -375,32 +403,78 @@ export declare function mkdirP(p: string): void;
375
403
  */
376
404
  export declare function resolve(...pathSegments: any[]): string;
377
405
  export declare const which: typeof im._which;
406
+ type ListOptionsVariants = OptionsPermutations<'ra'>;
407
+ /**
408
+ * Returns array of files in the given path, or in current directory if no path provided.
409
+ * @param {ListOptionsVariants} options - Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..)
410
+ * @param {...string[]} paths - Paths to search.
411
+ * @return {string[]} - An array of files in the given path(s).
412
+ */
413
+ export declare function ls(options: ListOptionsVariants, ...paths: string[]): string[];
378
414
  /**
379
- * Returns array of files in the given path, or in current directory if no path provided. See shelljs.ls
380
- * @param {string} options Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..)
381
- * @param {string[]} paths Paths to search.
382
- * @return {string[]} An array of files in the given path(s).
415
+ * Returns array of files in the given path, or in current directory if no path provided.
416
+ * @param {ListOptionsVariants} options - Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..)
417
+ * @param {string[]} paths - Paths to search.
418
+ * @return {string[]} - An array of files in the given path(s).
383
419
  */
384
- export declare function ls(options: string, paths: string[]): string[];
420
+ export declare function ls(options: ListOptionsVariants, paths: string[]): string[];
421
+ /**
422
+ * Returns array of files in the given path, or in current directory if no path provided.
423
+ * @param {ListOptionsVariants} options - Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..)
424
+ * @param {string} paths - Paths to search.
425
+ * @return {string[]} - An array of files in the given path(s).
426
+ */
427
+ export declare function ls(options: ListOptionsVariants, paths: string): string[];
428
+ /**
429
+ * Returns array of files in the given path, or in current directory if no path provided.
430
+ * @param {string} path - Paths to search.
431
+ * @return {string[]} - An array of files in the given path(s).
432
+ */
433
+ export declare function ls(path: string): string[];
434
+ /**
435
+ * Returns array of files in the given path, or in current directory if no path provided.
436
+ * @param {string[]} paths - Paths to search.
437
+ * @return {string[]} - An array of files in the given path(s).
438
+ */
439
+ export declare function ls(paths: string[]): string[];
440
+ /**
441
+ * Returns array of files in the given path, or in current directory if no path provided.
442
+ * @param {...string[]} paths - Paths to search.
443
+ * @return {string[]} - An array of files in the given path(s).
444
+ */
445
+ export declare function ls(...paths: string[]): string[];
446
+ type CopyOptionsVariants = OptionsPermutations<'frn'>;
385
447
  /**
386
448
  * Copies a file or folder.
387
- *
388
- * @param source source path
389
- * @param dest destination path
390
- * @param options string -r, -f or -rf for recursive and force
391
- * @param continueOnError optional. whether to continue on error
392
- * @param retryCount optional. Retry count to copy the file. It might help to resolve intermittent issues e.g. with UNC target paths on a remote host.
449
+ * @param {string} source - Source path.
450
+ * @param {string} destination - Destination path.
451
+ * @param {string} [options] - Options string '-r', '-f' , '-n' or '-rfn' for recursive, force and no-clobber.
452
+ * @param {boolean} [continueOnError=false] - Optional. Whether to continue on error.
453
+ * @param {number} [retryCount=0] - Optional. Retry count to copy the file. It might help to resolve intermittent issues e.g. with UNC target paths on a remote host.
454
+ * @returns {void}
455
+ */
456
+ export declare function cp(source: string, destination: string, options?: CopyOptionsVariants, continueOnError?: boolean, retryCount?: number): void;
457
+ /**
458
+ * Copies a file or folder.
459
+ * @param {string} options - Options string '-r', '-f' , '-n' or '-rfn' for recursive, force and no-clobber.
460
+ * @param {string} source - Source path.
461
+ * @param {string} [destination] - Destination path.
462
+ * @param {boolean} [continueOnError=false] - Optional. Whether to continue on error.
463
+ * @param {number} [retryCount=0] - Optional. Retry count to copy the file. It might help to resolve intermittent issues e.g. with UNC target paths on a remote host.
464
+ * @returns {void}
393
465
  */
394
- export declare function cp(source: string, dest: string, options?: string, continueOnError?: boolean, retryCount?: number): void;
466
+ export declare function cp(options: CopyOptionsVariants, source: string, destination: string, continueOnError?: boolean, retryCount?: number): void;
467
+ type MoveOptionsVariants = OptionsPermutations<'fn'>;
395
468
  /**
396
469
  * Moves a path.
397
470
  *
398
- * @param source source path
399
- * @param dest destination path
400
- * @param options string -f or -n for force and no clobber
401
- * @param continueOnError optional. whether to continue on error
471
+ * @param {string} source - Source path.
472
+ * @param {string} dest - Destination path.
473
+ * @param {MoveOptionsVariants} [options] - Option string -f or -n for force and no clobber.
474
+ * @param {boolean} [continueOnError] - Optional. Whether to continue on error.
475
+ * @returns {void}
402
476
  */
403
- export declare function mv(source: string, dest: string, options?: string, continueOnError?: boolean): void;
477
+ export declare function mv(source: string, dest: string, options?: MoveOptionsVariants, continueOnError?: boolean): void;
404
478
  /**
405
479
  * Interface for FindOptions
406
480
  * Contains properties to control whether to follow symlinks
@@ -472,8 +546,9 @@ export declare function legacyFindFiles(rootDirectory: string, pattern: string,
472
546
  /**
473
547
  * Remove a path recursively with force
474
548
  *
475
- * @param inputPath path to remove
476
- * @throws when the file or directory exists but could not be deleted.
549
+ * @param {string} inputPath - Path to remove
550
+ * @return {void}
551
+ * @throws When the file or directory exists but could not be deleted.
477
552
  */
478
553
  export declare function rmRF(inputPath: string): void;
479
554
  /**
@@ -486,6 +561,18 @@ export declare function rmRF(inputPath: string): void;
486
561
  * @param options optional exec options. See IExecOptions
487
562
  * @returns number
488
563
  */
564
+ export declare function execAsync(tool: string, args: any, options?: trm.IExecOptions): Promise<number>;
565
+ /**
566
+ * Exec a tool. Convenience wrapper over ToolRunner to exec with args in one call.
567
+ * Output will be streamed to the live console.
568
+ * Returns promise with return code
569
+ *
570
+ * @deprecated Use the {@link execAsync} method that returns a native Javascript Promise instead
571
+ * @param tool path to tool to exec
572
+ * @param args an arg string or array of args
573
+ * @param options optional exec options. See IExecOptions
574
+ * @returns number
575
+ */
489
576
  export declare function exec(tool: string, args: any, options?: trm.IExecOptions): Q.Promise<number>;
490
577
  /**
491
578
  * Exec a tool synchronously. Convenience wrapper over ToolRunner to execSync with args in one call.
@@ -735,3 +822,4 @@ export declare function addBuildTag(value: string): void;
735
822
  * @returns void
736
823
  */
737
824
  export declare function updateReleaseName(name: string): void;
825
+ export {};