You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For docker builds it would be nice to be able to run yarn with only the lock file, i.e. without the package.json file. Currently, whenever we run npm version patch we have to re-install all dependencies even though nothing has changed... :/
Reacted by Mark Penner, JC, Jon Goodger, brain4711, Pavel White, Sebastian Mellen, Andrew Scott, Mattia Fantoni, Nikita Eliseev, Alex Guerra and 3 more
Yarn needs both package.json and yarn.lock files by design and I don't think that will change anytime soon if ever.
I think instead of copying all files in the directory, you can find a way to leverage Docker's layered file system with selectively copying files over.
Reacted by Pulkit Gupta, Mattia Fantoni and Jonathan Holford
@BYK I don't see anyway to resolve this otherwise? Since the package.json is changed during versioning and it has to be included before you run yarn you always have to re-install all dependencies even if they haven't changed...
Reacted by Jack McCown, Kevin McBride, Sergio Alvarez Diaz, Alex Cardell, Nick, Stillward, Manuel Lopez, Vladislav, JC, Jon Goodger and 5 more
May be using another file to save the version, like VERSION. use semver -i patch <version> to generate the new version and use fs.writeFileSync to save it to VERSION file
I'm into doing the same thing as I'm using yarn workspaces, and otherwise I have to pull in and concatenate dependencies from the package.json files in each submodule I've added to my project. If I could just install from yarn.lock which is in the top-level directory and lists all the hoisted packages of all the submodules, I could just copy that over to the base Docker layer and save myself the trouble...
Thats a clever sollution @rohit-gohri, and also kinda proves that requiring the package.jsons for yarn install --immutable is arbitrary if you are able to generate what yarn wants from the lockfile.
I wonder if doing this as a plugin instead would be possible.
I wonder if doing this as a plugin instead would be possible.
@sod I tried doing it but could not figure out yarn internals 😅 , this way ended up being easier. There is a issue in yarn v2+ where the author tried implementing a plugin - yarnpkg/berry#4529
Activity
BYK commentedon Nov 1, 2017
Yarn needs both
package.jsonandyarn.lockfiles by design and I don't think that will change anytime soon if ever.I think instead of copying all files in the directory, you can find a way to leverage Docker's layered file system with selectively copying files over.
ronag commentedon Nov 1, 2017
@BYK I don't see anyway to resolve this otherwise? Since the package.json is changed during versioning and it has to be included before you run
yarnyou always have to re-install all dependencies even if they haven't changed...stillward commentedon Apr 17, 2019
May be using another file to save the version, like VERSION. use
semver -i patch <version>to generate the new version and usefs.writeFileSyncto save it to VERSION fileDownchuck commentedon Jun 25, 2019
This is an awful experience when using offline workspaces with Docker as the primary yarn.lock does contain information for unpacking files.
sebmellen commentedon Feb 7, 2021
@BYK and @ronag and @Downchuck have any of you found a way to resolve this yet?
I'm into doing the same thing as I'm using yarn workspaces, and otherwise I have to pull in and concatenate dependencies from the
package.jsonfiles in each submodule I've added to my project. If I could just install fromyarn.lockwhich is in the top-level directory and lists all the hoisted packages of all the submodules, I could just copy that over to the base Docker layer and save myself the trouble...Kinda stumped looking for ways around this.
psigen commentedon Oct 19, 2022
@sebmellen @Downchuck @ronag: FWIW, this is specifically addressed in
pnpm, which adds a command called pnpm fetch to do this exact thing for this exact purpose (and is specifically cited for docker builds):https://pnpm.io/cli/fetch
rohit-gohri commentedon Jan 7, 2023
I created a small helper for yarn berry (v2+) inspired by pnpm's fetch that recreates the workspace just from the lockfile so yarn can do a successful install - https://github.com/rohit-gohri/yarn-lock-to-package-json
This means docker layer cache is not invalidated due to random changes in package.jsons
sod commentedon Mar 2, 2023
Thats a clever sollution @rohit-gohri, and also kinda proves that requiring the package.jsons for
yarn install --immutableis arbitrary if you are able to generate what yarn wants from the lockfile.I wonder if doing this as a plugin instead would be possible.
rohit-gohri commentedon Mar 2, 2023
@sod I tried doing it but could not figure out yarn internals 😅 , this way ended up being easier. There is a issue in yarn v2+ where the author tried implementing a plugin - yarnpkg/berry#4529
devthejo commentedon Apr 12, 2023
here is my plugin (based on yarn-lock-to-package-json):
https://github.com/devthejo/yarn-plugin-fetch