Add automatic Prisma CLI update checks#57
Conversation
Verification: pnpm build:cli passed. TMPDIR=/tmp pnpm --filter @prisma/cli exec vitest run tests/update-check.test.ts --testTimeout 30000 passed. Full CLI suite with TMPDIR=/tmp and --testTimeout 30000 still fails in unrelated app/env/auth/project tests in this worktree; update-check.test.ts passes.
Verification: pnpm build:cli passed. TMPDIR=/tmp pnpm --filter @prisma/cli exec vitest run tests/update-check.test.ts --testTimeout 30000 passed. Full CLI suite remains red in unrelated app/env/auth/project tests in this worktree.
Verification: pnpm build:cli passed. TMPDIR=/tmp pnpm --filter @prisma/cli exec vitest run tests/update-check.test.ts --testTimeout 30000 passed. Full CLI suite remains red in unrelated app/env/auth/project tests in this worktree.
Verification: pnpm build:cli passed. TMPDIR=/tmp pnpm --filter @prisma/cli exec vitest run tests/update-check.test.ts tests/version.test.ts tests/shell.test.ts --testTimeout 30000 passed. Full CLI suite remains red in unrelated app/env/auth/project tests in this worktree. Publish staging was not run per operator instruction.
Summary by CodeRabbit
WalkthroughThis PR adds automatic CLI update notifications as an advisory feature. The CLI now checks for newer versions from npm, caches the result locally, and displays a notification to stderr when a stale version is detected—gated by TTY, CI, test mode, and explicit flags ( ChangesAutomatic Update Check Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cli/src/shell/update-check.ts`:
- Around line 97-103: The UpdateCheckStore.write call in the discovery update
replaces the entire cache entry and drops the existing notifiedAt timestamp; to
fix this, read the existing entry from UpdateCheckStore (or use
UpdateCheckStore.read/get) before calling write, merge the existing notifiedAt
into the new object (e.g., preserve existingEntry?.notifiedAt when creating the
payload for UpdateCheckStore.write), and then write the merged object; apply the
same merge logic for the other discovery write site around the code referenced
at lines 151-153 so notification throttling is preserved.
- Around line 36-45: The read() method currently rethrows on any non-ENOENT
error which causes parse/permission failures to abort update-check; change
read() (and the similar logic around lines 62-80) to treat unreadable or
unparsable cache files as a corrupt cache: catch JSON.parse and permission
errors, optionally attempt to unlink the cache file (fs.unlink) or at minimum
log the problem, then return null instead of throwing so the update-check flow
still proceeds to schedule discovery; update references to UpdateCheckState and
ensure callers that expect null continue to work.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: dba6da29-685a-4910-b920-a0b26c744d77
📒 Files selected for processing (6)
docs/product/command-spec.mddocs/product/output-conventions.mdpackages/cli/src/bin.tspackages/cli/src/cli.tspackages/cli/src/shell/update-check.tspackages/cli/tests/update-check.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cli/tests/update-check.test.ts`:
- Line 28: The test's expectation for the exact docs URL in update-check.test.ts
is brittle and points to a page that doesn't specifically contain step-by-step
CLI update instructions; update the assertion around expect(result.stderr) (the
expectation that currently contains "See
https://www.prisma.io/docs/orm/tools/prisma-cli for update instructions.") to
reference the correct, authoritative update instructions URL or loosen the check
(e.g., assert presence of a more general help domain or a shorter message like
"See prisma.io/docs for update instructions") so the test matches the intended
guidance; locate the expect(result.stderr).toContain(...) call and replace the
literal URL with the appropriate URL or a less strict substring/regex that
matches the intended user guidance.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: fc7da6c2-3f46-49f3-8f78-be2db334949c
📒 Files selected for processing (3)
docs/product/output-conventions.mdpackages/cli/src/shell/update-check.tspackages/cli/tests/update-check.test.ts
Adds advisory update checks to the CLI so interactive users can learn when a newer
@prisma/clirelease is available without changing command results or automation behavior.Changes
Update check shell flow: Adds
packages/cli/src/shell/update-check.tsand wires it intopackages/cli/src/cli.tsso cached stale-version notices render before eligible human command output. Notices are stderr-only and skipped for CI,--json,--quiet, non-TTY stderr,--version, tests by default, andNO_UPDATE_NOTIFIER.Background discovery: Adds a detached worker path in
packages/cli/src/bin.tsthat checks the npmlatestdist-tag for@prisma/cliat most once every 24 hours. Discovery uses a 3s fetch timeout, persists only package/version/check metadata in a user-level cache, and silently ignores network or registry failures.Update instructions: Adds best-effort install guidance for local npm, global npm, pnpm, and Bun installs. Ephemeral or ambiguous invocations such as
npx,pnpx,bunx, and unknown launch paths fall back tohttps://prisma.io/docsinstead of guessing.Product docs and planning artifacts: Documents update-notification stream behavior in
docs/product/output-conventions.mdand global command behavior indocs/product/command-spec.md. Includes the resolved spec and phased execution plan underdocs/specs.Coverage: Adds
packages/cli/tests/update-check.test.tsfor cached notices, suppression rules, stdout/JSON stability, interval behavior, stubbed registry discovery, failed discovery, and package-manager instruction selection.Why
The CLI beta changes quickly, so users need a low-friction way to discover newer releases. The implementation keeps this advisory and automation-safe: command stdout remains machine-readable, command exit codes are unchanged, and remote discovery never blocks the original command. Cached notifications are separated from background npm lookup so short commands stay fast and offline or restricted environments fail silently.