Skip to content

Commit 4c560c6

Browse files
author
Dimitar Tachev
authored
Merge pull request #5042 from NativeScript/tachev/marking-mode-warnings
feat: deprecate `markingMode:full`
2 parents 72f0d56 + 04b2ee1 commit 4c560c6

22 files changed

+160
-21
lines changed

lib/bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,4 @@ $injector.requirePublicClass("initializeService", "./services/initialize-service
232232
$injector.require("npmConfigService", "./services/npm-config-service");
233233
$injector.require("ipService", "./services/ip-service");
234234
$injector.require("jsonFileSettingsService", "./common/services/json-file-settings-service");
235+
$injector.require("markingModeService", "./services/marking-mode-service");

lib/commands/build.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
9797
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
9898
$buildDataService: IBuildDataService,
9999
protected $logger: ILogger,
100-
private $migrateController: IMigrateController) {
100+
private $migrateController: IMigrateController,
101+
private $markingModeService: IMarkingModeService) {
101102
super($options, $errors, $projectData, platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
102103
}
103104

104105
public async execute(args: string[]): Promise<void> {
106+
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
105107
await this.executeCore([this.$devicePlatformsConstants.Android.toLowerCase()]);
106108

107109
if (this.$options.aab) {

lib/commands/debug.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ export class DebugAndroidCommand implements ICommand {
157157
constructor(protected $errors: IErrors,
158158
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
159159
private $injector: IInjector,
160-
private $projectData: IProjectData) {
160+
private $projectData: IProjectData,
161+
private $markingModeService: IMarkingModeService) {
161162
this.$projectData.initializeProjectData();
162163
}
163164

164-
public execute(args: string[]): Promise<void> {
165+
public async execute(args: string[]): Promise<void> {
166+
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
165167
return this.debugPlatformCommand.execute(args);
166168
}
167169
public async canExecute(args: string[]): Promise<boolean> {

lib/commands/deploy.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,42 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
1818
private $mobileHelper: Mobile.IMobileHelper,
1919
$platformsDataService: IPlatformsDataService,
2020
private $deployCommandHelper: DeployCommandHelper,
21-
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
21+
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
22+
private $markingModeService: IMarkingModeService,
23+
private $migrateController: IMigrateController) {
2224
super($options, $platformsDataService, $platformValidationService, $projectData);
2325
this.$projectData.initializeProjectData();
2426
}
2527

2628
public async execute(args: string[]): Promise<void> {
27-
const platform = args[0].toLowerCase();
29+
const platform = args[0];
30+
if (this.$mobileHelper.isAndroidPlatform(platform)) {
31+
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
32+
}
33+
2834
await this.$deployCommandHelper.deploy(platform);
2935
}
3036

3137
public async canExecute(args: string[]): Promise<boolean> {
38+
const platform = args[0];
39+
if (!this.$options.force) {
40+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
41+
}
42+
3243
this.$androidBundleValidatorHelper.validateNoAab();
3344
if (!args || !args.length || args.length > 1) {
3445
return false;
3546
}
3647

37-
if (!(await this.$platformCommandParameter.validate(args[0]))) {
48+
if (!(await this.$platformCommandParameter.validate(platform))) {
3849
return false;
3950
}
4051

41-
if (this.$mobileHelper.isAndroidPlatform(args[0]) && this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
52+
if (this.$mobileHelper.isAndroidPlatform(platform) && this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
4253
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
4354
}
4455

45-
const result = await super.canExecuteCommandBase(args[0], { validateOptions: true });
56+
const result = await super.canExecuteCommandBase(platform, { validateOptions: true });
4657
return result;
4758
}
4859
}

lib/commands/prepare.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
1717
private $platformCommandParameter: ICommandParameter,
1818
$platformsDataService: IPlatformsDataService,
1919
private $prepareDataService: PrepareDataService,
20-
private $migrateController: IMigrateController) {
20+
private $migrateController: IMigrateController,
21+
private $markingModeService: IMarkingModeService,
22+
private $mobileHelper: Mobile.IMobileHelper) {
2123
super($options, $platformsDataService, $platformValidationService, $projectData);
2224
this.$projectData.initializeProjectData();
2325
}
2426

2527
public async execute(args: string[]): Promise<void> {
2628
const platform = args[0];
29+
if (this.$mobileHelper.isAndroidPlatform(platform)) {
30+
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
31+
}
2732

2833
const prepareData = this.$prepareDataService.getPrepareData(this.$projectData.projectDir, platform, this.$options);
2934
await this.$prepareController.prepare(prepareData);

lib/commands/preview.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ export class PreviewCommand implements ICommand {
1313
private $options: IOptions,
1414
private $previewAppLogProvider: IPreviewAppLogProvider,
1515
private $previewQrCodeService: IPreviewQrCodeService,
16-
$cleanupService: ICleanupService) {
16+
$cleanupService: ICleanupService,
17+
private $markingModeService: IMarkingModeService) {
1718
this.$analyticsService.setShouldDispose(false);
1819
$cleanupService.setShouldDispose(false);
1920
}
2021

2122
public async execute(): Promise<void> {
23+
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
2224
this.$previewAppLogProvider.on(DEVICE_LOG_EVENT_NAME, (deviceId: string, message: string) => {
2325
this.$logger.info(message);
2426
});

lib/commands/run.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ export class RunAndroidCommand implements ICommand {
113113
private $options: IOptions,
114114
private $platformValidationService: IPlatformValidationService,
115115
private $projectData: IProjectData,
116+
private $markingModeService: IMarkingModeService
116117
) { }
117118

118-
public execute(args: string[]): Promise<void> {
119+
public async execute(args: string[]): Promise<void> {
120+
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
119121
return this.runCommand.execute(args);
120122
}
121123

lib/commands/test.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class TestCommandBase {
1616
protected abstract $devicesService: Mobile.IDevicesService;
1717
protected abstract $migrateController: IMigrateController;
1818

19-
async execute(args: string[]): Promise<void> {
19+
public async execute(args: string[]): Promise<void> {
2020
let devices = [];
2121
if (this.$options.debugBrk) {
2222
await this.$devicesService.initialize({
@@ -102,9 +102,15 @@ class TestAndroidCommand extends TestCommandBase implements ICommand {
102102
protected $cleanupService: ICleanupService,
103103
protected $liveSyncCommandHelper: ILiveSyncCommandHelper,
104104
protected $devicesService: Mobile.IDevicesService,
105-
protected $migrateController: IMigrateController) {
105+
protected $migrateController: IMigrateController,
106+
protected $markingModeService: IMarkingModeService) {
106107
super();
107108
}
109+
110+
public async execute(args: string[]): Promise<void> {
111+
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
112+
await super.execute(args);
113+
}
108114
}
109115

110116
class TestIosCommand extends TestCommandBase implements ICommand {

lib/commands/update.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ export class UpdateCommand implements ICommand {
1010
private $options: IOptions,
1111
private $errors: IErrors,
1212
private $logger: ILogger,
13-
private $projectData: IProjectData) {
13+
private $projectData: IProjectData,
14+
private $markingModeService: IMarkingModeService) {
1415
this.$projectData.initializeProjectData();
1516
}
1617

1718
public async execute(args: string[]): Promise<void> {
19+
if (this.$options.markingMode) {
20+
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, forceSwitch: true });
21+
return;
22+
}
23+
1824
if (!await this.$updateController.shouldUpdate({ projectDir: this.$projectData.projectDir, version: args[0] })) {
1925
this.$logger.printMarkdown(`__${UpdateCommand.PROJECT_UP_TO_DATE_MESSAGE}__`);
2026
return;

lib/controllers/prepare-controller.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ export class PrepareController extends EventEmitter {
2727
private $projectDataService: IProjectDataService,
2828
private $webpackCompilerService: IWebpackCompilerService,
2929
private $watchIgnoreListService: IWatchIgnoreListService,
30-
private $analyticsService: IAnalyticsService
30+
private $analyticsService: IAnalyticsService,
31+
private $markingModeService: IMarkingModeService
3132
) { super(); }
3233

3334
public async prepare(prepareData: IPrepareData): Promise<IPrepareResultData> {
3435
const projectData = this.$projectDataService.getProjectData(prepareData.projectDir);
36+
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: projectData.projectDir });
3537

3638
await this.trackRuntimeVersion(prepareData.platform, projectData);
3739
await this.$pluginsService.ensureAllDependenciesAreInstalled(projectData);
@@ -187,8 +189,8 @@ export class PrepareController extends EventEmitter {
187189
path.join(projectData.getAppDirectoryPath(), PACKAGE_JSON_FILE_NAME),
188190
path.join(projectData.getAppResourcesRelativeDirectoryPath(), platformData.normalizedPlatformName),
189191
]
190-
.concat(pluginsNativeDirectories)
191-
.concat(pluginsPackageJsonFiles);
192+
.concat(pluginsNativeDirectories)
193+
.concat(pluginsPackageJsonFiles);
192194

193195
return patterns;
194196
}

lib/controllers/preview-app-controller.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon
2828
private $previewQrCodeService: IPreviewQrCodeService,
2929
private $previewSdkService: IPreviewSdkService,
3030
private $prepareDataService: PrepareDataService,
31-
private $projectDataService: IProjectDataService
31+
private $projectDataService: IProjectDataService,
32+
private $markingModeService: IMarkingModeService
3233
) { super(); }
3334

3435
public async startPreview(data: IPreviewAppLiveSyncData): Promise<IQrCodeImageData> {
@@ -57,6 +58,7 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon
5758
const projectData = this.$projectDataService.getProjectData(data.projectDir);
5859
await this.$pluginsService.ensureAllDependenciesAreInstalled(projectData);
5960
await this.$previewSdkService.initialize(data.projectDir, async (device: Device) => {
61+
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: projectData.projectDir });
6062
try {
6163
if (!device) {
6264
this.$errors.fail("Sending initial preview files without a specified device is not supported.");

lib/declarations.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ interface IOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd, IAvai
574574
cleanupLogFile: string;
575575
appleApplicationSpecificPassword: string;
576576
appleSessionBase64: string;
577+
markingMode: boolean;
577578
}
578579

579580
interface IEnvOptions {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
interface IMarkingModeService {
2+
handleMarkingModeFullDeprecation(options: IMarkingModeFullDeprecationOptions): Promise<void>;
3+
}
4+
5+
interface IMarkingModeFullDeprecationOptions {
6+
projectDir: string;
7+
skipWarnings?: boolean;
8+
forceSwitch?: boolean;
9+
}

lib/options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export class Options {
136136
certificate: { type: OptionType.String, hasSensitiveValue: true },
137137
certificatePassword: { type: OptionType.String, hasSensitiveValue: true },
138138
release: { type: OptionType.Boolean, alias: "r", hasSensitiveValue: false },
139+
markingMode: { type: OptionType.Boolean, hasSensitiveValue: false },
139140
var: { type: OptionType.Object, hasSensitiveValue: true },
140141
default: { type: OptionType.Boolean, hasSensitiveValue: false },
141142
count: { type: OptionType.Number, hasSensitiveValue: false },

lib/services/marking-mode-service.ts

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import * as helpers from "../common/helpers";
2+
import * as path from "path";
3+
import { EOL } from "os";
4+
import { PACKAGE_JSON_FILE_NAME, LoggerConfigData } from "../constants";
5+
6+
const enum MarkingMode {
7+
None = "none",
8+
Full = "full"
9+
}
10+
11+
const MARKING_MODE_PROP = "markingMode";
12+
const MARKING_MODE_FULL_DEPRECATION_MSG = `With the upcoming NativeScript 7.0 the "${MARKING_MODE_PROP}:${MarkingMode.None}" will become the only marking mode supported by the Android Runtime.`;
13+
const MARKING_MODE_NONE_CONFIRM_MSG = `Do you want to switch your app to the recommended "${MARKING_MODE_PROP}:${MarkingMode.None}"?
14+
More info about the reasons for this change can be found in the link below:
15+
https://www.nativescript.org/blog/markingmode-none-is-official-boost-android-performance-while-avoiding-memory-issues`;
16+
17+
export class MarkingModeService implements IMarkingModeService {
18+
19+
constructor(private $fs: IFileSystem,
20+
private $logger: ILogger,
21+
private $projectDataService: IProjectDataService,
22+
private $prompter: IPrompter
23+
) {
24+
}
25+
26+
public async handleMarkingModeFullDeprecation(options: IMarkingModeFullDeprecationOptions): Promise<void> {
27+
const { projectDir, skipWarnings, forceSwitch } = options;
28+
const projectData = this.$projectDataService.getProjectData(projectDir);
29+
const innerPackageJsonPath = path.join(projectData.getAppDirectoryPath(projectDir), PACKAGE_JSON_FILE_NAME);
30+
if (!this.$fs.exists(innerPackageJsonPath)) {
31+
return;
32+
}
33+
34+
const innerPackageJson = this.$fs.readJson(innerPackageJsonPath);
35+
let markingModeValue = (innerPackageJson && innerPackageJson.android
36+
&& typeof (innerPackageJson.android[MARKING_MODE_PROP]) === "string" && innerPackageJson.android[MARKING_MODE_PROP]) || "";
37+
38+
if (forceSwitch) {
39+
this.setMarkingMode(innerPackageJsonPath, innerPackageJson, MarkingMode.None);
40+
return;
41+
}
42+
43+
if (!markingModeValue && helpers.isInteractive()) {
44+
this.$logger.info();
45+
this.$logger.printMarkdown(`
46+
__Improve your app by switching to "${MARKING_MODE_PROP}:${MarkingMode.None}".__
47+
48+
\`${MARKING_MODE_FULL_DEPRECATION_MSG}\``);
49+
const hasSwitched = await this.$prompter.confirm(MARKING_MODE_NONE_CONFIRM_MSG, () => true);
50+
51+
markingModeValue = hasSwitched ? MarkingMode.None : MarkingMode.Full;
52+
this.setMarkingMode(innerPackageJsonPath, innerPackageJson, markingModeValue);
53+
}
54+
55+
if (!skipWarnings && markingModeValue.toLowerCase() !== MarkingMode.None) {
56+
this.showMarkingModeFullWarning();
57+
}
58+
}
59+
60+
private setMarkingMode(packagePath: string, packageValue: any, newMode: string) {
61+
packageValue = packageValue || {};
62+
packageValue.android = packageValue.android || {};
63+
packageValue.android[MARKING_MODE_PROP] = newMode;
64+
this.$fs.writeJson(packagePath, packageValue);
65+
}
66+
67+
private showMarkingModeFullWarning() {
68+
const markingModeFullWarning = `You are using the deprecated "${MARKING_MODE_PROP}:${MarkingMode.Full}".${EOL}${EOL}${MARKING_MODE_FULL_DEPRECATION_MSG}${EOL}${EOL}You should update your marking mode by executing 'tns update --markingMode'.`;
69+
70+
this.$logger.warn(markingModeFullWarning, { [LoggerConfigData.wrapMessageWithBorders]: true });
71+
}
72+
}
73+
74+
$injector.register("markingModeService", MarkingModeService);

lib/services/workflow/workflow.d.ts

Whitespace-only changes.

test/package-installation-manager.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import * as yok from "../lib/common/yok";
1414
import ChildProcessLib = require("../lib/common/child-process");
1515
import { SettingsService } from "../lib/common/test/unit-tests/stubs";
1616
import { ProjectDataService } from "../lib/services/project-data-service";
17-
import { ProjectDataStub } from "./stubs";
17+
import { MarkingModeServiceStub, ProjectDataStub } from "./stubs";
1818

1919
function createTestInjector(): IInjector {
2020
const testInjector = new yok.Yok();
2121

22+
testInjector.register("markingModeService", MarkingModeServiceStub);
2223
testInjector.register("projectData", ProjectDataStub);
2324
testInjector.register("config", ConfigLib.Configuration);
2425
testInjector.register("logger", LoggerLib.Logger);

test/platform-commands.ts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Messages } from "../lib/common/messages/messages";
2121
import { SettingsService } from "../lib/common/test/unit-tests/stubs";
2222
import { PlatformValidationService } from "../lib/services/platform/platform-validation-service";
2323
import { PlatformCommandHelper } from "../lib/helpers/platform-command-helper";
24+
import { MarkingModeServiceStub } from "./stubs";
2425

2526
let isCommandExecuted = true;
2627

@@ -103,6 +104,7 @@ function createTestInjector() {
103104
const testInjector = new yok.Yok();
104105

105106
testInjector.register("injector", testInjector);
107+
testInjector.register("markingModeService", MarkingModeServiceStub);
106108
testInjector.register("hooksService", stubs.HooksServiceStub);
107109
testInjector.register("staticConfig", StaticConfigLib.StaticConfig);
108110
testInjector.register("nodeModulesDependenciesBuilder", {});

test/services/playground/preview-app-livesync-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Yok } from "../../../lib/common/yok";
22
import * as _ from 'lodash';
3-
import { LoggerStub, ErrorsStub } from "../../stubs";
3+
import { LoggerStub, ErrorsStub, MarkingModeServiceStub } from "../../stubs";
44
import { FilePayload, Device, FilesPayload } from "nativescript-preview-sdk";
55
import * as chai from "chai";
66
import * as path from "path";
@@ -116,6 +116,7 @@ function createTestInjector(options?: {
116116

117117
const injector = new Yok();
118118
injector.register("logger", LoggerMock);
119+
injector.register("markingModeService", MarkingModeServiceStub);
119120
injector.register("hmrStatusService", {
120121
attachToHmrStatusEvent: () => ({})
121122
});

test/services/project-data-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Yok } from "../../lib/common/yok";
22
import { assert } from "chai";
33
import { ProjectDataService } from "../../lib/services/project-data-service";
4-
import { LoggerStub, ProjectDataStub } from "../stubs";
4+
import { LoggerStub, ProjectDataStub, MarkingModeServiceStub } from "../stubs";
55
import { NATIVESCRIPT_PROPS_INTERNAL_DELIMITER, PACKAGE_JSON_FILE_NAME, CONFIG_NS_FILE_NAME, AssetConstants, ProjectTypes } from '../../lib/constants';
66
import { DevicePlatformsConstants } from "../../lib/common/mobile/device-platforms-constants";
77
import { basename, join } from "path";
@@ -74,6 +74,7 @@ const createTestInjector = (packageJsonContent?: string, nsConfigContent?: strin
7474
});
7575

7676
testInjector.register("logger", LoggerStub);
77+
testInjector.register("markingModeService", MarkingModeServiceStub);
7778

7879
testInjector.register("projectDataService", ProjectDataService);
7980

0 commit comments

Comments
 (0)