Created
October 19, 2022 10:09
-
-
Save tonkla/6e84aa5c609191585362aa207a5e9a70 to your computer and use it in GitHub Desktop.
deno outdated : find outdated packages (inspired by yarn/pnpm oudated)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const deps = await Deno.readTextFile('./src/deps.ts') | |
const regexPkg = /(https:\/\/.+)@([^\/]+)/ | |
let isFinding = true | |
Deno.stdout.write(new TextEncoder().encode('.')) | |
const id = setInterval(() => { | |
if (isFinding) Deno.stdout.write(new TextEncoder().encode('.')) | |
}, 250) | |
const packages: { [key: string]: { name: string; version: string } } = {} | |
for (const line of deps.split('\n')) { | |
const pkg = line.match(regexPkg) | |
if (!pkg) continue | |
const key = pkg[0] | |
const name = pkg[1] | |
const version = pkg[2] | |
packages[key] = { name, version } | |
} | |
const outdated: string[][] = [] | |
for (const pkg of Object.values(packages)) { | |
const res = await fetch(pkg.name) | |
const latest = res.url.split('@')[1] | |
if (pkg.version !== latest) { | |
outdated.push([pkg.name, pkg.version, latest]) | |
} | |
} | |
isFinding = false | |
clearInterval(id) | |
console.info('\n') | |
if (outdated.length > 0) { | |
for (const pkg of outdated) { | |
console.info(pkg[0], ' ⟹ ', { current: pkg[1], latest: pkg[2] }) | |
} | |
} else { | |
console.info('All packages are updated.') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment