Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Fix support for Yarn 2 (berry) #465

Closed
wants to merge 4 commits into from
Closed

Conversation

ylemkimon
Copy link

@ylemkimon ylemkimon commented Aug 3, 2020

Closes #319.

Suggestion for Docs:
https://docs.netlify.com/configure-builds/environment-variables/#netlify-configuration-variables

- * `YARN_VERSION`: Sets the [Yarn version].
+ * `YARN_VERSION`: Sets the [Yarn version] to install globally.
+ * `YARN_ENABLE_GLOBAL_CACHE`: Use the [global cache](https://yarnpkg.com/configuration/yarnrc#enableGlobalCache) for Yarn 2. 

https://docs.netlify.com/configure-builds/manage-dependencies/#yarn

- * `YARN_VERSION`: defaults to the version preinstalled with your initial [build image]. Accepts any released version number.
+ * `YARN_VERSION`: defaults to the version preinstalled with your initial [build image]. Accepts any released version number. The specified version is installed globally.
+ * `YARN_ENABLE_GLOBAL_CACHE`: whether to use the [global cache](https://yarnpkg.com/configuration/yarnrc#enableGlobalCache) for Yarn 2. If you use zero-installs, do not set this variable.

CC @arcanis Could you check whether this is the right way to use Yarn 2 in CI?

@ylemkimon ylemkimon requested a review from a team as a code owner August 3, 2020 11:07
@ylemkimon ylemkimon changed the title Add support for Yarn 2 (berry) Fix support for Yarn 2 (berry) Aug 3, 2020
Copy link

@arcanis arcanis left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! I've left a few comments, I hope someone from Netlify will be able to take a look.

Comment on lines 116 to 117
export YARN_GLOBAL_FOLDER="$NETLIFY_BUILD_BASE/.yarn_cache"
export YARN_ENABLE_GLOBAL_CACHE=1
Copy link

Choose a reason for hiding this comment

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

I'm not a fan of using environment variables for this, because it'll break people using zero-installs (when the cache is inside the repository), overriding the config they explicitly requested (I know it's what the code already did, overriding --cache-folder etc, but that really strikes me as a bad idea).

I think a more gentle approach would be to create a .yarnrc.yml file in the home directory that would contain the "default options" you want to have. This way, users would still be able to opt-out of the default workflow to use their own.

Copy link
Author

@ylemkimon ylemkimon Aug 5, 2020

Choose a reason for hiding this comment

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

@arcanis Thank you for the review! I've removed export YARN_ENABLE_GLOBAL_CACHE=1. The user now can opt-in to use global cache by setting YARN_ENABLE_GLOBAL_CACHE in Netlify settings.

I guess it'd be for Netlify to decide the default for enableGlobalCache and whether to allow users to override the global folder, so I'll leave it for now.

Choose a reason for hiding this comment

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

Chiming in here... :)

I've also attempted to use zero-installs on Netlify and ran into issues as the install command always seems to run. Would it be possible to amend these changes to allow skipping of the install step completely? Or did I just miss how to do that 🙃 ?

Copy link
Author

Choose a reason for hiding this comment

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

@kara-todd AFAIK, shoudn't yarn install only take few seconds with zero-installs? You can set YARN_ENABLE_NETWORK=0 to disallow making network requests.

Copy link

@kara-todd kara-todd Aug 8, 2020

Choose a reason for hiding this comment

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

@ylemkimon when I was running it... it still seemed to still run the relink step, but I didn't try it with YARN_ENABLE_NETWORK=0. It didn't take terribly long as I recall... 🤔 However, I use this in conjunction with Netlify CMS which has to wait on builds for content reviews... So every second ends up being precious. :)

I know that part of the problem was caused by Netlify not correctly detecting the cache directory as you are trying to fix here. Still, a true zero install where I only run my build command would be preferable to me if it's not a huge lift.

Copy link
Author

Choose a reason for hiding this comment

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

@kara-todd I have a Netlify repo with zero-install and it takes less than two seconds running yarn install. If it takes more than a few seconds, the repo may not have been set up properly. A workaround for now would be move the whole project into a subdirectory, not having package.json and yarn.lock at the root, and cd in the build command.

run-build-functions.sh Outdated Show resolved Hide resolved
@benfurber
Copy link

Would love for this to be merged in so that I move a site over to netlify. 🙏

@kevinji
Copy link

kevinji commented Apr 7, 2022

The line below export PATH=$(yarn bin):$PATH also needs to be updated; yarn bin on Yarn 2+ no longer returns a node_modules/.bin directory (which doesn't exist with PnP) but instead just lists all available binaries.

@kitop
Copy link
Contributor

kitop commented Aug 24, 2022

Closing this PR as the it's against xenial branch and the Xenial image is going to be deprecated: https://answers.netlify.com/t/please-read-end-of-support-for-xenial-build-image-everything-you-need-to-know/68239

Feel free to reopen against focal branch.

@kitop kitop closed this Aug 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Yarn arguments
6 participants