@@ -75,9 +75,9 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
75
75
{ packageName : "nativescript-cardview" , verifiedVersion : "3.2.0" } ,
76
76
{
77
77
packageName : "nativescript-unit-test-runner" , verifiedVersion : "0.6.4" ,
78
- shouldMigrateAction : async ( projectData : IProjectData ) => {
78
+ shouldMigrateAction : async ( projectData : IProjectData , allowInvalidVersions : boolean ) => {
79
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 ) ;
80
+ const result = this . hasDependency ( dependency , projectData ) && await this . shouldMigrateDependencyVersion ( dependency , projectData , allowInvalidVersions ) ;
81
81
return result ;
82
82
} ,
83
83
migrateAction : this . migrateUnitTestRunner . bind ( this )
@@ -95,7 +95,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
95
95
} ;
96
96
}
97
97
98
- public async migrate ( { projectDir, platforms } : IMigrationData ) : Promise < void > {
98
+ public async migrate ( { projectDir, platforms, allowInvalidVersions = false } : IMigrationData ) : Promise < void > {
99
99
const projectData = this . $projectDataService . getProjectData ( projectDir ) ;
100
100
const backupDir = path . join ( projectDir , MigrateController . backupFolder ) ;
101
101
@@ -121,7 +121,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
121
121
122
122
try {
123
123
await this . cleanUpProject ( projectData ) ;
124
- await this . migrateDependencies ( projectData , platforms ) ;
124
+ await this . migrateDependencies ( projectData , platforms , allowInvalidVersions ) ;
125
125
} catch ( error ) {
126
126
this . restoreBackup ( MigrateController . folders , backupDir , projectData . projectDir ) ;
127
127
this . $errors . failWithoutHelp ( `${ MigrateController . migrateFailMessage } The error is: ${ error } ` ) ;
@@ -130,15 +130,15 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
130
130
this . $logger . info ( MigrateController . MIGRATE_FINISH_MESSAGE ) ;
131
131
}
132
132
133
- public async shouldMigrate ( { projectDir, platforms } : IMigrationData ) : Promise < boolean > {
133
+ public async shouldMigrate ( { projectDir, platforms, allowInvalidVersions = false } : IMigrationData ) : Promise < boolean > {
134
134
const projectData = this . $projectDataService . getProjectData ( projectDir ) ;
135
135
const shouldMigrateCommonMessage = "The app is not compatible with this CLI version and it should be migrated. Reason: " ;
136
136
137
137
for ( let i = 0 ; i < this . migrationDependencies . length ; i ++ ) {
138
138
const dependency = this . migrationDependencies [ i ] ;
139
139
const hasDependency = this . hasDependency ( dependency , projectData ) ;
140
140
141
- if ( hasDependency && dependency . shouldMigrateAction && await dependency . shouldMigrateAction ( projectData ) ) {
141
+ if ( hasDependency && dependency . shouldMigrateAction && await dependency . shouldMigrateAction ( projectData , allowInvalidVersions ) ) {
142
142
this . $logger . trace ( `${ shouldMigrateCommonMessage } '${ dependency . packageName } ' requires an update.` ) ;
143
143
return true ;
144
144
}
@@ -148,7 +148,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
148
148
return true ;
149
149
}
150
150
151
- if ( hasDependency && await this . shouldMigrateDependencyVersion ( dependency , projectData ) ) {
151
+ if ( hasDependency && await this . shouldMigrateDependencyVersion ( dependency , projectData , allowInvalidVersions ) ) {
152
152
this . $logger . trace ( `${ shouldMigrateCommonMessage } '${ dependency . packageName } ' should be updated.` ) ;
153
153
return true ;
154
154
}
@@ -163,15 +163,15 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
163
163
platform = platform && platform . toLowerCase ( ) ;
164
164
165
165
const hasRuntimeDependency = this . hasRuntimeDependency ( { platform, projectData } ) ;
166
- if ( hasRuntimeDependency && await this . shouldUpdateRuntimeVersion ( { targetVersion : this . verifiedPlatformVersions [ platform . toLowerCase ( ) ] , platform, projectData } ) ) {
166
+ if ( hasRuntimeDependency && await this . shouldUpdateRuntimeVersion ( this . verifiedPlatformVersions [ platform . toLowerCase ( ) ] , platform , projectData , allowInvalidVersions ) ) {
167
167
this . $logger . trace ( `${ shouldMigrateCommonMessage } Platform '${ platform } ' should be updated.` ) ;
168
168
return true ;
169
169
}
170
170
}
171
171
}
172
172
173
- public async validate ( { projectDir, platforms } : IMigrationData ) : Promise < void > {
174
- const shouldMigrate = await this . shouldMigrate ( { projectDir, platforms } ) ;
173
+ public async validate ( { projectDir, platforms, allowInvalidVersions = true } : IMigrationData ) : Promise < void > {
174
+ const shouldMigrate = await this . shouldMigrate ( { projectDir, platforms, allowInvalidVersions } ) ;
175
175
if ( shouldMigrate ) {
176
176
this . $errors . failWithoutHelp ( MigrateController . UNABLE_TO_MIGRATE_APP_ERROR ) ;
177
177
}
@@ -275,26 +275,26 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
275
275
return autoGeneratedFiles ;
276
276
}
277
277
278
- private async migrateDependencies ( projectData : IProjectData , platforms : string [ ] ) : Promise < void > {
278
+ private async migrateDependencies ( projectData : IProjectData , platforms : string [ ] , allowInvalidVersions : boolean ) : Promise < void > {
279
279
this . $logger . info ( "Start dependencies migration." ) ;
280
280
for ( let i = 0 ; i < this . migrationDependencies . length ; i ++ ) {
281
281
const dependency = this . migrationDependencies [ i ] ;
282
282
const hasDependency = this . hasDependency ( dependency , projectData ) ;
283
283
284
- if ( hasDependency && dependency . migrateAction && await dependency . shouldMigrateAction ( projectData ) ) {
284
+ if ( hasDependency && dependency . migrateAction && await dependency . shouldMigrateAction ( projectData , allowInvalidVersions ) ) {
285
285
const newDependencies = await dependency . migrateAction ( projectData , path . join ( projectData . projectDir , MigrateController . backupFolder ) ) ;
286
286
for ( const newDependency of newDependencies ) {
287
- await this . migrateDependency ( newDependency , projectData ) ;
287
+ await this . migrateDependency ( newDependency , projectData , allowInvalidVersions ) ;
288
288
}
289
289
}
290
290
291
- await this . migrateDependency ( dependency , projectData ) ;
291
+ await this . migrateDependency ( dependency , projectData , allowInvalidVersions ) ;
292
292
}
293
293
294
294
for ( const platform of platforms ) {
295
295
const lowercasePlatform = platform . toLowerCase ( ) ;
296
296
const hasRuntimeDependency = this . hasRuntimeDependency ( { platform, projectData } ) ;
297
- if ( hasRuntimeDependency && await this . shouldUpdateRuntimeVersion ( { targetVersion : this . verifiedPlatformVersions [ lowercasePlatform ] , platform, projectData } ) ) {
297
+ if ( hasRuntimeDependency && await this . shouldUpdateRuntimeVersion ( this . verifiedPlatformVersions [ lowercasePlatform ] , platform , projectData , allowInvalidVersions ) ) {
298
298
const verifiedPlatformVersion = this . verifiedPlatformVersions [ lowercasePlatform ] ;
299
299
const platformData = this . $platformsDataService . getPlatformData ( lowercasePlatform , projectData ) ;
300
300
this . $logger . info ( `Updating ${ platform } platform to version '${ verifiedPlatformVersion } '.` ) ;
@@ -313,7 +313,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
313
313
this . $logger . info ( "Migration complete." ) ;
314
314
}
315
315
316
- private async migrateDependency ( dependency : IMigrationDependency , projectData : IProjectData ) : Promise < void > {
316
+ private async migrateDependency ( dependency : IMigrationDependency , projectData : IProjectData , allowInvalidVersions : boolean ) : Promise < void > {
317
317
const hasDependency = this . hasDependency ( dependency , projectData ) ;
318
318
if ( hasDependency && dependency . warning ) {
319
319
this . $logger . warn ( dependency . warning ) ;
@@ -336,7 +336,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
336
336
}
337
337
338
338
const dependencyVersion = await this . getDependencyVerifiedVersion ( dependency , projectData ) ;
339
- if ( hasDependency && await this . shouldMigrateDependencyVersion ( dependency , projectData ) ) {
339
+ if ( hasDependency && await this . shouldMigrateDependencyVersion ( dependency , projectData , allowInvalidVersions ) ) {
340
340
this . $logger . info ( `Updating '${ dependency . packageName } ' to compatible version '${ dependencyVersion } '` ) ;
341
341
this . $pluginsService . addToPackageJson ( dependency . packageName , dependencyVersion , dependency . isDev , projectData . projectDir ) ;
342
342
return ;
@@ -356,21 +356,25 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
356
356
return dependency . verifiedVersion ;
357
357
}
358
358
359
- private async shouldMigrateDependencyVersion ( dependency : IMigrationDependency , projectData : IProjectData ) : Promise < boolean > {
359
+ private async shouldMigrateDependencyVersion ( dependency : IMigrationDependency , projectData : IProjectData , allowInvalidVersions : boolean ) : Promise < boolean > {
360
360
const devDependencies = projectData . devDependencies || { } ;
361
361
const dependencies = projectData . dependencies || { } ;
362
362
const packageName = dependency . packageName ;
363
363
const referencedVersion = dependencies [ packageName ] || devDependencies [ packageName ] ;
364
364
const installedVersion = await this . getMaxDependencyVersion ( dependency . packageName , referencedVersion ) ;
365
365
const requiredVersion = await this . getDependencyVerifiedVersion ( dependency , projectData ) ;
366
366
367
- return ! ! installedVersion && semver . lt ( installedVersion , requiredVersion ) ;
367
+ return this . isOutdatedVersion ( installedVersion , requiredVersion , allowInvalidVersions ) ;
368
368
}
369
369
370
- protected async shouldUpdateRuntimeVersion ( { targetVersion, platform , projectData } : { targetVersion : string , platform : string , projectData : IProjectData } ) : Promise < boolean > {
371
- const maxRuntimeVersion = await this . getMaxRuntimeVersion ( { platform, projectData } ) ;
370
+ private async shouldUpdateRuntimeVersion ( targetVersion : string , platform : string , projectData : IProjectData , allowInvalidVersions : boolean ) : Promise < boolean > {
371
+ const installedVersion = await this . getMaxRuntimeVersion ( { platform, projectData } ) ;
372
372
373
- return ! ( maxRuntimeVersion && semver . gte ( maxRuntimeVersion , targetVersion ) ) ;
373
+ return this . isOutdatedVersion ( installedVersion , targetVersion , allowInvalidVersions ) ;
374
+ }
375
+
376
+ private isOutdatedVersion ( version : string , targetVersion : string , allowInvalidVersions : boolean ) : boolean {
377
+ return ! ! version ? semver . lt ( version , targetVersion ) : ! allowInvalidVersions ;
374
378
}
375
379
376
380
private async migrateUnitTestRunner ( projectData : IProjectData , migrationBackupDirPath : string ) : Promise < IMigrationDependency [ ] > {
0 commit comments