Skip to content

Conversation

@DZakh
Copy link
Member

@DZakh DZakh commented Jun 5, 2025

Summary by CodeRabbit

  • New Features

    • Added automatic inclusion of the current envio version in generated projects.
    • Projects now explicitly declare themselves as private and include envio as a dependency.
  • Improvements

    • Enhanced version validation and retrieval for envio, ensuring accurate versioning in generated code.
    • Dynamic path handling for ABI imports in generated Fuel contracts.
    • Extraction now skips .gitkeep files to avoid unnecessary files in new projects.
    • Updated package installation process to improve dependency management during code generation.
  • Chores

    • Removed multiple .npmrc and pnpm-workspace.yaml files from templates and scenarios, streamlining workspace and package manager configurations.
    • Cleaned up configuration files by removing unused or redundant fields.
    • Narrowed workspace scope in specific scenarios to focus on generated packages.

@DZakh DZakh requested a review from JonoPrest June 5, 2025 13:46
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 5, 2025

Warning

Rate limit exceeded

@DZakh has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 15 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between a5e64ba and f9083c4.

⛔ Files ignored due to path filters (1)
  • scenarios/fuel_test/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • codegenerator/cli/npm/envio/package.json (1 hunks)
  • codegenerator/cli/npm/envio/package.json.tmpl (1 hunks)

Walkthrough

This update centralizes version validation and retrieval logic, modifies how dependencies and workspace configurations are managed, and removes several package manager configuration files. It introduces a new method for handling the "envio" version, updates template code and generated files, and adjusts extraction logic to skip .gitkeep files.

Changes

Files / Groups Change Summary
codegenerator/cli/src/commands.rs Removed rescript::clean; made pnpm_install private and changed its logic; updated build messages; removed clean step from post-codegen sequence.
codegenerator/cli/src/config_parsing/system_config.rs Added version validation and retrieval logic (is_valid_release_version_number, get_envio_version), plus related tests.
codegenerator/cli/src/executor/init.rs Refactored to use centralized get_envio_version; removed local version validation and tests.
codegenerator/cli/src/hbs_templating/codegen_templates.rs Added envio_version to ProjectTemplate, initialized via get_envio_version; updated Fuel ABI require path logic.
codegenerator/cli/templates/dynamic/codegen/package.json.hbs Added "private": true and "envio": "{{envio_version}}" dependency.
codegenerator/cli/templates/static/*/.npmrc, scenarios/*/.npmrc Deleted all .npmrc files from templates and scenarios.
codegenerator/cli/templates/static/*/rescript.json Removed "pinned-dependencies" field from all rescript.json files.
codegenerator/cli/templates/static/*/shared/pnpm-workspace.yaml, scenarios/*/pnpm-workspace.yaml, codegenerator/integration_tests/tests/test_indexers/*/pnpm-workspace.yaml Deleted all pnpm-workspace.yaml files from templates, scenarios, and integration tests; in one case, narrowed workspace packages to only ./generated and ../helpers.
codegenerator/cli/templates/static/*/typescript/.npmrc, codegenerator/cli/templates/static/*/javascript/.npmrc Deleted all .npmrc files from TypeScript and JavaScript template directories.
codegenerator/cli/src/template_dirs.rs Modified extraction to skip .gitkeep files.
scenarios/test_codegen/.npmrc Removed trailing newline.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant SystemConfig
    participant Templates

    User->>CLI: Run codegen/init command
    CLI->>SystemConfig: get_envio_version()
    SystemConfig-->>CLI: Returns validated envio version string
    CLI->>Templates: Pass envio_version to ProjectTemplate
    Templates-->>CLI: Generate files with envio_version
    CLI->>CLI: Run pnpm install in generated and project_root
Loading

Suggested labels

codex

Suggested reviewers

  • JonoPrest

Poem

