Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit 4ff79f1

Browse files
committed
fix: improve react-scripts version detection
1 parent f06d07d commit 4ff79f1

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ If those defaults do not work for you, the script accepts some arguments:
8282

8383
* `-b|--build-path`: expects either an absolute or relative path. If a relative path is given it will be prefixed by your project root path.
8484
* default: `yourProjectRoot/build`.
85-
* `--react-scripts-version`: expects the `react-scripts` version you are using in your project i.e `2.0.3`. If not given it will be implied from your package.json and if it cannot be implied the version `2.0.4` will be the default. Consider setting it if you ejected.
85+
* `--react-scripts-version`: expects the `react-scripts` version you are using in your project i.e `2.0.3`. If not given it will be implied from your `node_modules` and if it cannot be implied the version `2.0.4` will be the default. Consider setting it if you ejected.
8686
* `-p|--public-path`: expects a relative URL where `/` is the root. If you serve your files using an external webserver this argument is to match with your web server configuration. More information can be found in [webpack configuration guide](https://webpack.js.org/configuration/output/#output-publicpath).
8787
* default: "".
8888
* `-v|--verbose`: display webpack build output.

utils/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const DEFAULT_VERSION = {
1111
patch: 4,
1212
};
1313

14-
exports.isEjected = fs.pathExistsSync(path.join(process.cwd(), 'config/paths.js'))
14+
exports.isEjected = fs.pathExistsSync(path.join(process.cwd(), 'config/paths.js'));
1515

1616
exports.getReactScriptsVersion = function getReactScriptsVersion(cliVersion) {
1717
if (cliVersion) {
@@ -23,16 +23,16 @@ exports.getReactScriptsVersion = function getReactScriptsVersion(cliVersion) {
2323
return versions;
2424
}
2525

26-
const packageJson = importCwd.silent('./package.json');
27-
if (!packageJson || !packageJson.dependencies['react-scripts']) {
26+
const reactScriptsPkg = importCwd.silent('react-scripts/package.json');
27+
if (!reactScriptsPkg || !reactScriptsPkg.version) {
2828
return DEFAULT_VERSION;
2929
}
3030

31-
const { dependencies } = packageJson;
31+
const { version } = reactScriptsPkg;
3232
const versions = {
33-
major: Number(semver.major(dependencies['react-scripts'])),
34-
minor: Number(semver.minor(dependencies['react-scripts'])),
35-
patch: Number(semver.patch(dependencies['react-scripts'])),
33+
major: Number(semver.major(version)),
34+
minor: Number(semver.minor(version)),
35+
patch: Number(semver.patch(version)),
3636
};
3737
return versions;
3838
};

0 commit comments

Comments
 (0)