Skip to content

Commit

Permalink
build: improve npm scripts to update package-lock.json upon install
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Mar 15, 2019
1 parent 1d658fb commit 8a4e887
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ os:
- osx

script:
- npm run postinstall
- npm run postci
- npm run build
- npm run test:ci

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ install:
- ps: Install-Product node $env:nodejs_version
- node --version
- npm --version
- npm ci
- npm run ci

test_script:
- npm run build
Expand Down
40 changes: 25 additions & 15 deletions docs/site/DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,39 +133,49 @@ We use npm's
[package-lock feature](https://docs.npmjs.com/files/package-lock.json) to speed
up our development workflow and CI builds.

When installing dependencies in individual packages, `lerna bootstrap` calls
`npm ci` to install (deep) dependencies as specified in `package-lock.json`
file.
For individual packages within the monorepo, `lerna bootstrap` calls `npm ci` in
a CI environment or with `--ci` to install (deep) dependencies as specified in
`package-lock.json` file. Otherwise, `npm install` is run with the corresponding
`package.json`.

Top-level dependencies are installed either from `package-lock.json` (when you
run `npm ci`), or resolved freshly from the npm registry (when you run
`npm install`).
Top-level (`loopback-next`) dependencies are installed either from
`package-lock.json` (when you run `npm ci`), or resolved freshly from the npm
registry (when you run `npm install`).

**IMPORTANT: Dependencies resolved locally within the monorepo must be excluded
from package-lock files.**

### Fixing package locks
### Updating package locks

If you ever end up with corrupted package locks, run the following commands to
fix the problem:
If you ever end up with corrupted or out-of-date package locks, run the
following commands to fix the problem:

```
$ npx lerna clean && npx lerna bootstrap --no-ci
$ npm run update-package-lock
```

### Adding or updating dependencies

Use the following command to add or update dependency `dep` in a package `name`:

```
```sh
$ npx lerna add --scope ${name} ${dep}
```

At the moment, lerna does not update package-lock files when adding a dependency
to a scope, see [lerna#1989](https://github.com/lerna/lerna/issues/1989).
For example:

```sh
$ npx lerna add --scope @loopback/rest debug
```

See [lerna add](https://github.com/lerna/lerna/blob/master/commands/add#readme)
for more details.

You have to re-create package locks manually, see
[Fixing package locks](#fixing-package-locks) above.
**NOTE**: At the moment, `lerna` does not update `package-lock.json` files when
adding a dependency to a scope, see
[lerna#1989](https://github.com/lerna/lerna/issues/1989). You have to re-create
package locks manually, see [Updating package locks](#updating-package-locks)
above.

## File naming convention

Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
"typescript": "^3.3.1"
},
"scripts": {
"postinstall": "lerna bootstrap && npm run -s update-greenkeeper-json",
"postinstall": "npm run -s update-package-lock && npm run -s update-greenkeeper-json",
"ci": "npm ci --ignore-scripts && npm run -s postci",
"postci": "lerna bootstrap --ci",
"prerelease": "npm run build:full && npm run mocha && npm run lint",
"release": "lerna version && lerna publish from-git --yes",
"update-package-lock-json": "lerna exec \"npm install -s --ignore-scripts --package-lock-only --no-audit\" && git add \"**/package-lock.json\"",
"update-package-lock": "lerna clean && lerna bootstrap --no-ci",
"update-template-deps": "node bin/update-template-deps -f",
"update-greenkeeper-json": "node bin/update-greenkeeper-json -f",
"sync-dev-deps": "node bin/sync-dev-deps",
"version": "npm run update-package-lock-json && npm run update-template-deps && npm run apidocs",
"version": "npm run update-template-deps && npm run apidocs",
"outdated": "npm outdated --depth 0 && lerna exec --no-bail \"npm outdated --depth 0\"",
"apidocs": "node bin/run-lerna run build:apidocs",
"coverage:ci": "node packages/build/bin/run-nyc report --reporter=text-lcov | coveralls",
Expand All @@ -46,7 +48,7 @@
"clean": "lerna run clean && node packages/build/bin/run-clean \"packages/*/dist\" \"examples/*/dist\" \"benchmark/dist\"",
"clean:lerna": "lerna clean",
"build": "node bin/run-lerna run build",
"build:full": "npm run clean:lerna && npm install && npm run clean && npm run build",
"build:full": "npm run clean:lerna && npm run ci && npm run clean && npm run build",
"pretest": "npm run clean && npm run build",
"test": "node packages/build/bin/run-nyc npm run mocha --scripts-prepend-node-path",
"test:ci": "node packages/build/bin/run-nyc npm run mocha --scripts-prepend-node-path",
Expand Down

0 comments on commit 8a4e887

Please sign in to comment.