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

version: update lock before lifecycle #171

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/cli/npm-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ The exact order of execution is as follows:
1. Check to make sure the git working directory is clean before we get started.
Your scripts may add files to the commit in future steps.
This step is skipped if the `--force` flag is set.
2. Run the `preversion` script. These scripts have access to the old `version` in package.json.
2. Run the `preversion` script. These scripts have access to the old `version` in `package.json`.
A typical use would be running your full test suite before deploying.
Any files you want added to the commit should be explicitly added using `git add`.
3. Bump `version` in `package.json` as requested (`patch`, `minor`, `major`, etc).
4. Run the `version` script. These scripts have access to the new `version` in package.json
Also updates `npm-shrinkwrap.json` or `package-lock.json` if present.
4. Run the `version` script. These scripts have access to the new `version` in `package.json`
(so they can incorporate it into file headers in generated files for example).
Again, scripts should explicitly add generated files to the commit using `git add`.
5. Commit and tag.
Expand Down
15 changes: 7 additions & 8 deletions lib/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function persistVersion (newVersion, silent, data, localData, cb_) {
!localData.hasGit && [checkGit, localData],
[lifecycle, lifecycleData, 'preversion', where],
[updatePackage, newVersion, silent],
[updateShrinkwrap, newVersion, localData],
[lifecycle, lifecycleData, 'version', where],
[commit, localData, newVersion],
[lifecycle, lifecycleData, 'postversion', where]
Expand Down Expand Up @@ -144,12 +145,8 @@ function updatePackage (newVersion, silent, cb_) {
}

function commit (localData, newVersion, cb) {
updateShrinkwrap(newVersion, function (er, hasShrinkwrap, hasLock) {
if (er || !localData.hasGit) return cb(er)
localData.hasShrinkwrap = hasShrinkwrap
localData.hasPackageLock = hasLock
_commit(newVersion, localData, cb)
})
if (!localData.hasGit) return cb()
_commit(newVersion, localData, cb)
}

const SHRINKWRAP = 'npm-shrinkwrap.json'
Expand All @@ -161,7 +158,7 @@ function readLockfile (name) {
).catch({code: 'ENOENT'}, () => null)
}

function updateShrinkwrap (newVersion, cb) {
function updateShrinkwrap (newVersion, localData, cb) {
BB.join(
readLockfile(SHRINKWRAP),
readLockfile(PKGLOCK),
Expand All @@ -187,7 +184,9 @@ function updateShrinkwrap (newVersion, cb) {
log.error('version', `Failed to update version in ${file}`)
return cb(err)
} else {
return cb(null, !!shrinkwrap, !!lockfile)
localData.hasShrinkwrap = !!shrinkwrap
localData.hasPackageLock = !!lockfile
return cb(null)
}
})
}
Expand Down