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 903f7b6
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV=development
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 -- 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
12 changes: 6 additions & 6 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 @@ -15,11 +15,8 @@ const isProduction =
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 +47,9 @@ spurious results.`,
}
}
return false;
}
: function instanceOf(value: unknown, constructor: Constructor): boolean {
return value instanceof constructor;
};

interface Constructor extends Function {
Expand Down

0 comments on commit 903f7b6

Please sign in to comment.