Skip to content

Conversation

@DZakh
Copy link
Member

@DZakh DZakh commented Jun 6, 2025

Fixes: https://github.com/enviodev/hyperindex/actions/runs/15489582249/job/43611811130

Summary by CodeRabbit

  • New Features

    • Introduced a standalone CLI script to assist with migrating projects to updated entry points and scripts.
  • Bug Fixes

    • Corrected handler file paths and import statements throughout configuration files, scripts, and documentation to use the .res.js extension instead of .bs.js.
    • Updated test and start scripts to reference .res.js files for improved compatibility.
  • Chores

    • Updated .gitignore and configuration files to align with new ReScript output conventions.
    • Added and adjusted dependencies in package files.
    • Improved script and template consistency across multiple project templates.
  • Documentation

    • Refreshed documentation and example commands to reflect the new file naming conventions.
  • Refactor

    • Updated internal field names and visibility for improved maintainability.
    • Removed deprecated or unnecessary script arguments.

@DZakh DZakh marked this pull request as draft June 6, 2025 15:17
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 6, 2025

Walkthrough

This update systematically replaces references to BuckleScript output files (.bs.js, .bs.mjs) with the newer ReScript output conventions (.res.js, .res.mjs) across configuration files, code imports, templates, and documentation. Several package scripts, ignore patterns, and test configurations are updated accordingly. Minor enhancements and field additions are also included in Rust code and template structures.

Changes

