@@ -3,30 +3,18 @@ import * as semver from "semver";
33import * as constants from "../constants" ;
44import { BaseUpdateController } from "./base-update-controller" ;
55
6- interface IDependency {
7- packageName : string ;
8- isDev ?: boolean ;
9- }
10-
11- interface IMigrationDependency extends IDependency {
12- mustRemove ?: boolean ;
13- replaceWith ?: string ;
14- verifiedVersion ?: string ;
15- shouldAdd ?: boolean ;
16- }
17-
186export class MigrateController extends BaseUpdateController implements IMigrateController {
197 constructor (
208 protected $fs : IFileSystem ,
9+ protected $platformCommandHelper : IPlatformCommandHelper ,
10+ protected $platformsDataService : IPlatformsDataService ,
11+ protected $packageInstallationManager : IPackageInstallationManager ,
12+ protected $packageManager : IPackageManager ,
2113 private $logger : ILogger ,
22- private $platformCommandHelper : IPlatformCommandHelper ,
23- private $platformsDataService : IPlatformsDataService ,
2414 private $addPlatformService : IAddPlatformService ,
2515 private $pluginsService : IPluginsService ,
26- private $projectDataService : IProjectDataService ,
27- private $packageManager : INodePackageManager ,
28- private $packageInstallationManager : IPackageInstallationManager ) {
29- super ( $fs ) ;
16+ private $projectDataService : IProjectDataService ) {
17+ super ( $fs , $platformCommandHelper , $platformsDataService , $packageInstallationManager , $packageManager ) ;
3018 }
3119
3220 static readonly folders : string [ ] = [
@@ -111,12 +99,12 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
11199 return true ;
112100 }
113101
114- if ( ! this . shouldSkipDependency ( dependency , projectData ) && await this . shouldMigrateDependencyVersion ( dependency , projectData ) ) {
102+ if ( ! this . shouldSkipMigrationDependency ( dependency , projectData ) && await this . shouldMigrateDependencyVersion ( dependency , projectData ) ) {
115103 return true ;
116104 }
117105 }
118106 for ( const platform in constants . DEVICE_PLATFORMS ) {
119- if ( await this . shouldMigrateRuntimeVersion ( platform , projectData ) ) {
107+ if ( await this . shouldUpdateRuntimeVersion ( { targetVersion : MigrateController . verifiedPlatformVersions [ platform . toLowerCase ( ) ] , platform , projectData, shouldAdd : true } ) ) {
120108 return true ;
121109 }
122110 }
@@ -137,7 +125,7 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
137125 this . $logger . info ( "Start migrating dependencies." ) ;
138126 for ( let i = 0 ; i < MigrateController . migrationDependencies . length ; i ++ ) {
139127 const dependency = MigrateController . migrationDependencies [ i ] ;
140- if ( this . shouldSkipDependency ( dependency , projectData ) ) {
128+ if ( this . shouldSkipMigrationDependency ( dependency , projectData ) ) {
141129 continue ;
142130 }
143131
@@ -153,8 +141,8 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
153141 }
154142
155143 for ( const platform in constants . DEVICE_PLATFORMS ) {
156- if ( await this . shouldMigrateRuntimeVersion ( platform , projectData ) ) {
157- const lowercasePlatform = platform . toLowerCase ( ) ;
144+ const lowercasePlatform = platform . toLowerCase ( ) ;
145+ if ( await this . shouldUpdateRuntimeVersion ( { targetVersion : MigrateController . verifiedPlatformVersions [ lowercasePlatform ] , platform , projectData , shouldAdd : true } ) ) {
158146 const verifiedPlatformVersion = MigrateController . verifiedPlatformVersions [ lowercasePlatform ] ;
159147 const platformData = this . $platformsDataService . getPlatformData ( lowercasePlatform , projectData ) ;
160148 this . $logger . info ( `Updating ${ platform } platform to version '${ verifiedPlatformVersion } '.` ) ;
@@ -177,52 +165,35 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
177165 const collection = dependency . isDev ? projectData . devDependencies : projectData . dependencies ;
178166 if (
179167 collection &&
180- collection [ dependency . packageName ] &&
181- ( semver . valid ( collection [ dependency . packageName ] ) || semver . validRange ( collection [ dependency . packageName ] ) )
168+ collection [ dependency . packageName ]
182169 ) {
183- const maxSatisfyingVersion = await this . $packageInstallationManager . maxSatisfyingVersion ( dependency . packageName , collection [ dependency . packageName ] ) || collection [ dependency . packageName ] ;
184- const isPrereleaseVersion = semver . prerelease ( maxSatisfyingVersion ) ;
185- const coerceMaxSatisfying = semver . coerce ( maxSatisfyingVersion ) . version ;
186- const coerceVerifiedVersion = semver . coerce ( dependency . verifiedVersion ) . version ;
187- //This makes sure that if the user has a prerelease 6.0.0-next-2019-06-10-092158-01 version we will update it to 6.0.0
188- if ( isPrereleaseVersion ) {
189- if ( semver . gt ( coerceMaxSatisfying , coerceVerifiedVersion ) ) {
170+ const maxSatisfyingVersion = await this . getMaxDependencyVersion ( dependency . packageName , collection [ dependency . packageName ] ) ;
171+ if ( maxSatisfyingVersion ) {
172+ const isPrereleaseVersion = semver . prerelease ( maxSatisfyingVersion ) ;
173+ const coerceMaxSatisfying = semver . coerce ( maxSatisfyingVersion ) . version ;
174+ const coerceVerifiedVersion = semver . coerce ( dependency . verifiedVersion ) . version ;
175+ //This makes sure that if the user has a prerelease 6.0.0-next-2019-06-10-092158-01 version we will update it to 6.0.0
176+ if ( isPrereleaseVersion ) {
177+ if ( semver . gt ( coerceMaxSatisfying , coerceVerifiedVersion ) ) {
178+ return false ;
179+ }
180+
181+ //TODO This should be removed once we update the verified versions to no prerelease versions
182+ if ( semver . eq ( maxSatisfyingVersion , dependency . verifiedVersion ) ) {
183+ return false ;
184+ }
185+ } else if ( semver . gte ( coerceMaxSatisfying , coerceVerifiedVersion ) ) {
190186 return false ;
191187 }
192-
193- //TODO This should be removed once we update the verified versions to no prerelease versions
194- if ( isPrereleaseVersion && semver . eq ( maxSatisfyingVersion , dependency . verifiedVersion ) ) {
195- return false ;
196- }
197- } else if ( semver . gte ( coerceMaxSatisfying , coerceVerifiedVersion ) ) {
198- return false ;
199- }
200- }
201-
202- return true ;
203- }
204-
205- private async shouldMigrateRuntimeVersion ( platform : string , projectData : IProjectData ) {
206- const lowercasePlatform = platform . toLowerCase ( ) ;
207- const currentPlatformVersion = this . $platformCommandHelper . getCurrentPlatformVersion ( lowercasePlatform , projectData ) ;
208- const verifiedPlatformVersion = MigrateController . verifiedPlatformVersions [ lowercasePlatform ] ;
209- const platformData = this . $platformsDataService . getPlatformData ( lowercasePlatform , projectData ) ;
210- if ( currentPlatformVersion ) {
211- const maxPlatformSatisfyingVersion = await this . $packageInstallationManager . maxSatisfyingVersion ( platformData . frameworkPackageName , currentPlatformVersion ) || currentPlatformVersion ;
212- if ( semver . gte ( maxPlatformSatisfyingVersion , verifiedPlatformVersion ) ) {
213- return false ;
214188 }
215189 }
216190
217191 return true ;
218192 }
219193
220- private shouldSkipDependency ( dependency : IMigrationDependency , projectData : IProjectData ) : boolean {
194+ private shouldSkipMigrationDependency ( dependency : IMigrationDependency , projectData : IProjectData ) {
221195 if ( ! dependency . shouldAdd ) {
222- const collection = dependency . isDev ? projectData . devDependencies : projectData . dependencies ;
223- if ( ! collection [ dependency . packageName ] ) {
224- return true ;
225- }
196+ return this . shouldSkipDependency ( dependency , projectData ) ;
226197 }
227198 }
228199}
0 commit comments