From 758fb72605aa43d5edc918d7dab2e6dd1e356102 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Tue, 11 Jun 2024 23:13:59 +0300 Subject: [PATCH 1/2] docs: mention `env.DISABLE_NODE_FETCH_NATIVE_WARN` --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 96e00f7..c7bf5fa 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,10 @@ You have two ways to do this: - Set the `FORCE_NODE_FETCH` environment variable before starting the application. - Import from `node-fetch-native/node` +## Disable runtime check + +Once the `node-fetch-native/node` module is loaded, it pushes a log warning if the current runtime differs from the Node.js. Set the `DISABLE_NODE_FETCH_NATIVE_WARN` environment variable to turn this check off. + ## Polyfill support Using the polyfill method, we can ensure global fetch is available in the environment and all files. Natives are always preferred. From 819160b8804dc7d7d47984dcf279ff643c45caee Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Tue, 11 Jun 2024 23:20:18 +0300 Subject: [PATCH 2/2] chore: align index variables initialization --- src/index.ts | 9 +-------- src/node.ts | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index a6b07d7..0ad6768 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,14 +21,7 @@ export { const _forceNodeFetch = !!globalThis.process?.env?.FORCE_NODE_FETCH; -function _getFetch() { - if (!_forceNodeFetch && globalThis.fetch) { - return globalThis.fetch; - } - return _fetch; -} - -export const fetch = _getFetch(); +export const fetch = (!_forceNodeFetch && globalThis.fetch) || _fetch; export default fetch; export const Blob = (!_forceNodeFetch && globalThis.Blob) || _Blob; diff --git a/src/node.ts b/src/node.ts index d9cdb05..f8296ce 100644 --- a/src/node.ts +++ b/src/node.ts @@ -21,7 +21,7 @@ checkNodeEnvironment(); function checkNodeEnvironment() { if ( !globalThis.process?.versions?.node && - !globalThis.process?.env.DISABLE_NODE_FETCH_NATIVE_WARN + !globalThis.process?.env?.DISABLE_NODE_FETCH_NATIVE_WARN ) { console.warn( "[node-fetch-native] Node.js compatible build of `node-fetch-native` is being used in a non-Node.js environment. Please make sure you are using proper export conditions or report this issue to https://github.com/unjs/node-fetch-native. You can set `process.env.DISABLE_NODE_FETCH_NATIVE_WARN` to disable this warning.",