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

[BUG] Wrong behaviour of npm version inside workspaces #4017

Closed
2 tasks done
oleksiibatin-ne opened this issue Nov 8, 2021 · 5 comments
Closed
2 tasks done

[BUG] Wrong behaviour of npm version inside workspaces #4017

oleksiibatin-ne opened this issue Nov 8, 2021 · 5 comments
Labels
Bug thing that needs fixing cmd:version related to `npm version` config:workspaces related to `--workspaces` Priority 1 high priority issue Release 8.x work is associated with a specific npm 8 release

Comments

@oleksiibatin-ne
Copy link

oleksiibatin-ne commented Nov 8, 2021

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

After running npm version patch -m "chore: release %s " --workspaces --include-workspace-root command in monorepo, npm doesn't add inner packages.json files into a generated commit. Thus, version commit only contains changes from the root package.json, updated package.json inside workspace-a and workspace-b haven’t been added to version commit by npm.

.
+-- package.json
`-- workspace-a
   `-- package.json
`-- workspace-b
   `-- package.json

Expected Behavior

Version commit should contain changes that were made by npm version patch -m "chore: release %s " --workspaces --include-workspace-root command in monorepo.

Steps To Reproduce

  1. Create a folder with monorepo structure with two inner packages.
.
+-- package.json
`-- workspace-a
   `-- package.json
`-- workspace-b
   `-- package.json
  1. Root package.json config.
  "name": "my-workspaces-powered-project",
  "version": 0.0.0,
  "workspaces": [
    "workspace-a",
    "workspace-b"
  ]
}
  1. package.json inside workspace-a folder.
  "name": "package-a",
  "version": 0.0.0
}
  1. package.json inside workspace-b folder.
  "name": "package-b",
  "version": 0.0.0
}
  1. Run npm version patch -m "chore: release %s " --workspaces --include-workspace-root in root folder

Environment

  • npm: 8.1.3
  • Node: 16.13.0
  • OS: MacOS Big Sur 11.6
  • platform: Macbook Pro
@oleksiibatin-ne oleksiibatin-ne added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Nov 8, 2021
@lukekarrys lukekarrys added config:workspaces related to `--workspaces` cmd:version related to `npm version` Priority 1 high priority issue and removed Needs Triage needs review for next steps labels Mar 1, 2022
@bigujun
Copy link

bigujun commented Mar 2, 2022

Waiting for that to be fixed, for now as a work around i'm using:
npm version patch --workspaces && git add **/package.json; npm version patch --include-workspace-root --force

@wraithgar
Copy link
Member

Until we have a solution for git tagging of workspace version bumps this will always have to be at least two commands. The core issue here is that npm version -w x does not generate a git commit. The decision was made at the time of implementing npm version for workspaces to do this because the existing git tag config wasn't very conducive to workspaces. tag-version-prefix defaults to v, and is not something that can be templated or otherwise changed per workspace in a single command. Rather than block npm version for workspaces altogether it was implemented bypassing git tagging altogether.

If we come up with a git tagging strategy for workspaces this problem will be also fixed, as each workspace's version will get its own git commit, with an appropriate tag. Until then you need to isolate the versioning of the root workspace with its versions. If anyone has a solution for git tagging workspaces they feel would work, please sumbit an rfc so the rest of the npm community can approve it.

@ljharb
Copy link
Contributor

ljharb commented Apr 18, 2022

Seems pretty straightforward - add workspace-tag-version-prefix, defaulting to [$workspaceName] , and ignored when workspaces is not enabled. I'll try to write an RRFC.

@ljharb
Copy link
Contributor

ljharb commented Apr 18, 2022

npm/rfcs#570

@christianidas
Copy link

You can work around this in one commit. Add this scrip to your package.json at the root:
"version": "npm version $npm_package_version --workspaces && git add **/package.json"

dherman added a commit to neon-bindings/neon-rs that referenced this issue Apr 30, 2023
…p all packages atomically.

Uses a workaround for an npm limitation found at: npm/cli#4017 (comment)
joshwilsonvu added a commit to solidjs-community/eslint-plugin-solid that referenced this issue Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing cmd:version related to `npm version` config:workspaces related to `--workspaces` Priority 1 high priority issue Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

6 participants