azure-pipelines-task-lib 4.17.3 → 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.
@@ -1,36 +1,39 @@
1
1
  {
2
- "loc.messages.LIB_UnhandledEx": "Unhandled: %s",
2
+ "loc.messages.LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s",
3
+ "loc.messages.LIB_DirectoryStackEmpty": "Directory stack is empty",
4
+ "loc.messages.LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s",
5
+ "loc.messages.LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s",
6
+ "loc.messages.LIB_EndpointNotExist": "Endpoint not present: %s",
3
7
  "loc.messages.LIB_FailOnCode": "Failure return code: %d",
8
+ "loc.messages.LIB_InputRequired": "Input required: %s",
9
+ "loc.messages.LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s",
10
+ "loc.messages.LIB_InvalidPattern": "Invalid pattern: '%s'",
11
+ "loc.messages.LIB_InvalidSecureFilesInput": "Invalid secure file input: %s",
12
+ "loc.messages.LIB_LocStringNotFound": "Can\\'t find loc string for key: %s",
13
+ "loc.messages.LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
4
14
  "loc.messages.LIB_MkdirFailed": "Unable to create directory '%s'. %s",
5
15
  "loc.messages.LIB_MkdirFailedFileExists": "Unable to create directory '%s'. Conflicting file exists: '%s'",
6
16
  "loc.messages.LIB_MkdirFailedInvalidDriveRoot": "Unable to create directory '%s'. Root directory does not exist: '%s'",
7
17
  "loc.messages.LIB_MkdirFailedInvalidShare": "Unable to create directory '%s'. Unable to verify the directory exists: '%s'. If directory is a file share, please verify the share name is correct, the share is online, and the current process has permission to access the share.",
8
18
  "loc.messages.LIB_MultilineSecret": "Secrets cannot contain multiple lines",
19
+ "loc.messages.LIB_NotFoundPreviousDirectory": "Could not find previous directory",
20
+ "loc.messages.LIB_OperationFailed": "Failed %s: %s",
21
+ "loc.messages.LIB_ParameterIsRequired": "%s not supplied",
22
+ "loc.messages.LIB_PathHasNullByte": "Path cannot contain null bytes",
23
+ "loc.messages.LIB_PathIsNotADirectory": "Path is not a directory: %s",
24
+ "loc.messages.LIB_PathNotFound": "Not found %s: %s",
25
+ "loc.messages.LIB_PlatformNotSupported": "Platform not supported: %s",
9
26
  "loc.messages.LIB_ProcessError": "There was an error when attempting to execute the process '%s'. This may indicate the process failed to start. Error: %s",
10
27
  "loc.messages.LIB_ProcessExitCode": "The process '%s' failed with exit code %s",
11
28
  "loc.messages.LIB_ProcessStderr": "The process '%s' failed because one or more lines were written to the STDERR stream",
12
- "loc.messages.LIB_ReturnCode": "Return code: %d",
13
- "loc.messages.LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s",
14
29
  "loc.messages.LIB_ResourceFileAlreadySet": "Resource file has already set to: %s",
30
+ "loc.messages.LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s",
15
31
  "loc.messages.LIB_ResourceFileNotSet": "Resource file haven\\'t set, can\\'t find loc string for key: %s",
32
+ "loc.messages.LIB_ReturnCode": "Return code: %d",
16
33
  "loc.messages.LIB_StdioNotClosed": "The STDIO streams did not close within %s seconds of the exit event from process '%s'. This may indicate a child process inherited the STDIO streams and has not yet exited.",
17
- "loc.messages.LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.",
18
- "loc.messages.LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.",
19
- "loc.messages.LIB_LocStringNotFound": "Can\\'t find loc string for key: %s",
20
- "loc.messages.LIB_ParameterIsRequired": "%s not supplied",
21
- "loc.messages.LIB_InputRequired": "Input required: %s",
22
- "loc.messages.LIB_InvalidPattern": "Invalid pattern: '%s'",
23
- "loc.messages.LIB_EndpointNotExist": "Endpoint not present: %s",
24
- "loc.messages.LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s",
25
- "loc.messages.LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s",
26
- "loc.messages.LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s",
27
- "loc.messages.LIB_InvalidSecureFilesInput": "Invalid secure file input: %s",
28
- "loc.messages.LIB_PathNotFound": "Not found %s: %s",
29
- "loc.messages.LIB_PathHasNullByte": "Path cannot contain null bytes",
30
- "loc.messages.LIB_OperationFailed": "Failed %s: %s",
34
+ "loc.messages.LIB_UndefinedNodeVersion": "Node version is undefined.",
35
+ "loc.messages.LIB_UnhandledEx": "Unhandled: %s",
31
36
  "loc.messages.LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.",
32
- "loc.messages.LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
33
- "loc.messages.LIB_PlatformNotSupported": "Platform not supported: %s",
34
- "loc.messages.LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s",
35
- "loc.messages.LIB_UndefinedNodeVersion": "Node version is undefined."
37
+ "loc.messages.LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.",
38
+ "loc.messages.LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file."
36
39
  }
