Conversation
Implements #55 — users can now update ClaWatch from within the CLI. Features: - Checks current vs latest version from npm registry - Shows comparison with clear visual feedback - Prompts before installing (Y/n) - Auto-detects package manager (npm/yarn/pnpm) - Handles npx users gracefully (explains auto-update behavior) - Supports --check flag for check-only mode (no install) - Graceful error handling for network issues and permission errors - Post-update verification and restart instructions Usage: clawatch update # Check and update interactively clawatch update --check # Check only, don't install
There was a problem hiding this comment.
Pull request overview
Adds a new clawatch update CLI command to check the installed version against the latest npm registry release and (optionally) run a package-manager-specific global upgrade.
Changes:
- Introduces helpers to detect install/package-manager context, fetch latest version from npm registry, and compare versions.
- Adds
clawatch updatewith interactive update flow plus a--checkmode. - Adds post-update verification and restart guidance.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| } | ||
|
|
||
| // Detect package manager | ||
| const { manager, global: isGlobal } = detectPackageManager(); |
|
|
||
| if (opts.check) { | ||
| console.log(chalk.gray(`\n Run "clawatch update" to install.\n`)); | ||
| process.exit(0); |
Comment on lines
+735
to
+744
| // Prompt user | ||
| const readline = require('readline'); | ||
| const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); | ||
|
|
||
| const answer = await new Promise<string>((resolve) => { | ||
| rl.question(chalk.white(`\n Update now? [Y/n] `), (ans: string) => { | ||
| rl.close(); | ||
| resolve(ans.trim().toLowerCase()); | ||
| }); | ||
| }); |
Comment on lines
+641
to
+658
| async function fetchLatestVersion(packageName: string): Promise<string | null> { | ||
| const https = require('https'); | ||
| return new Promise((resolve) => { | ||
| const req = https.get(`https://registry.npmjs.org/${packageName}/latest`, { timeout: 10000 }, (res: any) => { | ||
| let data = ''; | ||
| res.on('data', (chunk: string) => { data += chunk; }); | ||
| res.on('end', () => { | ||
| try { | ||
| const parsed = JSON.parse(data); | ||
| resolve(parsed.version || null); | ||
| } catch { | ||
| resolve(null); | ||
| } | ||
| }); | ||
| }); | ||
| req.on('error', () => resolve(null)); | ||
| req.on('timeout', () => { req.destroy(); resolve(null); }); | ||
| }); |
Comment on lines
+687
to
+690
| if (!latestVersion) { | ||
| console.log(chalk.red('\n ❌ Could not reach npm registry.')); | ||
| console.log(chalk.yellow(' Check your internet connection and try again.\n')); | ||
| process.exit(1); |
Comment on lines
+661
to
+670
| // --- Helper: compare semver versions (returns -1, 0, or 1) --- | ||
| function compareSemver(a: string, b: string): number { | ||
| const pa = a.split('.').map(Number); | ||
| const pb = b.split('.').map(Number); | ||
| for (let i = 0; i < 3; i++) { | ||
| if ((pa[i] || 0) < (pb[i] || 0)) return -1; | ||
| if ((pa[i] || 0) > (pb[i] || 0)) return 1; | ||
| } | ||
| return 0; | ||
| } |
…ror handling Addresses all 6 PR #71 review comments: 1. detectPackageManager now detects local installs (node_modules/.bin) and sets global:false 2. --check mode exits with code 1 when update available (for CI/scripts) 3. Prompt checks process.stdin.isTTY before using readline, fails fast in non-interactive envs 4. fetchLatestVersion URL-encodes package name (scoped package support) and checks status codes 5. Error messages distinguish between connectivity, 404, 429, and parse errors 6. compareSemver strips pre-release/build metadata and validates numeric segments
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature
Adds a
clawatch updatecommand for easy CLI updates.Usage
What it does
Features
--checkflag for CI/scripting (check only, no prompt)Edge Cases Handled
Closes #55