Skip to content

feat: show error when the project is not migrated and is not compatible for 6.0 release #4824

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 7 commits into from
Jul 10, 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: 0 additions & 1 deletion lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ $injector.require("devicePathProvider", "./device-path-provider");

$injector.requireCommand("platform|clean", "./commands/platform-clean");

$injector.require("bundleValidatorHelper", "./helpers/bundle-validator-helper");
$injector.require("androidBundleValidatorHelper", "./helpers/android-bundle-validator-helper");
$injector.require("liveSyncCommandHelper", "./helpers/livesync-command-helper");
$injector.require("deployCommandHelper", "./helpers/deploy-command-helper");
Expand Down
8 changes: 6 additions & 2 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
$buildController: IBuildController,
$platformValidationService: IPlatformValidationService,
$logger: ILogger,
$buildDataService: IBuildDataService) {
$buildDataService: IBuildDataService,
private $migrateController: IMigrateController) {
super($options, $errors, $projectData, $platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
}

Expand All @@ -72,6 +73,7 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
}

public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
const platform = this.$devicePlatformsConstants.iOS;

super.validatePlatform(platform);
Expand Down Expand Up @@ -99,7 +101,8 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
$platformValidationService: IPlatformValidationService,
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
$buildDataService: IBuildDataService,
protected $logger: ILogger) {
protected $logger: ILogger,
private $migrateController: IMigrateController) {
super($options, $errors, $projectData, platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
}

Expand All @@ -116,6 +119,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
}

public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
const platform = this.$devicePlatformsConstants.Android;
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
Expand Down
5 changes: 4 additions & 1 deletion lib/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
private $debugDataService: IDebugDataService,
private $debugController: IDebugController,
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
private $migrateController: IMigrateController) {
super($options, $platformsDataService, $platformValidationService, $projectData);
$cleanupService.setShouldDispose(false);
}
Expand Down Expand Up @@ -52,6 +53,8 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
}

public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });

this.$androidBundleValidatorHelper.validateNoAab();

if (!this.$platformValidationService.isPlatformSupportedForOS(this.platform, this.$projectData)) {
Expand Down
6 changes: 4 additions & 2 deletions lib/commands/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export class MigrateCommand implements ICommand {
}

public async execute(args: string[]): Promise<void> {
await this.$migrateController.migrate({projectDir: this.$projectData.projectDir});
await this.$migrateController.migrate({ projectDir: this.$projectData.projectDir });
}

public async canExecute(args: string[]): Promise<boolean> {
if (!await this.$migrateController.shouldMigrate({ projectDir: this.$projectData.projectDir })) {
const shouldMigrateResult = await this.$migrateController.shouldMigrate({ projectDir: this.$projectData.projectDir });

if (!shouldMigrateResult) {
this.$errors.failWithoutHelp('Project is compatible with NativeScript "v6.0.0". To get the latest NativesScript packages execute "tns update".');
}

Expand Down
4 changes: 3 additions & 1 deletion lib/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
$projectData: IProjectData,
private $platformCommandParameter: ICommandParameter,
$platformsDataService: IPlatformsDataService,
private $prepareDataService: PrepareDataService) {
private $prepareDataService: PrepareDataService,
private $migrateController: IMigrateController) {
super($options, $platformsDataService, $platformValidationService, $projectData);
this.$projectData.initializeProjectData();
}
Expand All @@ -29,6 +30,7 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
}

public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
const platform = args[0];
const result = await this.$platformCommandParameter.validate(platform) &&
await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
Expand Down
5 changes: 3 additions & 2 deletions lib/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export class PreviewCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];

constructor(private $analyticsService: IAnalyticsService,
private $bundleValidatorHelper: IBundleValidatorHelper,
private $errors: IErrors,
private $logger: ILogger,
private $migrateController: IMigrateController,
private $previewAppController: IPreviewAppController,
private $networkConnectivityValidator: INetworkConnectivityValidator,
private $projectData: IProjectData,
Expand Down Expand Up @@ -41,8 +41,9 @@ export class PreviewCommand implements ICommand {
this.$errors.fail(`The arguments '${args.join(" ")}' are not valid for the preview command.`);
}

await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });

await this.$networkConnectivityValidator.validate();
this.$bundleValidatorHelper.validate(this.$projectData, "1.0.0");
return true;
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class RunCommandBase implements ICommand {
private $errors: IErrors,
private $hostInfo: IHostInfo,
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
private $migrateController: IMigrateController,
private $projectData: IProjectData
) { }

Expand All @@ -27,6 +28,8 @@ export class RunCommandBase implements ICommand {
this.$errors.fail(ERROR_NO_VALID_SUBCOMMAND_FORMAT, "run");
}

await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });

this.$androidBundleValidatorHelper.validateNoAab();

