Skip to content

Commit cdd17a6

Browse files
excitement-engineerfson
authored andcommitted
Crash the build during CI whenever linter warnings are encountered (#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 9ce0aa5 commit cdd17a6

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
@@ -810,7 +810,11 @@ Note that tests run much slower with coverage so it is recommended to run it sep
810810
811811
### Continuous Integration
812812
813-
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:
813+
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`.
814+
815+
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.
816+
817+
Popular CI servers already set the environment variable `CI` by default but you can do this yourself too:
814818
815819
### On CI servers
816820
#### Travis CI
@@ -827,6 +831,7 @@ cache:
827831
- node_modules
828832
script:
829833
- npm test
834+
- npm run build
830835
```
831836
1. Trigger your first build with a git push.
832837
1. [Customize your Travis CI Build](https://docs.travis-ci.com/user/customizing-the-build/) if needed.
@@ -838,6 +843,10 @@ script:
838843
set CI=true&&npm test
839844
```
840845
846+
```cmd
847+
set CI=true&&npm run build
848+
```
849+
841850
(Note: the lack of whitespace is intentional.)
842851
843852
##### Linux, OS X (Bash)
@@ -846,9 +855,15 @@ set CI=true&&npm test
846855
CI=true npm test
847856
```
848857
849-
This way Jest will run tests once instead of launching the watcher.
858+
```bash
859+
CI=true npm run build
860+
```
861+
862+
The test command will force Jest to run tests once instead of launching the watcher.
863+
864+
> 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.
850865
851-
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.
866+
The build command will check for linter warnings and fail if any are found.
852867
853868
### Disabling jsdom
854869

0 commit comments

Comments
 (0)