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

[Feature] Fetch dependencies from yarn.lock only #4529

Open
1 of 2 tasks
edsrzf opened this issue Jun 5, 2022 · 2 comments
Open
1 of 2 tasks

[Feature] Fetch dependencies from yarn.lock only #4529

edsrzf opened this issue Jun 5, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@edsrzf
Copy link

edsrzf commented Jun 5, 2022

  • I'd be willing to implement this feature (contributing guide)
  • This feature is important to have in this repository; a contrib plugin wouldn't do

Describe the user story

As a developer maintaining a CI pipeline, I want to keep a dependency cache that invalidates only when yarn.lock changes. However, yarn install requires all workspace package.json files in addition to yarn.lock, which means that the cache invalidates more often than it needs to.

It should be possible to populate the cache using only yarn.lock and no package.json files. The documentation for the pnpm fetch command describes exactly my use case and is similar to the solution I'm proposing.

Describe the solution you'd like

I imagine a yarn fetch command. It would perform a version of dependency resolution using only yarn.lock and populate the cache. Later, dependencies could be linked with yarn install --immutable --immutable-cache.

The command could be an external plugin, but currently it's difficult to implement (though possible). Ideally the command would consist mainly of calling Project.resolveEverything, followed by Project.fetchEverything, but currently there are two challenges:

  • resolveEverything requires reading all workspace package.json files. There's no way to avoid this except to reimplement the necessary pieces within the plugin, duplicating logic.
  • fetchEverything depends on resolveEverything, but mostly works otherwise. WorkspaceFetcher relies on package.json information, but it's not too hard to provide a custom Fetcher implementation to work around this.

There may be other problems; I've only tried writing a plugin that works for my monorepo use case.

Describe the drawbacks of your solution

A little bit of added complexity and increased surface area for the core API.

Describe alternatives you've considered

I've written a plugin that works for my use case, but it has to reimplement various parts of resolveEverything itself in order for fetchEverything to work properly. It feels fragile and unnecessarily complicated. It's hard for me to be sure that I've implemented it correctly since I'm not very familiar with Yarn internals.

@edsrzf edsrzf added the enhancement New feature or request label Jun 5, 2022
@rohit-gohri
Copy link

rohit-gohri commented Dec 3, 2022

I created a small package that recreates the full workspace structure with dummy package.jsons just from the yarn.lock file. You can use it in Dockerfile to do a yarn install - /~https://github.com/rohit-gohri/yarn-lock-to-package-json

Use like this

COPY .yarn ./.yarn
COPY yarn.lock .yarnrc.yml ./

RUN yarn dlx yarn-lock-to-package-json

RUN yarn install --immutable

This way you don't need to create a special command since yarn install itself works

@devthejo
Copy link
Contributor

here is my plugin (based on yarn-lock-to-package-json):
/~https://github.com/devthejo/yarn-plugin-fetch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants