Added support for scoped packages

This commit is contained in:
Admin Phil
2023-06-28 17:00:25 +01:00
parent 8d2102aacd
commit 2afb9b6877
2 changed files with 28 additions and 1 deletions
+24
View File
@@ -81,6 +81,30 @@ app.get( '/:package/-/:tarball', function( req, res, next ){
.catch( 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 // catch 404 and forward to error handler
app.use(function(req, res, next) { app.use(function(req, res, next) {
+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 ); packageName = encodePackageName( packageName );
var tarballUrl = 'http://' + REGISTRY_NAME + '/' + packageName + '/-/' + packageName + '-' + version + '.tgz'; 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 ); var packageTarballDir = path.dirname( tarballPath );
return exec( fetchAndCacheTarballCmd, { return exec( fetchAndCacheTarballCmd, {