Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core-util] Fix issue with Deno showing up as isNode at runtime. #27459

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/core/core-util/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Improved `isNode` to be false when `isDeno` is true due to Deno implementing `process.version.node`

### Other Changes

## 1.5.0 (2023-09-25)
Expand Down
16 changes: 10 additions & 6 deletions sdk/core/core-util/src/checkEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ export const isWebWorker =
self.constructor?.name === "ServiceWorkerGlobalScope" ||
self.constructor?.name === "SharedWorkerGlobalScope");

/**
* A constant that indicates whether the environment the code is running is Node.JS.
*/
export const isNode =
typeof process !== "undefined" && Boolean(process.version) && Boolean(process.versions?.node);

/**
* A constant that indicates whether the environment the code is running is Deno.
*/
Expand All @@ -66,6 +60,16 @@ export const isDeno =
typeof Deno.version !== "undefined" &&
typeof Deno.version.deno !== "undefined";

/**
* A constant that indicates whether the environment the code is running is Node.JS.
*/
export const isNode =
typeof process !== "undefined" &&
Boolean(process.version) &&
Boolean(process.versions?.node) &&
// Deno thought it was a good idea to spoof process.versions.node, see https://deno.land/std@0.177.0/node/process.ts?s=versions
!isDeno;

/**
* A constant that indicates whether the environment the code is running is Bun.sh.
*/
Expand Down