Skip to content

Commit 0341a15

Browse files
committed
feat: don't leak android debugging session and remove deprecated methods from logger
#4219
1 parent 81efc59 commit 0341a15

File tree

13 files changed

+58
-191
lines changed

13 files changed

+58
-191
lines changed

lib/common/definitions/logger.d.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,6 @@ declare global {
2525
trace(formatStr?: any, ...args: any[]): void;
2626
printMarkdown(...args: any[]): void;
2727
prepare(item: any): string;
28-
29-
/**
30-
* DEPRECATED
31-
* Do not use it.
32-
*/
33-
out(formatStr?: any, ...args: any[]): void;
34-
35-
/**
36-
* DEPRECATED
37-
* Do not use it.
38-
*/
39-
write(...args: any[]): void;
40-
41-
/**
42-
* DEPRECATED
43-
* Do not use it.
44-
*/
45-
printInfoMessageOnSameLine(message: string): void;
46-
47-
/**
48-
* DEPRECATED
49-
* Do not use it.
50-
*/
51-
printMsgWithTimeout(message: string, timeout: number): Promise<void>;
52-
53-
/**
54-
* DEPRECATED
55-
* Do not use it.
56-
*/
57-
printOnStderr(formatStr?: any, ...args: any[]): void;
5828
}
5929

6030
interface Log4JSAppenderConfiguration extends Configuration {

lib/common/logger/logger.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -191,37 +191,6 @@ export class Logger implements ILogger {
191191
return argument;
192192
});
193193
}
194-
195-
/*******************************************************************************************
196-
* Metods below are deprecated. Delete them in 6.0.0 release: *
197-
* Present only for backwards compatibility as some plugins (nativescript-plugin-firebase) *
198-
* use these methods in their hooks *
199-
*******************************************************************************************/
200-
201-
out(...args: any[]): void {
202-
this.info(args);
203-
}
204-
205-
write(...args: any[]): void {
206-
this.info(args, { [LoggerConfigData.skipNewLine]: true });
207-
}
208-
209-
printOnStderr(...args: string[]): void {
210-
this.error(args);
211-
}
212-
213-
printInfoMessageOnSameLine(message: string): void {
214-
this.info(message, { [LoggerConfigData.skipNewLine]: true });
215-
}
216-
217-
printMsgWithTimeout(message: string, timeout: number): Promise<void> {
218-
return new Promise<void>((resolve, reject) => {
219-
setTimeout(() => {
220-
this.printInfoMessageOnSameLine(message);
221-
resolve();
222-
}, timeout);
223-
});
224-
}
225194
}
226195

227196
$injector.register("logger", Logger);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ export class AndroidProcessService implements Mobile.IAndroidProcessService {
88
private _forwardedLocalPorts: IDictionary<number>;
99

1010
constructor(private $errors: IErrors,
11+
private $cleanupService: ICleanupService,
1112
private $injector: IInjector,
12-
private $net: INet) {
13+
private $net: INet,
14+
private $staticConfig: IStaticConfig) {
1315
this._devicesAdbs = {};
1416
this._forwardedLocalPorts = {};
1517
}
@@ -120,8 +122,7 @@ export class AndroidProcessService implements Mobile.IAndroidProcessService {
120122
}
121123

122124
this._forwardedLocalPorts[portForwardInputData.deviceIdentifier] = localPort;
123-
// TODO: Uncomment for 6.0.0 release
124-
// await this.$cleanupService.addCleanupCommand({ command: await this.$staticConfig.getAdbFilePath(), args: ["-s", portForwardInputData.deviceIdentifier, "forward", "--remove", `tcp:${localPort}`] });
125+
await this.$cleanupService.addCleanupCommand({ command: await this.$staticConfig.getAdbFilePath(), args: ["-s", portForwardInputData.deviceIdentifier, "forward", "--remove", `tcp:${localPort}`] });
125126
return localPort && +localPort;
126127
}
127128

