Skip to content

Runtime agnostic SDK configuration via env vars #2132

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented May 30, 2025

Less of this:

import { configure } from "@trigger.dev/sdk/v3";

configure({
  secretKey: "tr_dev_…", // nasty, don't do this
});

More of that:

TRIGGER_SECRET_KEY="tr_dev_…"

Copy link

changeset-bot bot commented May 30, 2025

🦋 Changeset detected

Latest commit: 0d34642

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

coderabbitai bot commented May 30, 2025

Walkthrough

A new changeset file was added to document patch-level updates for the "trigger.dev" and "@trigger.dev/core" packages, specifically noting the introduction of runtime-agnostic SDK configuration using environment variables. In the codebase, the getEnvVar function within the utilities was refactored to utilize the env object from the std-env package for accessing environment variables, replacing manual runtime detection and direct process.env access. A comprehensive JSDoc comment was also added to this function. No changes were made to the signatures of exported or public entities.


📜 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 ff157e5 and 0d34642.

📒 Files selected for processing (2)
  • .changeset/flat-pianos-live.md (1 hunks)
  • packages/core/src/v3/utils/getEnv.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/v3/utils/getEnv.ts (2)
packages/core/src/v3/workers/index.ts (1)
  • getEnvVar (4-4)
apps/webapp/app/env.server.ts (1)
  • env (788-788)
⏰ Context from checks skipped due to timeout of 90000ms (25)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (9, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (10, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
packages/core/src/v3/utils/getEnv.ts (3)

1-1: Excellent choice for runtime agnostic environment variable access!

Using the std-env package is a great approach for achieving runtime agnostic SDK configuration. This package automatically detects and works across different JavaScript runtimes (Node.js, Deno, Cloudflare Workers, etc.).


3-10: Well-documented function with clear JSDoc.

The comprehensive JSDoc documentation clearly explains the function's purpose, parameters, and return value. This is especially valuable for a utility function that will be used throughout the codebase.


11-12:

❓ Verification inconclusive

Verify std-env dependency and edge case compatibility.

The implementation looks correct and achieves the runtime agnostic goal. However, please verify:

  1. The std-env package is properly added to package dependencies
  2. Edge case compatibility between std-env and process.env behavior

🏁 Script executed:

#!/bin/bash
# Description: Verify std-env package is in dependencies and check for any compatibility concerns

# Check if std-env is in package.json dependencies
echo "=== Checking for std-env in package.json dependencies ==="
fd package.json --exec grep -l "std-env" {} \;

# Check for any existing usage of process.env that might need similar updates
echo "=== Checking for remaining process.env usage in the codebase ==="
rg "process\.env" --type ts --type js -A 2 -B 2 | head -20

# Check for any imports of std-env to understand current usage
echo "=== Checking current std-env imports ==="
rg "from ['\"]std-env['\"]" --type ts --type js

Length of output: 3729


std-env Dependency Present; Please Confirm Edge-Case Alignment

  • std-env is declared in packages/core/package.json (and used consistently across the repo)
  • 🔍 No remaining direct process.env references in core utils—every access now goes through std-env
  • ⚠️ As a final step, please verify that std-env’s env[name] behavior matches process.env[name] in your supported environments (e.g. handling of empty strings, Windows case-insensitivity, null vs. undefined)
.changeset/flat-pianos-live.md (1)

1-7: Changeset properly documents the runtime agnostic changes.

The changeset correctly specifies patch-level updates for the affected packages and provides a clear description that aligns with the PR objectives. The format follows standard changeset conventions.

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

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.

1 participant