Skip to content

Commit 497605a

Browse files
authored
Merge pull request #4824 from NativeScript/fatme/should-migrate
feat: show error when the project is not migrated and is not compatible for 6.0 release
2 parents 3ba3fc6 + bb0a216 commit 497605a

14 files changed

+64
-175
lines changed

lib/bootstrap.ts

-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ $injector.require("devicePathProvider", "./device-path-provider");
144144

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

147-
$injector.require("bundleValidatorHelper", "./helpers/bundle-validator-helper");
148147
$injector.require("androidBundleValidatorHelper", "./helpers/android-bundle-validator-helper");
149148
$injector.require("liveSyncCommandHelper", "./helpers/livesync-command-helper");
150149
$injector.require("deployCommandHelper", "./helpers/deploy-command-helper");

lib/commands/build.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
6363
$buildController: IBuildController,
6464
$platformValidationService: IPlatformValidationService,
6565
$logger: ILogger,
66-
$buildDataService: IBuildDataService) {
66+
$buildDataService: IBuildDataService,
67+
private $migrateController: IMigrateController) {
6768
super($options, $errors, $projectData, $platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
6869
}
6970

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

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

7779
super.validatePlatform(platform);
@@ -99,7 +101,8 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
99101
$platformValidationService: IPlatformValidationService,
100102
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
101103
$buildDataService: IBuildDataService,
102-
protected $logger: ILogger) {
104+
protected $logger: ILogger,
105+
private $migrateController: IMigrateController) {
103106
super($options, $errors, $projectData, platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
104107
}
105108

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

118121
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
122+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
119123
const platform = this.$devicePlatformsConstants.Android;
120124
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
121125
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });

lib/commands/debug.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
1616
private $debugDataService: IDebugDataService,
1717
private $debugController: IDebugController,
1818
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
19-
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
19+
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
20+
private $migrateController: IMigrateController) {
2021
super($options, $platformsDataService, $platformValidationService, $projectData);
2122
$cleanupService.setShouldDispose(false);
2223
}
@@ -52,6 +53,8 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
5253
}
5354

5455
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
56+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
57+
5558
this.$androidBundleValidatorHelper.validateNoAab();
5659

5760
if (!this.$platformValidationService.isPlatformSupportedForOS(this.platform, this.$projectData)) {

lib/commands/migrate.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ export class MigrateCommand implements ICommand {
99
}
1010

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

1515
public async canExecute(args: string[]): Promise<boolean> {
16-
if (!await this.$migrateController.shouldMigrate({ projectDir: this.$projectData.projectDir })) {
16+
const shouldMigrateResult = await this.$migrateController.shouldMigrate({ projectDir: this.$projectData.projectDir });
17+
18+
if (!shouldMigrateResult) {
1719
this.$errors.failWithoutHelp('Project is compatible with NativeScript "v6.0.0". To get the latest NativesScript packages execute "tns update".');
1820
}
1921

lib/commands/prepare.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
1616
$projectData: IProjectData,
1717
private $platformCommandParameter: ICommandParameter,
1818
$platformsDataService: IPlatformsDataService,
19-
private $prepareDataService: PrepareDataService) {
19+
private $prepareDataService: PrepareDataService,
20+
private $migrateController: IMigrateController) {
2021
super($options, $platformsDataService, $platformValidationService, $projectData);
2122
this.$projectData.initializeProjectData();
2223
}
@@ -29,6 +30,7 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
2930
}
3031

3132
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
33+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
3234
const platform = args[0];
3335
const result = await this.$platformCommandParameter.validate(platform) &&
3436
await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);

lib/commands/preview.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ export class PreviewCommand implements ICommand {
44
public allowedParameters: ICommandParameter[] = [];
55

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

44+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
45+
4446
await this.$networkConnectivityValidator.validate();
45-
this.$bundleValidatorHelper.validate(this.$projectData, "1.0.0");
4647
return true;
4748
}
4849
}

lib/commands/run.ts

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class RunCommandBase implements ICommand {
1313
private $errors: IErrors,
1414
private $hostInfo: IHostInfo,
1515
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
16+
private $migrateController: IMigrateController,
1617
private $projectData: IProjectData
1718
) { }
1819

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

31+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
32+
3033
this.$androidBundleValidatorHelper.validateNoAab();
3134

3235
this.$projectData.initializeProjectData();

