Skip to content

Commit 67809b2

Browse files
committed
Cleanup outdated to handle various one-off issues
1 parent 01bb8df commit 67809b2

File tree

2 files changed

+123
-106
lines changed

2 files changed

+123
-106
lines changed

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
{
22
"pinned": [
3-
"ENTER_PACKAGE_NAME_HERE"
3+
"fastify"
4+
],
5+
"onlyUseLatestTag": [],
6+
"ignored": [
7+
"aerospike",
8+
"mariadb",
9+
"microgateway-core",
10+
"winston"
411
],
512
"latests": {
6-
"aerospike": "6.1.0",
713
"amqp10": "3.6.0",
814
"amqplib": "0.10.5",
915
"apollo-server-core": "3.13.0",
@@ -13,7 +19,7 @@
1319
"@smithy/smithy-client": "4.1.6",
1420
"@aws-sdk/smithy-client": "3.374.0",
1521
"aws-sdk": "2.1692.0",
16-
"@azure/functions": "4.6.1",
22+
"@azure/functions": "4.7.0",
1723
"bluebird": "3.7.2",
1824
"body-parser": "2.1.0",
1925
"bunyan": "2.0.5",
@@ -30,18 +36,18 @@
3036
"express-mongo-sanitize": "2.2.0",
3137
"express-session": "1.18.1",
3238
"express": "5.0.1",
33-
"fastify": "5.2.1",
39+
"fastify": "4.28.1",
3440
"find-my-way": "9.2.0",
3541
"fs": "0.0.2",
3642
"generic-pool": "3.9.0",
3743
"@google-cloud/pubsub": "4.10.0",
38-
"@graphql-tools/executor": "1.4.3",
44+
"@graphql-tools/executor": "1.4.4",
3945
"graphql": "16.10.0",
4046
"@grpc/grpc-js": "1.12.6",
4147
"handlebars": "4.7.8",
42-
"@hapi/hapi": "21.3.12",
48+
"@hapi/hapi": "21.4.0",
4349
"hapi": "18.1.0",
44-
"ioredis": "5.5.0",
50+
"ioredis": "5.6.0",
4551
"jest-environment-node": "29.7.0",
4652
"jest-environment-jsdom": "29.7.0",
4753
"@jest/core": "29.7.0",
@@ -62,21 +68,19 @@
6268
"ldapjs": "3.0.7",
6369
"limitd-client": "2.14.1",
6470
"lodash": "4.17.21",
65-
"mariadb": "3.4.0",
6671
"memcached": "2.2.2",
67-
"microgateway-core": "3.3.5",
6872
"moleculer": "0.14.35",
6973
"mongodb-core": "3.2.7",
7074
"mongodb": "6.14.2",
7175
"mongoose": "8.12.1",
7276
"mquery": "5.0.0",
7377
"multer": "1.4.5-lts.1",
7478
"mysql": "2.18.1",
75-
"mysql2": "3.12.0",
79+
"mysql2": "3.13.0",
7680
"next": "15.2.1",
7781
"node-serialize": "0.0.4",
7882
"nyc": "17.1.0",
79-
"openai": "4.86.1",
83+
"openai": "4.86.2",
8084
"@opensearch-project/opensearch": "3.4.0",
8185
"oracledb": "6.8.0",
8286
"paperplane": "3.1.2",
@@ -86,8 +90,8 @@
8690
"pg": "8.13.3",
8791
"pino": "9.6.0",
8892
"pino-pretty": "13.0.0",
89-
"@playwright/test": "1.50.1",
90-
"playwright": "1.50.1",
93+
"@playwright/test": "1.51.0",
94+
"playwright": "1.51.0",
9195
"promise-js": "0.0.7",
9296
"promise": "8.3.0",
9397
"protobufjs": "7.4.0",
@@ -104,9 +108,8 @@
104108
"sharedb": "5.2.0",
105109
"tedious": "19.0.0",
106110
"undici": "7.4.0",
107-
"vitest": "3.0.7",
108-
"@vitest/runner": "3.0.7",
109-
"when": "3.7.8",
110-
"winston": "3.17.0"
111+
"vitest": "3.0.8",
112+
"@vitest/runner": "3.0.8",
113+
"when": "3.7.8"
111114
}
112115
}

scripts/outdated.js

Lines changed: 103 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable no-console */
2-
const {
3-
getInternals,
4-
npmView
5-
} = require('./helpers/versioning')
2+
'use strict'
3+
4+
const { getInternals } = require('./helpers/versioning')
65
const path = require('path')
76
const fs = require('fs')
87
const semver = require('semver')
8+
const childProcess = require('child_process')
99

