Skip to content

Commit

Permalink
instanceOf: disable dev instanceOf checks if NODE_ENV not set
Browse files Browse the repository at this point in the history
development behavior should be opt in, not opt out

#4075 (comment)
  • Loading branch information
yaacovCR committed Sep 9, 2024
1 parent 6c56e05 commit b1daf03
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 9 deletions.
167 changes: 167 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand All @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions src/jsutils/instanceOf.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b1daf03

Please sign in to comment.