File tree 1 file changed +12
-8
lines changed
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'
5
5
import { getConfig } from './config'
6
6
7
7
const shouldHighlight = ( ) => {
8
+ if ( typeof process === 'undefined' ) {
9
+ // Don't colorize in non-node environments (e.g. Browsers)
10
+ return false
11
+ }
8
12
let colors
13
+ // Try to safely parse env COLORS: We will default behavior if any step fails.
9
14
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
13
21
// care about `true` or `false`, we can safely ignore the error.
14
22
}
15
23
@@ -18,11 +26,7 @@ const shouldHighlight = () => {
18
26
return colors
19
27
} else {
20
28
// 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
26
30
}
27
31
}
28
32
You can’t perform that action at this time.
0 commit comments