Skip to content

Commit 21a623b

Browse files
authored
ref(utils): Simplify isDebugBuild logging guard (#4696)
This simplifies the `isDebugBuild` check used to strip logging from minified bundles in two ways: - It makes the return value independent of the value of `__SENTRY_BROWSER_BUNDLE__`, since we want to be able to have debug and non-debug browser bundles. - It switches the variable on which it's based from one preventing debug logging which defaults to being unset to one enabling debug logging which defaults to being true. The effect is the same, but eliminating the double negative makes the intention clearer.
1 parent 3784ee1 commit 21a623b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

packages/utils/src/env.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
/**
2-
* This module mostly exists for optimizations in the build process
3-
* through rollup and terser. We define some global constants which
4-
* are normally undefined. However terser overrides these with global
5-
* definitions which can be evaluated by the static analyzer when
6-
* creating a bundle.
7-
*
8-
* In turn the `isDebugBuild` and `isBrowserBundle` functions are pure
9-
* and can help us remove unused code from the bundles.
2+
* This module exists for optimizations in the build process through rollup and terser. We define some global
3+
* constants, which can be overridden during build. By guarding certain pieces of code with functions that return these
4+
* constants, we can control whether or not they appear in the final bundle. (Any code guarded by a false condition will
5+
* never run, and will hence be dropped during treeshaking.) The two primary uses for this are stripping out calls to
6+
* `logger` and preventing node-related code from appearing in browser bundles.
107
*/
118

129
declare const __SENTRY_BROWSER_BUNDLE__: boolean | undefined;
13-
declare const __SENTRY_NO_DEBUG__: boolean | undefined;
10+
11+
const __SENTRY_DEBUG__ = true;
1412

1513
/**
1614
* Figures out if we're building with debug functionality.
1715
*
1816
* @returns true if this is a debug build
1917
*/
2018
export function isDebugBuild(): boolean {
21-
return typeof __SENTRY_NO_DEBUG__ !== 'undefined' && !__SENTRY_BROWSER_BUNDLE__;
19+
return __SENTRY_DEBUG__;
2220
}
2321

2422
/**

0 commit comments

Comments
 (0)