Repository navigation
Expand file tree
/
Copy pathenv.ts
More file actions
35 lines (31 loc) · 1.58 KB
/
Copy pathenv.ts
File metadata and controls
35 lines (31 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* 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.
*
* Attention:
* This file should not be used to define constants/flags that are intended to be used for tree-shaking conducted by
* users. These flags should live in their respective packages, as we identified user tooling (specifically webpack)
* having issues tree-shaking these constants across package boundaries.
* An example for this is the __SENTRY_DEBUG__ constant. It is declared in each package individually because we want
* users to be able to shake away expressions that it guards.
*/
declare const __SENTRY_BROWSER_BUNDLE__: boolean | undefined;
export type SdkSource = 'npm' | 'cdn' | 'loader';
/**
* Figures out if we're building a browser bundle.
*
* @returns true if this is a browser bundle build.
*/
export function isBrowserBundle(): boolean {
return typeof __SENTRY_BROWSER_BUNDLE__ !== 'undefined' && !!__SENTRY_BROWSER_BUNDLE__;
}
/**
* Get source of SDK.
*/
export function getSDKSource(): SdkSource {
// @ts-expect-error __SENTRY_SDK_SOURCE__ is injected by rollup during build process
return __SENTRY_SDK_SOURCE__;
}