Speed up test suite by using local npm.js stub
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import semver from 'semver';
|
||||
|
||||
import asyncHandler from '../utils/asyncHandler.js';
|
||||
import createPackageURL from '../utils/createPackageURL.js';
|
||||
import { getPackageConfig, resolveVersion } from '../utils/npm.js';
|
||||
import { getPackageConfig, getVersionsAndTags } from '../utils/npm.js';
|
||||
|
||||
function semverRedirect(req, res, newVersion) {
|
||||
res
|
||||
@ -15,6 +17,24 @@ function semverRedirect(req, res, newVersion) {
|
||||
);
|
||||
}
|
||||
|
||||
async function resolveVersion(packageName, range) {
|
||||
const versionsAndTags = await getVersionsAndTags(packageName);
|
||||
|
||||
if (versionsAndTags) {
|
||||
const { versions, tags } = versionsAndTags;
|
||||
|
||||
if (range in tags) {
|
||||
range = tags[range];
|
||||
}
|
||||
|
||||
return versions.includes(range)
|
||||
? range
|
||||
: semver.maxSatisfying(versions, range);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the package version/tag in the URL and make sure it's good. Also
|
||||
* fetch the package config and add it to req.packageConfig. Redirect to
|
||||
|
||||
Reference in New Issue
Block a user