1010
const latestsPath = path.join(
1111
__dirname,
@@ -17,25 +17,83 @@ const latestsPath = path.join(
1717
'latests.json'
1818
)
1919

20-
// Get internal package names from existing getInternals helper
2120
const internalsNames = Array.from(new Set(getInternals().map(n => n.name)))
2221
.filter(x => typeof x === 'string' && x !== 'child_process' && !x.startsWith('node:'))
2322

24-
// Initial structure with placeholder for configuration
25-
const initialStructure = {
26-
pinned: ['ENTER_PACKAGE_NAME_HERE'],
27-
onlyUseLatestTag: ['ENTER_PACKAGE_NAME_HERE'],
23+
// Packages that should be ignored during version checking - these won't be included in latests.json
24+
const IGNORED_PACKAGES = [
25+
// Add package names here
26+
'aerospike', // I think this is due to architecture issues?
27+
'mariadb', // mariadb esm tests were failing
28+
'microgateway-core', // 'microgateway-core' was failing to find a directory
29+
'winston' // winston esm tests were failing
30+
]
31+
32+
// Packages that should be pinned to specific versions
33+
const PINNED_PACKAGES = {
34+
// Example: 'express': '4.17.3'
35+
fastify: '4.28.1' // v5+ is not supported
36+
}
37+
38+
// Packages that should only use the 'latest' tag (not 'next' or other dist-tags)
39+
// Some packages have a next tag that is a stable semver version
40+
const ONLY_USE_LATEST_TAG = [
41+
// Example: 'router'
42+
]
43+
44+
// Initial structure for latests.json that will be recreated each run
45+
const outputData = {
46+
pinned: Object.keys(PINNED_PACKAGES),
47+
onlyUseLatestTag: ONLY_USE_LATEST_TAG,
48+
ignored: IGNORED_PACKAGES,
2849
latests: {}
2950
}
3051

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 = {}) {
52+
function npmView (input) {
53+
return new Promise((resolve, reject) => {
54+
childProcess.exec(`npm view ${input} --json`, (err, stdout) => {
55+
if (err) {
56+
reject(err)
57+
return
58+
}
59+
try {
60+
resolve(JSON.parse(stdout.toString('utf8')))
61+
} catch (e) {
62+
reject(new Error(`Failed to parse npm output for ${input}: ${e.message}`))
63+
}
64+
})
65+
})
66+
}
67+
68+
async function getHighestCompatibleVersion (name) {
3669
try {
70+
if (IGNORED_PACKAGES.includes(name)) {
71+
console.log(`Skipping "${name}" as it's in the ignored list`)
72+
return null
73+
}
74+
75+
// If package is hardcoded as pinned, return the pinned version but also check latest
76+
// this is for logging purposes
77+
if (PINNED_PACKAGES[name]) {
78+
const pinnedVersion = PINNED_PACKAGES[name]
79+
80+
try {
81+
const distTags = await npmView(`${name} dist-tags`)
82+
const latestTagged = distTags.latest
83+
84+
if (latestTagged && semver.gt(latestTagged, pinnedVersion)) {
85+
console.log(`Note: "${name}" is pinned to ${pinnedVersion}, but ${latestTagged} is available`)
86+
}
87+
} catch (err) {
88+
// Just log the error but continue with the pinned version
89+
console.log(`Warning: Could not fetch latest version for pinned package "${name}": ${err.message}`)
90+
}
91+
92+
return pinnedVersion
93+
}
94+
3795
// Get all distribution tags (including 'latest')
38-
const distTags = await npmView(name + ' dist-tags')
96+
const distTags = await npmView(`${name} dist-tags`)
3997

4098
// Get the latest tagged version
4199
const latestTagged = distTags.latest
@@ -46,12 +104,12 @@ async function getHighestCompatibleVersion (name, config = {}) {
46104
}
47105

48106
// If package is in the onlyUseLatestTag list, always use the 'latest' tag
49-
if (config.onlyUseLatestTag && config.onlyUseLatestTag.includes(name)) {
107+
if (ONLY_USE_LATEST_TAG.includes(name)) {
50108
return latestTagged
51109
}
52110

53111
// Get all available versions
54-
const allVersions = await npmView(name + ' versions')
112+
const allVersions = await npmView(`${name} versions`)
55113

56114
// Find the highest non-prerelease version available
57115
const stableVersions = allVersions.filter(v => !semver.prerelease(v))
@@ -77,12 +135,7 @@ async function fix () {
77135
console.log('Starting fix operation...')
78136
console.log(`Found ${internalsNames.length} packages to process`)
79137

80-
let outputData = initialStructure
81-
if (fs.existsSync(latestsPath)) {
82-
console.log('Found existing latests.json, loading it...')
83-
outputData = require(latestsPath)
84-
}
85-
138+
// Process packages
86139
const latests = {}
87140
let processed = 0
88141
const total = internalsNames.length
@@ -91,87 +144,48 @@ async function fix () {
91144
processed++
92145
process.stdout.write(`Processing package ${processed}/${total}: ${name}...`)
93146

147+
// Skip ignored packages
148+
if (IGNORED_PACKAGES.includes(name)) {
149+
process.stdout.write(' IGNORED\n')
150+
continue
151+
}
152+
94153
try {
95-
const latestVersion = await getHighestCompatibleVersion(name, outputData)
154+
// Handle hardcoded pinned packages
155+
if (PINNED_PACKAGES[name]) {
156+
const pinnedVersion = PINNED_PACKAGES[name]
157+
latests[name] = pinnedVersion
158+
process.stdout.write(` PINNED to version ${pinnedVersion}\n`)
159+
continue
160+
}
161+
162+
// Normal package processing
163+
const latestVersion = await getHighestCompatibleVersion(name)
96164
if (latestVersion) {
97165
latests[name] = latestVersion
98166
process.stdout.write(` found version ${latestVersion}\n`)
99167
} else {
100168
process.stdout.write(' WARNING: no version found\n')
101-
console.log(`Warning: Could not fetch latest version for "${name}"`)
102169
}
103170
} catch (error) {
104171
process.stdout.write(' ERROR\n')
105-
console.error(`Error fetching version for "${name}":`, error.message)
172+
console.error(`Error processing "${name}":`, error.message)
106173
}
107174
}
108175

176+
// Update the output data
109177
outputData.latests = latests
110-
console.log('\nWriting updated versions to latests.json...')
111-
fs.writeFileSync(latestsPath, JSON.stringify(outputData, null, 2))
112-
console.log('Successfully updated latests.json')
113-
console.log(`Processed ${total} packages`)
114-
}
115178

116-
/**
117-
* Checks if latests.json matches current npm versions
118-
*/
119-
async function check () {
120-
console.log('Starting version check...')
121-
122-
if (!fs.existsSync(latestsPath)) {
123-
console.log('latests.json does not exist. Run with "fix" to create it.')
124-
process.exitCode = 1
125-
return
126-
}
127-
128-
const currentData = require(latestsPath)
129-
console.log(`Found ${internalsNames.length} packages to check`)
130-
131-
let processed = 0
132-
let mismatches = 0
133-
const total = internalsNames.length
134-
135-
for (const name of internalsNames) {
136-
processed++
137-
process.stdout.write(`Checking package ${processed}/${total}: ${name}...`)
138-
139-
const latest = currentData.latests[name]
140-
if (!latest) {
141-
process.stdout.write(' MISSING\n')
142-
console.log(`No latest version found for "${name}"`)
143-
process.exitCode = 1
144-
continue
145-
}
179+
// Write the updated configuration with a comment at the top
180+
console.log('\nWriting updated versions to latests.json...')
146181

147-
try {
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-
}
182+
// Convert to JSON with proper indentation
183+
const jsonContent = JSON.stringify(outputData, null, 2)
154184

155-
if (latestVersion !== latest) {
156-
process.stdout.write(' MISMATCH\n')
157-
console.log(`"latests.json: is not up to date for "${name}": expected "${latestVersion}", got "${latest}"`)
158-
process.exitCode = 1
159-
mismatches++
160-
} else {
161-
process.stdout.write(' OK\n')
162-
}
163-
} catch (error) {
164-
process.stdout.write(' ERROR\n')
165-
console.error(`Error checking version for "${name}":`, error.message)
166-
}
167-
}
185+
fs.writeFileSync(latestsPath, jsonContent)
168186

169-
console.log('\nCheck completed:')
170-
console.log(`- Total packages checked: ${total}`)
171-
console.log(`- Version mismatches found: ${mismatches}`)
172-
if (mismatches > 0) {
173-
console.log('Run with "fix" to update versions')
174-
}
187+
console.log('Successfully updated latests.json')
188+
console.log(`Processed ${total} packages`)
175189
}
176-
if (process.argv.includes('fix')) fix()
177-
else check()
190+
191+
fix()

0 commit comments

Comments
 (0)