File tree Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,14 @@ const commitHash = require('child_process')
99  . trim ( ) ; 
1010
1111const  terserInstance  =  terser ( { 
12+   compress : { 
13+     // Tell env.ts that we're building a browser bundle and that we do not 
14+     // want to have unnecessary debug functionality. 
15+     global_defs : { 
16+       __SENTRY_BROWSER_BUNDLE__ : true , 
17+       __SENTRY_NO_DEBUG__ : true , 
18+     } , 
19+   } , 
1220  mangle : { 
1321    // captureExceptions and captureMessage are public API methods and they don't need to be listed here 
1422    // as mangler doesn't touch user-facing thing, however sentryWrapped is not, and it would be mangled into a minified version. 
Original file line number Diff line number Diff line change 1+ /** 
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. 
10+  */ 
11+ 
12+ declare  const  __SENTRY_BROWSER_BUNDLE__ : boolean  |  undefined ; 
13+ declare  const  __SENTRY_NO_DEBUG__ : boolean  |  undefined ; 
14+ 
15+ /** 
16+  * Figures out if we're building with debug functionality. 
17+  * 
18+  * @returns  true if this is a debug build 
19+  */ 
20+ export  function  isDebugBuild ( ) : boolean  { 
21+   return  typeof  __SENTRY_NO_DEBUG__  !==  'undefined'  &&  ! __SENTRY_BROWSER_BUNDLE__ ; 
22+ } 
23+ 
24+ /** 
25+  * Figures out if we're building a browser bundle. 
26+  * 
27+  * @returns  true if this is a browser bundle build. 
28+  */ 
29+ export  function  isBrowserBundle ( ) : boolean  { 
30+   return  typeof  __SENTRY_BROWSER_BUNDLE__  !==  'undefined'  &&  ! ! __SENTRY_BROWSER_BUNDLE__ ; 
31+ } 
Original file line number Diff line number Diff line change @@ -17,3 +17,4 @@ export * from './string';
1717export  *  from  './supports' ; 
1818export  *  from  './syncpromise' ; 
1919export  *  from  './time' ; 
20+ export  *  from  './env' ; 
Original file line number Diff line number Diff line change 33 * you must either a) use `console.log` rather than the logger, or b) put your function elsewhere. 
44 */ 
55
6+ import  {  isBrowserBundle  }  from  './env' ; 
7+ 
68/** 
79 * Checks whether we're in the Node.js or Browser environment 
810 * 
911 * @returns  Answer to given question 
1012 */ 
1113export  function  isNodeEnv ( ) : boolean  { 
12-   return  Object . prototype . toString . call ( typeof  process  !==  'undefined'  ? process  : 0 )  ===  '[object process]' ; 
14+   // explicitly check for browser bundles as those can be optimized statically 
15+   // by terser/rollup. 
16+   return  ( 
17+     ! isBrowserBundle ( )  && 
18+     Object . prototype . toString . call ( typeof  process  !==  'undefined'  ? process  : 0 )  ===  '[object process]' 
19+   ) ; 
1320} 
1421
1522/** 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments