refactor(version): simplify version handling - #414
Conversation
- Export compile-time version and dev-build constants - Update version consumers to use the constants - Classify development builds during macro evaluation
🦋 Changeset detectedLatest commit: af0edc8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughThe CLI now resolves its version and development-build status at build time. Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
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-core/src/lib/version.macro.ts`:
- Around line 15-20: Update isDevVersion to isolate the SemVer prerelease
portion before the + build-metadata delimiter, so dashes in build metadata
cannot identify a development version. Add a compiled-fixture case for
3.1.0+release-dev asserting isDev: false.
🪄 Autofix
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: CHILL
Plan: Pro Plus
Run ID: ebbbf613-0b5d-41e7-9d99-773e54804119
📒 Files selected for processing (15)
.changeset/dry-spoons-bake.md.claude/rules/versioning.mdCLAUDE.mdpackages/cli-core/src/cli-program.tspackages/cli-core/src/commands/doctor/checks.tspackages/cli-core/src/commands/mcp/probe.tspackages/cli-core/src/commands/update/index.tspackages/cli-core/src/lib/credential-store.test.tspackages/cli-core/src/lib/credential-store.tspackages/cli-core/src/lib/update-check.test.tspackages/cli-core/src/lib/update-check.tspackages/cli-core/src/lib/user-agent.tspackages/cli-core/src/lib/version.macro.tspackages/cli-core/src/lib/version.test.tspackages/cli-core/src/lib/version.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
clerk/clerk_go(manual)clerk/dashboard(manual)clerk/accounts(manual)clerk/backoffice(manual)clerk/clerk(manual)clerk/clerk-docs(manual)clerk/cloudflare-workers(manual)clerk/javascript(auto-detected)
| function isDevVersion(version: string): boolean { | ||
| const dash = version.indexOf("-"); | ||
| if (dash === -1) return false; | ||
| const prerelease = version.slice(dash + 1); | ||
| return prerelease === DEV_TAG || prerelease.startsWith(`${DEV_TAG}.`); | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Do not classify build metadata as a prerelease.
isDevVersion("3.1.0+release-dev") returns true because Line 16 finds the dash in build metadata. This is a release SemVer value. IS_DEV_BUILD then disables update checks and changes the macOS keychain namespace.
Stop parsing at + before checking the prerelease identifier. Add a compiled-fixture test for 3.1.0+release-dev with isDev: false.
Proposed fix
function isDevVersion(version: string): boolean {
const dash = version.indexOf("-");
- if (dash === -1) return false;
- const prerelease = version.slice(dash + 1);
+ const buildMetadata = version.indexOf("+");
+ if (dash === -1 || (buildMetadata !== -1 && dash > buildMetadata)) return false;
+ const prerelease = version.slice(dash + 1, buildMetadata === -1 ? undefined : buildMetadata);
return prerelease === DEV_TAG || prerelease.startsWith(`${DEV_TAG}.`);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function isDevVersion(version: string): boolean { | |
| const dash = version.indexOf("-"); | |
| if (dash === -1) return false; | |
| const prerelease = version.slice(dash + 1); | |
| return prerelease === DEV_TAG || prerelease.startsWith(`${DEV_TAG}.`); | |
| } | |
| function isDevVersion(version: string): boolean { | |
| const dash = version.indexOf("-"); | |
| const buildMetadata = version.indexOf("+"); | |
| if (dash === -1 || (buildMetadata !== -1 && dash > buildMetadata)) return false; | |
| const prerelease = version.slice(dash + 1, buildMetadata === -1 ? undefined : buildMetadata); | |
| return prerelease === DEV_TAG || prerelease.startsWith(`${DEV_TAG}.`); | |
| } |
🤖 Prompt for 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.
In `@packages/cli-core/src/lib/version.macro.ts` around lines 15 - 20, Update
isDevVersion to isolate the SemVer prerelease portion before the +
build-metadata delimiter, so dashes in build metadata cannot identify a
development version. Add a compiled-fixture case for 3.1.0+release-dev asserting
isDev: false.
Summary
The version module exposed three functions (
getCurrentVersion(),resolveCliVersion(),isDevVersion()) for what are really two compile-time facts: the version string this binary was built with, and whether that version is a development build. Callers had to remember which accessor answered which question, andresolveCliVersion()returningundefinedfor dev builds encoded "unversioned" as an absent string rather than a boolean.This replaces the accessors with two constants,
CURRENT_VERSIONandIS_DEV_BUILD. The dev classification moves into the Bun macro so it happens once during transpilation alongside version derivation, and the macro now resolvesCLI_VERSIONitself rather than having the consuming module branch on it. That keeps the entire question of what version this is, and whether it is a dev build, in one place. The only signature change isshouldCheckForUpdates, which now takes the boolean directly instead of a version string.Nothing user-visible changes.
clerk --version, the outbound user agent, MCP client info,clerk doctor's CLI version check,clerk update, and the macOS keychain namespacing all produce the same output as before. A new.claude/rules/versioning.mdrecords the constant-over-accessor convention, and the changeset is empty since the change is internal.Test plan
format:check,lint,typecheckcleanversion.test.tscompiles real binaries with and without--define CLI_VERSION, confirming an injected release version still wins over checkout metadata, an injected-dev.*version still classifies as dev, and canary versions stay non-devbun changeset status --since=origin/mainexits clean