-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts/update_deps to set the correct webpack version in peerDep…
…endencies (Silences warnings from NPM.) Bump version
- Loading branch information
1 parent
25c1eeb
commit 954f174
Showing
3 changed files
with
45 additions
and
5 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
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,36 @@ | ||
#!/usr/bin/env node | ||
|
||
// Use the same webpack version as react-scripts. | ||
// This gets rid of the "unmet peer dependency" warning. | ||
|
||
// Related issues: | ||
// * https://github.com/FormAPI/craco-less/issues/3 | ||
// * https://github.com/FormAPI/craco-less/issues/4 | ||
// * https://stackoverflow.com/questions/53681694/how-can-i-resolve-the-webpack-unmet-peer-dependency-warning-for-my-create-reac | ||
// * https://github.com/yarnpkg/yarn/issues/4850#issuecomment-447277140 | ||
|
||
const fs = require("fs"); | ||
const { spawnSync } = require("child_process"); | ||
|
||
const reactScriptsPackageJSON = JSON.parse( | ||
fs.readFileSync("node_modules/react-scripts/package.json") | ||
); | ||
const webpackVersion = reactScriptsPackageJSON["dependencies"]["webpack"]; | ||
if (!webpackVersion) { | ||
throw new Error("Could not find webpack dependency for react-scripts!"); | ||
} | ||
|
||
const cracoLessPackageJSON = JSON.parse(fs.readFileSync("package.json")); | ||
if (cracoLessPackageJSON["dependencies"]["webpack"] == webpackVersion) { | ||
console.log(`Webpack dependency is already up-to-date (${webpackVersion})`); | ||
process.exit(); | ||
} | ||
|
||
console.log(`Updating webpack dependency to: ${webpackVersion}`); | ||
cracoLessPackageJSON["dependencies"]["webpack"] = webpackVersion; | ||
fs.writeFileSync( | ||
"package.json", | ||
JSON.stringify(cracoLessPackageJSON, null, 2) + "\n" | ||
); | ||
|
||
spawnSync("yarn", ["install"], { stdio: "inherit" }); |