Skip to content

Commit 01bb8df

Browse files
committed
Attempt to handle stable non-latest versions
1 parent a7aff38 commit 01bb8df

File tree

2 files changed

+69
-21
lines changed

2 files changed

+69
-21
lines changed

packages/datadog-instrumentations/src/helpers/latests.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"aws-sdk": "2.1692.0",
1616
"@azure/functions": "4.6.1",
1717
"bluebird": "3.7.2",
18-
"body-parser": "1.20.3",
19-
"bunyan": "1.8.15",
18+
"body-parser": "2.1.0",
19+
"bunyan": "2.0.5",
2020
"cassandra-driver": "4.8.0",
2121
"connect": "3.7.0",
2222
"cookie-parser": "1.4.7",
@@ -29,10 +29,10 @@
2929
"elasticsearch": "16.7.3",
3030
"express-mongo-sanitize": "2.2.0",
3131
"express-session": "1.18.1",
32-
"express": "4.21.2",
32+
"express": "5.0.1",
3333
"fastify": "5.2.1",
3434
"find-my-way": "9.2.0",
35-
"fs": "0.0.1-security",
35+
"fs": "0.0.2",
3636
"generic-pool": "3.9.0",
3737
"@google-cloud/pubsub": "4.10.0",
3838
"@graphql-tools/executor": "1.4.3",
@@ -92,17 +92,17 @@
9292
"promise": "8.3.0",
9393
"protobufjs": "7.4.0",
9494
"pug": "3.0.3",
95-
"q": "1.5.1",
95+
"q": "2.0.3",
9696
"@node-redis/client": "1.0.6",
9797
"@redis/client": "1.6.0",
9898
"redis": "4.7.0",
9999
"restify": "11.1.0",
100100
"rhea": "3.0.3",
101-
"router": "1.3.8",
101+
"router": "2.1.0",
102102
"selenium-webdriver": "4.29.0",
103103
"sequelize": "6.37.6",
104104
"sharedb": "5.2.0",
105-
"tedious": "18.6.1",
105+
"tedious": "19.0.0",
106106
"undici": "7.4.0",
107107
"vitest": "3.0.7",
108108
"@vitest/runner": "3.0.7",

scripts/outdated.js

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
} = require('./helpers/versioning')
66
const path = require('path')
77
const fs = require('fs')
8+
const semver = require('semver')
89

910
const latestsPath = path.join(
1011
__dirname,
@@ -20,15 +21,58 @@ const latestsPath = path.join(
2021
const internalsNames = Array.from(new Set(getInternals().map(n => n.name)))
2122
.filter(x => typeof x === 'string' && x !== 'child_process' && !x.startsWith('node:'))
2223

23-
// Initial structure with placeholder for pinned packages
24+
// Initial structure with placeholder for configuration
2425
const initialStructure = {
2526
pinned: ['ENTER_PACKAGE_NAME_HERE'],
27+
onlyUseLatestTag: ['ENTER_PACKAGE_NAME_HERE'],
2628
latests: {}
2729
}
2830

2931
/**
30-
* Updates latests.json with the current latest versions from npm
31-
*/
32+
* Gets the highest version that's compatible with our instrumentation
33+
* This handles cases where a package has newer versions that might break compatibility
34+
*/
35+
async function getHighestCompatibleVersion (name, config = {}) {
36+
try {
37+
// Get all distribution tags (including 'latest')
38+
const distTags = await npmView(name + ' dist-tags')
39+
40+
// Get the latest tagged version
41+
const latestTagged = distTags.latest
42+
43+
if (!latestTagged) {
44+
console.log(`Warning: Could not fetch latest version for "${name}"`)
45+
return null
46+
}
47+
48+
// If package is in the onlyUseLatestTag list, always use the 'latest' tag
49+
if (config.onlyUseLatestTag && config.onlyUseLatestTag.includes(name)) {
50+
return latestTagged
51+
}
52+
53+
// Get all available versions
54+
const allVersions = await npmView(name + ' versions')
55+
56+
// Find the highest non-prerelease version available
57+
const stableVersions = allVersions.filter(v => !semver.prerelease(v))
58+
const highestStableVersion = stableVersions.sort(semver.compare).pop()
59+
60+
// Use the highest stable version if it's greater than the latest tag
61+
if (highestStableVersion && semver.gt(highestStableVersion, latestTagged)) {
62+
process.stdout.write(` found version ${highestStableVersion} (higher than 'latest' tag ${latestTagged})`)
63+
return highestStableVersion
64+
}
65+
66+
return latestTagged
67+
} catch (error) {
68+
console.error(`Error fetching version for "${name}":`, error.message)
69+
return null
70+
}
71+
}
72+
73+
/**
74+
* Updates latests.json with the current latest versions from npm
75+
*/
3276
async function fix () {
3377
console.log('Starting fix operation...')
3478
console.log(`Found ${internalsNames.length} packages to process`)
@@ -48,11 +92,10 @@ async function fix () {
4892
process.stdout.write(`Processing package ${processed}/${total}: ${name}...`)
4993

5094
try {
51-
const distTags = await npmView(name + ' dist-tags')
52-
const latest = distTags.latest
53-
if (latest) {
54-
latests[name] = latest
55-
process.stdout.write(` found version ${latest}\n`)
95+
const latestVersion = await getHighestCompatibleVersion(name, outputData)
96+
if (latestVersion) {
97+
latests[name] = latestVersion
98+
process.stdout.write(` found version ${latestVersion}\n`)
5699
} else {
57100
process.stdout.write(' WARNING: no version found\n')
58101
console.log(`Warning: Could not fetch latest version for "${name}"`)
@@ -71,8 +114,8 @@ async function fix () {
71114
}
72115

73116
/**
74-
* Checks if latests.json matches current npm versions
75-
*/
117+
* Checks if latests.json matches current npm versions
118+
*/
76119
async function check () {
77120
console.log('Starting version check...')
78121

@@ -102,11 +145,16 @@ async function check () {
102145
}
103146

104147
try {
105-
const distTags = await npmView(name + ' dist-tags')
106-
const npmLatest = distTags.latest
107-
if (npmLatest !== latest) {
148+
const latestVersion = await getHighestCompatibleVersion(name, currentData)
149+
if (!latestVersion) {
150+
process.stdout.write(' ERROR\n')
151+
console.error(`Error fetching latest version for "${name}"`)
152+
continue
153+
}
154+
155+
if (latestVersion !== latest) {
108156
process.stdout.write(' MISMATCH\n')
109-
console.log(`"latests.json: is not up to date for "${name}": expected "${npmLatest}", got "${latest}"`)
157+
console.log(`"latests.json: is not up to date for "${name}": expected "${latestVersion}", got "${latest}"`)
110158
process.exitCode = 1
111159
mismatches++
112160
} else {

0 commit comments

Comments
 (0)