From 75bea4b5853c4d82e032bd5048e98f7850316f7b Mon Sep 17 00:00:00 2001 From: Alex Iglesias Date: Sun, 6 Nov 2022 11:42:09 +0100 Subject: [PATCH 1/3] fix `globalThis.process` conflict --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e2f308c..f47d805 100644 --- a/index.js +++ b/index.js @@ -223,7 +223,7 @@ export default class Emittery { // eslint-disable-next-line n/prefer-global/process const {env} = globalThis.process ?? {env: {}}; - return env.DEBUG === 'emittery' || env.DEBUG === '*' || isGlobalDebugEnabled; + return env?.DEBUG === 'emittery' || env?.DEBUG === '*' || isGlobalDebugEnabled; } static set isDebugEnabled(newValue) { From d428cd22c7b22c7b3565b703bedf14ccf6ba4570 Mon Sep 17 00:00:00 2001 From: Alex Iglesias Date: Sun, 6 Nov 2022 13:45:02 +0100 Subject: [PATCH 2/3] Implemented sindresorhus's feedback --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f47d805..3269551 100644 --- a/index.js +++ b/index.js @@ -216,14 +216,16 @@ export default class Emittery { } static get isDebugEnabled() { + // In a browser environment `globalThis.process` can potentially reference a DOM Element with a `#process` ID, + // so instead of just type checking `globalThis.process` we need to make sure that `globalThis.process.env` exists. // eslint-disable-next-line n/prefer-global/process - if (typeof globalThis.process !== 'object') { + if (typeof globalThis.process?.env !== 'object') { return isGlobalDebugEnabled; } // eslint-disable-next-line n/prefer-global/process const {env} = globalThis.process ?? {env: {}}; - return env?.DEBUG === 'emittery' || env?.DEBUG === '*' || isGlobalDebugEnabled; + return env.DEBUG === 'emittery' || env.DEBUG === '*' || isGlobalDebugEnabled; } static set isDebugEnabled(newValue) { From e002cc32033c275931f6ef1b1391076c68d4437d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 6 Nov 2022 21:13:08 +0700 Subject: [PATCH 3/3] Update index.js --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3269551..5b5f217 100644 --- a/index.js +++ b/index.js @@ -216,8 +216,8 @@ export default class Emittery { } static get isDebugEnabled() { - // In a browser environment `globalThis.process` can potentially reference a DOM Element with a `#process` ID, - // so instead of just type checking `globalThis.process` we need to make sure that `globalThis.process.env` exists. + // In a browser environment, `globalThis.process` can potentially reference a DOM Element with a `#process` ID, + // so instead of just type checking `globalThis.process`, we need to make sure that `globalThis.process.env` exists. // eslint-disable-next-line n/prefer-global/process if (typeof globalThis.process?.env !== 'object') { return isGlobalDebugEnabled;