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

Commit cb78244

Browse files
authored
Merge pull request #25 from Nargonath/develop
v1.4.0
2 parents a1d0e24 + 53ef9d9 commit cb78244

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
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.1.2` will be the default. Consider setting it if you **ejected** and are not using the latest `react-scripts` version.
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.

scripts/index.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@ const {
1111
flags: { buildPath, publicPath, reactScriptsVersion, verbose },
1212
} = require('../utils/cliHandler');
1313
const { getReactScriptsVersion, isEjected } = require('../utils');
14+
15+
const { major, minor, patch } = getReactScriptsVersion(reactScriptsVersion);
16+
1417
const paths = isEjected ? importCwd('./config/paths') : importCwd('react-scripts/config/paths');
1518
const webpack = importCwd('webpack');
16-
const config = isEjected
17-
? importCwd('./config/webpack.config.dev')
18-
: importCwd('react-scripts/config/webpack.config.dev');
19+
20+
const config =
21+
major >= 2 && minor >= 1 && patch >= 2
22+
? (isEjected
23+
? importCwd('./config/webpack.config')
24+
: importCwd('react-scripts/config/webpack.config'))('development')
25+
: isEjected
26+
? importCwd('./config/webpack.config.dev')
27+
: importCwd('react-scripts/config/webpack.config.dev');
28+
1929
const HtmlWebpackPlugin = importCwd('html-webpack-plugin');
2030
const InterpolateHtmlPlugin = importCwd('react-dev-utils/InterpolateHtmlPlugin');
2131
const getClientEnvironment = isEjected
@@ -50,10 +60,17 @@ config.output.filename = `js/bundle.js`;
5060
config.output.chunkFilename = `js/[name].chunk.js`;
5161

5262
// update media path destination
53-
const { major, minor, patch } = getReactScriptsVersion(reactScriptsVersion);
54-
5563
if (major >= 2) {
56-
const oneOfIndex = minor >= 1 || patch >= 4 ? 2 : 3;
64+
// 2.0.0 => 2
65+
// 2.0.1 => 3
66+
// 2.0.2 => 3
67+
// 2.0.3 => 3
68+
// 2.0.4 => 2
69+
// 2.1.0 => 2
70+
// 2.1.1 => 2
71+
// 2.1.2 => 2
72+
// 2.1.3 => 2
73+
const oneOfIndex = minor === 0 && patch < 4 && patch >= 1 ? 3 : 2;
5774
config.module.rules[oneOfIndex].oneOf[0].options.name = `media/[name].[hash:8].[ext]`;
5875
config.module.rules[oneOfIndex].oneOf[7].options.name = `media/[name].[hash:8].[ext]`;
5976
} else {

utils/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const path = require('path');
77

88
const DEFAULT_VERSION = {
99
major: 2,
10-
minor: 0,
11-
patch: 4,
10+
minor: 1,
11+
patch: 2,
1212
};
1313

14-
exports.isEjected = fs.pathExistsSync(path.join(process.cwd(), 'config/webpack.config.dev.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)