From 7d3302f140c878d7cc007e0a1b2465ed5a21ca98 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 10 May 2019 19:22:17 +0300 Subject: [PATCH] fix: make logger backwards compatible Several plugin use deleted logger methods in their hooks. Same is valid for `nativescript-cloud` extension. To resolve this, get back the deleted methods, we'll delete them in 6.0.0 release. Also, `nativescript-cloud` has an option `--workflow`, that is an object, while ours is boolean. This breaks its transpilation, so set ours to `any`. --- lib/common/definitions/logger.d.ts | 30 ++++++++++++++++++++++ lib/common/logger/logger.ts | 40 ++++++++++++++++++++++------- lib/common/test/unit-tests/stubs.ts | 6 +++++ lib/declarations.d.ts | 2 +- test/stubs.ts | 6 +++++ 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/lib/common/definitions/logger.d.ts b/lib/common/definitions/logger.d.ts index 6077c31d7d..6e098bc4c1 100644 --- a/lib/common/definitions/logger.d.ts +++ b/lib/common/definitions/logger.d.ts @@ -25,6 +25,36 @@ declare global { trace(formatStr?: any, ...args: any[]): void; printMarkdown(...args: any[]): void; prepare(item: any): string; + + /** + * DEPRECATED + * Do not use it. + */ + out(formatStr?: any, ...args: any[]): void; + + /** + * DEPRECATED + * Do not use it. + */ + write(...args: any[]): void; + + /** + * DEPRECATED + * Do not use it. + */ + printInfoMessageOnSameLine(message: string): void; + + /** + * DEPRECATED + * Do not use it. + */ + printMsgWithTimeout(message: string, timeout: number): Promise; + + /** + * DEPRECATED + * Do not use it. + */ + printOnStderr(formatStr?: any, ...args: any[]): void; } interface Log4JSAppenderConfiguration extends Configuration { diff --git a/lib/common/logger/logger.ts b/lib/common/logger/logger.ts index 4768e61e7e..ca80f80747 100644 --- a/lib/common/logger/logger.ts +++ b/lib/common/logger/logger.ts @@ -81,15 +81,6 @@ export class Logger implements ILogger { this.logMessage(args, LoggerLevel.INFO); } - /** - * DEPRECATED - * Present only for backwards compatibility as some plugins (nativescript-plugin-firebase) - * use $logger.out in their hooks - */ - out(...args: any[]): void { - this.info(args); - } - debug(...args: any[]): void { const encodedArgs: string[] = this.getPasswordEncodedArguments(args); this.logMessage(encodedArgs, LoggerLevel.DEBUG); @@ -200,6 +191,37 @@ export class Logger implements ILogger { return argument; }); } + + /******************************************************************************************* + * Metods below are deprecated. Delete them in 6.0.0 release: * + * Present only for backwards compatibility as some plugins (nativescript-plugin-firebase) * + * use these methods in their hooks * + *******************************************************************************************/ + + out(...args: any[]): void { + this.info(args); + } + + write(...args: any[]): void { + this.info(args, { [LoggerConfigData.skipNewLine]: true }); + } + + printOnStderr(...args: string[]): void { + this.error(args); + } + + printInfoMessageOnSameLine(message: string): void { + this.info(message, { [LoggerConfigData.skipNewLine]: true }); + } + + printMsgWithTimeout(message: string, timeout: number): Promise { + return new Promise((resolve, reject) => { + setTimeout(() => { + this.printInfoMessageOnSameLine(message); + resolve(); + }, timeout); + }); + } } $injector.register("logger", Logger); diff --git a/lib/common/test/unit-tests/stubs.ts b/lib/common/test/unit-tests/stubs.ts index b0fb842f02..075dcb4806 100644 --- a/lib/common/test/unit-tests/stubs.ts +++ b/lib/common/test/unit-tests/stubs.ts @@ -45,6 +45,12 @@ export class CommonLoggerStub implements ILogger { printMarkdown(message: string): void { this.output += message; } + + out(formatStr?: any, ...args: any[]): void { } + write(...args: any[]): void { } + printInfoMessageOnSameLine(message: string): void { } + async printMsgWithTimeout(message: string, timeout: number): Promise { } + printOnStderr(formatStr?: any, ...args: any[]): void { } } export class ErrorsStub implements IErrors { diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index 883943db2a..2b2ee41c09 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -570,7 +570,7 @@ interface IOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd, IAvai analyticsLogFile: string; performance: Object; cleanupLogFile: string; - workflow: boolean; + workflow: any; setupOptions(projectData: IProjectData): void; printMessagesForDeprecatedOptions(logger: ILogger): void; } diff --git a/test/stubs.ts b/test/stubs.ts index 5763c9d84c..4a0dde08c2 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -34,6 +34,12 @@ export class LoggerStub implements ILogger { } printMarkdown(message: string): void { } + + out(formatStr?: any, ...args: any[]): void { } + write(...args: any[]): void { } + printInfoMessageOnSameLine(message: string): void { } + async printMsgWithTimeout(message: string, timeout: number): Promise { } + printOnStderr(formatStr?: any, ...args: any[]): void { } } export class FileSystemStub implements IFileSystem {