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

fix: remove node env from build pipeline #1105

Closed
wants to merge 12 commits into from
Closed

Conversation

juliusmarminge
Copy link
Collaborator

@juliusmarminge juliusmarminge commented Dec 30, 2024

NODE_ENV being present during build causes static replacement and breaks automatic dev mode detection

Summary by CodeRabbit

  • Chores
    • Updated configuration to improve environment variable handling for development mode detection.
    • Refined Turbo configuration for more precise environment variable management.
    • Introduced new properties to exclude NODE_ENV from being passed through during the build process across multiple packages.

Copy link

changeset-bot bot commented Dec 30, 2024

🦋 Changeset detected

Latest commit: 7780e9e

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

This PR includes changesets to release 1 package
Name Type
uploadthing Patch

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

vercel bot commented Dec 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-uploadthing 🛑 Canceled (Inspect) Dec 30, 2024 0:13am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
legacy-docs-uploadthing ⬜️ Ignored (Inspect) Visit Preview Dec 30, 2024 0:13am

Copy link
Contributor

coderabbitai bot commented Dec 30, 2024

Warning

Rate limit exceeded

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

⌛ How to resolve this issue?

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

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

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

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

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e80b625 and 8e08221.

📒 Files selected for processing (1)
  • .github/workflows/release.yaml (1 hunks)

Walkthrough

This pull request introduces a patch for the "uploadthing" functionality, specifically addressing issues with automatic development mode detection based on the NODE_ENV environment variable. Additionally, it modifies the turbo.json configuration files across multiple packages to adjust how the NODE_ENV variable is handled during the build process, ensuring it is excluded from being passed through in the build tasks.

Changes

File Change Summary
.changeset/spotty-windows-fold.md Added a patch for "uploadthing" to address development mode detection.
turbo.json Modified globalPassThroughEnv array: Removed NODE and NODE_ENV.
packages/react/turbo.json Added property "passThroughEnv": ["!NODE_ENV"] in the build task.
packages/shared/turbo.json Added property "passThroughEnv": ["!NODE_ENV"] in the build task.
packages/uploadthing/turbo.json Added property "passThroughEnv": ["!NODE_ENV"] in the build task.

Possibly related PRs

Suggested reviewers

  • markflorkowski

🪧 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. (Beta)
  • @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

pkg-pr-new bot commented Dec 30, 2024

Copy link
Contributor

github-actions bot commented Dec 30, 2024

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 29.30KB See Treemap 📊
PR (0709354) 29.30KB See Treemap 📊
Diff No change

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.changeset/spotty-windows-fold.md (1)

1-5: Clarify the patch rationale for future reference.

Including a short explanation of why removing NODE_ENV from the pipeline resolves the dev mode inference issue can help others quickly understand the purpose of this patch in the future. Consider elaborating more in the changeset body.

  ---
  "uploadthing": patch
  ---
+ # Reason:
+ Removing `NODE_ENV` from the build pipeline ensures that the dev mode detection
+ code can automatically infer the environment without forced static replacements.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 92e8fdf and eaa42bd.

📒 Files selected for processing (4)
  • .changeset/spotty-windows-fold.md (1 hunks)
  • packages/uploadthing/src/internal/config.test.ts (1 hunks)
  • packages/uploadthing/src/internal/config.ts (1 hunks)
  • turbo.json (1 hunks)
🔇 Additional comments (3)
packages/uploadthing/src/internal/config.ts (1)

56-56: Ensure cross-environment compatibility.

By conditionally referencing process.env.NODE_ENV only when process is defined, you're making the code resilient to non-NodeJS runtimes. However, consider verifying that none of the bundling or hosting environments inadvertently remove or modify process references.

Run the following script to confirm there are no other unconditional references to process in the codebase:

✅ Verification successful

References to process are properly guarded in the codebase

After analyzing the codebase, I found that references to process are properly handled:

  1. In packages/uploadthing/src/internal/config.ts, the code safely checks for process existence:
typeof process !== "undefined" ? process.env.NODE_ENV : undefined
  1. Other occurrences of process are in:
  • Test files (*.test.ts) which run in Node.js environment
  • Configuration files (like env.mjs, next.config.js) which are Node.js scripts
  • Example applications that use frameworks (Next.js, Expo) which handle process references during build
  • Documentation files (.mdx) showing example usage

