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

Tooling: Add volta versions #48734

Closed
wants to merge 3 commits into from
Closed

Tooling: Add volta versions #48734

wants to merge 3 commits into from

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Jan 8, 2021

Changes proposed in this Pull Request

https://volta.sh/

This prepares the environment for use with Volta, a potential replacement for nvm (but more).

It sets a volta property in the root package.json. It also points all the other package.json in the repo to extend that root config. This is under the assumption that all tooling should use the version in the root.

It was a little annoying to add a volta property to every package.json, but that should be a one-time thing and doesn't seem like it should have any negative impact. That seems to be the way to do things in Volta at the moment. See volta-cli/volta#906 and the Workspaces docs.

Testing instructions

You'll need to set your system up for Volta. I have no idea if that will play well with nvm. I've removed nvm from my system completely.

From an arbitrary location like ~, install some volta tools (that don't correspond to the versions in Calypso). For example:

  • volta install node@latest
  • volta install typescript@beta

Check the versions with volta list:

$ volta list
⚡️ Currently active tools:

    Node: v15.6.0 (default)
    npm: v6.14.11 (default)
    Yarn: v1.22.10 (default)
    Tool binaries available:
        wp-env (default)
        neovim-node-host (default)
        tsc, tsserver (default)
        yarn-deduplicate (default)

$ node --version
v15.6.0
$ tsc --version
Version 4.2.0-dev

move to Calypso and check the versions:

$ volta list
⚡️ Currently active tools:

    Node: v12.20.1 (current @ /Users/jonsurrell/a8c/calypso/package.json)
    Yarn: v1.22.10 (current @ /Users/jonsurrell/a8c/calypso/package.json)
    Tool binaries available:
        wp-env (default)
        neovim-node-host (default)
        tsc, tsserver (current @ /Users/jonsurrell/a8c/calypso/package.json)
        yarn-deduplicate (default)

# Nice, volta picked up different versions! Let's check…

$ node --version
# installs on demand if necessary!!
v12.20.1

# It detects the package's version and prefers it!
$ tsc --version
Version 4.1.3

Repeat from another directory with a package.json such as packages/*/ or apps/editing-toolkit or client.

@sirreal sirreal added the Build label Jan 8, 2021
@matticbot
Copy link
Contributor

@sirreal sirreal self-assigned this Jan 8, 2021
@matticbot
Copy link
Contributor

matticbot commented Jan 8, 2021

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

package.json Outdated Show resolved Hide resolved
@matticbot
Copy link
Contributor

Caution: This PR affects files in the Editing Toolkit Plugin on WordPress.com
Please ensure your changes work on WordPress.com before merging.

D55743-code has been created so you can easily test it on your sandbox. See this FieldGuide page about developing the Editing Toolkit Plugin for more info: PCYsg-ly5-p2

@sirreal sirreal added [Type] Tooling Related to tools, scripts, automation, DevX, etc. Framework [Type] Question [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Jan 21, 2021
@sirreal
Copy link
Member Author

sirreal commented Jan 21, 2021

Looks like renovate should support: renovatebot/renovate#4262

@sirreal sirreal marked this pull request as ready for review January 21, 2021 17:22
@sirreal sirreal requested review from a team as code owners January 21, 2021 17:22
@sirreal sirreal requested review from withinboredom, noahtallen and a team and removed request for a team January 21, 2021 17:22
Copy link
Contributor

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

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

I did a bit of testing with nvm + volta, and it looks like if NVM is configured in .the zshrc file, then it overrides volta. nvm use sets to 12.x, and that persists when changing to other directories. (e.g. the volta version is not used)

Screen Shot 2021-02-17 at 2 54 04 PM

When nvm is not set in .zshrc, it works as expected:

Screen Shot 2021-02-17 at 2 56 40 PM

It appears that nvm still works fine with volta config available. So in other words, this shouldn't break anything for existing users :)

I'm all for this, as I've been getting frustrated by NVM. For example, if I try to do a git commit or push via Visual Studio Code's GUI, the precommit hooks will utilize the "default" node version rather than the local nvm node version, which sucks when different projects use different node versions.

After trying out the precommit hooks with volta, it looks like that problem is finally solved! My editor is using the node version for the project without any intervention. (Tried with both wp-calypso and gutenberg using your branches.)

package.json Outdated
},
"volta": {
"node": "12.20.1",
"yarn": "1.22.10"
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this interact with the version set in .yarnrc?

Copy link
Member Author

Choose a reason for hiding this comment

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

Part of the yarn executable's behavior is to get the correct version via .yarnrc, isn't it? I did a test by pinning [email protected] for volta. You can see that although volta will invoke it's [email protected] binary, yarn reports its version is 1.22.10. I think everything will work smoothly and ultimately .yarnrc determines the version like I'd expect.

# volta list
⚡️ Currently active tools:

    Node: v12.20.1 (current @ …/calypso/package.json)
    Yarn: v1.21.1 (current @ …/calypso/package.json)
    Tool binaries available:
        wp-env (default)
        neovim-node-host (default)
        stryker (default)
        tsc, tsserver (current @ …/calypso/package.json)
        yarn-deduplicate (default)

See options for more detailed reports by running `volta list --help`.
# yarn --version
1.22.10

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems weird and confusing to have a yarn version defined in two places. Do we really need to tell volta about yarn version?

What's the dev experience if we drop the version in .yarnrc and we want to update yarn?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we go all-in with volta, I believe we could safely drop either one.

What's the dev experience if we drop the version in .yarnrc and we want to update yarn?

I don't understand the question. Updating yarn via volta means running volta pin yarn@latest in the repo root.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's say we drop .yarnrc and we pin yarn using volta to a specific version (1.22.10).

How do update the version? I guess it is only a change in package.json, right?

What happens when a dev checks out a branch that points to a version they don't have locally? Does volta automatically downloads the new version?

Copy link
Member Author

Choose a reason for hiding this comment

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

How do update the version? I guess it is only a change in package.json, right?

Yep.

What happens when a dev checks out a branch that points to a version they don't have locally? Does volta automatically downloads the new version?

Yes.

@scinos
Copy link
Contributor

scinos commented Feb 18, 2021

It is great that we are looking for alternatives to NVM if NVM is causing problems. Could you expand on the problems we are trying to solve with volta?

In any case, I think that we should only have one tool to do one thing. In other words, if we go ahead with this change, it should be a migration from nvm to volta with the aim of removing nvm from our system. Otherwise we are increasing the maintenance burden and the risk of `nvm

@griffbrad
Copy link
Contributor

It is great that we are looking for alternatives to NVM if NVM is causing problems. Could you expand on the problems we are trying to solve with volta?

I found @noahtallen’s comment on the related Gutenberg PR helpful in this regard. With volta, you no longer need to nvm i && nvm use. Instead, you should automatically use the correct node version for the project. That’s nice when on an interactive shell but perhaps more useful in the context of other tools that might otherwise end up using the incorrect version.

Dropping nvm in Calypso would be fine with me.

@creativecoder
Copy link
Contributor

FYI, I'm proposing the same change in Jetpack: Automattic/jetpack#19705

@noahtallen
Copy link
Contributor

I do like the ergonomics of Volta a lot, and have been using it exclusively recently, even without these changes. I wonder what our next steps should be? Do we need to commit to nvm or volta, or can we support both at the same time? (I don't see supporting volta as having a high cost, since it just involves bumping the version in the root package.json whenever we update node.)

Relatedly... I really, really wish they had not gone with this approach for monorepos. It seems to be the largest source of concern for project adoption since it increases the surface area by so much.

@scinos
Copy link
Contributor

scinos commented May 1, 2021

I wonder what our next steps should be? Do we need to commit to nvm or volta, or can we support both at the same time?

I still think we should draft a plan to do a full transition from NVM to Volta. IMO, at the very least we need (in no particular order):

  • Change our Docker images to use Volta instead of NVM
  • Write P2s explaining the difference, defining the transition plan and in general educating our devs about the new tool.
  • Land this PR.

Nice to have:

  • Clean up all those package.json. As @sirreal said, only a few of those will actually need volta (let's say only those that define 'scripts'?). Eventually get rid of the "fake" package.json files, this is not the first time they cause troubles.
  • Detect when someone is using node from nvm, and warn them (example: have a pre-install hook that warns if the node binary is from ~/.nvm/versions/node/v*/bin/node)