lib/commands/test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ abstract class TestCommandBase {
1010
protected abstract $cleanupService: ICleanupService;
1111
protected abstract $liveSyncCommandHelper: ILiveSyncCommandHelper;
1212
protected abstract $devicesService: Mobile.IDevicesService;
13+
protected abstract $migrateController: IMigrateController;
1314

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

5051
async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
52+
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir });
53+
5154
this.$projectData.initializeProjectData();
5255
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
5356
this.$cleanupService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
@@ -86,7 +89,8 @@ class TestAndroidCommand extends TestCommandBase implements ICommand {
8689
protected $errors: IErrors,
8790
protected $cleanupService: ICleanupService,
8891
protected $liveSyncCommandHelper: ILiveSyncCommandHelper,
89-
protected $devicesService: Mobile.IDevicesService) {
92+
protected $devicesService: Mobile.IDevicesService,
93+
protected $migrateController: IMigrateController) {
9094
super();
9195
}
9296
}
@@ -102,7 +106,8 @@ class TestIosCommand extends TestCommandBase implements ICommand {
102106
protected $errors: IErrors,
103107
protected $cleanupService: ICleanupService,
104108
protected $liveSyncCommandHelper: ILiveSyncCommandHelper,
105-
protected $devicesService: Mobile.IDevicesService) {
109+
protected $devicesService: Mobile.IDevicesService,
110+
protected $migrateController: IMigrateController) {
106111
super();
107112
}
108113

lib/controllers/migrate-controller.ts

+32-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import { UpdateControllerBase } from "./update-controller-base";
66
import { fromWindowsRelativePathToUnix } from "../common/helpers";
77

