Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT:proritizing trigger.config istead of package.json #1778

Conversation

Rudra-Sankha-Sinhamahapatra
Copy link

@Rudra-Sankha-Sinhamahapatra Rudra-Sankha-Sinhamahapatra commented Mar 9, 2025

PR: Prioritize trigger.config.ts location for base path determination

Closes #1467

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Testing

  1. Ran package tests using:
pnpm run test --filter @trigger.dev/core
  1. Tested the realtime runs functionality to ensure no errors after extended periods

Changelog

[Short description of what has changed]
This PR fixes an issue with path resolution in monorepo setups that don't have individual package.json files in each workspace. The fix prioritizes finding the trigger.config.ts file to determine the "base" path instead of relying solely on package.json location.

Changes made:

Added a findTriggerConfigDir function to locate the directory containing trigger.config.ts
Updated the path resolution logic in resolveConfig to prioritize trigger.config.ts location over package.json

// Prioritize trigger.config.ts location over package.json
const workingDir = result.configFile
? dirname(result.configFile)
: configDir
? configDir
: packageJsonPath
? dirname(packageJsonPath)
: cwd;

Screenshots

N.A

💯

Summary by CodeRabbit

  • Chores
    • Upgraded the package management integrity check by switching to a stronger checksum algorithm.
  • New Features
    • Enhanced configuration resolution to automatically identify the correct configuration directory when no explicit configuration file is provided.

Copy link

changeset-bot bot commented Mar 9, 2025

⚠️ No Changeset found

Latest commit: 9a5419a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Mar 9, 2025

Walkthrough

This PR updates the package manager configuration in the monorepo-react-email project's package.json by replacing a SHA-256 checksum with a SHA-512 checksum. Additionally, it enhances the configuration resolution logic in packages/cli-v3/src/config.ts by introducing the new function findTriggerConfigDir and revising resolveConfig to prioritize the configuration directory when a config file is not provided.

Changes

File(s) Change Summary
packages/cli-v3/.../monorepo-react-email/package.json Updated the packageManager field: replaced the SHA-256 checksum with a SHA-512 checksum.
packages/cli-v3/src/config.ts Added the findTriggerConfigDir function and modified resolveConfig to use the configuration directory when undefined.

Sequence Diagram(s)

sequenceDiagram
    participant R as resolveConfig
    participant F as findTriggerConfigDir
    participant C as Config Loader (c12.loadConfig)
    
    R->>R: Check if result.configFile exists
    alt configFile exists
        R->>R: Use provided configFile
    else configFile missing
        R->>F: Call findTriggerConfigDir(cwd)
        F->>C: Attempt to load configuration
        C-->>F: Return configuration or error
        F-->>R: Return configuration directory (if found)
    end
Loading

Possibly related PRs

  • triggerdotdev/trigger.dev#1665: Modified configuration resolution in config.ts, directly impacting the directory resolution logic similar to this PR.

Suggested reviewers

  • ericallam
  • nicktrn

Poem

In my code burrow, I hop with delight,
New checksums and configs shine so bright.
With updated paths on my nightly quest,
I savor each change, feeling truly blessed.
Here's to smooth code in every byte! 🐰✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6cf86d5 and 79b1020.

📒 Files selected for processing (2)
  • packages/cli-v3/e2e/fixtures/monorepo-react-email/package.json (1 hunks)
  • packages/cli-v3/src/config.ts (2 hunks)
🔇 Additional comments (4)
packages/cli-v3/e2e/fixtures/monorepo-react-email/package.json (1)

4-4: Updated package manager integrity check to SHA-512

The package manager field has been updated with a SHA-512 checksum, replacing the previous SHA-256 checksum. This is a security improvement that provides stronger cryptographic verification of the package manager.

packages/cli-v3/src/config.ts (3)

157-162: LGTM: Added logic to find config directory

This new code adds the ability to determine the trigger config directory when the config file is not explicitly provided, which directly addresses the PR objective of prioritizing trigger.config over package.json.


163-170: LGTM: Updated working directory resolution logic

The working directory resolution has been updated to prioritize:

  1. The config file directory (if provided)
  2. The trigger config directory (if found)
  3. The package.json directory (if found)
  4. The current working directory (fallback)

This change properly implements the PR objective to prioritize trigger.config.ts location over package.json.


223-235: LGTM: Well-implemented function to find trigger config directory

The findTriggerConfigDir function effectively locates the directory containing trigger.config.ts. It includes proper error handling to log any errors in debug mode and return undefined in case of failure, making it robust for use in various environments.

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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 bot commented Mar 9, 2025

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the PR diff to see the changes
git fetch origin pull/1778/head:pr-1778
git checkout pr-1778
git diff origin/main...pr-1778

# Look at the specific files mentioned in the AI summary
echo "==== config.ts changes ===="
git show pr-1778:packages/cli-v3/src/config.ts

# Check the issue that this PR addresses
echo "==== Related issue #1467 ===="
gh issue view 1467 --json title,body

Length of output: 12831


@Rudra-Sankha-Sinhamahapatra After reviewing your PR, I think this is a good implementation that correctly addresses issue #1467. You've added the findTriggerConfigDir function and modified the path resolution logic to prioritize trigger.config.ts over package.json when determining the base path.

The changes look clean and well-implemented with proper error handling. This will help fix the path resolution issues in monorepo setups that don't have individual package.json files in each workspace.

Everything looks good to me - nice work!

✅ Actions performed

Comments resolved.

@Rudra-Sankha-Sinhamahapatra
Copy link
Author

Rudra-Sankha-Sinhamahapatra commented Mar 12, 2025

Can someone check this pr

@ericallam @matt-aitken

@matt-aitken
Copy link
Member

@Rudra-Sankha-Sinhamahapatra thanks for this. This fix had already been done in a branch for v4 which will release very soon.

@Rudra-Sankha-Sinhamahapatra Rudra-Sankha-Sinhamahapatra deleted the issue/triggerconfig branch March 27, 2025 13:55
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.

prioritize location of trigger.config.ts file to set the "base" path instead of package.json
2 participants