-
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.
Merge branch 'issue-8674-enforce-__DEV__-everywhere' into release-3.5.
This merge of the still-open PR #8689 into `release-3.5` will allow us to test those changes in an `@apollo/client@beta` release before merging to `main` and releasing in v3.4.x.
- Loading branch information
Showing
33 changed files
with
308 additions
and
194 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.