Skip to content

Commit

Permalink
fix: remove optional chaining in debug environment variable check (#6412
Browse files Browse the repository at this point in the history
)

* fix: remove optional chaining in debug environment variable check

Removed optional chaining from `globalThis?.process.env['DEBUG'] || globalThis.DEBUG` to ensure it runs on Cloudflare Workers.
 
The current implementation with optional chaining is flawed as it fails when `globalThis` is undefined, resulting in an error when accessing `process.env`. Although this change does not fully resolve the issue, it aligns with the requirement for Cloudflare Workers compatibility.

Ref: cloudflare/workers-sdk#6402

* Update packages/utils/src/debugTimer.ts

---------

Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
  • Loading branch information
schettn and ardatan authored Aug 7, 2024
1 parent 05c6121 commit b1c5701
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/utils/src/debugTimer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const debugNamesOngoing = new Set<string>();

export function debugTimerStart(name: string) {
const debugEnvVar = globalThis?.process.env['DEBUG'] || (globalThis as any).DEBUG;
const debugEnvVar = globalThis.process?.env?.['DEBUG'] || (globalThis as any).DEBUG;
if (debugEnvVar === '1' || debugEnvVar?.includes(name)) {
debugNamesOngoing.add(name);
console.time(name);
Expand Down

0 comments on commit b1c5701

Please sign in to comment.