@creativecoder
Copy link
Contributor

I still think we should draft a plan to do a full transition from NVM to Volta. IMO, at the very least we need (in no particular order): ...

That all seems good to me.

Note that I still have nvm installed and volta seems to take precedence when running shell commands for which version of node and any npm installed binaries are used.

@sirreal
Copy link
Member Author

sirreal commented May 11, 2021

I can draft or help with a p2 post. I'd recommend upgrading to Node 16 first (p7H4VZ-31V-p2) so everyone gets native Node binaries with Volta.

@github-actions
Copy link

This PR has been marked as stale due to lack of activity within the last 30 days.

@matticbot
Copy link
Contributor

matticbot commented Oct 4, 2021

@worldomonation worldomonation removed request for a team and worldomonation June 6, 2022 17:20
@sirreal
Copy link
Member Author

sirreal commented Apr 11, 2023

This is very stale, I'll close it now. If there's interest and a desire to move forward with this I'd be happy to get this ready again.

@sirreal sirreal closed this Apr 11, 2023
@sirreal sirreal deleted the add/volta-pin branch April 11, 2023 13:25
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Apr 11, 2023
@noahtallen
Copy link
Contributor

Totally. I really wish they would just support reading from a higher-level .json file! I also looked into manual pinning -- like if I could achieve automatic version switching via a file I could add to .gitignore, but that also isn't supported :(

So I'm back to nvm for now, just because both Gutenberg and Calypso use it.

@scinos
Copy link
Contributor

scinos commented Apr 11, 2023

I really wish they would just support reading from a higher-level .json file

For the record, they kind of do, with extends. Docs.

@noahtallen
Copy link
Contributor

Oh hey! Hope things are going great :D That's what this PR was exploring originally

@creativecoder
Copy link
Contributor

I'm following this issue in the volta repo, but there hasn't been much movement: volta-cli/volta#282

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Framework [Status] Stale [Type] Tooling Related to tools, scripts, automation, DevX, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants