From 4b9c7f88db733e229d5fefd5a87bd20c12f907b7 Mon Sep 17 00:00:00 2001 From: "Harish.K" Date: Sat, 15 Oct 2016 12:12:54 +0530 Subject: [PATCH] Feature: remove the versions not available in the cache while responding to package info requests --- utils.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/utils.js b/utils.js index 0205a47..f5be964 100644 --- a/utils.js +++ b/utils.js @@ -6,6 +6,7 @@ var _exec = Promise.promisify( require('child_process').exec ); var REGISTRY_NAME = config.REGISTRY_NAME; var LOCAL_REGISTRY = config.LOCAL_REGISTRY; +var NPM_PATH = config.NPM_PATH; function exec( cmd, envVars ){ @@ -27,8 +28,18 @@ exports.readFile = readFile; exports.patchData = function ( data ){ + /* Get the list of versions which is available in local cache */ + var cachedVersions = fs.readdirSync( path.join( NPM_PATH, data.name ) ); Object.keys(data.versions).forEach( function( v ){ var val = data.versions[v]; + + /* Suppose our cache.json is at latest revision. It contains lot of versions which is not available in local cache. + Then, Remove the versions which is not in local cache from the list. Otherwise npm will always choose higher versions whcih is not available in our cache */ + /* TODO: If this feature causing problem, We can make this behaviour optional via some commandline-arguments/Env-variables */ + if( cachedVersions.indexOf(v) == -1 ){ + delete data.versions[v]; + return; + } var protocal = 'http://'; if( val.dist.tarball.indexOf( 'https:' ) !== false ){ protocal = 'https://';