From 916e69709f40808469dc1adfa47a989d3f229745 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Thu, 11 Jun 2020 00:15:23 +0300 Subject: [PATCH] instanceOf: support Deno (#2642) Motivation #2566 --- src/jsutils/instanceOf.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/jsutils/instanceOf.js b/src/jsutils/instanceOf.js index d45b58f0f0..6b7c17576b 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,28 @@ spurious results.`, } return false; }; + +/* global Deno */ +/* :: declare var Deno: any; */ + +function isProductionEnvironment() { + // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317') + try { + if (process.env.NODE_ENV === 'production') { + return true; + } + } catch (e) { + // ignore + } + + // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317') + try { + if (Deno.env.get('DENO_ENV') === 'production') { + return true; + } + } catch (e) { + // ignore + } + + return false; +}