|
|
@ -29,17 +29,26 @@ 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 ) ); |
|
|
|
var cacheJsonFile, cacheJsonFileData = []; |
|
|
|
|
|
|
|
if( config.STRICT ){ |
|
|
|
cacheJsonFile = path.join( NPM_PATH, data.name ); |
|
|
|
cacheJsonFileData = fs.existsSync( cacheJsonFile ) ? fs.readdirSync( cacheJsonFile ) : []; |
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
if( cacheJsonFileData.length && config.STRICT ){ |
|
|
|
/* 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 */ |
|
|
|
if( cacheJsonFileData.indexOf(v) == -1 ){ |
|
|
|
delete data.versions[v]; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var protocal = 'http://'; |
|
|
|
if( val.dist.tarball.indexOf( 'https:' ) !== false ){ |
|
|
|
protocal = 'https://'; |
|
|
|