A bunny hops through code so neat,
No .npmrc beneath its feet.
"envio" version now in hand,
Templates updated as we planned.
.gitkeep files, we skip your track—
The workspace pruned, no turning back!
🐇✨


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
codegenerator/cli/src/config_parsing/system_config.rs (1)

392-398: Consider making the local development path construction more robust.

The current implementation assumes the executable is always 3 directories deep from cli/npm/envio. This could break if the directory structure changes or if the executable is in a different location (as your comment suggests with "integration_tests").

Consider:

  1. Using a more robust path resolution method
  2. Checking if the constructed path actually exists before returning it
  3. Handling the different executable locations mentioned in the comment
-        match env::current_exe() {
-            // This should be something like "file:~/envio/hyperindex/codegenerator/target/debug/envio" or "file:.../target/debug/integration_tests"
-            Ok(exe_path) => Ok(format!(
-                "file:{}/../../../cli/npm/envio",
-                exe_path.to_string_lossy()
-            )),
-            Err(e) => Err(anyhow!("failed to get current exe path: {e}")),
-        }
+        match env::current_exe() {
+            Ok(exe_path) => {
+                // Try to find the cli/npm/envio directory relative to the executable
+                let mut current_dir = exe_path.parent().ok_or_else(|| anyhow!("executable has no parent directory"))?;
+                
+                // Go up the directory tree looking for cli/npm/envio
+                for _ in 0..5 { // Limit search depth
+                    let potential_path = current_dir.join("cli/npm/envio");
+                    if potential_path.exists() {
+                        return Ok(format!("file:{}", potential_path.to_string_lossy()));
+                    }
+                    current_dir = match current_dir.parent() {
+                        Some(parent) => parent,
+                        None => break,
+                    };
+                }
+                
+                // Fallback to the original logic if not found
+                Ok(format!(
+                    "file:{}/../../../cli/npm/envio",
+                    exe_path.to_string_lossy()
+                ))
+            }
+            Err(e) => Err(anyhow!("failed to get current exe path: {e}")),
+        }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 074bef0 and e4c10d5.

📒 Files selected for processing (34)
  • codegenerator/cli/src/commands.rs (2 hunks)
  • codegenerator/cli/src/config_parsing/system_config.rs (3 hunks)
  • codegenerator/cli/src/executor/init.rs (3 hunks)
  • codegenerator/cli/src/hbs_templating/codegen_templates.rs (4 hunks)
  • codegenerator/cli/templates/dynamic/codegen/package.json.hbs (2 hunks)
  • codegenerator/cli/templates/static/blank_template/javascript/.npmrc (0 hunks)
  • codegenerator/cli/templates/static/blank_template/rescript/.npmrc (0 hunks)
  • codegenerator/cli/templates/static/blank_template/rescript/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/blank_template/shared/pnpm-workspace.yaml (0 hunks)
  • codegenerator/cli/templates/static/blank_template/typescript/.npmrc (0 hunks)
  • codegenerator/cli/templates/static/erc20_template/javascript/.npmrc (0 hunks)
  • codegenerator/cli/templates/static/erc20_template/rescript/.npmrc (0 hunks)
  • codegenerator/cli/templates/static/erc20_template/rescript/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/erc20_template/shared/pnpm-workspace.yaml (0 hunks)
  • codegenerator/cli/templates/static/erc20_template/typescript/.npmrc (0 hunks)
  • codegenerator/cli/templates/static/greeter_template/javascript/.npmrc (0 hunks)
  • codegenerator/cli/templates/static/greeter_template/rescript/.npmrc (0 hunks)
  • codegenerator/cli/templates/static/greeter_template/rescript/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/greeter_template/shared/pnpm-workspace.yaml (0 hunks)
  • codegenerator/cli/templates/static/greeter_template/typescript/.npmrc (0 hunks)
  • codegenerator/cli/templates/static/greeteronfuel_template/javascript/.npmrc (0 hunks)
  • codegenerator/cli/templates/static/greeteronfuel_template/rescript/.npmrc (0 hunks)
  • codegenerator/cli/templates/static/greeteronfuel_template/rescript/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/greeteronfuel_template/shared/pnpm-workspace.yaml (0 hunks)
  • codegenerator/cli/templates/static/greeteronfuel_template/typescript/.npmrc (0 hunks)
  • codegenerator/integration_tests/tests/test_indexers/dynamic_contracts/pnpm-workspace.yaml (0 hunks)
  • codegenerator/integration_tests/tests/test_indexers/test_exits/pnpm-workspace.yaml (0 hunks)
  • codegenerator/integration_tests/tests/test_indexers/wildcard-uni-factory/pnpm-workspace.yaml (0 hunks)
  • scenarios/erc20_multichain_factory/.npmrc (0 hunks)
  • scenarios/erc20_multichain_factory/pnpm-workspace.yaml (0 hunks)
  • scenarios/fuel_test/.npmrc (0 hunks)
  • scenarios/fuel_test/pnpm-workspace.yaml (0 hunks)
  • scenarios/test_codegen/.npmrc (0 hunks)
  • scenarios/test_codegen/pnpm-workspace.yaml (0 hunks)
