@@ -4,6 +4,20 @@ import * as constants from "../constants";
4
4
import { UpdateControllerBase } from "./update-controller-base" ;
5
5
6
6
export class UpdateController extends UpdateControllerBase implements IUpdateController {
7
+ private getTemplateManifest : Function ;
8
+ static readonly updatableDependencies : string [ ] = [ constants . TNS_CORE_MODULES_NAME , constants . TNS_CORE_MODULES_WIDGETS_NAME ] ;
9
+ static readonly folders : string [ ] = [
10
+ constants . LIB_DIR_NAME ,
11
+ constants . HOOKS_DIR_NAME ,
12
+ constants . WEBPACK_CONFIG_NAME ,
13
+ constants . PACKAGE_JSON_FILE_NAME ,
14
+ constants . PACKAGE_LOCK_JSON_FILE_NAME
15
+ ] ;
16
+
17
+ static readonly backupFolder : string = ".update_backup" ;
18
+ static readonly updateFailMessage : string = "Could not update the project!" ;
19
+ static readonly backupFailMessage : string = "Could not backup project folders!" ;
20
+
7
21
constructor (
8
22
protected $fs : IFileSystem ,
9
23
protected $platformsDataService : IPlatformsDataService ,
@@ -16,23 +30,11 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
16
30
private $pluginsService : IPluginsService ,
17
31
private $pacoteService : IPacoteService ,
18
32
private $projectDataService : IProjectDataService ) {
19
- super ( $fs , $platformCommandHelper , $platformsDataService , $packageInstallationManager , $packageManager ) ;
20
- this . getTemplateManifest = _ . memoize ( this . _getTemplateManifest , ( ...args ) => {
21
- return args . join ( "@" ) ;
22
- } ) ;
33
+ super ( $fs , $platformCommandHelper , $platformsDataService , $packageInstallationManager , $packageManager ) ;
34
+ this . getTemplateManifest = _ . memoize ( this . _getTemplateManifest , ( ...args ) => {
35
+ return args . join ( "@" ) ;
36
+ } ) ;
23
37
}
24
- private getTemplateManifest : Function ;
25
- static readonly folders : string [ ] = [
26
- constants . LIB_DIR_NAME ,
27
- constants . HOOKS_DIR_NAME ,
28
- constants . WEBPACK_CONFIG_NAME ,
29
- constants . PACKAGE_JSON_FILE_NAME ,
30
- constants . PACKAGE_LOCK_JSON_FILE_NAME
31
- ] ;
32
-
33
- static readonly backupFolder : string = ".update_backup" ;
34
- static readonly updateFailMessage : string = "Could not update the project!" ;
35
- static readonly backupFailMessage : string = "Could not backup project folders!" ;
36
38
37
39
public async update ( updateOptions : IUpdateOptions ) : Promise < void > {
38
40
const projectData = this . $projectDataService . getProjectData ( updateOptions . projectDir ) ;
@@ -55,16 +57,16 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
55
57
}
56
58
}
57
59
58
- public async shouldUpdate ( { projectDir, version} : { projectDir : string , version ?: string } ) : Promise < boolean > {
60
+ public async shouldUpdate ( { projectDir, version } : { projectDir : string , version ?: string } ) : Promise < boolean > {
59
61
const projectData = this . $projectDataService . getProjectData ( projectDir ) ;
60
62
const templateName = this . getTemplateName ( projectData ) ;
61
63
const templateManifest = await this . getTemplateManifest ( templateName , version ) ;
62
- const dependencies = templateManifest . dependencies ;
63
- const devDependencies = templateManifest . devDependencies ;
64
+ const dependencies = this . getUpdatableDependencies ( templateManifest . dependencies ) ;
65
+ const devDependencies = this . getUpdatableDependencies ( templateManifest . devDependencies ) ;
64
66
65
67
if (
66
- await this . hasDependenciesToUpdate ( { dependencies, areDev : false , projectData} ) ||
67
- await this . hasDependenciesToUpdate ( { dependencies : devDependencies , areDev : true , projectData} )
68
+ await this . hasDependenciesToUpdate ( { dependencies, areDev : false , projectData } ) ||
69
+ await this . hasDependenciesToUpdate ( { dependencies : devDependencies , areDev : true , projectData } )
68
70
) {
69
71
return true ;
70
72
}
@@ -93,12 +95,14 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
93
95
private async updateProject ( projectData : IProjectData , version : string ) : Promise < void > {
94
96
const templateName = this . getTemplateName ( projectData ) ;
95
97
const templateManifest = await this . getTemplateManifest ( templateName , version ) ;
98
+ const dependencies = this . getUpdatableDependencies ( templateManifest . dependencies ) ;
99
+ const devDependencies = this . getUpdatableDependencies ( templateManifest . devDependencies ) ;
96
100
97
101
this . $logger . info ( "Start updating dependencies." ) ;
98
- await this . updateDependencies ( { dependencies : templateManifest . dependencies , areDev : false , projectData} ) ;
102
+ await this . updateDependencies ( { dependencies, areDev : false , projectData } ) ;
99
103
this . $logger . info ( "Finished updating dependencies." ) ;
100
104
this . $logger . info ( "Start updating devDependencies." ) ;
101
- await this . updateDependencies ( { dependencies : templateManifest . devDependencies , areDev : true , projectData} ) ;
105
+ await this . updateDependencies ( { dependencies : devDependencies , areDev : true , projectData } ) ;
102
106
this . $logger . info ( "Finished updating devDependencies." ) ;
103
107
104
108
this . $logger . info ( "Start updating runtimes." ) ;
@@ -114,7 +118,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
114
118
} ) ;
115
119
}
116
120
117
- private async updateDependencies ( { dependencies, areDev, projectData} : { dependencies : IDictionary < string > , areDev : boolean , projectData : IProjectData } ) {
121
+ private async updateDependencies ( { dependencies, areDev, projectData } : { dependencies : IDictionary < string > , areDev : boolean , projectData : IProjectData } ) {
118
122
for ( const dependency in dependencies ) {
119
123
const templateVersion = dependencies [ dependency ] ;
120
124
if ( ! this . hasDependency ( { packageName : dependency , isDev : areDev } , projectData ) ) {
@@ -134,11 +138,10 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
134
138
const projectVersion = dependencies [ dependency ] || devDependencies [ dependency ] ;
135
139
const maxSatisfyingTargetVersion = await this . getMaxDependencyVersion ( dependency , targetVersion ) ;
136
140
const maxSatisfyingProjectVersion = await this . getMaxDependencyVersion ( dependency , projectVersion ) ;
137
-
138
141
return maxSatisfyingProjectVersion && maxSatisfyingTargetVersion && semver . gt ( maxSatisfyingTargetVersion , maxSatisfyingProjectVersion ) ;
139
142
}
140
143
141
- private async hasDependenciesToUpdate ( { dependencies, areDev, projectData} : { dependencies : IDictionary < string > , areDev : boolean , projectData :IProjectData } ) {
144
+ private async hasDependenciesToUpdate ( { dependencies, areDev, projectData } : { dependencies : IDictionary < string > , areDev : boolean , projectData : IProjectData } ) {
142
145
for ( const dependency in dependencies ) {
143
146
const templateVersion = dependencies [ dependency ] ;
144
147
if ( ! this . hasDependency ( { packageName : dependency , isDev : areDev } , projectData ) ) {
@@ -165,26 +168,32 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
165
168
}
166
169
167
170
private async shouldUpdateRuntimeVersion ( templateRuntimeVersion : string , frameworkPackageName : string , platform : string , projectData : IProjectData ) : Promise < boolean > {
168
- const hasRuntimeDependency = this . hasRuntimeDependency ( { platform, projectData} ) ;
171
+ const hasRuntimeDependency = this . hasRuntimeDependency ( { platform, projectData } ) ;
169
172
170
173
if ( ! hasRuntimeDependency ) {
171
174
return false ;
172
175
}
173
176
174
177
const maxTemplateRuntimeVersion = await this . getMaxDependencyVersion ( frameworkPackageName , templateRuntimeVersion ) ;
175
- const maxRuntimeVersion = await this . getMaxRuntimeVersion ( { platform, projectData} ) ;
178
+ const maxRuntimeVersion = await this . getMaxRuntimeVersion ( { platform, projectData } ) ;
176
179
177
180
return maxTemplateRuntimeVersion && maxRuntimeVersion && semver . gt ( maxTemplateRuntimeVersion , maxRuntimeVersion ) ;
178
181
}
179
182
180
- private async _getTemplateManifest ( templateName : string , version : string ) {
181
- let packageVersion = version ? version : await this . $packageInstallationManager . getLatestCompatibleVersionSafe ( templateName ) ;
182
- packageVersion = semver . valid ( version ) ? version : await this . $packageManager . getTagVersion ( templateName , packageVersion ) ;
183
- packageVersion = packageVersion ? packageVersion : await this . $packageInstallationManager . getLatestCompatibleVersionSafe ( templateName ) ;
183
+ private async _getTemplateManifest ( templateName : string , version ? : string ) {
184
+ const packageVersion = semver . valid ( version ) ||
185
+ await this . $packageManager . getTagVersion ( templateName , version ) ||
186
+ await this . $packageInstallationManager . getLatestCompatibleVersionSafe ( templateName ) ;
184
187
185
188
return await this . $pacoteService . manifest ( `${ templateName } @${ packageVersion } ` , { fullMetadata : true } ) ;
186
189
}
187
190
191
+ private getUpdatableDependencies ( dependencies : IDictionary < string > ) : IDictionary < string > {
192
+ return _ . pickBy ( dependencies , ( value , key ) => {
193
+ return UpdateController . updatableDependencies . indexOf ( key ) > - 1 ;
194
+ } ) ;
195
+ }
196
+
188
197
private getTemplateName ( projectData : IProjectData ) {
189
198
let template ;
190
199
switch ( projectData . projectType ) {
0 commit comments