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

Support for Yarn Berry #194

Merged
merged 10 commits into from
Aug 3, 2022
Merged

Support for Yarn Berry #194

merged 10 commits into from
Aug 3, 2022

Conversation

thitch97
Copy link
Contributor

@thitch97 thitch97 commented May 3, 2022

Readable

Checklist

  • I have viewed, signed, and submitted the Contributor License Agreement.
  • I have linked issue(s) that this PR should close using keywords or the Github UI (See docs)
  • I have added an integration test, if necessary.
  • I have reviewed the styleguide for guidance on my code quality.
  • I'm happy with the commit history on this PR (I have rebased/squashed as needed).

@thitch97 thitch97 marked this pull request as ready for review May 10, 2022 18:01
@thitch97 thitch97 requested a review from a team as a code owner May 10, 2022 18:01
## Unresolved Questions and Bikeshedding


- Should this buildpack require `yarn`?
Copy link
Contributor Author

@thitch97 thitch97 May 11, 2022

Choose a reason for hiding this comment

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

Would love to hear any thoughts on this item (and the related one below). Configuring corepack to correctly enable yarn in the offline case would require the developer to corepack prepare their yarn release so that the buildpack can corepack hydrate it. Does that seem reasonable? Foregoing the yarn requirement is starting to feel more idealistic than it is practical.

An argument against introducing another buildpack here is that it would increase complexity in other buildpacks that use yarn like the Web Servers buildpack.


- If there is no `.pnp.cjs` in the working directory, even if a local cache exists.

- If the `yarn.lock` has changed.
Copy link
Member

Choose a reason for hiding this comment

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

From what? Is this from a checksum recorded in a previous build?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the yarn-install buildpack generates a checksum of yarn.lock and the output of yarn config --list. The plan is to do the same, replacing yarn config with yarn info.

Copy link
Member

Choose a reason for hiding this comment

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

Can you clarify what happens if there is a .pnp.cjs file and a local cache and the yarn.lock file has changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've reworked this section a bit, let me know if that makes sense.


`yarn-berry-install`

Provides: `yarn_packages` OR `node_modules` Requires: `node`, during `build` and `launch`
Copy link
Member

Choose a reason for hiding this comment

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

Why does this require anything at launch? At launch, this buildpack isn't really doing anything other than making sure that there are some JavaScript files available on the filesystem. I'd expect that if someone wanted to run these files, they'd need to require node some other way, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct, I've updated accordingly.


- If there is no `.pnp.cjs` in the working directory, even if a local cache exists.

- If the `yarn.lock` has changed.
Copy link
Member

Choose a reason for hiding this comment

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

Can you clarify what happens if there is a .pnp.cjs file and a local cache and the yarn.lock file has changed?

fail if the `yarn.lock` file needs to be updated. As such, developers must run
`yarn install` locally in order to update their app's `yarn.lock` file.
`--frozen-lockfile` has been deprecated in favour of `--immutable`, which this
buildpack will utilize.
Copy link

@aurelienbottazini aurelienbottazini Jun 9, 2022

Choose a reason for hiding this comment

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

I am bit concerned by this.
I agree --immutable is a good idea in theory.
But I had strange cases where for an identical node and yarn version, yarn install --immutable would fail on some env and succeed on others. Very frustrating and hard to debug.

Should we instead not specify the option by default and let users either

  • add enableImmutableInstalls: true to .yarnrc.yml
  • or set with yarn env vars mechanism: YARN_ENABLE_IMMUTABLE_INSTALLS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is helpful feedback, thank you. I'm okay with making this configurable.

Comment on lines 234 to 246
- Include logic for Yarn Berry workflows in the existing `yarn-install`
buildpack.

Berry includes breaking changes to the `yarn` CLI used by the buildpack to
install dependencies. The changes to CLI options are such that at the very
least, the buildpack would need to decide which ones to use based on the type
of application being built. Trying to incorporate both workflows will
increase the scope of responsibility of the buildpack, likely increasing its
complexity at the expense of maintainability. Classic Yarn is now in
maintenance mode and, though it is still heavily used now (due to the
relatively slow adoption of Berry), its unclear how long it will be
supported. For this reason, it is even more prudent to keep the logic
separate to facilitate the eventual transition.
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be reasonable to still get Berry support in the existing buildpack if we just take some effort to keep the "Classic" and Berry parts separate. If we did something like move all the existing code in the buildpack into a classic package and then created a new berry package we can keep them logically separated. We could then just have a small amount of code at the top-level that decides with codepath to invoke.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hadn't considered separate packages, that's an interesting suggestion. It would remove a lot of overhead in the event that we drop support for Classic altogether.

id = "paketo-buildpacks/yarn-berry-install"

[[order.group]]
id = "paketo-buildpacks/node-module-bom"
Copy link
Member

Choose a reason for hiding this comment

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

Are any updates to this buildpack required to generate the SBOM in cases where there is a yarn cache instead of node_modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I think the inclusion of node-module-bom here is a mistake on my part. The buildpack shouldn't need to leverage that buildpack at all for generating the SBoM and would instead include logic for SBoM generation akin to what exists in yarn-install currently.

Comment on lines 229 to 230
All `node` commands run via the shell should be run with `yarn node` instead. The default
start command in the Yarn Start buildpack may need to be modified.
Copy link
Member

Choose a reason for hiding this comment

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

