@@ -6,6 +6,7 @@ export class NpmInstallationManager implements INpmInstallationManager {
6
6
private static NPM_LOAD_FAILED = "Failed to retrieve data from npm. Please try again a little bit later." ;
7
7
8
8
constructor ( private $npm : INodePackageManager ,
9
+ private $childProcess : IChildProcess ,
9
10
private $logger : ILogger ,
10
11
private $errors : IErrors ,
11
12
private $options : IOptions ,
@@ -57,6 +58,39 @@ export class NpmInstallationManager implements INpmInstallationManager {
57
58
} ) . future < string > ( ) ( ) ;
58
59
}
59
60
61
+ public getInspectorFromCache ( inspectorNpmPackageName : string , projectDir : string ) : IFuture < string > {
62
+ return ( ( ) => {
63
+ let inspectorPath = path . join ( projectDir , "node_modules" , inspectorNpmPackageName ) ;
64
+
65
+ // local installation takes precedence over cache
66
+ if ( ! this . inspectorAlreadyInstalled ( inspectorPath ) . wait ( ) ) {
67
+ let cachepath = this . $childProcess . exec ( "npm get cache" ) . wait ( ) . trim ( ) ;
68
+ let version = this . getLatestCompatibleVersion ( inspectorNpmPackageName ) . wait ( ) ;
69
+ let pathToPackageInCache = path . join ( cachepath , inspectorNpmPackageName , version ) ;
70
+ let pathToUnzippedInspector = path . join ( pathToPackageInCache , "package" ) ;
71
+
72
+ if ( ! this . $fs . exists ( pathToPackageInCache ) . wait ( ) ) {
73
+ this . $childProcess . exec ( `npm cache add ${ inspectorNpmPackageName } @${ version } ` ) . wait ( ) ;
74
+ let inspectorTgzPathInCache = path . join ( pathToPackageInCache , "package.tgz" ) ;
75
+ this . $childProcess . exec ( `tar -xf ${ inspectorTgzPathInCache } -C ${ pathToPackageInCache } ` ) . wait ( ) ;
76
+ this . $childProcess . exec ( `npm install --prefix ${ pathToUnzippedInspector } ` ) . wait ( ) ;
77
+ }
78
+ this . $logger . out ( "Using inspector from cache." ) ;
79
+ return pathToUnzippedInspector ;
80
+ }
81
+ return inspectorPath ;
82
+ } ) . future < string > ( ) ( ) ;
83
+ }
84
+
85
+ private inspectorAlreadyInstalled ( pathToInspector : string ) : IFuture < Boolean > {
86
+ return ( ( ) => {
87
+ if ( this . $fs . exists ( pathToInspector ) . wait ( ) ) {
88
+ return true ;
89
+ }
90
+ return false ;
91
+ } ) . future < Boolean > ( ) ( ) ;
92
+ }
93
+
60
94
private installCore ( packageName : string , pathToSave : string , version : string , dependencyType : string ) : IFuture < string > {
61
95
return ( ( ) => {
62
96
const possiblePackageName = path . resolve ( packageName ) ;
0 commit comments