-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforce that __DEV__
is polyfilled in every entry point that uses it
#8689
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
623fab5
Fix #8674 by polyfilling __DEV__ upon @apollo/client/link/http import.
benjamn b435c0b
Make every @apollo/client/* entry point using __DEV__ call checkDEV().
benjamn e1f01bf
Enforce checkDEV() called by every entry point that uses __DEV__.
benjamn 99fa6a0
Mention PR #8689 in CHANGELOG.md.
benjamn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as path from "path"; | ||
import { readFileSync, promises as fs } from "fs"; | ||
import { eachFile, distDir } from "./helpers"; | ||
|
||
const entryPoints = require("./entryPoints.js"); | ||
|
||
const filesWithDEV = new Set<string>(); | ||
|
||
eachFile(distDir, async file => { | ||
const source = await fs.readFile(file, "utf8"); | ||
if (/\b__DEV__\b/.test(source)) { | ||
filesWithDEV.add(file); | ||
} | ||
}).then(() => { | ||
const filesByEntryPoint = new Map<string, { | ||
indexPath: string; | ||
source: string; | ||
files: Set<string>; | ||
}>(); | ||
|
||
entryPoints.forEach(({ dirs }: { dirs: string[] }) => { | ||
const relIndexPath = path.join(...dirs, "index.js"); | ||
const absIndexPath = path.join(distDir, relIndexPath); | ||
filesByEntryPoint.set(dirs.join("/"), { | ||
indexPath: relIndexPath, | ||
source: readFileSync(absIndexPath, "utf8"), | ||
files: new Set<string>(), | ||
}); | ||
}); | ||
|
||
filesWithDEV.forEach(file => { | ||
const entryPointDir = entryPoints.getEntryPointDirectory(file); | ||
const info = filesByEntryPoint.get(entryPointDir); | ||
const absEntryPointDir = path.join(distDir, entryPointDir); | ||
const relPath = "./" + path.relative(absEntryPointDir, file); | ||
if (info) { | ||
info.files.add(relPath); | ||
} | ||
}); | ||
|
||
filesByEntryPoint.forEach(({ indexPath, source, files }, entryPointDir) => { | ||
if (!files.size || source.indexOf("checkDEV()") >= 0) { | ||
return; | ||
} | ||
const entryPointId = `@apollo/client/${entryPointDir}`; | ||
throw new Error(`Entry point ${ | ||
entryPointId | ||
}/index.js does not call checkDEV(), but ${ | ||
entryPointId | ||
} contains the following files that use __DEV__: ${ | ||
Array.from(files).join(", ") | ||
}`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { checkDEV } from "../../utilities"; | ||
checkDEV(); | ||
|
||
export { | ||
parseAndCheckHttpResponse, | ||
ServerParseError | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { checkDEV } from "../../utilities"; | ||
checkDEV(); | ||
|
||
import { print } from 'graphql'; | ||
import { | ||
DocumentNode, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { checkDEV } from "../../utilities"; | ||
checkDEV(); | ||
|
||
export * from './ApolloConsumer'; | ||
export * from './ApolloContext'; | ||
export * from './ApolloProvider'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { checkDEV } from "../../utilities"; | ||
checkDEV(); | ||
|
||
import { | ||
DocumentNode, | ||
DefinitionNode, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { invariant } from "ts-invariant"; | ||
import { DEV } from "../utilities"; | ||
invariant("boolean" === typeof DEV, DEV); | ||
import { checkDEV } from "../utilities"; | ||
checkDEV(); | ||
|
||
export * from '../utilities/testing'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { invariant } from "ts-invariant"; | ||
|
||
// Just in case the graphql package switches from process.env.NODE_ENV to | ||
// __DEV__, make sure __DEV__ is polyfilled before importing graphql. | ||
import DEV from "./DEV"; | ||
export { DEV } | ||
export function checkDEV() { | ||
invariant("boolean" === typeof DEV, DEV); | ||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
} | ||
|
||
// Import graphql/jsutils/instanceOf safely, working around its unchecked usage | ||
// of process.env.NODE_ENV and https://github.com/graphql/graphql-js/pull/2894. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out a number of entry points that weren't obviously using
__DEV__
actually do need it, because they useinvariant
orInvariantError
, which we transform to an expression containing__DEV__
to enable stripping long error messages in production.