Skip to content

ref(utils): Simplify isDebugBuild logging guard #4696

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

Merged
merged 1 commit into from
Mar 9, 2022
Merged
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
18 changes: 8 additions & 10 deletions packages/utils/src/env.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
/**
* This module mostly exists for optimizations in the build process
* through rollup and terser. We define some global constants which
* are normally undefined. However terser overrides these with global
* definitions which can be evaluated by the static analyzer when
* creating a bundle.
*
* In turn the `isDebugBuild` and `isBrowserBundle` functions are pure
* and can help us remove unused code from the bundles.
* This module exists for optimizations in the build process through rollup and terser. We define some global
* constants, which can be overridden during build. By guarding certain pieces of code with functions that return these
* constants, we can control whether or not they appear in the final bundle. (Any code guarded by a false condition will
* never run, and will hence be dropped during treeshaking.) The two primary uses for this are stripping out calls to
* `logger` and preventing node-related code from appearing in browser bundles.
*/

declare const __SENTRY_BROWSER_BUNDLE__: boolean | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Are we going to do the same for __SENTRY_BROWSER_BUNDLE__?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably it makes sense to do so, yes. That's a future-me problem, though. 🙂

declare const __SENTRY_NO_DEBUG__: boolean | undefined;

const __SENTRY_DEBUG__ = true;

/**
* Figures out if we're building with debug functionality.
*
* @returns true if this is a debug build
*/
export function isDebugBuild(): boolean {
return typeof __SENTRY_NO_DEBUG__ !== 'undefined' && !__SENTRY_BROWSER_BUNDLE__;
return __SENTRY_DEBUG__;
}

/**
Expand Down