@@ -3,30 +3,18 @@ import * as semver from "semver";
3
3
import * as constants from "../constants" ;
4
4
import { BaseUpdateController } from "./base-update-controller" ;
5
5
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
-
18
6
export class MigrateController extends BaseUpdateController implements IMigrateController {
19
7
constructor (
20
8
protected $fs : IFileSystem ,
9
+ protected $platformCommandHelper : IPlatformCommandHelper ,
10
+ protected $platformsDataService : IPlatformsDataService ,
11
+ protected $packageInstallationManager : IPackageInstallationManager ,
12
+ protected $packageManager : IPackageManager ,
21
13
private $logger : ILogger ,
22
- private $platformCommandHelper : IPlatformCommandHelper ,
23
- private $platformsDataService : IPlatformsDataService ,
24
14
private $addPlatformService : IAddPlatformService ,
25
15
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 ) ;
30
18
}
31
19
32
20
static readonly folders : string [ ] = [
@@ -111,12 +99,12 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
111
99
return true ;
112
100
}
113
101
114
- if ( ! this . shouldSkipDependency ( dependency , projectData ) && await this . shouldMigrateDependencyVersion ( dependency , projectData ) ) {
102
+ if ( ! this . shouldSkipMigrationDependency ( dependency , projectData ) && await this . shouldMigrateDependencyVersion ( dependency , projectData ) ) {
115
103
return true ;
116
104
}
117
105
}
118
106
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 } ) ) {
120
108
return true ;
121
109
}
122
110
}
@@ -137,7 +125,7 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
137
125
this . $logger . info ( "Start migrating dependencies." ) ;
138
126
for ( let i = 0 ; i < MigrateController . migrationDependencies . length ; i ++ ) {
139
127
const dependency = MigrateController . migrationDependencies [ i ] ;
140
- if ( this . shouldSkipDependency ( dependency , projectData ) ) {
128
+ if ( this . shouldSkipMigrationDependency ( dependency , projectData ) ) {
141
129
continue ;
142
130
}
143
131
@@ -153,8 +141,8 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
153
141
}
154
142
155
143
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 } ) ) {
158
146
const verifiedPlatformVersion = MigrateController . verifiedPlatformVersions [ lowercasePlatform ] ;
159
147
const platformData = this . $platformsDataService . getPlatformData ( lowercasePlatform , projectData ) ;
160
148
this . $logger . info ( `Updating ${ platform } platform to version '${ verifiedPlatformVersion } '.` ) ;
@@ -177,52 +165,35 @@ export class MigrateController extends BaseUpdateController implements IMigrateC
177
165
const collection = dependency . isDev ? projectData . devDependencies : projectData . dependencies ;
178
166
if (
179
167
collection &&
180
- collection [ dependency . packageName ] &&
181
- ( semver . valid ( collection [ dependency . packageName ] ) || semver . validRange ( collection [ dependency . packageName ] ) )
168
+ collection [ dependency . packageName ]
182
169
) {
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 ) ) {
190
186
return false ;
191
187
}
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 ;
214
188
}
215
189
}
216
190
217
191
return true ;
218
192
}
219
193
220
- private shouldSkipDependency ( dependency : IMigrationDependency , projectData : IProjectData ) : boolean {
194
+ private shouldSkipMigrationDependency ( dependency : IMigrationDependency , projectData : IProjectData ) {
221
195
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 ) ;
226
197
}
227
198
}
228
199
}
0 commit comments