@@ -4,6 +4,20 @@ import * as constants from "../constants";
44import { UpdateControllerBase } from "./update-controller-base" ;
55
66export 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+
721 constructor (
822 protected $fs : IFileSystem ,
923 protected $platformsDataService : IPlatformsDataService ,
@@ -16,23 +30,11 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
1630 private $pluginsService : IPluginsService ,
1731 private $pacoteService : IPacoteService ,
1832 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+ } ) ;
2337 }
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!" ;
3638
3739 public async update ( updateOptions : IUpdateOptions ) : Promise < void > {
3840 const projectData = this . $projectDataService . getProjectData ( updateOptions . projectDir ) ;
@@ -55,16 +57,16 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
5557 }
5658 }
5759
58- public async shouldUpdate ( { projectDir, version} : { projectDir : string , version ?: string } ) : Promise < boolean > {
60+ public async shouldUpdate ( { projectDir, version } : { projectDir : string , version ?: string } ) : Promise < boolean > {
5961 const projectData = this . $projectDataService . getProjectData ( projectDir ) ;
6062 const templateName = this . getTemplateName ( projectData ) ;
6163 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 ) ;
6466
6567 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 } )
6870 ) {
6971 return true ;
7072 }
@@ -93,12 +95,14 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
9395 private async updateProject ( projectData : IProjectData , version : string ) : Promise < void > {
9496 const templateName = this . getTemplateName ( projectData ) ;
9597 const templateManifest = await this . getTemplateManifest ( templateName , version ) ;
98+ const dependencies = this . getUpdatableDependencies ( templateManifest . dependencies ) ;
99+ const devDependencies = this . getUpdatableDependencies ( templateManifest . devDependencies ) ;
96100
97101 this . $logger . info ( "Start updating dependencies." ) ;
98- await this . updateDependencies ( { dependencies : templateManifest . dependencies , areDev : false , projectData} ) ;
102+ await this . updateDependencies ( { dependencies, areDev : false , projectData } ) ;
99103 this . $logger . info ( "Finished updating dependencies." ) ;
100104 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 } ) ;
102106 this . $logger . info ( "Finished updating devDependencies." ) ;
103107
104108 this . $logger . info ( "Start updating runtimes." ) ;
@@ -114,7 +118,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
114118 } ) ;
115119 }
116120
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 } ) {
118122 for ( const dependency in dependencies ) {
119123 const templateVersion = dependencies [ dependency ] ;
120124 if ( ! this . hasDependency ( { packageName : dependency , isDev : areDev } , projectData ) ) {
@@ -134,11 +138,10 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
134138 const projectVersion = dependencies [ dependency ] || devDependencies [ dependency ] ;
135139 const maxSatisfyingTargetVersion = await this . getMaxDependencyVersion ( dependency , targetVersion ) ;
136140 const maxSatisfyingProjectVersion = await this . getMaxDependencyVersion ( dependency , projectVersion ) ;
137-
138141 return maxSatisfyingProjectVersion && maxSatisfyingTargetVersion && semver . gt ( maxSatisfyingTargetVersion , maxSatisfyingProjectVersion ) ;
139142 }
140143
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 } ) {
142145 for ( const dependency in dependencies ) {
143146 const templateVersion = dependencies [ dependency ] ;
144147 if ( ! this . hasDependency ( { packageName : dependency , isDev : areDev } , projectData ) ) {
@@ -165,26 +168,32 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
165168 }
166169
167170 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 } ) ;
169172
170173 if ( ! hasRuntimeDependency ) {
171174 return false ;
172175 }
173176
174177 const maxTemplateRuntimeVersion = await this . getMaxDependencyVersion ( frameworkPackageName , templateRuntimeVersion ) ;
175- const maxRuntimeVersion = await this . getMaxRuntimeVersion ( { platform, projectData} ) ;
178+ const maxRuntimeVersion = await this . getMaxRuntimeVersion ( { platform, projectData } ) ;
176179
177180 return maxTemplateRuntimeVersion && maxRuntimeVersion && semver . gt ( maxTemplateRuntimeVersion , maxRuntimeVersion ) ;
178181 }
179182
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 ) ;
184187
185188 return await this . $pacoteService . manifest ( `${ templateName } @${ packageVersion } ` , { fullMetadata : true } ) ;
186189 }
187190
191+ private getUpdatableDependencies ( dependencies : IDictionary < string > ) : IDictionary < string > {
192+ return _ . pickBy ( dependencies , ( value , key ) => {
193+ return UpdateController . updatableDependencies . indexOf ( key ) > - 1 ;
194+ } ) ;
195+ }
196+
188197 private getTemplateName ( projectData : IProjectData ) {
189198 let template ;
190199 switch ( projectData . projectType ) {
0 commit comments