Skip to content

Commit 2144791

Browse files
committed
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.
1 parent 33aabf4 commit 2144791

File tree

7 files changed

+57
-43
lines changed

7 files changed

+57
-43
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ reports
1212
/lib
1313
/specbuild
1414

15-
# version file and tarball created by 'npm pack'
15+
# version file and tarball created by `npm pack` / `yarn pack`
1616
/git-revision.txt
1717
/matrix-js-sdk-*.tgz

README.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ Please check [the working browser example](examples/browser) for more informatio
2121
In Node.js
2222
----------
2323

24-
``npm install matrix-js-sdk``
24+
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.
25+
26+
``yarn add matrix-js-sdk``
2527

2628
```javascript
2729
var sdk = require("matrix-js-sdk");
@@ -283,7 +285,7 @@ This SDK uses JSDoc3 style comments. You can manually build and
283285
host the API reference from the source files like this:
284286

285287
```
286-
$ npm run gendoc
288+
$ yarn gendoc
287289
$ cd .jsdoc
288290
$ python -m SimpleHTTPServer 8005
289291
```
@@ -319,15 +321,15 @@ To provide the Olm library in a browser application:
319321

320322
To provide the Olm library in a node.js application:
321323

322-
* ``npm install https://matrix.org/packages/npm/olm/olm-3.0.0.tgz``
324+
* ``yarn add https://matrix.org/packages/npm/olm/olm-3.0.0.tgz``
323325
(replace the URL with the latest version you want to use from
324326
https://matrix.org/packages/npm/olm/)
325327
* ``global.Olm = require('olm');`` *before* loading ``matrix-js-sdk``.
326328

327-
If you want to package Olm as dependency for your node.js application, you
328-
can use ``npm install https://matrix.org/packages/npm/olm/olm-3.0.0.tgz
329-
--save-optional`` (if your application also works without e2e crypto enabled)
330-
or ``--save`` (if it doesn't) to do so.
329+
If you want to package Olm as dependency for your node.js application, you can
330+
use ``yarn add https://matrix.org/packages/npm/olm/olm-3.0.0.tgz``. If your
331+
application also works without e2e crypto enabled, add ``--optional`` to mark it
332+
as an optional dependency.
331333

332334

333335
Contributing
@@ -337,28 +339,28 @@ want to use this SDK, skip this section.*
337339

338340
First, you need to pull in the right build tools:
339341
```
340-
$ npm install
342+
$ yarn install
341343
```
342344

343345
Building
344346
--------
345347

346348
To build a browser version from scratch when developing::
347349
```
348-
$ npm run build
350+
$ yarn build
349351
```
350352

351353
To constantly do builds when files are modified (using ``watchify``)::
352354
```
353-
$ npm run watch
355+
$ yarn watch
354356
```
355357

356358
To run tests (Jasmine)::
357359
```
358-
$ npm test
360+
$ yarn test
359361
```
360362

361363
To run linting:
362364
```
363-
$ npm run lint
365+
$ yarn lint
364366
```

git-hooks/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ export PATH="$rootdir/node_modules/.bin:$PATH"
2121

2222
# now run our checks
2323
cd "$tmpdir"
24-
npm run lint
24+
yarn lint

jenkins.sh

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export NVM_DIR="$HOME/.nvm"
66
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
77

88
nvm use 10 || exit $?
9-
npm install || exit $?
9+
yarn install || exit $?
1010

1111
RC=0
1212

@@ -18,17 +18,19 @@ function fail {
1818
# don't use last time's test reports
1919
rm -rf reports coverage || exit $?
2020

21-
npm test || fail "npm test finished with return code $?"
21+
yarn test || fail "yarn test finished with return code $?"
2222

23-
npm run -s lint -- -f checkstyle > eslint.xml ||
23+
yarn -s lint -f checkstyle > eslint.xml ||
2424
fail "eslint finished with return code $?"
2525

2626
# delete the old tarball, if it exists
2727
rm -f matrix-js-sdk-*.tgz
2828

29-
npm pack ||
30-
fail "npm pack finished with return code $?"
29+
# `yarn pack` doesn't seem to run scripts, however that seems okay here as we
30+
# just built as part of `install` above.
31+
yarn pack ||
32+
fail "yarn pack finished with return code $?"
3133

32-
npm run gendoc || fail "JSDoc failed with code $?"
34+
yarn gendoc || fail "JSDoc failed with code $?"
3335

3436
exit $RC

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
"test:build": "babel -s -d specbuild spec",
88
"test:run": "istanbul cover --report text --report cobertura --config .istanbul.yml -i \"lib/**/*.js\" node_modules/mocha/bin/_mocha -- --recursive specbuild --colors --reporter mocha-jenkins-reporter --reporter-options junit_report_path=reports/test-results.xml",
99
"test:watch": "mocha --watch --compilers js:babel-core/register --recursive spec --colors",
10-
"test": "npm run test:build && npm run test:run",
11-
"check": "npm run test:build && _mocha --recursive specbuild --colors",
10+
"test": "yarn test:build && yarn test:run",
11+
"check": "yarn test:build && _mocha --recursive specbuild --colors",
1212
"gendoc": "babel --no-babelrc -d .jsdocbuild src && jsdoc -r .jsdocbuild -P package.json -R README.md -d .jsdoc",
13-
"start": "npm run start:init && npm run start:watch",
13+
"start": "yarn start:init && yarn start:watch",
1414
"start:watch": "babel -s -w --skip-initial-build -d lib src",
1515
"start:init": "babel -s -d lib src",
1616
"clean": "rimraf lib dist",
1717
"build": "babel -s -d lib src && rimraf dist && mkdir dist && browserify -d browser-index.js | exorcist dist/browser-matrix.js.map > dist/browser-matrix.js && uglifyjs -c -m -o dist/browser-matrix.min.js --source-map dist/browser-matrix.min.js.map --in-source-map dist/browser-matrix.js.map dist/browser-matrix.js",
18-
"dist": "npm run build",
18+
"dist": "yarn build",
1919
"watch": "watchify -d browser-index.js -o 'exorcist dist/browser-matrix.js.map > dist/browser-matrix.js' -v",
2020
"lint": "eslint --max-warnings 101 src spec",
21-
"prepublish": "npm run clean && npm run build && git rev-parse HEAD > git-revision.txt"
21+
"prepare": "yarn clean && yarn build && git rev-parse HEAD > git-revision.txt"
2222
},
2323
"repository": {
2424
"type": "git",

release.sh

+20-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
# github-changelog-generator; install via:
77
# pip install git+https://github.com/matrix-org/github-changelog-generator.git
88
# jq; install from your distribution's package manager (https://stedolan.github.io/jq/)
9-
# hub; install via brew (OSX) or source/pre-compiled binaries (debian) (https://github.com/github/hub) - Tested on v2.2.9
9+
# hub; install via brew (macOS) or source/pre-compiled binaries (debian) (https://github.com/github/hub) - Tested on v2.2.9
10+
# npm; typically installed by Node.js
11+
# yarn; install via brew (macOS) or similar (https://yarnpkg.com/docs/install/)
1012

1113
set -e
1214

@@ -22,6 +24,8 @@ else
2224
echo "hub is required: please install it"
2325
exit
2426
fi
27+
npm --version > /dev/null || (echo "npm is required: please install it"; kill $$)
28+
yarn --version > /dev/null || (echo "yarn is required: please install it"; kill $$)
2529

2630
USAGE="$0 [-xz] [-c changelog_file] vX.Y.Z"
2731

@@ -88,6 +92,8 @@ if [ -z "$skip_changelog" ]; then
8892
update_changelog -h > /dev/null || (echo "github-changelog-generator is required: please install it"; exit)
8993
fi
9094

95+
# Login and publish continues to use `npm`, as it seems to have more clearly
96+
# defined options and semantics than `yarn` for writing to the registry.
9197
actual_npm_user=`npm whoami`;
9298
if [ $expected_npm_user != $actual_npm_user ]; then
9399
echo "you need to be logged into npm as $expected_npm_user, but you are logged in as $actual_npm_user" >&2
@@ -147,18 +153,18 @@ cat "${changelog_file}" | `dirname $0`/scripts/changelog_head.py > "${latest_cha
147153
set -x
148154

149155
# Bump package.json and build the dist
150-
echo "npm version"
151-
# npm version will automatically commit its modification
156+
echo "yarn version"
157+
# yarn version will automatically commit its modification
152158
# and make a release tag. We don't want it to create the tag
153159
# because it can only sign with the default key, but we can
154160
# only turn off both of these behaviours, so we have to
155161
# manually commit the result.
156-
npm version --no-git-tag-version "$release"
162+
yarn version --no-git-tag-version "$release"
157163

158-
# commit package-lock.json if it exists, is versioned, and is modified
159-
if [[ -f package-lock.json && `git status --porcelain package-lock.json | grep '^ M'` ]];
164+
# commit yarn.lock if it exists, is versioned, and is modified
165+
if [[ -f yarn.lock && `git status --porcelain yarn.lock | grep '^ M'` ]];
160166
then
161-
pkglock='package-lock.json'
167+
pkglock='yarn.lock'
162168
else
163169
pkglock=''
164170
fi
@@ -178,7 +184,7 @@ fi
178184
# assets.
179185
# We make a completely separate checkout to be sure
180186
# we're using released versions of the dependencies
181-
# (rather than whatever we're pulling in from npm link)
187+
# (rather than whatever we're pulling in from yarn link)
182188
assets=''
183189
dodist=0
184190
jq -e .scripts.dist package.json 2> /dev/null || dodist=$?
@@ -189,10 +195,10 @@ if [ $dodist -eq 0 ]; then
189195
pushd "$builddir"
190196
git clone "$projdir" .
191197
git checkout "$rel_branch"
192-
npm install
198+
yarn install
193199
# We haven't tagged yet, so tell the dist script what version
194200
# it's building
195-
DIST_VERSION="$tag" npm run dist
201+
DIST_VERSION="$tag" yarn dist
196202

197203
popd
198204

@@ -281,12 +287,13 @@ fi
281287
rm "${release_text}"
282288
rm "${latest_changes}"
283289

284-
# publish to npmjs
290+
# Login and publish continues to use `npm`, as it seems to have more clearly
291+
# defined options and semantics than `yarn` for writing to the registry.
285292
npm publish
286293

287294
if [ -z "$skip_jsdoc" ]; then
288295
echo "generating jsdocs"
289-
npm run gendoc
296+
yarn gendoc
290297

291298
echo "copying jsdocs to gh-pages branch"
292299
git checkout gh-pages
@@ -311,7 +318,7 @@ git checkout master
311318
git pull
312319
git merge "$rel_branch"
313320

314-
# push master and docs (if generated) to github
321+
# push master and docs (if generated) to github
315322
git push origin master
316323
if [ -z "$skip_jsdoc" ]; then
317324
git push origin gh-pages

travis.sh

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
set -ex
44

5-
npm run lint
5+
yarn lint
66

77
# install Olm so that we can run the crypto tests.
8-
npm install https://matrix.org/packages/npm/olm/olm-3.1.0-pre1.tgz
8+
# This will add Olm as dependency, since it's currently unlisted.
9+
# (`yarn` does not have an install dependency without adding mode.)
10+
# TODO: Should Olm be a listed dev dependency instead, so that we can have it for testing
11+
# and don't need to run an extra step here?
12+
yarn add https://matrix.org/packages/npm/olm/olm-3.1.0-pre1.tgz
913

10-
npm run test
11-
12-
npm run gendoc
14+
yarn test
1315

16+
yarn gendoc

0 commit comments

Comments
 (0)