Skip to content

Conversation

@jaipaljadeja
Copy link
Member

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented May 26, 2025

📝 Walkthrough

Walkthrough

This update introduces debug logging to the indexer, controlled by a debug flag, and extends support for .mjs file extensions across configuration, indexer scanning, and file generation. The CLI and build tools are updated to recognize and handle .mjs files, ensuring consistent behavior for JavaScript module files throughout the codebase.

Changes

File(s) / Area Summary
change/@apibara-indexer-...json, change/apibara-...json Metadata updates for prerelease patch versions reflecting debug logging and CLI .mjs fix.
packages/cli/src/core/build/dev.ts Expanded ignore pattern to include apibara.config.mjs in watcher logic.
packages/cli/src/core/scan.ts Added .indexer.mjs to recognized indexer file extensions.
packages/cli/src/create/add.ts, packages/cli/src/create/templates.ts Switched to dynamic file extension handling using an extension property for file paths and messages.
packages/cli/src/create/types.ts Introduced FileExtension type and added extension to IndexerOptions.
packages/cli/src/create/utils.ts Updated config detection and language handling to support .mjs extension.
packages/cli/src/rolldown/plugins/instrumentation.ts Enhanced instrumentation logic to resolve .mjs files.
packages/indexer/src/indexer.ts Set debug flag in context if debug mode is enabled.
packages/indexer/src/plugins/logger.ts Logger now sets log level to debug if context debug flag is true.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant ConfigUtils
    participant Indexer
    participant Logger

    User->>CLI: Run command with .mjs config/indexer
    CLI->>ConfigUtils: Detect config/indexer file extension
    ConfigUtils-->>CLI: Return detected extension (.js, .ts, or .mjs)
    CLI->>Indexer: Start indexer with options (including debug flag)
    Indexer->>Logger: Initialize logger plugin
    Indexer->>Indexer: Set context.debug if debug enabled
    Logger->>Logger: Set log level to debug if context.debug is true
    Logger-->>Indexer: Logger ready with correct level
    Indexer-->>User: Indexer runs, outputs debug logs if enabled
Loading

Possibly related PRs

Suggested reviewers

  • fracek

Poem

In the warren, code hops anew,
With .mjs files now in view.
Debug logs light up the night,
Helping bunnies set things right.
Extensions handled with a twitch—
Our indexer’s never been so rich!
🐇✨

✨ 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.

@jaipaljadeja jaipaljadeja requested a review from fracek May 26, 2025 11:03
Copy link

@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

🔭 Outside diff range comments (2)
packages/cli/src/create/utils.ts (2)

40-43: ⚠️ Potential issue

Update error message to include "mjs" option

The error message should reflect that "mjs" is now a valid language option, matching the validation logic above.

-      `Invalid language ${cyan("(--language | -l)")}: ${red(language)}. Options: ${blue("typescript, ts")} or ${yellow("javascript, js")} | default: ${cyan("typescript")}`,
+      `Invalid language ${cyan("(--language | -l)")}: ${red(language)}. Options: ${blue("typescript, ts")} or ${yellow("javascript, js, mjs")} | default: ${cyan("typescript")}`,

57-59: ⚠️ Potential issue

Error message needs to include "mjs" option

Similar to the previous comment, this error message should mention "mjs" as a valid option.

-    `Invalid language ${cyan("(--language | -l)")}: ${red(alias)}. Options: ${blue("typescript, ts")} or ${yellow("javascript, js")}`,
+    `Invalid language ${cyan("(--language | -l)")}: ${red(alias)}. Options: ${blue("typescript, ts")} or ${yellow("javascript, js, mjs")}`,
🧹 Nitpick comments (1)
packages/cli/src/rolldown/plugins/instrumentation.ts (1)

10-10: Extension detection logic is correct, consider extracting for readability.

The nested ternary correctly handles .ts, .mjs, and .js extensions. However, for improved readability and maintainability, consider extracting this logic.

Consider extracting the extension detection logic:

