Skip to content

Use npm package version for release builds#1008

Merged
DZakh merged 6 commits intomainfrom
claude/fix-envio-path-error-xq3lQ
Mar 3, 2026
Merged

Use npm package version for release builds#1008
DZakh merged 6 commits intomainfrom
claude/fix-envio-path-error-xq3lQ

Conversation

@DZakh
Copy link
Member

@DZakh DZakh commented Mar 3, 2026

Summary

This PR updates the version detection logic to prioritize the npm package's package.json version for release builds, while maintaining fallback to local development mode detection.

Key Changes

  • New read_version_from_package_json() function: Reads the version from the npm platform package's package.json file by traversing up from the executable location (<pkg>/bin/envio<pkg>/package.json)
  • Updated get_envio_version() logic: Now uses a two-tier approach:
    1. First attempts to read version from npm package's package.json (used for published releases)
    2. Falls back to walking up the directory tree to find local packages/envio (for development)
  • Replaced static version constant: Changed from compile-time CURRENT_CRATE_VERSION constant to a runtime current_version() function that uses OnceLock for lazy initialization
  • Updated all version references: Modified persisted_state, codegen, dev, and mod modules to use the new current_version() function
  • Updated test snapshots: Changed expected version from "0.0.1-dev" to "dev" in all codegen template snapshots

Implementation Details

  • The version detection now gracefully handles both npm-installed and locally-built binaries
  • Uses OnceLock to ensure the version is computed only once and cached for the lifetime of the application
  • Maintains backward compatibility with development workflows while enabling proper version tracking for npm releases
  • Error handling provides clear guidance when package.json cannot be found (suggests reinstalling via pnpm)

https://claude.ai/code/session_01QvDMVPq3tH4A1EQqtxudj2

Summary by CodeRabbit

  • Refactor
    • Improved CLI version detection to read from the package manifest as the primary source, with fallback handling for development environments.
    • Enhanced version reporting and mismatch validation across CLI commands.

claude added 6 commits March 3, 2026 17:57
The CI refactor (5932048) dropped the Cargo.toml version patching step
that was in the old release.yml. Without it, release binaries are compiled
with version "0.0.1-dev", causing get_envio_version() to walk up the
filesystem looking for packages/envio — which doesn't exist when the
binary is installed via npm.

- Add "Set version in Cargo.toml" step to build-platforms.yml
- Add linux-x64 (musl) to build-platforms.yml matrix so all 4 release
  binaries get the correct version baked in
- Update publish.yml to download all platform packages from build-platforms
  instead of reusing the dev linux-x64 from build_and_verify

https://claude.ai/code/session_01QvDMVPq3tH4A1EQqtxudj2
Instead of relying solely on the compile-time CARGO_PKG_VERSION (which
requires Cargo.toml patching during CI), read the version from the
sibling package.json of the npm platform package at runtime.

This avoids rebuilding linux-x64 in the publish pipeline — the binary
from build_and_verify (compiled with 0.0.1-dev) will read the correct
version from the package.json that publish.yml already patches.

The Cargo.toml patching in build-platforms.yml is kept as a safety net
for the 3 other platforms.

Fallback order:
1. ../package.json version (npm-installed binaries)
2. Compile-time CARGO_PKG_VERSION (standalone binaries)
3. Filesystem walk for packages/envio (local dev)

https://claude.ai/code/session_01QvDMVPq3tH4A1EQqtxudj2
The runtime package.json read is the sole mechanism for determining
the version in published binaries. No need for Cargo.toml patching
in CI or the compile-time version fallback in get_envio_version().

Note: CURRENT_CRATE_VERSION in persisted_state still uses
CARGO_PKG_VERSION for detecting version changes during codegen.

https://claude.ai/code/session_01QvDMVPq3tH4A1EQqtxudj2
Replace CURRENT_CRATE_VERSION static (compile-time CARGO_PKG_VERSION)
with current_version() function that reads from the npm platform
package's package.json at runtime, cached via OnceLock. Falls back
to CARGO_PKG_VERSION for local dev builds.

This ensures persisted state correctly detects version changes between
envio upgrades in published binaries.

https://claude.ai/code/session_01QvDMVPq3tH4A1EQqtxudj2
…errors

The function now returns descriptive error messages (e.g. "Could not
read package.json ... Try reinstalling with: pnpm add envio") instead
of silently returning None.

current_version() still falls back to "dev" for local dev/test builds
where no package.json exists, while get_envio_version() surfaces the
error when both package.json and packages/envio are missing.

https://claude.ai/code/session_01QvDMVPq3tH4A1EQqtxudj2
@DZakh DZakh enabled auto-merge (squash) March 3, 2026 18:21
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dacd062 and 4d82b05.

⛔ Files ignored due to path filters (7)
  • packages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__internal_config_json_code_generated_for_evm.snap is excluded by !**/*.snap
  • packages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__internal_config_json_code_generated_for_fuel.snap is excluded by !**/*.snap
  • packages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__internal_config_json_code_omits_default_values.snap is excluded by !**/*.snap
  • packages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__internal_config_json_code_with_all_options.snap is excluded by !**/*.snap
  • packages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__internal_config_json_code_with_lowercase_contract_name.snap is excluded by !**/*.snap
  • packages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__internal_config_json_code_with_multiple_contracts.snap is excluded by !**/*.snap
  • packages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__internal_config_json_code_with_no_contracts.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • packages/cli/src/config_parsing/system_config.rs
  • packages/cli/src/executor/codegen.rs
  • packages/cli/src/executor/dev.rs
  • packages/cli/src/executor/mod.rs
  • packages/cli/src/hbs_templating/codegen_templates.rs
  • packages/cli/src/persisted_state/mod.rs

📝 Walkthrough

Walkthrough

A refactoring that replaces the hard-coded CURRENT_CRATE_VERSION constant with dynamic version retrieval from package.json. The system_config module introduces a helper to read versions from package.json with fallback logic, while persisted_state adds a lazily-initialized current_version() function that sources versions dynamically and falls back to "dev".

Changes

Cohort / File(s) Summary
Version Retrieval Infrastructure
packages/cli/src/config_parsing/system_config.rs, packages/cli/src/persisted_state/mod.rs
Added read_version_from_package_json() helper with fallback logic; introduced current_version() public function with lazy initialization and fallback to "dev"; reworked version retrieval to read dynamically from package.json instead of environment variables.
Version Usage Updates
packages/cli/src/executor/codegen.rs, packages/cli/src/executor/dev.rs, packages/cli/src/executor/mod.rs, packages/cli/src/hbs_templating/codegen_templates.rs
Replaced all direct imports and usage of CURRENT_CRATE_VERSION constant with calls to persisted_state::current_version() function; updated import paths and version comparison logic across version-dependent operations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A version tale, from constants we flee,
Now lazy and dynamic, how fair to see!
From package.json our versions now brew,
With fallbacks to "dev" when all else is through,
The refactor hops on with purpose so true! 📦✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Use npm package version for release builds' accurately describes the main change: switching from compile-time version constants to runtime package.json reads for release builds.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/fix-envio-path-error-xq3lQ

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DZakh DZakh merged commit 70bdcca into main Mar 3, 2026
7 checks passed
@DZakh DZakh deleted the claude/fix-envio-path-error-xq3lQ branch March 3, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants