@@ -47,27 +47,38 @@ export class NpmInstallationManager implements INpmInstallationManager {
4747 }
4848
4949 public async getInspectorFromCache ( inspectorNpmPackageName : string , projectDir : string ) : Promise < string > {
50- let inspectorPath = path . join ( projectDir , "node_modules" , inspectorNpmPackageName ) ;
50+ let inspectorPath = path . join ( projectDir , constants . NODE_MODULES_FOLDER_NAME , inspectorNpmPackageName ) ;
5151
5252 // local installation takes precedence over cache
5353 if ( ! this . inspectorAlreadyInstalled ( inspectorPath ) ) {
54- let cachepath = ( await this . $childProcess . exec ( "npm get cache" ) ) . trim ( ) ;
55- let version = await this . getLatestCompatibleVersion ( inspectorNpmPackageName ) ;
56- let pathToPackageInCache = path . join ( cachepath , inspectorNpmPackageName , version ) ;
57- let pathToUnzippedInspector = path . join ( pathToPackageInCache , "package" ) ;
54+ const cachePath = path . join ( this . $options . profileDir , constants . INSPECTOR_CACHE_DIRNAME ) ;
55+ this . prepareCacheDir ( cachePath ) ;
56+ const pathToPackageInCache = path . join ( cachePath , constants . NODE_MODULES_FOLDER_NAME , inspectorNpmPackageName ) ;
5857
5958 if ( ! this . $fs . exists ( pathToPackageInCache ) ) {
60- await this . $childProcess . exec ( `npm cache add ${ inspectorNpmPackageName } @${ version } ` ) ;
61- let inspectorTgzPathInCache = path . join ( pathToPackageInCache , "package.tgz" ) ;
62- await this . $childProcess . exec ( `tar -xf ${ inspectorTgzPathInCache } -C ${ pathToPackageInCache } ` ) ;
63- await this . $childProcess . exec ( `npm install --prefix ${ pathToUnzippedInspector } ` ) ;
59+ const version = await this . getLatestCompatibleVersion ( inspectorNpmPackageName ) ;
60+ await this . $childProcess . exec ( `npm install ${ inspectorNpmPackageName } @${ version } --prefix ${ cachePath } ` ) ;
6461 }
62+
6563 this . $logger . out ( "Using inspector from cache." ) ;
66- return pathToUnzippedInspector ;
64+ return pathToPackageInCache ;
6765 }
66+
6867 return inspectorPath ;
6968 }
7069
70+ private prepareCacheDir ( cacheDirName : string ) : void {
71+ this . $fs . ensureDirectoryExists ( cacheDirName ) ;
72+
73+ const cacheDirPackageJsonLocation = path . join ( cacheDirName , constants . PACKAGE_JSON_FILE_NAME ) ;
74+ if ( ! this . $fs . exists ( cacheDirPackageJsonLocation ) ) {
75+ this . $fs . writeJson ( cacheDirPackageJsonLocation , {
76+ name : constants . INSPECTOR_CACHE_DIRNAME ,
77+ version : "0.1.0"
78+ } ) ;
79+ }
80+ }
81+
7182 private inspectorAlreadyInstalled ( pathToInspector : string ) : Boolean {
7283 if ( this . $fs . exists ( pathToInspector ) ) {
7384 return true ;
0 commit comments