Skip to content

Commit 14c2654

Browse files
committed
build: configure static globals to control bundle/debug code
1 parent 5216184 commit 14c2654

File tree

7 files changed

+21
-4
lines changed

7 files changed

+21
-4
lines changed

globals.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const SENTRY_BROWSER_BUNDLE: boolean | undefined;
2+
declare const SENTRY_NDBEUG: boolean | undefined;

packages/browser/rollup.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ const commitHash = require('child_process')
99
.trim();
1010

1111
const terserInstance = terser({
12+
compress: {
13+
global_defs: {
14+
SENTRY_BROWSER_BUNDLE: true,
15+
SENTRY_NDEBUG: true,
16+
},
17+
},
1218
mangle: {
1319
// captureExceptions and captureMessage are public API methods and they don't need to be listed here
1420
// as mangler doesn't touch user-facing thing, however sentryWrapped is not, and it would be mangled into a minified version.

packages/browser/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33

4-
"include": ["src/**/*"],
4+
"include": ["src/**/*", "../../globals.d.ts"],
55

66
"compilerOptions": {
77
// package-specific options

packages/utils/src/global.ts

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface SentryGlobal {
2424
hub: any;
2525
logger: any;
2626
};
27+
SENTRY_BROWSER_BUNDLE?: boolean;
28+
SENTRY_NDEBUG?: boolean;
2729
}
2830

2931
const fallbackGlobalObject = {};

packages/utils/src/node.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
* @returns Answer to given question
1010
*/
1111
export function isNodeEnv(): boolean {
12-
return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
12+
if (SENTRY_BROWSER_BUNDLE) {
13+
return false;
14+
} else {
15+
return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
16+
}
1317
}
1418

1519
/**

packages/utils/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33

4-
"include": ["src/**/*"],
4+
"include": ["src/**/*", "../../globals.d.ts"],
55

66
"compilerOptions": {
77
// package-specific options

tsconfig.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"allowSyntheticDefaultImports": true,
66
"types": ["node"],
77
"noErrorTruncation": true // move me up to @sentry/typescript
8-
}
8+
},
9+
"include": [
10+
"./globals.d.ts"
11+
]
912
}

0 commit comments

Comments
 (0)