Skip to content

Commit

Permalink
Add scripts/update_deps to set the correct webpack version in peerDep…
Browse files Browse the repository at this point in the history
…endencies (Silences warnings from NPM.) Bump version
  • Loading branch information
ndbroadbent committed Oct 9, 2019
1 parent 25c1eeb commit 954f174
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ Before submitting a pull request, please check the following:
- `yarn format`
- If you use VS Code, you should enable the `formatOnSave` option.
- Using the correct webpack version
- `./scripts/update_deps`
- `yarn update_deps`
- NOTE: The `webpack` peerDependency is only needed to silence some annoying warnings from NPM.

## License

Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "craco-less",
"version": "1.14.1",
"version": "1.14.2",
"description": "A Less plugin for craco / react-scripts / create-react-app",
"main": "lib/craco-less.js",
"scripts": {
"test": "jest",
"lint": "eslint --fix lib",
"format": "prettier --write **/*.js"
"format": "prettier --write **/*.js",
"update_deps": "node scripts/update_deps"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -37,11 +38,13 @@
},
"dependencies": {
"less": "3.10.3",
"less-loader": "^5.0.0"
"less-loader": "^5.0.0",
"webpack": "4.41.0"
},
"peerDependencies": {
"@craco/craco": "^5.5.0",
"react-scripts": "^3.2.0"
"react-scripts": "^3.2.0",
"webpack": "4.41.0"
},
"husky": {
"hooks": {
Expand Down
36 changes: 36 additions & 0 deletions scripts/update_deps
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" });

0 comments on commit 954f174

Please sign in to comment.