mirror of
https://github.com/harish2704/npm-offline-registry.git
synced 2026-09-10 14:31:09 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a774fee6a | ||
|
|
2afb9b6877 |
@@ -81,6 +81,30 @@ app.get( '/:package/-/:tarball', function( req, res, next ){
|
||||
.catch( next );
|
||||
});
|
||||
|
||||
app.get( '/:scope/:package/-/:tarball', function( req, res, next ){
|
||||
var scopeName = req.params.scope;
|
||||
var packageName = req.params.package;
|
||||
var version = req.params.tarball.match( new RegExp( packageName + '-(.*).tgz') )[1];
|
||||
var packagePath = [ NPM_PATH , scopeName + "/" + packageName, version, 'package.tgz'].join( '/' );
|
||||
|
||||
fileExists( packagePath )
|
||||
.tap( function( isExists ){
|
||||
if( !isExists ){
|
||||
if ( !ENABLE_NPM_FAILOVER ) {
|
||||
res._log.cacheHit = '!!!';
|
||||
return Promise.reject( { status: 404 });
|
||||
}
|
||||
res._log.cacheHit = '---';
|
||||
return fetchAndCacheTarball( packageName, version, packagePath, scopeName );
|
||||
}
|
||||
})
|
||||
.then( function( ){
|
||||
res._log.cacheFile = packagePath;
|
||||
return res.sendFile( packagePath );
|
||||
})
|
||||
.catch( next );
|
||||
});
|
||||
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function(req, res, next) {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "npm-offline-registry",
|
||||
"version": "0.0.8",
|
||||
"version": "0.0.9",
|
||||
"description": "Super simple loca npm registry server for offline usage",
|
||||
"main": "bin/www",
|
||||
"directories": {
|
||||
|
||||
@@ -85,10 +85,13 @@ exports.fetchAndCacheMetadata = function ( packageName, cacheFile ){
|
||||
});
|
||||
};
|
||||
|
||||
exports.fetchAndCacheTarball = function ( packageName, version, tarballPath ){
|
||||
exports.fetchAndCacheTarball = function ( packageName, version, tarballPath, scopeName ){
|
||||
packageName = encodePackageName( packageName );
|
||||
|
||||
var tarballUrl = 'http://' + REGISTRY_NAME + '/' + packageName + '/-/' + packageName + '-' + version + '.tgz';
|
||||
if (scopeName) {
|
||||
tarballUrl = 'http://' + REGISTRY_NAME + '/' + scopeName + '/' + packageName + '/-/' + packageName + '-' + version + '.tgz';
|
||||
}
|
||||
var packageTarballDir = path.dirname( tarballPath );
|
||||
|
||||
return exec( fetchAndCacheTarballCmd, {
|
||||
|
||||
Reference in New Issue
Block a user