The codebase demonstrates proper handling of environment variables across different runtime environments, with appropriate guards for non-Node.js environments.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find unconditional references to `process` across the codebase.
rg -A 3 "process\." 

Length of output: 17739

packages/uploadthing/src/internal/config.test.ts (1)

280-280: Good coverage for dev mode detection using NODE_ENV.

The test ensures that development mode is accurately recognized when NODE_ENV is set. This addresses the scenario where NODE_ENV might not properly propagate in certain bundles. No issues detected.

turbo.json (1)

12-12: Confirm no breakage from removing NODE_ENV in the pipeline.

Removing NODE_ENV may impact scripts or build steps that previously relied on it. Verify that all tasks can still correctly detect dev vs. production mode if needed.

✅ Verification successful

Removing NODE_ENV from globalPassThroughEnv is safe

Based on the search results, NODE_ENV is primarily used in:

  • Example apps' env.mjs files for environment validation
  • Development scripts in backend-adapters examples
  • UploadThing package for development mode detection

All these usages either:

  1. Access NODE_ENV directly from process.env
  2. Set NODE_ENV explicitly in npm scripts
  3. Have fallbacks when NODE_ENV is undefined

The removal from turbo.json's globalPassThroughEnv won't impact the codebase since:

  • Build scripts explicitly set NODE_ENV when needed
  • Runtime code properly accesses it through process.env
  • Environment validation in examples uses process.env directly
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check references to NODE_ENV in config and scripts to ensure they don't rely on it from the pipeline.
rg -A 5 "NODE_ENV"

Length of output: 7938

Copy link
Contributor

A new canary is available for testing. You can install this latest build in your project with:

pnpm add @uploadthing/expo@7.1.5-canary.0063144
pnpm add @uploadthing/mime-types@0.3.4-canary.0063144
pnpm add @uploadthing/nuxt@7.1.5-canary.0063144
pnpm add @uploadthing/react@7.1.5-canary.0063144
pnpm add @uploadthing/shared@7.1.5-canary.0063144
pnpm add @uploadthing/solid@7.1.5-canary.0063144
pnpm add @uploadthing/svelte@7.1.5-canary.0063144
pnpm add uploadthing@7.4.3-canary.0063144
pnpm add @uploadthing/vue@7.1.5-canary.0063144

@github-actions github-actions bot removed the release canary Trigger a canary release to npm label Dec 30, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/uploadthing/turbo.json (1)

6-6: LGTM! Consider documenting this change.

The NODE_ENV exclusion is consistently implemented across all packages.

Consider adding a comment in the root turbo.json or README explaining why NODE_ENV is excluded from builds. This will help future maintainers understand the reasoning behind this configuration, especially regarding the development mode detection behavior.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3875bc9 and 4da4af2.

📒 Files selected for processing (4)
  • packages/react/turbo.json (1 hunks)
  • packages/shared/turbo.json (1 hunks)
  • packages/uploadthing/turbo.json (1 hunks)
  • turbo.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • turbo.json
🔇 Additional comments (2)
packages/shared/turbo.json (1)

6-6: LGTM! Verify schema validation.

The exclusion of NODE_ENV is correctly configured using the passThroughEnv property.

Let's verify the turbo.json schema to ensure the syntax is valid:

✅ Verification successful

Schema validation confirms correct syntax for passThroughEnv

Based on the schema definition, the passThroughEnv property in the task configuration is correctly defined. The schema shows that:

  • It accepts an array of EnvWildcard items (string type)
  • Supports negation patterns (like "!NODE_ENV")
  • Is an optional property with a default value of null
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Validate turbo.json schema
curl -s https://turbo.build/schema.json | jq -r '.properties.tasks.additionalProperties.properties.passThroughEnv'

Length of output: 119


Script:

#!/bin/bash
# Let's check the actual content of the schema to understand the correct property path
curl -s https://turbo.build/schema.json | jq '.'

Length of output: 14262

packages/react/turbo.json (1)

6-6: LGTM! Consistent with shared package configuration.

The NODE_ENV exclusion is implemented consistently across packages.

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