lib/common/services/commands-service.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,8 @@ export class CommandsService implements ICommandsService {
2727
private $staticConfig: Config.IStaticConfig,
2828
private $helpService: IHelpService,
2929
private $extensibilityService: IExtensibilityService,
30-
private $optionsTracker: IOptionsTracker,
31-
private $projectDataService: IProjectDataService) {
32-
let projectData = null;
33-
try {
34-
projectData = this.$projectDataService.getProjectData();
35-
} catch (err) {
36-
this.$logger.trace(`Error while trying to get project data. More info: ${err}`);
37-
}
38-
39-
this.$options.setupOptions(projectData);
40-
this.$options.printMessagesForDeprecatedOptions(this.$logger);
30+
private $optionsTracker: IOptionsTracker) {
31+
this.$options.setupOptions();
4132
}
4233

4334
public allCommands(opts: { includeDevCommands: boolean }): string[] {

lib/declarations.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,7 @@ interface IOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd, IAvai
557557
analyticsLogFile: string;
558558
performance: Object;
559559
cleanupLogFile: string;
560-
setupOptions(projectData: IProjectData): void;
561-
printMessagesForDeprecatedOptions(logger: ILogger): void;
560+
setupOptions(): void;
562561
}
563562

564563
interface IEnvOptions {

lib/definitions/project.d.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,6 @@ interface IProjectDataService {
142142
*/
143143
setNSValue(projectDir: string, key: string, value: any): void;
144144

145-
/**
146-
* Sets a value in the `useLegacyWorkflow` key in a project's nsconfig.json.
147-
* @param {string} projectDir The project directory - the place where the root package.json is located.
148-
* @param {any} value Value of the key to be set to `useLegacyWorkflow` key in project's nsconfig.json.
149-
* @returns {void}
150-
*/
151-
setUseLegacyWorkflow(projectDir: string, value: any): void;
152-
153145
/**
154146
* Removes a property from `nativescript` key in project's package.json.
155147
* @param {string} projectDir The project directory - the place where the root package.json is located.

lib/options.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,18 @@ export class Options {
2121

2222
public options: IDictionary<IDashedOption>;
2323

24-
public setupOptions(projectData: IProjectData): void {
24+
public setupOptions(): void {
2525
if (this.argv.release && this.argv.hmr) {
2626
this.$errors.failWithoutHelp("The options --release and --hmr cannot be used simultaneously.");
2727
}
2828

29-
// HACK: temporary solution for 5.3.0 release (until the webpack only feature)
30-
const parsed = require("yargs-parser")(process.argv.slice(2), { 'boolean-negation': false });
31-
const noBundle = parsed && (parsed.bundle === false || parsed.bundle === 'false');
32-
if (noBundle && this.argv.hmr) {
33-
this.$errors.failWithoutHelp("The options --no-bundle and --hmr cannot be used simultaneously.");
34-
}
35-
36-
if (projectData && projectData.useLegacyWorkflow === false) {
37-
this.argv.bundle = this.argv.bundle !== undefined ? this.argv.bundle : "webpack";
38-
this.argv.hmr = !this.argv.release;
39-
}
29+
this.argv.bundle = "webpack";
4030

31+
const parsed = require("yargs-parser")(process.argv.slice(2), { 'boolean-negation': false });
4132
// --no-hmr -> hmr: false or --hmr false -> hmr: 'false'
4233
const noHmr = parsed && (parsed.hmr === false || parsed.hmr === 'false');
43-
if (noHmr) {
44-
this.argv.hmr = false;
45-
}
46-
47-
if (noBundle) {
48-
this.argv.bundle = undefined;
49-
this.argv.hmr = false;
34+
if (!noHmr) {
35+
this.argv.hmr = !this.argv.release;
5036
}
5137

5238
if (this.argv.debugBrk) {
@@ -207,16 +193,6 @@ export class Options {
207193
});
208194
}
209195

210-
public printMessagesForDeprecatedOptions($logger: ILogger) {
211-
if (this.argv.platformTemplate) {
212-
$logger.warn(`"--platformTemplate" option has been deprecated and will be removed in the upcoming NativeScript CLI v6.0.0. More info can be found in this issue https://github.com/NativeScript/nativescript-cli/issues/4518.`);
213-
}
214-
215-
if (this.argv.syncAllFiles) {
216-
$logger.warn(`"--syncAllFiles" option has been deprecated and will be removed in the upcoming NativeScript CLI v6.0.0. More info can be found in this issue https://github.com/NativeScript/nativescript-cli/issues/4518.`);
217-
}
218-
}
219-
220196
private getCorrectOptionName(optionName: string): string {
221197
const secondaryOptionName = this.getNonDashedOptionName(optionName);
222198
return _.includes(this.optionNames, secondaryOptionName) ? secondaryOptionName : optionName;

lib/services/android-device-debug-service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ export class AndroidDeviceDebugService extends DebugServiceBase implements IDevi
1313

1414
constructor(protected device: Mobile.IAndroidDevice,
1515
protected $devicesService: Mobile.IDevicesService,
16+
protected $cleanupService: ICleanupService,
1617
private $errors: IErrors,
1718
private $logger: ILogger,
1819
private $androidProcessService: Mobile.IAndroidProcessService,
20+
private $staticConfig: IStaticConfig,
1921
private $net: INet,
2022
private $deviceLogProvider: Mobile.IDeviceLogProvider) {
2123

@@ -69,8 +71,7 @@ export class AndroidDeviceDebugService extends DebugServiceBase implements IDevi
6971
await this.unixSocketForward(port, `${unixSocketName}`);
7072
}
7173

72-
// TODO: Uncomment for 6.0.0 release
73-
// await this.$cleanupService.addCleanupCommand({ command: await this.$staticConfig.getAdbFilePath(), args: ["-s", deviceId, "forward", "--remove", `tcp:${port}`] });
74+
await this.$cleanupService.addCleanupCommand({ command: await this.$staticConfig.getAdbFilePath(), args: ["-s", deviceId, "forward", "--remove", `tcp:${port}`] });
7475

7576
return port;
7677
}

lib/services/project-data-service.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as path from "path";
2-
import * as constants from "../constants";
32
import { ProjectData } from "../project-data";
43
import { exported } from "../common/decorators";
54
import {
@@ -139,13 +138,6 @@ export class ProjectDataService implements IProjectDataService {
139138
};
140139
}
141140

142-
public setUseLegacyWorkflow(projectDir: string, value: any): void {
143-
this.$logger.trace(`useLegacyWorkflow will be set to ${value}`);
144-
this.updateNsConfigValue(projectDir, { useLegacyWorkflow: value });
145-
this.refreshProjectData(projectDir);
146-
this.$logger.trace(`useLegacyWorkflow was set to ${value}`);
147-
}
148-
149141
public getAppExecutableFiles(projectDir: string): string[] {
150142
const projectData = this.getProjectData(projectDir);
151143

@@ -179,33 +171,6 @@ export class ProjectDataService implements IProjectDataService {
179171
return files;
180172
}
181173

182-
private refreshProjectData(projectDir: string) {
183-
if (this.projectDataCache[projectDir]) {
184-
this.projectDataCache[projectDir].initializeProjectData(projectDir);
185-
}
186-
}
187-
188-
private updateNsConfigValue(projectDir: string, updateObject: INsConfig): void {
189-
const nsConfigPath = path.join(projectDir, constants.CONFIG_NS_FILE_NAME);
190-
const currentNsConfig = this.getNsConfig(nsConfigPath);
191-
const newNsConfig = Object.assign(currentNsConfig, updateObject);
192-
193-
this.$fs.writeJson(nsConfigPath, newNsConfig);
194-
}
195-
196-
private getNsConfig(nsConfigPath: string): INsConfig {
197-
let result = this.getNsConfigDefaultObject();
198-
if (this.$fs.exists(nsConfigPath)) {
199-
try {
200-
result = <INsConfig>this.$fs.readJson(nsConfigPath);
201-
} catch (e) {
202-
// default
203-
}
204-
}
205-
206-
return result;
207-
}
208-
209174
private getImageDefinitions(): IImageDefinitionsStructure {
210175
const pathToImageDefinitions = path.join(__dirname, "..", "..", CLI_RESOURCES_DIR_NAME, AssetConstants.assets, AssetConstants.imageDefinitionsFileName);
211176
const imageDefinitions = this.$fs.readJson(pathToImageDefinitions);

0 commit comments

Comments
 (0)