From b1daf0317fd73cc2e49e130d36e972dced374506 Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Mon, 9 Sep 2024 14:39:18 +0300 Subject: [PATCH] instanceOf: disable dev instanceOf checks if NODE_ENV not set development behavior should be opt in, not opt out https://github.com/graphql/graphql-js/issues/4075#issuecomment-2088870697 --- package-lock.json | 167 ++++++++++++++++++++++++++++++++++++++ package.json | 3 +- src/jsutils/instanceOf.ts | 16 ++-- 3 files changed, 177 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 352224e43e..b5963855df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "devDependencies": { "@docusaurus/core": "3.5.2", "@docusaurus/preset-classic": "3.5.2", + "@dotenvx/dotenvx": "^1.14.0", "@mdx-js/react": "3.0.1", "@svgr/webpack": "8.1.0", "@types/chai": "4.3.19", @@ -3759,6 +3760,95 @@ "node": ">=18.0" } }, + "node_modules/@dotenvx/dotenvx": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@dotenvx/dotenvx/-/dotenvx-1.14.0.tgz", + "integrity": "sha512-ujWncblsqokvW8w6tCW35hjwlD3FHySMdrC5OPMYqfcGR96B/H6xK9xSu5F/SyZ8uk8USoPZynsXxB24IGvfmQ==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "commander": "^11.1.0", + "dotenv": "^16.4.5", + "eciesjs": "^0.4.6", + "execa": "^5.1.1", + "fdir": "^6.2.0", + "ignore": "^5.3.0", + "object-treeify": "1.1.33", + "picomatch": "^4.0.2", + "which": "^4.0.0" + }, + "bin": { + "dotenvx": "src/cli/dotenvx.js", + "git-dotenvx": "src/cli/dotenvx.js" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/@dotenvx/dotenvx/node_modules/commander": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", + "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=16" + } + }, + "node_modules/@dotenvx/dotenvx/node_modules/fdir": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.3.0.tgz", + "integrity": "sha512-QOnuT+BOtivR77wYvCWHfGt9s4Pz1VIMbD463vegT5MLqNXy8rYFT/lPVEqf/bhYeT6qmqrNHhsX+rWwe3rOCQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/@dotenvx/dotenvx/node_modules/isexe": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-3.1.1.tgz", + "integrity": "sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=16" + } + }, + "node_modules/@dotenvx/dotenvx/node_modules/picomatch": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", + "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/@dotenvx/dotenvx/node_modules/which": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz", + "integrity": "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^3.1.1" + }, + "bin": { + "node-which": "bin/which.js" + }, + "engines": { + "node": "^16.13.0 || >=18.0.0" + } + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -4179,6 +4269,45 @@ "dev": true, "license": "MIT" }, + "node_modules/@noble/ciphers": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-0.5.3.tgz", + "integrity": "sha512-B0+6IIHiqEs3BPMT0hcRmHvEj2QHOLu+uwt+tqDDeVd0oyVzh7BPrDcPjRnV1PV/5LaknXJJQvOuRGR0zQJz+w==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/curves": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.6.0.tgz", + "integrity": "sha512-TlaHRXDehJuRNR9TfZDNQ45mMEd5dwUwmicsafcIX4SsNiqnCHKjE/1alYPd/lDRVhxdhUAlv8uEhMCI5zjIJQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@noble/hashes": "1.5.0" + }, + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/hashes": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.5.0.tgz", + "integrity": "sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -8684,6 +8813,19 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/duplexer": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", @@ -8698,6 +8840,21 @@ "dev": true, "license": "MIT" }, + "node_modules/eciesjs": { + "version": "0.4.7", + "resolved": "https://registry.npmjs.org/eciesjs/-/eciesjs-0.4.7.tgz", + "integrity": "sha512-4JQahOkBdDy27jjW4q3FJQigHlcwZXx28sCtBQkBamF2XUdcNXrInpgrr8h205MtVIS0CMHufyIKGVjtjxQ2ZA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@noble/ciphers": "^0.5.3", + "@noble/curves": "^1.4.0", + "@noble/hashes": "^1.4.0" + }, + "engines": { + "node": ">=16.0.0" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -16104,6 +16261,16 @@ "node": ">= 0.4" } }, + "node_modules/object-treeify": { + "version": "1.1.33", + "resolved": "https://registry.npmjs.org/object-treeify/-/object-treeify-1.1.33.tgz", + "integrity": "sha512-EFVjAYfzWqWsBMRHPMAXLCDIJnpMhdWAqR7xG6M6a2cs6PMFpl/+Z20w9zDW4vkxOFfddegBKq9Rehd0bxWE7A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 10" + } + }, "node_modules/object.assign": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.5.tgz", diff --git a/package.json b/package.json index afba3d93eb..c7d99f2d32 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "test": "npm run lint && npm run check && npm run testonly:cover && npm run prettier:check && npm run check:spelling && npm run check:integrations", "lint": "eslint --cache --max-warnings 0 --rulesdir resources/eslint-internal-rules/ .", "check": "tsc --pretty", - "testonly": "mocha --full-trace src/**/__tests__/**/*-test.ts", + "testonly": "dotenvx run --quiet --env NODE_ENV=development -- mocha --full-trace src/**/__tests__/**/*-test.ts", "testonly:cover": "c8 npm run testonly", "testonly:watch": "npm run testonly -- --watch", "prettier": "prettier --cache --cache-strategy metadata --write --list-different .", @@ -56,6 +56,7 @@ "devDependencies": { "@docusaurus/core": "3.5.2", "@docusaurus/preset-classic": "3.5.2", + "@dotenvx/dotenvx": "^1.14.0", "@mdx-js/react": "3.0.1", "@svgr/webpack": "8.1.0", "@types/chai": "4.3.19", diff --git a/src/jsutils/instanceOf.ts b/src/jsutils/instanceOf.ts index 562aee3e2f..0155c8c6d2 100644 --- a/src/jsutils/instanceOf.ts +++ b/src/jsutils/instanceOf.ts @@ -1,10 +1,10 @@ import { inspect } from './inspect.js'; /* c8 ignore next 3 */ -const isProduction = +const isDevelopment = globalThis.process != null && // eslint-disable-next-line no-undef - process.env.NODE_ENV === 'production'; + process.env.NODE_ENV === 'development'; /** * A replacement for instanceof which includes an error warning when multi-realm @@ -13,13 +13,8 @@ const isProduction = * See: https://webpack.js.org/guides/production/ */ export const instanceOf: (value: unknown, constructor: Constructor) => boolean = - /* c8 ignore next 6 */ - // FIXME: https://github.com/graphql/graphql-js/issues/2317 - isProduction + isDevelopment ? function instanceOf(value: unknown, constructor: Constructor): boolean { - return value instanceof constructor; - } - : function instanceOf(value: unknown, constructor: Constructor): boolean { if (value instanceof constructor) { return true; } @@ -50,6 +45,11 @@ spurious results.`, } } return false; + } + : /* c8 ignore next 4 */ + // FIXME: https://github.com/graphql/graphql-js/issues/2317 + function instanceOf(value: unknown, constructor: Constructor): boolean { + return value instanceof constructor; }; interface Constructor extends Function {