@@ -47,27 +47,38 @@ export class NpmInstallationManager implements INpmInstallationManager {
47
47
}
48
48
49
49
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 ) ;
51
51
52
52
// local installation takes precedence over cache
53
53
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 ) ;
58
57
59
58
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 } ` ) ;
64
61
}
62
+
65
63
this . $logger . out ( "Using inspector from cache." ) ;
66
- return pathToUnzippedInspector ;
64
+ return pathToPackageInCache ;
67
65
}
66
+
68
67
return inspectorPath ;
69
68
}
70
69
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
+
71
82
private inspectorAlreadyInstalled ( pathToInspector : string ) : Boolean {
72
83
if ( this . $fs . exists ( pathToInspector ) ) {
73
84
return true ;
0 commit comments