azure-pipelines-task-lib 4.0.1-preview → 4.1.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-answer.d.ts CHANGED
@@ -1,55 +1,55 @@
1
- import * as task from './task';
2
- export interface TaskLibAnswerExecResult {
3
- code: number;
4
- stdout?: string;
5
- stderr?: string;
6
- }
7
- export interface TaskLibAnswers {
8
- checkPath?: {
9
- [key: string]: boolean;
10
- };
11
- cwd?: {
12
- [key: string]: string;
13
- };
14
- exec?: {
15
- [key: string]: TaskLibAnswerExecResult;
16
- };
17
- exist?: {
18
- [key: string]: boolean;
19
- };
20
- find?: {
21
- [key: string]: string[];
22
- };
23
- findMatch?: {
24
- [key: string]: string[];
25
- };
26
- getPlatform?: {
27
- [key: string]: task.Platform;
28
- };
29
- legacyFindFiles?: {
30
- [key: string]: string[];
31
- };
32
- ls?: {
33
- [key: string]: string;
34
- };
35
- osType?: {
36
- [key: string]: string;
37
- };
38
- rmRF?: {
39
- [key: string]: {
40
- success: boolean;
41
- };
42
- };
43
- stats?: {
44
- [key: string]: any;
45
- };
46
- which?: {
47
- [key: string]: string;
48
- };
49
- }
50
- export declare type MockedCommand = keyof TaskLibAnswers;
51
- export declare class MockAnswers {
52
- private _answers;
53
- initialize(answers: TaskLibAnswers): void;
54
- getResponse(cmd: MockedCommand, key: string, debug: (message: string) => void): any;
55
- }
1
+ import * as task from './task';
2
+ export interface TaskLibAnswerExecResult {
3
+ code: number;
4
+ stdout?: string;
5
+ stderr?: string;
6
+ }
7
+ export interface TaskLibAnswers {
8
+ checkPath?: {
9
+ [key: string]: boolean;
10
+ };
11
+ cwd?: {
12
+ [key: string]: string;
13
+ };
14
+ exec?: {
15
+ [key: string]: TaskLibAnswerExecResult;
16
+ };
17
+ exist?: {
18
+ [key: string]: boolean;
19
+ };
20
+ find?: {
21
+ [key: string]: string[];
22
+ };
23
+ findMatch?: {
24
+ [key: string]: string[];
25
+ };
26
+ getPlatform?: {
27
+ [key: string]: task.Platform;
28
+ };
29
+ legacyFindFiles?: {
30
+ [key: string]: string[];
31
+ };
32
+ ls?: {
33
+ [key: string]: string;
34
+ };
35
+ osType?: {
36
+ [key: string]: string;
37
+ };
38
+ rmRF?: {
39
+ [key: string]: {
40
+ success: boolean;
41
+ };
42
+ };
43
+ stats?: {
44
+ [key: string]: any;
45
+ };
46
+ which?: {
47
+ [key: string]: string;
48
+ };
49
+ }
50
+ export declare type MockedCommand = keyof TaskLibAnswers;
51
+ export declare class MockAnswers {
52
+ private _answers;
53
+ initialize(answers: TaskLibAnswers): void;
54
+ getResponse(cmd: MockedCommand, key: string, debug: (message: string) => void): any;
55
+ }
package/mock-answer.js CHANGED
@@ -1,41 +1,41 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MockAnswers = void 0;
4
- var MockAnswers = /** @class */ (function () {
5
- function MockAnswers() {
6
- }
7
- MockAnswers.prototype.initialize = function (answers) {
8
- if (!answers) {
9
- throw new Error('Answers not supplied');
10
- }
11
- this._answers = answers;
12
- };
13
- MockAnswers.prototype.getResponse = function (cmd, key, debug) {
14
- debug("looking up mock answers for " + JSON.stringify(cmd) + ", key '" + JSON.stringify(key) + "'");
15
- if (!this._answers) {
16
- throw new Error('Must initialize');
17
- }
18
- if (!this._answers[cmd]) {
19
- debug("no mock responses registered for " + JSON.stringify(cmd));
20
- return null;
21
- }
22
- var cmd_answer = this._answers[cmd];
23
- //use this construction to avoid falsy zero
24
- if (cmd_answer[key] != null) {
25
- debug('found mock response');
26
- return cmd_answer[key];
27
- }
28
- if (key && process.env['MOCK_NORMALIZE_SLASHES'] === 'true') {
29
- // try normalizing the slashes
30
- var key2 = key.replace(/\\/g, "/");
31
- if (cmd_answer[key2]) {
32
- debug('found mock response for normalized key');
33
- return cmd_answer[key2];
34
- }
35
- }
36
- debug('mock response not found');
37
- return null;
38
- };
39
- return MockAnswers;
40
- }());
41
- exports.MockAnswers = MockAnswers;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockAnswers = void 0;
4
+ var MockAnswers = /** @class */ (function () {
5
+ function MockAnswers() {
6
+ }
7
+ MockAnswers.prototype.initialize = function (answers) {
8
+ if (!answers) {
9
+ throw new Error('Answers not supplied');
10
+ }
11
+ this._answers = answers;
12
+ };
13
+ MockAnswers.prototype.getResponse = function (cmd, key, debug) {
14
+ debug("looking up mock answers for " + JSON.stringify(cmd) + ", key '" + JSON.stringify(key) + "'");
15
+ if (!this._answers) {
16
+ throw new Error('Must initialize');
17
+ }
18
+ if (!this._answers[cmd]) {
19
+ debug("no mock responses registered for " + JSON.stringify(cmd));
20
+ return null;
21
+ }
22
+ var cmd_answer = this._answers[cmd];
23
+ //use this construction to avoid falsy zero
24
+ if (cmd_answer[key] != null) {
25
+ debug('found mock response');
26
+ return cmd_answer[key];
27
+ }
28
+ if (key && process.env['MOCK_NORMALIZE_SLASHES'] === 'true') {
29
+ // try normalizing the slashes
30
+ var key2 = key.replace(/\\/g, "/");
31
+ if (cmd_answer[key2]) {
32
+ debug('found mock response for normalized key');
33
+ return cmd_answer[key2];
34
+ }
35
+ }
36
+ debug('mock response not found');
37
+ return null;
38
+ };
39
+ return MockAnswers;
40
+ }());
41
+ exports.MockAnswers = MockAnswers;
package/mock-run.d.ts CHANGED
@@ -1,44 +1,44 @@
1
- import ma = require('./mock-answer');
2
- export declare class TaskMockRunner {
3
- constructor(taskPath: string);
4
- _taskPath: string;
5
- _answers: ma.TaskLibAnswers | undefined;
6
- _exports: {
7
- [key: string]: any;
8
- };
9
- _moduleCount: number;
10
- setInput(name: string, val: string): void;
11
- setVariableName(name: string, val: string, isSecret?: boolean): void;
12
- /**
13
- * Register answers for the mock "azure-pipelines-task-lib/task" instance.
14
- *
15
- * @param answers Answers to be returned when the task lib functions are called.
16
- */
17
- setAnswers(answers: ma.TaskLibAnswers): void;
18
- /**
19
- * Register a mock module. When require() is called for the module name,
20
- * the mock implementation will be returned instead.
21
- *
22
- * @param modName Module name to override.
23
- * @param val Mock implementation of the module.
24
- * @returns void
25
- */
26
- registerMock(modName: string, mod: any): void;
27
- /**
28
- * Registers an override for a specific function on the mock "azure-pipelines-task-lib/task" instance.
29
- * This can be used in conjunction with setAnswers(), for cases where additional runtime
30
- * control is needed for a specific function.
31
- *
32
- * @param key Function or field to override.
33
- * @param val Function or field value.
34
- * @returns void
35
- */
36
- registerMockExport(key: string, val: any): void;
37
- /**
38
- * Runs a task script.
39
- *
40
- * @param noMockTask Indicates whether to mock "azure-pipelines-task-lib/task". Default is to mock.
41
- * @returns void
42
- */
43
- run(noMockTask?: boolean): void;
44
- }
1
+ import ma = require('./mock-answer');
2
+ export declare class TaskMockRunner {
3
+ constructor(taskPath: string);
4
+ _taskPath: string;
5
+ _answers: ma.TaskLibAnswers | undefined;
6
+ _exports: {
7
+ [key: string]: any;
8
+ };
9
+ _moduleCount: number;
10
+ setInput(name: string, val: string): void;
11
+ setVariableName(name: string, val: string, isSecret?: boolean): void;
12
+ /**
13
+ * Register answers for the mock "azure-pipelines-task-lib/task" instance.
14
+ *
15
+ * @param answers Answers to be returned when the task lib functions are called.
16
+ */
17
+ setAnswers(answers: ma.TaskLibAnswers): void;
18
+ /**
19
+ * Register a mock module. When require() is called for the module name,
20
+ * the mock implementation will be returned instead.
21
+ *
22
+ * @param modName Module name to override.
23
+ * @param val Mock implementation of the module.
24
+ * @returns void
25
+ */
26
+ registerMock(modName: string, mod: any): void;
27
+ /**
28
+ * Registers an override for a specific function on the mock "azure-pipelines-task-lib/task" instance.
29
+ * This can be used in conjunction with setAnswers(), for cases where additional runtime
30
+ * control is needed for a specific function.
31
+ *
32
+ * @param key Function or field to override.
33
+ * @param val Function or field value.
34
+ * @returns void
35
+ */
36
+ registerMockExport(key: string, val: any): void;
37
+ /**
38
+ * Runs a task script.
39
+ *
40
+ * @param noMockTask Indicates whether to mock "azure-pipelines-task-lib/task". Default is to mock.
41
+ * @returns void
42
+ */
43
+ run(noMockTask?: boolean): void;
44
+ }
package/mock-run.js CHANGED
@@ -1,92 +1,92 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaskMockRunner = void 0;
4
- var mockery = require("mockery");
5
- var im = require("./internal");
6
- var TaskMockRunner = /** @class */ (function () {
7
- function TaskMockRunner(taskPath) {
8
- this._exports = {};
9
- this._moduleCount = 0;
10
- this._taskPath = taskPath;
11
- }
12
- TaskMockRunner.prototype.setInput = function (name, val) {
13
- var key = im._getVariableKey(name);
14
- process.env['INPUT_' + key] = val;
15
- };
16
- TaskMockRunner.prototype.setVariableName = function (name, val, isSecret) {
17
- var key = im._getVariableKey(name);
18
- if (isSecret) {
19
- process.env['SECRET_' + key] = val;
20
- }
21
- else {
22
- process.env['VSTS_TASKVARIABLE_' + key] = val;
23
- }
24
- };
25
- /**
26
- * Register answers for the mock "azure-pipelines-task-lib/task" instance.
27
- *
28
- * @param answers Answers to be returned when the task lib functions are called.
29
- */
30
- TaskMockRunner.prototype.setAnswers = function (answers) {
31
- this._answers = answers;
32
- };
33
- /**
34
- * Register a mock module. When require() is called for the module name,
35
- * the mock implementation will be returned instead.
36
- *
37
- * @param modName Module name to override.
38
- * @param val Mock implementation of the module.
39
- * @returns void
40
- */
41
- TaskMockRunner.prototype.registerMock = function (modName, mod) {
42
- this._moduleCount++;
43
- mockery.registerMock(modName, mod);
44
- };
45
- /**
46
- * Registers an override for a specific function on the mock "azure-pipelines-task-lib/task" instance.
47
- * This can be used in conjunction with setAnswers(), for cases where additional runtime
48
- * control is needed for a specific function.
49
- *
50
- * @param key Function or field to override.
51
- * @param val Function or field value.
52
- * @returns void
53
- */
54
- TaskMockRunner.prototype.registerMockExport = function (key, val) {
55
- this._exports[key] = val;
56
- };
57
- /**
58
- * Runs a task script.
59
- *
60
- * @param noMockTask Indicates whether to mock "azure-pipelines-task-lib/task". Default is to mock.
61
- * @returns void
62
- */
63
- TaskMockRunner.prototype.run = function (noMockTask) {
64
- var _this = this;
65
- // determine whether to enable mockery
66
- if (!noMockTask || this._moduleCount) {
67
- mockery.enable({ warnOnUnregistered: false });
68
- }
69
- // answers and exports not compatible with "noMockTask" mode
70
- if (noMockTask) {
71
- if (this._answers || Object.keys(this._exports).length) {
72
- throw new Error('setAnswers() and registerMockExport() is not compatible with "noMockTask" mode');
73
- }
74
- }
75
- // register mock task lib
76
- else {
77
- var tlm = require('azure-pipelines-task-lib/mock-task');
78
- if (this._answers) {
79
- tlm.setAnswers(this._answers);
80
- }
81
- Object.keys(this._exports)
82
- .forEach(function (key) {
83
- tlm[key] = _this._exports[key];
84
- });
85
- mockery.registerMock('azure-pipelines-task-lib/task', tlm);
86
- }
87
- // run it
88
- require(this._taskPath);
89
- };
90
- return TaskMockRunner;
91
- }());
92
- exports.TaskMockRunner = TaskMockRunner;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskMockRunner = void 0;
4
+ var mockery = require("mockery");
5
+ var im = require("./internal");
6
+ var TaskMockRunner = /** @class */ (function () {
7
+ function TaskMockRunner(taskPath) {
8
+ this._exports = {};
9
+ this._moduleCount = 0;
10
+ this._taskPath = taskPath;
11
+ }
12
+ TaskMockRunner.prototype.setInput = function (name, val) {
13
+ var key = im._getVariableKey(name);
14
+ process.env['INPUT_' + key] = val;
15
+ };
16
+ TaskMockRunner.prototype.setVariableName = function (name, val, isSecret) {
17
+ var key = im._getVariableKey(name);
18
+ if (isSecret) {
19
+ process.env['SECRET_' + key] = val;
20
+ }
21
+ else {
22
+ process.env['VSTS_TASKVARIABLE_' + key] = val;
23
+ }
24
+ };
25
+ /**
26
+ * Register answers for the mock "azure-pipelines-task-lib/task" instance.
27
+ *
28
+ * @param answers Answers to be returned when the task lib functions are called.
29
+ */
30
+ TaskMockRunner.prototype.setAnswers = function (answers) {
31
+ this._answers = answers;
32
+ };
33
+ /**
34
+ * Register a mock module. When require() is called for the module name,
35
+ * the mock implementation will be returned instead.
36
+ *
37
+ * @param modName Module name to override.
38
+ * @param val Mock implementation of the module.
39
+ * @returns void
40
+ */
41
+ TaskMockRunner.prototype.registerMock = function (modName, mod) {
42
+ this._moduleCount++;
43
+ mockery.registerMock(modName, mod);
44
+ };
45
+ /**
46
+ * Registers an override for a specific function on the mock "azure-pipelines-task-lib/task" instance.
47
+ * This can be used in conjunction with setAnswers(), for cases where additional runtime
48
+ * control is needed for a specific function.
49
+ *
50
+ * @param key Function or field to override.
51
+ * @param val Function or field value.
52
+ * @returns void
53
+ */
54
+ TaskMockRunner.prototype.registerMockExport = function (key, val) {
55
+ this._exports[key] = val;
56
+ };
57
+ /**
58
+ * Runs a task script.
59
+ *
60
+ * @param noMockTask Indicates whether to mock "azure-pipelines-task-lib/task". Default is to mock.
61
+ * @returns void
62
+ */
63
+ TaskMockRunner.prototype.run = function (noMockTask) {
64
+ var _this = this;
65
+ // determine whether to enable mockery
66
+ if (!noMockTask || this._moduleCount) {
67
+ mockery.enable({ warnOnUnregistered: false });
68
+ }
69
+ // answers and exports not compatible with "noMockTask" mode
70
+ if (noMockTask) {
71
+ if (this._answers || Object.keys(this._exports).length) {
72
+ throw new Error('setAnswers() and registerMockExport() is not compatible with "noMockTask" mode');
73
+ }
74
+ }
75
+ // register mock task lib
76
+ else {
77
+ var tlm = require('azure-pipelines-task-lib/mock-task');
78
+ if (this._answers) {
79
+ tlm.setAnswers(this._answers);
80
+ }
81
+ Object.keys(this._exports)
82
+ .forEach(function (key) {
83
+ tlm[key] = _this._exports[key];
84
+ });
85
+ mockery.registerMock('azure-pipelines-task-lib/task', tlm);
86
+ }
87
+ // run it
88
+ require(this._taskPath);
89
+ };
90
+ return TaskMockRunner;
91
+ }());
92
+ exports.TaskMockRunner = TaskMockRunner;