File(s) / Group Change Summary
.gitignore files (various) Updated ignore patterns from *.bs.js/*.bs.mjs to *.res.js/*.res.mjs.
rescript.json (various) Changed output file suffix from .bs.js to .res.js.
config.yaml, README.md (various) Updated handler paths and documentation references from .bs.js to .res.js.
package.json, package.json.tmpl, package.json.hbs (various) Updated scripts and file inclusions to use .res.js; added/removed dependencies; raised Node.js engine version in templates.
Mocha config (.mocharc.json, .mocharc.json) Changed test file pattern from **/*.bs.js to **/*.res.js.
JavaScript/TypeScript imports (various) Updated import/require paths from .bs.js/.bs to .res.js.
Rust source (init_config.rs, commands.rs, graph_migration/mod.rs) Updated file path returns for ReScript handlers from .bs.js to .res.js; changed working directory in command execution.
Rust struct changes (codegen_templates.rs, handler_paths.rs) Added has_typescript: bool to ProjectTemplate; made relative_to_config field public in HandlerPathsTemplate.
Templates (various .hbs files) Updated script commands, dependencies, and entry points from .bs.js to .res.js; simplified script logic.
Static codegen/src/Config.res Improved error logging by prettifying exceptions before logging.
Static codegen/src/Index.bs.js Added new CLI migration script for updating package.json and launching envio start.
Static codegen/src/Index.res Removed syncFromRawEvents boolean argument from args type.
Static codegen/src/db/DbFunctionsImplementation.js Updated imports to .res.js; removed trailing commas in SQL templates and function calls.
Test helpers and integration tests (various) Updated import paths and start scripts from .bs.js to .res.js.
Shell scripts (integration_tests) Changed indexer start commands from using $envio_cmd to direct pnpm commands.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI Script
    participant File System
    participant Child Process

    User->>CLI Script: Run Index.bs.js migration script
    CLI Script->>File System: Search for package.json upwards
    File System-->>CLI Script: Return path to package.json
    CLI Script->>File System: Read and parse package.json
    CLI Script->>File System: Update start script to use 'envio start'
    CLI Script->>File System: Write updated package.json
    CLI Script->>Child Process: Spawn 'envio start'
    Child Process-->>CLI Script: Forward stdout/stderr, exit code
    CLI Script-->>User: Log status and exit
Loading

Poem

Hop, hop, a suffix swap!
From .bs.js to .res.js, we hop nonstop.
Ignore files tidy, configs align,
Scripts and handlers all redesigned.
With every leap, our code grows bright—
ReScript bunnies coding right!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

@DZakh
Copy link
Member Author

DZakh commented Jun 9, 2025

The PR has two breaking changes:

  • ReScript users should start using .res.js for the indexer as well
  • Js/Ts users should update their start script. This can be mitigated by making envio start run Node.js directly, without using user's scripts

@DZakh
Copy link
Member Author

DZakh commented Jun 9, 2025

Related to #568

Comment on lines 23 to 26
{{#if is_typescript}}
"start": "ts-node generated/src/Index.bs.js"
"start": "ts-node generated/src/Index.res.js"
{{else}}
"start": "node generated/src/Index.bs.js"
Copy link
Member Author

Choose a reason for hiding this comment

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

This will break for existing indexers

@DZakh
Copy link
Member Author

DZakh commented Jun 9, 2025

Note: The PR is still draft, I need to include envio start change to make it usable

@@ -0,0 +1,135 @@
#!/usr/bin/env node
Copy link
Member Author

Choose a reason for hiding this comment

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

Should look like this, but for some reason it's not included to the generated directory

image

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, looks like it's working correctly now

Copy link
Collaborator

Choose a reason for hiding this comment

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

When does this script get run?

Should it always be logging this migration log?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this file ".bs.js"? Surely it should just be Index.js?

@DZakh DZakh marked this pull request as ready for review June 9, 2025 12:37
@DZakh
Copy link
Member Author

DZakh commented Jun 9, 2025

The main problem here was that the rescript project doesn't build rescript-schema, which is the envio dependency. So as a solution, I changed .bs.js to .res.js, since .res.js is prebuilt and published in rescript-schema package.

I should have also install all dependencies correctly, as well as update the start script. And prevent envio start from depending on the user's start script.

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: 5

♻️ Duplicate comments (1)
codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs (1)

19-19: This breaking change aligns with the migration goals but requires user action.

The simplified start script using envio start instead of direct file execution is part of the broader migration from .bs.js to .res.js naming. This change will require existing users to update their workflows.

🧹 Nitpick comments (8)
codegenerator/cli/src/project_paths/handler_paths.rs (1)

12-12: Expose relative_to_config as public for external access
The relative_to_config field is now accessible outside this module, which aligns with its intended use in codegen templates. Consider whether the other path fields (relative_to_generated_src, relative_to_project_root) should also be exposed via getters or made public for API consistency.

codegenerator/cli/templates/static/blank_template/shared/.gitignore (1)

33-34: Add .res.js and .res.mjs ignore patterns
These entries ensure generated ReScript files are excluded from version control. For conciseness, you could merge them into a single glob pattern (e.g., *.res.{js,mjs}).

scenarios/helpers/.gitignore (1)

8-8: Ignore new ReScript module format
Adding *.res.mjs ensures generated ES modules are excluded from version control, consistent with .res.js ignores.

Consider removing *.bs.js if BuckleScript outputs are no longer generated.

scenarios/fuel_test/.gitignore (1)

32-33: Clean up legacy ignore patterns

Consider removing *.bs.js now that only .res.js is generated. Dropping obsolete patterns avoids clutter and potential confusion.

codegenerator/cli/templates/static/erc20_template/rescript/config.yaml (1)

10-10: Standardize handler path syntax

The other template uses ./src/.... For consistency, prepend ./ here as well:

-handler: src/EventHandlers.res.js
+handler: ./src/EventHandlers.res.js
codegenerator/integration_tests/tests/test_indexers/test_exits/package.json (1)

9-9: Consider using node instead of ts-node for .res.js artifacts
Since this entrypoint is a plain JS file generated by ReScript, running it with node generated/src/Index.res.js avoids pulling in the TypeScript runtime and may simplify dependencies.

scenarios/test_codegen/.gitignore (1)

31-32: Remove obsolete .bs.js patterns if fully migrated
You’ve added *.res.js and *.res.mjs but still list *.bs.js/*.bs.mjs below. Dropping the old patterns will prevent accidentally committing stale BuckleScript artifacts.

codegenerator/integration_tests/tests/test_indexers/dynamic_contracts/package.json (1)

12-12: Point start script to ReScript entrypoint

The start script now runs Index.res.js in the generated output, reflecting the suffix migration.

Consider using node generated/src/Index.res.js instead of ts-node for pure JavaScript files to simplify execution.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ee5707b and 39a818d.

⛔ Files ignored due to path filters (1)
  • scenarios/test_codegen/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (61)
  • codegenerator/cli/npm/envio/.gitignore (1 hunks)
  • codegenerator/cli/npm/envio/index.js (2 hunks)
  • codegenerator/cli/npm/envio/package.json (1 hunks)
  • codegenerator/cli/npm/envio/package.json.tmpl (2 hunks)
  • codegenerator/cli/npm/envio/rescript.json (1 hunks)
  • codegenerator/cli/npm/envio/src/bindings/BigDecimal.gen.ts (1 hunks)
  • codegenerator/cli/npm/envio/src/bindings/Ethers.gen.ts (1 hunks)
  • codegenerator/cli/src/cli_args/init_config.rs (1 hunks)
  • codegenerator/cli/src/commands.rs (1 hunks)
  • codegenerator/cli/src/config_parsing/graph_migration/mod.rs (2 hunks)
  • codegenerator/cli/src/hbs_templating/codegen_templates.rs (2 hunks)
  • codegenerator/cli/src/project_paths/handler_paths.rs (1 hunks)
  • codegenerator/cli/templates/dynamic/codegen/package.json.hbs (2 hunks)
  • codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs (2 hunks)
  • codegenerator/cli/templates/dynamic/subgraph_migration_templates/javascript/src/EventHandlers.js.hbs (1 hunks)
  • codegenerator/cli/templates/static/blank_template/rescript/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/blank_template/shared/.gitignore (1 hunks)
  • codegenerator/cli/templates/static/codegen/.gitignore (1 hunks)
  • codegenerator/cli/templates/static/codegen/index.js (1 hunks)
  • codegenerator/cli/templates/static/codegen/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/codegen/src/Config.res (1 hunks)
  • codegenerator/cli/templates/static/codegen/src/Index.bs.js (1 hunks)
  • codegenerator/cli/templates/static/codegen/src/Index.res (0 hunks)
  • codegenerator/cli/templates/static/codegen/src/db/DbFunctionsImplementation.js (18 hunks)
  • codegenerator/cli/templates/static/erc20_template/rescript/config.yaml (1 hunks)
  • codegenerator/cli/templates/static/erc20_template/rescript/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/erc20_template/shared/.gitignore (1 hunks)
  • codegenerator/cli/templates/static/greeter_template/rescript/README.md (1 hunks)
  • codegenerator/cli/templates/static/greeter_template/rescript/config.yaml (1 hunks)
  • codegenerator/cli/templates/static/greeter_template/rescript/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/greeter_template/shared/.gitignore (1 hunks)
  • codegenerator/cli/templates/static/greeteronfuel_template/rescript/config.yaml (1 hunks)
  • codegenerator/cli/templates/static/greeteronfuel_template/rescript/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/greeteronfuel_template/shared/.gitignore (1 hunks)
  • codegenerator/integration_tests/tests/test_indexers/dynamic_contracts/.gitignore (1 hunks)
  • codegenerator/integration_tests/tests/test_indexers/dynamic_contracts/package.json (1 hunks)
  • codegenerator/integration_tests/tests/test_indexers/test_exits/.gitignore (1 hunks)
  • codegenerator/integration_tests/tests/test_indexers/test_exits/package.json (1 hunks)
  • codegenerator/integration_tests/tests/test_indexers/wildcard-uni-factory/.gitignore (1 hunks)
  • codegenerator/integration_tests/tests/test_indexers/wildcard-uni-factory/package.json (1 hunks)
  • scenarios/erc20_multichain_factory/.gitignore (1 hunks)
  • scenarios/erc20_multichain_factory/.mocharc.json (1 hunks)
  • scenarios/erc20_multichain_factory/config.yaml (1 hunks)
  • scenarios/erc20_multichain_factory/package.json (1 hunks)
  • scenarios/erc20_multichain_factory/rescript.json (1 hunks)
  • scenarios/erc20_multichain_factory/test/DbHelpers.res (1 hunks)
  • scenarios/fuel_test/.gitignore (1 hunks)
  • scenarios/fuel_test/package.json (1 hunks)
  • scenarios/fuel_test/rescript.json (1 hunks)
  • scenarios/helpers/.gitignore (1 hunks)
  • scenarios/test_codegen/.gitignore (1 hunks)
  • scenarios/test_codegen/.mocharc.json (1 hunks)
  • scenarios/test_codegen/config.yaml (2 hunks)
  • scenarios/test_codegen/package.json (2 hunks)
  • scenarios/test_codegen/rescript.json (1 hunks)
  • scenarios/test_codegen/test/Integration_ts_helpers.gen.ts (1 hunks)
  • scenarios/test_codegen/test/helpers/DbHelpers.res (1 hunks)
  • scenarios/test_codegen/test/helpers/utils.ts (1 hunks)
  • scenarios/test_codegen/test/integration-raw-events-test.ts (2 hunks)
  • scenarios/test_codegen/test/manual/README.md (1 hunks)
  • scenarios/test_codegen/test/topic-hashing-test.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • codegenerator/cli/templates/static/codegen/src/Index.res
🧰 Additional context used
🧠 Learnings (2)
scenarios/test_codegen/test/helpers/DbHelpers.res (2)
Learnt from: JonoPrest
PR: enviodev/hyperindex#555
File: scenarios/test_codegen/test/lib_tests/EntityHistory_test.res:582-629
Timestamp: 2025-05-27T17:07:04.699Z
Learning: In ReScript test files using DbHelpers.resetPostgresClient(), this function is synchronous with signature `unit => unit` and should not be awaited. It performs a raw JavaScript reassignment of the postgres client and does not return a promise.
Learnt from: JonoPrest
PR: enviodev/hyperindex#555
File: scenarios/test_codegen/test/lib_tests/EntityHistory_test.res:582-629
Timestamp: 2025-05-27T17:07:04.699Z
Learning: In ReScript test files using DbHelpers.resetPostgresClient(), this function is synchronous with signature `unit => unit` and should not be awaited. It performs a raw JavaScript reassignment of the postgres client and does not return a promise.
scenarios/erc20_multichain_factory/test/DbHelpers.res (2)
Learnt from: JonoPrest
PR: enviodev/hyperindex#555
File: scenarios/test_codegen/test/lib_tests/EntityHistory_test.res:582-629
Timestamp: 2025-05-27T17:07:04.699Z
Learning: In ReScript test files using DbHelpers.resetPostgresClient(), this function is synchronous with signature `unit => unit` and should not be awaited. It performs a raw JavaScript reassignment of the postgres client and does not return a promise.
Learnt from: JonoPrest
PR: enviodev/hyperindex#555
File: scenarios/test_codegen/test/lib_tests/EntityHistory_test.res:582-629
Timestamp: 2025-05-27T17:07:04.699Z
Learning: In ReScript test files using DbHelpers.resetPostgresClient(), this function is synchronous with signature `unit => unit` and should not be awaited. It performs a raw JavaScript reassignment of the postgres client and does not return a promise.
🪛 Biome (1.9.4)
scenarios/test_codegen/.mocharc.json

[error] 5-5: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 5-5: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 5-5: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 5-5: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build_and_test
  • GitHub Check: build_and_test
🔇 Additional comments (66)
scenarios/fuel_test/rescript.json (1)

13-13: Update ReScript output suffix to .res.js
Aligns this scenario’s compiler configuration with the new file naming convention.

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

21-21: Switch ReScript suffix to .res.js
Reflects the updated ReScript output naming in the blank template’s configuration.

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

21-21: Switch Greeter template suffix to .res.js
Ensures the Greeter template uses the new ReScript output file extension.

scenarios/test_codegen/test/topic-hashing-test.ts (2)

1-1: Update TestEvents import to ReScript output file
Import path suffix updated from .bs.js to .res.js correctly aligns with the new ReScript conventions.


4-4: Update Rpc import to ReScript suffix
The GetLogs import path has been updated to .res.js, matching the ReScript migration.

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

21-21: Align compiled file suffix with ReScript
The "suffix" field has been updated from .bs.js to .res.js in the template, ensuring generated artifacts follow ReScript naming conventions.

codegenerator/cli/templates/dynamic/subgraph_migration_templates/javascript/src/EventHandlers.js.hbs (1)

9-9: Update handler import to .res.js
The require path for Handlers has been changed to .res.js, consistent with the overall migration.

scenarios/erc20_multichain_factory/.mocharc.json (1)

2-2: Update test spec pattern to ReScript outputs
The Mocha "spec" pattern now targets **/*.res.js files, reflecting the new output suffix.

