-
Notifications
You must be signed in to change notification settings - Fork 87
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
beachball not updating package-lock.json version field when publishing #525
Comments
Sorry for the late response. You use the postpublish hook in a module.exports = {
// ... your other config ...
hooks: {
postpublish: async (packagePath, name, version) => {
// your logic here
}
}
} It might be possible to detect the package manager based on which type of lock file is present and automatically run an appropriate command, but I'm not sure offhand exactly what would be involved with implementing that. |
I tried to do something similar to what @matthias-ccri described in: #525 (comment) But for an npm 7 workspace monorepo. It didn't actually work because beachball deletes the publish branch so the To use the approach @matthias-ccri used I'd need a way to skip deleting the publish branch for a npm workspace monorepo. I haven't tried the lifecycle hook @ecraig12345 described but as long as the timing is right, ie after package file updates but before publish branch delete, that might work out. In addition native npm 7 monorepo workspace support in beachball would be nice. I'd expect usage of npm's native workspace support to be increasingly popular :) |
We were able to get the package-lock.json to update using a workflow similar to the following: # Publish like normal
npx beachball publish --yes
# Pull in beachball's new changes
git merge --ff-only origin/main
# Delete the current node_modules, it seems to get in a state
# after beachball publish that causes subsequent `npm install`s
# to fail with a npm 7 workspace monorepo
rm -rf node_modules
# Update just the lock file
npm i --package-lock-only
# Create and publish the commit only if there are lock file changes
git add -A
if git diff-index --quiet HEAD;
then
echo "no changes found to push to main"
else
echo "changes found to push to main"
git commit -m "applying package lock updates [skip ci]"
git push --set-upstream origin main
fi The end result isn't perfect, we end up with two commits, one for the package publish and one for the lock file publish. It's also not as robust as native beachball support with the retries, etc. Native support for npm lock files + npm 7 workspaces would be awesome 🔥 Edit: Another big con of this approach is that it can cause unexpected version bumps for unrelated packages when the lock file is updated this way. I found a commit that revved several packages unexpectedly and because the commit is tagged |
The workaround to run I came up with an alternative that uses the newer postbump hook (since beachball 2.20.0) and does string replacements inside the package-lock.json instead. I don't think it's a great long-term solution since it's not updating the lockfile using context aware tooling, it's just doing dumb string replacements. We have got a few weeks of runway out of it so thought I'd share: https://gist.github.com/rajsite/71fb9a1bd32139c38e8b880a3618c020 |
Combining the approaches from @rajsite and @ecraig12345 answers, we got this working by adding the following to our const { execFileSync } = require('child_process')
module.exports = {
// ...
hooks: {
postbump: (_, name) => {
console.log(
`${name} bumped, running 'npm install --package-lock-only --ignore-scripts' to update package-lock.json`
)
execFileSync('npm', ['install', '--package-lock-only', '--ignore-scripts'])
}
}
} By running the @ecraig12345 would it be helpful to add in the docs beachball/src/types/BeachballOptions.ts Line 150 in 2e63fb5
postbump hook (unlike the postpublish hook)?
|
My biggest concern with that approach is looking back through the lockfile updates I found some instances where unrelated packages were updated after the That's why we switched to an approach like the gist in the previous comment: #525 (comment) |
It looks like the the latest npm v8.6 was updated to reify the lockfile when |
@rajsite seems odd that other packages would get updated (and break your setup). According to the docs and here, it should just regenerate the In any case, I'm going to watch this closely 👀 |
That would be a cleaner solution for sure, plus we would get all of the standard pre/post version script goodness that's standard in npm. According to #482 (comment) they are only using beachball with yarn, so I'm guessing we won't get much love on npm support 😭 I have a few ideas:
|
It was partially because my original script did the following:
So my original script deleted the If you don't delete the |
# Justification We were using the `@ni/beachball-lock-update` package to work around [a bug](microsoft/beachball#525) with how beachball modifies `package-lock.json` when publishing. That bug has been addressed in more recent versions of beachball so we can stop using the workaround. This moves us towards fixing [this Nimble issue](ni/nimble#601). # Implementation 1. Remove `@ni/beachball-lock-update` from `package.json` and `beachball.config.js`. 2. Install the latest version of `beachball` # Testing 1. We've been running with this setup in Nimble for a few months and it's worked well 2. I verified that basic beachball commands still work 3. I'll monitor the publishing pipeline as future changes go in. I considered making a trivial edit to a pakckage to trigger a publish but that seems pretty noisy now that our apps uptake new versions every night.
Hello,
I am using beachball to manage a single-package repo (not a monorepo), which it says on the beachball site: "single or monorepo". I'm using npm. I understand that the majority of monorepo users are using yarn, but npm is popular in the single repo ecosystem. Also, the best practice for npm is to use lockfiles (package-lock.json).
The issue is that package-lock.json files have a
version
field that corresponds to theversion
field of package.json, but beachball does not update this field in package-lock.json. Other tooling does, such as thenpm version
command.Currently our workaround is to do some manual script wrangling with git:
This is a bit uglier than the happy path:
npx beachball publish --yes --message "applying package updates [skip ci]"
This related issue (#482) saw the same issue and added a postpublish hook, but it's not clear how to use it.
I do use beachball with yarn in other monorepos and it's wonderful. It would just be nice if beachball updated the lockfile. Would this be hard?
The text was updated successfully, but these errors were encountered: