Skip to content

Commit

Permalink
[core-util] Fix issue with Deno showing up as isNode at runtime. (#27459
Browse files Browse the repository at this point in the history
)

### Packages impacted by this PR

`@azure/core-util`

### Issues associated with this PR

Fixes #27077

### Describe the problem that is addressed by this PR

Deno implemented `process.versions.node`, which is how we detect that we
are running inside a Node environment. Since Deno actually is much
closer to a browser environment, this is *not* what was expected at
runtime and resulted in things like loading the browser version of
pipeline policies that throw due to not being implemented/relevant in
browsers.

I kept this really simple by making `isNode` check that `isDeno` is
false. Since `isNode` was previously false inside Deno environments, I
don't think this will break anything.

### Provide a list of related PRs _(if any)_

#27090
  • Loading branch information
xirzec authored Oct 18, 2023
1 parent e2d0a5e commit bee878f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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

0 comments on commit bee878f

Please sign in to comment.