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