88
export class MigrateController extends UpdateControllerBase implements IMigrateController {
9+
// TODO: Update the links to blog post when it is available
10+
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>.";
11+
private static UNABLE_TO_MIGRATE_APP_ERROR = `The current application is not compatible with NativeScript CLI 6.0.
12+
Use the \`tns migrate\` command to migrate the app dependencies to a form compatible with NativeScript 6.0.
13+
Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
14+
private static MIGRATE_FINISH_MESSAGE = `The \`tns migrate\` command does ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
15+
916
constructor(
1017
protected $fs: IFileSystem,
1118
protected $platformCommandHelper: IPlatformCommandHelper,
@@ -68,10 +75,17 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
6875
{ packageName: "nativescript-cardview", verifiedVersion: "3.2.0" },
6976
{
7077
packageName: "nativescript-unit-test-runner", verifiedVersion: "0.6.4",
71-
shouldMigrateAction: (projectData: IProjectData) => this.hasDependency({ packageName: "nativescript-unit-test-runner", isDev: false }, projectData),
78+
shouldMigrateAction: async (projectData: IProjectData) => {
79+
const dependency = { packageName: "nativescript-unit-test-runner", verifiedVersion: "0.6.4", isDev: false };
80+
const result = this.hasDependency(dependency, projectData) && await this.shouldMigrateDependencyVersion(dependency, projectData);
81+
return result;
82+
},
7283
migrateAction: this.migrateUnitTestRunner.bind(this)
7384
},
74-
{ packageName: MigrateController.typescriptPackageName, isDev: true, getVerifiedVersion: this.getAngularTypeScriptVersion.bind(this) }
85+
{ packageName: MigrateController.typescriptPackageName, isDev: true, getVerifiedVersion: this.getAngularTypeScriptVersion.bind(this) },
86+
{ packageName: "nativescript-localize", verifiedVersion: "4.2.0" },
87+
{ packageName: "nativescript-dev-babel", verifiedVersion: "0.2.1" },
88+
{ packageName: "nativescript-nfc", verifiedVersion: "4.0.1" }
7589
];
7690

7791
get verifiedPlatformVersions(): IDictionary<string> {
@@ -112,6 +126,8 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
112126
this.restoreBackup(MigrateController.folders, backupDir, projectData.projectDir);
113127
this.$errors.failWithoutHelp(`${MigrateController.migrateFailMessage} The error is: ${error}`);
114128
}
129+
130+
this.$logger.info(MigrateController.MIGRATE_FINISH_MESSAGE);
115131
}
116132

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

124-
if (hasDependency && dependency.shouldMigrateAction && dependency.shouldMigrateAction(projectData)) {
140+
if (hasDependency && dependency.shouldMigrateAction && await dependency.shouldMigrateAction(projectData)) {
125141
return true;
126142
}
127143

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

140-
if (!this.$androidResourcesMigrationService.hasMigrated(projectData.getAppResourcesDirectoryPath())) {
141-
return true;
142-
}
157+
if (!this.$androidResourcesMigrationService.hasMigrated(projectData.getAppResourcesDirectoryPath())) {
158+
return true;
143159
}
144160

145161
for (const platform in this.$devicePlatformsConstants) {
146162
const hasRuntimeDependency = this.hasRuntimeDependency({ platform, projectData });
147-
if (!hasRuntimeDependency || await this.shouldUpdateRuntimeVersion({ targetVersion: this.verifiedPlatformVersions[platform.toLowerCase()], platform, projectData })) {
163+
if (hasRuntimeDependency && await this.shouldUpdateRuntimeVersion({ targetVersion: this.verifiedPlatformVersions[platform.toLowerCase()], platform, projectData })) {
148164
return true;
149165
}
150166
}
151167
}
152168

169+
public async validate({ projectDir }: IProjectDir): Promise<void> {
170+
const shouldMigrate = await this.shouldMigrate({ projectDir });
171+
if (shouldMigrate) {
172+
this.$errors.failWithoutHelp(MigrateController.UNABLE_TO_MIGRATE_APP_ERROR);
173+
}
174+
}
175+
153176
private async getAngularTypeScriptVersion(projectData: IProjectData): Promise<string> {
154177
let verifiedVersion = "3.4.1";
155178
try {
@@ -254,7 +277,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
254277
const dependency = this.migrationDependencies[i];
255278
const hasDependency = this.hasDependency(dependency, projectData);
256279

257-
if (hasDependency && dependency.migrateAction && dependency.shouldMigrateAction(projectData)) {
280+
if (hasDependency && dependency.migrateAction && await dependency.shouldMigrateAction(projectData)) {
258281
const newDependencies = await dependency.migrateAction(projectData, path.join(projectData.projectDir, MigrateController.backupFolder));
259282
for (const newDependency of newDependencies) {
260283
await this.migrateDependency(newDependency, projectData);
@@ -267,7 +290,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
267290
for (const platform in this.$devicePlatformsConstants) {
268291
const lowercasePlatform = platform.toLowerCase();
269292
const hasRuntimeDependency = this.hasRuntimeDependency({ platform, projectData });
270-
if (!hasRuntimeDependency || await this.shouldUpdateRuntimeVersion({ targetVersion: this.verifiedPlatformVersions[lowercasePlatform], platform, projectData })) {
293+
if (hasRuntimeDependency && await this.shouldUpdateRuntimeVersion({ targetVersion: this.verifiedPlatformVersions[lowercasePlatform], platform, projectData })) {
271294
const verifiedPlatformVersion = this.verifiedPlatformVersions[lowercasePlatform];
272295
const platformData = this.$platformsDataService.getPlatformData(lowercasePlatform, projectData);
273296
this.$logger.info(`Updating ${platform} platform to version '${verifiedPlatformVersion}'.`);

lib/controllers/prepare-controller.ts

-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export class PrepareController extends EventEmitter {
1616
private persistedData: IFilesChangeEventData[] = [];
1717

1818
constructor(
19-
private $bundleValidatorHelper: IBundleValidatorHelper,
2019
private $platformController: IPlatformController,
2120
public $hooksService: IHooksService,
2221
private $logger: ILogger,
@@ -55,8 +54,6 @@ export class PrepareController extends EventEmitter {
5554
@performanceLog()
5655
@hook("prepare")
5756
private async prepareCore(prepareData: IPrepareData, projectData: IProjectData): Promise<IPrepareResultData> {
58-
this.$bundleValidatorHelper.validate(projectData, "1.0.0");
59-
6057
await this.$platformController.addPlatformIfNeeded(prepareData);
6158

6259
this.$logger.info("Preparing project...");

lib/definitions/migrate.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
interface IMigrateController {
22
migrate(migrateData: IProjectDir): Promise<void>;
33
shouldMigrate(data: IProjectDir): Promise<boolean>;
4+
validate(data: IProjectDir): Promise<void>;
45
}
56

67
interface IDependency {
@@ -15,6 +16,6 @@ interface IMigrationDependency extends IDependency {
1516
verifiedVersion?: string;
1617
getVerifiedVersion?: (projectData: IProjectData) => Promise<string>;
1718
shouldAddIfMissing?: boolean;
18-
shouldMigrateAction?: (projectData: IProjectData) => boolean;
19+
shouldMigrateAction?: (projectData: IProjectData) => Promise<boolean>;
1920
migrateAction?: (projectData: IProjectData, migrationBackupDirPath: string) => Promise<IMigrationDependency[]>;
2021
}

lib/helpers/bundle-validator-helper.ts

-40
This file was deleted.

test/controllers/prepare-controller.ts

-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ function createTestInjector(data: { hasNativeChanges: boolean }): IInjector {
5454
isFileInIgnoreList: () => false
5555
});
5656

57-
injector.register("bundleValidatorHelper", {
58-
validate: () => ({})
59-
});
60-
6157
const prepareController: PrepareController = injector.resolve("prepareController");
6258
prepareController.emit = (eventName: string, eventData: any) => {
6359
emittedEventNames.push(eventName);

0 commit comments

Comments
 (0)