💤 Files with no reviewable changes (25)
  • codegenerator/integration_tests/tests/test_indexers/test_exits/pnpm-workspace.yaml
  • scenarios/erc20_multichain_factory/pnpm-workspace.yaml
  • codegenerator/cli/templates/static/greeteronfuel_template/shared/pnpm-workspace.yaml
  • codegenerator/cli/templates/static/erc20_template/rescript/.npmrc
  • scenarios/test_codegen/pnpm-workspace.yaml
  • codegenerator/integration_tests/tests/test_indexers/dynamic_contracts/pnpm-workspace.yaml
  • codegenerator/cli/templates/static/greeter_template/shared/pnpm-workspace.yaml
  • codegenerator/cli/templates/static/greeteronfuel_template/javascript/.npmrc
  • scenarios/test_codegen/.npmrc
  • scenarios/fuel_test/pnpm-workspace.yaml
  • codegenerator/cli/templates/static/greeter_template/rescript/.npmrc
  • codegenerator/cli/templates/static/blank_template/rescript/.npmrc
  • codegenerator/cli/templates/static/blank_template/shared/pnpm-workspace.yaml
  • codegenerator/cli/templates/static/blank_template/javascript/.npmrc
  • codegenerator/cli/templates/static/erc20_template/shared/pnpm-workspace.yaml
  • codegenerator/cli/templates/static/greeteronfuel_template/rescript/.npmrc
  • codegenerator/cli/templates/static/greeter_template/javascript/.npmrc
  • scenarios/erc20_multichain_factory/.npmrc
  • codegenerator/cli/templates/static/blank_template/typescript/.npmrc
  • codegenerator/integration_tests/tests/test_indexers/wildcard-uni-factory/pnpm-workspace.yaml
  • codegenerator/cli/templates/static/greeter_template/typescript/.npmrc
  • codegenerator/cli/templates/static/erc20_template/javascript/.npmrc
  • codegenerator/cli/templates/static/greeteronfuel_template/typescript/.npmrc
  • scenarios/fuel_test/.npmrc
  • codegenerator/cli/templates/static/erc20_template/typescript/.npmrc
🧰 Additional context used
🧬 Code Graph Analysis (1)
codegenerator/cli/src/hbs_templating/codegen_templates.rs (1)
codegenerator/cli/src/config_parsing/system_config.rs (1)
  • get_envio_version (383-400)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_and_test
🔇 Additional comments (15)
codegenerator/cli/templates/static/greeteronfuel_template/rescript/rescript.json (1)

22-22: LGTM! Clean removal of pinned dependencies.

The removal of the "pinned-dependencies" field aligns with the PR objective to centralize version management and eliminate pnpm workspace requirements while preserving the necessary ReScript dependencies.

codegenerator/cli/templates/static/blank_template/rescript/rescript.json (1)

