mirror of
https://github.com/harish2704/npm-offline-registry.git
synced 2026-09-10 06:21:09 +00:00
Feature: remove the versions not available in the cache while responding to package info requests
This commit is contained in:
@@ -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://';
|
||||||
|
|||||||
Reference in New Issue
Block a user