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

Suggestion: Switch package manager to Yarn 2 #3292

Closed
MaikoTan opened this issue Jul 12, 2021 · 9 comments
Closed

Suggestion: Switch package manager to Yarn 2 #3292

MaikoTan opened this issue Jul 12, 2021 · 9 comments

Comments

@MaikoTan
Copy link
Contributor

MaikoTan commented Jul 12, 2021

Yarn 2 (Berry) brings many features:

  • πŸ”Œ Plug'n'Play. To get rid of the extremely biggest node_modules, it also make node scripts run faster. moon, earth, sun, black hole, node_modules.

  • 🏎️ Faster installation. Not only because of the Zero-installs feature, but Yarn installs packages in parallel, however npm does this one by one, usually Yarn is faster than npm several times.

  • πŸ”© Cross-platform scripts. Yarn includes a simple shell interpreter, make scripts runs consistently across platforms, no matter which OS/Shell you're running from. It is time to get rid of node_modules/.bin/blahblah prefixes!

There are also disadvantages:

  • πŸ”§ The first one is obvious: you should install Yarn manually and globally, it is not bundled like npm.

  • πŸ› The Plug'n'Play feature is not compatible with all tools, or only be supported by the new version, so it might be painful to make a bunch of tools work.

  • 😫 Many IDE/Editor would assume that you are running npm by default, although you can configure it manually, for example in VSCode ESLint plugin.


Feel free to comment your thoughts! (γ₯q◕‿‿◕q)γ₯

@quisquous
Copy link
Owner

I don't know much about yarn, but I know it's widely used. I think really my hesitation is that this creates more friction because it's another dependency to install. Faster sounds nice, though. :)

@MaikoTan
Copy link
Contributor Author

Yeah, Yarn is widely used. Mostly I like its modern and fashion CLI. It is also bundled in setup-node action in Github Actions, so I think the most important thing is that how many cactbot developers supports it?

@JLGarber
Copy link
Collaborator

From a "developer-user" standpoint, my primary concern is "how much work will it take to make our existing tools work with Yarn?" I'm completely unfamiliar with Yarn, so anything that needs to be modified will block me completely until Someone Else is able to convert tools. This isn't necessarily a problem, since I would assume part of the process of moving to Yarn would be that conversion step, but it is something to be aware of.

It's also important that we consider the novice contributor. When I started contributing here, I knew next to nothing about package managers and build tools. Those were things for Experienced And Serious Software Engineers, while I just wanted to write a few lines of Javascript. Installing NPM is already a bit of a barrier for newer contributors, and we really want to do our best to ensure that we do not make things more difficult for them, if possible.

Laying that aside, I think moving to Yarn is worth serious consideration just on the basis of improved speed and reduced disk churn. With the next expansion coming up, and all the new content that we will have to add, cutting off 10-15% of the time spent waiting for our tools to work would really add up.

How much effort would it take to set up a "prototype" Yarn environment or sandbox that we could try? I am happy to provide feedback on something like that, but I would have very little to contribute as far as putting it together.

@MaikoTan
Copy link
Contributor Author

MaikoTan commented Jul 19, 2021

AFAIK, the migration should be done as follows:

  1. npm i -g yarn (install yarn globally)
  2. yarn set version berry (use yarn 2)
  3. change scripts in package.json to be suitable with yarn
  4. add .yarnrc.yml (configuration file of yarn)
  5. generate lock file (yarn.lock) with yarn install and remove package-lock.json
  6. modify .gitignore and .gitattributes
  7. commit changes

I can upload a playable environment with yarn later when I have enough time to tweak configurations.


For novices, I think, after installed nodejs, and then just run npm i -g yarn and yarn install. There you go!

(If we enable Plug'n'Play feature that I mentioned before, the yarn install part is also ignorable, but I didn't enable successfully the VSCode support of PnP on my machine as far, maybe need some tweaks, I don't know. I would google and try something else later.)

@MaikoTan
Copy link
Contributor Author

After trying several times, sadly I found that Yarn's PnP feature doesn't support ESM currently. So it seems redundant to migrate to Yarn 2 if we don't enable PnP/Zero-Install feature since it does the same work as NPM basically.

@quisquous
Copy link
Owner

It is so surprising to me how few things support ESM. :C

@quisquous
Copy link
Owner

It looks like that issue got closed without any fixes? So maybe Yarn isn't going to support PnP+ESM?

@MaikoTan
Copy link
Contributor Author

Well, no?
I remember Yarn has already ability to generate the ESM version of PnP bootstrap script, but I didn't try it in cactbot ever.
I'll try it when I have time. Sorry but I got being busying so long...

@MaikoTan
Copy link
Contributor Author

MaikoTan commented Nov 7, 2022

As NPM now has part of Yarn Berry's features now, it would be better to just upgrade our npm version.

@MaikoTan MaikoTan closed this as completed Nov 7, 2022
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

No branches or pull requests

3 participants