22-22: Consistent dependency configuration cleanup.

This change is consistent with the removal of "pinned-dependencies" across all ReScript templates, maintaining only the necessary "bs-dependencies" for proper functionality.

codegenerator/cli/templates/static/erc20_template/rescript/rescript.json (1)

22-22: Dependency configuration standardized.

The removal of "pinned-dependencies" follows the same pattern as other templates, ensuring consistent dependency management across all ReScript project templates.

codegenerator/cli/templates/static/greeter_template/rescript/rescript.json (1)

22-22: Final template updated consistently.

This completes the uniform removal of "pinned-dependencies" across all ReScript templates, ensuring standardized dependency management while preserving required build dependencies.

codegenerator/cli/templates/dynamic/codegen/package.json.hbs (2)

6-6: Appropriately marks generated packages as private.

Adding "private": true prevents accidental publishing of generated packages, which is the correct approach for code generation templates.


59-59: Centralizes envio version management.

The templated envio dependency "envio": "{{envio_version}}" aligns with the PR's goal to centralize version validation and management, replacing the previous pinned dependency approach with dynamic version injection.

codegenerator/cli/src/executor/init.rs (1)

9-12: Clean refactoring to centralize version validation logic.

Good job moving the version validation logic to a centralized location in system_config.rs. This follows the DRY principle and improves maintainability.

Also applies to: 232-232

codegenerator/cli/src/commands.rs (2)

119-119: More descriptive progress message.

Good improvement - the new message "Generating HyperIndex code..." is more specific than the generic "Building code".


92-108:

✅ Verification successful

Verify the two-step pnpm installation approach.

The new installation process first installs in the generated directory with --no-lockfile, then in the project root. This approach should work without pnpm workspaces, but please verify that:

  1. The envio dependency (dynamically added to package.json as mentioned in the PR summary) is correctly resolved in both directories
  2. Dependencies are properly shared between the generated and root directories without workspace configuration

🏁 Script executed:

#!/bin/bash
# Description: Check for package.json files and their envio dependency configuration

# Find all package.json files in the codebase
fd -t f "package.json" | head -20

# Check if any package.json.hbs template includes envio dependency
fd -t f "package.json.hbs" | xargs grep -l "envio" || echo "No package.json.hbs files with envio dependency found"

# Look for the dynamic envio version injection mentioned in PR summary
rg -A 3 -B 3 "envio.*version" --type handlebars || rg -A 3 -B 3 "envio.*version" -g "*.hbs"

Length of output: 2413


🏁 Script executed:

#!/bin/bash
# Show the context around the generated optional dependency in the shared package.json template
rg -C3 "{{relative_path_from_root_to_generated}}" -g 'codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs'

Length of output: 245


🏁 Script executed:

#!/bin/bash
# Properly escape braces or use fixed string search to show context for the generated optional dependency
rg -F -C3 '{{relative_path_from_root_to_generated}}' -g 'codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs'

Length of output: 826


pnpm installation and envio dependency handling verified

The two-step install correctly handles the dynamically injected envio dependency and the generated directory link:

  • Both codegenerator/cli/templates/dynamic/codegen/package.json.hbs and .../init_templates/shared/package.json.hbs include
    "envio": "{{envio_version}}".
  • The shared template also adds the generated folder as an optional dependency via
    "generated": "{{relative_path_from_root_to_generated}}".

With pnpm install --no-lockfile in generated and pnpm install in the root, envio and the local generated package will be resolved as intended. No further changes are required.

codegenerator/cli/src/config_parsing/system_config.rs (2)

374-381: Version validation logic looks good.

The regex pattern correctly validates semantic versions with optional RC suffix and main branch versions. The implementation is clean and well-focused.


1974-2007: Comprehensive unit tests for version validation.

Excellent test coverage! The tests cover all important cases including:

  • Standard semantic versions
  • Versions with RC suffix
  • Main branch development versions
  • Various invalid formats
