Skip to content

Commit 96d4d0e

Browse files
NathanWalkerrigor789
authored andcommitted
chore: update to es2020 taraget
1 parent b0acd67 commit 96d4d0e

37 files changed

+3492
-2593
lines changed

lib/common/bootstrap.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
(<ICliGlobal>global)._ = require("lodash");
2-
(<ICliGlobal>global).$injector = require("./yok").injector;
1+
(<ICliGlobal><unknown>global)._ = require("lodash");
2+
(<ICliGlobal><unknown>global).$injector = require("./yok").injector;
33

44
require("colors");
55
$injector.require("errors", "./errors");

lib/common/declarations.d.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ interface Object {
44

55
interface IStringDictionary extends IDictionary<string> { }
66

7+
declare enum Platforms {
8+
ios = 'ios',
9+
android = 'android'
10+
}
11+
type SupportedPlatform = Platforms.ios | Platforms.android;
12+
713
/**
814
* Describes iTunes Connect application types
915
*/
@@ -268,7 +274,7 @@ interface IReadFileOptions {
268274
/**
269275
* Defines the encoding. Defaults to null.
270276
*/
271-
encoding: string;
277+
encoding?: BufferEncoding | null;
272278

273279
/**
274280
* Defines file flags. Defaults to "r".
@@ -344,9 +350,9 @@ interface IFileSystem {
344350
* Reads the entire contents of a file.
345351
* @param {string} filename Path to the file that has to be read.
346352
* @param {string} @optional options Options used for reading the file - encoding and flags.
347-
* @returns {string|NodeBuffer} Content of the file as buffer. In case encoding is specified, the content is returned as string.
353+
* @returns {string|Buffer} Content of the file as buffer. In case encoding is specified, the content is returned as string.
348354
*/
349-
readFile(filename: string, options?: IReadFileOptions): string | NodeBuffer;
355+
readFile(filename: string, options?: IReadFileOptions): string | Buffer;
350356

351357
/**
352358
* Reads the entire contents of a file and returns the result as string.
@@ -369,20 +375,20 @@ interface IFileSystem {
369375
/**
370376
* Writes data to a file, replacing the file if it already exists. data can be a string or a buffer.
371377
* @param {string} filename Path to file to be created.
372-
* @param {string | NodeBuffer} data Data to be written to file.
378+
* @param {string | Buffer} data Data to be written to file.
373379
* @param {string} encoding @optional File encoding, defaults to utf8.
374380
* @returns {void}
375381
*/
376-
writeFile(filename: string, data: string | NodeBuffer, encoding?: string): void;
382+
writeFile(filename: string, data: string | Buffer, encoding?: string): void;
377383

378384
/**
379385
* Appends data to a file, creating the file if it does not yet exist. Data can be a string or a buffer.
380386
* @param {string} filename Path to file to be created.
381-
* @param {string | NodeBuffer} data Data to be appended to file.
387+
* @param {string | Buffer} data Data to be appended to file.
382388
* @param {string} encoding @optional File encoding, defaults to utf8.
383389
* @returns {void}
384390
*/
385-
appendFile(filename: string, data: string | NodeBuffer, encoding?: string): void;
391+
appendFile(filename: string, data: string | Buffer, encoding?: string): void;
386392

387393
/**
388394
* Writes JSON data to file.

lib/common/errors.ts

+15-14
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function Exception() {
1111

1212
Exception.prototype = new Error();
1313

14-
function resolveCallStack(error: Error): string {
14+
async function resolveCallStack(error: Error): Promise<string> {
1515
const stackLines: string[] = error.stack.split("\n");
1616
const parsed = _.map(stackLines, (line: string): any => {
1717
let match = line.match(/^\s*at ([^(]*) \((.*?):([0-9]+):([0-9]+)\)$/);
@@ -28,9 +28,9 @@ function resolveCallStack(error: Error): string {
2828
return line;
2929
});
3030

31-
const fs = require("fs");
31+
const fs = require("fs");
3232

33-
const remapped = _.map(parsed, (parsedLine) => {
33+
const remapped = await Promise.all(_.map(parsed, async (parsedLine) => {
3434
if (_.isString(parsedLine)) {
3535
return parsedLine;
3636
}
@@ -47,15 +47,16 @@ function resolveCallStack(error: Error): string {
4747

4848
const mapData = JSON.parse(fs.readFileSync(mapFileName).toString());
4949

50-
const consumer = new SourceMapConsumer(mapData);
51-
const sourcePos = consumer.originalPositionFor({ line: line, column: column });
52-
if (sourcePos && sourcePos.source) {
53-
const source = path.join(path.dirname(fileName), sourcePos.source);
54-
return util.format(" at %s (%s:%s:%s)", functionName, source, sourcePos.line, sourcePos.column);
55-
}
56-
57-
return util.format(" at %s (%s:%s:%s)", functionName, fileName, line, column);
58-
});
50+
return await SourceMapConsumer.with(mapData, mapFileName, (consumer) => {
51+
const sourcePos = consumer.originalPositionFor({ line: line, column: column });
52+
if (sourcePos && sourcePos.source) {
53+
const source = path.join(path.dirname(fileName), sourcePos.source);
54+
return util.format(" at %s (%s:%s:%s)", functionName, source, sourcePos.line, sourcePos.column);
55+
}
56+
57+
return util.format(" at %s (%s:%s:%s)", functionName, fileName, line, column);
58+
});
59+
}));
5960

6061
let outputMessage = remapped.join("\n");
6162

@@ -73,7 +74,7 @@ export function installUncaughtExceptionListener(actionOnException?: () => void)
7374
let callstack = err.stack;
7475
if (callstack) {
7576
try {
76-
callstack = resolveCallStack(err);
77+
callstack = await resolveCallStack(err);
7778
} catch (err) {
7879
console.error("Error while resolving callStack:", err);
7980
}
@@ -178,7 +179,7 @@ export class Errors implements IErrors {
178179
const logger = this.$injector.resolve("logger");
179180
const loggerLevel: string = logger.getLevel().toUpperCase();
180181
const printCallStack = this.printCallStack || loggerLevel === "TRACE" || loggerLevel === "DEBUG";
181-
const message = printCallStack ? resolveCallStack(ex) : isInteractive() ? `\x1B[31;1m${ex.message}\x1B[0m` : ex.message;
182+
const message = printCallStack ? await resolveCallStack(ex) : isInteractive() ? `\x1B[31;1m${ex.message}\x1B[0m` : ex.message;
182183

183184
if (ex.printOnStdout) {
184185
logger.info(message);

lib/common/file-system.ts

+20-11
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import * as shelljs from "shelljs";
77
import { parseJson } from "./helpers";
88
import { PACKAGE_JSON_FILE_NAME } from "../constants";
99
import { EOL } from "os";
10-
import stringifyPackage = require("stringify-package");
11-
import detectNewline = require("detect-newline");
10+
import stringifyPackage from "stringify-package";
11+
import detectNewline from "detect-newline";
1212

1313
// TODO: Add .d.ts for mkdirp module (or use it from @types repo).
1414
const mkdirp = require("mkdirp");
@@ -185,7 +185,7 @@ export class FileSystem implements IFileSystem {
185185
options = options || { encoding: "utf8" };
186186

187187
if (_.isString(options)) {
188-
options = { encoding: options };
188+
options = { encoding: <BufferEncoding>options };
189189
}
190190

191191
if (!options.encoding) {
@@ -210,11 +210,11 @@ export class FileSystem implements IFileSystem {
210210
// clean any null or undefined data
211211
data = '';
212212
}
213-
fs.writeFileSync(filename, data, { encoding: encoding });
213+
fs.writeFileSync(filename, data, { encoding: <BufferEncoding>encoding });
214214
}
215215

216216
public appendFile(filename: string, data: any, encoding?: string): void {
217-
fs.appendFileSync(filename, data, { encoding: encoding });
217+
fs.appendFileSync(filename, data, { encoding: <BufferEncoding>encoding });
218218
}
219219

220220
public writeJson(filename: string, data: any, space?: string, encoding?: string): void {
@@ -257,18 +257,27 @@ export class FileSystem implements IFileSystem {
257257

258258
public createReadStream(path: string, options?: {
259259
flags?: string;
260-
encoding?: string;
261-
fd?: number;
262-
mode?: number;
263-
bufferSize?: number;
260+
encoding?: BufferEncoding;
261+
fd?: number;
262+
mode?: number;
263+
autoClose?: boolean;
264+
emitClose?: boolean;
265+
start?: number;
266+
end?: number;
267+
highWaterMark?: number;
264268
}): NodeJS.ReadableStream {
265269
return fs.createReadStream(path, options);
266270
}
267271

268272
public createWriteStream(path: string, options?: {
269273
flags?: string;
270-
encoding?: string;
271-
string?: string;
274+
encoding?: BufferEncoding;
275+
fd?: number;
276+
mode?: number;
277+
autoClose?: boolean;
278+
emitClose?: boolean;
279+
start?: number;
280+
highWaterMark?: number;
272281
}): any {
273282
return fs.createWriteStream(path, options);
274283
}

lib/common/helpers.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,16 @@ export function getRelativeToRootPath(rootPath: string, filePath: string): strin
273273
return relativeToRootPath;
274274
}
275275

276+
let customIsInteractive: any;
277+
278+
export function setIsInteractive(override?: () => boolean) {
279+
customIsInteractive = override;
280+
}
281+
276282
export function isInteractive(): boolean {
283+
if (customIsInteractive) {
284+
return customIsInteractive();
285+
}
277286
const result = isRunningInTTY() && !isCIEnvironment();
278287
return result;
279288
}
@@ -406,12 +415,12 @@ export function parseJson(data: string): any {
406415
}
407416

408417
// TODO: Use generic for predicatе predicate: (element: T|T[]) when TypeScript support this.
409-
export async function getFuturesResults<T>(promises: Promise<T | T[]>[], predicate: (element: any) => boolean): Promise<T[]> {
418+
export async function getFuturesResults<T>(promises: Promise<T | T[] | T[][]>[], predicate: (element: any) => boolean): Promise<T[] | T[][]> {
410419
const results = await Promise.all(promises);
411420

412421
return _(results)
413422
.filter(predicate)
414-
.flatten<T>()
423+
.flatten()
415424
.value();
416425
}
417426

lib/common/logger/appenders/cli-appender.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function cliAppender(layout: Function) {
1313
return appender;
1414
}
1515

16-
function configure(config: Log4JSAppenderConfiguration, layouts: any) {
16+
export function configure(config: Log4JSAppenderConfiguration, layouts: any) {
1717
// the default layout for the appender
1818
let layout = layouts.messagePassThroughLayout;
1919

@@ -25,5 +25,3 @@ function configure(config: Log4JSAppenderConfiguration, layouts: any) {
2525
// create a new appender instance
2626
return cliAppender(layout);
2727
}
28-
29-
exports.configure = configure;

lib/common/logger/appenders/emit-appender.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function emitAppender(layout: Function, emitter: EventEmitter) {
1414
return appender;
1515
}
1616

17-
function configure(config: Log4JSEmitAppenderConfiguration, layouts: any) {
17+
export function configure(config: Log4JSEmitAppenderConfiguration, layouts: any) {
1818
if (!config.emitter) {
1919
throw new Error("Emitter must be passed to emit-appender");
2020
}
@@ -34,5 +34,3 @@ function configure(config: Log4JSEmitAppenderConfiguration, layouts: any) {
3434
// create a new appender instance
3535
return emitAppender(layout, config.emitter);
3636
}
37-
38-
exports.configure = configure;

lib/common/mobile/android/logcat-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import byline = require("byline");
1+
import byline from "byline";
22
import { DeviceAndroidDebugBridge } from "./device-android-debug-bridge";
33
import { ChildProcess } from "child_process";
44
import * as semver from "semver";

lib/common/mobile/ios/device/ios-device-operations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IOSDeviceLib as IOSDeviceLibModule } from "ios-device-lib";
22
import { cache } from "../../../decorators";
33
import { DEVICE_LOG_EVENT_NAME } from "../../../constants";
4-
import assert = require("assert");
4+
import assert from "assert";
55
import { EventEmitter } from "events";
66

77
export class IOSDeviceOperations extends EventEmitter implements IIOSDeviceOperations, IDisposable, IShouldDispose {

lib/common/mobile/mobile-core/android-device-discovery.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ export class AndroidDeviceDiscovery extends DeviceDiscovery implements Mobile.IA
5656
});
5757

5858
_(this._devices)
59-
.reject(d => _.find(currentDevices, device => device.identifier === d.identifier && device.status === d.status))
59+
.reject(d => <any>_.find(currentDevices, device => device.identifier === d.identifier && device.status === d.status))
6060
.each((d: IAdbAndroidDeviceInfo) => this.deleteAndRemoveDevice(d.identifier));
6161

6262
await Promise.all(_(currentDevices)
63-
.reject(d => _.find(this._devices, device => device.identifier === d.identifier && device.status === d.status))
63+
.reject(d => <any>_.find(this._devices, device => device.identifier === d.identifier && device.status === d.status))
6464
.map((d: IAdbAndroidDeviceInfo) => this.createAndAddDevice(d)).value());
6565
}
6666

lib/common/mobile/mobile-core/android-process-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class AndroidProcessService implements Mobile.IAndroidProcessService {
101101
.filter(deviceAppInfo => !!deviceAppInfo)
102102
.groupBy(element => element.framework)
103103
.map((group: Mobile.IDeviceApplicationInformation[]) => _.uniqBy(group, g => g.appIdentifier))
104-
.flatten<Mobile.IDeviceApplicationInformation>()
104+
.flatten()
105105
.value();
106106
}
107107

lib/common/opener.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import xopen = require("open");
1+
import xopen from "open";
22

33
export class Opener implements IOpener {
44

lib/common/prompter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ export class Prompter implements IPrompter {
7878
}
7979

8080
public async promptForChoice(promptMessage: string, choices: string[]): Promise<string> {
81-
const schema: prompt.Question = {
81+
const schema: prompt.Answers = {
8282
message: promptMessage,
8383
type: "list",
8484
name: "userAnswer",
85-
choices: choices
85+
choices
8686
};
8787

8888
const result = await this.get([schema]);

lib/common/services/help-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from "path";
22
import { EOL } from "os";
3-
import marked = require("marked");
3+
import marked from "marked";
44
import { CommandsDelimiters } from "../constants";
55

66
interface IHtmlPageGenerationData {

lib/common/services/lock-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class LockService implements ILockService {
9393

9494
fileOpts.retriesObj = fileOpts.retriesObj || {};
9595
if (fileOpts.retries) {
96-
fileOpts.retriesObj.retries = fileOpts.retries;
96+
fileOpts.retriesObj.retries = <number>fileOpts.retries;
9797
}
9898

9999
if (fileOpts.retryWait) {

lib/common/services/net-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Net implements INet {
1515
return new Promise<number>((resolve, reject) => {
1616
let isResolved = false;
1717
server.listen(0, () => {
18-
const portUsed = server.address().port;
18+
const portUsed = (<net.AddressInfo>server.address()).port;
1919
server.close();
2020

2121
if (!isResolved) {

lib/common/services/project-files-manager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import minimatch = require("minimatch");
1+
import minimatch from "minimatch";
22
import * as path from "path";
33
import * as util from "util";
44

lib/common/test/test-bootstrap.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
(<ICliGlobal>global)._ = require("lodash");
2-
(<ICliGlobal>global).$injector = require("../yok").injector;
1+
(<ICliGlobal><unknown>global)._ = require("lodash");
2+
(<ICliGlobal><unknown>global).$injector = require("../yok").injector;
33
$injector.require("hostInfo", "../host-info");
44
$injector.register("config", {});
55

@@ -15,5 +15,5 @@ $injector.register("analyticsService", {
1515
});
1616

1717
// Converts the js callstack to typescript
18-
import errors = require("../errors");
19-
errors.installUncaughtExceptionListener();
18+
import { installUncaughtExceptionListener } from "../errors";
19+
installUncaughtExceptionListener();

0 commit comments

Comments
 (0)