Browse Source

Make strict mode as a configurable option ( using env variable )

In strict mode, Only versions available in the cache will appear in the info response.
master 0.0.8
Harish.K 9 years ago
parent
commit
8d2102aacd
  1. 12
      README.md
  2. 6
      config.js
  3. 2
      package.json
  4. 23
      utils.js

12
README.md

@ -1,4 +1,3 @@
# npm-offline-registry
Supper simple NPM registry server for offline NPM install
# Usage
@ -56,3 +55,14 @@ Please check config.js. All config values can be over-written by `environment-va
If you set the ``ENABLE_NPM_FAILOVER`` config value to ``false`` then npm-offlin-registry will not attempt to
contact the upstream NPM registry for unknown packages and instead return a 404 response, meaning you can use
it as an alternative to the NPM registry behind a firewall / isolated from the internet.
# Enabling strict mode
If config value `STRICT` is set to true, while npm checks for the available versions of a given packages,
registry server will reply with list of cached versions.
In this case, if the version is not previously cached, npm-offline-install will fail with, error message `version not available`
example
```bash
env STRICT=true npm-offline-registry`
```

6
config.js

@ -3,7 +3,8 @@ var defaultConfig = {
NPM_PATH : process.env.HOME + '/.npm',
REGISTRY_NAME : 'registry.npmjs.org',
PORT: 8234,
ENABLE_NPM_FAILOVER: true
ENABLE_NPM_FAILOVER: true,
STRICT: false
};
var config = {};
@ -21,5 +22,8 @@ if( config.ENABLE_NPM_FAILOVER == 'false' ){
config.ENABLE_NPM_FAILOVER = false;
}
if( config.STRICT == 'true' ){
config.STRICT = true;
}
module.exports = config;

2
package.json

@ -1,6 +1,6 @@
{
"name": "npm-offline-registry",
"version": "0.0.7",
"version": "0.0.8",
"description": "Super simple loca npm registry server for offline usage",
"main": "bin/www",
"directories": {

23
utils.js

@ -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://';

Loading…
Cancel
Save