Can we elaborate on any changes needed to the yarn-start or node-start (included in the berry group above) buildpacks? Seems like there could be some gotchas here with detection criteria and cache vs modules configurations.

Comment on lines 70 to 71
[[order.group]]
id = "paketo-buildpacks/yarn-berry-install"
Copy link
Member

Choose a reason for hiding this comment

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

Should this be optional and opt out if users are going with the zero-installs method? This might mess up detection for the group without some changes in (yarn start), but it could be confusing to see yarn install opt-in when you are explicitly striving for zero-installs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This order group may now be obsolete as I was able to prove out a sane way to keep the build logic for both Yarn classic and Berry in a single buildpack (per @ryanmoran's suggestion). As for the UX, I figured we could indicate through the logs whenever the buildpack has chosen to forgo running yarn install based on adherence to the zero-installs setup.

@divoxx
Copy link

divoxx commented Jul 8, 2022

Is this RFC still actively being worked on? We have interest in helping push this forward as well, if help is needed.

@ekcasey
Copy link
Member

ekcasey commented Jul 12, 2022

@thitch97 IIRC you mentioned during WG you were making some largish changes to the RFC. Do you mind posting a comment describing where it is at and what your intentions are? If it needs more work before it is ready for further discussion/reviews maybe we should put it back into draft temporarily?

@thitch97 thitch97 marked this pull request as draft July 12, 2022 18:11
@thitch97
Copy link
Contributor Author

thitch97 commented Jul 12, 2022

@divoxx @ekcasey My intention at the moment is to shift to the model initially enumerated in the "Rationale and Alternatives" section. It turns out that hosting both Classic and Berry codepaths in one buildpack isn't as heavy an engineering/maintenance burden as it seemed (and in fact removes some overhead). As such, many of the technical decisions here, especially the order groupings, are now obsolete.

@divoxx
Copy link

divoxx commented Jul 12, 2022

Sounds good and thanks for the update @thitch97 & @ekcasey

We at @doximity are very interested in Yarn Berry support as well, so feel free to reach out to me in case any help is needed.

@thitch97 thitch97 marked this pull request as ready for review July 19, 2022 15:42
@fg-j
Copy link

fg-j commented Jul 19, 2022

From WG 7/19/22:

  • In latest update of this RFC, the Build Plan dependency node_modules has been renamed node_packages. This simplifies plan resolution.

  • In latest update, Yarn Berry builds still require yarn at build, instead of using corepack. This presents some issues that are hashed out in the Alternatives and Unresolved Questions sections.

  • Concern: Yarn Berry doesn't seem to play well with offline builds.

    • Comment: "offline" builds are rare; builds that only have access to a private network are more common
    • Comment: there still is a fully offline workflow for yarn 1
    • Q: Could we enable users to volume-mount a package cache for offline builds? The maven buildpack currently supports this?
      • This sounds tricky but possible. In yarn context, your global cache on your workstation might contain dependencies that don't have anything to do with the app in question. Also, the location of the package cache isn't configurable for yarn.
  • Requested change: Add a list of buildpacks that provide or require the node_modules plan entry so it's easy to tell which buildpacks would need to change

Seeking @paketo-buildpacks/nodejs-maintainers feedback on these changes.

Comment on lines 45 to 62
Provides: `node_pkgs`
Requires: `node`, `yarn` during `build`

The Node.js buildpacks use `node_modules` as a keyword for providing/requiring
packages in the build plan across the board. Since Berry explicitly excludes
`node_modules`, however, it seems reasonable to instead use a generic term for
node packages such as `node_pkgs`.

The buildpacks affected by this change to the `node_modules` build plan dependency are:

- `npm-install`
- `yarn-install`
- `npm-start`
- `yarn-start`
- `node-start`
- `node-run-script`
- `node-module-bom`
- `rails-assets`
Copy link
Member

Choose a reason for hiding this comment

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

Can you provide some more of the rational behind this choice? I'm not seeing how we don't end up in a state where its either confusing to Berry users or confusing to non-Berry users about what is being provided here.

Copy link
Contributor Author

@thitch97 thitch97 Jul 21, 2022

Choose a reason for hiding this comment

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

@ryanmoran The rationale was that node_modules is just not an artifact that is produced in the Berry PnP case. I thought that providing node_modules would be confusing to users who've opted into PnP, and that referring to them both as a set of Node.js "packages" was a reasonable compromise. It also seemed neater than using the Or field to provide either node_modules or something like yarn_cache.

Copy link

Choose a reason for hiding this comment

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

To me, it'd be more intuitive if the yarn classic and yarn berry paths resulted in two slightly different build plans, since they do involve dealing with different sets of artifacts.

I'd be in favor of the yarn-install buildpack providing node_modules if it plans on running yarn install and yarn_cache if it doesn't. Then the start command buildpacks could require one Or the other.

@joshuatcasey
Copy link
Contributor

joshuatcasey commented Jul 26, 2022

2022-07-26 Working Group notes:

Use different build plans for yarn classic and yarn berry (#194 (comment))

@fg-j fg-j self-requested a review August 2, 2022 18:26
@dmikusa
Copy link
Contributor

dmikusa commented Aug 2, 2022

2022-08-02 WG Notes:

Approved by Node maintainers. Final call for any comments. Scheduled to be merged soon.

@ryanmoran ryanmoran merged commit a6d500e into main Aug 3, 2022
@ryanmoran ryanmoran deleted the yarn2 branch August 3, 2022 17:32
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.

9 participants