Skip to content

Commit 6421127

Browse files
excitement-engineeralexdriaguine
authored andcommitted
Crash the build during CI whenever linter warnings are encountered (facebook#944)
* Added functionality to crash the build during CI whenever linter warnings are encountered. * Updated the docs with a description on how to use the build in CI * Fixed small typo * Fixed description of build error.
1 parent ed583fc commit 6421127

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

packages/react-scripts/scripts/build.js

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ function build(previousSizeMap) {
144144
process.exit(1);
145145
}
146146

147+
if (process.env.CI && stats.compilation.warnings.length) {
148+
printErrors('Failed to compile.', stats.compilation.warnings);
149+
process.exit(1);
150+
}
151+
147152
console.log(chalk.green('Compiled successfully.'));
148153
console.log();
149154

packages/react-scripts/template/README.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,11 @@ Note that tests run much slower with coverage so it is recommended to run it sep
815815
816816
### Continuous Integration
817817
818-
By default `npm test` runs the watcher with interactive CLI. However, you can force it to run tests once and finish the process by setting an environment variable called `CI`. Popular CI servers already set it by default but you can do this yourself too:
818+
By default `npm test` runs the watcher with interactive CLI. However, you can force it to run tests once and finish the process by setting an environment variable called `CI`.
819+
820+
When creating a build of your application with `npm run build` linter warnings are not checked by default. Like `npm test`, you can force the build to perform a linter warning check by setting the environment variable `CI`. If any warnings are encountered then the build fails.
821+
822+
Popular CI servers already set the environment variable `CI` by default but you can do this yourself too:
819823
820824
### On CI servers
821825
#### Travis CI
@@ -832,6 +836,7 @@ cache:
832836
- node_modules
833837
script:
834838
- npm test
839+
- npm run build
835840
```
836841
1. Trigger your first build with a git push.
837842
1. [Customize your Travis CI Build](https://docs.travis-ci.com/user/customizing-the-build/) if needed.
@@ -843,6 +848,10 @@ script:
843848
set CI=true&&npm test
844849
```
845850
851+
```cmd
852+
set CI=true&&npm run build
853+
```
854+
846855
(Note: the lack of whitespace is intentional.)
847856
848857
##### Linux, OS X (Bash)
@@ -851,9 +860,15 @@ set CI=true&&npm test
851860
CI=true npm test
852861
```
853862
854-
This way Jest will run tests once instead of launching the watcher.
863+
```bash
864+
CI=true npm run build
865+
```
866+
867+
The test command will force Jest to run tests once instead of launching the watcher.
868+
869+
> If you find yourself doing this often in development, please [file an issue](https://github.com/facebookincubator/create-react-app/issues/new) to tell us about your use case because we want to make watcher the best experience and are open to changing how it works to accommodate more workflows.
855870
856-
If you find yourself doing this often in development, please [file an issue](https://github.com/facebookincubator/create-react-app/issues/new) to tell us about your use case because we want to make watcher the best experience and are open to changing how it works to accommodate more workflows.
871+
The build command will check for linter warnings and fail if any are found.
857872
858873
### Disabling jsdom
859874

0 commit comments

Comments
 (0)