Skip to content

Commit 1f06a23

Browse files
authored
fix: SDK removed isDebugBuild (getsentry/sentry-replay#44)
Replaced with a constant that can be treeshaked. See #4842
1 parent 6e35957 commit 1f06a23

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "@sentry/replay",
3-
"version": "0.2.0-0",
3+
"version": "0.2.0-1",
44
"description": "User replays for Sentry",
55
"main": "dist/index.js",
66
"module": "dist/index.es.js",
77
"scripts": {
88
"bootstrap": "yarn && cd demo && yarn",
9-
"build": "yarn rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
9+
"build": "NODE_ENV=production yarn rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
1010
"clean": "yarn rimraf dist",
1111
"lint": "yarn eslint . --ext .js,.jsx,.ts,.tsx",
1212
"prepare": "husky install",
1313
"start:demo": "yarn build && cd demo && yarn start",
1414
"test": "yarn jest",
15-
"watch": "yarn build --watch"
15+
"watch": "NODE_ENV=development yarn build --watch"
1616
},
1717
"files": [
1818
"dist"
@@ -35,6 +35,7 @@
3535
},
3636
"devDependencies": {
3737
"@babel/core": "^7.17.5",
38+
"@rollup/plugin-replace": "^4.0.0",
3839
"@rollup/plugin-typescript": "^8.3.1",
3940
"@sentry/browser": "^6.19.1",
4041
"@sentry/tracing": "^6.19.1",

rollup.config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { RollupOptions } from 'rollup';
2+
import replace from '@rollup/plugin-replace';
23
import typescript from '@rollup/plugin-typescript';
34

45
import pkg from './package.json';
@@ -20,7 +21,17 @@ const config: RollupOptions = {
2021
...Object.keys(pkg.dependencies || {}),
2122
...Object.keys(pkg.peerDependencies || {}),
2223
],
23-
plugins: [typescript()],
24+
plugins: [
25+
typescript(),
26+
replace({
27+
// __SENTRY_DEBUG__ should be save to replace in any case, so no checks for assignments necessary
28+
preventAssignment: false,
29+
values: {
30+
// @ts-expect-error not gonna deal with types here
31+
__SENTRY_DEBUG__: process.env.NODE_ENV === 'development',
32+
},
33+
}),
34+
],
2435
};
2536

2637
export default config;

src/flags.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* See https://github.com/getsentry/sentry-javascript/pull/4842
3+
* This file defines flags and constants that can be modified during compile time in order to facilitate tree shaking
4+
* for users.
5+
*
6+
* Debug flags need to be declared in each package individually and must not be imported across package boundaries,
7+
* because some build tools have trouble tree-shaking imported guards.
8+
*
9+
* As a convention, we define debug flags in a `flags.ts` file in the root of a package's `src` folder.
10+
*
11+
* Debug flag files will contain "magic strings" like `__SENTRY_DEBUG__` that may get replaced with actual values during
12+
* our, or the user's build process. Take care when introducing new flags - they must not throw if they are not
13+
* replaced.
14+
*/
15+
16+
declare const __SENTRY_DEBUG__: boolean;
17+
18+
/** Flag that is true for debug builds, false otherwise. */
19+
export const IS_DEBUG_BUILD =
20+
typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;

src/util/logger.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { isDebugBuild, logger as sentryLogger } from '@sentry/utils';
1+
import { logger as sentryLogger } from '@sentry/utils';
2+
3+
import { IS_DEBUG_BUILD } from '../flags';
24

35
function wrapLogger(logFn: typeof sentryLogger[keyof typeof sentryLogger]) {
46
return function wrappedLog(...args: any[]) {
5-
if (!isDebugBuild()) {
7+
if (!IS_DEBUG_BUILD) {
68
return;
79
}
810
return logFn.call(sentryLogger, '[Replay]', ...args);

yarn.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,14 @@
680680
"@nodelib/fs.scandir" "2.1.5"
681681
fastq "^1.6.0"
682682

683+
"@rollup/plugin-replace@^4.0.0":
684+
version "4.0.0"
685+
resolved "https://registry.yarnpkg.com/@rollup/plugin-replace/-/plugin-replace-4.0.0.tgz#e34c457d6a285f0213359740b43f39d969b38a67"
686+
integrity sha512-+rumQFiaNac9y64OHtkHGmdjm7us9bo1PlbgQfdihQtuNxzjpaB064HbRnewUOggLQxVCCyINfStkgmBeQpv1g==
687+
dependencies:
688+
"@rollup/pluginutils" "^3.1.0"
689+
magic-string "^0.25.7"
690+
683691
"@rollup/plugin-typescript@^8.3.1":
684692
version "8.3.1"
685693
resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-8.3.1.tgz#b7dc75ed6b4876e260b9e80624fab23bc98e4ac1"
@@ -2815,6 +2823,13 @@ lru-cache@^6.0.0:
28152823
dependencies:
28162824
yallist "^4.0.0"
28172825

2826+
magic-string@^0.25.7:
2827+
version "0.25.9"
2828+
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c"
2829+
integrity sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==
2830+
dependencies:
2831+
sourcemap-codec "^1.4.8"
2832+
28182833
make-dir@^3.0.0:
28192834
version "3.0.0"
28202835
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.0.0.tgz#1b5f39f6b9270ed33f9f054c5c0f84304989f801"
@@ -3366,6 +3381,11 @@ source-map@^0.7.3:
33663381
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
33673382
integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==
33683383

3384+
sourcemap-codec@^1.4.8:
3385+
version "1.4.8"
3386+
resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4"
3387+
integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==
3388+
33693389
sprintf-js@~1.0.2:
33703390
version "1.0.3"
33713391
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"

0 commit comments

Comments
 (0)