1
+ import { isProduction } from '../utilities/env.js' ;
2
+
1
3
import { inspect } from './inspect.js' ;
2
4
3
- /* c8 ignore next 3 */
4
- const isProduction =
5
- globalThis . process != null &&
6
- // eslint-disable-next-line no-undef
7
- process . env . NODE_ENV === 'production' ;
8
-
9
- /**
10
- * A replacement for instanceof which includes an error warning when multi-realm
11
- * constructors are detected.
12
- * See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
13
- * See: https://webpack.js.org/guides/production/
14
- */
15
- export const instanceOf : ( value : unknown , constructor : Constructor ) => boolean =
16
- /* c8 ignore next 6 */
17
- // FIXME: https://github.com/graphql/graphql-js/issues/2317
18
- isProduction
19
- ? function instanceOf ( value : unknown , constructor : Constructor ) : boolean {
20
- return value instanceof constructor ;
21
- }
22
- : function instanceOf ( value : unknown , constructor : Constructor ) : boolean {
23
- if ( value instanceof constructor ) {
24
- return true ;
25
- }
26
- if ( typeof value === 'object' && value !== null ) {
27
- // Prefer Symbol.toStringTag since it is immune to minification.
28
- const className = constructor . prototype [ Symbol . toStringTag ] ;
29
- const valueClassName =
30
- // We still need to support constructor's name to detect conflicts with older versions of this library.
31
- Symbol . toStringTag in value
32
- ? value [ Symbol . toStringTag ]
33
- : value . constructor ?. name ;
34
- if ( className === valueClassName ) {
35
- const stringifiedValue = inspect ( value ) ;
36
- throw new Error (
37
- `Cannot use ${ className } "${ stringifiedValue } " from another module or realm.
5
+ export function instanceOf ( value : unknown , constructor : Constructor ) : boolean {
6
+ if ( isProduction ( ) ) {
7
+ return value instanceof constructor ;
8
+ }
9
+
10
+ if ( value instanceof constructor ) {
11
+ return true ;
12
+ }
13
+
14
+ if ( typeof value === 'object' && value !== null ) {
15
+ // Prefer Symbol.toStringTag since it is immune to minification.
16
+ const className = constructor . prototype [ Symbol . toStringTag ] ;
17
+ const valueClassName =
18
+ // We still need to support constructor's name to detect conflicts with older versions of this library.
19
+ Symbol . toStringTag in value
20
+ ? value [ Symbol . toStringTag ]
21
+ : value . constructor ?. name ;
22
+ if ( className === valueClassName ) {
23
+ const stringifiedValue = inspect ( value ) ;
24
+ throw new Error (
25
+ `Cannot use ${ className } "${ stringifiedValue } " from another module or realm.
38
26
39
27
Ensure that there is only one instance of "graphql" in the node_modules
40
28
directory. If different versions of "graphql" are the dependencies of other
@@ -46,11 +34,11 @@ Duplicate "graphql" modules cannot be used at the same time since different
46
34
versions may have different capabilities and behavior. The data from one
47
35
version used in the function from another could produce confusing and
48
36
spurious results.` ,
49
- ) ;
50
- }
51
- }
52
- return false ;
53
- } ;
37
+ ) ;
38
+ }
39
+ }
40
+ return false ;
41
+ }
54
42
55
43
interface Constructor {
56
44
prototype : {
0 commit comments