this.$projectData.initializeProjectData();
Expand Down
9 changes: 7 additions & 2 deletions lib/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ abstract class TestCommandBase {
protected abstract $cleanupService: ICleanupService;
protected abstract $liveSyncCommandHelper: ILiveSyncCommandHelper;
protected abstract $devicesService: Mobile.IDevicesService;
protected abstract $migrateController: IMigrateController;

async execute(args: string[]): Promise<void> {
let devices = [];
Expand Down Expand Up @@ -48,6 +49,8 @@ abstract class TestCommandBase {
}

async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });

this.$projectData.initializeProjectData();
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
this.$cleanupService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
Expand Down Expand Up @@ -86,7 +89,8 @@ class TestAndroidCommand extends TestCommandBase implements ICommand {
protected $errors: IErrors,
protected $cleanupService: ICleanupService,
protected $liveSyncCommandHelper: ILiveSyncCommandHelper,
protected $devicesService: Mobile.IDevicesService) {
protected $devicesService: Mobile.IDevicesService,
protected $migrateController: IMigrateController) {
super();
}
}
Expand All @@ -102,7 +106,8 @@ class TestIosCommand extends TestCommandBase implements ICommand {
protected $errors: IErrors,
protected $cleanupService: ICleanupService,
protected $liveSyncCommandHelper: ILiveSyncCommandHelper,
protected $devicesService: Mobile.IDevicesService) {
protected $devicesService: Mobile.IDevicesService,
protected $migrateController: IMigrateController) {
super();
}

Expand Down
41 changes: 32 additions & 9 deletions lib/controllers/migrate-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { UpdateControllerBase } from "./update-controller-base";
import { fromWindowsRelativePathToUnix } from "../common/helpers";

export class MigrateController extends UpdateControllerBase implements IMigrateController {
// TODO: Update the links to blog post when it is available
private static COMMON_MIGRATE_MESSAGE = "not affect the codebase of the application and you might need to do additional changes manually – for more information, refer to the instructions in the following blog post: <link to blog post>.";
private static UNABLE_TO_MIGRATE_APP_ERROR = `The current application is not compatible with NativeScript CLI 6.0.
Use the \`tns migrate\` command to migrate the app dependencies to a form compatible with NativeScript 6.0.
Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
private static MIGRATE_FINISH_MESSAGE = `The \`tns migrate\` command does ${MigrateController.COMMON_MIGRATE_MESSAGE}`;

constructor(
protected $fs: IFileSystem,
protected $platformCommandHelper: IPlatformCommandHelper,
Expand Down Expand Up @@ -68,10 +75,17 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
{ packageName: "nativescript-cardview", verifiedVersion: "3.2.0" },
{
packageName: "nativescript-unit-test-runner", verifiedVersion: "0.6.4",
shouldMigrateAction: (projectData: IProjectData) => this.hasDependency({ packageName: "nativescript-unit-test-runner", isDev: false }, projectData),
shouldMigrateAction: async (projectData: IProjectData) => {
const dependency = { packageName: "nativescript-unit-test-runner", verifiedVersion: "0.6.4", isDev: false };
const result = this.hasDependency(dependency, projectData) && await this.shouldMigrateDependencyVersion(dependency, projectData);
return result;
},
migrateAction: this.migrateUnitTestRunner.bind(this)
},
{ packageName: MigrateController.typescriptPackageName, isDev: true, getVerifiedVersion: this.getAngularTypeScriptVersion.bind(this) }
{ packageName: MigrateController.typescriptPackageName, isDev: true, getVerifiedVersion: this.getAngularTypeScriptVersion.bind(this) },
{ packageName: "nativescript-localize", verifiedVersion: "4.2.0" },
{ packageName: "nativescript-dev-babel", verifiedVersion: "0.2.1" },
{ packageName: "nativescript-nfc", verifiedVersion: "4.0.1" }
];

get verifiedPlatformVersions(): IDictionary<string> {
Expand Down Expand Up @@ -112,6 +126,8 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
this.restoreBackup(MigrateController.folders, backupDir, projectData.projectDir);
this.$errors.failWithoutHelp(`${MigrateController.migrateFailMessage} The error is: ${error}`);
}

this.$logger.info(MigrateController.MIGRATE_FINISH_MESSAGE);
}

