From 7c947d87ab39712a6ae88d1f4aa45721ab1b0c56 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 11 Mar 2019 14:22:02 +0000 Subject: [PATCH] Update scripts and docs to use `yarn` where appropriate Most `npm` operations are replaced with `yarn`, which generally has better behavior. However, steps like publish that write to the NPM registry are left to `npm`, which currently handles these tasks best. --- .gitignore | 2 +- .travis.yml | 2 +- README.md | 31 ++++++++++++++++++++---------- jenkins.sh | 12 ++++++------ karma.conf.js | 6 +++--- package.json | 8 ++++---- scripts/travis/build.sh | 6 +++--- scripts/travis/end-to-end-tests.sh | 2 +- scripts/travis/install-deps.sh | 4 ++-- scripts/travis/riot-unit-tests.sh | 4 ++-- scripts/travis/unit-tests.sh | 4 ++-- 11 files changed, 46 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index f828c37393..5e5f6d0aa5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ npm-debug.log /node_modules /lib -# version file and tarball created by 'npm pack' +# version file and tarball created by `npm pack` / `yarn pack` /git-revision.txt /matrix-react-sdk-*.tgz diff --git a/.travis.yml b/.travis.yml index ebb772fd0d..55b6797c57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ matrix: - name: Linting Checks script: # run the linter, but exclude any files known to have errors or warnings. - - npm run lintwithexclusions + - yarn lintwithexclusions # - name: End-to-End Tests # if: branch = develop # install: diff --git a/README.md b/README.md index c70f68902b..b2338dfe36 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ practices that anyone working with the SDK needs to be be aware of and uphold: component is a view or a structure, and then a broad functional grouping (e.g. 'rooms' here) - * After creating a new component you must run `npm run reskindex` to regenerate + * After creating a new component you must run `yarn reskindex` to regenerate the `component-index.js` for the SDK (used in future for skinning) * The view's CSS file MUST have the same name (e.g. view/rooms/MessageTile.css). @@ -131,26 +131,37 @@ for now. Development =========== -Ensure you have the latest stable Node JS runtime installed (v8.x is the best choice). Then check out -the code and pull in dependencies: +Ensure you have the latest stable Node JS runtime installed (v8.x is the best +choice). + +Using `yarn` instead of `npm` is recommended. Please see the Yarn [install +guide](https://yarnpkg.com/docs/install/) if you do not have it already. + +Then check out the code and pull in dependencies: ```bash git clone https://github.com/matrix-org/matrix-react-sdk.git cd matrix-react-sdk git checkout develop -npm install +yarn install ``` -`matrix-react-sdk` depends on `matrix-js-sdk`. To make use of changes in the +`matrix-react-sdk` depends on `matrix-js-sdk`. To make use of changes in the latter and to ensure tests run against the develop branch of `matrix-js-sdk`, -you should run the following which will sync changes from the JS sdk here. +you should check out `matrix-js-sdk`, change into that new directory, and run: ```bash -npm link ../matrix-js-sdk +yarn link ``` -Command assumes a checked out and installed `matrix-js-sdk` folder in parent -folder. +Then, switch back to `matrix-react-sdk` and run: + +```bash +yarn link matrix-js-sdk +``` + +See the [help for `yarn link`](https://yarnpkg.com/docs/cli/link) for more +details about this. Running tests ============= @@ -158,5 +169,5 @@ Running tests Ensure you've followed the above development instructions and then: ```bash -npm run test +yarn test ``` diff --git a/jenkins.sh b/jenkins.sh index f4bb8da449..32094d9de0 100755 --- a/jenkins.sh +++ b/jenkins.sh @@ -9,24 +9,24 @@ nvm use 10 set -x # install the other dependencies -npm install +yarn install scripts/fetchdep.sh matrix-org matrix-js-sdk rm -r node_modules/matrix-js-sdk || true ln -s ../matrix-js-sdk node_modules/matrix-js-sdk -(cd matrix-js-sdk && npm install) +(cd matrix-js-sdk && yarn install) # run the mocha tests -npm run test -- --no-colors +yarn test --no-colors # run eslint -npm run lintall -- -f checkstyle -o eslint.xml || true +yarn lintall -f checkstyle -o eslint.xml || true # re-run the linter, excluding any files known to have errors or warnings. -npm run lintwithexclusions +yarn lintwithexclusions # delete the old tarball, if it exists rm -f matrix-react-sdk-*.tgz # build our tarball -npm pack +yarn pack diff --git a/karma.conf.js b/karma.conf.js index 93063dbc04..5e7fe76d56 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -8,7 +8,7 @@ var fs = require('fs'); * to build everything; however it's the easiest way to load our dependencies * from node_modules. * - * If you run karma in multi-run mode (with `npm run test-multi`), it will watch + * If you run karma in multi-run mode (with `yarn test-multi`), it will watch * the tests for changes, and webpack will rebuild using a cache. This is much quicker * than a clean rebuild. */ @@ -35,7 +35,7 @@ function fileExists(name) { } } -// try find the gemini-scrollbar css in an npm-version-agnostic way +// try find the gemini-scrollbar css in an version-agnostic way var gsCss = 'node_modules/gemini-scrollbar/gemini-scrollbar.css'; if (!fileExists(gsCss)) { gsCss = 'node_modules/react-gemini-scrollbar/'+gsCss; @@ -198,7 +198,7 @@ module.exports = function (config) { alias: { // alias any requires to the react module to the one in our // path, otherwise we tend to get the react source included - // twice when using npm link. + // twice when using `npm link` / `yarn link`. react: path.resolve('./node_modules/react'), 'matrix-react-sdk': path.resolve('test/skinned-sdk.js'), diff --git a/package.json b/package.json index 7801d6f062..6c25e8ad33 100644 --- a/package.json +++ b/package.json @@ -40,17 +40,17 @@ "rethemendex": "res/css/rethemendex.sh", "i18n": "matrix-gen-i18n", "prunei18n": "matrix-prune-i18n", - "build": "npm run reskindex && npm run start:init", + "build": "yarn reskindex && yarn start:init", "build:watch": "babel src -w --skip-initial-build -d lib --source-maps --copy-files", "emoji-data-strip": "node scripts/emoji-data-strip.js", - "start": "npm run start:init && npm run start:all", - "start:all": "concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n build,reskindex \"npm run build:watch\" \"npm run reskindex:watch\"", + "start": "yarn start:init && yarn start:all", + "start:all": "concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n build,reskindex \"yarn build:watch\" \"yarn reskindex:watch\"", "start:init": "babel src -d lib --source-maps --copy-files", "lint": "eslint src/", "lintall": "eslint src/ test/", "lintwithexclusions": "eslint --max-warnings 0 --ignore-path .eslintignore.errorfiles src test", "clean": "rimraf lib", - "prepublish": "npm run clean && npm run build && git rev-parse HEAD > git-revision.txt", + "prepublish": "yarn clean && yarn build && git rev-parse HEAD > git-revision.txt", "test": "karma start --single-run=true --browsers ChromeHeadless", "test-multi": "karma start" }, diff --git a/scripts/travis/build.sh b/scripts/travis/build.sh index a353e38a06..74743b241f 100755 --- a/scripts/travis/build.sh +++ b/scripts/travis/build.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# script which is run by the travis build (after `npm run test`). +# script which is run by the travis build (after `yarn test`). # # clones riot-web develop and runs the tests against our version of react-sdk. @@ -13,7 +13,7 @@ scripts/fetchdep.sh vector-im riot-web pushd "$RIOT_WEB_DIR" mkdir node_modules -npm install +yarn install # use the version of js-sdk we just used in the react-sdk tests rm -r node_modules/matrix-js-sdk @@ -23,5 +23,5 @@ ln -s "$REACT_SDK_DIR/node_modules/matrix-js-sdk" node_modules/matrix-js-sdk rm -r node_modules/matrix-react-sdk ln -s "$REACT_SDK_DIR" node_modules/matrix-react-sdk -npm run build +yarn build popd diff --git a/scripts/travis/end-to-end-tests.sh b/scripts/travis/end-to-end-tests.sh index 361b053d2b..0c728be509 100755 --- a/scripts/travis/end-to-end-tests.sh +++ b/scripts/travis/end-to-end-tests.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# script which is run by the travis build (after `npm run test`). +# script which is run by the travis build (after `yarn test`). # # clones riot-web develop and runs the tests against our version of react-sdk. diff --git a/scripts/travis/install-deps.sh b/scripts/travis/install-deps.sh index 04cd728157..5e036bf135 100755 --- a/scripts/travis/install-deps.sh +++ b/scripts/travis/install-deps.sh @@ -1,11 +1,11 @@ #!/bin/sh set -ex -npm install +yarn install scripts/fetchdep.sh matrix-org matrix-js-sdk rm -r node_modules/matrix-js-sdk || true ln -s ../matrix-js-sdk node_modules/matrix-js-sdk cd matrix-js-sdk -npm install +yarn install cd .. diff --git a/scripts/travis/riot-unit-tests.sh b/scripts/travis/riot-unit-tests.sh index a2f0d61112..ca53dc9268 100755 --- a/scripts/travis/riot-unit-tests.sh +++ b/scripts/travis/riot-unit-tests.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# script which is run by the travis build (after `npm run test`). +# script which is run by the travis build (after `yarn test`). # # clones riot-web develop and runs the tests against our version of react-sdk. @@ -10,5 +10,5 @@ RIOT_WEB_DIR=riot-web scripts/travis/build.sh pushd "$RIOT_WEB_DIR" -npm run test +yarn test popd diff --git a/scripts/travis/unit-tests.sh b/scripts/travis/unit-tests.sh index a7e8425fa0..fe3e383c0a 100755 --- a/scripts/travis/unit-tests.sh +++ b/scripts/travis/unit-tests.sh @@ -1,10 +1,10 @@ #!/bin/bash # -# script which is run by the travis build (after `npm run test`). +# script which is run by the travis build (after `yarn test`). # # clones riot-web develop and runs the tests against our version of react-sdk. set -ev scripts/travis/build.sh -CHROME_BIN='/usr/bin/google-chrome-stable' npm run test +CHROME_BIN='/usr/bin/google-chrome-stable' yarn test