scenarios/test_codegen/rescript.json (1)

14-14: Change output suffix to ReScript convention
The "suffix" property has been updated to .res.js, aligning the test scenario with the ReScript migration.

scenarios/test_codegen/test/integration-raw-events-test.ts (1)

5-6: Consistent path updates for ReScript output
Imports have been correctly updated to use .res.js extensions, aligning with the new naming convention.

scenarios/erc20_multichain_factory/rescript.json (1)

32-32: Update ReScript suffix to .res.js
The suffix field has been changed to .res.js, matching the migration from BuckleScript outputs. Ensure this aligns with your build and tooling configurations.

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

21-21: Align template output suffix with ReScript convention
The suffix is now .res.js, consistent with the rest of the project’s migration away from .bs.js.

scenarios/erc20_multichain_factory/package.json (1)

11-11: Switch start script to .res.js entry point
The start script now points to Index.res.js, reflecting the new build output.

codegenerator/integration_tests/tests/test_indexers/wildcard-uni-factory/package.json (1)

12-12: Update start script to .res.js: Approved

The start script now correctly targets the ReScript-generated Index.res.js entry point. Ensure your test harness generates this file before running the script.

scenarios/fuel_test/package.json (1)

16-16: Align start script with ReScript output: Approved

The start command now invokes generated/src/Index.res.js as expected. Confirm that your build step (res:build) precedes this invocation in CI or local workflows.

