forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core-util] Create isNodeLike and isNodeRuntime (Azure#29086)
### Packages impacted by this PR - @azure/core-util ### Issues associated with this PR - Azure#28101 ### Describe the problem that is addressed by this PR Reverts the behavior of `isNode` checks to ensure that it can still return true for Bun and Deno. Introducing `isNodeLike` to also have the same behavior as `isNode` so we can deprecate the former function. We have also added `isNodeRuntime` which then checks for an explicit Node.js runtime. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? The previous attempt was to create a `isNodeLike` and be opt-in, versus this PR which gives the old behavior and new opt-in for strict Node runtimes. ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ - Azure#29083 ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [x] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary) --------- Co-authored-by: Deyaaeldeen Almahallawi <[email protected]>
- Loading branch information
1 parent
0f49259
commit e9f9ff8
Showing
10 changed files
with
133 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,15 +64,23 @@ export const isDeno = | |
export const isBun = typeof Bun !== "undefined" && typeof Bun.version !== "undefined"; | ||
|
||
/** | ||
* A constant that indicates whether the environment the code is running is Node.JS. | ||
* A constant that indicates whether the environment the code is running is a Node.js compatible environment. | ||
*/ | ||
export const isNode = | ||
export const isNodeLike = | ||
typeof globalThis.process !== "undefined" && | ||
Boolean(globalThis.process.version) && | ||
Boolean(globalThis.process.versions?.node) && | ||
// Deno thought it was a good idea to spoof process.versions.node, see https://deno.land/[email protected]/node/process.ts?s=versions | ||
!isDeno && | ||
!isBun; | ||
Boolean(globalThis.process.versions?.node); | ||
|
||
/** | ||
* A constant that indicates whether the environment the code is running is a Node.js compatible environment. | ||
* @deprecated Use `isNodeLike` instead. | ||
*/ | ||
export const isNode = isNodeLike; | ||
|
||
/** | ||
* A constant that indicates whether the environment the code is running is Node.JS. | ||
*/ | ||
export const isNodeRuntime = isNodeLike && !isBun && !isDeno; | ||
|
||
/** | ||
* A constant that indicates whether the environment the code is running is in React-Native. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ export { | |
isBrowser, | ||
isBun, | ||
isNode, | ||
isNodeLike, | ||
isNodeRuntime, | ||
isDeno, | ||
isReactNative, | ||
isWebWorker, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,8 @@ export { | |
isBrowser, | ||
isBun, | ||
isNode, | ||
isNodeLike, | ||
isNodeRuntime, | ||
isDeno, | ||
isReactNative, | ||
isWebWorker, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,16 +45,24 @@ export const isDeno = | |
typeof Deno.version !== "undefined" && | ||
typeof Deno.version.deno !== "undefined"; | ||
|
||
/** | ||
* A constant that indicates whether the environment the code is running is a Node.js compatible environment. | ||
*/ | ||
export const isNodeLike = | ||
typeof globalThis.process !== "undefined" && | ||
Boolean(globalThis.process.version) && | ||
Boolean(globalThis.process.versions?.node); | ||
|
||
/** | ||
* A constant that indicates whether the environment the code is running is a Node.js compatible environment. | ||
* @deprecated Use `isNodeLike` instead. | ||
*/ | ||
export const isNode = isNodeLike; | ||
|
||
/** | ||
* 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/[email protected]/node/process.ts?s=versions | ||
!isDeno && | ||
!isBun; | ||
export const isNodeRuntime = isNodeLike && !isBun && !isDeno; | ||
|
||
/** | ||
* A constant that indicates whether the environment the code is running is in React-Native. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters