Skip to content

Commit a2c4de0

Browse files
committed
Attempt to limit capping to within major versions
1 parent 27c442a commit a2c4de0

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

scripts/install_plugin_modules.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,34 @@ async function assertPackage (name, version, dependencyVersionRange, external) {
246246
// Apply version cap from latests.json if available
247247
let cappedVersionRange = dependencyVersionRange
248248

249-
if (latests.latests[name]) {
250-
const latestVersion = latests.latests[name]
251-
252-
// Only process string version ranges
253-
if (dependencyVersionRange && typeof dependencyVersionRange === 'string') {
254-
cappedVersionRange = applyCap(dependencyVersionRange, latestVersion)
249+
// Handle simple major version numbers like "1" or exact versions like "1.0.0"
250+
if (dependencyVersionRange) {
251+
const simpleVersionMatch = dependencyVersionRange.match(/^(\d+)$/)
252+
const exactVersionMatch = dependencyVersionRange.match(/^(\d+)\.(\d+)\.(\d+)$/)
253+
254+
// Attempt to fix issue seen with fastify
255+
if (simpleVersionMatch) {
256+
// For simple major versions like "1", restrict to that major version only
257+
const majorVersion = simpleVersionMatch[1]
258+
cappedVersionRange = `>=${majorVersion}.0.0 <${parseInt(majorVersion) + 1}.0.0`
259+
} else if (exactVersionMatch) {
260+
// For exact versions like "1.0.0", still restrict to the same major version
261+
const majorVersion = exactVersionMatch[1]
262+
cappedVersionRange = `>=${dependencyVersionRange} <${parseInt(majorVersion) + 1}.0.0`
263+
} else if (latests.latests[name]) {
264+
// Apply normal capping for other version ranges
265+
const latestVersion = latests.latests[name]
266+
if (typeof dependencyVersionRange === 'string') {
267+
cappedVersionRange = applyCap(dependencyVersionRange, latestVersion)
268+
}
255269
}
256270
}
271+
257272
const dependencies = { [name]: cappedVersionRange }
258273
if (deps[name]) {
259274
await addDependencies(dependencies, name, cappedVersionRange)
260275
}
276+
261277
const pkg = {
262278
name: [name, sha1(name).substr(0, 8), sha1(version)].filter(val => val).join('-'),
263279
version: '1.0.0',
@@ -279,7 +295,6 @@ async function assertPackage (name, version, dependencyVersionRange, external) {
279295
}
280296
fs.writeFileSync(filename(name, version, 'package.json'), JSON.stringify(pkg, null, 2) + '\n')
281297
}
282-
283298
async function addDependencies (dependencies, name, versionRange) {
284299
const versionList = await getVersionList(name)
285300
const version = semver.maxSatisfying(versionList, versionRange)

0 commit comments

Comments
 (0)