-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce checkDEV() called by every entry point that uses __DEV__.
- Loading branch information
Showing
19 changed files
with
108 additions
and
27 deletions.
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(); | ||
|
||
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
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