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 19, 2019
1 parent a56e911 commit a6ebb4d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
42 changes: 27 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-locks
```

### 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 Expand Up @@ -479,6 +489,8 @@ Please register the new package in the following files:
- Update
[CODEOWNERS](https://github.com/strongloop/loopback-next/blob/master/CODEOWNERS) -
add a new entry listing the primary maintainers (owners) of the new package.
- Run `npm run update-packages` to make sure the newly added package will be
monitored by greenkeeper and corresponding `package-lock.json` is updated.
- Ask somebody from the IBM team (e.g. [@bajtos](https://github.com/bajtos) or
[@raymondfeng](https://github.com/raymondfeng) to enlist the new package on
<http://apidocs.loopback.io/>.
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
"typescript": "^3.3.1"
},
"scripts": {
"postinstall": "lerna bootstrap && npm run -s update-greenkeeper-json",
"postinstall": "lerna bootstrap",
"update-packages": "npm run -s update-package-locks && npm run -s update-greenkeeper-json",
"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-locks": "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-packages && git add greenkeeper.json \"**/package-lock.json\" && 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 +47,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 a6ebb4d

Please sign in to comment.