Skip to content

feat: deprecate markingMode:full #5042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,4 @@ $injector.requirePublicClass("initializeService", "./services/initialize-service
$injector.require("npmConfigService", "./services/npm-config-service");
$injector.require("ipService", "./services/ip-service");
$injector.require("jsonFileSettingsService", "./common/services/json-file-settings-service");
$injector.require("markingModeService", "./services/marking-mode-service");
4 changes: 3 additions & 1 deletion lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
$buildDataService: IBuildDataService,
protected $logger: ILogger,
private $migrateController: IMigrateController) {
private $migrateController: IMigrateController,
private $markingModeService: IMarkingModeService) {
super($options, $errors, $projectData, platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
}

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

if (this.$options.aab) {
Expand Down
6 changes: 4 additions & 2 deletions lib/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ export class DebugAndroidCommand implements ICommand {
constructor(protected $errors: IErrors,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $injector: IInjector,
private $projectData: IProjectData) {
private $projectData: IProjectData,
private $markingModeService: IMarkingModeService) {
this.$projectData.initializeProjectData();
}

public execute(args: string[]): Promise<void> {
public async execute(args: string[]): Promise<void> {
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
return this.debugPlatformCommand.execute(args);
}
public async canExecute(args: string[]): Promise<boolean> {
Expand Down
21 changes: 16 additions & 5 deletions lib/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,42 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
private $mobileHelper: Mobile.IMobileHelper,
$platformsDataService: IPlatformsDataService,
private $deployCommandHelper: DeployCommandHelper,
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
private $markingModeService: IMarkingModeService,
private $migrateController: IMigrateController) {
super($options, $platformsDataService, $platformValidationService, $projectData);
this.$projectData.initializeProjectData();
}

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

await this.$deployCommandHelper.deploy(platform);
}

public async canExecute(args: string[]): Promise<boolean> {
const platform = args[0];
if (!this.$options.force) {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
}

this.$androidBundleValidatorHelper.validateNoAab();
if (!args || !args.length || args.length > 1) {
return false;
}

if (!(await this.$platformCommandParameter.validate(args[0]))) {
if (!(await this.$platformCommandParameter.validate(platform))) {
return false;
}

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

const result = await super.canExecuteCommandBase(args[0], { validateOptions: true });
const result = await super.canExecuteCommandBase(platform, { validateOptions: true });
return result;
}
}
Expand Down
7 changes: 6 additions & 1 deletion lib/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
private $platformCommandParameter: ICommandParameter,
$platformsDataService: IPlatformsDataService,
private $prepareDataService: PrepareDataService,
private $migrateController: IMigrateController) {
private $migrateController: IMigrateController,
private $markingModeService: IMarkingModeService,
private $mobileHelper: Mobile.IMobileHelper) {
super($options, $platformsDataService, $platformValidationService, $projectData);
this.$projectData.initializeProjectData();
}

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

const prepareData = this.$prepareDataService.getPrepareData(this.$projectData.projectDir, platform, this.$options);
await this.$prepareController.prepare(prepareData);
Expand Down
4 changes: 3 additions & 1 deletion lib/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export class PreviewCommand implements ICommand {
private $options: IOptions,
private $previewAppLogProvider: IPreviewAppLogProvider,
private $previewQrCodeService: IPreviewQrCodeService,
$cleanupService: ICleanupService) {
$cleanupService: ICleanupService,
private $markingModeService: IMarkingModeService) {
this.$analyticsService.setShouldDispose(false);
$cleanupService.setShouldDispose(false);
}

public async execute(): Promise<void> {
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
this.$previewAppLogProvider.on(DEVICE_LOG_EVENT_NAME, (deviceId: string, message: string) => {
this.$logger.info(message);
});
Expand Down
4 changes: 3 additions & 1 deletion lib/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ export class RunAndroidCommand implements ICommand {
private $options: IOptions,
private $platformValidationService: IPlatformValidationService,
private $projectData: IProjectData,
private $markingModeService: IMarkingModeService
) { }

public execute(args: string[]): Promise<void> {
public async execute(args: string[]): Promise<void> {
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
return this.runCommand.execute(args);
}

Expand Down
10 changes: 8 additions & 2 deletions lib/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class TestCommandBase {
protected abstract $devicesService: Mobile.IDevicesService;
protected abstract $migrateController: IMigrateController;

async execute(args: string[]): Promise<void> {
public async execute(args: string[]): Promise<void> {
let devices = [];
if (this.$options.debugBrk) {
await this.$devicesService.initialize({
Expand Down Expand Up @@ -102,9 +102,15 @@ class TestAndroidCommand extends TestCommandBase implements ICommand {
protected $cleanupService: ICleanupService,
protected $liveSyncCommandHelper: ILiveSyncCommandHelper,
protected $devicesService: Mobile.IDevicesService,
protected $migrateController: IMigrateController) {
protected $migrateController: IMigrateController,
protected $markingModeService: IMarkingModeService) {
super();
}

public async execute(args: string[]): Promise<void> {
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
await super.execute(args);
}
}

class TestIosCommand extends TestCommandBase implements ICommand {
Expand Down
8 changes: 7 additions & 1 deletion lib/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ export class UpdateCommand implements ICommand {
private $options: IOptions,
private $errors: IErrors,
private $logger: ILogger,
private $projectData: IProjectData) {
private $projectData: IProjectData,
private $markingModeService: IMarkingModeService) {
this.$projectData.initializeProjectData();
}

public async execute(args: string[]): Promise<void> {
if (this.$options.markingMode) {
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, forceSwitch: true });
return;
}

if (!await this.$updateController.shouldUpdate({ projectDir: this.$projectData.projectDir, version: args[0] })) {
this.$logger.printMarkdown(`__${UpdateCommand.PROJECT_UP_TO_DATE_MESSAGE}__`);
return;
Expand Down
8 changes: 5 additions & 3 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export class PrepareController extends EventEmitter {
private $projectDataService: IProjectDataService,
private $webpackCompilerService: IWebpackCompilerService,
private $watchIgnoreListService: IWatchIgnoreListService,
private $analyticsService: IAnalyticsService
private $analyticsService: IAnalyticsService,
private $markingModeService: IMarkingModeService
) { super(); }

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

await this.trackRuntimeVersion(prepareData.platform, projectData);
await this.$pluginsService.ensureAllDependenciesAreInstalled(projectData);
Expand Down Expand Up @@ -187,8 +189,8 @@ export class PrepareController extends EventEmitter {
path.join(projectData.getAppDirectoryPath(), PACKAGE_JSON_FILE_NAME),
path.join(projectData.getAppResourcesRelativeDirectoryPath(), platformData.normalizedPlatformName),
]
.concat(pluginsNativeDirectories)
.concat(pluginsPackageJsonFiles);
.concat(pluginsNativeDirectories)
.concat(pluginsPackageJsonFiles);

return patterns;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/controllers/preview-app-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon
private $previewQrCodeService: IPreviewQrCodeService,
private $previewSdkService: IPreviewSdkService,
private $prepareDataService: PrepareDataService,
private $projectDataService: IProjectDataService
private $projectDataService: IProjectDataService,
private $markingModeService: IMarkingModeService
) { super(); }

public async startPreview(data: IPreviewAppLiveSyncData): Promise<IQrCodeImageData> {
Expand Down Expand Up @@ -57,6 +58,7 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon
const projectData = this.$projectDataService.getProjectData(data.projectDir);
await this.$pluginsService.ensureAllDependenciesAreInstalled(projectData);
await this.$previewSdkService.initialize(data.projectDir, async (device: Device) => {
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: projectData.projectDir });
try {
if (!device) {
this.$errors.fail("Sending initial preview files without a specified device is not supported.");
Expand Down
1 change: 1 addition & 0 deletions lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ interface IOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd, IAvai
cleanupLogFile: string;
appleApplicationSpecificPassword: string;
appleSessionBase64: string;
markingMode: boolean;
}

interface IEnvOptions {
Expand Down
9 changes: 9 additions & 0 deletions lib/definitions/marking-mode-service.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface IMarkingModeService {
handleMarkingModeFullDeprecation(options: IMarkingModeFullDeprecationOptions): Promise<void>;
}

interface IMarkingModeFullDeprecationOptions {
projectDir: string;
skipWarnings?: boolean;
forceSwitch?: boolean;
}
1 change: 1 addition & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class Options {
certificate: { type: OptionType.String, hasSensitiveValue: true },
certificatePassword: { type: OptionType.String, hasSensitiveValue: true },
release: { type: OptionType.Boolean, alias: "r", hasSensitiveValue: false },
markingMode: { type: OptionType.Boolean, hasSensitiveValue: false },
var: { type: OptionType.Object, hasSensitiveValue: true },
default: { type: OptionType.Boolean, hasSensitiveValue: false },
count: { type: OptionType.Number, hasSensitiveValue: false },
Expand Down
74 changes: 74 additions & 0 deletions lib/services/marking-mode-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as helpers from "../common/helpers";
import * as path from "path";
import { EOL } from "os";
import { PACKAGE_JSON_FILE_NAME, LoggerConfigData } from "../constants";

const enum MarkingMode {
None = "none",
Full = "full"
}

const MARKING_MODE_PROP = "markingMode";
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.`;
const MARKING_MODE_NONE_CONFIRM_MSG = `Do you want to switch your app to the recommended "${MARKING_MODE_PROP}:${MarkingMode.None}"?
More info about the reasons for this change can be found in the link below:
https://www.nativescript.org/blog/markingmode-none-is-official-boost-android-performance-while-avoiding-memory-issues`;

export class MarkingModeService implements IMarkingModeService {

constructor(private $fs: IFileSystem,
private $logger: ILogger,
private $projectDataService: IProjectDataService,
private $prompter: IPrompter
) {
}

public async handleMarkingModeFullDeprecation(options: IMarkingModeFullDeprecationOptions): Promise<void> {
const { projectDir, skipWarnings, forceSwitch } = options;
const projectData = this.$projectDataService.getProjectData(projectDir);
const innerPackageJsonPath = path.join(projectData.getAppDirectoryPath(projectDir), PACKAGE_JSON_FILE_NAME);
if (!this.$fs.exists(innerPackageJsonPath)) {
return;
}

const innerPackageJson = this.$fs.readJson(innerPackageJsonPath);
let markingModeValue = (innerPackageJson && innerPackageJson.android
&& typeof (innerPackageJson.android[MARKING_MODE_PROP]) === "string" && innerPackageJson.android[MARKING_MODE_PROP]) || "";

if (forceSwitch) {
this.setMarkingMode(innerPackageJsonPath, innerPackageJson, MarkingMode.None);
return;
}

if (!markingModeValue && helpers.isInteractive()) {
this.$logger.info();
this.$logger.printMarkdown(`
__Improve your app by switching to "${MARKING_MODE_PROP}:${MarkingMode.None}".__

\`${MARKING_MODE_FULL_DEPRECATION_MSG}\``);
const hasSwitched = await this.$prompter.confirm(MARKING_MODE_NONE_CONFIRM_MSG, () => true);

markingModeValue = hasSwitched ? MarkingMode.None : MarkingMode.Full;
this.setMarkingMode(innerPackageJsonPath, innerPackageJson, markingModeValue);
}

if (!skipWarnings && markingModeValue.toLowerCase() !== MarkingMode.None) {
this.showMarkingModeFullWarning();
}
}

private setMarkingMode(packagePath: string, packageValue: any, newMode: string) {
packageValue = packageValue || {};
packageValue.android = packageValue.android || {};
packageValue.android[MARKING_MODE_PROP] = newMode;
this.$fs.writeJson(packagePath, packageValue);
}

private showMarkingModeFullWarning() {
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'.`;

this.$logger.warn(markingModeFullWarning, { [LoggerConfigData.wrapMessageWithBorders]: true });
}
}

$injector.register("markingModeService", MarkingModeService);
Empty file.
3 changes: 2 additions & 1 deletion test/package-installation-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import * as yok from "../lib/common/yok";
import ChildProcessLib = require("../lib/common/child-process");
import { SettingsService } from "../lib/common/test/unit-tests/stubs";
import { ProjectDataService } from "../lib/services/project-data-service";
import { ProjectDataStub } from "./stubs";
import { MarkingModeServiceStub, ProjectDataStub } from "./stubs";

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

testInjector.register("markingModeService", MarkingModeServiceStub);
testInjector.register("projectData", ProjectDataStub);
testInjector.register("config", ConfigLib.Configuration);
testInjector.register("logger", LoggerLib.Logger);
Expand Down
2 changes: 2 additions & 0 deletions test/platform-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Messages } from "../lib/common/messages/messages";
import { SettingsService } from "../lib/common/test/unit-tests/stubs";
import { PlatformValidationService } from "../lib/services/platform/platform-validation-service";
import { PlatformCommandHelper } from "../lib/helpers/platform-command-helper";
import { MarkingModeServiceStub } from "./stubs";

let isCommandExecuted = true;

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

testInjector.register("injector", testInjector);
testInjector.register("markingModeService", MarkingModeServiceStub);
testInjector.register("hooksService", stubs.HooksServiceStub);
testInjector.register("staticConfig", StaticConfigLib.StaticConfig);
testInjector.register("nodeModulesDependenciesBuilder", {});
Expand Down
3 changes: 2 additions & 1 deletion test/services/playground/preview-app-livesync-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Yok } from "../../../lib/common/yok";
import * as _ from 'lodash';
import { LoggerStub, ErrorsStub } from "../../stubs";
import { LoggerStub, ErrorsStub, MarkingModeServiceStub } from "../../stubs";
import { FilePayload, Device, FilesPayload } from "nativescript-preview-sdk";
import * as chai from "chai";
import * as path from "path";
Expand Down Expand Up @@ -116,6 +116,7 @@ function createTestInjector(options?: {

const injector = new Yok();
injector.register("logger", LoggerMock);
injector.register("markingModeService", MarkingModeServiceStub);
injector.register("hmrStatusService", {
attachToHmrStatusEvent: () => ({})
});
Expand Down
3 changes: 2 additions & 1 deletion test/services/project-data-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Yok } from "../../lib/common/yok";
import { assert } from "chai";
import { ProjectDataService } from "../../lib/services/project-data-service";
import { LoggerStub, ProjectDataStub } from "../stubs";
import { LoggerStub, ProjectDataStub, MarkingModeServiceStub } from "../stubs";
import { NATIVESCRIPT_PROPS_INTERNAL_DELIMITER, PACKAGE_JSON_FILE_NAME, CONFIG_NS_FILE_NAME, AssetConstants, ProjectTypes } from '../../lib/constants';
import { DevicePlatformsConstants } from "../../lib/common/mobile/device-platforms-constants";
import { basename, join } from "path";
Expand Down Expand Up @@ -74,6 +74,7 @@ const createTestInjector = (packageJsonContent?: string, nsConfigContent?: strin
});

testInjector.register("logger", LoggerStub);
testInjector.register("markingModeService", MarkingModeServiceStub);

testInjector.register("projectDataService", ProjectDataService);

Expand Down
Loading