Skip to content

Commit 7f0822d

Browse files
committed
Update outdated to generate latests.json
This also adds some logging as it is excruciatingly slow and I want to know what it is doing.
1 parent ca74390 commit 7f0822d

File tree

2 files changed

+200
-14
lines changed

2 files changed

+200
-14
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"pinned": [
3+
"ENTER_PACKAGE_NAME_HERE"
4+
],
5+
"latests": {
6+
"aerospike": "5.13.2",
7+
"amqp10": "3.6.0",
8+
"amqplib": "0.10.4",
9+
"apollo-server-core": "3.13.0",
10+
"@apollo/server": "4.11.2",
11+
"@apollo/gateway": "2.9.3",
12+
"avsc": "5.7.7",
13+
"@smithy/smithy-client": "3.4.4",
14+
"@aws-sdk/smithy-client": "3.374.0",
15+
"aws-sdk": "2.1692.0",
16+
"@azure/functions": "4.6.0",
17+
"bluebird": "3.7.2",
18+
"body-parser": "1.20.3",
19+
"bunyan": "1.8.15",
20+
"cassandra-driver": "4.7.2",
21+
"connect": "3.7.0",
22+
"cookie-parser": "1.4.7",
23+
"cookie": "1.0.1",
24+
"couchbase": "4.4.3",
25+
"@cucumber/cucumber": "11.1.0",
26+
"cypress": "13.15.2",
27+
"@elastic/transport": "8.9.1",
28+
"@elastic/elasticsearch": "8.16.1",
29+
"elasticsearch": "16.7.3",
30+
"express-mongo-sanitize": "2.2.0",
31+
"express": "4.21.1",
32+
"fastify": "5.1.0",
33+
"find-my-way": "9.1.0",
34+
"fs": "0.0.1-security",
35+
"generic-pool": "3.9.0",
36+
"@google-cloud/pubsub": "4.9.0",
37+
"@graphql-tools/executor": "1.3.3",
38+
"graphql": "16.9.0",
39+
"@grpc/grpc-js": "1.12.2",
40+
"handlebars": "4.7.8",
41+
"@hapi/hapi": "21.3.12",
42+
"hapi": "18.1.0",
43+
"ioredis": "5.4.1",
44+
"jest-environment-node": "29.7.0",
45+
"jest-environment-jsdom": "29.7.0",
46+
"@jest/core": "29.7.0",
47+
"@jest/test-sequencer": "29.7.0",
48+
"@jest/reporters": "29.7.0",
49+
"jest-circus": "29.7.0",
50+
"@jest/transform": "29.7.0",
51+
"jest-config": "29.7.0",
52+
"jest-runtime": "29.7.0",
53+
"jest-worker": "29.7.0",
54+
"kafkajs": "2.2.4",
55+
"knex": "3.1.0",
56+
"koa": "2.15.3",
57+
"@koa/router": "13.1.0",
58+
"koa-router": "13.0.1",
59+
"ldapjs": "3.0.7",
60+
"limitd-client": "2.14.1",
61+
"lodash": "4.17.21",
62+
"mariadb": "3.4.0",
63+
"memcached": "2.2.2",
64+
"microgateway-core": "3.3.4",
65+
"moleculer": "0.14.35",
66+
"mongodb-core": "3.2.7",
67+
"mongodb": "6.10.0",
68+
"mongoose": "8.8.2",
69+
"mquery": "5.0.0",
70+
"multer": "1.4.5-lts.1",
71+
"mysql": "2.18.1",
72+
"mysql2": "3.11.4",
73+
"next": "15.0.3",
74+
"nyc": "17.1.0",
75+
"openai": "4.72.0",
76+
"@opensearch-project/opensearch": "2.13.0",
77+
"oracledb": "6.7.0",
78+
"paperplane": "3.1.2",
79+
"passport-http": "0.3.0",
80+
"passport-local": "1.0.0",
81+
"pg": "8.13.1",
82+
"pino": "9.5.0",
83+
"pino-pretty": "13.0.0",
84+
"@playwright/test": "1.49.0",
85+
"playwright": "1.49.0",
86+
"promise-js": "0.0.7",
87+
"promise": "8.3.0",
88+
"protobufjs": "7.4.0",
89+
"pug": "3.0.3",
90+
"q": "1.5.1",
91+
"qs": "6.13.1",
92+
"@node-redis/client": "1.0.6",
93+
"@redis/client": "1.6.0",
94+
"redis": "4.7.0",
95+
"restify": "11.1.0",
96+
"rhea": "3.0.3",
97+
"router": "1.3.8",
98+
"selenium-webdriver": "4.26.0",
99+
"sequelize": "6.37.5",
100+
"sharedb": "5.1.1",
101+
"tedious": "18.6.1",
102+
"undici": "6.21.0",
103+
"vitest": "2.1.5",
104+
"@vitest/runner": "2.1.5",
105+
"when": "3.7.8",
106+
"winston": "3.17.0"
107+
}
108+
}

