diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..405acc968 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,165 @@ + + +### Is this a bug report? + +(write your answer here) + + + + +### Can you also reproduce the problem with npm 4.x? + + + +(Write your answer here.) + + +### Which terms did you search for in User Guide? + + + +(Write your answer here if relevant.) + + +### Environment + + + +1. `npm ls react-scripts-ts` (if you haven’t ejected): +2. `node -v`: +3. `npm -v`: +4. `yarn --version` (if you use Yarn): +<<<<<<< HEAD +5. `npm ls react-scripts` (if you haven’t ejected): +======= +3. `npm ls react-scripts-ts` (if you haven’t ejected): +>>>>>>> Fix Code Review + +Then, specify: + +1. Operating system: +2. Browser and version (if relevant): + + +### Steps to Reproduce + + + +(Write your steps here:) + +1. +2. +3. + + +### Expected Behavior + + + +(Write what you thought would happen.) + + +### Actual Behavior + + + +(Write what happened. Please add screenshots!) + + +### Reproducible Demo + + + +(Paste the link to an example project and exact instructions to reproduce the issue.) + + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..45268d0b6 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,7 @@ + diff --git a/.travis.yml b/.travis.yml index 6b973ae44..0bee9a16b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: node_js node_js: - 6 - - 7 + - 8 cache: directories: - node_modules diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cbeed3a4..0e2c349eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,311 @@ +## 1.0.10 (June 29, 2017) + +#### :bug: Bug Fix + +* `react-dev-utils` + + * [#2692](https://github.com/facebookincubator/create-react-app/pull/2692) Fix IE11 crash in development. ([@pdhoopr](https://github.com/pdhoopr)) + +* `create-react-app` + * [#2683](https://github.com/facebookincubator/create-react-app/pull/2683) Fix a typo. ([@BenBrostoff](https://github.com/BenBrostoff)) + +#### :memo: Documentation + +* README + + * [#2402](https://github.com/facebookincubator/create-react-app/pull/2402) Added `gluestick` to the alternatives section. ([@JoeCortopassi](https://github.com/JoeCortopassi)) + +#### Committers: 5 +- Ben Brostoff ([BenBrostoff](https://github.com/BenBrostoff)) +- Forbes Lindesay ([ForbesLindesay](https://github.com/ForbesLindesay)) +- Joe Haddad ([Timer](https://github.com/Timer)) +- Patrick Hooper ([pdhoopr](https://github.com/pdhoopr)) +- [JoeCortopassi](https://github.com/JoeCortopassi) + +### Migrating from 1.0.9 to 1.0.10 + +Inside any created project that has not been ejected, run: + +``` +npm install --save --save-exact react-scripts@1.0.10 +``` + +or + +``` +yarn add --exact react-scripts@1.0.10 +``` + +## 1.0.9 (June 29, 2017) + +#### :bug: Bug Fix + +* `react-scripts` + + * [#2680](https://github.com/facebookincubator/create-react-app/pull/2680) Fix external CSS imports. ([@gaearon](https://github.com/gaearon)) + +#### :memo: Documentation + +* `react-scripts` + + * [#2679](https://github.com/facebookincubator/create-react-app/pull/2679) Fix minor typo. ([@dbanck](https://github.com/dbanck)) + * [#2666](https://github.com/facebookincubator/create-react-app/pull/2666) Add more info about Apache client side routing. ([@viankakrisna](https://github.com/viankakrisna)) + * [#2671](https://github.com/facebookincubator/create-react-app/pull/2671) Add JSON and CSS to Prettier instructions. ([@jbovenschen](https://github.com/jbovenschen)) + +#### :house: Internal + +* Other + + * [#2673](https://github.com/facebookincubator/create-react-app/pull/2673) Bootstrap with Yarn. ([@Timer](https://github.com/Timer)) + * [#2659](https://github.com/facebookincubator/create-react-app/pull/2659) Test Node 8 on Travis. ([@gaearon](https://github.com/gaearon)) + +#### Committers: 5 + +- Ade Viankakrisna Fadlil ([viankakrisna](https://github.com/viankakrisna)) +- Dan Abramov ([gaearon](https://github.com/gaearon)) +- Daniel Banck ([dbanck](https://github.com/dbanck)) +- Jaco Bovenschen ([jbovenschen](https://github.com/jbovenschen)) +- Joe Haddad ([Timer](https://github.com/Timer)) + +### Migrating from 1.0.8 to 1.0.9 + +Inside any created project that has not been ejected, run: + +``` +npm install --save --save-exact react-scripts@1.0.9 +``` + +or + +``` +yarn add --exact react-scripts@1.0.9 +``` + +## 1.0.8 (June 28, 2017) + +#### :bug: Bug Fix +* `react-scripts` + + * [#2550](https://github.com/facebookincubator/create-react-app/pull/2550) Fix Node 8 compatibility. ([@josephfrazier](https://github.com/josephfrazier)) + * [#2610](https://github.com/facebookincubator/create-react-app/pull/2610) Fix sourcemap directory organization on Windows. ([@plusCubed](https://github.com/plusCubed)) + * [#2596](https://github.com/facebookincubator/create-react-app/pull/2596) Fix an issue with minifying emojis. ([@viankakrisna](https://github.com/viankakrisna)) + * [#2501](https://github.com/facebookincubator/create-react-app/pull/2501) Fix incorrect check if `CI` variable is set to true. ([@varnav](https://github.com/varnav)) + * [#2432](https://github.com/facebookincubator/create-react-app/pull/2432) In new projects, don't register service worker for projects using `PUBLIC_URL` for CDN. ([@jeffposnick](https://github.com/jeffposnick)) + * [#2470](https://github.com/facebookincubator/create-react-app/pull/2470) In new projects, prioritize `index.css` over `App.css`. ([@bryankang](https://github.com/bryankang)) + +* `react-dev-utils` + + * [#2405](https://github.com/facebookincubator/create-react-app/pull/2405) Fix detection of parent directory in `ModuleScopePlugin`. ([@diligiant](https://github.com/diligiant)) + * [#2562](https://github.com/facebookincubator/create-react-app/pull/2562) Fix eject command output. ([@paweljedrzejczyk](https://github.com/paweljedrzejczyk)) + +#### :nail_care: Enhancement + +* `react-scripts` + + * [#2648](https://github.com/facebookincubator/create-react-app/pull/2648) Warn about large bundle sizes. ([@gaearon](https://github.com/gaearon)) + * [#2511](https://github.com/facebookincubator/create-react-app/pull/2511) Support `.web.js` extension for React Native Web. ([@mini-eggs](https://github.com/mini-eggs)) + * [#2645](https://github.com/facebookincubator/create-react-app/pull/2645) Hide confusing "Skipping static resource" message. ([@gaearon](https://github.com/gaearon)) + * [#2389](https://github.com/facebookincubator/create-react-app/pull/2389) Silence unnecessary warning from Babel. ([@gaearon](https://github.com/gaearon)) + * [#2429](https://github.com/facebookincubator/create-react-app/pull/2429) Update `sw-precache-webpack-plugin` to lastest version. ([@goldhand](https://github.com/goldhand)) + * [#2600](https://github.com/facebookincubator/create-react-app/pull/2600) Add empty mock for `dgram` Node module. ([@micopiira](https://github.com/micopiira)) + * [#2458](https://github.com/facebookincubator/create-react-app/pull/2458) Add names to module factories in development. ([@Zaccc123](https://github.com/Zaccc123)) + * [#2551](https://github.com/facebookincubator/create-react-app/pull/2551) In new projects, unregister service worker and force reload if `service-worker.js` is not found. ([@ro-savage](https://github.com/ro-savage)) + +* `babel-preset-react-app`, `react-dev-utils`, `react-scripts` + + * [#2658](https://github.com/facebookincubator/create-react-app/pull/2658) Bump dependencies. ([@gaearon](https://github.com/gaearon)) + +* `create-react-app`, `react-scripts` + + * [#2657](https://github.com/facebookincubator/create-react-app/pull/2657) Put `react-scripts` in `dependencies`, not `devDependencies`. ([@gaearon](https://github.com/gaearon)) + * [#2635](https://github.com/facebookincubator/create-react-app/pull/2635) Silence unhelpful npm warnings. ([@gaearon](https://github.com/gaearon)) + +* `react-dev-utils` + + * [#2637](https://github.com/facebookincubator/create-react-app/pull/2637) Auto-detect Brackets editor from error overlay. ([@petetnt](https://github.com/petetnt)) + * [#2552](https://github.com/facebookincubator/create-react-app/pull/2552) Auto-detect running editor on Windows for error overlay. ([@levrik](https://github.com/levrik)) + * [#2622](https://github.com/facebookincubator/create-react-app/pull/2622) Support opening PhpStorm for error overlay. ([@miraage](https://github.com/miraage)) + * [#2414](https://github.com/facebookincubator/create-react-app/pull/2414) Support opening WebStorm 2017+ from error overlay. ([@wirmar](https://github.com/wirmar)) + * [#2518](https://github.com/facebookincubator/create-react-app/pull/2518) Warn when trying to run on port below 1024 without admin permissions under Linux/macOS. ([@levrik](https://github.com/levrik)) + * [#2385](https://github.com/facebookincubator/create-react-app/pull/2385) Suggest just `yarn build` in output. ([@gaearon](https://github.com/gaearon)) + +* `create-react-app` + + * [#1945](https://github.com/facebookincubator/create-react-app/pull/1945) Fix grammar in CLI output. ([@ColinEberhardt](https://github.com/ColinEberhardt)) + +#### :memo: Documentation + +* User Guide + + * [#2662](https://github.com/facebookincubator/create-react-app/pull/2662) Local testing docker links. ([@EnoahNetzach](https://github.com/EnoahNetzach)) + * [#2660](https://github.com/facebookincubator/create-react-app/pull/2660) Minor code style edits to user guide. ([@gaearon](https://github.com/gaearon)) + * [#2656](https://github.com/facebookincubator/create-react-app/pull/2656) Don't ask to install webpack for using Styleguidist. ([@gaearon](https://github.com/gaearon)) + * [#1641](https://github.com/facebookincubator/create-react-app/pull/1641) Add instructions to use `source-map-explorer`. ([@gr33nfury](https://github.com/gr33nfury)) + * [#2044](https://github.com/facebookincubator/create-react-app/pull/2044) Add React Styleguidist. ([@sapegin](https://github.com/sapegin)) + * [#2006](https://github.com/facebookincubator/create-react-app/pull/2006) Added instruction on how to install Prettier. ([@MrHus](https://github.com/MrHus)) + * [#1813](https://github.com/facebookincubator/create-react-app/pull/1813) Fix grammar. ([@iheng](https://github.com/iheng)) + * [#2060](https://github.com/facebookincubator/create-react-app/pull/2060) Add more info about OOM build failiure [docs]. ([@GAumala](https://github.com/GAumala)) + * [#2305](https://github.com/facebookincubator/create-react-app/pull/2305) Update docs with WebSocket proxy information. ([@jamesblight](https://github.com/jamesblight)) + * [#2445](https://github.com/facebookincubator/create-react-app/pull/2445) Document `REACT_EDITOR` environment variable. ([@wirmar](https://github.com/wirmar)) + * [#2362](https://github.com/facebookincubator/create-react-app/pull/2362) Add yarn example under "Installing a Dependency". ([@BrianDGLS](https://github.com/BrianDGLS)) + * [#2423](https://github.com/facebookincubator/create-react-app/pull/2423) Add docs for setting up CircleCI for CRA. ([@knowbody](https://github.com/knowbody)) + * [#2427](https://github.com/facebookincubator/create-react-app/pull/2427) Added link to tutorial on code splitting. ([@jayair](https://github.com/jayair)) + * [#2447](https://github.com/facebookincubator/create-react-app/pull/2447) Fix wrong comment on Proxy guide. ([@hellowin](https://github.com/hellowin)) + * [#2538](https://github.com/facebookincubator/create-react-app/pull/2538) Fix broken link to a tutorial. ([@romanyanke](https://github.com/romanyanke)) + * [#2522](https://github.com/facebookincubator/create-react-app/pull/2522) Flow init to run as command not flag. ([@khanglu](https://github.com/khanglu)) + * [#2521](https://github.com/facebookincubator/create-react-app/pull/2521) Fix broken link to Storybook docs. ([@shilman](https://github.com/shilman)) + * [#2500](https://github.com/facebookincubator/create-react-app/pull/2500) Fix minor typo. ([@AlexxNica](https://github.com/AlexxNica)) + * [#2331](https://github.com/facebookincubator/create-react-app/pull/2331) Re-add storybook && update the documentation and links. ([@ndelangen](https://github.com/ndelangen)) + * [#2454](https://github.com/facebookincubator/create-react-app/pull/2454) Update Travis CI Node versions in User Guide. ([@ryansully](https://github.com/ryansully)) + * [#2420](https://github.com/facebookincubator/create-react-app/pull/2420) Fix typo. ([@ruskakimov](https://github.com/ruskakimov)) + * [#2392](https://github.com/facebookincubator/create-react-app/pull/2392) Update `jest-enzyme` section. ([@luftywiranda13](https://github.com/luftywiranda13)) + +* README + + * [#2517](https://github.com/facebookincubator/create-react-app/pull/2517) Add Razzle to the alternatives. ([@kireerik](https://github.com/kireerik)) + * [#1931](https://github.com/facebookincubator/create-react-app/pull/1931) Updated README. ([@shaunwallace](https://github.com/shaunwallace)) + * [#2492](https://github.com/facebookincubator/create-react-app/pull/2492) Update webpack links to point to webpack 2. ([@laruiss](https://github.com/laruiss)) + +#### :house: Internal + +* Other + + * [#2465](https://github.com/facebookincubator/create-react-app/pull/2465) Update Prettier to v1. ([@ianschmitz](https://github.com/ianschmitz)) + * [#2489](https://github.com/facebookincubator/create-react-app/pull/2489) chore(templates): Move GitHub templates to hidden .github folder. ([@glennreyes](https://github.com/glennreyes)) + * [#2400](https://github.com/facebookincubator/create-react-app/pull/2400) Added cache clear to e2e scripts. ([@ro-savage](https://github.com/ro-savage)) + * [#2397](https://github.com/facebookincubator/create-react-app/pull/2397) Fix command in e2e-kitchensink.sh cleanup. ([@ro-savage](https://github.com/ro-savage)) + * [#2388](https://github.com/facebookincubator/create-react-app/pull/2388) Fix wrong path expansion in end-to-end test. ([@gaearon](https://github.com/gaearon)) + * [#2387](https://github.com/facebookincubator/create-react-app/pull/2387) Catch "No tests found" during CI. ([@EnoahNetzach](https://github.com/EnoahNetzach)) + +* `react-scripts` + + * [#2408](https://github.com/facebookincubator/create-react-app/pull/2408) E2E testing enhancements. ([@EnoahNetzach](https://github.com/EnoahNetzach)) + * [#2430](https://github.com/facebookincubator/create-react-app/pull/2430) Remove an unnecessary webpack option. ([@andykenward](https://github.com/andykenward)) + +* `react-dev-utils` + + * [#2483](https://github.com/facebookincubator/create-react-app/pull/2483) Remove a scoped package dependency. ([@Timer](https://github.com/Timer)) + +#### Committers: 46 +- Ade Viankakrisna Fadlil ([viankakrisna](https://github.com/viankakrisna)) +- Alexandre Nicastro ([AlexxNica](https://github.com/AlexxNica)) +- Andi N. Dirgantara ([hellowin](https://github.com/hellowin)) +- Andy Kenward ([andykenward](https://github.com/andykenward)) +- Artem Sapegin ([sapegin](https://github.com/sapegin)) +- Ashton ([ashtonsix](https://github.com/ashtonsix)) +- Brian Douglas ([BrianDGLS](https://github.com/BrianDGLS)) +- Colin Eberhardt ([ColinEberhardt](https://github.com/ColinEberhardt)) +- Colin Galindo ([gr33nfury](https://github.com/gr33nfury)) +- Dan Abramov ([gaearon](https://github.com/gaearon)) +- Daniel Ciao ([plusCubed](https://github.com/plusCubed)) +- Erik Engi ([kireerik](https://github.com/kireerik)) +- Evan Jones ([mini-eggs](https://github.com/mini-eggs)) +- Fabrizio Castellarin ([EnoahNetzach](https://github.com/EnoahNetzach)) +- Frédéric Miserey ([diligiant](https://github.com/diligiant)) +- Gabriel Aumala ([GAumala](https://github.com/GAumala)) +- Glenn Reyes ([glennreyes](https://github.com/glennreyes)) +- Heng Li ([iheng](https://github.com/iheng)) +- Ian Schmitz ([ianschmitz](https://github.com/ianschmitz)) +- James Blight ([jamesblight](https://github.com/jamesblight)) +- Jay V ([jayair](https://github.com/jayair)) +- Jeffrey Posnick ([jeffposnick](https://github.com/jeffposnick)) +- Joe Haddad ([Timer](https://github.com/Timer)) +- Joseph Frazier ([josephfrazier](https://github.com/josephfrazier)) +- Khang Lu ([khanglu](https://github.com/khanglu)) +- Levin Rickert ([levrik](https://github.com/levrik)) +- Lufty Wiranda ([luftywiranda13](https://github.com/luftywiranda13)) +- Maarten Hus ([MrHus](https://github.com/MrHus)) +- Marius Wirtherle ([wirmar](https://github.com/wirmar)) +- Mateusz Zatorski ([knowbody](https://github.com/knowbody)) +- Michael Shilman ([shilman](https://github.com/shilman)) +- Mico Piira ([micopiira](https://github.com/micopiira)) +- Mikhail Osher ([miraage](https://github.com/miraage)) +- Norbert de Langen ([ndelangen](https://github.com/ndelangen)) +- Paweł Jędrzejczyk ([paweljedrzejczyk](https://github.com/paweljedrzejczyk)) +- Pete Nykänen ([petetnt](https://github.com/petetnt)) +- Ro Savage ([ro-savage](https://github.com/ro-savage)) +- Roman ([romanyanke](https://github.com/romanyanke)) +- Rustem Kakimov ([ruskakimov](https://github.com/ruskakimov)) +- Ryan Sullivan ([ryansully](https://github.com/ryansully)) +- Stanislas Ormières ([laruiss](https://github.com/laruiss)) +- Will Farley ([goldhand](https://github.com/goldhand)) +- Zac Kwan ([Zaccc123](https://github.com/Zaccc123)) +- [bryankang](https://github.com/bryankang) +- [varnav](https://github.com/varnav) +- shaun wallace ([shaunwallace](https://github.com/shaunwallace)) + +### Migrating from 1.0.7 to 1.0.8 + +Inside any created project that has not been ejected, run: + +``` +npm install --save-dev --save-exact react-scripts@1.0.8 +``` + +or + +``` +yarn add --dev --exact react-scripts@1.0.8 +``` + +**If you previously used `HTTPS=true` environment variable in development**, make sure you aren't affected by a now-fixed vulnerability in Webpack by [visiting this page](http://badcert.mike.works/). You can read more about the vulnerability [here](https://medium.com/@mikenorth/webpack-preact-cli-vulnerability-961572624c54). + +You may optionally then move `react-scripts` from `devDependencies` to `dependencies` since that’s how we’ll structure newly created projects. It is not necessary though. + +If you left the service worker integration enabled and didn’t change how it works, you can replace `src/registerServiceWorker.js` with [this updated version](https://raw.githubusercontent.com/facebookincubator/create-react-app/895c475d3fc218c65dcac9a3ef3f2c0ea746a1ed/packages/react-scripts/template/src/registerServiceWorker.js). + +If you haven't changed the default CSS organization, you may want to apply [this fix](https://github.com/facebookincubator/create-react-app/pull/2470/files) that makes `index.css` take precedence over `App.css` in your project. + +## 1.0.7 (May 27, 2017) + +#### :bug: Bug Fix + +* `react-scripts` + + * [#2382](https://github.com/facebookincubator/create-react-app/pull/2382) Consistently set environment variables. ([@gaearon](https://github.com/gaearon)) + * [#2379](https://github.com/facebookincubator/create-react-app/pull/2379) Temporarily disable `comparisons` feature in uglify compression. ([@davidascher](https://github.com/davidascher)) + +#### :nail_care: Enhancement + +* `react-scripts` + + * [#2383](https://github.com/facebookincubator/create-react-app/pull/2383) Update webpack to 2.6.1. ([@gaearon](https://github.com/gaearon)) + * [#2349](https://github.com/facebookincubator/create-react-app/pull/2349) Update webpack to v2.6.0. ([@ingro](https://github.com/ingro)) + * [#2351](https://github.com/facebookincubator/create-react-app/pull/2351) Removed the overriding of `reduce_vars` since webpack v2.6.0 included fix of Uglify. ([@Zaccc123](https://github.com/Zaccc123)) + +* `react-dev-utils`, `react-scripts` + + * [#2361](https://github.com/facebookincubator/create-react-app/pull/2361) Print file sizes with correct build folder path. ([@fezhengjin](https://github.com/fezhengjin)) + +#### :memo: Documentation + +* `react-scripts` + + * [#2372](https://github.com/facebookincubator/create-react-app/pull/2372) Update README.md for `now` deployments. ([@purplecones](https://github.com/purplecones)) + * [#2350](https://github.com/facebookincubator/create-react-app/pull/2350) Fix broken links. ([@gaearon](https://github.com/gaearon)) + +#### Committers: 6 +- Dan Abramov ([gaearon](https://github.com/gaearon)) +- David Ascher ([davidascher](https://github.com/davidascher)) +- Emanuele Ingrosso ([ingro](https://github.com/ingro)) +- Jin Zheng ([fezhengjin](https://github.com/fezhengjin)) +- Mirza Joldic ([purplecones](https://github.com/purplecones)) +- Zac Kwan ([Zaccc123](https://github.com/Zaccc123)) + +### Migrating from 1.0.6 to 1.0.7 + +Inside any created project that has not been ejected, run: + +``` +npm install --save-dev --save-exact react-scripts@1.0.7 +``` + +or + +``` +yarn add --dev --exact react-scripts@1.0.7 +``` + ## 1.0.6 (May 24, 2017) #### :bug: Bug Fix diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a4e3414be..68a9c4e09 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -90,6 +90,12 @@ and then run `npm start` or `npm run build`. *Note: if you are using yarn, we suggest that you use `yarn install --no-lockfile` instead of the bare `yarn` or `yarn install` because we [intentionally](https://github.com/facebookincubator/create-react-app/pull/2014#issuecomment-300811661) do not ignore or add yarn.lock to our repo.* +## Contributing to E2E (end to end) tests + +**TL;DR** use the command `yarn e2e:docker` to run unit and e2e tests. + +More detailed information are in the dedicated [README](/packages/react-scripts/fixtures/kitchensink/README.md). + ## Cutting a Release 1. Tag all merged pull requests that go into the release with the relevant milestone. Each merged PR should also be labeled with one of the [labels](https://github.com/facebookincubator/create-react-app/labels) named `tag: ...` to indicate what kind of change it is. diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md deleted file mode 100644 index a1e7638b4..000000000 --- a/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,59 +0,0 @@ -If you are reporting a bug, please fill in below. Otherwise feel free to remove this template entirely. - -### Can you reproduce the problem with latest npm? - -Many errors, especially related to "missing modules", are due to npm bugs. - -If you're using Windows, [follow these instructions to update npm](https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows). - -If you're using OS X or Linux, run this to update npm: - -``` -npm install -g npm@latest - -cd your_project_directory -rm -rf node_modules -npm install -``` - -Then try to reproduce the issue again. - -Can you still reproduce it? - -### Description - -What are you reporting? - -### Expected behavior - -Tell us what you think should happen. - -### Actual behavior - -Tell us what actually happens. - -### Environment - -Run these commands in the project folder and fill in their results: - -1. `npm ls react-scripts-ts` (if you haven’t ejected): -2. `node -v`: -3. `npm -v`: - -Then, specify: - -1. Operating system: -2. Browser and version: - -### Reproducible Demo - -Please take the time to create a new app that reproduces the issue. - -Alternatively, you could copy your app that experiences the problem and start removing things until you’re left with the minimal reproducible demo. - -(Accidentally, you might get to the root of your problem during that process.) - -Push to GitHub and paste the link here. - -By doing this, you're helping the Create React App contributors a big time! -Demonstrable issues gets fixed faster. diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 87acf9c2f..000000000 --- a/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/README.md b/README.md index de9bfe65f..37805d28c 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,7 @@ When you run `npm run build` the terminal will output the error, including the h * Fix `typescript` version to 2.3.x until 2.4 @types are fixed ### 2.3.1 -* Fix issue with new @types/react -### 2.3.0 * All tsc to parse config (for `extend`) - Thanks to @DorianGrey * Fix various jest issues - thanks to @zinserjan * Fix code coverage - thanks to @zinserjan diff --git a/bootstrap.js b/bootstrap.js new file mode 100644 index 000000000..b54a1ed9f --- /dev/null +++ b/bootstrap.js @@ -0,0 +1,67 @@ +'use strict'; + +const { execSync, spawn } = require('child_process'); +const { resolve } = require('path'); +const { existsSync } = require('fs'); +const { platform } = require('os'); + +function shouldUseYarn() { + try { + execSync('yarnpkg --version', { stdio: 'ignore' }); + return true; + } catch (e) { + return false; + } +} + +function shouldUseNpmConcurrently() { + try { + const versionString = execSync('npm --version'); + const m = /^(\d+)[.]/.exec(versionString); + // NPM >= 5 support concurrent installs + return Number(m[1]) >= 5; + } catch (e) { + return false; + } +} + +const yarn = shouldUseYarn(); +const windows = platform() === 'win32'; +const lerna = resolve( + __dirname, + 'node_modules', + '.bin', + windows ? 'lerna.cmd' : 'lerna' +); + +if (!existsSync(lerna)) { + if (yarn) { + console.log('Cannot find lerna. Please run `yarn --check-files`.'); + } else { + console.log( + 'Cannot find lerna. Please remove `node_modules` and run `npm install`.' + ); + } + process.exit(1); +} + +let child; +if (yarn) { + // Yarn does not support concurrency + child = spawn(lerna, ['bootstrap', '--npm-client=yarn', '--concurrency=1'], { + stdio: 'inherit', + }); +} else { + let args = ['bootstrap']; + if ( + // The Windows filesystem does not handle concurrency well + windows || + // Only newer npm versions support concurrency + !shouldUseNpmConcurrently() + ) { + args.push('--concurrency=1'); + } + child = spawn(lerna, args, { stdio: 'inherit' }); +} + +child.on('close', code => process.exit(code)); diff --git a/lerna.json b/lerna.json index e2429777d..7ca916a85 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "lerna": "2.0.0-beta.38", + "lerna": "2.0.0-rc.5", "version": "independent", "changelog": { "repo": "facebookincubator/create-react-app", diff --git a/package.json b/package.json index 39a0d002d..ab4de27c6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "changelog": "lerna-changelog", "create-react-app": "tasks/cra.sh", "e2e": "tasks/e2e-simple.sh", - "postinstall": "lerna bootstrap && cd packages/react-error-overlay/ && npm run build:prod", + "e2e:docker": "tasks/local-test.sh", + "postinstall": "node bootstrap.js && cd packages/react-error-overlay/ && npm run build:prod", "publish": "tasks/release.sh", "start": "node packages/react-scripts/scripts/start.js", "test": "node packages/react-scripts/scripts/test.js --env=jsdom", @@ -19,10 +20,10 @@ "@types/react-dom": "^15.5.0", "eslint": "3.19.0", "husky": "^0.13.2", - "lerna": "2.0.0-beta.38", + "lerna": "2.0.0-rc.5", "lerna-changelog": "^0.2.3", "lint-staged": "^3.3.1", - "prettier": "^0.21.0" + "prettier": "^1.5.2" }, "lint-staged": { "*.js": [ diff --git a/packages/babel-preset-react-app/package.json b/packages/babel-preset-react-app/package.json index 175b7b129..d10188fda 100644 --- a/packages/babel-preset-react-app/package.json +++ b/packages/babel-preset-react-app/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-react-app", - "version": "3.0.0", + "version": "3.0.1", "description": "Babel preset used by Create React App", "repository": "facebookincubator/create-react-app", "license": "BSD-3-Clause", @@ -21,7 +21,7 @@ "babel-plugin-transform-react-jsx-source": "6.22.0", "babel-plugin-transform-regenerator": "6.24.1", "babel-plugin-transform-runtime": "6.23.0", - "babel-preset-env": "1.4.0", + "babel-preset-env": "1.5.2", "babel-preset-react": "6.24.1" }, "peerDependencies": { diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index b3d0638e9..4509b4978 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -74,10 +74,14 @@ const program = new commander.Command(packageJson.name) ); console.log(` - a specific npm version: ${chalk.green('0.8.2')}`); console.log( - ` - a custom fork published on npm: ${chalk.green('my-react-scripts')}` + ` - a custom fork published on npm: ${chalk.green( + 'my-react-scripts' + )}` ); console.log( - ` - a .tgz archive: ${chalk.green('https://mysite.com/my-react-scripts-0.8.2.tgz')}` + ` - a .tgz archive: ${chalk.green( + 'https://mysite.com/my-react-scripts-0.8.2.tgz' + )}` ); console.log( ` It is not needed unless you specifically want to use a fork.` @@ -87,7 +91,9 @@ const program = new commander.Command(packageJson.name) ` If you have any problems, do not hesitate to file an issue:` ); console.log( - ` ${chalk.cyan('https://github.com/facebookincubator/create-react-app/issues/new')}` + ` ${chalk.cyan( + 'https://github.com/facebookincubator/create-react-app/issues/new' + )}` ); console.log(); }) @@ -163,7 +169,7 @@ function createApp(name, verbose, version, template) { if (!semver.satisfies(process.version, '>=6.0.0')) { console.log( chalk.yellow( - `You are using Node ${process.version} so the project will be boostrapped with an old unsupported version of tools.\n\n` + + `You are using Node ${process.version} so the project will be bootstrapped with an old unsupported version of tools.\n\n` + `Please update to Node 6 or higher for a better, fully supported experience.\n` ) ); @@ -218,7 +224,13 @@ function install(useYarn, dependencies, verbose, isOnline) { } } else { command = 'npm'; - args = ['install', '--save', '--save-exact'].concat(dependencies); + args = [ + 'install', + '--save', + '--save-exact', + '--loglevel', + 'error', + ].concat(dependencies); } if (verbose) { @@ -250,17 +262,21 @@ function run( const packageToInstall = getInstallPackage(version); const allDependencies = ['react', 'react-dom', packageToInstall]; - console.log('Installing packages. This might take a couple minutes.'); + console.log('Installing packages. This might take a couple of minutes.'); getPackageName(packageToInstall) - .then(packageName => checkIfOnline(useYarn).then(isOnline => ({ - isOnline: isOnline, - packageName: packageName, - }))) + .then(packageName => + checkIfOnline(useYarn).then(isOnline => ({ + isOnline: isOnline, + packageName: packageName, + })) + ) .then(info => { const isOnline = info.isOnline; const packageName = info.packageName; console.log( - `Installing ${chalk.cyan('react')}, ${chalk.cyan('react-dom')}, and ${chalk.cyan(packageName)}...` + `Installing ${chalk.cyan('react')}, ${chalk.cyan( + 'react-dom' + )}, and ${chalk.cyan(packageName)}...` ); console.log(); @@ -270,11 +286,7 @@ function run( }) .then(packageName => { checkNodeVersion(packageName); - - // Since react-scripts has been installed with --save - // we need to move it into devDependencies and rewrite package.json - // also ensure react dependencies have caret version range - fixDependencies(packageName); + setCaretRangeForRuntimeDeps(packageName); const scriptsPath = path.resolve( process.cwd(), @@ -332,7 +344,9 @@ function run( if (!remainingFiles.length) { // Delete target folder if empty console.log( - `Deleting ${chalk.cyan(`${appName} /`)} from ${chalk.cyan(path.resolve(root, '..'))}` + `Deleting ${chalk.cyan(`${appName} /`)} from ${chalk.cyan( + path.resolve(root, '..') + )}` ); process.chdir(path.resolve(root, '..')); fs.removeSync(path.join(root)); @@ -420,7 +434,9 @@ function getPackageName(installPackage) { /^.+\/(.+?)(?:-\d+.+)?\.tgz$/ )[1]; console.log( - `Based on the filename, assuming it is "${chalk.cyan(assumedProjectName)}"` + `Based on the filename, assuming it is "${chalk.cyan( + assumedProjectName + )}"` ); return Promise.resolve(assumedProjectName); }); @@ -483,7 +499,9 @@ function checkAppName(appName) { const validationResult = validateProjectName(appName); if (!validationResult.validForNewPackages) { console.error( - `Could not create a project called ${chalk.red(`"${appName}"`)} because of npm naming restrictions:` + `Could not create a project called ${chalk.red( + `"${appName}"` + )} because of npm naming restrictions:` ); printValidationResults(validationResult.errors); printValidationResults(validationResult.warnings); @@ -491,16 +509,16 @@ function checkAppName(appName) { } // TODO: there should be a single place that holds the dependencies - const dependencies = ['react', 'react-dom']; - const devDependencies = ['react-scripts']; - const allDependencies = dependencies.concat(devDependencies).sort(); - if (allDependencies.indexOf(appName) >= 0) { + const dependencies = ['react', 'react-dom', 'react-scripts'].sort(); + if (dependencies.indexOf(appName) >= 0) { console.error( chalk.red( - `We cannot create a project called ${chalk.green(appName)} because a dependency with the same name exists.\n` + + `We cannot create a project called ${chalk.green( + appName + )} because a dependency with the same name exists.\n` + `Due to the way npm works, the following names are not allowed:\n\n` ) + - chalk.cyan(allDependencies.map(depName => ` ${depName}`).join('\n')) + + chalk.cyan(dependencies.map(depName => ` ${depName}`).join('\n')) + chalk.red('\n\nPlease choose a different project name.') ); process.exit(1); @@ -519,7 +537,9 @@ function makeCaretRange(dependencies, name) { if (!semver.validRange(patchedVersion)) { console.error( - `Unable to patch ${name} dependency version because version ${chalk.red(version)} will become invalid ${chalk.red(patchedVersion)}` + `Unable to patch ${name} dependency version because version ${chalk.red( + version + )} will become invalid ${chalk.red(patchedVersion)}` ); patchedVersion = version; } @@ -527,7 +547,7 @@ function makeCaretRange(dependencies, name) { dependencies[name] = patchedVersion; } -function fixDependencies(packageName) { +function setCaretRangeForRuntimeDeps(packageName) { const packagePath = path.join(process.cwd(), 'package.json'); const packageJson = require(packagePath); @@ -537,16 +557,11 @@ function fixDependencies(packageName) { } const packageVersion = packageJson.dependencies[packageName]; - if (typeof packageVersion === 'undefined') { console.error(chalk.red(`Unable to find ${packageName} in package.json`)); process.exit(1); } - packageJson.devDependencies = packageJson.devDependencies || {}; - packageJson.devDependencies[packageName] = packageVersion; - delete packageJson.dependencies[packageName]; - makeCaretRange(packageJson.dependencies, 'react'); makeCaretRange(packageJson.dependencies, 'react-dom'); diff --git a/packages/create-react-app/package.json b/packages/create-react-app/package.json index 13a567fa7..613007b40 100644 --- a/packages/create-react-app/package.json +++ b/packages/create-react-app/package.json @@ -1,6 +1,6 @@ { "name": "create-react-app", - "version": "1.3.1", + "version": "1.3.2", "keywords": [ "react" ], diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index 2cbcae04c..7298a8c3b 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -236,7 +236,8 @@ module.exports = { { object: 'System', property: 'import', - message: 'Please use import() instead. More info: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting', + message: + 'Please use import() instead. More info: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting', }, ], diff --git a/packages/eslint-config-react-app/package.json b/packages/eslint-config-react-app/package.json index 87b63c5b6..cd36a70e5 100644 --- a/packages/eslint-config-react-app/package.json +++ b/packages/eslint-config-react-app/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-react-app", - "version": "1.0.4", + "version": "1.0.5", "description": "ESLint configuration used by Create React App", "repository": "facebookincubator/create-react-app", "license": "BSD-3-Clause", diff --git a/packages/react-dev-utils/FileSizeReporter.js b/packages/react-dev-utils/FileSizeReporter.js index a0db0684f..ab9a27287 100644 --- a/packages/react-dev-utils/FileSizeReporter.js +++ b/packages/react-dev-utils/FileSizeReporter.js @@ -18,7 +18,13 @@ var stripAnsi = require('strip-ansi'); var gzipSize = require('gzip-size').sync; // Prints a detailed summary of build files. -function printFileSizesAfterBuild(webpackStats, previousSizeMap) { +function printFileSizesAfterBuild( + webpackStats, + previousSizeMap, + buildFolder, + maxBundleGzipSize, + maxChunkGzipSize +) { var root = previousSizeMap.root; var sizes = previousSizeMap.sizes; var assets = webpackStats @@ -30,7 +36,7 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap) { var previousSize = sizes[removeFileNameHash(root, asset.name)]; var difference = getDifferenceLabel(size, previousSize); return { - folder: path.join('build', path.dirname(asset.name)), + folder: path.join(path.basename(buildFolder), path.dirname(asset.name)), name: path.basename(asset.name), size: size, sizeLabel: filesize(size) + (difference ? ' (' + difference + ')' : ''), @@ -41,6 +47,7 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap) { null, assets.map(a => stripAnsi(a.sizeLabel).length) ); + var suggestBundleSplitting = false; assets.forEach(asset => { var sizeLabel = asset.sizeLabel; var sizeLength = stripAnsi(sizeLabel).length; @@ -48,14 +55,38 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap) { var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLength); sizeLabel += rightPadding; } + var isMainBundle = asset.name.indexOf('main.') === 0; + var maxRecommendedSize = isMainBundle + ? maxBundleGzipSize + : maxChunkGzipSize; + var isLarge = maxRecommendedSize && asset.size > maxRecommendedSize; + if (isLarge && path.extname(asset.name) === '.js') { + suggestBundleSplitting = true; + } console.log( ' ' + - sizeLabel + + (isLarge ? chalk.yellow(sizeLabel) : sizeLabel) + ' ' + chalk.dim(asset.folder + path.sep) + chalk.cyan(asset.name) ); }); + if (suggestBundleSplitting) { + console.log(); + console.log( + chalk.yellow('The bundle size is significantly larger than recommended.') + ); + console.log( + chalk.yellow( + 'Consider reducing it with code splitting: https://goo.gl/9VhYWB' + ) + ); + console.log( + chalk.yellow( + 'You can also analyze the project dependencies: https://goo.gl/LeUzfb' + ) + ); + } } function removeFileNameHash(buildFolder, fileName) { @@ -88,15 +119,12 @@ function measureFileSizesBeforeBuild(buildFolder) { if (!err && fileNames) { sizes = fileNames .filter(fileName => /\.(js|css)$/.test(fileName)) - .reduce( - (memo, fileName) => { - var contents = fs.readFileSync(fileName); - var key = removeFileNameHash(buildFolder, fileName); - memo[key] = gzipSize(contents); - return memo; - }, - {} - ); + .reduce((memo, fileName) => { + var contents = fs.readFileSync(fileName); + var key = removeFileNameHash(buildFolder, fileName); + memo[key] = gzipSize(contents); + return memo; + }, {}); } resolve({ root: buildFolder, diff --git a/packages/react-dev-utils/ModuleScopePlugin.js b/packages/react-dev-utils/ModuleScopePlugin.js index fd70a2f40..f630a0279 100644 --- a/packages/react-dev-utils/ModuleScopePlugin.js +++ b/packages/react-dev-utils/ModuleScopePlugin.js @@ -37,7 +37,7 @@ class ModuleScopePlugin { // Maybe an indexOf === 0 would be better? const relative = path.relative(appSrc, request.context.issuer); // If it's not in src/ or a subdirectory, not our request! - if (relative[0] === '.') { + if (relative.startsWith('../') || relative.startsWith('..\\')) { return callback(); } // Find path from src to the requested file @@ -49,12 +49,25 @@ class ModuleScopePlugin { ) ); // Error if in a parent directory of src/ - if (requestRelative[0] === '.') { + if ( + requestRelative.startsWith('../') || + requestRelative.startsWith('..\\') + ) { callback( new Error( - `You attempted to import ${chalk.cyan(request.__innerRequest_request)} which falls outside of the project ${chalk.cyan('src/')} directory. ` + - `Relative imports outside of ${chalk.cyan('src/')} are not supported. ` + - `You can either move it inside ${chalk.cyan('src/')}, or add a symlink to it from project's ${chalk.cyan('node_modules/')}.` + `You attempted to import ${chalk.cyan( + request.__innerRequest_request + )} which falls outside of the project ${chalk.cyan( + 'src/' + )} directory. ` + + `Relative imports outside of ${chalk.cyan( + 'src/' + )} are not supported. ` + + `You can either move it inside ${chalk.cyan( + 'src/' + )}, or add a symlink to it from project's ${chalk.cyan( + 'node_modules/' + )}.` ), request ); diff --git a/packages/react-dev-utils/WebpackDevServerUtils.js b/packages/react-dev-utils/WebpackDevServerUtils.js index 62eafa40a..f9957aaa3 100644 --- a/packages/react-dev-utils/WebpackDevServerUtils.js +++ b/packages/react-dev-utils/WebpackDevServerUtils.js @@ -13,7 +13,8 @@ const fs = require('fs'); const path = require('path'); const url = require('url'); const chalk = require('chalk'); -const detect = require('@timer/detect-port'); +const detect = require('detect-port-alt'); +const isRoot = require('is-root'); const inquirer = require('inquirer'); const clearConsole = require('./clearConsole'); const formatWebpackMessages = require('./formatWebpackMessages'); @@ -36,18 +37,20 @@ if (isSmokeTest) { } function prepareUrls(protocol, host, port) { - const formatUrl = hostname => url.format({ - protocol, - hostname, - port, - pathname: '/', - }); - const prettyPrintUrl = hostname => url.format({ - protocol, - hostname, - port: chalk.bold(port), - pathname: '/', - }); + const formatUrl = hostname => + url.format({ + protocol, + hostname, + port, + pathname: '/', + }); + const prettyPrintUrl = hostname => + url.format({ + protocol, + hostname, + port: chalk.bold(port), + pathname: '/', + }); const isUnspecifiedHost = host === '0.0.0.0' || host === '::'; let prettyHost, lanUrlForConfig, lanUrlForTerminal; @@ -107,7 +110,7 @@ function printInstructions(appName, urls, useYarn) { console.log('Note that the development build is not optimized.'); console.log( `To create a production build, use ` + - `${chalk.cyan(`${useYarn ? 'yarn' : 'npm'} run build`)}.` + `${chalk.cyan(`${useYarn ? 'yarn' : 'npm run'} build`)}.` ); console.log(); } @@ -316,9 +319,11 @@ function prepareProxy(proxy, appPublicFolder) { // However API calls like `fetch()` won’t generally accept text/html. // If this heuristic doesn’t work well for you, use a custom `proxy` object. context: function(pathname, req) { - return mayProxy(pathname) && + return ( + mayProxy(pathname) && req.headers.accept && - req.headers.accept.indexOf('text/html') === -1; + req.headers.accept.indexOf('text/html') === -1 + ); }, onProxyReq: proxyReq => { // Browers may send Origin headers even with same-origin @@ -374,36 +379,40 @@ function prepareProxy(proxy, appPublicFolder) { function choosePort(host, defaultPort) { return detect(defaultPort, host).then( - port => new Promise(resolve => { - if (port === defaultPort) { - return resolve(port); - } - if (isInteractive) { - clearConsole(); - const existingProcess = getProcessForPort(defaultPort); - const question = { - type: 'confirm', - name: 'shouldChangePort', - message: chalk.yellow( - `Something is already running on port ${defaultPort}.` + - `${existingProcess ? ` Probably:\n ${existingProcess}` : ''}` - ) + '\n\nWould you like to run the app on another port instead?', - default: true, - }; - inquirer.prompt(question).then(answer => { - if (answer.shouldChangePort) { - resolve(port); - } else { - resolve(null); - } - }); - } else { - console.log( - chalk.red(`Something is already running on port ${defaultPort}.`) - ); - resolve(null); - } - }), + port => + new Promise(resolve => { + if (port === defaultPort) { + return resolve(port); + } + const message = + process.platform !== 'win32' && defaultPort < 1024 && !isRoot() + ? `Admin permissions are required to run a server on a port below 1024.` + : `Something is already running on port ${defaultPort}.`; + if (isInteractive) { + clearConsole(); + const existingProcess = getProcessForPort(defaultPort); + const question = { + type: 'confirm', + name: 'shouldChangePort', + message: + chalk.yellow( + message + + `${existingProcess ? ` Probably:\n ${existingProcess}` : ''}` + ) + '\n\nWould you like to run the app on another port instead?', + default: true, + }; + inquirer.prompt(question).then(answer => { + if (answer.shouldChangePort) { + resolve(port); + } else { + resolve(null); + } + }); + } else { + console.log(chalk.red(message)); + resolve(null); + } + }), err => { throw new Error( chalk.red(`Could not find an open port at ${chalk.bold(host)}.`) + diff --git a/packages/react-dev-utils/ansiHTML.js b/packages/react-dev-utils/ansiHTML.js index 5d3e79203..9f53cea67 100644 --- a/packages/react-dev-utils/ansiHTML.js +++ b/packages/react-dev-utils/ansiHTML.js @@ -69,7 +69,8 @@ function ansiHTML(txt) { var open = false; for (var index = 0; index < arr.length; ++index) { var c = arr[index]; - var content = c.content, fg = c.fg; + var content = c.content, + fg = c.fg; var contentParts = content.split('\n'); for (var _index = 0; _index < contentParts.length; ++_index) { diff --git a/packages/react-dev-utils/eslintFormatter.js b/packages/react-dev-utils/eslintFormatter.js index 96b6ce14b..b7756b7a2 100644 --- a/packages/react-dev-utils/eslintFormatter.js +++ b/packages/react-dev-utils/eslintFormatter.js @@ -82,7 +82,8 @@ function formatter(results) { // it here because we always show at most one error, and // we can only be sure it's an ESLint error before exiting // this function. - output += 'Search for the ' + + output += + 'Search for the ' + chalk.underline(chalk.red('keywords')) + ' to learn more about each error.'; } diff --git a/packages/react-dev-utils/launchEditor.js b/packages/react-dev-utils/launchEditor.js index 8bfa3f3dc..bcf0a5060 100644 --- a/packages/react-dev-utils/launchEditor.js +++ b/packages/react-dev-utils/launchEditor.js @@ -8,12 +8,12 @@ */ 'use strict'; -var fs = require('fs'); -var path = require('path'); -var child_process = require('child_process'); -var os = require('os'); -var chalk = require('chalk'); -var shellQuote = require('shell-quote'); +const fs = require('fs'); +const path = require('path'); +const child_process = require('child_process'); +const os = require('os'); +const chalk = require('chalk'); +const shellQuote = require('shell-quote'); function isTerminalEditor(editor) { switch (editor) { @@ -28,14 +28,26 @@ function isTerminalEditor(editor) { // Map from full process name to binary that starts the process // We can't just re-use full process name, because it will spawn a new instance // of the app every time -var COMMON_EDITORS = { +const COMMON_EDITORS_OSX = { '/Applications/Atom.app/Contents/MacOS/Atom': 'atom', - '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta': '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta', - '/Applications/Sublime Text.app/Contents/MacOS/Sublime Text': '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl', - '/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2': '/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl', + '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta': + '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta', + '/Applications/Brackets.app/Contents/MacOS/Brackets': 'brackets', + '/Applications/Sublime Text.app/Contents/MacOS/Sublime Text': + '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl', + '/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2': + '/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl', '/Applications/Visual Studio Code.app/Contents/MacOS/Electron': 'code', }; +const COMMON_EDITORS_WIN = [ + 'Brackets.exe', + 'Code.exe', + 'atom.exe', + 'sublime_text.exe', + 'notepad++.exe', +]; + function addWorkspaceToArgumentsIfExists(args, workspace) { if (workspace) { args.unshift(workspace); @@ -44,7 +56,7 @@ function addWorkspaceToArgumentsIfExists(args, workspace) { } function getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) { - var editorBasename = path.basename(editor).replace(/\.(exe|cmd|bat)$/i, ''); + const editorBasename = path.basename(editor).replace(/\.(exe|cmd|bat)$/i, ''); switch (editorBasename) { case 'vim': case 'mvim': @@ -54,11 +66,14 @@ function getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) { case 'Atom Beta': case 'subl': case 'sublime': + case 'sublime_text': case 'wstorm': case 'appcode': case 'charm': case 'idea': return [fileName + ':' + lineNumber]; + case 'notepad++': + return ['-n' + lineNumber, fileName]; case 'joe': case 'emacs': case 'emacsclient': @@ -68,10 +83,19 @@ function getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) { case 'mine': return ['--line', lineNumber, fileName]; case 'code': + case 'Code': return addWorkspaceToArgumentsIfExists( ['-g', fileName + ':' + lineNumber], workspace ); + case 'webstorm': + case 'webstorm64': + case 'phpstorm': + case 'phpstorm64': + return addWorkspaceToArgumentsIfExists( + ['--line', lineNumber, fileName], + workspace + ); } // For all others, drop the lineNumber until we have @@ -86,21 +110,41 @@ function guessEditor() { return shellQuote.parse(process.env.REACT_EDITOR); } - // Using `ps x` on OSX we can find out which editor is currently running. - // Potentially we could use similar technique for Windows and Linux - if (process.platform === 'darwin') { - try { - var output = child_process.execSync('ps x').toString(); - var processNames = Object.keys(COMMON_EDITORS); - for (var i = 0; i < processNames.length; i++) { - var processName = processNames[i]; + // Using `ps x` on OSX or `Get-Process` on Windows we can find out which editor is currently running. + // Potentially we could use similar technique for Linux + try { + if (process.platform === 'darwin') { + const output = child_process.execSync('ps x').toString(); + const processNames = Object.keys(COMMON_EDITORS_OSX); + for (let i = 0; i < processNames.length; i++) { + const processName = processNames[i]; if (output.indexOf(processName) !== -1) { - return [COMMON_EDITORS[processName]]; + return [COMMON_EDITORS_OSX[processName]]; + } + } + } else if (process.platform === 'win32') { + const output = child_process + .execSync('powershell -Command "Get-Process | Select-Object Path"', { + stdio: ['pipe', 'pipe', 'ignore'], + }) + .toString(); + const runningProcesses = output.split('\r\n'); + for (let i = 0; i < runningProcesses.length; i++) { + // `Get-Process` sometimes returns empty lines + if (!runningProcesses[i]) { + continue; + } + + const fullProcessPath = runningProcesses[i].trim(); + const shortProcessName = path.basename(fullProcessPath); + + if (COMMON_EDITORS_WIN.indexOf(shortProcessName) !== -1) { + return [fullProcessPath]; } } - } catch (error) { - // Ignore... } + } catch (error) { + // Ignore... } // Last resort, use old skool env vars @@ -133,12 +177,13 @@ function printInstructions(fileName, errorMessage) { ' to the ' + chalk.green('.env.local') + ' file in your project folder ' + - 'and restart the development server.' + 'and restart the development server. Learn more: ' + + chalk.green('https://goo.gl/MMTaZt') ); console.log(); } -var _childProcess = null; +let _childProcess = null; function launchEditor(fileName, lineNumber) { if (!fs.existsSync(fileName)) { return; @@ -170,7 +215,7 @@ function launchEditor(fileName, lineNumber) { fileName = path.relative('', fileName); } - var workspace = null; + let workspace = null; if (lineNumber) { args = args.concat( getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) diff --git a/packages/react-dev-utils/openBrowser.js b/packages/react-dev-utils/openBrowser.js index 9ded70781..4f5700125 100644 --- a/packages/react-dev-utils/openBrowser.js +++ b/packages/react-dev-utils/openBrowser.js @@ -68,7 +68,8 @@ function startBrowserProcess(browser, url) { // requested a different browser, we can try opening // Chrome with AppleScript. This lets us reuse an // existing tab when possible instead of creating a new one. - const shouldTryOpenChromeWithAppleScript = process.platform === 'darwin' && + const shouldTryOpenChromeWithAppleScript = + process.platform === 'darwin' && (typeof browser !== 'string' || browser === OSX_CHROME); if (shouldTryOpenChromeWithAppleScript) { diff --git a/packages/react-dev-utils/package.json b/packages/react-dev-utils/package.json index f62d87f8b..9fbbd7640 100644 --- a/packages/react-dev-utils/package.json +++ b/packages/react-dev-utils/package.json @@ -1,6 +1,6 @@ { "name": "react-dev-utils", - "version": "2.0.1", + "version": "3.0.1", "description": "Webpack utilities used by Create React App", "repository": "facebookincubator/create-react-app", "license": "BSD-3-Clause", @@ -33,18 +33,19 @@ "webpackHotDevClient.js" ], "dependencies": { - "@timer/detect-port": "1.1.3", - "address": "1.0.1", - "anser": "1.3.0", + "address": "1.0.2", + "anser": "1.4.1", "babel-code-frame": "6.22.0", "chalk": "1.1.3", "cross-spawn": "4.0.2", + "detect-port-alt": "1.1.3", "escape-string-regexp": "1.0.5", "filesize": "3.3.0", "gzip-size": "3.0.0", "html-entities": "1.2.1", - "inquirer": "3.0.6", - "opn": "5.0.0", + "inquirer": "3.1.1", + "is-root": "1.0.0", + "opn": "5.1.0", "recursive-readdir": "2.2.1", "shell-quote": "1.6.1", "sockjs-client": "1.1.4", diff --git a/packages/react-dev-utils/printHostingInstructions.js b/packages/react-dev-utils/printHostingInstructions.js index 7b9284d4e..f9882d44a 100644 --- a/packages/react-dev-utils/printHostingInstructions.js +++ b/packages/react-dev-utils/printHostingInstructions.js @@ -23,10 +23,14 @@ function printHostingInstructions( if (publicUrl && publicUrl.indexOf('.github.io/') !== -1) { // "homepage": "http://user.github.io/project" console.log( - `The project was built assuming it is hosted at ${chalk.green(publicPathname)}.` + `The project was built assuming it is hosted at ${chalk.green( + publicPathname + )}.` ); console.log( - `You can control this with the ${chalk.green('homepage')} field in your ${chalk.cyan('package.json')}.` + `You can control this with the ${chalk.green( + 'homepage' + )} field in your ${chalk.cyan('package.json')}.` ); console.log(); console.log(`The ${chalk.cyan('build')} folder is ready to be deployed.`); @@ -48,10 +52,14 @@ function printHostingInstructions( console.log(` ${chalk.yellow('"scripts"')}: {`); console.log(` ${chalk.dim('// ...')}`); console.log( - ` ${chalk.yellow('"predeploy"')}: ${chalk.yellow('"npm run build",')}` + ` ${chalk.yellow('"predeploy"')}: ${chalk.yellow( + '"npm run build",' + )}` ); console.log( - ` ${chalk.yellow('"deploy"')}: ${chalk.yellow('"gh-pages -d build"')}` + ` ${chalk.yellow('"deploy"')}: ${chalk.yellow( + '"gh-pages -d build"' + )}` ); console.log(' }'); console.log(); @@ -63,10 +71,14 @@ function printHostingInstructions( } else if (publicPath !== '/') { // "homepage": "http://mywebsite.com/project" console.log( - `The project was built assuming it is hosted at ${chalk.green(publicPath)}.` + `The project was built assuming it is hosted at ${chalk.green( + publicPath + )}.` ); console.log( - `You can control this with the ${chalk.green('homepage')} field in your ${chalk.cyan('package.json')}.` + `You can control this with the ${chalk.green( + 'homepage' + )} field in your ${chalk.cyan('package.json')}.` ); console.log(); console.log(`The ${chalk.cyan('build')} folder is ready to be deployed.`); @@ -75,10 +87,14 @@ function printHostingInstructions( if (publicUrl) { // "homepage": "http://mywebsite.com" console.log( - `The project was built assuming it is hosted at ${chalk.green(publicUrl)}.` + `The project was built assuming it is hosted at ${chalk.green( + publicUrl + )}.` ); console.log( - `You can control this with the ${chalk.green('homepage')} field in your ${chalk.cyan('package.json')}.` + `You can control this with the ${chalk.green( + 'homepage' + )} field in your ${chalk.cyan('package.json')}.` ); console.log(); } else { @@ -87,12 +103,16 @@ function printHostingInstructions( 'The project was built assuming it is hosted at the server root.' ); console.log( - `To override this, specify the ${chalk.green('homepage')} in your ${chalk.cyan('package.json')}.` + `To override this, specify the ${chalk.green( + 'homepage' + )} in your ${chalk.cyan('package.json')}.` ); console.log('For example, add this to build it for GitHub Pages:'); console.log(); console.log( - ` ${chalk.green('"homepage"')} ${chalk.cyan(':')} ${chalk.green('"http://myname.github.io/myapp"')}${chalk.cyan(',')}` + ` ${chalk.green('"homepage"')} ${chalk.cyan(':')} ${chalk.green( + '"http://myname.github.io/myapp"' + )}${chalk.cyan(',')}` ); console.log(); } diff --git a/packages/react-dev-utils/webpackHotDevClient.js b/packages/react-dev-utils/webpackHotDevClient.js index 7d6a979e2..78002b28e 100644 --- a/packages/react-dev-utils/webpackHotDevClient.js +++ b/packages/react-dev-utils/webpackHotDevClient.js @@ -81,14 +81,16 @@ function addOverlayDivTo(iframe) { } function overlayHeaderStyle() { - return 'font-size: 2em;' + + return ( + 'font-size: 2em;' + 'font-family: sans-serif;' + 'color: rgb(206, 17, 38);' + 'white-space: pre-wrap;' + 'margin: 0 2rem 0.75rem 0px;' + 'flex: 0 0 auto;' + 'max-height: 35%;' + - 'overflow: auto;'; + 'overflow: auto;' + ); } var overlayIframe = null; @@ -127,7 +129,8 @@ function ensureOverlayDivExists(onOverlayDivReady) { function showErrorOverlay(message) { ensureOverlayDivExists(function onOverlayDivReady(overlayDiv) { // TODO: unify this with our runtime overlay - overlayDiv.innerHTML = '
{ expect.assertions(1); - const error = 'TypeError: document.body.missing is not a function\n at App.componentDidMount (http://localhost:3000/static/js/bundle.js:26122:21)\n at http://localhost:3000/static/js/bundle.js:30091:25\n at measureLifeCyclePerf (http://localhost:3000/static/js/bundle.js:29901:12)\n at http://localhost:3000/static/js/bundle.js:30090:11\n at CallbackQueue.notifyAll (http://localhost:3000/static/js/bundle.js:13256:22)\n at ReactReconcileTransaction.close (http://localhost:3000/static/js/bundle.js:35124:26)\n at ReactReconcileTransaction.closeAll (http://localhost:3000/static/js/bundle.js:7390:25)\n at ReactReconcileTransaction.perform (http://localhost:3000/static/js/bundle.js:7337:16)\n at batchedMountComponentIntoNode (http://localhost:3000/static/js/bundle.js:14204:15)\n at ReactDefaultBatchingStrategyTransaction.perform (http://localhost:3000/static/js/bundle.js:7324:20)\n at Object.batchedUpdates (http://localhost:3000/static/js/bundle.js:33900:26)\n at Object.batchedUpdates (http://localhost:3000/static/js/bundle.js:2181:27)\n at Object._renderNewRootComponent (http://localhost:3000/static/js/bundle.js:14398:18)\n at Object._renderSubtreeIntoContainer (http://localhost:3000/static/js/bundle.js:14479:32)\n at Object.render (http://localhost:3000/static/js/bundle.js:14500:23)\n at Object.friendlySyntaxErrorLabel (http://localhost:3000/static/js/bundle.js:17287:20)\n at __webpack_require__ (http://localhost:3000/static/js/bundle.js:660:30)\n at fn (http://localhost:3000/static/js/bundle.js:84:20)\n at Object.(http://localhost:3000/static/js/bundle.js:41219:18)\n at __webpack_require__ (http://localhost:3000/static/js/bundle.js:660:30)\n at validateFormat (http://localhost:3000/static/js/bundle.js:709:39)\n at http://localhost:3000/static/js/bundle.js:712:10'; + const error = + 'TypeError: document.body.missing is not a function\n at App.componentDidMount (http://localhost:3000/static/js/bundle.js:26122:21)\n at http://localhost:3000/static/js/bundle.js:30091:25\n at measureLifeCyclePerf (http://localhost:3000/static/js/bundle.js:29901:12)\n at http://localhost:3000/static/js/bundle.js:30090:11\n at CallbackQueue.notifyAll (http://localhost:3000/static/js/bundle.js:13256:22)\n at ReactReconcileTransaction.close (http://localhost:3000/static/js/bundle.js:35124:26)\n at ReactReconcileTransaction.closeAll (http://localhost:3000/static/js/bundle.js:7390:25)\n at ReactReconcileTransaction.perform (http://localhost:3000/static/js/bundle.js:7337:16)\n at batchedMountComponentIntoNode (http://localhost:3000/static/js/bundle.js:14204:15)\n at ReactDefaultBatchingStrategyTransaction.perform (http://localhost:3000/static/js/bundle.js:7324:20)\n at Object.batchedUpdates (http://localhost:3000/static/js/bundle.js:33900:26)\n at Object.batchedUpdates (http://localhost:3000/static/js/bundle.js:2181:27)\n at Object._renderNewRootComponent (http://localhost:3000/static/js/bundle.js:14398:18)\n at Object._renderSubtreeIntoContainer (http://localhost:3000/static/js/bundle.js:14479:32)\n at Object.render (http://localhost:3000/static/js/bundle.js:14500:23)\n at Object.friendlySyntaxErrorLabel (http://localhost:3000/static/js/bundle.js:17287:20)\n at __webpack_require__ (http://localhost:3000/static/js/bundle.js:660:30)\n at fn (http://localhost:3000/static/js/bundle.js:84:20)\n at Object. (http://localhost:3000/static/js/bundle.js:41219:18)\n at __webpack_require__ (http://localhost:3000/static/js/bundle.js:660:30)\n at validateFormat (http://localhost:3000/static/js/bundle.js:709:39)\n at http://localhost:3000/static/js/bundle.js:712:10'; fetch.mockResponseOnce( fs @@ -38,7 +39,8 @@ test('basic error; 0 context', async () => { test('default context (3)', async () => { expect.assertions(1); - const error = 'TypeError: document.body.missing is not a function\n at App.componentDidMount (http://localhost:3000/static/js/bundle.js:26122:21)'; + const error = + 'TypeError: document.body.missing is not a function\n at App.componentDidMount (http://localhost:3000/static/js/bundle.js:26122:21)'; fetch.mockResponseOnce( fs @@ -62,7 +64,8 @@ test('default context (3)', async () => { test('bad comes back same', async () => { expect.assertions(2); - const error = 'TypeError: document.body.missing is not a function\n at App.componentDidMount (A:1:2)'; + const error = + 'TypeError: document.body.missing is not a function\n at App.componentDidMount (A:1:2)'; const orig = parse(error); expect(orig).toEqual([ { diff --git a/packages/react-error-overlay/src/components/frame.js b/packages/react-error-overlay/src/components/frame.js index 3b27406dd..43d0d4043 100644 --- a/packages/react-error-overlay/src/components/frame.js +++ b/packages/react-error-overlay/src/components/frame.js @@ -242,8 +242,8 @@ function createFrame( let needsHidden = false; const isInternalUrl = isInternalFile(sourceFileName, fileName); const isThrownIntentionally = !isBultinErrorName(errorName); - const shouldCollapse = isInternalUrl && - (isThrownIntentionally || omits.hasReachedAppCode); + const shouldCollapse = + isInternalUrl && (isThrownIntentionally || omits.hasReachedAppCode); if (!isInternalUrl) { omits.hasReachedAppCode = true; @@ -281,9 +281,8 @@ function createFrame( let onSourceClick = null; if (sourceFileName) { // e.g. "/path-to-my-app/webpack/bootstrap eaddeb46b67d75e4dfc1" - const isInternalWebpackBootstrapCode = sourceFileName - .trim() - .indexOf(' ') !== -1; + const isInternalWebpackBootstrapCode = + sourceFileName.trim().indexOf(' ') !== -1; if (!isInternalWebpackBootstrapCode) { onSourceClick = () => { // Keep this in sync with react-error-overlay/middleware.js @@ -312,7 +311,10 @@ function createFrame( let hasSource = false; if (!shouldCollapse) { if ( - compiled && scriptLines && scriptLines.length !== 0 && lineNumber != null + compiled && + scriptLines && + scriptLines.length !== 0 && + lineNumber != null ) { elem.appendChild( createCode( diff --git a/packages/react-error-overlay/src/components/overlay.js b/packages/react-error-overlay/src/components/overlay.js index 573db8def..69acf9ad4 100644 --- a/packages/react-error-overlay/src/components/overlay.js +++ b/packages/react-error-overlay/src/components/overlay.js @@ -60,9 +60,8 @@ function createOverlay( applyStyles(header, headerStyle); // Make message prettier - let finalMessage = message.match(/^\w*:/) || !name - ? message - : name + ': ' + message; + let finalMessage = + message.match(/^\w*:/) || !name ? message : name + ': ' + message; finalMessage = finalMessage // TODO: maybe remove this prefix from fbjs? diff --git a/packages/react-error-overlay/src/utils/isInternalFile.js b/packages/react-error-overlay/src/utils/isInternalFile.js index 71beea7cc..c78bbe3ed 100644 --- a/packages/react-error-overlay/src/utils/isInternalFile.js +++ b/packages/react-error-overlay/src/utils/isInternalFile.js @@ -9,13 +9,15 @@ /* @flow */ function isInternalFile(sourceFileName: ?string, fileName: ?string) { - return sourceFileName == null || + return ( + sourceFileName == null || sourceFileName === '' || sourceFileName.indexOf('/~/') !== -1 || sourceFileName.indexOf('/node_modules/') !== -1 || sourceFileName.trim().indexOf(' ') !== -1 || fileName == null || - fileName === ''; + fileName === '' + ); } export { isInternalFile }; diff --git a/packages/react-error-overlay/src/utils/unmapper.js b/packages/react-error-overlay/src/utils/unmapper.js index 74e389555..b01736d74 100644 --- a/packages/react-error-overlay/src/utils/unmapper.js +++ b/packages/react-error-overlay/src/utils/unmapper.js @@ -15,7 +15,8 @@ import path from 'path'; function count(search: string, string: string): number { // Count starts at -1 becuse a do-while loop always runs at least once - let count = -1, index = -1; + let count = -1, + index = -1; do { // First call or the while case evaluated true, meaning we have to make // count 0 or we found a character diff --git a/packages/react-scripts/config/env.js b/packages/react-scripts/config/env.js index e7d7f9f32..ebef79ed9 100644 --- a/packages/react-scripts/config/env.js +++ b/packages/react-scripts/config/env.js @@ -88,13 +88,10 @@ function getClientEnvironment(publicUrl) { ); // Stringify all values so we can feed into Webpack DefinePlugin const stringified = { - 'process.env': Object.keys(raw).reduce( - (env, key) => { - env[key] = JSON.stringify(raw[key]); - return env; - }, - {} - ), + 'process.env': Object.keys(raw).reduce((env, key) => { + env[key] = JSON.stringify(raw[key]); + return env; + }, {}), }; return { raw, stringified }; diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index c680d87b9..e860d9b04 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -43,8 +43,8 @@ const getPublicUrl = appPackageJson => // like /todos/42/static/js/bundle.7289d.js. We have to know the root. function getServedPath(appPackageJson) { const publicUrl = getPublicUrl(appPackageJson); - const servedUrl = envPublicUrl || - (publicUrl ? url.parse(publicUrl).pathname : '/'); + const servedUrl = + envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/'); return ensureSlash(servedUrl, true); } @@ -92,7 +92,8 @@ module.exports = { const ownPackageJson = require('../package.json'); const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`); -const reactScriptsLinked = fs.existsSync(reactScriptsPath) && +const reactScriptsLinked = + fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink(); // config before publish: we're in ./packages/react-scripts/config/ diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index 2eed1e04e..2934aeae6 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -76,9 +76,9 @@ module.exports = { chunkFilename: 'static/js/[name].chunk.js', // This is the URL that app is served from. We use "/" in development. publicPath: publicPath, - // Point sourcemap entries to original disk location + // Point sourcemap entries to original disk location (format as URL on Windows) devtoolModuleFilenameTemplate: info => - path.resolve(info.absoluteResourcePath), + path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'), }, resolve: { // This allows you to set a fallback for where Webpack should look for modules. @@ -93,7 +93,19 @@ module.exports = { // We also include JSX as a common component filename extension to support // some tools, although we do not recommend using it, see: // https://github.com/facebookincubator/create-react-app/issues/290 - extensions: ['.ts', '.tsx', '.js', '.json', '.jsx'], + // `web` extension prefixes have been added for better support + // for React Native Web. + extensions: [ + '.web.ts', + '.ts', + '.web.tsx', + '.tsx', + '.web.js', + '.js', + '.json', + '.web.jsx', + '.jsx', + ], alias: { // @remove-on-eject-begin // Resolve Babel runtime relative to react-scripts. @@ -205,7 +217,9 @@ module.exports = { { loader: require.resolve('postcss-loader'), options: { - ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options + // Necessary for external CSS imports to work + // https://github.com/facebookincubator/create-react-app/issues/2677 + ident: 'postcss', plugins: () => [ require('postcss-flexbugs-fixes'), autoprefixer({ @@ -237,6 +251,8 @@ module.exports = { inject: true, template: paths.appHtml, }), + // Add module names to factory functions so they appear in browser profiler. + new webpack.NamedModulesPlugin(), // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`. new webpack.DefinePlugin(env.stringified), @@ -261,6 +277,7 @@ module.exports = { // Some libraries import Node modules but don't use them in the browser. // Tell Webpack to provide empty mocks for them so importing them works. node: { + dgram: 'empty', fs: 'empty', net: 'empty', tls: 'empty', diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index b710f480e..8519c6603 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -74,9 +74,11 @@ module.exports = { chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js', // We inferred the "public path" (such as / or /my-project) from homepage. publicPath: publicPath, - // Point sourcemap entries to original disk location + // Point sourcemap entries to original disk location (format as URL on Windows) devtoolModuleFilenameTemplate: info => - path.relative(paths.appSrc, info.absoluteResourcePath), + path + .relative(paths.appSrc, info.absoluteResourcePath) + .replace(/\\/g, '/'), }, resolve: { // This allows you to set a fallback for where Webpack should look for modules. @@ -91,7 +93,19 @@ module.exports = { // We also include JSX as a common component filename extension to support // some tools, although we do not recommend using it, see: // https://github.com/facebookincubator/create-react-app/issues/290 - extensions: ['.ts', '.tsx', '.js', '.json', '.jsx'], + // `web` extension prefixes have been added for better support + // for React Native Web. + extensions: [ + '.web.ts', + '.ts', + '.web.tsx', + '.tsx', + '.web.js', + '.js', + '.json', + '.web.jsx', + '.jsx', + ], alias: { // @remove-on-eject-begin // Resolve Babel runtime relative to react-scripts. @@ -175,7 +189,7 @@ module.exports = { { test: /\.(ts|tsx)$/, include: paths.appSrc, - loader: require.resolve('ts-loader'), + loader: require.resolve('ts-loader') }, // The notation here is somewhat confusing. // "postcss" loader applies autoprefixer to our CSS. @@ -207,7 +221,9 @@ module.exports = { { loader: require.resolve('postcss-loader'), options: { - ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options + // Necessary for external CSS imports to work + // https://github.com/facebookincubator/create-react-app/issues/2677 + ident: 'postcss', plugins: () => [ require('postcss-flexbugs-fixes'), autoprefixer({ @@ -266,13 +282,17 @@ module.exports = { new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false, - // This feature has been reported as buggy a few times, such as: - // https://github.com/mishoo/UglifyJS2/issues/1964 - // We'll wait with enabling it by default until it is more solid. - reduce_vars: false, + // Disabled because of an issue with Uglify breaking seemingly valid code: + // https://github.com/facebookincubator/create-react-app/issues/2376 + // Pending further investigation: + // https://github.com/mishoo/UglifyJS2/issues/2011 + comparisons: false, }, output: { comments: false, + // Turned on because emoji and regex is not minified properly using default + // https://github.com/facebookincubator/create-react-app/issues/2488 + ascii_only: true, }, sourceMap: true, }), @@ -300,6 +320,11 @@ module.exports = { // This message occurs for every build and is a bit too noisy. return; } + if (message.indexOf('Skipping static resource') === 0) { + // This message obscures real errors so we ignore it. + // https://github.com/facebookincubator/create-react-app/issues/2612 + return; + } console.log(message); }, minify: true, @@ -310,9 +335,6 @@ module.exports = { navigateFallbackWhitelist: [/^(?!\/__).*/], // Don't precache sourcemaps (they're large) and build asset manifest: staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/], - // Work around Windows path issue in SWPrecacheWebpackPlugin: - // https://github.com/facebookincubator/create-react-app/issues/2235 - stripPrefix: paths.appBuild.replace(/\\/g, '/') + '/', }), // Moment.js is an extremely popular library that bundles large locale files // by default due to how Webpack interprets its code. This is a practical @@ -324,6 +346,7 @@ module.exports = { // Some libraries import Node modules but don't use them in the browser. // Tell Webpack to provide empty mocks for them so importing them works. node: { + dgram: 'empty', fs: 'empty', net: 'empty', tls: 'empty', diff --git a/packages/react-scripts/config/webpackDevServer.config.js b/packages/react-scripts/config/webpackDevServer.config.js index cf7584e5b..2a351e668 100644 --- a/packages/react-scripts/config/webpackDevServer.config.js +++ b/packages/react-scripts/config/webpackDevServer.config.js @@ -36,8 +36,8 @@ module.exports = function(proxy, allowedHost) { // So we will disable the host check normally, but enable it if you have // specified the `proxy` setting. Finally, we let you override it if you // really know what you're doing with a special environment variable. - disableHostCheck: !proxy || - process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true', + disableHostCheck: + !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true', // Enable gzip compression of generated files. compress: true, // Silence WebpackDevServer's own logs since they're generally not useful. diff --git a/packages/react-scripts/fixtures/kitchensink/.template.dependencies.json b/packages/react-scripts/fixtures/kitchensink/.template.dependencies.json index 63ecaf90d..b8500f804 100644 --- a/packages/react-scripts/fixtures/kitchensink/.template.dependencies.json +++ b/packages/react-scripts/fixtures/kitchensink/.template.dependencies.json @@ -6,6 +6,7 @@ "chai": "3.5.0", "jsdom": "9.8.3", "mocha": "3.2.0", + "normalize.css": "7.0.0", "prop-types": "15.5.6", "test-integrity": "1.0.0" } diff --git a/packages/react-scripts/fixtures/kitchensink/README.md b/packages/react-scripts/fixtures/kitchensink/README.md new file mode 100644 index 000000000..4e7725ce1 --- /dev/null +++ b/packages/react-scripts/fixtures/kitchensink/README.md @@ -0,0 +1,54 @@ +# Contributing to Create React App's E2E tests + +This is an end to end kitchensink test suite, but has multiple usages in it. + +## Running the test suite + +Tests are automatically run by the CI tools. +In order to run them locally, without having to manually install and configure everything, the `yarn e2e:docker` CLI command can be used. + +This is a simple script that runs a **Docker** container, where the node version, git branch to clone, test suite, and whether to run it with `yarn` or `npm` can be chosen. +Simply run `yarn e2e:docker -- --help` to get additional info. + +If you need guidance installing **Docker**, you should follow their [official docs](https://docs.docker.com/engine/installation/). + +## Writing tests + +Each time a new feature is added, it is advised to add at least one test covering it. + +Features are categorized by their scope: + + - *env*, all those which deal with environment variables (e.g. `NODE_PATH`) + + - *syntax*, all those which showcase a single EcmaScript syntax feature that is expected to be transpiled by **Babel** + + - *webpack*, all those which make use of webpack settings, loaders or plugins + +### Using it as Unit Tests + +In it's most basic for this serve as a collection of unit tests on a single functionality. + +Unit tests are written in a `src/features/**/*.test.js` file located in the same folder as the feature they test, and usually consist of a simple `ReactDOM.render` call. + +These tests are run by **jest** and the environment is `test`, so that it resembles how a **Create React App** application is tested. + +### Using it as Integration Tests + +This suite tests how the single features as before behave while development and in production. +A local HTTP server is started, then every single feature is loaded, one by one, to be tested. + +Test are written in `integration/{env|syntax|webpack}.test.js`, depending on their scope. + +For every test case added there is just a little chore to do: + + - a `case` statement must be added in `src/App.js`, which simply perform a dynamic `import()` of the feature + + - add a test case in the appropriate integration test file, which calls and awaits `initDOM` with the previous `SwitchCase` string + +An usual flow for the test itself is something similar to: + + - add an `id` attribute in a target HTML tag in the feature itself + + - since `initDOM` returns a `Document` element, the previous `id` attribute is used to target the feature's DOM and `expect` accordingly + +These tests are run by **mocha** (why not **jest**? See [this issue](https://github.com/facebook/jest/issues/2288)) and the environments used are both `development` and `production`. diff --git a/packages/react-scripts/fixtures/kitchensink/integration/env.test.js b/packages/react-scripts/fixtures/kitchensink/integration/env.test.js index 89d19fcf4..a7d4ff2a2 100644 --- a/packages/react-scripts/fixtures/kitchensink/integration/env.test.js +++ b/packages/react-scripts/fixtures/kitchensink/integration/env.test.js @@ -50,9 +50,10 @@ describe('Integration', () => { it('PUBLIC_URL', async () => { const doc = await initDOM('public-url'); - const prefix = process.env.NODE_ENV === 'development' - ? '' - : 'http://www.example.org/spa'; + const prefix = + process.env.NODE_ENV === 'development' + ? '' + : 'http://www.example.org/spa'; expect(doc.getElementById('feature-public-url').textContent).to.equal( `${prefix}.` ); diff --git a/packages/react-scripts/fixtures/kitchensink/integration/initDOM.js b/packages/react-scripts/fixtures/kitchensink/integration/initDOM.js index 4d6f531ea..b865b5641 100644 --- a/packages/react-scripts/fixtures/kitchensink/integration/initDOM.js +++ b/packages/react-scripts/fixtures/kitchensink/integration/initDOM.js @@ -38,13 +38,14 @@ if (process.env.E2E_FILE) { ) ); } else if (process.env.E2E_URL) { - getMarkup = () => new Promise(resolve => { - http.get(process.env.E2E_URL, res => { - let rawData = ''; - res.on('data', chunk => rawData += chunk); - res.on('end', () => resolve(rawData)); + getMarkup = () => + new Promise(resolve => { + http.get(process.env.E2E_URL, res => { + let rawData = ''; + res.on('data', chunk => (rawData += chunk)); + res.on('end', () => resolve(rawData)); + }); }); - }); resourceLoader = (resource, callback) => resource.defaultFetch(callback); } else { @@ -58,21 +59,22 @@ if (process.env.E2E_FILE) { ); } -export default feature => new Promise(async resolve => { - const markup = await getMarkup(); - const host = process.env.E2E_URL || 'http://www.example.org/spa:3000'; - const doc = jsdom.jsdom(markup, { - features: { - FetchExternalResources: ['script', 'css'], - ProcessExternalResources: ['script'], - }, - created: (_, win) => - win.addEventListener('ReactFeatureDidMount', () => resolve(doc), true), - deferClose: true, - resourceLoader, - url: `${host}#${feature}`, - virtualConsole: jsdom.createVirtualConsole().sendTo(console), - }); +export default feature => + new Promise(async resolve => { + const markup = await getMarkup(); + const host = process.env.E2E_URL || 'http://www.example.org/spa:3000'; + const doc = jsdom.jsdom(markup, { + features: { + FetchExternalResources: ['script', 'css'], + ProcessExternalResources: ['script'], + }, + created: (_, win) => + win.addEventListener('ReactFeatureDidMount', () => resolve(doc), true), + deferClose: true, + resourceLoader, + url: `${host}#${feature}`, + virtualConsole: jsdom.createVirtualConsole().sendTo(console), + }); - doc.close(); -}); + doc.close(); + }); diff --git a/packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js b/packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js index bda69cc61..e3845e79e 100644 --- a/packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js +++ b/packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js @@ -17,6 +17,9 @@ describe('Integration', () => { expect( doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '') + ).to.match(/html\{/); + expect( + doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '') ).to.match(/#feature-css-inclusion\{background:.+;color:.+}/); }); diff --git a/packages/react-scripts/fixtures/kitchensink/src/App.js b/packages/react-scripts/fixtures/kitchensink/src/App.js index 3a1981a40..cb342b062 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/App.js +++ b/packages/react-scripts/fixtures/kitchensink/src/App.js @@ -30,10 +30,7 @@ class BuiltEmitter extends Component { } render() { - const { - props: { feature }, - handleReady, - } = this; + const { props: { feature }, handleReady } = this; return ( {createElement(feature, { @@ -57,114 +54,132 @@ class App extends Component { const feature = window.location.hash.slice(1); switch (feature) { case 'array-destructuring': - import( - './features/syntax/ArrayDestructuring' - ).then(f => this.setFeature(f.default)); + import('./features/syntax/ArrayDestructuring').then(f => + this.setFeature(f.default) + ); break; case 'array-spread': import('./features/syntax/ArraySpread').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'async-await': import('./features/syntax/AsyncAwait').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'class-properties': import('./features/syntax/ClassProperties').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'computed-properties': - import( - './features/syntax/ComputedProperties' - ).then(f => this.setFeature(f.default)); + import('./features/syntax/ComputedProperties').then(f => + this.setFeature(f.default) + ); break; case 'css-inclusion': import('./features/webpack/CssInclusion').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'custom-interpolation': - import( - './features/syntax/CustomInterpolation' - ).then(f => this.setFeature(f.default)); + import('./features/syntax/CustomInterpolation').then(f => + this.setFeature(f.default) + ); break; case 'default-parameters': import('./features/syntax/DefaultParameters').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'destructuring-and-await': - import( - './features/syntax/DestructuringAndAwait' - ).then(f => this.setFeature(f.default)); + import('./features/syntax/DestructuringAndAwait').then(f => + this.setFeature(f.default) + ); break; case 'file-env-variables': import('./features/env/FileEnvVariables').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'generators': import('./features/syntax/Generators').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'image-inclusion': import('./features/webpack/ImageInclusion').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'json-inclusion': import('./features/webpack/JsonInclusion').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'linked-modules': import('./features/webpack/LinkedModules').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'node-path': import('./features/env/NodePath').then(f => this.setFeature(f.default)); break; case 'no-ext-inclusion': import('./features/webpack/NoExtInclusion').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'object-destructuring': - import( - './features/syntax/ObjectDestructuring' - ).then(f => this.setFeature(f.default)); + import('./features/syntax/ObjectDestructuring').then(f => + this.setFeature(f.default) + ); break; case 'object-spread': import('./features/syntax/ObjectSpread').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'promises': import('./features/syntax/Promises').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'public-url': import('./features/env/PublicUrl').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'rest-and-default': import('./features/syntax/RestAndDefault').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'rest-parameters': import('./features/syntax/RestParameters').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'shell-env-variables': import('./features/env/ShellEnvVariables').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'svg-inclusion': import('./features/webpack/SvgInclusion').then(f => - this.setFeature(f.default)); + this.setFeature(f.default) + ); break; case 'template-interpolation': - import( - './features/syntax/TemplateInterpolation' - ).then(f => this.setFeature(f.default)); + import('./features/syntax/TemplateInterpolation').then(f => + this.setFeature(f.default) + ); break; case 'unknown-ext-inclusion': - import( - './features/webpack/UnknownExtInclusion' - ).then(f => this.setFeature(f.default)); + import('./features/webpack/UnknownExtInclusion').then(f => + this.setFeature(f.default) + ); break; default: throw new Error(`Missing feature "${feature}"`); diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/env/FileEnvVariables.js b/packages/react-scripts/fixtures/kitchensink/src/features/env/FileEnvVariables.js index 55ae368e4..03d638471 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/env/FileEnvVariables.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/env/FileEnvVariables.js @@ -9,7 +9,7 @@ import React from 'react'; -export default () => ( +export default () => {process.env.REACT_APP_ORIGINAL_1} @@ -18,8 +18,10 @@ export default () => ( {process.env.REACT_APP_ORIGINAL_2} - {process.env.REACT_APP_DEVELOPMENT}{process.env.REACT_APP_PRODUCTION} + {process.env.REACT_APP_DEVELOPMENT} + {process.env.REACT_APP_PRODUCTION} - {process.env.REACT_APP_X} - -); + + {process.env.REACT_APP_X} + + ; diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.js b/packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.js index a039cefed..6d2437a64 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/env/NodePath.js @@ -33,7 +33,11 @@ export default class extends Component { render() { return (- {this.state.users.map(user =>); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/env/PublicUrl.js b/packages/react-scripts/fixtures/kitchensink/src/features/env/PublicUrl.js index 4ea9b96f8..af87748e6 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/env/PublicUrl.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/env/PublicUrl.js @@ -9,6 +9,7 @@ import React from 'react'; -export default () => ( - {process.env.PUBLIC_URL}. -); +export default () => + + {process.env.PUBLIC_URL}. + ; diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/env/ShellEnvVariables.js b/packages/react-scripts/fixtures/kitchensink/src/features/env/ShellEnvVariables.js index 8449097d6..400dfc013 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/env/ShellEnvVariables.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/env/ShellEnvVariables.js @@ -9,8 +9,7 @@ import React from 'react'; -export default () => ( +export default () => {process.env.REACT_APP_SHELL_ENV_MESSAGE}. - -); + ; diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ArrayDestructuring.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ArrayDestructuring.js index be6c39f90..de0576549 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ArrayDestructuring.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ArrayDestructuring.js @@ -38,7 +38,11 @@ export default class extends Component {{user.name})} + {this.state.users.map(user => ++ {user.name} ++ )}{this.state.users.map(user => { const [id, name] = user; - return); diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ArraySpread.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ArraySpread.js index eb7886aa4..ebf90ef6e 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ArraySpread.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ArraySpread.js @@ -41,7 +41,11 @@ export default class extends Component { render() { return ({name}; + return ( ++ {name} ++ ); })}- {this.state.users.map(user =>); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/AsyncAwait.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/AsyncAwait.js index a60633460..c91da311d 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/AsyncAwait.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/AsyncAwait.js @@ -41,7 +41,11 @@ export default class extends Component { render() { return ({user.name})} + {this.state.users.map(user => ++ {user.name} ++ )}- {this.state.users.map(user =>); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ClassProperties.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ClassProperties.js index ed96d4f8c..58ae10763 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ClassProperties.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ClassProperties.js @@ -29,7 +29,11 @@ export default class extends Component { render() { return ({user.name})} + {this.state.users.map(user => ++ {user.name} ++ )}- {this.users.map(user =>); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ComputedProperties.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ComputedProperties.js index 38dc797a8..fcbf721e8 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ComputedProperties.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ComputedProperties.js @@ -41,9 +41,11 @@ export default class extends Component { render() { return ({user.name})} + {this.users.map(user => ++ {user.name} ++ )}- {this.state.users.map(user => ( -); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/CustomInterpolation.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/CustomInterpolation.js index 1a0123391..ab648255a 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/CustomInterpolation.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/CustomInterpolation.js @@ -53,9 +53,11 @@ export default class extends Component { return ({user.user_name}- ))} + {this.state.users.map(user => ++ {user.user_name} ++ )}- {this.state.users.map(user => ( -); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/DefaultParameters.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/DefaultParameters.js index 0a519eba8..6ebabaec7 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/DefaultParameters.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/DefaultParameters.js @@ -41,7 +41,11 @@ export default class extends Component { render() { return ({user.name}- ))} + {this.state.users.map(user => ++ {user.name} ++ )}- {this.state.users.map(user =>); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/DestructuringAndAwait.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/DestructuringAndAwait.js index d44f4cf22..aa8c9d7db 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/DestructuringAndAwait.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/DestructuringAndAwait.js @@ -43,7 +43,11 @@ export default class extends Component { render() { return ({user.name})} + {this.state.users.map(user => ++ {user.name} ++ )}- {this.state.users.map(user =>); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/Generators.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/Generators.js index 2fe473d13..44b2776e1 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/Generators.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/Generators.js @@ -43,7 +43,11 @@ export default class extends Component { render() { return ({user.name})} + {this.state.users.map(user => ++ {user.name} ++ )}- {this.state.users.map(user =>); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectDestructuring.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectDestructuring.js index 2994d14af..8a7b1095f 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectDestructuring.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectDestructuring.js @@ -43,7 +43,11 @@ export default class extends Component {{user.name})} + {this.state.users.map(user => ++ {user.name} ++ )}{this.state.users.map(user => { const { id, name } = user; - return); diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectSpread.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectSpread.js index 65705f11b..5ff4e10ac 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectSpread.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectSpread.js @@ -41,9 +41,11 @@ export default class extends Component { render() { return ({name}; + return ( ++ {name} ++ ); })}- {this.state.users.map(user => ( -); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/Promises.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/Promises.js index e626de5d8..31ef2c9eb 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/Promises.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/Promises.js @@ -42,7 +42,11 @@ export default class extends Component { render() { return ({user.name}: {user.age}- ))} + {this.state.users.map(user => ++ {user.name}: {user.age} ++ )}- {this.state.users.map(user =>); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/RestAndDefault.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/RestAndDefault.js index dc2a1563a..9e3e3fbab 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/RestAndDefault.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/RestAndDefault.js @@ -41,7 +41,11 @@ export default class extends Component { render() { return ({user.name})} + {this.state.users.map(user => ++ {user.name} ++ )}- {this.state.users.map(user =>); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/RestParameters.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/RestParameters.js index e703a33cc..98a0e7edc 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/RestParameters.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/RestParameters.js @@ -41,7 +41,11 @@ export default class extends Component { render() { return ({user.name})} + {this.state.users.map(user => ++ {user.name} ++ )}- {this.state.users.map(user =>); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/TemplateInterpolation.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/TemplateInterpolation.js index 5aba5da62..b69f7ede8 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/TemplateInterpolation.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/TemplateInterpolation.js @@ -41,7 +41,11 @@ export default class extends Component { render() { return ({user.name})} + {this.state.users.map(user => ++ {user.name} ++ )}- {this.state.users.map(user =>); } diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/ImageInclusion.js b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/ImageInclusion.js index a6ca7aaa8..8598d8d06 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/ImageInclusion.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/ImageInclusion.js @@ -10,6 +10,5 @@ import React from 'react'; import tiniestCat from './assets/tiniest-cat.jpg'; -export default () => ( -{user.name})} + {this.state.users.map(user => ++ {user.name} ++ )}-); +export default () => +
; diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/JsonInclusion.js b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/JsonInclusion.js index e81f76397..66425c66c 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/JsonInclusion.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/JsonInclusion.js @@ -10,4 +10,7 @@ import React from 'react'; import { abstract } from './assets/abstract.json'; -export default () =>
{abstract} ; +export default () => ++ {abstract} + ; diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/LinkedModules.js b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/LinkedModules.js index de8a5e4ab..395ebd7ed 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/LinkedModules.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/LinkedModules.js @@ -16,5 +16,9 @@ export default () => { if (!test() || v !== '2.0.0') { throw new Error('Functionality test did not pass.'); } - return{v}
; + return ( ++ {v} +
+ ); }; diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/NoExtInclusion.js b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/NoExtInclusion.js index 7f824c2f2..086885db2 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/NoExtInclusion.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/NoExtInclusion.js @@ -14,6 +14,7 @@ const text = aFileWithoutExt.includes('base64') ? atob(aFileWithoutExt.split('base64,')[1]).trim() : aFileWithoutExt; -export default () => ( - aFileWithoutExt -); +export default () => + + aFileWithoutExt + ; diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/UnknownExtInclusion.js b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/UnknownExtInclusion.js index 70b046e95..c41a1e0c0 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/UnknownExtInclusion.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/UnknownExtInclusion.js @@ -14,6 +14,7 @@ const text = aFileWithExtUnknown.includes('base64') ? atob(aFileWithExtUnknown.split('base64,')[1]).trim() : aFileWithExtUnknown; -export default () => ( - aFileWithExtUnknown -); +export default () => + + aFileWithExtUnknown + ; diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/assets/style.css b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/assets/style.css index c399d1aca..9502cfaa1 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/assets/style.css +++ b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/assets/style.css @@ -1,3 +1,9 @@ +/* + * Ensure CSS inclusion doesn't regress + * https://github.com/facebookincubator/create-react-app/issues/2677 + */ +@import '~normalize.css/normalize.css'; + #feature-css-inclusion { background: palevioletred; color: papayawhip; diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index de6a54484..94b189747 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -22,15 +22,16 @@ "react-scripts-ts": "./bin/react-scripts-ts.js" }, "dependencies": { - "autoprefixer": "7.1.0", + "autoprefixer": "7.1.1", "app-root-path": "^2.0.1", - "case-sensitive-paths-webpack-plugin": "2.0.0", + "case-sensitive-paths-webpack-plugin": "2.1.1", + "chalk": "1.1.3", "chalk": "1.1.3", "cli-highlight": "1.1.4", - "css-loader": "0.28.1", + "css-loader": "0.28.4", "dotenv": "4.0.0", - "extract-text-webpack-plugin": "2.1.0", - "file-loader": "0.11.1", + "extract-text-webpack-plugin": "2.1.2", + "file-loader": "0.11.2", "fs-extra": "3.0.1", "html-webpack-plugin": "2.28.0", "jest": "20.0.3", @@ -38,9 +39,9 @@ "postcss-flexbugs-fixes": "3.0.0", "postcss-loader": "2.0.5", "promise": "7.1.1", - "react-dev-utils": "^2.0.1", - "react-error-overlay": "^1.0.6", - "style-loader": "0.17.0", + "react-dev-utils": "^3.0.1", + "react-error-overlay": "^1.0.8", + "style-loader": "0.18.2", "ts-jest": "^20.0.7", "ts-loader": "^2.2.1", "tslint": "^5.2.0", @@ -48,10 +49,10 @@ "tslint-react": "^3.0.0", "typescript": "~2.4.0", "source-map-loader": "^0.2.1", - "sw-precache-webpack-plugin": "0.9.1", + "sw-precache-webpack-plugin": "0.11.3", "url-loader": "0.5.8", - "webpack": "2.6.0", - "webpack-dev-server": "2.4.5", + "webpack": "2.6.1", + "webpack-dev-server": "2.5.0", "webpack-manifest-plugin": "1.1.0", "whatwg-fetch": "2.0.3" }, @@ -60,6 +61,6 @@ "react-dom": "^15.5.4" }, "optionalDependencies": { - "fsevents": "1.0.17" + "fsevents": "1.1.2" } } diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 6548609ff..b9b65f531 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -11,6 +11,7 @@ 'use strict'; // Do this as the first thing so that any code reading it knows the right env. +process.env.BABEL_ENV = 'production'; process.env.NODE_ENV = 'production'; // Makes the script crash on unhandled rejections instead of silently @@ -34,10 +35,15 @@ const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages'); const printHostingInstructions = require('react-dev-utils/printHostingInstructions'); const FileSizeReporter = require('react-dev-utils/FileSizeReporter'); -const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild; +const measureFileSizesBeforeBuild = + FileSizeReporter.measureFileSizesBeforeBuild; const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild; const useYarn = fs.existsSync(paths.yarnLockFile); +// These sizes are pretty large. We'll warn for bundles exceeding them. +const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024; +const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; + // Warn and crash if required files are missing if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { process.exit(1); @@ -75,7 +81,13 @@ measureFileSizesBeforeBuild(paths.appBuild) } console.log('File sizes after gzip:\n'); - printFileSizesAfterBuild(stats, previousFileSizes); + printFileSizesAfterBuild( + stats, + previousFileSizes, + paths.appBuild, + WARN_AFTER_BUNDLE_GZIP_SIZE, + WARN_AFTER_CHUNK_GZIP_SIZE + ); console.log(); const appPackage = require(paths.appPackageJson); @@ -111,7 +123,12 @@ function build(previousFileSizes) { if (messages.errors.length) { return reject(new Error(messages.errors.join('\n\n'))); } - if (process.env.CI && messages.warnings.length) { + if ( + process.env.CI && + (typeof process.env.CI !== 'string' || + process.env.CI.toLowerCase() !== 'false') && + messages.warnings.length + ) { console.log( chalk.yellow( '\nTreating warnings as errors because process.env.CI = true.\n' + diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index c771e075d..3d8d258cc 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -85,19 +85,16 @@ inquirer const folders = ['config', 'config/jest', 'scripts']; // Make shallow array of files paths - const files = folders.reduce( - (files, folder) => { - return files.concat( - fs - .readdirSync(path.join(ownPath, folder)) - // set full path - .map(file => path.join(ownPath, folder, file)) - // omit dirs from file list - .filter(file => fs.lstatSync(file).isFile()) - ); - }, - [] - ); + const files = folders.reduce((files, folder) => { + return files.concat( + fs + .readdirSync(path.join(ownPath, folder)) + // set full path + .map(file => path.join(ownPath, folder, file)) + // omit dirs from file list + .filter(file => fs.lstatSync(file).isFile()) + ); + }, []); // Ensure that the app folder is clean and we won't override any files folders.forEach(verifyAbsent); @@ -124,18 +121,19 @@ inquirer if (content.match(/\/\/ @remove-file-on-eject/)) { return; } - content = content - // Remove dead code from .js files on eject - .replace( - /\/\/ @remove-on-eject-begin([\s\S]*?)\/\/ @remove-on-eject-end/mg, - '' - ) - // Remove dead code from .applescript files on eject - .replace( - /-- @remove-on-eject-begin([\s\S]*?)-- @remove-on-eject-end/mg, - '' - ) - .trim() + '\n'; + content = + content + // Remove dead code from .js files on eject + .replace( + /\/\/ @remove-on-eject-begin([\s\S]*?)\/\/ @remove-on-eject-end/gm, + '' + ) + // Remove dead code from .applescript files on eject + .replace( + /-- @remove-on-eject-begin([\s\S]*?)-- @remove-on-eject-end/gm, + '' + ) + .trim() + '\n'; console.log(` Adding ${cyan(file.replace(ownPath, ''))} to the project`); fs.writeFileSync(file.replace(ownPath, appPath), content); }); @@ -146,35 +144,50 @@ inquirer console.log(cyan('Updating the dependencies')); const ownPackageName = ownPackage.name; - if (appPackage.devDependencies[ownPackageName]) { - console.log(` Removing ${cyan(ownPackageName)} from devDependencies`); - delete appPackage.devDependencies[ownPackageName]; + if (appPackage.devDependencies) { + // We used to put react-scripts in devDependencies + if (appPackage.devDependencies[ownPackageName]) { + console.log(` Removing ${cyan(ownPackageName)} from devDependencies`); + delete appPackage.devDependencies[ownPackageName]; + } } + appPackage.dependencies = appPackage.dependencies || {}; if (appPackage.dependencies[ownPackageName]) { console.log(` Removing ${cyan(ownPackageName)} from dependencies`); delete appPackage.dependencies[ownPackageName]; } - Object.keys(ownPackage.dependencies).forEach(key => { // For some reason optionalDependencies end up in dependencies after install if (ownPackage.optionalDependencies[key]) { return; } - console.log(` Adding ${cyan(key)} to devDependencies`); - appPackage.devDependencies[key] = ownPackage.dependencies[key]; + console.log(` Adding ${cyan(key)} to dependencies`); + appPackage.dependencies[key] = ownPackage.dependencies[key]; + }); + // Sort the deps + const unsortedDependencies = appPackage.dependencies; + appPackage.dependencies = {}; + Object.keys(unsortedDependencies).sort().forEach(key => { + appPackage.dependencies[key] = unsortedDependencies[key]; }); console.log(); + console.log(cyan('Updating the scripts')); delete appPackage.scripts['eject']; Object.keys(appPackage.scripts).forEach(key => { Object.keys(ownPackage.bin).forEach(binKey => { const regex = new RegExp(binKey + ' (\\w+)', 'g'); + if (!regex.test(appPackage.scripts[key])) { + return; + } appPackage.scripts[key] = appPackage.scripts[key].replace( regex, 'node scripts/$1.js' ); console.log( - ` Replacing ${cyan(`"${binKey} ${key}"`)} with ${cyan(`"node scripts/${key}.js"`)}` + ` Replacing ${cyan(`"${binKey} ${key}"`)} with ${cyan( + `"node scripts/${key}.js"` + )}` ); }); }); @@ -217,11 +230,26 @@ inquirer } if (fs.existsSync(paths.yarnLockFile)) { - console.log(cyan('Running yarn...')); - spawnSync('yarnpkg', [], { stdio: 'inherit' }); + // TODO: this is disabled for three reasons. + // + // 1. It produces garbage warnings on Windows on some systems: + // https://github.com/facebookincubator/create-react-app/issues/2030 + // + // 2. For the above reason, it breaks Windows CI: + // https://github.com/facebookincubator/create-react-app/issues/2624 + // + // 3. It is wrong anyway: re-running yarn will respect the lockfile + // rather than package.json we just updated. Instead we should have + // updated the lockfile. So we might as well not do it while it's broken. + // https://github.com/facebookincubator/create-react-app/issues/2627 + // + // console.log(cyan('Running yarn...')); + // spawnSync('yarnpkg', [], { stdio: 'inherit' }); } else { console.log(cyan('Running npm install...')); - spawnSync('npm', ['install'], { stdio: 'inherit' }); + spawnSync('npm', ['install', '--loglevel', 'error'], { + stdio: 'inherit', + }); } console.log(green('Ejected successfully!')); console.log(); diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index de8ab085e..d7fc56652 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -28,18 +28,14 @@ module.exports = function( originalDirectory, template ) { - const ownPackageName = require(path.join( - __dirname, - '..', - 'package.json' - )).name; + const ownPackageName = require(path.join(__dirname, '..', 'package.json')) + .name; const ownPath = path.join(appPath, 'node_modules', ownPackageName); const appPackage = require(path.join(appPath, 'package.json')); const useYarn = fs.existsSync(path.join(appPath, 'yarn.lock')); // Copy over some of the devDependencies appPackage.dependencies = appPackage.dependencies || {}; - appPackage.devDependencies = appPackage.devDependencies || {}; // Setup the script rules appPackage.scripts = { @@ -212,6 +208,8 @@ module.exports = function( function isReactInstalled(appPackage) { const dependencies = appPackage.dependencies || {}; - return typeof dependencies.react !== 'undefined' && - typeof dependencies['react-dom'] !== 'undefined'; + return ( + typeof dependencies.react !== 'undefined' && + typeof dependencies['react-dom'] !== 'undefined' + ); } diff --git a/packages/react-scripts/scripts/start.js b/packages/react-scripts/scripts/start.js index a451228df..b86943b4d 100644 --- a/packages/react-scripts/scripts/start.js +++ b/packages/react-scripts/scripts/start.js @@ -10,6 +10,10 @@ // @remove-on-eject-end 'use strict'; +// Do this as the first thing so that any code reading it knows the right env. +process.env.BABEL_ENV = 'development'; +process.env.NODE_ENV = 'development'; + // Makes the script crash on unhandled rejections instead of silently // ignoring them. In the future, promise rejections that are not handled will // terminate the Node.js process with a non-zero exit code. @@ -17,8 +21,6 @@ process.on('unhandledRejection', err => { throw err; }); -process.env.NODE_ENV = 'development'; - // Ensure environment variables are read. require('../config/env'); diff --git a/packages/react-scripts/scripts/test.js b/packages/react-scripts/scripts/test.js index ef333e6c0..e9adb48f0 100644 --- a/packages/react-scripts/scripts/test.js +++ b/packages/react-scripts/scripts/test.js @@ -10,6 +10,8 @@ // @remove-on-eject-end 'use strict'; +// Do this as the first thing so that any code reading it knows the right env. +process.env.BABEL_ENV = 'test'; process.env.NODE_ENV = 'test'; process.env.PUBLIC_URL = ''; diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index 019767d7e..559f96f45 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -27,7 +27,17 @@ module.exports = (resolve, rootDir) => { collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], setupFiles: [resolve('config/polyfills.js')], setupTestFrameworkScriptFile: setupTestsFile, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], + moduleFileExtensions: [ + 'web.ts', + 'ts', + 'web.tsx', + 'tsx', + 'web.js', + 'js', + 'web.jsx', + 'jsx', + 'json', + ], testMatch: [ '/src/**/__tests__/**/*.ts?(x)', ' /src/**/?(*.)(spec|test).ts?(x)', @@ -49,7 +59,7 @@ module.exports = (resolve, rootDir) => { 'ts-jest': { tsConfigFile: paths.appTsTestConfig, }, - }, + } }; if (rootDir) { config.rootDir = rootDir; diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index dd7a48299..577502840 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -17,6 +17,7 @@ You can find the most recent version of this guide [here](https://github.com/fac - [Syntax Highlighting in the Editor](#syntax-highlighting-in-the-editor) - [Displaying Lint Output in the Editor](#displaying-lint-output-in-the-editor) - [Debugging in the Editor](#debugging-in-the-editor) +- [Formatting Code Automatically](#formatting-code-automatically) - [Changing the Page ` `](#changing-the-page-title) - [Installing a Dependency](#installing-a-dependency) - [Importing a Component](#importing-a-component) @@ -44,6 +45,7 @@ You can find the most recent version of this guide [here](https://github.com/fac - [Proxying API Requests in Development](#proxying-api-requests-in-development) - ["Invalid Host Header" Errors After Configuring Proxy](#invalid-host-header-errors-after-configuring-proxy) - [Configuring the Proxy Manually](#configuring-the-proxy-manually) + - [Configuring a WebSocket Proxy](#configuring-a-websocket-proxy) - [Using HTTPS in Development](#using-https-in-development) - [Generating Dynamic `` Tags on the Server](#generating-dynamic-meta-tags-on-the-server) - [Pre-Rendering into Static HTML Files](#pre-rendering-into-static-html-files) @@ -62,9 +64,13 @@ You can find the most recent version of this guide [here](https://github.com/fac - [Disabling jsdom](#disabling-jsdom) - [Snapshot Testing](#snapshot-testing) - [Editor Integration](#editor-integration) +- [Developing Components in Isolation](#developing-components-in-isolation) + - [Getting Started with Storybook](#getting-started-with-storybook) + - [Getting Started with Styleguidist](#getting-started-with-styleguidist) - [Making a Progressive Web App](#making-a-progressive-web-app) - [Offline-First Considerations](#offline-first-considerations) - [Progressive Web App Metadata](#progressive-web-app-metadata) +- [Analyzing the Bundle Size](#analyzing-the-bundle-size) - [Deployment](#deployment) - [Static Server](#static-server) - [Other Solutions](#other-solutions) @@ -83,7 +89,7 @@ You can find the most recent version of this guide [here](https://github.com/fac - [Troubleshooting](#troubleshooting) - [`npm start` doesn’t detect changes](#npm-start-doesnt-detect-changes) - [`npm test` hangs on macOS Sierra](#npm-test-hangs-on-macos-sierra) - - [`npm run build` silently fails](#npm-run-build-silently-fails) + - [`npm run build` exits too early](#npm-run-build-exits-too-early) - [`npm run build` fails on Heroku](#npm-run-build-fails-on-heroku) - [Moment.js locales are missing](#momentjs-locales-are-missing) - [Something Missing?](#something-missing) @@ -138,7 +144,7 @@ For the project to build, **these files must exist with exact filenames**: You can delete or rename the other files. You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack.
-You need to **put any JS and CSS files inside `src`**, or Webpack won’t see them. +You need to **put any JS and CSS files inside `src`**, otherwise Webpack won’t see them. Only files inside `public` can be used from `public/index.html`.
Read instructions below for using assets from JavaScript and HTML. @@ -263,6 +269,56 @@ Then add the block below to your `launch.json` file and put it inside the `.vsco Start your app by running `npm start`, and start debugging in VS Code by pressing `F5` or by clicking the green debug icon. You can now write code, set breakpoints, make changes to the code, and debug your newly modified code—all from your editor. +## Formatting Code Automatically + +Prettier is an opinionated code formatter with support for JavaScript, CSS and JSON. With Prettier you can format the code you write automatically to ensure a code style within your project. See the [Prettier's GitHub page](https://github.com/prettier/prettier) for more information, and look at this [page to see it in action](https://prettier.github.io/prettier/). + +To format our code whenever we make a commit in git, we need to install the following dependencies: + +```sh +npm install --save husky lint-staged prettier +``` + +Alternatively you may use `yarn`: + +```sh +yarn add husky lint-staged prettier +``` + +* `husky` makes it easy to use githooks as if they are npm scripts. +* `lint-staged` allows us to run scripts on staged files in git. See this [blog post about lint-staged to learn more about it](https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8). +* `prettier` is the JavaScript formatter we will run before commits. + +Now we can make sure every file is formatted correctly by adding a few lines to the `package.json` in the project root. + +Add the following line to `scripts` section: + +```diff + "scripts": { ++ "precommit": "lint-staged", + "start": "react-scripts start", + "build": "react-scripts build", +``` + +Next we add a 'lint-staged' field to the `package.json`, for example: + +```diff + "dependencies": { + // ... + }, ++ "lint-staged": { ++ "src/**/*.{js,jsx,json,css}": [ ++ "prettier --single-quote --write", ++ "git add" ++ ] ++ }, + "scripts": { +``` + +Now, whenever you make a commit, Prettier will format the changed files automatically. You can also run `./node_modules/.bin/prettier --single-quote --write "src/**/*.{js,jsx}"` to format your entire project for the first time. + +Next you might want to integrate Prettier in your favorite editor. Read the section on [Editor Integration](https://github.com/prettier/prettier#editor-integration) on the Prettier GitHub page. + ## Changing the Page `` You can find the source HTML file in the `public` folder of the generated project. You may edit the ` ` tag in it to change the title from “React App” to anything else. @@ -277,10 +333,18 @@ If you use a custom server for your app in production and want to modify the tit The generated project includes React and ReactDOM as dependencies. It also includes a set of scripts used by Create React App as a development dependency. You may install other dependencies (for example, React Router) with `npm`: +```sh +npm install --save react-router ``` -npm install --save + +Alternatively you may use `yarn`: + +```sh +yarn add react-router ``` +This works for any library, not just `react-router`. + ## Importing a Component This project setup supports ES6 modules thanks to Babel.
@@ -377,6 +441,10 @@ This will make `moduleA.js` and all its unique dependencies as a separate chunk You can also use it with `async` / `await` syntax if you prefer it. +### With React Router + +If you are using React Router check out [this tutorial](http://serverless-stack.com/chapters/code-splitting-in-create-react-app.html) on how to use code splitting with it. You can find the companion GitHub repository [here](https://github.com/AnomalyInnovations/serverless-stack-demo-client/tree/code-splitting-in-create-react-app). + ## Adding a Stylesheet This project setup uses [Webpack](https://webpack.js.org/) for handling all assets. Webpack offers a custom way of “extending” the concept of `import` beyond JavaScript. To express that a JavaScript file depends on a CSS file, you need to **import the CSS from the JavaScript file**: @@ -450,9 +518,16 @@ Following this rule often makes CSS preprocessors less useful, as features like First, let’s install the command-line interface for Sass: +```sh +npm install --save node-sass-chokidar ``` -npm install node-sass-chokidar --save-dev + +Alternatively you may use `yarn`: + +```sh +yarn add node-sass-chokidar ``` + Then in `package.json`, add the following lines to `scripts`: ```diff @@ -488,8 +563,14 @@ At this point you might want to remove all CSS files from the source control, an As a final step, you may find it convenient to run `watch-css` automatically with `npm start`, and run `build-css` as a part of `npm run build`. You can use the `&&` operator to execute two scripts sequentially. However, there is no cross-platform way to run two scripts in parallel, so we will install a package for this: +```sh +npm install --save npm-run-all ``` -npm install --save-dev npm-run-all + +Alternatively you may use `yarn`: + +```sh +yarn add npm-run-all ``` Then we can change `start` and `build` scripts to include the CSS preprocessor commands: @@ -647,9 +728,14 @@ You don’t have to use [React Bootstrap](https://react-bootstrap.github.io) tog Install React Bootstrap and Bootstrap from npm. React Bootstrap does not include Bootstrap CSS so this needs to be installed as well: +```sh +npm install --save react-bootstrap bootstrap@3 ``` -npm install react-bootstrap --save -npm install bootstrap@3 --save + +Alternatively you may use `yarn`: + +```sh +yarn add react-bootstrap bootstrap@3 ``` Import Bootstrap CSS and optionally Bootstrap theme CSS in the beginning of your ```src/index.js``` file: @@ -688,9 +774,9 @@ Recent versions of [Flow](http://flowtype.org/) work with Create React App proje To add Flow to a Create React App project, follow these steps: -1. Run `npm install --save-dev flow-bin` (or `yarn add --dev flow-bin`). +1. Run `npm install --save flow-bin` (or `yarn add flow-bin`). 2. Add `"flow": "flow"` to the `scripts` section of your `package.json`. -3. Run `npm run flow -- init` (or `yarn flow -- init`) to create a [`.flowconfig` file](https://flowtype.org/docs/advanced-configuration.html) in the root directory. +3. Run `npm run flow init` (or `yarn flow init`) to create a [`.flowconfig` file](https://flowtype.org/docs/advanced-configuration.html) in the root directory. 4. Add `// @flow` to any files you want to type check (for example, to `src/App.js`). Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors. @@ -972,7 +1058,7 @@ You may also narrow down matches using `*` and/or `**`, to match the path exactl "target": "", // ... }, - // Matches /bar/abc.html and /bar/sub/def.html + // Matches /baz/abc.html and /baz/sub/def.html "/baz/**/*.html": { "target": " " // ... @@ -982,6 +1068,36 @@ You may also narrow down matches using `*` and/or `**`, to match the path exactl } ``` +### Configuring a WebSocket Proxy + +When setting up a WebSocket proxy, there are a some extra considerations to be aware of. + +If you’re using a WebSocket engine like [Socket.io](https://socket.io/), you must have a Socket.io server running that you can use as the proxy target. Socket.io will not work with a standard WebSocket server. Specifically, don't expect Socket.io to work with [the websocket.org echo test](http://websocket.org/echo.html). + +There’s some good documentation available for [setting up a Socket.io server](https://socket.io/docs/). + +Standard WebSockets **will** work with a standard WebSocket server as well as the websocket.org echo test. You can use libraries like [ws](https://github.com/websockets/ws) for the server, with [native WebSockets in the browser](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket). + +Either way, you can proxy WebSocket requests manually in `package.json`: + +```js +{ + // ... + "proxy": { + "/socket": { + // Your compatible WebSocket server + "target": "ws:// ", + // Tell http-proxy-middleware that this is a WebSocket proxy. + // Also allows you to proxy WebSocket requests without an additional HTTP request + // https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade + "ws": true + // ... + } + } + // ... +} +``` + ## Using HTTPS in Development >Note: this feature is available with `react-scripts@0.4.0` and higher. @@ -1082,7 +1198,7 @@ The watcher includes an interactive command-line interface with the ability to r ### Version Control Integration -By default, when you run `npm test`, Jest will only run the tests related to files changed since the last commit. This is an optimization designed to make your tests runs fast regardless of how many tests you have. However it assumes that you don’t often commit the code that doesn’t pass the tests. +By default, when you run `npm test`, Jest will only run the tests related to files changed since the last commit. This is an optimization designed to make your tests run fast regardless of how many tests you have. However it assumes that you don’t often commit the code that doesn’t pass the tests. Jest will always explicitly mention that it only ran tests related to the files changed since the last commit. You can also press `a` in the watch mode to force Jest to run all tests. @@ -1127,12 +1243,20 @@ This test mounts a component and makes sure that it didn’t throw during render When you encounter bugs caused by changing components, you will gain a deeper insight into which parts of them are worth testing in your application. This might be a good time to introduce more specific tests asserting specific expected output or behavior. -If you’d like to test components in isolation from the child components they render, we recommend using [`shallow()` rendering API](http://airbnb.io/enzyme/docs/api/shallow.html) from [Enzyme](http://airbnb.io/enzyme/). You can write a smoke test with it too: +If you’d like to test components in isolation from the child components they render, we recommend using [`shallow()` rendering API](http://airbnb.io/enzyme/docs/api/shallow.html) from [Enzyme](http://airbnb.io/enzyme/). To install it, run: + +```sh +npm install --save enzyme react-test-renderer +``` + +Alternatively you may use `yarn`: ```sh -npm install --save-dev enzyme react-test-renderer +yarn add enzyme react-test-renderer ``` +You can write a smoke test with it too: + ```js import React from 'react'; import { shallow } from 'enzyme'; @@ -1171,18 +1295,24 @@ Additionally, you might find [jest-enzyme](https://github.com/blainekasten/enzym expect(wrapper).toContainReact(welcome) ``` -To setup jest-enzyme with Create React App, follow the instructions for [initializing your test environment](#initializing-test-environment) to import `jest-enzyme`. **Note that currently only version 2.x is compatible with Create React App.** +To enable this, install `jest-enzyme`: ```sh -npm install --save-dev jest-enzyme@2.x +npm install --save jest-enzyme ``` +Alternatively you may use `yarn`: + +```sh +yarn add jest-enzyme +``` + +Import it in [`src/setupTests.js`](#initializing-test-environment) to make its matchers available in every test: + ```js -// src/setupTests.js import 'jest-enzyme'; ``` - ### Using Third Party Assertion Libraries We recommend that you use `expect()` for assertions and `jest.fn()` for spies. If you are having issues with them please [file those against Jest](https://github.com/facebook/jest/issues/new), and we’ll fix them. We intend to keep making them better for React, supporting, for example, [pretty-printing React elements as JSX](https://github.com/facebook/jest/pull/1566). @@ -1244,7 +1374,6 @@ Popular CI servers already set the environment variable `CI` by default but you ``` language: node_js node_js: - - 4 - 6 cache: directories: @@ -1256,6 +1385,10 @@ script: 1. Trigger your first build with a git push. 1. [Customize your Travis CI Build](https://docs.travis-ci.com/user/customizing-the-build/) if needed. +#### CircleCI + +Follow [this article](https://medium.com/@knowbody/circleci-and-zeits-now-sh-c9b7eebcd3c1) to set up CircleCI with a Create React App project. + ### On your own environment ##### Windows (cmd.exe) @@ -1290,14 +1423,22 @@ The build command will check for linter warnings and fail if any are found. By default, the `package.json` of the generated project looks like this: ```js - // ... "scripts": { - // ... + "start": "react-scripts start", + "build": "react-scripts build", "test": "react-scripts test --env=jsdom" - } ``` -If you know that none of your tests depend on [jsdom](https://github.com/tmpvar/jsdom), you can safely remove `--env=jsdom`, and your tests will run faster.
+If you know that none of your tests depend on [jsdom](https://github.com/tmpvar/jsdom), you can safely remove `--env=jsdom`, and your tests will run faster: + +```diff + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", +- "test": "react-scripts test --env=jsdom" ++ "test": "react-scripts test" +``` + To help you make up your mind, here is a list of APIs that **need jsdom**: * Any browser globals like `window` and `document` @@ -1322,30 +1463,31 @@ If you use [Visual Studio Code](https://code.visualstudio.com), there is a [Jest  - +* [GitHub Repo](https://github.com/storybooks/storybook) +* [Documentation](https://storybook.js.org/basics/introduction/) +* [Snapshot Testing UI](https://github.com/storybooks/storybook/tree/master/addons/storyshots) with Storybook + addon/storyshot + +### Getting Started with Styleguidist + +Styleguidist combines a style guide, where all your components are presented on a single page with their props documentation and usage examples, with an environment for developing components in isolation, similar to Storybook. In Styleguidist you write examples in Markdown, where each code snippet is rendered as a live editable playground. + +First, install Styleguidist: + +```sh +npm install --save react-styleguidist +``` + +Alternatively you may use `yarn`: + +```sh +yarn add react-styleguidist +``` + +Then, add these scripts to your `package.json`: + +```diff + "scripts": { ++ "styleguide": "styleguidist server", ++ "styleguide:build": "styleguidist build", + "start": "react-scripts start", +``` + +Then, run the following command inside your app’s directory: + +```sh +npm run styleguide +``` + +After that, follow the instructions on the screen. + +Learn more about React Styleguidist: + +* [GitHub Repo](https://github.com/styleguidist/react-styleguidist) +* [Documentation](https://react-styleguidist.js.org/docs/getting-started.html) ## Making a Progressive Web App @@ -1381,7 +1560,7 @@ and it will take care of generating a service worker file that will automaticall precache all of your local assets and keep them up to date as you deploy updates. The service worker will use a [cache-first strategy](https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-falling-back-to-network) for handling all requests for local assets, including the initial HTML, ensuring -that you web app is reliably fast, even on a slow or unreliable network. +that your web app is reliably fast, even on a slow or unreliable network. If you would prefer not to enable service workers prior to your initial production deployment, then remove the call to `serviceWorkerRegistration.register()` @@ -1464,6 +1643,52 @@ icons, names, and branding colors to use when the web app is displayed. provides more context about what each field means, and how your customizations will affect your users' experience. +## Analyzing the Bundle Size + +[Source map explorer](https://www.npmjs.com/package/source-map-explorer) analyzes +JavaScript bundles using the source maps. This helps you understand where code +bloat is coming from. + +To add Source map explorer to a Create React App project, follow these steps: + +```sh +npm install --save source-map-explorer +``` + +Alternatively you may use `yarn`: + +```sh +yarn add source-map-explorer +``` + +Then in `package.json`, add the following line to `scripts`: + +```diff + "scripts": { ++ "analyze": "source-map-explorer build/static/js/main.*", + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test --env=jsdom", +``` + +>**Note:** +> +>This doesn't quite work on Windows because it doesn't automatically expand `*` in the filepath. For now, the workaround is to look at the full hashed filename in `build/static/js` (e.g. `main.89b7e95a.js`) and copy it into `package.json` when you're running the analyzer. For example: +> +>```diff +>+ "analyze": "source-map-explorer build/static/js/main.89b7e95a.js", +>``` +> +>Unfortunately it will be different after every build. You can express support for fixing this on Windows [in this issue](https://github.com/danvk/source-map-explorer/issues/52). + +Then to analyze the bundle run the production build then run the analyze +script. + +``` +npm run build +npm run analyze +``` + ## Deployment `npm run build` creates a `build` directory with a production build of your app. Set up your favourite HTTP server so that a visitor to your site is served `index.html`, and requests to static paths like `/static/js/main..js` are served with the contents of the `/static/js/main. .js` file. @@ -1526,7 +1751,7 @@ This is because when there is a fresh page load for a `/todos/42`, the server lo }); ``` -If you’re using [Apache](https://httpd.apache.org/), you need to create a `.htaccess` file in the `public` folder that looks like this: +If you’re using [Apache HTTP Server](https://httpd.apache.org/), you need to create a `.htaccess` file in the `public` folder that looks like this: ``` Options -MultiViews @@ -1535,7 +1760,9 @@ If you’re using [Apache](https://httpd.apache.org/), you need to create a `.ht RewriteRule ^ index.html [QSA,L] ``` -It will get copied to the `build` folder when you run `npm run build`. +It will get copied to the `build` folder when you run `npm run build`. + +If you’re using [Apache Tomcat](http://tomcat.apache.org/), you need to follow [this Stack Overflow answer](https://stackoverflow.com/a/41249464/4878474). Now requests to `/todos/42` will be handled correctly both in development and in production. @@ -1660,18 +1887,23 @@ Now, whenever you run `npm run build`, you will see a cheat sheet with instructi To publish it at [https://myusername.github.io/my-app](https://myusername.github.io/my-app), run: ```sh -npm install --save-dev gh-pages +npm install --save gh-pages +``` + +Alternatively you may use `yarn`: + +```sh +yarn add gh-pages ``` Add the following scripts in your `package.json`: -```js - // ... +```diff "scripts": { - // ... - "predeploy": "npm run build", - "deploy": "gh-pages -d build" - } ++ "predeploy": "npm run build", ++ "deploy": "gh-pages -d build", + "start": "react-scripts start", + "build": "react-scripts build", ``` The `predeploy` script will run automatically before `deploy` is run. @@ -1698,7 +1930,7 @@ You can configure a custom domain with GitHub Pages by adding a `CNAME` file to GitHub Pages doesn’t support routers that use the HTML5 `pushState` history API under the hood (for example, React Router using `browserHistory`). This is because when there is a fresh page load for a url like `http://user.github.io/todomvc/todos/42`, where `/todos/42` is a frontend route, the GitHub Pages server returns 404 because it knows nothing of `/todos/42`. If you want to add a router to a project hosted on GitHub Pages, here are a couple of solutions: -* You could switch from using HTML5 history API to routing with hashes. If you use React Router, you can switch to `hashHistory` for this effect, but the URL will be longer and more verbose (for example, `http://user.github.io/todomvc/#/todos/42?_k=yknaj`). [Read more](https://github.com/reactjs/react-router/blob/master/docs/guides/Histories.md#histories) about different history implementations in React Router. +* You could switch from using HTML5 history API to routing with hashes. If you use React Router, you can switch to `hashHistory` for this effect, but the URL will be longer and more verbose (for example, `http://user.github.io/todomvc/#/todos/42?_k=yknaj`). [Read more](https://reacttraining.com/react-router/web/api/Router) about different history implementations in React Router. * Alternatively, you can use a trick to teach GitHub Pages to handle 404 by redirecting to your `index.html` page with a special redirect parameter. You would need to add a `404.html` file with the redirection code to the `build` folder before deploying your project, and you’ll need to add code handling the redirect parameter to `index.html`. You can find a detailed explanation of this technique [in this guide](https://github.com/rafrex/spa-github-pages). ### Heroku @@ -1774,27 +2006,23 @@ When you build the project, Create React App will place the `public` folder cont ### Now -[now](https://zeit.co/now) offers a zero-configuration single-command deployment. +[now](https://zeit.co/now) offers a zero-configuration single-command deployment. You can use `now` to deploy your app for free. 1. Install the `now` command-line tool either via the recommended [desktop tool](https://zeit.co/download) or via node with `npm install -g now`. -2. Install `serve` by running `npm install --save serve`. +2. Build your app by running `npm run build`. -3. Add this line to `scripts` in `package.json`: +3. Move into the build directory by running `cd build`. - ``` - "now-start": "serve -s build/", - ``` - -4. Run `now` from your project directory. You will see a **now.sh** URL in your output like this: +4. Run `now --name your-project-name` from within the build directory. You will see a **now.sh** URL in your output like this: ``` - > Ready! https://your-project-dirname-tpspyhtdtk.now.sh (copied to clipboard) + > Ready! https://your-project-name-tpspyhtdtk.now.sh (copied to clipboard) ``` Paste that URL into your browser when the build is complete, and you will see your deployed app. -Details are available in [this article.](https://zeit.co/blog/now-static) +Details are available in [this article.](https://zeit.co/blog/unlimited-static) ### S3 and CloudFront @@ -1824,6 +2052,7 @@ PORT | :white_check_mark: | :x: | By default, the development web server will at HTTPS | :white_check_mark: | :x: | When set to `true`, Create React App will run the development server in `https` mode. PUBLIC_URL | :x: | :white_check_mark: | Create React App assumes your application is hosted at the serving web server's root or a subpath as specified in [`package.json` (`homepage`)](#building-for-relative-paths). Normally, Create React App ignores the hostname. You may use this variable to force assets to be referenced verbatim to the url you provide (hostname included). This may be particularly useful when using a CDN to host your application. CI | :large_orange_diamond: | :white_check_mark: | When set to `true`, Create React App treats warnings as failures in the build. It also makes the test runner non-watching. Most CIs set this flag by default. +REACT_EDITOR | :white_check_mark: | :x: | When an app crashes in development, you will see an error overlay with clickable stack trace. When you click on it, Create React App will try to determine the editor you are using based on currently running processes, and open the relevant source file. You can [send a pull request to detect your editor of choice](https://github.com/facebookincubator/create-react-app/issues/2636). Setting this environment variable overrides the automatic detection. If you do it, make sure your systems [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) environment variable points to your editor’s bin folder. ## Troubleshooting @@ -1865,9 +2094,13 @@ If this still doesn’t help, try running `launchctl unload -F ~/Library/LaunchA There are also reports that *uninstalling* Watchman fixes the issue. So if nothing else helps, remove it from your system and try again. -### `npm run build` silently fails +### `npm run build` exits too early + +It is reported that `npm run build` can fail on machines with limited memory and no swap space, which is common in cloud environments. Even with small projects this command can increase RAM usage in your system by hundreds of megabytes, so if you have less than 1 GB of available memory your build is likely to fail with the following message: + +> The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process. -It is reported that `npm run build` can fail on machines with no swap space, which is common in cloud environments. If [the symptoms are matching](https://github.com/facebookincubator/create-react-app/issues/1133#issuecomment-264612171), consider adding some swap space to the machine you’re building on, or build the project locally. +If you are completely sure that you didn't terminate the process, consider [adding some swap space](https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04) to the machine you’re building on, or build the project locally. ### `npm run build` fails on Heroku diff --git a/packages/react-scripts/template/src/registerServiceWorker.ts b/packages/react-scripts/template/src/registerServiceWorker.ts index 69e361673..11c4bc72c 100644 --- a/packages/react-scripts/template/src/registerServiceWorker.ts +++ b/packages/react-scripts/template/src/registerServiceWorker.ts @@ -1,49 +1,108 @@ +// tslint:disable:no-console // In production, we register a service worker to serve assets from local cache. // This lets the app load faster on subsequent visits in production, and gives // it offline capabilities. However, it also means that developers (and users) -// will only see deployed updates on the "N+1" visit to a page, since previously +// will only see deployed updates on the 'N+1' visit to a page, since previously // cached resources are updated in the background. // To learn more about the benefits of this model, read https://goo.gl/KwvDNy. // This link also includes instructions on opting out of this behavior. +const isLocalhost = Boolean( + window.location.hostname === 'localhost' || + // [::1] is the IPv6 localhost address. + window.location.hostname === '[::1]' || + // 127.0.0.1/8 is considered localhost for IPv4. + window.location.hostname.match( + /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ + ) +); + export default function register() { if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { + // The URL constructor is available in all browsers that support SW. + const publicUrl = new URL( + process.env.PUBLIC_URL!, + window.location.toString() + ); + if (publicUrl.origin !== window.location.origin) { + // Our service worker won't work if PUBLIC_URL is on a different origin + // from what our page is served on. This might happen if a CDN is used to + // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374 + return; + } + window.addEventListener('load', () => { const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; - navigator.serviceWorker - .register(swUrl) - .then(registration => { - registration.onupdatefound = () => { - const installingWorker = registration.installing; - if (!installingWorker) { - return; - } - installingWorker.onstatechange = () => { - if (installingWorker.state === 'installed') { - if (navigator.serviceWorker.controller) { - // At this point, the old content will have been purged and - // the fresh content will have been added to the cache. - // It's the perfect time to display a "New content is - // available; please refresh." message in your web app. - console.log('New content is available; please refresh.'); // tslint:disable-line - } else { - // At this point, everything has been precached. - // It's the perfect time to display a - // "Content is cached for offline use." message. - console.log('Content is cached for offline use.'); // tslint:disable-line - } + if (!isLocalhost) { + // Is not local host. Just register service worker + registerValidSW(swUrl); + } else { + // This is running on localhost. Lets check if a service worker still exists or not. + checkValidServiceWorker(swUrl); + } + }); + } +} + +function registerValidSW(swUrl: string) { + navigator.serviceWorker + .register(swUrl) + .then(registration => { + registration.onupdatefound = () => { + const installingWorker = registration.installing; + if (installingWorker) { + installingWorker.onstatechange = () => { + if (installingWorker.state === 'installed') { + if (navigator.serviceWorker.controller) { + // At this point, the old content will have been purged and + // the fresh content will have been added to the cache. + // It's the perfect time to display a 'New content is + // available; please refresh.' message in your web app. + console.log('New content is available; please refresh.'); + } else { + // At this point, everything has been precached. + // It's the perfect time to display a + // 'Content is cached for offline use.' message. + console.log('Content is cached for offline use.'); } - }; + } }; - }) - .catch(error => { - console.error('Error during service worker registration:', error); // tslint:disable-line + } + }; + }) + .catch(error => { + console.error('Error during service worker registration:', error); + }); +} + +function checkValidServiceWorker(swUrl: string) { + // Check if the service worker can be found. If it can't reload the page. + fetch(swUrl) + .then(response => { + // Ensure service worker exists, and that we really are getting a JS file. + if ( + response.status === 404 || + response.headers.get('content-type')!.indexOf('javascript') === -1 + ) { + // No service worker found. Probably a different app. Reload the page. + navigator.serviceWorker.ready.then(registration => { + registration.unregister().then(() => { + window.location.reload(); + }); }); + } else { + // Service worker found. Proceed as normal. + registerValidSW(swUrl); + } + }) + .catch(() => { + console.log( + 'No internet connection found. App is running in offline mode.' + ); }); - } } export function unregister() { diff --git a/tasks/e2e-installs.sh b/tasks/e2e-installs.sh index b27b1239e..588642632 100755 --- a/tasks/e2e-installs.sh +++ b/tasks/e2e-installs.sh @@ -55,15 +55,6 @@ function checkDependencies { echo "There are extraneous dependencies in package.json" exit 1 fi - - - if ! awk '/"devDependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \ - grep -v -q -E '^\s*"react(-dom|-scripts)?"'; then - echo "Dev Dependencies are correct" - else - echo "There are extraneous devDependencies in package.json" - exit 1 - fi } function create_react_app { @@ -83,9 +74,37 @@ set -x cd .. root_path=$PWD -# Prevent lerna bootstrap, we only want top-level dependencies +# Clear cache to avoid issues with incorrect packages being used +if hash yarnpkg 2>/dev/null +then + # AppVeyor uses an old version of yarn. + # Once updated to 0.24.3 or above, the workaround can be removed + # and replaced with `yarnpkg cache clean` + # Issues: + # https://github.com/yarnpkg/yarn/issues/2591 + # https://github.com/appveyor/ci/issues/1576 + # https://github.com/facebookincubator/create-react-app/pull/2400 + # When removing workaround, you may run into + # https://github.com/facebookincubator/create-react-app/issues/2030 + case "$(uname -s)" in + *CYGWIN*|MSYS*|MINGW*) yarn=yarn.cmd;; + *) yarn=yarnpkg;; + esac + $yarn cache clean +fi + +if hash npm 2>/dev/null +then + # npm 5 is too buggy right now + if [ $(npm -v | head -c 1) -eq 5 ]; then + npm i -g npm@^4.x + fi; + npm cache clean || npm cache verify +fi + +# Prevent bootstrap, we only want top-level dependencies cp package.json package.json.bak -grep -v "lerna bootstrap" package.json > temp && mv temp package.json +grep -v "postinstall" package.json > temp && mv temp package.json npm install mv package.json.bak package.json @@ -97,7 +116,7 @@ then fi # We removed the postinstall, so do it manually -./node_modules/.bin/lerna bootstrap --concurrency=1 +node bootstrap.js cd packages/react-error-overlay/ npm run build:prod diff --git a/tasks/e2e-kitchensink.sh b/tasks/e2e-kitchensink.sh index 2295615e8..ebbac271e 100755 --- a/tasks/e2e-kitchensink.sh +++ b/tasks/e2e-kitchensink.sh @@ -22,7 +22,7 @@ temp_module_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_module_path'` function cleanup { echo 'Cleaning up.' - ps -ef | grep 'react-scripts' | grep -v grep | awk '{print $2}' | xargs kill -s 9 + ps -ef | grep 'react-scripts' | grep -v grep | awk '{print $2}' | xargs kill -9 cd "$root_path" # TODO: fix "Device or resource busy" and remove ``|| $CI` rm -rf "$temp_cli_path" "$temp_app_path" "$temp_module_path" || $CI @@ -66,9 +66,37 @@ set -x cd .. root_path=$PWD -# Prevent lerna bootstrap, we only want top-level dependencies +# Clear cache to avoid issues with incorrect packages being used +if hash yarnpkg 2>/dev/null +then + # AppVeyor uses an old version of yarn. + # Once updated to 0.24.3 or above, the workaround can be removed + # and replaced with `yarnpkg cache clean` + # Issues: + # https://github.com/yarnpkg/yarn/issues/2591 + # https://github.com/appveyor/ci/issues/1576 + # https://github.com/facebookincubator/create-react-app/pull/2400 + # When removing workaround, you may run into + # https://github.com/facebookincubator/create-react-app/issues/2030 + case "$(uname -s)" in + *CYGWIN*|MSYS*|MINGW*) yarn=yarn.cmd;; + *) yarn=yarnpkg;; + esac + $yarn cache clean +fi + +if hash npm 2>/dev/null +then + # npm 5 is too buggy right now + if [ $(npm -v | head -c 1) -eq 5 ]; then + npm i -g npm@^4.x + fi; + npm cache clean || npm cache verify +fi + +# Prevent bootstrap, we only want top-level dependencies cp package.json package.json.bak -grep -v "lerna bootstrap" package.json > temp && mv temp package.json +grep -v "postinstall" package.json > temp && mv temp package.json npm install mv package.json.bak package.json @@ -80,7 +108,7 @@ then fi # We removed the postinstall, so do it manually -./node_modules/.bin/lerna bootstrap --concurrency=1 +node bootstrap.js cd packages/react-error-overlay/ npm run build:prod @@ -156,7 +184,7 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ CI=true \ NODE_PATH=src \ NODE_ENV=test \ - npm test -- --no-cache --testPathPattern="/src/" + npm test -- --no-cache --testPathPattern=src # Test "development" environment tmp_server_log=`mktemp` @@ -220,7 +248,7 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ CI=true \ NODE_PATH=src \ NODE_ENV=test \ - npm test -- --no-cache --testPathPattern='/src/' + npm test -- --no-cache --testPathPattern=src # Test "development" environment tmp_server_log=`mktemp` diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index 72a3698a3..2918fc0f5 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -65,9 +65,37 @@ set -x cd .. root_path=$PWD -# Prevent lerna bootstrap, we only want top-level dependencies +# Clear cache to avoid issues with incorrect packages being used +if hash yarnpkg 2>/dev/null +then + # AppVeyor uses an old version of yarn. + # Once updated to 0.24.3 or above, the workaround can be removed + # and replaced with `yarnpkg cache clean` + # Issues: + # https://github.com/yarnpkg/yarn/issues/2591 + # https://github.com/appveyor/ci/issues/1576 + # https://github.com/facebookincubator/create-react-app/pull/2400 + # When removing workaround, you may run into + # https://github.com/facebookincubator/create-react-app/issues/2030 + case "$(uname -s)" in + *CYGWIN*|MSYS*|MINGW*) yarn=yarn.cmd;; + *) yarn=yarnpkg;; + esac + $yarn cache clean +fi + +if hash npm 2>/dev/null +then + # npm 5 is too buggy right now + if [ $(npm -v | head -c 1) -eq 5 ]; then + npm i -g npm@^4.x + fi; + npm cache clean || npm cache verify +fi + +# Prevent bootstrap, we only want top-level dependencies cp package.json package.json.bak -grep -v "lerna bootstrap" package.json > temp && mv temp package.json +grep -v "postinstall" package.json > temp && mv temp package.json npm install mv package.json.bak package.json @@ -87,9 +115,6 @@ then [[ $err_output =~ You\ are\ running\ Node ]] && exit 0 || exit 1 fi -# We removed the postinstall, so do it manually here -./node_modules/.bin/lerna bootstrap --concurrency=1 - if [ "$USE_YARN" = "yes" ] then # Install Yarn so that the test can use it to install packages. @@ -97,6 +122,9 @@ then yarn cache clean fi +# We removed the postinstall, so do it manually here +node bootstrap.js + # Lint own code ./node_modules/.bin/eslint --max-warnings 0 packages/babel-preset-react-app/ ./node_modules/.bin/eslint --max-warnings 0 packages/create-react-app/ diff --git a/tasks/local-test.sh b/tasks/local-test.sh new file mode 100755 index 000000000..42d98ffcd --- /dev/null +++ b/tasks/local-test.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash + +function print_help { + echo "Usage: ${0} [OPTIONS]" + echo "" + echo "OPTIONS:" + echo " --node-version the node version to use while testing [6]" + echo " --git-branch the git branch to checkout for testing [the current one]" + echo " --test-suite which test suite to use ('simple', installs', 'kitchensink', 'all') ['all']" + echo " --yarn if present, use yarn as the package manager" + echo " --interactive gain a bash shell after the test run" + echo " --help print this message and exit" + echo "" +} + +cd $(dirname $0) + +node_version=6 +current_git_branch=`git rev-parse --abbrev-ref HEAD` +git_branch=${current_git_branch} +use_yarn=no +test_suite=all +interactive=false + +while [ "$1" != "" ]; do + case $1 in + "--node-version") + shift + node_version=$1 + ;; + "--git-branch") + shift + git_branch=$1 + ;; + "--yarn") + use_yarn=yes + ;; + "--test-suite") + shift + test_suite=$1 + ;; + "--interactive") + interactive=true + ;; + "--help") + print_help + exit 0 + ;; + esac + shift +done + +test_command="./tasks/e2e-simple.sh && ./tasks/e2e-kitchensink.sh && ./tasks/e2e-installs.sh" +case ${test_suite} in + "all") + ;; + "simple") + test_command="./tasks/e2e-simple.sh" + ;; + "kitchensink") + test_command="./tasks/e2e-kitchensink.sh" + ;; + "installs") + test_command="./tasks/e2e-installs.sh" + ;; + *) + ;; +esac + +read -r -d '' apply_changes <<- CMD +cd /var/create-react-app +git config --global user.name "Create React App" +git config --global user.email "cra@email.com" +git stash save -u +git stash show -p > patch +git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 stash^3 >> patch +git stash pop +cd - +mv /var/create-react-app/patch . +git apply patch +rm patch +CMD + +if [ ${git_branch} != ${current_git_branch} ]; then + apply_changes='' +fi + +read -r -d '' command <<- CMD +echo "prefix=~/.npm" > ~/.npmrc +mkdir ~/.npm +export PATH=\$PATH:~/.npm/bin +set -x +git clone /var/create-react-app create-react-app --branch ${git_branch} +cd create-react-app +${apply_changes} +node --version +npm --version +set +x +${test_command} && echo -e "\n\e[1;32m✔ Job passed\e[0m" || echo -e "\n\e[1;31m✘ Job failes\e[0m" +$([[ ${interactive} == 'true' ]] && echo 'bash') +CMD + +docker run \ + --env CI=true \ + --env NPM_CONFIG_QUIET=true \ + --env USE_YARN=${use_yarn} \ + --tty \ + --user node \ + --volume ${PWD}/..:/var/create-react-app \ + --workdir /home/node \ + $([[ ${interactive} == 'true' ]] && echo '--interactive') \ + node:${node_version} \ + bash -c "${command}"