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

feat(version): reify on workspace version change #4588

Merged
merged 1 commit into from
Mar 24, 2022

Conversation

ruyadorno
Copy link
Contributor

Adds a minimalistic reify step that updates the installed tree after a
version change within one of the configured workspaces when using any
of the workspaces config options.

It's also possible to use the --save config option in order to
auto update semver ranges of dependencies declarations accross dependent
package.json files.

References

Fixes: #3403
Relates to: npm/rfcs#556
Relates to: #3757
Relates to: #4193

@ruyadorno ruyadorno requested a review from a team as a code owner March 17, 2022 22:22
@ruyadorno ruyadorno added semver:minor new backwards-compatible feature Release 8.x work is associated with a specific npm 8 release labels Mar 17, 2022
@ruyadorno ruyadorno force-pushed the feat-add-update-post-version branch from cdaa79a to 883fa8f Compare March 17, 2022 22:24
Adds a minimalistic reify step that updates the installed tree after a
version change within one of the configured workspaces when using any
of the workspaces config options.

It's also possible to use the `--save` config option in order to
auto update semver ranges of dependencies declarations accross dependent
`package.json` files.

Fixes: npm#3403
Relates to: npm/rfcs#556
Relates to: npm#3757
Relates to: npm#4193
@ruyadorno ruyadorno force-pushed the feat-add-update-post-version branch from 883fa8f to 9eb120d Compare March 21, 2022 20:40
@ruyadorno ruyadorno added the release: next These items should be addressed in the next release label Mar 21, 2022
Copy link
Contributor

@nlf nlf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes look good to me, however i do think it's probably a good idea to document this more explicitly in the workspaces docs with examples of exactly what will happen when it's used.

that can be a follow up pull request, though, so i'm marking this approved as-is :shipit:

@ruyadorno
Copy link
Contributor Author

Thanks @nlf that's a great idea! I know that page is in need of some love, I was chatting with @bnb the other day that was also noticing it could use more consistent naming across the examples there.

With that in mind I'll pb take the time this week to work on a small revamp/clean up of that page and will make sure to also add examples and notes about this behavior 🤔 although it might be better to land these doc updates after we also add this similar behavior to npm init and any other command that can use this immediate reify step when operating in workspaces, anyways something we can chat about in a diff PR 😊

@fritzy fritzy merged commit 723a091 into npm:latest Mar 24, 2022
@lukekarrys lukekarrys mentioned this pull request Mar 31, 2022
@lukekarrys lukekarrys mentioned this pull request Apr 1, 2022
ruyadorno added a commit to ruyadorno/cli that referenced this pull request May 12, 2022
Adds a minimalistic reify step that updates the installed tree after
initializing a new workspace.

Moved the shared update logic from `lib/commands/version.js` to a
`lib/workspaces/update-workspaces.js` module that is reused between
both `npm version` and `npm init`.

Relates to: npm/rfcs#556
Relates to: npm#4588
ruyadorno added a commit to ruyadorno/cli that referenced this pull request May 12, 2022
Adds a minimalistic reify step that updates the installed tree after
initializing a new workspace.

Moved the shared update logic from `lib/commands/version.js` to a
`lib/workspaces/update-workspaces.js` module that is reused between
both `npm version` and `npm init`.

Relates to: npm/rfcs#556
Relates to: npm#4588
ruyadorno added a commit to ruyadorno/cli that referenced this pull request May 19, 2022
Adds a minimalistic reify step that updates the installed tree after
initializing a new workspace.

Moved the shared update logic from `lib/commands/version.js` to a
`lib/workspaces/update-workspaces.js` module that is reused between
both `npm version` and `npm init`.

Relates to: npm/rfcs#556
Relates to: npm#4588
ruyadorno added a commit that referenced this pull request Jun 1, 2022
Adds a minimalistic reify step that updates the installed tree after
initializing a new workspace.

Moved the shared update logic from `lib/commands/version.js` to a
`lib/workspaces/update-workspaces.js` module that is reused between
both `npm version` and `npm init`.

Relates to: npm/rfcs#556
Relates to: #4588
@Regaddi
Copy link

Regaddi commented Jul 4, 2022

Sorry to come back to this PR so late, but I think I just noticed this new behavior.

Does this change mean it's no longer possible to do a very simple npm version patch bump that will only bump the "version" field in a package's package.json?

@manuth
Copy link

manuth commented Aug 16, 2022

@fritzy I just stumbled accross this PR because I still have issues with npms version behavior in workspaces.

In workspace-a I have added workspace-b as a dependency. When running npm version, the workspace-b dependency inside workspace-as package.json file isn't getting updated. Only dependencies inside the root workspace-test are being updated.

Thus, I wouldn't consider #3403 as closed.

Anyhow - thanks a ton for the great work, this is highly appreciated.

Steps to reproduce

  1. Create a root package.json:

    package.json:

    {
        "name": "workspaces-test",
        "version": "1.0.0",
        "workspaces": [
            "workspace-a",
            "workspace-b"
        ],
        "dependencies": {
            "workspace-a": "^1.0.0",
            "workspace-b": "^1.0.0"
        }
    }
  2. Create package.json files for the workspaces:

    workspace-a/package.json:

    {
        "name": "workspace-a",
        "version": "1.0.0",
        "dependencies": {
            "workspace-b": "^1.0.0"
        }
    }

    workspace-b/package.json:

    {
        "name": "workspace-b",
        "version": "1.0.0"
    }
  3. npm install the workspace root

  4. Run npm version:

    npm version -ws 2.0.0
    
  5. Inspect the result

    • Take note that the workspace-a and workspace-b dependencies inside the root package.json have been updated properly.
    • In workspace-a/package.json, take note, that the workspace-b dependency did not update and still is ^1.0.0 instead of ^2.0.0.

@ruyadorno
Copy link
Contributor Author

Sorry to come back to this PR so late, but I think I just noticed this new behavior.

Does this change mean it's no longer possible to do a very simple npm version patch bump that will only bump the "version" field in a package's package.json?

@Regaddi There's a --no-workspaces-update or workspace-update=false in .npmrc file escape hatch included in the original implementation.

@necolas
Copy link

necolas commented Apr 15, 2023

I was looking for this feature and had the same problem as @manuth with the option seemingly not working to update the versions of the package in dependencies within the workspace root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: next These items should be addressed in the next release Release 8.x work is associated with a specific npm 8 release semver:minor new backwards-compatible feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] npm --workspaces version doesn't update dependencies
6 participants