|
| 1 | +import { defineAction } from "codeup"; |
| 2 | +import { updatePackageJSON } from "../../src/utils/pkg"; |
| 3 | + |
| 4 | +export default defineAction({ |
| 5 | + meta: { |
| 6 | + name: "update-deps", |
| 7 | + description: "Upgrade dependencies to latest versions", |
| 8 | + date: "2025-10-06", |
| 9 | + }, |
| 10 | + async apply({ utils }) { |
| 11 | + await utils.runPackageManagerCommand('upgrade') |
| 12 | + await updatePackageJSON(async (pkg) => { |
| 13 | + if (pkg.devDependencies) { |
| 14 | + await Promise.allSettled(Object.keys(pkg.devDependencies).map(async (name) => { |
| 15 | + const info = await getRegistryInfo(name); |
| 16 | + const latest = info["dist-tags"].latest |
| 17 | + pkg.devDependencies![name] = `^${latest}`; |
| 18 | + })); |
| 19 | + } |
| 20 | + if (pkg.packageManager) { |
| 21 | + const name = pkg.packageManager.split('@')[0]; |
| 22 | + const info = await getRegistryInfo(name); |
| 23 | + const latest = info["dist-tags"].latest |
| 24 | + pkg.packageManager = `${name}@${latest}`; |
| 25 | + } |
| 26 | + }) |
| 27 | + const pm = await utils.detectPackageManager(); |
| 28 | + for (const lockfileName of [pm?.lockFile].flat().filter(Boolean)) { |
| 29 | + // await utils.remove(lockfileName) |
| 30 | + console.log(`Removing ${lockfileName}`) |
| 31 | + } |
| 32 | + await utils.runPackageManagerCommand('outdated', { ignoreErrors: true }) |
| 33 | + }, |
| 34 | +}); |
| 35 | + |
| 36 | + |
| 37 | +interface RegistryInfo { |
| 38 | + name: string; |
| 39 | + "dist-tags": Record<string, string>; |
| 40 | + versions: Record<string, any>; |
| 41 | +} |
| 42 | + |
| 43 | +async function getRegistryInfo(name: string) { |
| 44 | + return await fetch(`https://registry.npmjs.org/${name}`).then(res => res.json()) as RegistryInfo; |
| 45 | +} |
0 commit comments