@@ -28,18 +28,14 @@ export class NpmInstallationManager implements INpmInstallationManager {
28
28
return path . join ( this . getCacheRootPath ( ) , packageName , version , "package" ) ;
29
29
}
30
30
31
- public addToCache ( packageName : string , version : string ) : IFuture < void > {
31
+ public addToCache ( packageName : string , version : string ) : IFuture < void > {
32
32
return ( ( ) => {
33
- let shasumProperty = "dist.shasum" ;
34
33
let cachedPackagePath = this . getCachedPackagePath ( packageName , version ) ;
35
34
if ( ! this . $fs . exists ( cachedPackagePath ) . wait ( ) ) {
36
35
this . addToCacheCore ( packageName , version ) . wait ( ) ;
37
36
}
38
37
39
- let realShasum = this . $npm . view ( `${ packageName } @${ version } ` , shasumProperty ) . wait ( ) [ version ] [ shasumProperty ] ;
40
- let ourShasum = this . $fs . getFileShasum ( cachedPackagePath + ".tgz" ) . wait ( ) ;
41
- this . $logger . trace ( `Checking shasum of package: ${ packageName } @${ version } : expected ${ realShasum } , actual ${ ourShasum } .` ) ;
42
- if ( realShasum !== ourShasum ) {
38
+ if ( ! this . isShasumOfPackageCorrect ( packageName , version ) . wait ( ) ) {
43
39
// In some cases the package is not fully downloaded and the framework directory is missing
44
40
// Try removing the old package and add the real one to cache again
45
41
this . addCleanCopyToCache ( packageName , version ) . wait ( ) ;
@@ -88,6 +84,9 @@ export class NpmInstallationManager implements INpmInstallationManager {
88
84
this . $logger . trace ( `Deleting: ${ packagePath } .` ) ;
89
85
this . $fs . deleteDirectory ( packagePath ) . wait ( ) ;
90
86
this . addToCacheCore ( packageName , version ) . wait ( ) ;
87
+ if ( ! this . isShasumOfPackageCorrect ( packageName , version ) . wait ( ) ) {
88
+ this . $errors . failWithoutHelp ( `Unable to add package ${ packageName } with version ${ version } to npm cache. Try cleaning your cache and execute the command again.` )
89
+ }
91
90
} ) . future < void > ( ) ( ) ;
92
91
}
93
92
@@ -101,6 +100,17 @@ export class NpmInstallationManager implements INpmInstallationManager {
101
100
} ) . future < void > ( ) ( ) ;
102
101
}
103
102
103
+ private isShasumOfPackageCorrect ( packageName : string , version : string ) : IFuture < boolean > {
104
+ return ( ( ) : boolean => {
105
+ let shasumProperty = "dist.shasum" ;
106
+ let cachedPackagePath = this . getCachedPackagePath ( packageName , version ) ;
107
+ let realShasum = this . $npm . view ( `${ packageName } @${ version } ` , shasumProperty ) . wait ( ) [ version ] [ shasumProperty ] ;
108
+ let ourShasum = this . $fs . getFileShasum ( cachedPackagePath + ".tgz" ) . wait ( ) ;
109
+ this . $logger . trace ( `Checking shasum of package: ${ packageName } @${ version } : expected ${ realShasum } , actual ${ ourShasum } .` ) ;
110
+ return realShasum === ourShasum ;
111
+ } ) . future < boolean > ( ) ( ) ;
112
+ }
113
+
104
114
private installCore ( packageName : string , pathToSave : string , version : string ) : IFuture < string > {
105
115
return ( ( ) => {
106
116
if ( this . $options . frameworkPath ) {
0 commit comments