Skip to content

Commit

Permalink
Access process only if defined
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jul 5, 2024
1 parent 76cb73d commit 3786efb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/pretty-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {getConfig} from './config'
const shouldHighlight = () => {
// Try to safely parse env COLORS: We will default behavior if any step fails.
try {
const colors = process?.env?.COLORS
const colors =
typeof process !== 'undefined' ? process?.env?.COLORS : undefined
if (colors) {
const b = JSON.parse(colors)
if (typeof b === 'boolean') return b
Expand All @@ -18,7 +19,7 @@ const shouldHighlight = () => {

// In all other cases, whether COLORS was a weird type, or the attempt threw:
// Fall back to colorizing if we are running in node.
return !!process?.versions?.node
return typeof process !== 'undefined' && !!process.versions?.node
}

const {DOMCollection} = prettyFormat.plugins
Expand Down

0 comments on commit 3786efb

Please sign in to comment.