Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching from yarn to npm #2329

Merged
merged 4 commits into from Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -21,6 +21,5 @@ notifications:
after_success: 'npm run coveralls'

cache:
yarn: true
directories:
- node_modules
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -100,11 +100,10 @@ There’s also a <a href="https://vimeo.com/168648012">fantastic video</a> on ho

## Quick start

1. Make sure that you have Node v8 or above installed.
1. Make sure that you have Node.js v8.10 and npm v5 or above installed.
2. Clone this repo using `git clone --depth=1 https://github.com/react-boilerplate/react-boilerplate.git`
3. Move to the appropriate directory: `cd react-boilerplate`.<br />
4. Run `npm run setup` in order to install dependencies and clean the git repo.<br />
_We auto-detect `yarn` for installing packages by default, if you wish to force `npm` usage do: `USE_YARN=false npm run setup`_<br />
_At this point you can run `npm start` to see the example app at `http://localhost:3000`._
5. Run `npm run clean` to delete the example app.

Expand Down
11 changes: 5 additions & 6 deletions appveyor.yml
Expand Up @@ -24,8 +24,8 @@ install:
- choco install -y googlechrome --ignore-checksums
# Install the latest stable version of Node
- ps: Install-Product node $env:nodejs_version
- set PATH=%APPDATA%\yarn;%PATH%
- yarn
- npm install npm -g
- npm ci

# Disable automatic builds
build: off
Expand All @@ -36,15 +36,14 @@ test_script:
- node --version
- node ./internals/scripts/generate-templates-for-linting
# run tests and run build
- yarn run test
- yarn run build
- npm run test
- npm run build

# Cache node_modules for faster builds
cache:
- "%LOCALAPPDATA%\\Yarn"
- node_modules -> package.json

# remove, as appveyor doesn't support secure variables on pr builds
# so `COVERALLS_REPO_TOKEN` cannot be set, without hard-coding in this file
#on_success:
#- yarn run coveralls
#- npm run coveralls
2 changes: 1 addition & 1 deletion docs/general/deployment.md
Expand Up @@ -22,7 +22,7 @@ _Step 5:_ Follow the standard Heroku deploy process:

### Easy 7-Step Deployment Process

_Step 1:_ Run `yarn` to install dependencies, then `npm run build` to create the `./build` folder.
_Step 1:_ Run `npm install` to install dependencies, then `npm run build` to create the `./build` folder.

