2 Commits
Author SHA1 Message Date
harish2704 7a774fee6a Updated package version 2023-06-29 10:12:43 +05:30
Admin Phil 2afb9b6877 Added support for scoped packages 2023-06-28 17:00:25 +01:00
3 changed files with 29 additions and 2 deletions
+24
View File
@@ -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
View File
@@ -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": {
+4 -1
View File
@@ -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, {