package/internal.js CHANGED
@@ -921,7 +921,7 @@ function _exposeTaskLibSecret(keyFile, secret) {
921
921
  if (secret) {
922
922
  var encryptKey = crypto.randomBytes(256);
923
923
  var cipher = crypto.createCipher("aes-256-ctr", encryptKey);
924
- var encryptedContent = cipher.update(secret, "utf8", "hex");
924
+ var encryptedContent = cipher.update(secret, "utf8", "hex"); // CodeQL [SM01511] agent need to retrieve password later to connect to proxy server
925
925
  encryptedContent += cipher.final("hex");
926
926
  var storageFile = path.join(_getVariable('Agent.TempDirectory') || _getVariable("agent.workFolder") || process.cwd(), keyFile);
927
927
  fs.writeFileSync(storageFile, encryptKey.toString('base64'), { encoding: 'utf8' });
package/lib.json CHANGED
@@ -1,38 +1,41 @@
1
1
  {
2
2
  "messages": {
3
- "LIB_UnhandledEx": "Unhandled: %s",
3
+ "LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s",
4
+ "LIB_DirectoryStackEmpty": "Directory stack is empty",
5
+ "LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s",
6
+ "LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s",
7
+ "LIB_EndpointNotExist": "Endpoint not present: %s",
4
8
  "LIB_FailOnCode": "Failure return code: %d",
9
+ "LIB_InputRequired": "Input required: %s",
10
+ "LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s",
11
+ "LIB_InvalidPattern": "Invalid pattern: '%s'",
12
+ "LIB_InvalidSecureFilesInput": "Invalid secure file input: %s",
13
+ "LIB_LocStringNotFound": "Can\\'t find loc string for key: %s",
14
+ "LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
5
15
  "LIB_MkdirFailed": "Unable to create directory '%s'. %s",
6
16
  "LIB_MkdirFailedFileExists": "Unable to create directory '%s'. Conflicting file exists: '%s'",
7
17
  "LIB_MkdirFailedInvalidDriveRoot": "Unable to create directory '%s'. Root directory does not exist: '%s'",
8
18
  "LIB_MkdirFailedInvalidShare": "Unable to create directory '%s'. Unable to verify the directory exists: '%s'. If directory is a file share, please verify the share name is correct, the share is online, and the current process has permission to access the share.",
9
19
  "LIB_MultilineSecret": "Secrets cannot contain multiple lines",
20
+ "LIB_NotFoundPreviousDirectory": "Could not find previous directory",
21
+ "LIB_OperationFailed": "Failed %s: %s",
22
+ "LIB_ParameterIsRequired": "%s not supplied",
23
+ "LIB_PathHasNullByte": "Path cannot contain null bytes",
24
+ "LIB_PathIsNotADirectory": "Path is not a directory: %s",
25
+ "LIB_PathNotFound": "Not found %s: %s",
26
+ "LIB_PlatformNotSupported": "Platform not supported: %s",
10
27
  "LIB_ProcessError": "There was an error when attempting to execute the process '%s'. This may indicate the process failed to start. Error: %s",
11
28
  "LIB_ProcessExitCode": "The process '%s' failed with exit code %s",
12
29
  "LIB_ProcessStderr": "The process '%s' failed because one or more lines were written to the STDERR stream",
13
- "LIB_ReturnCode": "Return code: %d",
14
- "LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s",
15
30
  "LIB_ResourceFileAlreadySet": "Resource file has already set to: %s",
31
+ "LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s",
16
32
  "LIB_ResourceFileNotSet": "Resource file haven\\'t set, can\\'t find loc string for key: %s",
33
+ "LIB_ReturnCode": "Return code: %d",
17
34
  "LIB_StdioNotClosed": "The STDIO streams did not close within %s seconds of the exit event from process '%s'. This may indicate a child process inherited the STDIO streams and has not yet exited.",
18
- "LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.",
19
- "LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.",
20
- "LIB_LocStringNotFound": "Can\\'t find loc string for key: %s",
21
- "LIB_ParameterIsRequired": "%s not supplied",
22
- "LIB_InputRequired": "Input required: %s",
23
- "LIB_InvalidPattern": "Invalid pattern: '%s'",
24
- "LIB_EndpointNotExist": "Endpoint not present: %s",
25
- "LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s",
26
- "LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s",
27
- "LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s",
28
- "LIB_InvalidSecureFilesInput": "Invalid secure file input: %s",
29
- "LIB_PathNotFound": "Not found %s: %s",
30
- "LIB_PathHasNullByte": "Path cannot contain null bytes",
31
- "LIB_OperationFailed": "Failed %s: %s",
35
+ "LIB_UndefinedNodeVersion": "Node version is undefined.",
36
+ "LIB_UnhandledEx": "Unhandled: %s",
32
37
  "LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.",
33
- "LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
34
- "LIB_PlatformNotSupported": "Platform not supported: %s",
35
- "LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s",
36
- "LIB_UndefinedNodeVersion": "Node version is undefined."
37
- }
38
- }
38
+ "LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.",
39
+ "LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file."
40
+ }
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azure-pipelines-task-lib",
3
- "version": "4.17.3",
3
+ "version": "5.0.0",
4
4
  "description": "Azure Pipelines Task SDK",
5
5
  "main": "./task.js",
6
6
  "typings": "./task.d.ts",
package/task.d.ts CHANGED
@@ -4,6 +4,8 @@ import Q = require('q');
4
4
  import fs = require('fs');
5
5
  import im = require('./internal');
6
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> | '';
7
9
  export declare enum TaskResult {
8
10
  Succeeded = 0,
9
11
  SucceededWithIssues = 1,
@@ -320,8 +322,6 @@ export declare const command: typeof im._command;
320
322
  export declare const warning: typeof im._warning;
321
323
  export declare const error: typeof im._error;
322
324
  export declare const debug: typeof im._debug;
323
- export interface FsStats extends fs.Stats {
324
- }
325
325
  /**
326
326
  * Get's stat on a path.
327
327
  * Useful for checking whether a file or directory. Also getting created, modified and accessed time.
@@ -330,7 +330,7 @@ export interface FsStats extends fs.Stats {
330
330
  * @param path path to check
331
331
  * @returns fsStat
332
332
  */
333
- export declare function stats(path: string): FsStats;
333
+ export declare function stats(path: string): fs.Stats;
334
334
  export declare const exist: typeof im._exist;
335
335
  export declare function writeFile(file: string, data: string | Buffer, options?: BufferEncoding | fs.WriteFileOptions): void;
336
336
  /**
@@ -368,29 +368,30 @@ export declare const checkPath: typeof im._checkPath;
368
368
  /**
369
369
  * Change working directory.
370
370
  *
371
- * @param path new working directory path
372
- * @returns void
371
+ * @param {string} path - New working directory path
372
+ * @returns {void}
373
373
  */
374
374
  export declare function cd(path: string): void;
375
375
  /**
376
376
  * Change working directory and push it on the stack
377
377
  *
378
- * @param path new working directory path
379
- * @returns void
378
+ * @param {string} dir - New working directory path
379
+ * @returns {void}
380
380
  */
381
- export declare function pushd(path: string): void;
381
+ export declare function pushd(dir?: string): string[];
382
382
  /**
383
383
  * Change working directory back to previously pushed directory
384
384
  *
385
- * @returns void
385
+ * @param {string} index - Index to remove from the stack
386
+ * @returns {void}
386
387
  */
387
- export declare function popd(): void;
388
+ export declare function popd(index?: string): string[];
388
389
  /**
389
- * Make a directory. Creates the full path with folders in between
390
+ * Make a directory. Creates the full path with folders in between
390
391
  * Will throw if it fails
391
392
  *
392
- * @param p path to create
393
- * @returns void
393
+ * @param {string} p - Path to create
394
+ * @returns {void}
394
395
  */
395
396
  export declare function mkdirP(p: string): void;
396
397
  /**
@@ -402,32 +403,78 @@ export declare function mkdirP(p: string): void;
402
403
  */
403
404
  export declare function resolve(...pathSegments: any[]): string;
404
405
  export declare const which: typeof im._which;
406
+ type ListOptionsVariants = OptionsPermutations<'ra'>;
405
407
  /**
406
- * Returns array of files in the given path, or in current directory if no path provided. See shelljs.ls
407
- * @param {string} options Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..)
408
- * @param {string[]} paths Paths to search.
409
- * @return {string[]} An array of files in the given path(s).
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).
410
412
  */
411
- export declare function ls(options: string, paths: string[]): string[];
413
+ export declare function ls(options: ListOptionsVariants, ...paths: string[]): string[];
414
+ /**
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).
419
+ */
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'>;
412
447
  /**
413
448
  * Copies a file or folder.
414
- *
415
- * @param source source path
416
- * @param dest destination path
417
- * @param options string -r, -f or -rf for recursive and force
418
- * @param continueOnError optional. whether to continue on error
419
- * @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}
420
465
  */
421
- 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'>;
422
468
  /**
423
469
  * Moves a path.
424
470
  *
425
- * @param source source path
426
- * @param dest destination path
427
- * @param options string -f or -n for force and no clobber
428
- * @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}
429
476
  */
430
- 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;
431
478
  /**
432
479
  * Interface for FindOptions
433
480
  * Contains properties to control whether to follow symlinks
@@ -499,8 +546,9 @@ export declare function legacyFindFiles(rootDirectory: string, pattern: string,
499
546
  /**
500
547
  * Remove a path recursively with force
501
548
  *
502
- * @param inputPath path to remove
503
- * @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.
504
552
  */
505
553
  export declare function rmRF(inputPath: string): void;
506
554
  /**
@@ -774,3 +822,4 @@ export declare function addBuildTag(value: string): void;
774
822
  * @returns void
775
823
  */
776
824
  export declare function updateReleaseName(name: string): void;
825
+ export {};
package/task.js CHANGED
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  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.getPipelineFeature = exports.getBoolFeatureFlag = exports.getBoolInput = exports.getInputRequired = exports.getInput = exports.setSecret = exports.setVariable = exports.getVariables = exports.assertAgent = exports.getVariable = exports.loc = exports.setResourcePath = exports.setSanitizedResult = exports.setResult = exports.setErrStream = exports.setStdStream = exports.AgentHostedMode = exports.Platform = exports.IssueSource = exports.FieldType = exports.ArtifactType = exports.IssueType = exports.TaskState = exports.TaskResult = void 0;
4
13
  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.getNodeMajorVersion = void 0;
5
- var shell = require("shelljs");
6
14
  var childProcess = require("child_process");
7
15
  var fs = require("fs");
8
16
  var path = require("path");
@@ -598,17 +606,6 @@ exports.debug = im._debug;
598
606
  //-----------------------------------------------------
599
607
  // Disk Functions
600
608
  //-----------------------------------------------------
601
- function _checkShell(cmd, continueOnError) {
602
- var se = shell.error();
603
- if (se) {
604
- (0, exports.debug)(cmd + ' failed');
605
- var errMsg = (0, exports.loc)('LIB_OperationFailed', cmd, se);
606
- (0, exports.debug)(errMsg);
607
- if (!continueOnError) {
608
- throw new Error(errMsg);
609
- }
610
- }
611
- }
612
609
  /**
613
610
  * Get's stat on a path.
614
611
  * Useful for checking whether a file or directory. Also getting created, modified and accessed time.
@@ -700,43 +697,120 @@ exports.checkPath = im._checkPath;
700
697
  /**
701
698
  * Change working directory.
702
699
  *
703
- * @param path new working directory path
704
- * @returns void
700
+ * @param {string} path - New working directory path
701
+ * @returns {void}
705
702
  */
706
703
  function cd(path) {
707
- if (path) {
708
- shell.cd(path);
709
- _checkShell('cd');
704
+ if (path === '-') {
705
+ if (!process.env.OLDPWD) {
706
+ throw new Error((0, exports.loc)('LIB_NotFoundPreviousDirectory'));
707
+ }
708
+ else {
709
+ path = process.env.OLDPWD;
710
+ }
711
+ }
712
+ if (path === '~') {
713
+ path = os.homedir();
714
+ }
715
+ if (!fs.existsSync(path)) {
716
+ throw new Error((0, exports.loc)('LIB_PathNotFound', 'cd', path));
717
+ }
718
+ if (!fs.statSync(path).isDirectory()) {
719
+ throw new Error((0, exports.loc)('LIB_PathIsNotADirectory', path));
720
+ }
721
+ try {
722
+ var currentPath = process.cwd();
723
+ process.chdir(path);
724
+ process.env.OLDPWD = currentPath;
725
+ }
726
+ catch (error) {
727
+ (0, exports.debug)((0, exports.loc)('LIB_OperationFailed', 'cd', error));
710
728
  }
711
729
  }
712
730
  exports.cd = cd;
731
+ var dirStack = [];
732
+ function getActualStack() {
733
+ return [process.cwd()].concat(dirStack);
734
+ }
713
735
  /**
714
736
  * Change working directory and push it on the stack
715
737
  *
716
- * @param path new working directory path
717
- * @returns void
738
+ * @param {string} dir - New working directory path
739
+ * @returns {void}
718
740
  */
719
- function pushd(path) {
720
- shell.pushd(path);
721
- _checkShell('pushd');
741
+ function pushd(dir) {
742
+ if (dir === void 0) { dir = ''; }
743
+ var dirs = getActualStack();
744
+ var maybeIndex = parseInt(dir);
745
+ if (dir === '+0') {
746
+ return dirs;
747
+ }
748
+ else if (dir.length === 0) {
749
+ if (dirs.length > 1) {
750
+ dirs.splice.apply(dirs, __spreadArray([0, 0], dirs.splice(1, 1), false));
751
+ }
752
+ else {
753
+ throw new Error((0, exports.loc)('LIB_DirectoryStackEmpty'));
754
+ }
755
+ }
756
+ else if (!isNaN(maybeIndex)) {
757
+ if (maybeIndex < dirStack.length + 1) {
758
+ maybeIndex = dir.charAt(0) === '-' ? maybeIndex - 1 : maybeIndex;
759
+ }
760
+ dirs.splice.apply(dirs, __spreadArray([0, dirs.length], dirs.slice(maybeIndex).concat(dirs.slice(0, maybeIndex)), false));
761
+ }
762
+ else {
763
+ dirs.unshift(dir);
764
+ }
765
+ var _path = path.resolve(dirs.shift());
766
+ try {
767
+ cd(_path);
768
+ }
769
+ catch (error) {
770
+ if (!fs.existsSync(_path)) {
771
+ throw new Error((0, exports.loc)('Not found', 'pushd', _path));
772
+ }
773
+ throw error;
774
+ }
775
+ dirStack.splice.apply(dirStack, __spreadArray([0, dirStack.length], dirs, false));
776
+ return getActualStack();
722
777
  }
723
778
  exports.pushd = pushd;
724
779
  /**
725
780
  * Change working directory back to previously pushed directory
726
781
  *
727
- * @returns void
782
+ * @param {string} index - Index to remove from the stack
783
+ * @returns {void}
728
784
  */
729
- function popd() {
730
- shell.popd();
731
- _checkShell('popd');
785
+ function popd(index) {
786
+ if (index === void 0) { index = ''; }
787
+ if (dirStack.length === 0) {
788
+ throw new Error((0, exports.loc)('LIB_DirectoryStackEmpty'));
789
+ }
790
+ var maybeIndex = parseInt(index);
791
+ if (isNaN(maybeIndex)) {
792
+ maybeIndex = 0;
793
+ }
794
+ else if (maybeIndex < dirStack.length + 1) {
795
+ maybeIndex = index.charAt(0) === '-' ? maybeIndex - 1 : maybeIndex;
796
+ }
797
+ if (maybeIndex > 0 || dirStack.length + maybeIndex === 0) {
798
+ maybeIndex = maybeIndex > 0 ? maybeIndex - 1 : maybeIndex;
799
+ dirStack.splice(maybeIndex, 1);
800
+ }
801
+ else {
802
+ var _path = path.resolve(dirStack.shift());
803
+ cd(_path);
804
+ }
805
+ return getActualStack();
732
806
  }
733
807
  exports.popd = popd;
734
808
  /**
735
- * Make a directory. Creates the full path with folders in between
809
+ * Make a directory. Creates the full path with folders in between
736
810
  * Will throw if it fails
737
811
  *
738
- * @param p path to create
739
- * @returns void
812
+ * @param {string} p - Path to create
813
+ * @returns {void}
740
814
  */
741
815
  function mkdirP(p) {
742
816
  if (!p) {
@@ -815,76 +889,204 @@ function resolve() {
815
889
  exports.resolve = resolve;
816
890
  exports.which = im._which;
817
891
  /**
818
- * Returns array of files in the given path, or in current directory if no path provided. See shelljs.ls
819
- * @param {string} options Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..)
820
- * @param {string[]} paths Paths to search.
821
- * @return {string[]} An array of files in the given path(s).
892
+ * Returns array of files in the given path, or in current directory if no path provided.
893
+ * @param {unknown} optionsOrPaths - Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..)
894
+ * @param {unknown[]} paths - Paths to search.
895
+ * @return {string[]} - An array of files in the given path(s).
822
896
  */
823
- function ls(options, paths) {
824
- if (options) {
825
- return shell.ls(options, paths);
897
+ function ls(optionsOrPaths) {
898
+ var paths = [];
899
+ for (var _i = 1; _i < arguments.length; _i++) {
900
+ paths[_i - 1] = arguments[_i];
826
901
  }
827
- else {
828
- return shell.ls(paths);
902
+ var isRecursive = false;
903
+ var includeHidden = false;
904
+ if (typeof optionsOrPaths === 'string' && optionsOrPaths.startsWith('-')) {
905
+ var options = String(optionsOrPaths).toLowerCase();
906
+ isRecursive = options.includes('r');
907
+ includeHidden = options.includes('a');
908
+ }
909
+ // Flatten paths if the paths argument is array
910
+ if (Array.isArray(paths)) {
911
+ paths = paths.flat(Infinity);
912
+ }
913
+ // If the first argument is not options, then it is a path
914
+ if (typeof optionsOrPaths !== 'string' || !optionsOrPaths.startsWith('-')) {
915
+ var pathsFromOptions = [];
916
+ if (Array.isArray(optionsOrPaths)) {
917
+ pathsFromOptions = optionsOrPaths;
918
+ }
919
+ else if (optionsOrPaths && typeof optionsOrPaths === 'string') {
920
+ pathsFromOptions = [optionsOrPaths];
921
+ }
922
+ if (paths === undefined || paths.length === 0) {
923
+ paths = pathsFromOptions;
924
+ }
925
+ else {
926
+ paths.push.apply(paths, pathsFromOptions);
927
+ }
928
+ }
929
+ if (paths.length === 0) {
930
+ paths.push(path.resolve('.'));
931
+ }
932
+ var preparedPaths = [];
933
+ try {
934
+ var _loop_1 = function () {
935
+ var pathEntry = resolve(paths.shift());
936
+ if (pathEntry === null || pathEntry === void 0 ? void 0 : pathEntry.includes('*')) {
937
+ paths.push.apply(paths, findMatch(path.dirname(pathEntry), [path.basename(pathEntry)]));
938
+ return "continue";
939
+ }
940
+ if (fs.lstatSync(pathEntry).isDirectory()) {
941
+ preparedPaths.push.apply(preparedPaths, fs.readdirSync(pathEntry).map(function (file) { return path.join(pathEntry, file); }));
942
+ }
943
+ else {
944
+ preparedPaths.push(pathEntry);
945
+ }
946
+ };
947
+ while (paths.length > 0) {
948
+ _loop_1();
949
+ }
950
+ var entries = [];
951
+ var _loop_2 = function () {
952
+ var entry = preparedPaths.shift();
953
+ var entrybasename = path.basename(entry);
954
+ if (entry === null || entry === void 0 ? void 0 : entry.includes('*')) {
955
+ preparedPaths.push.apply(preparedPaths, findMatch(path.dirname(entry), [entrybasename]));
956
+ return "continue";
957
+ }
958
+ if (!includeHidden && entrybasename.startsWith('.') && entrybasename !== '.' && entrybasename !== '..') {
959
+ return "continue";
960
+ }
961
+ if (fs.lstatSync(entry).isDirectory() && isRecursive) {
962
+ preparedPaths.push.apply(preparedPaths, fs.readdirSync(entry).map(function (x) { return path.join(entry, x); }));
963
+ }
964
+ else {
965
+ entries.push(entry);
966
+ }
967
+ };
968
+ while (preparedPaths.length > 0) {
969
+ _loop_2();
970
+ }
971
+ return entries;
972
+ }
973
+ catch (error) {
974
+ if (error.code === 'ENOENT') {
975
+ throw new Error((0, exports.loc)('LIB_PathNotFound', 'ls', error.message));
976
+ }
977
+ else {
978
+ throw new Error((0, exports.loc)('LIB_OperationFailed', 'ls', error));
979
+ }
829
980
  }
830
981
  }
831
982
  exports.ls = ls;
832
983
  /**
833
984
  * Copies a file or folder.
834
- *
835
- * @param source source path
836
- * @param dest destination path
837
- * @param options string -r, -f or -rf for recursive and force
838
- * @param continueOnError optional. whether to continue on error
839
- * @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.
840
- */
841
- function cp(source, dest, options, continueOnError, retryCount) {
985
+ * @param {string} sourceOrOptions - Either the source path or an option string '-r', '-f' , '-n' or '-rfn' for recursive, force and no-clobber.
986
+ * @param {string} destinationOrSource - Destination path or the source path.
987
+ * @param {string} [optionsOrDestination] - Options string or the destination path.
988
+ * @param {boolean} [continueOnError=false] - Optional. Whether to continue on error.
989
+ * @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.
990
+ * @returns {void}
991
+ */
992
+ function cp(sourceOrOptions, destinationOrSource, optionsOrDestination, continueOnError, retryCount) {
993
+ if (continueOnError === void 0) { continueOnError = false; }
842
994
  if (retryCount === void 0) { retryCount = 0; }
843
- while (retryCount >= 0) {
844
- try {
845
- if (options) {
846
- shell.cp(options, source, dest);
847
- }
848
- else {
849
- shell.cp(source, dest);
850
- }
851
- _checkShell('cp', false);
852
- break;
995
+ retry(function () {
996
+ var recursive = false;
997
+ var force = true;
998
+ var source = String(sourceOrOptions);
999
+ var destination = destinationOrSource;
1000
+ var options = '';
1001
+ if (typeof sourceOrOptions === 'string' && sourceOrOptions.startsWith('-')) {
1002
+ options = sourceOrOptions.toLowerCase();
1003
+ recursive = options.includes('r');
1004
+ force = !options.includes('n');
1005
+ source = destinationOrSource;
1006
+ destination = String(optionsOrDestination);
1007
+ }
1008
+ else if (typeof optionsOrDestination === 'string' && optionsOrDestination && optionsOrDestination.startsWith('-')) {
1009
+ options = optionsOrDestination.toLowerCase();
1010
+ recursive = options.includes('r');
1011
+ force = !options.includes('n');
1012
+ source = String(sourceOrOptions);
1013
+ destination = destinationOrSource;
1014
+ }
1015
+ if (!fs.existsSync(destination) && !force) {
1016
+ throw new Error((0, exports.loc)('LIB_PathNotFound', 'cp', destination));
1017
+ }
1018
+ var lstatSource = fs.lstatSync(source);
1019
+ if (!force && fs.existsSync(destination)) {
1020
+ return;
853
1021
  }
854
- catch (e) {
855
- if (retryCount <= 0) {
856
- if (continueOnError) {
857
- (0, exports.warning)(e, exports.IssueSource.TaskInternal);
858
- break;
1022
+ try {
1023
+ if (lstatSource.isFile()) {
1024
+ if (fs.existsSync(destination) && fs.lstatSync(destination).isDirectory()) {
1025
+ destination = path.join(destination, path.basename(source));
1026
+ }
1027
+ if (force) {
1028
+ fs.copyFileSync(source, destination);
859
1029
  }
860
1030
  else {
861
- throw e;
1031
+ fs.copyFileSync(source, destination, fs.constants.COPYFILE_EXCL);
862
1032
  }
863
1033
  }
864
1034
  else {
865
- console.log((0, exports.loc)('LIB_CopyFileFailed', retryCount));
866
- retryCount--;
1035
+ fs.cpSync(source, path.join(destination, path.basename(source)), { recursive: recursive, force: force });
867
1036
  }
868
1037
  }
869
- }
1038
+ catch (error) {
1039
+ throw new Error((0, exports.loc)('LIB_OperationFailed', 'cp', error));
1040
+ }
1041
+ }, [], { retryCount: retryCount, continueOnError: continueOnError });
870
1042
  }
871
1043
  exports.cp = cp;
872
1044
  /**
873
1045
  * Moves a path.
874
1046
  *
875
- * @param source source path
876
- * @param dest destination path
877
- * @param options string -f or -n for force and no clobber
878
- * @param continueOnError optional. whether to continue on error
1047
+ * @param {string} source - Source path.
1048
+ * @param {string} dest - Destination path.
1049
+ * @param {MoveOptionsVariants} [options] - Option string -f or -n for force and no clobber.
1050
+ * @param {boolean} [continueOnError] - Optional. Whether to continue on error.
1051
+ * @returns {void}
879
1052
  */
880
1053
  function mv(source, dest, options, continueOnError) {
881
- if (options) {
882
- shell.mv(options, source, dest);
1054
+ var force = false;
1055
+ if (options && typeof options === 'string' && options.startsWith('-')) {
1056
+ var lowercasedOptions = String(options).toLowerCase();
1057
+ force = lowercasedOptions.includes('f') && !lowercasedOptions.includes('n');
1058
+ }
1059
+ var sourceExists = fs.existsSync(source);
1060
+ var destExists = fs.existsSync(dest);
1061
+ var sources = [];
1062
+ try {
1063
+ if (!sourceExists) {
1064
+ if (source.includes('*')) {
1065
+ sources.push.apply(sources, findMatch(path.resolve(path.dirname(source)), [path.basename(source)]));
1066
+ }
1067
+ else {
1068
+ throw new Error((0, exports.loc)('LIB_PathNotFound', 'mv', source));
1069
+ }
1070
+ }
1071
+ else {
1072
+ sources.push(source);
1073
+ }
1074
+ if (destExists && !force) {
1075
+ throw new Error("File already exists at ".concat(dest));
1076
+ }
1077
+ for (var _i = 0, sources_1 = sources; _i < sources_1.length; _i++) {
1078
+ var source_1 = sources_1[_i];
1079
+ fs.renameSync(source_1, dest);
1080
+ }
883
1081
  }
884
- else {
885
- shell.mv(source, dest);
1082
+ catch (error) {
1083
+ (0, exports.debug)('mv failed');
1084
+ var errMsg = (0, exports.loc)('LIB_OperationFailed', 'mv', error);
1085
+ (0, exports.debug)(errMsg);
1086
+ if (!continueOnError) {
1087
+ throw new Error(errMsg);
1088
+ }
886
1089
  }
887
- _checkShell('mv', continueOnError);
888
1090
  }
889
1091
  exports.mv = mv;
890
1092
  /**
@@ -988,7 +1190,7 @@ function find(findPath, options) {
988
1190
  // push the first item
989
1191
  var stack = [new _FindItem(findPath, 1)];
990
1192
  var traversalChain = []; // used to detect cycles
991
- var _loop_1 = function () {
1193
+ var _loop_3 = function () {
992
1194
  // pop the next item and push to the result array
993
1195
  var item = stack.pop(); // non-null because `stack.length` was truthy
994
1196
  var stats_2 = void 0;
@@ -1048,7 +1250,7 @@ function find(findPath, options) {
1048
1250
  }
1049
1251
  };
1050
1252
  while (stack.length) {
1051
- _loop_1();
1253
+ _loop_3();
1052
1254
  }
1053
1255
  (0, exports.debug)("".concat(result.length, " results"));
1054
1256
  return result;
@@ -1171,7 +1373,7 @@ function _legacyFindFiles_getMatchingItems(includePatterns, excludePatterns, inc
1171
1373
  (0, exports.debug)('includeFiles: ' + includeFiles);
1172
1374
  (0, exports.debug)('includeDirectories: ' + includeDirectories);
1173
1375
  var allFiles = {};
1174
- var _loop_2 = function (pattern) {
1376
+ var _loop_4 = function (pattern) {
1175
1377
  // determine the directory to search
1176
1378
  //
1177
1379
  // note, getDirectoryName removes redundant path separators
@@ -1233,15 +1435,16 @@ function _legacyFindFiles_getMatchingItems(includePatterns, excludePatterns, inc
1233
1435
  };
1234
1436
  for (var _b = 0, includePatterns_2 = includePatterns; _b < includePatterns_2.length; _b++) {
1235
1437
  var pattern = includePatterns_2[_b];
1236
- _loop_2(pattern);
1438
+ _loop_4(pattern);
1237
1439
  }
1238
1440
  return Object.keys(allFiles).sort();
1239
1441
  }
1240
1442
  /**
1241
1443
  * Remove a path recursively with force
1242
1444
  *
1243
- * @param inputPath path to remove
1244
- * @throws when the file or directory exists but could not be deleted.
1445
+ * @param {string} inputPath - Path to remove
1446
+ * @return {void}
1447
+ * @throws When the file or directory exists but could not be deleted.
1245
1448
  */
1246
1449
  function rmRF(inputPath) {
1247
1450
  (0, exports.debug)('rm -rf ' + inputPath);
@@ -1251,11 +1454,11 @@ function rmRF(inputPath) {
1251
1454
  try {
1252
1455
  if (fs.statSync(inputPath).isDirectory()) {
1253
1456
  (0, exports.debug)('removing directory ' + inputPath);
1254
- childProcess.execSync("rd /s /q \"".concat(inputPath, "\""));
1457
+ childProcess.execFileSync("cmd.exe", ["/c", "rd", "/s", "/q", inputPath]);
1255
1458
  }
1256
1459
  else {
1257
1460
  (0, exports.debug)('removing file ' + inputPath);
1258
- childProcess.execSync("del /f /a \"".concat(inputPath, "\""));
1461
+ childProcess.execFileSync("cmd.exe", ["/c", "del", "/f", "/a", inputPath]);
1259
1462
  }
1260
1463
  }
1261
1464
  catch (err) {
@@ -1282,7 +1485,17 @@ function rmRF(inputPath) {
1282
1485
  // with missing targets are not handled correctly by "rm('-rf', path)"
1283
1486
  var lstats = void 0;
1284
1487
  try {
1285
- lstats = fs.lstatSync(inputPath);
1488
+ if (inputPath.includes('*')) {
1489
+ var entries = findMatch(path.dirname(inputPath), [path.basename(inputPath)]);
1490
+ for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
1491
+ var entry = entries_1[_i];
1492
+ fs.rmSync(entry, { recursive: true, force: true });
1493
+ }
1494
+ return;
1495
+ }
1496
+ else {
1497
+ lstats = fs.lstatSync(inputPath);
1498
+ }
1286
1499
  }
1287
1500
  catch (err) {
1288
1501
  // if you try to delete a file that doesn't exist, desired result is achieved
@@ -1294,16 +1507,31 @@ function rmRF(inputPath) {
1294
1507
  }
1295
1508
  if (lstats.isDirectory()) {
1296
1509
  (0, exports.debug)('removing directory');
1297
- shell.rm('-rf', inputPath);
1298
- var errMsg = shell.error();
1299
- if (errMsg) {
1510
+ try {
1511
+ fs.rmSync(inputPath, { recursive: true, force: true });
1512
+ }
1513
+ catch (errMsg) {
1514
+ throw new Error((0, exports.loc)('LIB_OperationFailed', 'rmRF', errMsg));
1515
+ }
1516
+ return;
1517
+ }
1518
+ else if (lstats.isSymbolicLink()) {
1519
+ (0, exports.debug)('removing symbolic link');
1520
+ try {
1521
+ fs.unlinkSync(inputPath);
1522
+ }
1523
+ catch (errMsg) {
1300
1524
  throw new Error((0, exports.loc)('LIB_OperationFailed', 'rmRF', errMsg));
1301
1525
  }
1302
1526
  return;
1303
1527
  }
1304
1528
  (0, exports.debug)('removing file');
1305
1529
  try {
1306
- fs.unlinkSync(inputPath);
1530
+ var entries = findMatch(path.dirname(inputPath), [path.basename(inputPath)]);
1531
+ for (var _a = 0, entries_2 = entries; _a < entries_2.length; _a++) {
1532
+ var entry = entries_2[_a];
1533
+ fs.rmSync(entry, { recursive: true, force: true });
1534
+ }
1307
1535
  }
1308
1536
  catch (err) {
1309
1537
  throw new Error((0, exports.loc)('LIB_OperationFailed', 'rmRF', err.message));