_Step 2:_ Navigate to [AWS S3](https://aws.amazon.com/s3) and login (or sign up if you don't have an account). Click on `Services` followed by `S3` in the dropdown.

Expand Down
17 changes: 3 additions & 14 deletions docs/general/faq.md
Expand Up @@ -5,17 +5,15 @@
- [Where are Babel, Prettier and ESLint configured?](#where-are-babel-prettier-and-eslint-configured)
- [Where are the files coming from when I run `npm start`?](#where-are-the-files-coming-from-when-i-run-npm-start)
- [How do I fix `Error: listen EADDRINUSE 127.0.0.1:3000`?](#how-do-i-fix-error-listen-eaddrinuse-1270013000)
- [OS X / Linux](#os-x-linux)
- [OS X / Linux:](#os-x--linux)
- [Windows](#windows)
- [Issue with local caching when running in production mode (F5 / ctrl+F5 / cmd+r weird behavior)](#issue-with-local-caching-when-running-in-production-mode-f5--ctrlf5--cmdr-weird-behavior)
- [Quick fix on your local browser:](#quick-fix-on-your-local-browser)
- [Full in-depth explanation](#full-in-depth-explanation)
- [Quick fix on your local browser:](#quick-fix-on-your-local-browser)
- [Full in-depth explanation](#full-in-depth-explanation)
- [Local webfonts not working for development](#local-webfonts-not-working-for-development)
- [Non-route containers](#non-route-containers)
- [Where do I put the reducer?](#where-do-i-put-the-reducer)
- [How do I run the saga?](#how-do-i-run-the-saga)
- [Use CI with bitbucket pipelines](#use-ci-with-bitbucket-pipelines)
- [I'm using Node v0.12 and the server doesn't work?](#im-using-node-v012-and-the-server-doesnt-work)
- [How to keep my project up-to-date with `react-boilerplate`?](#how-to-keep-my-project-up-to-date-with-react-boilerplate)
- [How to turn off Webpack performance warnings after production build?](#how-to-turn-off-webpack-performance-warnings-after-production-build)
- [Styles getting overridden?](#styles-getting-overridden)
Expand Down Expand Up @@ -163,15 +161,6 @@ pipelines:
- npm test
```

## I'm using Node v0.12 and the server doesn't work?

We settled on supporting the last three major Node.js versions for the boilerplate – at the moment
of this writing those are v5, v6 and v7. We **highly recommend upgrading to a newer Node.js version**!

If you _have_ to use Node.js 0.12, you can hack around the server not running by using `babel-cli` to
run the server: `npm install babel-cli`, and then replace all instances of `node server` in the `"scripts"`
in the `package.json` with `babel server`!

## How to keep my project up-to-date with `react-boilerplate`?

While it's possible to keep your project up-to-date or "in sync" with `react-boilerplate`, it's usually
Expand Down
21 changes: 10 additions & 11 deletions docs/general/gotchas.md
Expand Up @@ -2,13 +2,13 @@

These are some things to be aware of when using this boilerplate.

1. [Special images in HTML files](#special-images-in-html-files)
2. [Load reducers optimistically](#load-reducers-optimistically)
3. [Exclude modules from Babel processing](#exclude-modules-from-babel-processing)
4. [Running tests in watch mode](#running-tests-in-watch-mode)
5. [When in doubt, re-install!](#when-in-doubt-re-install)
6. [Cleaning up Jest cache](#cleaning-up-jest-cache)
7. [Using short_name in Web App manifest](#using-short_name-in-web-app-manifest)
- [Special images in HTML files](#special-images-in-html-files)
- [Load reducers optimistically](#load-reducers-optimistically)
- [Exclude modules from Babel processing](#exclude-modules-from-babel-processing)
- [Running tests in `watch` mode](#running-tests-in-watch-mode)
- [When in doubt, re-install!](#when-in-doubt-re-install)
- [Cleaning up Jest cache](#cleaning-up-jest-cache)
- [Using short_name in Web App manifest](#using-short_name-in-web-app-manifest)

## Special images in HTML files

Expand Down Expand Up @@ -86,13 +86,12 @@ Remove node_modules

- `rm -rf node_modules`

Using yarn (recommended)
Clear cache

- `yarn install`
- `npm cache clean`

Using npm
Re-install dependencies

- `npm cache clean`
- `npm install`

Build project
Expand Down
27 changes: 12 additions & 15 deletions docs/maintenance/dependency.md
Expand Up @@ -4,20 +4,18 @@ Updating the dependencies is a tedious job. This doc is intended to help streaml

## Maintain Update Log

There's a sample `Update Log` at the end of this document. Create a new file where you can dump the Version Diff, Test results, Chrome/Node/Yarn versions. Mention the dependencies that you had to roll back along with the reason. Optionally you can mention the errors/warnings that you encountered while updating dependencies.
There's a sample `Update Log` at the end of this document. Create a new file where you can dump the Version Diff, Test results, Chrome/Node/npm versions. Mention the dependencies that you had to roll back along with the reason. Optionally you can mention the errors/warnings that you encountered while updating dependencies.

## Managing Node Versions

It is recommended that you use [Node Version Manager](https://github.com/creationix/nvm) or [Node Version Control](https://github.com/tj/n) to switch node versions quickly in order to run and test this project on multiple node versions.

## Update Tooling

**Update Yarn:**
**Update npm:**

1. For OSX users- `brew unlink yarn && brew install yarn`

2. For other users, follow [yarn docs](https://yarnpkg.com/en/docs/install).
3. Run `yarn --version` and record yarn version in `Update Log`.
1. Run `npm install -g npm`
2. Run `npm -v` and record npm version in `Update Log`.

**Update Chrome**

Expand All @@ -27,7 +25,7 @@ It is recommended that you use [Node Version Manager](https://github.com/creatio

## Update Dependencies

[npm-check-updates](https://github.com/tjunnone/npm-check-updates) is a great tool to update your dependencies. It will only update your `package.json`. Run `npm install` or `yarn` if you want to install updated package versions. There are 3 useful commands.
[npm-check-updates](https://github.com/tjunnone/npm-check-updates) is a great tool to update your dependencies. It will only update your `package.json`. Run `npm install` if you want to install updated package versions. There are 3 useful commands.

1. `ncu -u --semverLevel minor`
2. `ncu -u --semverLevel major`
Expand All @@ -45,7 +43,7 @@ At this point, you should copy and paste the version diff from the terminal into

## Correct Errors and Rollback Dependencies

Run `yarn` to install updated versions and then start the example app by running `npm start`. Make sure that the project is running smoothly. If not, track down the dependencies that are causing problems and try to roll them back one by one and check if the example application is running.
Run `npm install` to install updated versions and then start the example app by running `npm start`. Make sure that the project is running smoothly. If not, track down the dependencies that are causing problems and try to roll them back one by one and check if the example application is running.

Note down the rolled back dependencies and state the reason in your `Update Log`.

Expand All @@ -55,8 +53,8 @@ Most of the errors/warnings would go away once you roll back the problemetic dep

**Example App:**

- `rm -rf node_modules && rm yarn.lock`
- `yarn && npm start`
- `rm -rf node_modules && rm package-lock.json`
- `npm install && npm start`

- Browse example app on development server
- Browse Features page, change language to `de`
Expand Down Expand Up @@ -90,11 +88,10 @@ import TestPage from 'containers/TestPage/Loadable';

## Tooling Versions

- Node 7.5.0
- npm 4.1.2
- yarn 0.20.0
- Mac OS 10.11.6
- Chrome 56.0.2924.87 (64-bit)
- Node 8.11.4
- npm 6.4.0
- Mac OS 10.13.6
- Chrome 68.0.3440.106 (64-bit)

## :spiral_notepad: Notes

Expand Down
43 changes: 23 additions & 20 deletions internals/scripts/setup.js 100755 → 100644
@@ -1,14 +1,13 @@
#!/usr/bin/env node



const shell = require('shelljs');
const exec = require('child_process').exec;
const { exec } = require('child_process');
const path = require('path');
const fs = require('fs');
const readline = require('readline');
const compareVersions = require('compare-versions');
const animateProgress = require('./helpers/progress');
const addCheckMark = require('./helpers/checkmark');
const readline = require('readline');

process.stdin.resume();
process.stdin.setEncoding('utf8');
Expand Down Expand Up @@ -42,8 +41,8 @@ function cleanRepo(callback) {
if (isClonedRepo) {
process.stdout.write('\nDo you want to clear old repository? [Y/n] ');
process.stdin.resume();
process.stdin.on('data', data => {
const val = data.toString().trim();
process.stdin.on('data', pData => {
const val = pData.toString().trim();
if (val === 'y' || val === 'Y' || val === '') {
process.stdout.write('Removing old repository');
shell.rm('-rf', '.git/');
Expand All @@ -66,7 +65,7 @@ function cleanRepo(callback) {
*/
function dontClearRepo(nl, callback) {
clearRepo = false;
process.stdout.write(`${nl }Leaving your repository untouched`);
process.stdout.write(`${nl} Leaving your repository untouched`);
addCheckMark(callback);
}

Expand All @@ -89,25 +88,29 @@ function deleteFileInCurrentDir(file, callback) {

/**
* Installs dependencies
*
* NOTE: Could be refactored with aync/await and:
* const exec = util.promisify(require('child_process').exec);
*
*/
function installDeps() {
exec('node --version', (err, stdout, stderr) => {
const nodeVersion = stdout && parseFloat(stdout.substring(1));
if (nodeVersion < 5 || err) {
exec('node --version', (err, stdout) => {
const nodeVersion = stdout.replace(/(\r\n\t|\n|\r\t)/gm, '');
if (err || compareVersions(nodeVersion, '8.10.0') === -1) {
installDepsCallback(
err ||
'Unsupported node.js version, make sure you have the latest version installed.',
`[ERROR] You need Node.js v8.10 or above but you have ${nodeVersion}`,
);
} else {
exec('yarn --version', function (err, stdout, stderr) {
if (
parseFloat(stdout) < 0.15 ||
err ||
process.env.USE_YARN === 'false'
) {
exec('npm install', addCheckMark.bind(null, installDepsCallback));
exec('npm --version', (err2, stdout2) => {
const npmVersion = stdout2.replace(/(\r\n\t|\n|\r\t)/gm, '');
if (err2 || compareVersions(npmVersion, '5.0.0') === -1) {
installDepsCallback(
err2 ||
`[ERROR] You need npm v5 or above but you have v${npmVersion}`,
);
} else {
exec('yarn install', addCheckMark.bind(null, installDepsCallback));
exec('npm install', addCheckMark.bind(null, installDepsCallback));
}
});
}
Expand All @@ -130,7 +133,7 @@ function installDepsCallback(error) {
if (clearRepo) {
interval = animateProgress('Initialising new repository');
process.stdout.write('Initialising new repository');
initGit(function () {
initGit(() => {
clearInterval(interval);
endProcess();
});
Expand Down