+function getFileExtension(configFile?: string): string {
+  if (configFile?.endsWith(".ts")) return "ts";
+  if (configFile?.endsWith(".mjs")) return "mjs";
+  return "js";
+}
+
 export function instrumentation(apibara: Apibara) {
   const instrumentationPath = join(
     apibara.options._c12.cwd!,
-    `instrumentation.${apibara.options._c12.configFile?.endsWith(".ts") ? "ts" : apibara.options._c12.configFile?.endsWith(".mjs") ? "mjs" : "js"}`,
+    `instrumentation.${getFileExtension(apibara.options._c12.configFile)}`,
   );

This makes the code more readable and easier to extend if additional extensions need to be supported in the future.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2f91f23 and 6b0baca.

📒 Files selected for processing (11)
  • change/@apibara-indexer-d223a0d2-d422-40bd-a7b0-939c3b04ead1.json (1 hunks)
  • change/apibara-b87e2be4-ca28-4711-b029-a215cfd726c8.json (1 hunks)
  • packages/cli/src/core/build/dev.ts (1 hunks)
  • packages/cli/src/core/scan.ts (1 hunks)
  • packages/cli/src/create/add.ts (3 hunks)
  • packages/cli/src/create/templates.ts (5 hunks)
  • packages/cli/src/create/types.ts (2 hunks)
  • packages/cli/src/create/utils.ts (4 hunks)
  • packages/cli/src/rolldown/plugins/instrumentation.ts (1 hunks)
  • packages/indexer/src/indexer.ts (1 hunks)
  • packages/indexer/src/plugins/logger.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (15)
change/@apibara-indexer-d223a0d2-d422-40bd-a7b0-939c3b04ead1.json (1)

1-7: LGTM! Changelog entry accurately reflects debug logging enhancement.

The changelog entry correctly documents the addition of debug logging functionality when debug mode is enabled, which aligns with the PR objectives.

packages/indexer/src/indexer.ts (1)

229-231: LGTM! Debug flag implementation is correct.

The conditional check properly sets the debug flag on the context when the indexer's debug option is enabled. The placement after useIndexerContext() and before middleware registration is appropriate for enabling debug behavior throughout the indexer lifecycle.

packages/cli/src/create/types.ts (2)

19-19: LGTM! FileExtension type properly includes .mjs support.

The new FileExtension type correctly includes all three supported extensions ("js", "ts", "mjs"), which aligns with the PR objective to add .mjs file support.


31-31:

✅ Verification successful

Verify backward compatibility of the extension property.

The addition of the extension property to IndexerOptions looks good. However, ensure this property is handled appropriately in existing code that may not provide it.


🏁 Script executed:

#!/bin/bash
# Description: Check how IndexerOptions is used throughout the codebase to ensure backward compatibility.
# Expected: Find usages and verify they handle the new extension property.

rg -A 3 -B 3 "IndexerOptions" --type ts

Length of output: 4433


🏁 Script executed:

#!/bin/bash
# Display contents of types.ts to verify IndexerOptions definition
sed -n '1,200p' packages/cli/src/create/types.ts

Length of output: 882


🏁 Script executed:

#!/bin/bash
# Display the create/add.ts file to inspect how IndexerOptions and extension are handled
sed -n '1,200p' packages/cli/src/create/add.ts

Length of output: 5378


🏁 Script executed:

#!/bin/bash
# Display lines 200-300 around the IndexerOptions assignment in create/add.ts
sed -n '200,300p' packages/cli/src/create/add.ts

Length of output: 1061


🏁 Script executed:

#!/bin/bash
# Search for updateApibaraConfigFile definition to inspect parameter usage
rg -n "export async function updateApibaraConfigFile" -n packages/cli/src/create/templates.ts

Length of output: 147


🏁 Script executed:

#!/bin/bash
# Locate definition of getApibaraConfigLanguage
rg -n "getApibaraConfigLanguage" -n packages/cli/src/create/utils.ts

Length of output: 129


🏁 Script executed:

#!/bin/bash
# Inspect getApibaraConfigLanguage in utils.ts
sed -n '190,260p' packages/cli/src/create/utils.ts

echo
# Inspect updateApibaraConfigFile in templates.ts
sed -n '200,260p' packages/cli/src/create/templates.ts

Length of output: 3543


Backward compatibility of extension property confirmed

The new extension field is always derived from getApibaraConfigLanguage(cwd) in add.ts and correctly propagated to every code path that consumes IndexerOptions. Specifically:

  • packages/cli/src/create/add.ts:
    const { language, extension } = getApibaraConfigLanguage(cwd);
    • Passed into updateApibaraConfigFile, updatePackageJson, createIndexerFile, and createStorageRelatedFiles

  • packages/cli/src/create/utils.ts:
    getApibaraConfigLanguage reliably returns both language and extension based on existing config file

  • packages/cli/src/create/templates.ts:
    updateApibaraConfigFile, updatePackageJson, createIndexerFile, and createStorageRelatedFiles all accept and use the extension value

No code path omits handling of extension.

change/apibara-b87e2be4-ca28-4711-b029-a215cfd726c8.json (1)

1-7: LGTM! Changelog entry accurately documents .mjs extension fix.

The changelog entry correctly describes the CLI fix for .mjs extension support, which directly addresses one of the key PR objectives.

packages/indexer/src/plugins/logger.ts (1)

24-27: LGTM! Debug logging implementation is correct.

The conditional check properly enables debug level logging when the debug flag is set in the context. This implementation correctly applies the debug level after logger creation, regardless of whether a custom reporter is provided.

packages/cli/src/core/build/dev.ts (1)

106-106: LGTM! Correctly extends ignore pattern for .mjs configuration files.

The glob pattern properly includes .mjs extension alongside .ts and .js, ensuring that apibara.config.mjs files are ignored by the watcher as intended.

packages/cli/src/create/utils.ts (2)

185-195: LGTM! Correctly extends config detection for .mjs files

The function now properly checks for all three config file variants.


197-216: Well-structured refactor to support file extensions

The function now returns both language and extension, enabling proper handling of .mjs files throughout the codebase. The check order (mjs → js → ts) ensures newer module formats take precedence.

packages/cli/src/create/add.ts (2)

80-80: Good refactor to support dynamic file extensions

Properly destructures both language and extension from the updated getApibaraConfigLanguage function.


98-104: Consistent use of dynamic extension throughout

All file paths and success messages now correctly use the extension variable, ensuring proper support for .js, .ts, and .mjs files.

Also applies to: 208-209, 213-214, 221-222

packages/cli/src/core/scan.ts (1)

5-5: Correctly extends indexer scanning for .mjs files

The scanner now recognizes .indexer.mjs files alongside .indexer.ts and .indexer.js.

packages/cli/src/create/templates.ts (3)

146-146: Good change for extension flexibility.

The modification correctly uses the dynamic extension from options, enabling support for .mjs files as intended.


217-219: Properly updated to support dynamic extensions.

The function signature and path construction correctly incorporate the extension parameter, maintaining consistency with the extension-agnostic approach.


268-274: Comprehensive extension handling for Drizzle storage files.

All file references have been properly updated to use the dynamic fileExtension. The implementation correctly handles schema files, drizzle config files, and user-facing messages.

Also applies to: 286-286, 300-300, 354-354, 362-362, 371-371

@fracek
Copy link
Contributor

fracek commented May 28, 2025

Looks good, thank you!

@fracek fracek merged commit 1e92ba8 into apibara:main May 28, 2025
2 checks passed
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