Browse Source

Feature: remove the versions not available in the cache while responding to package info requests

master
Harish.K 9 years ago
parent
commit
4b9c7f88db
  1. 11
      utils.js

11
utils.js

@ -6,6 +6,7 @@ var _exec = Promise.promisify( require('child_process').exec );
var REGISTRY_NAME = config.REGISTRY_NAME; var REGISTRY_NAME = config.REGISTRY_NAME;
var LOCAL_REGISTRY = config.LOCAL_REGISTRY; var LOCAL_REGISTRY = config.LOCAL_REGISTRY;
var NPM_PATH = config.NPM_PATH;
function exec( cmd, envVars ){ function exec( cmd, envVars ){
@ -27,8 +28,18 @@ exports.readFile = readFile;
exports.patchData = function ( data ){ 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 ){ Object.keys(data.versions).forEach( function( v ){
var val = data.versions[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://'; var protocal = 'http://';
if( val.dist.tarball.indexOf( 'https:' ) !== false ){ if( val.dist.tarball.indexOf( 'https:' ) !== false ){
protocal = 'https://'; protocal = 'https://';

Loading…
Cancel
Save