codegenerator/cli/templates/static/greeter_template/rescript/config.yaml (1)

10-10: Handler path updated correctly

The contract’s handler now points to EventHandlers.res.js, matching the ReScript output convention.

scenarios/test_codegen/test/helpers/utils.ts (1)

1-1: ReScript imports updated correctly to .res.js
The runUpMigrations and config imports now point to .res.js outputs as expected.

Also applies to: 3-3

codegenerator/integration_tests/tests/test_indexers/dynamic_contracts/.gitignore (1)

33-34: Ignore new ReScript output suffixes
Adding *.res.js and *.res.mjs ensures these generated files are excluded from source control in this test scenario.

scenarios/erc20_multichain_factory/config.yaml (1)

13-13: Correctly updated event handler suffix
The handler path is now .res.js, aligning with ReScript naming conventions. Ensure the corresponding EventHandlers.res.js file is present under src/.

codegenerator/cli/npm/envio/rescript.json (1)

10-10: Updated ReScript output suffix
The suffix field has been changed to .res.js, matching the new compiler output. Confirm that no leftover .bs.js artifacts remain in the build outputs.

scenarios/test_codegen/test/helpers/DbHelpers.res (1)

6-6: Renamed raw require path
The raw JS require now points to Db.res.js instead of Db.bs.js. Since resetPostgresClient is synchronous (unit => unit), no await is needed here.

codegenerator/cli/npm/envio/.gitignore (1)

137-138: Ignore new ReScript artifacts
Added *.res.js and *.res.mjs to ensure generated ReScript outputs are excluded from version control.

codegenerator/cli/templates/static/codegen/.gitignore (1)

