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

Add corepack plugin #15

Merged
merged 2 commits into from
Feb 26, 2024
Merged

Add corepack plugin #15

merged 2 commits into from
Feb 26, 2024

Conversation

jasononeil
Copy link
Member

@jasononeil jasononeil commented Feb 23, 2024

Adds a corepack plugin that enables Corepack to handle PNPM and Yarn version installs while using the same version of Node.js as the project.

Motivation

(largely copy-pasted from @jay-aye-see-kay's explanation on Slack)

There’s a subtle but messy issue that can arise using Devbox, Node.js, and Yarn/PNPM. If you install node and yarn as documented you will end up with two different versions of node:

$ devbox add [email protected] yarn
...
$ devbox run node --version
v20.8.0
$ devbox run yarn node --version
yarn node v1.22.19
v18.18.0

This happens because nix bundles all dependencies into every package, yarn is getting it’s own copy of Node.js, which may be more recent than the Node.js version the project is using.

Corepack by default tries to install shim scripts for both yarn and pnpm in the same directory that node is found in. Unfortunately when using devbox, the node binary is in the Nix store, which is read only, so Corepack fails to set up correctly.

How the plugin works works

  • creating a folder in .devbox/virtenv/pnpm_plugin/bin/
  • running corepack enable --install-directory "./devbox/virtenv/pnpm_plugin/bin/", which adds the pnpm and yarn shim scripts
  • and then adding ./devbox/virtenv/pnpm_plugin/bin/ to the PATH environment variable.

Testing

Devbox doesn't seem to allow using a plugin from Github with a branch (it's hard-coded to "master"), but I tested this on employee-imports: https://github.com/cultureamp/employee-imports/compare/jasono/demonstrate-corepack-plugin?expand=1

It might be worth setting up the unit tests to cover our plugins, perhaps even as part of this PR

Jira card: https://cultureamp.atlassian.net/browse/FEF-879
See also issue on Devbox repo: jetify-com/devbox#1577

The motivation is listed in the README.
@jasononeil jasononeil merged commit 3e3aa98 into main Feb 26, 2024
4 checks passed
@jasononeil jasononeil deleted the jasono/corepack-plugin branch February 26, 2024 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants