Skip to content

Commit 72f8e8a

Browse files
committed
change check to globals.__DEV__ !== false
1 parent 3567c97 commit 72f8e8a

File tree

5 files changed

+24
-52
lines changed

5 files changed

+24
-52
lines changed

config/jest.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const defaults = {
33
preset: "ts-jest",
44
testEnvironment: "jsdom",
55
setupFilesAfterEnv: ["<rootDir>/config/jest/setup.ts"],
6+
globals: {
7+
__DEV__: undefined,
8+
},
69
testEnvironmentOptions: {
710
url: "http://localhost",
811
},

config/postprocessDist.ts

-22
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,6 @@ eachFile(distDir, (file, relPath) => new Promise((resolve, reject) => {
2525
const tr = new Transformer;
2626
const output = tr.transform(source, file);
2727

28-
if (
29-
/\b__DEV__\b/.test(source) &&
30-
// Ignore modules that reside within @apollo/client/utilities/globals.
31-
relPath.split(path.sep, 2).join("/") !== "utilities/globals"
32-
) {
33-
let importsUtilitiesGlobals = false;
34-
35-
tr.absolutePaths.forEach(absPath => {
36-
const distRelativePath =
37-
path.relative(distDir, absPath).split(path.sep).join("/");
38-
if (distRelativePath === "utilities/globals/index.js") {
39-
importsUtilitiesGlobals = true;
40-
}
41-
});
42-
43-
if (!importsUtilitiesGlobals) {
44-
reject(new Error(`Module ${
45-
relPath
46-
} uses __DEV__ but does not import @apollo/client/utilities/globals`));
47-
}
48-
}
49-
5028
if (source === output) {
5129
resolve(file);
5230
} else {

config/processInvariants.ts

+18-13
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,25 @@ function transform(code: string, relativeFilePath: string) {
190190
},
191191
});
192192

193-
recast.visit(ast, {
194-
visitIdentifier(path) {
195-
this.traverse(path);
196-
const node = path.node;
197-
if (isDEVExpr(node)) {
198-
return b.memberExpression(
199-
b.identifier('globalThis'),
200-
b.identifier('__DEV__')
201-
);
202-
}
193+
if (relativeFilePath !== 'config/jest/setup.js')
194+
recast.visit(ast, {
195+
visitIdentifier(path) {
196+
this.traverse(path);
197+
const node = path.node;
198+
if (isDEVExpr(node)) {
199+
return b.binaryExpression(
200+
'!==',
201+
b.memberExpression(
202+
b.identifier('globalThis'),
203+
b.identifier('__DEV__')
204+
),
205+
b.literal(false)
206+
);
207+
}
203208

204-
return node;
205-
},
206-
});
209+
return node;
210+
},
211+
});
207212

208213
return reprint(ast);
209214
}

src/utilities/globals/DEV.ts

-6
This file was deleted.

src/utilities/globals/index.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { invariant, newInvariantError, InvariantError } from "./invariantWrappers";
22

3-
// Just in case the graphql package switches from process.env.NODE_ENV to
4-
// __DEV__, make sure __DEV__ is polyfilled before importing graphql.
5-
import DEV from "./DEV";
6-
export { DEV }
7-
export function checkDEV() {
8-
invariant("boolean" === typeof DEV, "%s", DEV);
9-
}
10-
3+
export function checkDEV(){}
114
// Import graphql/jsutils/instanceOf safely, working around its unchecked usage
125
// of process.env.NODE_ENV and https://github.com/graphql/graphql-js/pull/2894.
136
import { removeTemporaryGlobals } from "./fix-graphql";
@@ -20,6 +13,5 @@ export { maybe } from "./maybe";
2013
export { default as global } from "./global";
2114
export { invariant, newInvariantError, InvariantError }
2215

23-
// Ensure __DEV__ was properly initialized, and prevent tree-shaking bundlers
24-
// from mistakenly pruning the ./DEV module (see issue #8674).
25-
checkDEV();
16+
// @ts-ignore
17+
export const DEV = __DEV__;

0 commit comments

Comments
 (0)