From 8484e25e30ce524705c940ceaac803340ed47c31 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Wed, 10 Jun 2020 23:48:25 +0300 Subject: [PATCH] instanceOf: support Deno Motivation #2566 --- src/jsutils/instanceOf.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/jsutils/instanceOf.js b/src/jsutils/instanceOf.js index d45b58f0f0d..13ef72ba339 100644 --- a/src/jsutils/instanceOf.js +++ b/src/jsutils/instanceOf.js @@ -11,7 +11,7 @@ declare function instanceOf( // See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production // See: https://webpack.js.org/guides/production/ -export default process.env.NODE_ENV === 'production' +export default isProductionEnvironment() ? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317') // eslint-disable-next-line no-shadow function instanceOf(value: mixed, constructor: mixed) { @@ -44,3 +44,26 @@ spurious results.`, } return false; }; + +/* global Deno */ +/* :: declare var Deno: any; */ + +function isProductionEnvironment() { + try { + if (process.env.NODE_ENV === 'production') { + return true; + } + } catch (e) { + // ignore + } + + try { + if (Deno.env.get('DENO_ENV') === 'production') { + return true; + } + } catch (e) { + // ignore + } + + return false; +}