Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/bundler/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,11 @@ pub fn defines_from_transform_options(
Box::from(b"\"development\"".as_slice())
};

user_defines.get_or_put_value(b"process.env.NODE_ENV", quoted_node_env.clone())?;
user_defines.get_or_put_value(b"process.env.BUN_ENV", quoted_node_env)?;
// Only inject NODE_ENV if env_behavior is not Disable
if self.env_behavior != DotEnv::Behavior::Disable {
user_defines.get_or_put_value(b"process.env.NODE_ENV", quoted_node_env.clone())?;
user_defines.get_or_put_value(b"process.env.BUN_ENV", quoted_node_env)?;
}
Comment on lines +921 to +925

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu
file="$(pwd)/src/bundler/options.rs"
rg -n 'pub fn defines_from_transform_options|self\.env_behavior|let mut behavior|DotEnvBehavior::disable' "$file"

Repository: oven-sh/bun

Length of output: 487


🏁 Script executed:

#!/bin/bash
set -eu
file="$(pwd)/src/bundler/options.rs"

echo "Function signature and dotenv behavior handling:"
sed -n '815,930p' "$file" | cat -n | sed 's/^/options.rs /'

echo
echo "Top-level module/type aliases around this file:"
rg -n '^pub (use|mod) |type DotEnv =|enum DotEnvBehavior|struct DotEnv|api::' "$file" | sed -n '1,80p'

Repository: oven-sh/bun

Length of output: 10670


Fix the out-of-scope self reference.

defines_from_transform_options is a free function, so self.env_behavior is undefined and prevents compilation. Use the local behavior value and the existing api::DotEnvBehavior::disable variant.

Proposed fix
-        // Only inject NODE_ENV if env_behavior is not Disable
-        if self.env_behavior != DotEnv::Behavior::Disable {
+        // Only inject NODE_ENV and BUN_ENV when dotenv behavior is not Disable
+        if behavior != api::DotEnvBehavior::disable {
📝 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
// Only inject NODE_ENV if env_behavior is not Disable
if self.env_behavior != DotEnv::Behavior::Disable {
user_defines.get_or_put_value(b"process.env.NODE_ENV", quoted_node_env.clone())?;
user_defines.get_or_put_value(b"process.env.BUN_ENV", quoted_node_env)?;
}
// Only inject NODE_ENV and BUN_ENV when dotenv behavior is not Disable
if behavior != api::DotEnvBehavior::disable {
user_defines.get_or_put_value(b"process.env.NODE_ENV", quoted_node_env.clone())?;
user_defines.get_or_put_value(b"process.env.BUN_ENV", quoted_node_env)?;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/bundler/options.rs` around lines 921 - 925, Update the
environment-injection condition in defines_from_transform_options to use the
local behavior value instead of the undefined self.env_behavior reference,
comparing it against api::DotEnvBehavior::disable. Preserve the existing
NODE_ENV and BUN_ENV define insertion behavior when dotenv handling is enabled.


// Automatically set `process.browser` to `true` for browsers and false for node+js
// This enables some extra dead code elimination
Expand Down