29-30: Update ignore patterns for ReScript outputs
Switching to *.res.js/*.res.mjs aligns the template’s .gitignore with the updated file suffixes.

scenarios/test_codegen/.mocharc.json (1)

5-5: Update test spec pattern to new ReScript suffix

The Mocha spec now includes .res.js output files, aligning with the ReScript compilation convention.

🧰 Tools
🪛 Biome (1.9.4)

[error] 5-5: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 5-5: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 5-5: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 5-5: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)

codegenerator/cli/templates/static/greeteronfuel_template/rescript/config.yaml (1)

11-11: Use ReScript handler file in template

The handler path now references EventHandlers.res.js, matching the updated ReScript output.

codegenerator/cli/src/cli_args/init_config.rs (1)

343-343: Align event handler path for ReScript

The Language::ReScript branch now returns the correct .res.js handler path.

scenarios/erc20_multichain_factory/.gitignore (1)

32-33: Ignore ReScript compiled outputs

Add patterns for .res.js and .res.mjs to avoid committing generated files.

scenarios/test_codegen/test/manual/README.md (1)

11-21: Update .bs.js references to .res.js in manual tests.

The example commands now correctly reference LogTesting.res.js for all log strategies.

codegenerator/cli/npm/envio/src/bindings/BigDecimal.gen.ts (1)

6-6: Require correct ReScript output file.

Updated require('./BigDecimal.res.js') aligns with the new naming convention.

scenarios/test_codegen/test/Integration_ts_helpers.gen.ts (1)

6-6: Require correct ReScript output file.

Updated require('./Integration_ts_helpers.res.js') to match the ReScript output changes.

codegenerator/integration_tests/tests/test_indexers/wildcard-uni-factory/.gitignore (1)

32-33: Add new ReScript artifact patterns to ignore.

Added *.res.js and *.res.mjs to ignore the updated ReScript outputs.

codegenerator/cli/templates/static/greeteronfuel_template/shared/.gitignore (1)

32-33: Add new ReScript artifact patterns to ignore.

Added *.res.js and *.res.mjs to keep template projects in sync with ReScript output.

codegenerator/cli/templates/static/greeter_template/shared/.gitignore (1)

32-33: Update ignore patterns for ReScript outputs
Ignoring the new .res.js and .res.mjs artifacts aligns with the migration from BuckleScript to ReScript.

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

27-27: Switch generated file suffix to .res.js
The suffix field now matches the new ReScript output convention, ensuring generated files use the correct extension.

codegenerator/cli/templates/static/erc20_template/shared/.gitignore (1)

32-33: Update ignore patterns for ReScript outputs
Aligned the ERC-20 template’s .gitignore with the new .res.js and .res.mjs suffixes.

codegenerator/cli/templates/static/codegen/index.js (1)

5-6: Adjust imports to use .res.js extensions
Module require paths have been updated to reflect the ReScript build outputs instead of BuckleScript.

codegenerator/integration_tests/tests/test_indexers/test_exits/.gitignore (1)

33-34: Update ignore patterns for ReScript outputs
Ensure .res.js and .res.mjs files are correctly excluded in the integration test environment.

codegenerator/cli/src/config_parsing/graph_migration/mod.rs (2)

117-117: LGTM: ReScript file extension migration applied correctly.

The update from .bs.js to .res.js aligns with the broader migration from BuckleScript to ReScript naming conventions.


557-557: Test updated correctly to match implementation.

The test expectation properly reflects the new ReScript file extension, ensuring consistency between the implementation and tests.

codegenerator/cli/templates/static/codegen/src/Config.res (1)

103-103: Enhanced error formatting for better debugging.

The addition of Internal.prettifyExn improves error message formatting when Hasura table tracking fails, making debugging easier.

scenarios/test_codegen/package.json (1)

14-14: NPM scripts updated for ReScript file extension migration.

Both scripts correctly reference the new .res.js output files, ensuring compatibility with the ReScript naming convention migration.

Also applies to: 23-23

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

178-178:

✅ Verification successful

Verify working directory change for npm start command.

The working directory for the npm run start command has been changed from project_paths.project_root to project_paths.generated. Ensure this change is compatible with the package.json scripts and that the start command works correctly from the generated directory.


🏁 Script executed:

#!/bin/bash
# Description: Verify that package.json files in generated directories contain the correct start scripts

# Search for package.json files that might be in generated directories
fd -t f "package.json" | xargs grep -l "start.*Index\.res\.js"

# Check if there are any references to the old .bs.js files in package.json files
rg -A 2 -B 2 "\.bs\.js" --type json

Length of output: 523


I’d like to inspect the surrounding code and the package.json template to confirm the start command is wired up correctly in the generated directory.


🏁 Script executed:

#!/bin/bash
# Show commands.rs around the invocation
echo "=== commands.rs (lines 150–210) ==="
sed -n '150,210p' codegenerator/cli/src/commands.rs

# Show the package.json.hbs used in the generated folder
echo ""
echo "=== codegenerator/cli/templates/dynamic/codegen/package.json.hbs ==="
sed -n '1,200p' codegenerator/cli/templates/dynamic/codegen/package.json.hbs

Length of output: 4245


Confirmed: Working directory for npm run start is correct

The generated directory includes a package.json (from the provided Handlebars template) with a "start": "node src/Index.res.js" script, so running npm run start in project_paths.generated is intentional and valid.

codegenerator/cli/templates/static/greeter_template/rescript/README.md (2)

27-27: LGTM! Handler path correctly updated for ReScript migration.

The change from .bs.js to .res.js aligns with the broader migration from BuckleScript to ReScript output conventions, ensuring users get the correct configuration for new projects.


29-30: Good cleanup of trailing whitespace.

Removing trailing spaces improves formatting consistency.

codegenerator/cli/npm/envio/package.json.tmpl (2)

39-40: LGTM! Logging dependencies added.

The addition of pino and pino-pretty dependencies suggests enhanced logging capabilities for the envio package.


49-49: Good simplification of files array.

Removing the .bs.js exclusion pattern is appropriate since the migration moves to .res.js files. The simplified approach of just including "src" is cleaner and more maintainable.

codegenerator/cli/npm/envio/package.json (2)

28-29: LGTM! Consistent logging dependencies.

The addition of pino logging dependencies is consistent with the template file changes.


31-39: Appropriate explicit file inclusion list.

The detailed files array provides precise control over package contents for development builds, including necessary binaries, schemas, and source files.

scenarios/erc20_multichain_factory/test/DbHelpers.res (1)

6-6: Essential path update for ReScript migration.

The require path correctly changes from .bs.js to .res.js to match the new ReScript output conventions. This update is necessary for the resetPostgresClient function to continue working after the migration.

scenarios/test_codegen/config.yaml (1)

12-12: LGTM: Handler paths correctly updated for ReScript migration.

The configuration file has been properly updated to reference .res.js files instead of .bs.js files, which aligns with the migration from BuckleScript to ReScript naming conventions.

Also applies to: 16-16, 37-37

codegenerator/cli/src/hbs_templating/codegen_templates.rs (3)

1231-1231: LGTM: TypeScript detection field added correctly.

The new has_typescript boolean field is properly added to the ProjectTemplate struct to support conditional logic in templates.


1335-1337: LGTM: TypeScript detection logic is sound.

The implementation correctly determines if TypeScript is used by checking if any contract handler path ends with ".ts". This is a simple and effective approach for template conditionals.


1341-1341: LGTM: Field properly assigned in constructor.

The has_typescript field is correctly assigned in the ProjectTemplate constructor, ensuring the detection result is available to templates.

codegenerator/cli/npm/envio/index.js (1)

5-5: LGTM: Import paths correctly updated for ReScript migration.

The module import paths have been properly updated from .bs.js to .res.js extensions, maintaining consistency with the broader migration from BuckleScript to ReScript naming conventions.

Also applies to: 33-33

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

12-15: LGTM: Script paths correctly updated for ReScript migration.

All database and benchmark scripts have been properly updated to reference .res.js files instead of .bs.js files, maintaining consistency with the ReScript migration.


16-16: LGTM: Smart conditional TypeScript support implemented.

The start script correctly uses the has_typescript template variable to conditionally prepend ts- to the node command, enabling seamless TypeScript execution when needed. This integrates well with the TypeScript detection logic in the Rust code.


60-60: LGTM: ts-node dependency added to support TypeScript execution.

The addition of ts-node dependency enables the conditional TypeScript support in the start script, completing the TypeScript integration feature.

codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs (1)

44-44:

❓ Verification inconclusive

Verify the Node.js version requirement increase.

The Node.js version requirement was increased from >=18.0.0 to >=20.6.0. Ensure this aligns with the actual requirements of the envio start command and document this breaking change for users.


🏁 Script executed:

#!/bin/bash
# Check what Node.js features are being used that require 20.6.0+
rg -A 5 -B 5 "20\.6\.0|node.*20" 

Length of output: 32441


🏁 Script executed:

#!/bin/bash
set -eux
# Search for Node-specific APIs that may require newer Node.js versions in the CLI implementation
rg -n "global\.fetch" -A2 -B2 codegenerator/cli || true
rg -n "AbortController" -A2 -B2 codegenerator/cli || true
rg -n "from 'node:" -A2 -B2 codegenerator/cli || true
rg -n "diagnostics_channel" -A2 -B2 codegenerator/cli || true
rg -n "timers/promises" -A2 -B2 codegenerator/cli || true
rg -n "AbortSignal.timeout" -A2 -B2 codegenerator/cli || true

Length of output: 361


Review Node.js engine bump

I didn’t find any Node 20.6+-specific APIs in the CLI code that would strictly require raising the minimum from ≥18.0.0 to ≥20.6.0. If this change is intentional (for policy, alignment with downstream engines, etc.), please:

  • Document the breaking change in your release notes or migration guide.
  • Confirm that users of envio start understand they must upgrade Node.js.

• Location: codegenerator/cli/templates/dynamic/init_templates/shared/package.json.hbs
Line 44: "node": ">=20.6.0" (previously "node": ">=18.0.0")

codegenerator/cli/templates/static/codegen/src/db/DbFunctionsImplementation.js (2)

1-3: Import path migration correctly implemented.

The import paths have been correctly updated from .bs.js to .res.js as part of the ReScript migration. This aligns with the broader codebase changes.


24-24: Formatting improvements enhance code consistency.

The removal of trailing commas in template literals and function parameters improves code consistency and follows JavaScript best practices.

Also applies to: 60-60, 97-97, 129-129, 155-156, 159-159, 162-162, 171-171, 190-190, 204-204, 216-216, 229-229, 246-246, 278-278, 303-303, 321-321, 351-351, 384-384, 397-397, 399-399

codegenerator/cli/templates/static/codegen/src/Index.bs.js (6)

1-1: Clarify the .bs.js filename convention for this migration script.

This file is named Index.bs.js but the PR is migrating away from .bs.js to .res.js naming. Is this intentional since it's a migration tool, or should it follow the new naming convention?


17-24: Directory traversal logic is correct and secure.

The upward directory search correctly uses path.dirname() and stops at the filesystem root. This prevents infinite loops and handles edge cases properly.


72-75: JSON formatting preserves structure correctly.

The JSON.stringify with proper indentation and trailing newline maintains package.json formatting standards.


92-96: Process spawning is secure with proper stdio inheritance.

The spawn call uses stdio: "inherit" which correctly forwards input/output streams, and cwd: process.cwd() maintains the current working directory context.


97-106: Error handling for missing envio command is comprehensive.

The error handling properly detects the ENOENT code for missing commands and provides helpful user feedback.


108-113: Exit code propagation maintains CLI contract.

The script correctly propagates non-zero exit codes from the spawned envio start process, maintaining proper CLI behavior.

startProcessing,
} from "./Integration_ts_helpers.gen";
// import { setLogLevel } from "generated/src/Logging.bs.js";
// import { setLogLevel } from "generated/src/Logging.res.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix commented import path
The commented import for setLogLevel uses generated/src/... without a leading .., which will fail when uncommented. Update it to:
// import { setLogLevel } from "../generated/src/Logging.res.js";

🤖 Prompt for AI Agents
In scenarios/test_codegen/test/integration-raw-events-test.ts at line 23, the
commented import statement for setLogLevel uses an incorrect relative path
without the leading "..". To fix this, update the import path to include the
leading ".." so it reads: import { setLogLevel } from
"../generated/src/Logging.res.js"; ensuring the path correctly points to the
generated directory.

"codegen": "cargo run --manifest-path ../../codegenerator/cli/Cargo.toml -- codegen",
"dev": "pnpm build && envio dev",
"start": "pnpm build && node generated/src/Index.bs.js"
"start": "pnpm build && node generated/src/Index.res.js"
Copy link
Contributor

@coderabbitai coderabbitai bot Jun 9, 2025

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify no stale .bs.js references remain
Ensure other package.json scripts and documentation have been updated. Run:


🏁 Script executed:

#!/bin/bash
# Search for any remaining .bs.js entries
rg "generated/src/.*\.bs\.js" -A1

Length of output: 481


Update stale .bs.js references in code generator templates

The search revealed that your change in scenarios/erc20_multichain_factory/package.json updated the start script to use .res.js, but there are still lingering .bs.js references in your code generator templates:

• codegenerator/cli/templates/static/codegen/src/Index.bs.js
– Contains comments and replace calls targeting generated/src/Index.bs.js

Please update these template files to reference Index.res.js (or remove the old .bs.js logic) so new projects won’t include stale .bs.js artifacts. You may also want to re-run:

rg "\.bs\.js"

to confirm no other occurrences remain.

🤖 Prompt for AI Agents
In scenarios/erc20_multichain_factory/package.json at line 11, you updated the
start script to use generated/src/Index.res.js instead of .bs.js, but there are
still stale .bs.js references in the
codegenerator/cli/templates/static/codegen/src/Index.bs.js file. To fix this,
update the template file to replace all occurrences of Index.bs.js with
Index.res.js or remove any logic related to .bs.js files. After making these
changes, run a search for ".bs.js" again to ensure no other stale references
remain.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this valid @DZakh

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

/* tslint:disable */

