From 4c7fd5a4e8b745bfdbfca20b5495f48332aae90d Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 15:03:13 +0200 Subject: Replace process.browser with detect-node library --- packages/utils/package.json | 1 + packages/utils/src/fetchAsync.ts | 3 ++- packages/utils/src/globals.d.ts | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'packages/utils') diff --git a/packages/utils/package.json b/packages/utils/package.json index cb0989836..a454b35ee 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -39,6 +39,7 @@ "@0xproject/typescript-typings": "^0.4.2", "@types/node": "^8.0.53", "bignumber.js": "~4.1.0", + "detect-node": "2.0.3", "ethereum-types": "^0.0.2", "ethereumjs-util": "^5.1.1", "ethers": "3.0.22", diff --git a/packages/utils/src/fetchAsync.ts b/packages/utils/src/fetchAsync.ts index a009f0c86..47d87815e 100644 --- a/packages/utils/src/fetchAsync.ts +++ b/packages/utils/src/fetchAsync.ts @@ -1,3 +1,4 @@ +import isNode = require('detect-node'); import 'isomorphic-fetch'; export const fetchAsync = async ( @@ -6,7 +7,7 @@ export const fetchAsync = async ( timeoutMs: number = 20000, ): Promise => { let optionsWithAbortParam; - if ((process as any).browser === true) { + if (isNode) { const controller = new AbortController(); const signal = controller.signal; setTimeout(() => { diff --git a/packages/utils/src/globals.d.ts b/packages/utils/src/globals.d.ts index 94e63a32d..98a4b56fc 100644 --- a/packages/utils/src/globals.d.ts +++ b/packages/utils/src/globals.d.ts @@ -4,3 +4,7 @@ declare module '*.json' { export default json; /* tslint:enable */ } + +declare module 'detect-node' { + export const isNode: boolean; +} -- cgit v1.2.3