@@ -34,10 +34,20 @@ export class PluginsService implements IPluginsService {
34
34
this . ensure ( ) . wait ( ) ;
35
35
let dependencyData = this . $npm . cache ( plugin , undefined , PluginsService . NPM_CONFIG ) . wait ( ) ;
36
36
if ( dependencyData . nativescript ) {
37
- this . executeNpmCommand ( PluginsService . INSTALL_COMMAND_NAME , plugin ) . wait ( ) ;
38
-
39
37
let pluginData = this . convertToPluginData ( dependencyData ) ;
40
- this . $pluginVariablesService . savePluginVariablesInProjectFile ( pluginData ) . wait ( ) ;
38
+ this . validate ( pluginData ) . wait ( ) ;
39
+
40
+ try {
41
+ this . $pluginVariablesService . savePluginVariablesInProjectFile ( pluginData ) . wait ( ) ;
42
+ this . executeNpmCommand ( PluginsService . INSTALL_COMMAND_NAME , plugin ) . wait ( ) ;
43
+ } catch ( err ) {
44
+ // Revert package.json
45
+ this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
46
+ this . $projectDataService . removeProperty ( this . $pluginVariablesService . getPluginVariablePropertyName ( pluginData ) ) . wait ( ) ;
47
+ this . $projectDataService . removeDependency ( pluginData . name ) . wait ( ) ;
48
+
49
+ throw err ;
50
+ }
41
51
42
52
this . $logger . out ( `Successfully installed plugin ${ dependencyData . name } .` ) ;
43
53
} else {
@@ -49,6 +59,17 @@ export class PluginsService implements IPluginsService {
49
59
50
60
public remove ( pluginName : string ) : IFuture < void > {
51
61
return ( ( ) => {
62
+ let isUninstallCommandExecuted = false ;
63
+
64
+ let executeUninstallCommand = ( ) => {
65
+ return ( ( ) => {
66
+ if ( ! isUninstallCommandExecuted ) {
67
+ this . executeNpmCommand ( PluginsService . UNINSTALL_COMMAND_NAME , pluginName ) . wait ( ) ;
68
+ isUninstallCommandExecuted = true ;
69
+ }
70
+ } ) . future < void > ( ) ( ) ;
71
+ } ;
72
+
52
73
let removePluginNativeCodeAction = ( modulesDestinationPath : string , platform : string , platformData : IPlatformData ) => {
53
74
return ( ( ) => {
54
75
let pluginData = this . convertToPluginData ( this . getNodeModuleData ( pluginName ) . wait ( ) ) ;
@@ -60,10 +81,13 @@ export class PluginsService implements IPluginsService {
60
81
if ( this . $fs . exists ( pluginConfigurationFilePath ) . wait ( ) ) {
61
82
let tnsModulesDestinationPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME , constants . TNS_MODULES_FOLDER_NAME ) ;
62
83
let nodeModules = this . $broccoliBuilder . getChangedNodeModules ( tnsModulesDestinationPath , platform ) . wait ( ) ;
63
- _ . each ( nodeModules , ( index , nodeModule ) => {
64
- let data = this . convertToPluginData ( this . getNodeModuleData ( pluginName ) . wait ( ) ) ;
84
+ let plugins = _ . map ( _ . keys ( nodeModules ) , nodeModule => this . convertToPluginData ( this . getNodeModuleData ( pluginName ) . wait ( ) ) ) ;
85
+
86
+ _ . forEach ( plugins , ( data , index ) => {
65
87
if ( data . isPlugin ) {
66
88
if ( this . $fs . exists ( this . getPluginConfigurationFilePath ( data , platformData ) ) . wait ( ) ) {
89
+ executeUninstallCommand ( ) . wait ( ) ;
90
+
67
91
if ( index === 0 ) {
68
92
this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
69
93
let frameworkVersion = this . $projectDataService . getValue ( platformData . frameworkPackageName ) . wait ( ) . version ;
@@ -73,9 +97,12 @@ export class PluginsService implements IPluginsService {
73
97
let cachedPackagePath = this . $injector . resolve ( "npmInstallationManager" ) . getCachedPackagePath ( platformData . frameworkPackageName , frameworkVersion ) ;
74
98
let cachedConfigurationFilePath = path . join ( cachedPackagePath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , relativeConfigurationFilePath ) ;
75
99
76
- shelljs . cp ( "-f" , cachedConfigurationFilePath , platformData . configurationFilePath ) ;
100
+ shelljs . cp ( "-f" , cachedConfigurationFilePath , path . dirname ( platformData . configurationFilePath ) ) ;
101
+ }
102
+
103
+ if ( data . name !== pluginName ) {
104
+ this . merge ( data , platformData ) . wait ( ) ;
77
105
}
78
- this . merge ( data , platformData ) . wait ( ) ;
79
106
}
80
107
}
81
108
} ) ;
@@ -88,7 +115,7 @@ export class PluginsService implements IPluginsService {
88
115
} ;
89
116
this . executeForAllInstalledPlatforms ( removePluginNativeCodeAction ) . wait ( ) ;
90
117
91
- this . executeNpmCommand ( PluginsService . UNINSTALL_COMMAND_NAME , pluginName ) . wait ( ) ;
118
+ executeUninstallCommand ( ) . wait ( ) ;
92
119
93
120
let showMessage = true ;
94
121
let action = ( modulesDestinationPath : string , platform : string , platformData : IPlatformData ) => {
@@ -111,23 +138,10 @@ export class PluginsService implements IPluginsService {
111
138
return ( ( ) => {
112
139
let pluginData = this . convertToPluginData ( dependencyData ) ;
113
140
141
+ this . validate ( pluginData ) . wait ( ) ;
142
+
114
143
let action = ( pluginDestinationPath : string , platform : string , platformData : IPlatformData ) => {
115
144
return ( ( ) => {
116
- let installedFrameworkVersion = this . getInstalledFrameworkVersion ( platform ) . wait ( ) ;
117
- let pluginPlatformsData = pluginData . platformsData ;
118
- if ( pluginPlatformsData ) {
119
- let pluginVersion = ( < any > pluginPlatformsData ) [ platform ] ;
120
- if ( ! pluginVersion ) {
121
- this . $logger . warn ( `${ pluginData . name } is not supported for ${ platform } .` ) ;
122
- return ;
123
- }
124
-
125
- if ( semver . gt ( pluginVersion , installedFrameworkVersion ) ) {
126
- this . $logger . warn ( `${ pluginData . name } ${ pluginVersion } for ${ platform } is not compatible with the currently installed framework version ${ installedFrameworkVersion } .` ) ;
127
- return ;
128
- }
129
- }
130
-
131
145
if ( this . $fs . exists ( path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME ) ) . wait ( ) ) {
132
146
this . $fs . ensureDirectoryExists ( pluginDestinationPath ) . wait ( ) ;
133
147
shelljs . cp ( "-Rf" , pluginData . fullPath , pluginDestinationPath ) ;
@@ -342,5 +356,30 @@ export class PluginsService implements IPluginsService {
342
356
let pluginConfigurationFilePath = path . join ( pluginPlatformsFolderPath , platformData . configurationFileName ) ;
343
357
return pluginConfigurationFilePath ;
344
358
}
359
+
360
+ private validate ( pluginData : IPluginData ) : IFuture < void > {
361
+ return ( ( ) => {
362
+ let action = ( pluginDestinationPath : string , platform : string , platformData : IPlatformData ) => {
363
+ return ( ( ) => {
364
+ let installedFrameworkVersion = this . getInstalledFrameworkVersion ( platform ) . wait ( ) ;
365
+ let pluginPlatformsData = pluginData . platformsData ;
366
+ if ( pluginPlatformsData ) {
367
+ let pluginVersion = ( < any > pluginPlatformsData ) [ platform ] ;
368
+ if ( ! pluginVersion ) {
369
+ this . $logger . warn ( `${ pluginData . name } is not supported for ${ platform } .` ) ;
370
+ return ;
371
+ }
372
+
373
+ if ( semver . gt ( pluginVersion , installedFrameworkVersion ) ) {
374
+ this . $logger . warn ( `${ pluginData . name } ${ pluginVersion } for ${ platform } is not compatible with the currently installed framework version ${ installedFrameworkVersion } .` ) ;
375
+ return ;
376
+ }
377
+ }
378
+ } ) . future < void > ( ) ( ) ;
379
+ } ;
380
+
381
+ this . executeForAllInstalledPlatforms ( action ) . wait ( ) ;
382
+ } ) . future < void > ( ) ( ) ;
383
+ }
345
384
}
346
385
$injector . register ( "pluginsService" , PluginsService ) ;
0 commit comments