codegenerator/cli/src/hbs_templating/codegen_templates.rs (4)

16-17: LGTM: Import addition is correct

The import of get_envio_version from system_config is properly added and aligns with the function usage later in the file.


1245-1245: LGTM: Struct field addition is appropriate

The envio_version: String field addition to ProjectTemplate struct correctly supports the centralized version management approach described in the PR objectives.


1351-1351: LGTM: Correct field initialization

The initialization of envio_version using get_envio_version()? properly calls the centralized function and handles potential errors with the ? operator.


841-847:

❌ Incorrect review comment

Verify template variable syntax and scope

The string interpolation on line 841 uses ${{Path.relativePathToRootFromGenerated}} which appears to be a template variable, but this syntax is unconventional and potentially problematic:

  1. The ${{...}} syntax doesn't match standard Handlebars template syntax ({{...}})
  2. It's unclear where Path.relativePathToRootFromGenerated is defined or how it gets populated
  3. Mixing template variables with Rust string formatting could lead to confusion

🏁 Script executed:

#!/bin/bash
# Search for Path.relativePathToRootFromGenerated usage and definition
rg -A 3 -B 3 "Path\.relativePathToRootFromGenerated"

# Search for similar template variable patterns
rg -A 2 -B 2 '\$\{\{.*\}\}'

# Look for template processing of this generated code
rg -A 5 "transpileAbi.*require"

Length of output: 4315


Ignore incorrect template variable warning

The ${{Path.relativePathToRootFromGenerated}} syntax is intentional: the leading $ starts a JavaScript template‐literal placeholder and the doubled curly braces are a Handlebars variable. At runtime the Rust format! builds this HBS template string, then Handlebars replaces {{Path.relativePathToRootFromGenerated}} with the correct path. You can see the same pattern in:

  • codegenerator/cli/templates/dynamic/codegen/src/RegisterHandlers.res.hbs
    require(`../${Path.relativePathToRootFromGenerated}/${handlerPathRelativeToRoot}`)
  • codegenerator/cli/templates/static/codegen/src/bindings/Dotenv.res
    switch require.resolve(`../../${Path.relativePathToRootFromGenerated}/.env`) {
  • codegenerator/cli/src/hbs_templating/codegen_templates.rs (line 841)

No change needed—this is by design.

Likely an incorrect or invalid review comment.

Comment on lines -117 to -123
println!("Clean build directory");
let exit2 = rescript::clean(&project_paths.generated)
.await
.context("Failed running rescript clean")?;
if !exit2.success() {
return Ok(exit2);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember what case we were worried about stale build 🤔, I assume it's when a file gets removed from generated (but still exists from a stale generated version)

Copy link
Collaborator

@JonoPrest JonoPrest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, these things can be brittle though. At least it shouldn't affect existing indexers

@JonoPrest
Copy link
Collaborator

If we can just fix the failing cargo tests. Looks like its an expected fail now

@DZakh
Copy link
Member Author

DZakh commented Jun 5, 2025

Yes, I've tested several cases, including the upgrade flow from the existing version, and everything appears to be in order.

@DZakh DZakh enabled auto-merge (squash) June 5, 2025 14:59
@JonoPrest
Copy link
Collaborator

Yes, I've tested several cases, including the upgrade flow from the existing version, and everything appears to be in order.

What about when a file gets removed from generated from earlier to later version? I think the generated folder gets purged but I can't remember.

@DZakh
Copy link
Member Author

DZakh commented Jun 5, 2025

What about when a file gets removed from generated from earlier to later version? I think the generated folder gets purged but I can't remember.

Yes, the generated folder is purged on a version change.

@DZakh
Copy link
Member Author

DZakh commented Jun 5, 2025

Otherwise it's upserted

@DZakh DZakh merged commit ee5707b into main Jun 6, 2025
2 checks passed
@DZakh DZakh deleted the dz/remove-dependency-on-workspace branch June 6, 2025 11:33
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.

3 participants