Skip to content

Instantly share code, notes, and snippets.

@wraithgar
Last active February 28, 2022 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wraithgar/d5c974ee8e4a7e08ded89742c15e96ce to your computer and use it in GitHub Desktop.
Save wraithgar/d5c974ee8e4a7e08ded89742c15e96ce to your computer and use it in GitHub Desktop.
batch latest versions for a given npm package
'use strict'
const pacote = require('pacote')
const fetch = require('npm-registry-fetch')
const semver = require('semver')
const perRequest = 10
async function main() {
const manifest = await pacote.manifest(process.argv[2])
const dependencies = Object.keys(manifest.dependencies)
for (let i = 0; i <= dependencies.length; i = i + perRequest) {
const slice = dependencies.slice(i, i + perRequest).map(d => `${d.split('/').join('%2f')}@*`)
const uri = `-/npm/v1/dependencies/${slice.join(';')}`
const batch = await fetch.json(uri)
for (const dep in batch) {
const max = semver.sort(batch[dep].versions).slice(-1)
console.log(`${dep} (${manifest.dependencies[dep]}): ${max}`)
}
}
}
main().then(() => process.exit(0)).catch(err => { console.error(err); process.exit(1); })
'use strict'
const pacote = require('pacote')
const fetch = require('npm-registry-fetch')
const semver = require('semver')
const perRequest = 10
async function main() {
const manifest = await pacote.manifest(process.argv[2])
const dependencies = Object.keys(manifest.dependencies)
for (let i = 0; i <= dependencies.length; i = i + perRequest) {
const slice = dependencies.slice(i, i + perRequest).map(d => `${d.split('/').join('%2f')}@${encodeURI(manifest.dependencies[d])}`)
const uri = `-/npm/v1/dependencies/${slice.join(';')}`
const batch = await fetch.json(uri)
for (const dep in batch) {
const max = semver.maxSatisfying(batch[dep].versions, manifest.dependencies[dep])
console.log(`${dep} (${manifest.dependencies[dep]}): ${max}`)
}
}
}
main().then(() => process.exit(0)).catch(err => { console.error(err); process.exit(1); })
$ node all-latest pacote
cacache (^15.3.0): 15.3.0
chownr (^2.0.0): 2.0.0
fs-minipass (^2.1.0): 2.1.0
infer-owner (^1.0.4): 1.0.4
minipass (^3.1.6): 3.1.6
mkdirp (^1.0.4): 1.0.4
@npmcli/git (^3.0.0): 3.0.0
@npmcli/installed-package-contents (^1.0.7): 1.0.7
@npmcli/promise-spawn (^1.2.0): 1.3.2
@npmcli/run-script (^3.0.0): 3.0.0
npm-package-arg (^9.0.0): 9.0.0
npm-packlist (^3.0.0): 3.0.0
npm-pick-manifest (^7.0.0): 7.0.0
npm-registry-fetch (^13.0.0): 13.0.0
proc-log (^2.0.0): 2.0.0
promise-retry (^2.0.1): 2.0.1
read-package-json (^4.1.1): 4.1.1
read-package-json-fast (^2.0.3): 2.0.3
rimraf (^3.0.2): 3.0.2
ssri (^8.0.1): 8.0.1
tar (^6.1.11): 6.1.11
$ node all-highest pacote
cacache (^15.3.0): 15.3.0
chownr (^2.0.0): 2.0.0
fs-minipass (^2.1.0): 2.1.0
infer-owner (^1.0.4): 1.0.4
minipass (^3.1.6): 3.1.6
mkdirp (^1.0.4): 1.0.4
@npmcli/git (^3.0.0): 3.0.0
@npmcli/installed-package-contents (^1.0.7): 1.0.7
@npmcli/promise-spawn (^1.2.0): 2.0.0
@npmcli/run-script (^3.0.0): 3.0.0
npm-package-arg (^9.0.0): 9.0.0
npm-packlist (^3.0.0): 3.0.0
npm-pick-manifest (^7.0.0): 7.0.0
npm-registry-fetch (^13.0.0): 13.0.0
proc-log (^2.0.0): 2.0.0
promise-retry (^2.0.1): 2.0.1
read-package-json (^4.1.1): 4.1.1
read-package-json-fast (^2.0.3): 2.0.3
rimraf (^3.0.2): 3.0.2
ssri (^8.0.1): 8.0.1
tar (^6.1.11): 6.1.11
@wraithgar
Copy link
Author

all-latest.js does the newest possible given the existing semver in the manifest.
all-highest.js does the newest possible given all of the semver ranges in the registry.

@wraithgar
Copy link
Author

Notice @npmcli/promise-spawn is a different result based on which script is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment