File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,19 @@ import {getDocument} from './helpers'
55import { getConfig } from './config'
66
77const shouldHighlight = ( ) => {
8+ if ( typeof process === 'undefined' ) {
9+ // Don't colorize in non-node environments (e.g. Browsers)
10+ return false
11+ }
812 let colors
13+ // Try to safely parse env COLORS: We will default behavior if any step fails.
914 try {
10- colors = JSON . parse ( process ?. env ?. COLORS )
11- } catch ( e ) {
12- // If this throws, process?.env?.COLORS wasn't parsable. Since we only
15+ const colorsJSON = process . env ?. COLORS
16+ if ( colorsJSON ) {
17+ colors = JSON . parse ( colorsJSON )
18+ }
19+ } catch {
20+ // If this throws, process.env?.COLORS wasn't parsable. Since we only
1321 // care about `true` or `false`, we can safely ignore the error.
1422 }
1523
@@ -18,11 +26,7 @@ const shouldHighlight = () => {
1826 return colors
1927 } else {
2028 // If `colors` is not set, colorize if we're in node.
21- return (
22- typeof process !== 'undefined' &&
23- process . versions !== undefined &&
24- process . versions . node !== undefined
25- )
29+ return process . versions !== undefined && process . versions . node !== undefined
2630 }
2731}
2832
You can’t perform that action at this time.
0 commit comments