({ args })
| 20 | json: { type: "boolean", description: "Output as JSON", default: false }, |
| 21 | }, |
| 22 | async run({ args }) { |
| 23 | const useJson = args.json === true; |
| 24 | const checkOnly = args.check === true; |
| 25 | |
| 26 | // JSON mode: always force-check and output structured data |
| 27 | if (useJson) { |
| 28 | const result = await checkForUpdate(true); |
| 29 | console.log(JSON.stringify(withMeta(result), null, 2)); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | const autoYes = args.yes === true; |
| 34 | clack.intro(c.bold("hyperframes upgrade")); |
| 35 | |
| 36 | const s = clack.spinner(); |
| 37 | s.start("Checking for updates..."); |
| 38 | |
| 39 | const result = await checkForUpdate(true); |
| 40 | |
| 41 | if (result.latest === result.current) { |
| 42 | s.stop(c.success("Already up to date")); |
| 43 | clack.outro(`${c.success("\u25C7")} ${c.bold("v" + VERSION)}`); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | s.stop("Update available"); |
| 48 | |
| 49 | console.log(); |
| 50 | console.log(` ${c.dim("Current:")} ${c.bold("v" + result.current)}`); |
| 51 | console.log(` ${c.dim("Latest:")} ${c.bold(c.accent("v" + result.latest))}`); |
| 52 | console.log(); |
| 53 | |
| 54 | if (checkOnly) { |
| 55 | clack.outro(c.accent("Update available: v" + result.latest)); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | if (!autoYes) { |
| 60 | const shouldUpgrade = await clack.confirm({ |
| 61 | message: "Upgrade now?", |
| 62 | }); |
| 63 | |
| 64 | if (clack.isCancel(shouldUpgrade) || !shouldUpgrade) { |
| 65 | clack.outro(c.dim("Skipped.")); |
| 66 | return; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // Reject anything that isn't a strict semver-shaped string before it reaches |
| 71 | // the install command. A poisoned npm registry response could otherwise put |
| 72 | // shell metacharacters into `result.latest`; rejecting up front means the |
| 73 | // version flows through execFile (and the displayed command) as an opaque |
| 74 | // token, not something the shell might re-parse. |
| 75 | const SAFE_VERSION = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/; |
| 76 | if (!SAFE_VERSION.test(result.latest)) { |
| 77 | clack.outro(c.dim("Refusing to install: unexpected version string from npm registry.")); |
| 78 | process.exitCode = 1; |
| 79 | return; |
nothing calls this directly
no test coverage detected