public async shouldMigrate({ projectDir }: IProjectDir): Promise<boolean> {
Expand All @@ -121,7 +137,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
const dependency = this.migrationDependencies[i];
const hasDependency = this.hasDependency(dependency, projectData);

if (hasDependency && dependency.shouldMigrateAction && dependency.shouldMigrateAction(projectData)) {
if (hasDependency && dependency.shouldMigrateAction && await dependency.shouldMigrateAction(projectData)) {
return true;
}

Expand All @@ -136,20 +152,27 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
if (!hasDependency && dependency.shouldAddIfMissing) {
return true;
}
}

if (!this.$androidResourcesMigrationService.hasMigrated(projectData.getAppResourcesDirectoryPath())) {
return true;
}
if (!this.$androidResourcesMigrationService.hasMigrated(projectData.getAppResourcesDirectoryPath())) {
return true;
}

for (const platform in this.$devicePlatformsConstants) {
const hasRuntimeDependency = this.hasRuntimeDependency({ platform, projectData });
if (!hasRuntimeDependency || await this.shouldUpdateRuntimeVersion({ targetVersion: this.verifiedPlatformVersions[platform.toLowerCase()], platform, projectData })) {
if (hasRuntimeDependency && await this.shouldUpdateRuntimeVersion({ targetVersion: this.verifiedPlatformVersions[platform.toLowerCase()], platform, projectData })) {
return true;
}
}
}

public async validate({ projectDir }: IProjectDir): Promise<void> {
const shouldMigrate = await this.shouldMigrate({ projectDir });
if (shouldMigrate) {
this.$errors.failWithoutHelp(MigrateController.UNABLE_TO_MIGRATE_APP_ERROR);
}
}

private async getAngularTypeScriptVersion(projectData: IProjectData): Promise<string> {
let verifiedVersion = "3.4.1";
try {
Expand Down Expand Up @@ -254,7 +277,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
const dependency = this.migrationDependencies[i];
const hasDependency = this.hasDependency(dependency, projectData);

if (hasDependency && dependency.migrateAction && dependency.shouldMigrateAction(projectData)) {
if (hasDependency && dependency.migrateAction && await dependency.shouldMigrateAction(projectData)) {
const newDependencies = await dependency.migrateAction(projectData, path.join(projectData.projectDir, MigrateController.backupFolder));
for (const newDependency of newDependencies) {
await this.migrateDependency(newDependency, projectData);
Expand All @@ -267,7 +290,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
for (const platform in this.$devicePlatformsConstants) {
const lowercasePlatform = platform.toLowerCase();
const hasRuntimeDependency = this.hasRuntimeDependency({ platform, projectData });
if (!hasRuntimeDependency || await this.shouldUpdateRuntimeVersion({ targetVersion: this.verifiedPlatformVersions[lowercasePlatform], platform, projectData })) {
if (hasRuntimeDependency && await this.shouldUpdateRuntimeVersion({ targetVersion: this.verifiedPlatformVersions[lowercasePlatform], platform, projectData })) {
const verifiedPlatformVersion = this.verifiedPlatformVersions[lowercasePlatform];
const platformData = this.$platformsDataService.getPlatformData(lowercasePlatform, projectData);
this.$logger.info(`Updating ${platform} platform to version '${verifiedPlatformVersion}'.`);
Expand Down
3 changes: 0 additions & 3 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class PrepareController extends EventEmitter {
private persistedData: IFilesChangeEventData[] = [];

constructor(
private $bundleValidatorHelper: IBundleValidatorHelper,
private $platformController: IPlatformController,
public $hooksService: IHooksService,
private $logger: ILogger,
Expand Down Expand Up @@ -55,8 +54,6 @@ export class PrepareController extends EventEmitter {
@performanceLog()
@hook("prepare")
private async prepareCore(prepareData: IPrepareData, projectData: IProjectData): Promise<IPrepareResultData> {
this.$bundleValidatorHelper.validate(projectData, "1.0.0");

await this.$platformController.addPlatformIfNeeded(prepareData);

this.$logger.info("Preparing project...");
Expand Down
3 changes: 2 additions & 1 deletion lib/definitions/migrate.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface IMigrateController {
migrate(migrateData: IProjectDir): Promise<void>;
shouldMigrate(data: IProjectDir): Promise<boolean>;
validate(data: IProjectDir): Promise<void>;
}

interface IDependency {
Expand All @@ -15,6 +16,6 @@ interface IMigrationDependency extends IDependency {
verifiedVersion?: string;
getVerifiedVersion?: (projectData: IProjectData) => Promise<string>;
shouldAddIfMissing?: boolean;
shouldMigrateAction?: (projectData: IProjectData) => boolean;
shouldMigrateAction?: (projectData: IProjectData) => Promise<boolean>;
migrateAction?: (projectData: IProjectData, migrationBackupDirPath: string) => Promise<IMigrationDependency[]>;
}
40 changes: 0 additions & 40 deletions lib/helpers/bundle-validator-helper.ts

This file was deleted.

4 changes: 0 additions & 4 deletions test/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ function createTestInjector(data: { hasNativeChanges: boolean }): IInjector {
isFileInIgnoreList: () => false
});

injector.register("bundleValidatorHelper", {
validate: () => ({})
});

const prepareController: PrepareController = injector.resolve("prepareController");
prepareController.emit = (eventName: string, eventData: any) => {
emittedEventNames.push(eventName);
Expand Down
Loading