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' ;
5
+ export function instanceOf ( value : unknown , constructor : Constructor ) : boolean {
6
+ if ( isProduction ( ) ) {
7
+ return value instanceof constructor ;
8
+ }
8
9
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.
10
+ if ( value instanceof constructor ) {
11
+ return true ;
12
+ }
13
+ if ( typeof value === 'object' && value !== null ) {
14
+ // Prefer Symbol.toStringTag since it is immune to minification.
15
+ const className = constructor . prototype [ Symbol . toStringTag ] ;
16
+ const valueClassName =
17
+ // We still need to support constructor's name to detect conflicts with older versions of this library.
18
+ Symbol . toStringTag in value
19
+ ? value [ Symbol . toStringTag ]
20
+ : value . constructor ?. name ;
21
+ if ( className === valueClassName ) {
22
+ const stringifiedValue = inspect ( value ) ;
23
+ throw new Error (
24
+ `Cannot use ${ className } "${ stringifiedValue } " from another module or realm.
38
25
39
26
Ensure that there is only one instance of "graphql" in the node_modules
40
27
directory. If different versions of "graphql" are the dependencies of other
@@ -46,11 +33,11 @@ Duplicate "graphql" modules cannot be used at the same time since different
46
33
versions may have different capabilities and behavior. The data from one
47
34
version used in the function from another could produce confusing and
48
35
spurious results.` ,
49
- ) ;
50
- }
51
- }
52
- return false ;
53
- } ;
36
+ ) ;
37
+ }
38
+ }
39
+ return false ;
40
+ }
54
41
55
42
interface Constructor {
56
43
prototype : {
0 commit comments