Skip to content

Commit ee430bd

Browse files
committed
fix: only set the variable if not already set
1 parent eef77e4 commit ee430bd

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/bundler-plugin-core/src/build-plugin-manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ export function createSentryBuildPluginManager(
221221
] = `${bundlerPluginMetaContext.buildTool}-plugin/${__PACKAGE_VERSION__}`;
222222

223223
// Propagate debug flag to Sentry CLI via environment variable
224-
if (options.debug) {
224+
// Only set if not already defined to respect user's explicit configuration
225+
if (options.debug && !process.env["SENTRY_LOG_LEVEL"]) {
225226
process.env["SENTRY_LOG_LEVEL"] = "debug";
226227
}
227228

packages/bundler-plugin-core/test/build-plugin-manager.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,27 @@ describe("createSentryBuildPluginManager", () => {
6666
expect(process.env["SENTRY_LOG_LEVEL"]).toBe("debug");
6767
});
6868

69+
it("should NOT override existing SENTRY_LOG_LEVEL even when debug is true", () => {
70+
// User explicitly set SENTRY_LOG_LEVEL to "info"
71+
process.env["SENTRY_LOG_LEVEL"] = "info";
72+
73+
createSentryBuildPluginManager(
74+
{
75+
authToken: "test-token",
76+
org: "test-org",
77+
project: "test-project",
78+
debug: true,
79+
},
80+
{
81+
buildTool: "webpack",
82+
loggerPrefix: "[sentry-webpack-plugin]",
83+
}
84+
);
85+
86+
// Should respect the user's explicit setting
87+
expect(process.env["SENTRY_LOG_LEVEL"]).toBe("info");
88+
});
89+
6990
it("should not set SENTRY_LOG_LEVEL environment variable when debug is false", () => {
7091
createSentryBuildPluginManager(
7192
{

0 commit comments

Comments
 (0)