const EthersJS = require('./Ethers.bs.js');
const EthersJS = require('./Ethers.res.js');
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid manual edits in generated files
This file is auto-generated by genType. Instead of patching the require path here, update your genType template/config to emit .res.js imports so the change persists across regenerations.

🤖 Prompt for AI Agents
In codegenerator/cli/npm/envio/src/bindings/Ethers.gen.ts at line 6, the require
path is manually edited to './Ethers.res.js' in a generated file. Instead of
modifying this file directly, update the genType template or configuration to
output imports with the '.res.js' extension so that the change is preserved when
the file is regenerated.

pub fn get_event_handler_directory(&self) -> String {
match self {
Language::ReScript => "./src/EventHandlers.bs.js".to_string(),
Language::ReScript => "./src/EventHandlers.res.js".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify no remaining BuckleScript suffix references

Ensure all instances of the old .bs.js suffix have been removed across the codebase:


🏁 Script executed:

#!/bin/bash
rg '\.bs\.js' -n

Length of output: 275


🏁 Script executed:

#!/bin/bash
rg '\.bs\.js' -n -A2 -B2 codegenerator/cli/templates/static/codegen/src/Index.bs.js

Length of output: 475


Fix remaining .bs.js suffix references in static codegen templates

The search for .bs.js found two hard-coded references in your codegen template that need updating:

• codegenerator/cli/templates/static/codegen/src/Index.bs.js
– Line 49: /ts-node\s+generated\/src\/Index\.bs\.js/g
– Line 55: /node\s+generated\/src\/Index\.bs\.js/g

Please update both patterns to use the new .res.js suffix, for example:

- newScript = newScript.replace(
-   /ts-node\s+generated\/src\/Index\.bs\.js/g,
+ newScript = newScript.replace(
+   /ts-node\s+generated\/src\/Index\.res\.js/g,

- newScript = newScript.replace(
-   /node\s+generated\/src\/Index\.bs\.js/g,
+ newScript = newScript.replace(
+   /node\s+generated\/src\/Index\.res\.js/g,

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In codegenerator/cli/src/cli_args/init_config.rs at line 343, update the
hard-coded file suffix from ".bs.js" to ".res.js" to remove any remaining
BuckleScript suffix references. Additionally, in the
codegenerator/cli/templates/static/codegen/src/Index.bs.js file, locate lines 49
and 55 where the regex patterns reference "Index.bs.js" and change these to
"Index.res.js" to ensure consistency with the new suffix convention.

Comment on lines +50 to +59
newScript = newScript.replace(
/ts-node\s+generated\/src\/Index\.bs\.js/g,
"envio start"
);

// Replace node generated/src/Index.bs.js with envio start
newScript = newScript.replace(
/node\s+generated\/src\/Index\.bs\.js/g,
"envio start"
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Regex patterns should be more precise to avoid unintended replacements.

The current regex patterns could potentially match unintended strings. Consider making them more specific to avoid false positives.

-      newScript = newScript.replace(
-        /ts-node\s+generated\/src\/Index\.bs\.js/g,
-        "envio start"
-      );
+      newScript = newScript.replace(
+        /\bts-node\s+generated\/src\/Index\.bs\.js\b/g,
+        "envio start"
+      );

-      newScript = newScript.replace(
-        /node\s+generated\/src\/Index\.bs\.js/g,
-        "envio start"
-      );
+      newScript = newScript.replace(
+        /\bnode\s+generated\/src\/Index\.bs\.js\b/g,
+        "envio start"
+      );
📝 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.

Suggested change
newScript = newScript.replace(
/ts-node\s+generated\/src\/Index\.bs\.js/g,
"envio start"
);
// Replace node generated/src/Index.bs.js with envio start
newScript = newScript.replace(
/node\s+generated\/src\/Index\.bs\.js/g,
"envio start"
);
newScript = newScript.replace(
/\bts-node\s+generated\/src\/Index\.bs\.js\b/g,
"envio start"
);
// Replace node generated/src/Index.bs.js with envio start
newScript = newScript.replace(
/\bnode\s+generated\/src\/Index\.bs\.js\b/g,
"envio start"
);
🤖 Prompt for AI Agents
In codegenerator/cli/templates/static/codegen/src/Index.bs.js between lines 50
and 59, the regex patterns used to replace command strings are too broad and may
match unintended text. Refine the regex patterns by anchoring them to match the
exact command format, such as ensuring they match the entire command string or
include start/end boundaries, to prevent accidental replacements of similar but
unrelated strings.

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 (2)
codegenerator/integration_tests/tests/runSingle.sh (1)

53-53: Optional: Capture the indexer PID for precise cleanup
Currently, cleanup relies on port-based detection; capturing the background process PID—for example:

TUI_OFF="true" pnpm dev & PID=$!
echo "Indexer PID: $PID"

—would allow you to target the specific process and avoid potential collisions.

codegenerator/integration_tests/tests/testIndexerExits.sh (1)

47-47: Nit: Quote environment variable assignment
For consistency and stricter POSIX compliance, consider quoting the value:

-export TUI_OFF=true
+export TUI_OFF="true"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 39a818d and 5e70ca7.

📒 Files selected for processing (6)
  • codegenerator/cli/templates/static/blank_template/rescript/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/erc20_template/rescript/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/greeter_template/rescript/rescript.json (1 hunks)
  • codegenerator/cli/templates/static/greeteronfuel_template/rescript/rescript.json (1 hunks)
  • codegenerator/integration_tests/tests/runSingle.sh (1 hunks)
  • codegenerator/integration_tests/tests/testIndexerExits.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • codegenerator/cli/templates/static/greeteronfuel_template/rescript/rescript.json
  • codegenerator/cli/templates/static/blank_template/rescript/rescript.json
  • codegenerator/cli/templates/static/greeter_template/rescript/rescript.json
  • codegenerator/cli/templates/static/erc20_template/rescript/rescript.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_and_test
🔇 Additional comments (2)
codegenerator/integration_tests/tests/runSingle.sh (1)

53-53: Direct invocation of pnpm dev is aligned with PR objectives
By removing the envio wrapper and running pnpm dev with TUI_OFF="true", the test now accurately reflects the intended startup command and avoids the previous dependency-hoisting issue.

codegenerator/integration_tests/tests/testIndexerExits.sh (1)

48-48: Replace envio wrapper with direct pnpm start as intended
Executing pnpm start under TUI_OFF matches the new integration-test convention and ensures the indexer runs correctly without the envio CLI intermediary.

"suffix": ".bs.js",
"bs-dependencies": ["generated", "envio"]
"suffix": ".res.js",
"bs-dependencies": ["generated", "envio", "rescript-schema"]
Copy link
Member Author

Choose a reason for hiding this comment

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

Need this for correct genType import path. Interesting that it's not required to add it to the indexer dependency.


echo "Starting indexer"
TUI_OFF="true" $envio_cmd dev &
TUI_OFF="true" pnpm dev &
Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise it won't run rescript compiler for ReScript lang.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, just wondering if this removes coverage of the cli. I'm not too worried though its been quite stable

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it should be fine. We don't change the command anyways. I'd even say that it increases the coverage.

@DZakh DZakh changed the title Fix ReScript indexers without shamefully hoisting deps Fix ReScript indexers without shamefully hoisting deps + removes deps on user's start script Jun 9, 2025
@DZakh DZakh requested a review from JonoPrest June 9, 2025 15:52
# ReScript artifacts
*.bs.js
*.res.js
*.res.mjs
Copy link
Collaborator

Choose a reason for hiding this comment

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

When do we use mjs?

Copy link
Member Author

Choose a reason for hiding this comment

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

We might need to migrate to it in v3 when we start using ESM. I decided to add it beforehand.

Comment on lines 116 to 120
// Main execution
console.log("📋 Migration steps:");
console.log(" 1. Update package.json scripts");
console.log(" 2. Run envio start");
console.log("");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure about automatically running this, surely it should check and then prompt a user?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it should be fine.

"log_index",
"block_timestamp",
"is_pre_registering_dynamic_contracts",
"is_pre_registering_dynamic_contracts"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm sure we want to eventually refactor this file entirely but we should probably have a prettier config file so we don't see this stuff changing between commits

Copy link
Member Author

Choose a reason for hiding this comment

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

True 😅

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.

Hey @DZakh I dont' want to block this PR but I'm skeptical of the startup script and just want to check if you've done a grep for all files or references to files with .bs.js?

@@ -0,0 +1,135 @@
#!/usr/bin/env node
Copy link
Collaborator

Choose a reason for hiding this comment

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

@DZakh maybe you can also include a comment at the top of this file to explain why it exists.

@DZakh DZakh enabled auto-merge (squash) June 10, 2025 11:35
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: 1

♻️ Duplicate comments (2)
codegenerator/cli/templates/static/codegen/src/Index.bs.js (2)

65-74: Regex patterns are still too broad and could cause unintended replacements.

This is the same issue flagged in previous reviews. The current patterns could match unintended strings within larger commands or file paths.

Apply the previously suggested fix to make the regex patterns more precise:

-      newScript = newScript.replace(
-        /ts-node\s+generated\/src\/Index\.bs\.js/g,
-        "envio start"
-      );
+      newScript = newScript.replace(
+        /\bts-node\s+generated\/src\/Index\.bs\.js\b/g,
+        "envio start"
+      );

-      newScript = newScript.replace(
-        /node\s+generated\/src\/Index\.bs\.js/g,
-        "envio start"
-      );
+      newScript = newScript.replace(
+        /\bnode\s+generated\/src\/Index\.bs\.js\b/g,
+        "envio start"
+      );

1-1: ⚠️ Potential issue

Filename contradicts the migration purpose.

This migration script is designed to move away from .bs.js files to .res.js files, yet the script itself uses the .bs.js extension. This creates confusion and contradicts the migration objective.

Consider renaming this file to use a more appropriate extension:

-Index.bs.js
+Index.js

Or if you need to maintain the ReScript connection for some reason:

-Index.bs.js
+Index.res.js
🧹 Nitpick comments (2)
codegenerator/cli/templates/static/codegen/src/Index.bs.js (2)

112-118: Timeout behavior might confuse users.

The 30-second timeout that automatically skips migration without user awareness could be confusing, especially since users might not notice the timeout message.

Consider providing a clearer indication when the timeout is approaching:

+    // Warn user about timeout after 20 seconds
+    const warningTimeout = setTimeout(() => {
+      console.log("\n⏰ Migration prompt will timeout in 10 seconds...");
+    }, 20000);
+
     const timeout = setTimeout(() => {
+      clearTimeout(warningTimeout);
       rl.close();
       console.log(
         "\n⏱️  No response received in 30 seconds, skipping package.json migration."
       );
       resolve(false);
     }, 30000);

     rl.question(
       "🤔 Would you like to automatically update your package.json scripts? (y/N): ",
       (answer) => {
+        clearTimeout(warningTimeout);
         clearTimeout(timeout);

144-153: Error handling could be more informative.

While the ENOENT error is handled well, other potential errors could benefit from more specific guidance.

Consider adding more specific error handling:

   envioProcess.on("error", (error) => {
     if (error.code === "ENOENT") {
       console.error(
         '❌ Error: "envio" command not found. Please make sure Envio CLI is installed.'
       );
+      console.error("   Try running: npm install -g @envio-dev/envio");
+    } else if (error.code === "EACCES") {
+      console.error("❌ Error: Permission denied. Try running with appropriate permissions.");
     } else {
       console.error("❌ Error running envio start:", error.message);
     }
     process.exit(1);
   });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3e8ba42 and ae7a509.

📒 Files selected for processing (1)
  • codegenerator/cli/templates/static/codegen/src/Index.bs.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_and_test
🔇 Additional comments (1)
codegenerator/cli/templates/static/codegen/src/Index.bs.js (1)

3-17: Excellent documentation explaining the migration purpose.

The comprehensive comment block clearly explains the context, breaking changes, and migration steps. This addresses previous feedback about including explanatory comments.

Comment on lines +125 to +129
const shouldMigrate =
answer.toLowerCase() === "y" ||
answer.toLowerCase() === "yes" ||
answer.trim() === "";
resolve(shouldMigrate);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Empty input defaulting to "yes" may be confusing to users.

The current logic treats an empty string (just pressing Enter) as agreeing to the migration. This might be unexpected behavior for users who expect explicit confirmation.

Consider making the default behavior more explicit:

-        const shouldMigrate =
-          answer.toLowerCase() === "y" ||
-          answer.toLowerCase() === "yes" ||
-          answer.trim() === "";
+        const shouldMigrate =
+          answer.toLowerCase() === "y" ||
+          answer.toLowerCase() === "yes";

And update the prompt to indicate the default:

-      "🤔 Would you like to automatically update your package.json scripts? (y/N): ",
+      "🤔 Would you like to automatically update your package.json scripts? (y/n): ",
📝 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.

Suggested change
const shouldMigrate =
answer.toLowerCase() === "y" ||
answer.toLowerCase() === "yes" ||
answer.trim() === "";
resolve(shouldMigrate);
rl.question(
// Updated prompt to show no “yes” default.
"🤔 Would you like to automatically update your package.json scripts? (y/n): ",
(answer: string) => {
// Only “y” or “yes” now count as confirmation; empty no longer defaults to yes.
const shouldMigrate =
answer.toLowerCase() === "y" ||
answer.toLowerCase() === "yes";
resolve(shouldMigrate);
}
);
🤖 Prompt for AI Agents
In codegenerator/cli/templates/static/codegen/src/Index.bs.js around lines 125
to 129, the code treats empty input as a "yes" response, which can confuse
users. Modify the logic to not default empty input to "yes" by removing the
condition that treats an empty string as confirmation. Additionally, update the
user prompt to clearly indicate what the default choice is or require explicit
confirmation to proceed.

@DZakh DZakh merged commit b8db882 into main Jun 10, 2025
2 checks passed
@DZakh DZakh deleted the dz/fix-rescript-without-shamefully-hoist branch June 10, 2025 11:44
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