scripts/outdated.js

Lines changed: 92 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
const {
23
getInternals,
34
npmView
@@ -14,38 +15,115 @@ const latestsPath = path.join(
1415
'helpers',
1516
'latests.json'
1617
)
17-
const latestsJson = require(latestsPath)
18+
19+
// Get internal package names from existing getInternals helper
1820
const internalsNames = Array.from(new Set(getInternals().map(n => n.name)))
1921
.filter(x => typeof x === 'string' && x !== 'child_process' && !x.startsWith('node:'))
2022

21-
// TODO A lot of this can be optimized by using `npm outdated`.
23+
// Initial structure with placeholder for pinned packages
24+
const initialStructure = {
25+
pinned: ['ENTER_PACKAGE_NAME_HERE'],
26+
latests: {}
27+
}
2228

29+
/**
30+
* Updates latests.json with the current latest versions from npm
31+
*/
2332
async function fix () {
33+
console.log('Starting fix operation...')
34+
console.log(`Found ${internalsNames.length} packages to process`)
35+
36+
let outputData = initialStructure
37+
if (fs.existsSync(latestsPath)) {
38+
console.log('Found existing latests.json, loading it...')
39+
outputData = require(latestsPath)
40+
}
41+
2442
const latests = {}
43+
let processed = 0
44+
const total = internalsNames.length
45+
2546
for (const name of internalsNames) {
26-
const distTags = await npmView(name + ' dist-tags')
27-
const latest = distTags.latest
28-
latests[name] = latest
47+
processed++
48+
process.stdout.write(`Processing package ${processed}/${total}: ${name}...`)
49+
50+
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`)
56+
} else {
57+
process.stdout.write(' WARNING: no version found\n')
58+
console.log(`Warning: Could not fetch latest version for "${name}"`)
59+
}
60+
} catch (error) {
61+
process.stdout.write(' ERROR\n')
62+
console.error(`Error fetching version for "${name}":`, error.message)
63+
}
2964
}
30-
latestsJson.latests = latests
31-
fs.writeFileSync(latestsPath, JSON.stringify(latestsJson, null, 2))
65+
66+
outputData.latests = latests
67+
console.log('\nWriting updated versions to latests.json...')
68+
fs.writeFileSync(latestsPath, JSON.stringify(outputData, null, 2))
69+
console.log('Successfully updated latests.json')
70+
console.log(`Processed ${total} packages`)
3271
}
3372

73+
/**
74+
* Checks if latests.json matches current npm versions
75+
*/
3476
async function check () {
77+
console.log('Starting version check...')
78+
79+
if (!fs.existsSync(latestsPath)) {
80+
console.log('latests.json does not exist. Run with "fix" to create it.')
81+
process.exitCode = 1
82+
return
83+
}
84+
85+
const currentData = require(latestsPath)
86+
console.log(`Found ${internalsNames.length} packages to check`)
87+
88+
let processed = 0
89+
let mismatches = 0
90+
const total = internalsNames.length
91+
3592
for (const name of internalsNames) {
36-
const latest = latestsJson.latests[name]
93+
processed++
94+
process.stdout.write(`Checking package ${processed}/${total}: ${name}...`)
95+
96+
const latest = currentData.latests[name]
3797
if (!latest) {
98+
process.stdout.write(' MISSING\n')
3899
console.log(`No latest version found for "${name}"`)
39100
process.exitCode = 1
101+
continue
40102
}
41-
const distTags = await npmView(name + ' dist-tags')
42-
const npmLatest = distTags.latest
43-
if (npmLatest !== latest) {
44-
console.log(`"latests.json: is not up to date for "${name}": expected "${npmLatest}", got "${latest}"`)
45-
process.exitCode = 1
103+
104+
try {
105+
const distTags = await npmView(name + ' dist-tags')
106+
const npmLatest = distTags.latest
107+
if (npmLatest !== latest) {
108+
process.stdout.write(' MISMATCH\n')
109+
console.log(`"latests.json: is not up to date for "${name}": expected "${npmLatest}", got "${latest}"`)
110+
process.exitCode = 1
111+
mismatches++
112+
} else {
113+
process.stdout.write(' OK\n')
114+
}
115+
} catch (error) {
116+
process.stdout.write(' ERROR\n')
117+
console.error(`Error checking version for "${name}":`, error.message)
46118
}
47119
}
48-
}
49120

121+
console.log('\nCheck completed:')
122+
console.log(`- Total packages checked: ${total}`)
123+
console.log(`- Version mismatches found: ${mismatches}`)
124+
if (mismatches > 0) {
125+
console.log('Run with "fix" to update versions')
126+
}
127+
}
50128
if (process.argv.includes('fix')) fix()
51129
else check()

0 commit comments

Comments
 (0)