Skip to content

Commit a4139ea

Browse files
committed
FI master
2 parents 7373857 + 97f225f commit a4139ea

12 files changed

+224
-253
lines changed

node/internal.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ let _libResourceFileLoaded: boolean = false;
7171
let _resourceCulture: string = 'en-US';
7272

7373
function _loadResJson(resjsonFile: string): any {
74-
var resJson: {} = null;
74+
var resJson: any;
7575
if (_exist(resjsonFile)) {
7676
var resjsonContent = fs.readFileSync(resjsonFile, 'utf8').toString();
7777
// remove BOM
@@ -84,7 +84,6 @@ function _loadResJson(resjsonFile: string): any {
8484
}
8585
catch (err) {
8686
_debug('unable to parse resjson with err: ' + err.message);
87-
resJson = null;
8887
}
8988
}
9089
else {
@@ -102,12 +101,12 @@ function _loadLocStrings(resourceFile: string, culture: string): { [key: string]
102101
if (_exist(resourceFile)) {
103102
var resourceJson = require(resourceFile);
104103
if (resourceJson && resourceJson.hasOwnProperty('messages')) {
105-
var locResourceJson = null;
104+
var locResourceJson: any;
106105
// load up resource resjson for different culture
107106

108107
var localizedResourceFile = path.join(path.dirname(resourceFile), 'Strings', 'resources.resjson');
109108
var upperCulture = culture.toUpperCase();
110-
var cultures = [];
109+
var cultures: string[] = [];
111110
try { cultures = fs.readdirSync(localizedResourceFile); }
112111
catch (ex) { }
113112
for (var i = 0; i < cultures.length; i++) {
@@ -224,11 +223,11 @@ export function _loc(key: string, ...param: any[]): string {
224223
* @param name name of the variable to get
225224
* @returns string
226225
*/
227-
export function _getVariable(name: string): string {
228-
let varval: string;
226+
export function _getVariable(name: string): string | undefined {
227+
let varval: string | undefined;
229228

230229
// get the metadata
231-
let info: _KnownVariableInfo;
230+
let info: _KnownVariableInfo | undefined;
232231
let key: string = _getVariableKey(name);
233232
if (_knownVariableMap.hasOwnProperty(key)) {
234233
info = _knownVariableMap[key];
@@ -274,7 +273,7 @@ export interface _KnownVariableInfo {
274273
// Cmd Helpers
275274
//-----------------------------------------------------
276275

277-
export function _command(command: string, properties, message: string) {
276+
export function _command(command: string, properties: any, message: string) {
278277
var taskCmd = new tcm.TaskCommand(command, properties, message);
279278
_writeLine(taskCmd.toString());
280279
}
@@ -304,7 +303,7 @@ export function _debug(message: string): void {
304303
export function _exist(path: string): boolean {
305304
var exist = false;
306305
try {
307-
exist = path && fs.statSync(path) != null;
306+
exist = !!(path && fs.statSync(path) != null);
308307
} catch (err) {
309308
if (err && err.code === 'ENOENT') {
310309
exist = false;
@@ -921,16 +920,16 @@ export function _normalizeSeparators(p: string): string {
921920
// Expose proxy information to vsts-node-api
922921
//-----------------------------------------------------
923922
export function _exposeProxySettings(): void {
924-
let proxyUrl: string = _getVariable('Agent.ProxyUrl');
923+
let proxyUrl: string | undefined = _getVariable('Agent.ProxyUrl');
925924
if (proxyUrl && proxyUrl.length > 0) {
926-
let proxyUsername: string = _getVariable('Agent.ProxyUsername');
927-
let proxyPassword: string = _getVariable('Agent.ProxyPassword');
928-
let proxyBypassHostsJson: string = _getVariable('Agent.ProxyBypassList');
925+
let proxyUsername: string | undefined = _getVariable('Agent.ProxyUsername');
926+
let proxyPassword: string | undefined = _getVariable('Agent.ProxyPassword');
927+
let proxyBypassHostsJson: string | undefined = _getVariable('Agent.ProxyBypassList');
929928

930929
global['_vsts_task_lib_proxy_url'] = proxyUrl;
931930
global['_vsts_task_lib_proxy_username'] = proxyUsername;
932931
global['_vsts_task_lib_proxy_bypass'] = proxyBypassHostsJson;
933-
global['_vsts_task_lib_proxy_password'] = _exposeTaskLibSecret('proxy', proxyPassword);
932+
global['_vsts_task_lib_proxy_password'] = _exposeTaskLibSecret('proxy', proxyPassword || '');
934933

935934
_debug('expose agent proxy configuration.')
936935
global['_vsts_task_lib_proxy'] = true;
@@ -941,21 +940,21 @@ export function _exposeProxySettings(): void {
941940
// Expose certificate information to vsts-node-api
942941
//-----------------------------------------------------
943942
export function _exposeCertSettings(): void {
944-
let ca: string = _getVariable('Agent.CAInfo');
943+
let ca: string | undefined = _getVariable('Agent.CAInfo');
945944
if (ca) {
946945
global['_vsts_task_lib_cert_ca'] = ca;
947946
}
948947

949-
let clientCert: string = _getVariable('Agent.ClientCert');
948+
let clientCert = _getVariable('Agent.ClientCert');
950949
if (clientCert) {
951-
let clientCertKey: string = _getVariable('Agent.ClientCertKey');
952-
let clientCertArchive: string = _getVariable('Agent.ClientCertArchive');
953-
let clientCertPassword: string = _getVariable('Agent.ClientCertPassword');
950+
let clientCertKey: string | undefined = _getVariable('Agent.ClientCertKey');
951+
let clientCertArchive: string | undefined = _getVariable('Agent.ClientCertArchive');
952+
let clientCertPassword: string | undefined = _getVariable('Agent.ClientCertPassword');
954953

955954
global['_vsts_task_lib_cert_clientcert'] = clientCert;
956955
global['_vsts_task_lib_cert_key'] = clientCertKey;
957956
global['_vsts_task_lib_cert_archive'] = clientCertArchive;
958-
global['_vsts_task_lib_cert_passphrase'] = _exposeTaskLibSecret('cert', clientCertPassword);
957+
global['_vsts_task_lib_cert_passphrase'] = _exposeTaskLibSecret('cert', clientCertPassword || '');
959958
}
960959

961960
if (ca || clientCert) {
@@ -972,7 +971,7 @@ export function _exposeCertSettings(): void {
972971
// We store the encryption key on disk and hold the encrypted content and key file in memory
973972
// return base64encoded<keyFilePath>:base64encoded<encryptedContent>
974973
// downstream vsts-node-api will retrieve the secret later
975-
function _exposeTaskLibSecret(keyFile: string, secret: string): string {
974+
function _exposeTaskLibSecret(keyFile: string, secret: string): string | undefined {
976975
if (secret) {
977976
let encryptKey = crypto.randomBytes(256);
978977
let cipher = crypto.createCipher("aes-256-ctr", encryptKey);

node/mock-answer.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,10 @@ export interface TaskLibAnswers {
2121
which?: { [key: string]: string },
2222
}
2323

24-
// TODO TypeScript 2.1: replace with `keyof TaskLibAnswers`
25-
export type MockedCommand = 'checkPath'
26-
| 'cwd'
27-
| 'exec'
28-
| 'exist'
29-
| 'find'
30-
| 'findMatch'
31-
| 'ls'
32-
| 'osType'
33-
| 'rmRF'
34-
| 'stats'
35-
| 'which';
24+
export type MockedCommand = keyof TaskLibAnswers;
3625

3726
export class MockAnswers {
38-
private _answers: TaskLibAnswers;
27+
private _answers: TaskLibAnswers | undefined;
3928

4029
public initialize(answers: TaskLibAnswers) {
4130
if (!answers) {
@@ -55,17 +44,19 @@ export class MockAnswers {
5544
return null;
5645
}
5746

58-
if (this._answers[cmd][key]) {
47+
const cmd_answer = this._answers[cmd]!;
48+
49+
if (cmd_answer[key]) {
5950
debug('found mock response');
60-
return this._answers[cmd][key];
51+
return cmd_answer[key];
6152
}
6253

6354
if (key && process.env['MOCK_NORMALIZE_SLASHES'] === 'true') {
6455
// try normalizing the slashes
6556
var key2 = key.replace(/\\/g, "/");
66-
if (this._answers[cmd][key2]) {
57+
if (cmd_answer[key2]) {
6758
debug('found mock response for normalized key');
68-
return this._answers[cmd][key2];
59+
return cmd_answer[key2];
6960
}
7061
}
7162

node/mock-run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class TaskMockRunner {
77
}
88

99
_taskPath: string;
10-
_answers: ma.TaskLibAnswers;
10+
_answers: ma.TaskLibAnswers | undefined;
1111
_exports: {[key: string]: any} = { };
1212
_moduleCount: number = 0;
1313

node/mock-task.ts

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module.exports.getBoolInput = task.getBoolInput;
6161
module.exports.getDelimitedInput = task.getDelimitedInput;
6262
module.exports.filePathSupplied = task.filePathSupplied;
6363

64-
function getPathInput(name, required, check) {
64+
function getPathInput(name: string, required?: boolean, check?: boolean): string {
6565
var inval = module.exports.getInput(name, required);
6666
if (inval) {
6767
if (check) {
@@ -100,52 +100,52 @@ module.exports.getSecureFileTicket = task.getSecureFileTicket;
100100
//-----------------------------------------------------
101101

102102
export class FsStats implements fs.Stats {
103-
private m_isFile: boolean;
104-
private m_isDirectory: boolean;
105-
private m_isBlockDevice: boolean;
106-
private m_isCharacterDevice: boolean;
107-
private m_isSymbolicLink: boolean;
108-
private m_isFIFO: boolean;
109-
private m_isSocket: boolean;
110-
111-
dev: number;
112-
ino: number;
113-
mode: number;
114-
nlink: number;
115-
uid: number;
116-
gid: number;
117-
rdev: number;
118-
size: number;
119-
blksize: number;
120-
blocks: number;
121-
atime: Date;
122-
mtime: Date;
123-
ctime: Date;
124-
birthtime: Date;
125-
126-
setAnswers(mockResponses) {
127-
this.m_isFile = mockResponses['isFile'] || false;
128-
this.m_isDirectory = mockResponses['isDirectory'] || false;
129-
this.m_isBlockDevice = mockResponses['isBlockDevice'] || false;
130-
this.m_isCharacterDevice = mockResponses['isCharacterDevice'] || false;
131-
this.m_isSymbolicLink = mockResponses['isSymbolicLink'] || false;
132-
this.m_isFIFO = mockResponses['isFIFO'] || false;
133-
this.m_isSocket = mockResponses['isSocket'] || false;
134-
135-
this.dev = mockResponses['dev'];
136-
this.ino = mockResponses['ino'];
137-
this.mode = mockResponses['mode'];
138-
this.nlink = mockResponses['nlink'];
139-
this.uid = mockResponses['uid'];
140-
this.gid = mockResponses['gid'];
141-
this.rdev = mockResponses['rdev'];
142-
this.size = mockResponses['size'];
143-
this.blksize = mockResponses['blksize'];
144-
this.blocks = mockResponses['blocks'];
145-
this.atime = mockResponses['atime'];
146-
this.mtime = mockResponses['mtime'];
147-
this.ctime = mockResponses['ctime'];
148-
this.m_isSocket = mockResponses['isSocket'];
103+
private m_isFile: boolean = false;
104+
private m_isDirectory: boolean = false;
105+
private m_isBlockDevice: boolean = false;
106+
private m_isCharacterDevice: boolean = false;
107+
private m_isSymbolicLink: boolean = false;
108+
private m_isFIFO: boolean = false;
109+
private m_isSocket: boolean = false;
110+
111+
dev: number = 0;
112+
ino: number = 0;
113+
mode: number = 0;
114+
nlink: number = 0;
115+
uid: number = 0;
116+
gid: number = 0;
117+
rdev: number = 0;
118+
size: number = 0;
119+
blksize: number = 0;
120+
blocks: number = 0;
121+
atime: Date = new Date();
122+
mtime: Date = new Date();
123+
ctime: Date = new Date();
124+
birthtime: Date = new Date();
125+
126+
setAnswers(mockResponses: any): void {
127+
this.m_isFile = mockResponses['isFile'] || this.m_isFile;
128+
this.m_isDirectory = mockResponses['isDirectory'] || this.m_isDirectory;
129+
this.m_isBlockDevice = mockResponses['isBlockDevice'] || this.m_isBlockDevice;
130+
this.m_isCharacterDevice = mockResponses['isCharacterDevice'] || this.m_isCharacterDevice;
131+
this.m_isSymbolicLink = mockResponses['isSymbolicLink'] || this.m_isSymbolicLink;
132+
this.m_isFIFO = mockResponses['isFIFO'] || this.m_isFIFO;
133+
this.m_isSocket = mockResponses['isSocket'] || this.m_isSocket;
134+
135+
this.dev = mockResponses['dev'] || this.dev;
136+
this.ino = mockResponses['ino'] || this.ino;
137+
this.mode = mockResponses['mode'] || this.mode;
138+
this.nlink = mockResponses['nlink'] || this.nlink;
139+
this.uid = mockResponses['uid'] || this.uid;
140+
this.gid = mockResponses['gid'] || this.gid;
141+
this.rdev = mockResponses['rdev'] || this.rdev;
142+
this.size = mockResponses['size'] || this.size;
143+
this.blksize = mockResponses['blksize'] || this.blksize;
144+
this.blocks = mockResponses['blocks'] || this.blocks;
145+
this.atime = mockResponses['atime'] || this.atime;
146+
this.mtime = mockResponses['mtime'] || this.mtime;
147+
this.ctime = mockResponses['ctime'] || this.ctime;
148+
this.m_isSocket = mockResponses['isSocket'] || this.m_isSocket;
149149
}
150150

151151
isFile(): boolean {
@@ -354,13 +354,10 @@ export function findMatch(defaultRoot: string, patterns: string[] | string) : st
354354
// Test Publisher
355355
//-----------------------------------------------------
356356
export class TestPublisher {
357-
constructor(testRunner) {
358-
this.testRunner = testRunner;
357+
constructor(public testRunner: string) {
359358
}
360359

361-
public testRunner: string;
362-
363-
public publish(resultFiles, mergeResults, platform, config, runTitle, publishRunAttachments) {
360+
public publish(resultFiles?: string, mergeResults?: string, platform?: string, config?: string, runTitle?: string, publishRunAttachments?: string) {
364361

365362
var properties = <{ [key: string]: string }>{};
366363
properties['type'] = this.testRunner;
@@ -399,7 +396,7 @@ export class TestPublisher {
399396
export class CodeCoveragePublisher {
400397
constructor() {
401398
}
402-
public publish(codeCoverageTool, summaryFileLocation, reportDirectory, additionalCodeCoverageFiles) {
399+
public publish(codeCoverageTool?: string, summaryFileLocation?: string, reportDirectory?: string, additionalCodeCoverageFiles?: string) {
403400

404401
var properties = <{ [key: string]: string }>{};
405402

@@ -452,13 +449,13 @@ exports.ToolRunner = trm.ToolRunner;
452449
//-----------------------------------------------------
453450
// Http Proxy Helper
454451
//-----------------------------------------------------
455-
export function getHttpProxyConfiguration(requestUrl?: string): task.ProxyConfiguration {
452+
export function getHttpProxyConfiguration(requestUrl?: string): task.ProxyConfiguration | null {
456453
return null;
457454
}
458455

459456
//-----------------------------------------------------
460457
// Http Certificate Helper
461458
//-----------------------------------------------------
462-
export function getHttpCertConfiguration(): task.CertConfiguration {
459+
export function getHttpCertConfiguration(): task.CertConfiguration | null {
463460
return null
464461
}

node/mock-test.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,21 @@ const COMMAND_TAG = '[command]';
99
const COMMAND_LENGTH = COMMAND_TAG.length;
1010

1111
export class MockTestRunner {
12-
constructor(testPath: string) {
13-
this._testPath = testPath;
12+
constructor(private _testPath: string) {
1413
}
1514

16-
private _testPath: string;
17-
public stdout: string;
18-
public stderr: string;
19-
public cmdlines: any;
20-
public invokedToolCount: number;
21-
public succeeded: boolean;
22-
public errorIssues: string[];
23-
public warningIssues: string[];
15+
public stdout = '';
16+
public stderr = ''
17+
public cmdlines = {};
18+
public invokedToolCount = 0;
19+
public succeeded = false;
20+
public errorIssues: string[] = [];
21+
public warningIssues: string[] = [];
2422

2523
get failed(): boolean {
2624
return !this.succeeded;
2725
}
28-
26+
2927
public ran(cmdline: string): boolean {
3028
return this.cmdlines.hasOwnProperty(cmdline.trim());
3129
}
@@ -36,14 +34,14 @@ export class MockTestRunner {
3634

3735
public createdWarningIssue(message: string): boolean {
3836
return this.warningIssues.indexOf(message.trim()) >= 0;
39-
}
37+
}
4038

4139
public stdOutContained(message: string): boolean {
42-
return this.stdout && this.stdout.indexOf(message) > 0;
40+
return this.stdout.indexOf(message) > 0;
4341
}
4442

4543
public stdErrContained(message: string): boolean {
46-
return this.stderr && this.stderr.indexOf(message) > 0;
44+
return this.stderr.indexOf(message) > 0;
4745
}
4846

4947
public run(): void {
@@ -59,7 +57,7 @@ export class MockTestRunner {
5957
let nodePath = shelljs.which('node');
6058
if (!nodePath) {
6159
console.error('Could not find node in path');
62-
return;
60+
return;
6361
}
6462

6563
let spawn = cp.spawnSync(nodePath, [this._testPath]);
@@ -80,7 +78,7 @@ export class MockTestRunner {
8078
let traceFile: string = this._testPath + '.log';
8179
lines.forEach((line: string) => {
8280
let ci = line.indexOf('##vso[');
83-
let cmd: cmdm.TaskCommand;
81+
let cmd: cmdm.TaskCommand | undefined;
8482
let cmi = line.indexOf(COMMAND_TAG);
8583
if (ci >= 0) {
8684
cmd = cmdm.commandFromString(line.substring(ci));

0 commit comments

Comments
 (0)