{"id":18486838,"url":"https://github.com/devthefuture-org/yarn-plugin-fetch","last_synced_at":"2026-01-23T05:29:29.353Z","repository":{"id":177228405,"uuid":"627051050","full_name":"devthefuture-org/yarn-plugin-fetch","owner":"devthefuture-org","description":"Optimized yarn workflow for docker build","archived":false,"fork":false,"pushed_at":"2024-12-15T11:58:11.000Z","size":23961,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-15T12:28:52.574Z","etag":null,"topics":["berry","docker","docker-build","fetch","pnpm-fetch","yarn","yarn-lock-to-package-json"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devthefuture-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-12T17:22:05.000Z","updated_at":"2024-12-15T11:58:14.000Z","dependencies_parsed_at":"2024-11-06T12:53:57.607Z","dependency_job_id":"3a8bdc81-85d9-461c-b1de-82b383a8c76e","html_url":"https://github.com/devthefuture-org/yarn-plugin-fetch","commit_stats":null,"previous_names":["devthejo/yarn-plugin-fetch","devthefuture-org/yarn-plugin-fetch"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devthefuture-org%2Fyarn-plugin-fetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devthefuture-org%2Fyarn-plugin-fetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devthefuture-org%2Fyarn-plugin-fetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devthefuture-org%2Fyarn-plugin-fetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devthefuture-org","download_url":"https://codeload.github.com/devthefuture-org/yarn-plugin-fetch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247922536,"owners_count":21018815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["berry","docker","docker-build","fetch","pnpm-fetch","yarn","yarn-lock-to-package-json"],"created_at":"2024-11-06T12:49:52.603Z","updated_at":"2026-01-23T05:29:29.323Z","avatar_url":"https://github.com/devthefuture-org.png","language":"JavaScript","readme":"# yarn-plugin-fetch\n\nOptimized yarn workflow for docker build.\nDon't re-download all your dependencies on each package.json change.\n\nImplementation of pnpm [fetch](https://pnpm.io/cli/fetch) for yarn berry with additional features:\n\n- workspace focus support\n- custom install command\n\nIt work's by expanding your yarn.lock into package.json file(s) and structured workspaces.\n\n## requirements:\n\n- yarn berry (\u003e= 2)\n\n### migration to yarn berry\n\n- run `yarn set version berry` in your repository\n- .gitignore (without [zero install](#yarn-zero-install))\n  ```.gitignore\n  .pnp.*\n  .yarn/*\n  !.yarn/patches\n  !.yarn/plugins\n  !.yarn/releases\n  !.yarn/sdks\n  !.yarn/versions\n  ```\n  \n  https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored\n- to ensure retrocompatibility, put in your `.yarnrc.yml`: `nodeLinker: pnpm` (recommended, all advantages of pnpm symlink method) or `nodeLinker: node-modules` (better compatibility)\n\n## getting started\n\n```sh\nyarn plugin import https://codeberg.org/devthefuture/yarn-plugin-fetch/raw/branch/master/bundles/@yarnpkg/plugin-fetch.js\n```\n\n## Docker implementation\n\n### standalone repository\n\nDockerfile\n\n```Dockerfile\nCOPY yarn.lock .yarnrc.yml ./\nCOPY .yarn .yarn\nRUN yarn fetch --immutable\n\nCOPY . .\n\nRUN yarn postinstall # if you have postinstall script in your package.json\nRUN yarn build # and/or other build commands\n```\n\n#### production optimization\n\nThis is specific to yarn berry, not directly related to this plugin, but this documentation attempt to be a complete migration guide from yarn classic (v1) to yarn berry (v2+).\n\nYarn berry need [workspace-tools plugin](https://yarnpkg.com/api/modules/plugin_workspace_tools.html) to support `--production` (This plugin is included by default starting from Yarn 4).\n\nYou can install it with this simple command:\n\n```sh\nyarn plugin import workspace-tools\n```\n\nThen you can add this line of previous example:\n\n```Dockerfile\nRUN yarn workspaces focus --production\n```\n\nAnd if you have postinstall script in your package.json that needs dev dependencies, you can replace by this command instead:\n\n```Dockerfile\nRUN yarn fetch-tools production\n```\n\nAnd to get a lighter layer you can do:\n\n```Dockerfile\nRUN yarn fetch-tools production \u0026\u0026 yarn cache clean\n```\n\nNote: this optimization will make sense in case you make a multistage Dockerfile and copy node_modules in the final stage, eg:\n\n```Dockerfile\nFROM node as build\nCOPY yarn.lock .yarnrc.yml ./\nCOPY .yarn .yarn\nRUN yarn fetch --immutable\n\nCOPY . .\n\nRUN yarn postinstall # if you have postinstall script in your package.json\nRUN yarn build # and/or other build commands\nRUN yarn fetch-tools production\n\nFROM node as final\nCOPY --from=build /app/node_modules /app/node_modules\n```\n\n### monorepo\n\nYou need the [workspace-tools plugin](https://yarnpkg.com/api/modules/plugin_workspace_tools.html) to be installed to implement this example (This plugin is included by default starting from Yarn 4).\nYou can install it with `yarn plugin import workspace-tools`.\n\npackage/mypackage/Dockerfile\n\n```Dockerfile\nCOPY yarn.lock .yarnrc.yml ./\nCOPY .yarn .yarn\nRUN yarn fetch workspaces focus mypackage\n\nCOPY package/mypackage package/mypackage\n\n# COPY package/my-package-dep1 . # if you have one or many workspace dependencies\nRUN yarn workspaces foreach -At run postinstall # if you have postinstall scripts in your package.json file(s)\nRUN yarn workspace mypackage build # and/or other build commands\n\nRUN yarn workspaces focus mypackage --production\n```\n\n## extra commands (fetch-tools)\n\n### production\n\nThis need [workspace-tools plugin](https://yarnpkg.com/api/modules/plugin_workspace_tools.html) to support `--production` (This plugin is included by default starting from Yarn 4). You can install it with `yarn plugin import workspace-tools`.\n\nThis command will clean the dev dependencies (generally implemented after build):\n\n```sh\nyarn fetch-tools production\n```\n\nit's equivalent to\n\n```sh\nyarn fetch-tools disable-postinstall\nyarn workspaces focus --production\nyarn fetch-tools enable-postinstall\n```\n\nall extra arguments are transmitted as argument to `yarn workspaces focus --production` command.\n\n### expand-lock\n\nIf you don't want to install dependencies but want to expand the yarn.lock to package.json only, you can run:\n\n```sh\nyarn fetch-tools expand-lock\n```\n\n### postinstall\n\nthis is renaming the scripts postinstall key in package.json to \\_postinstall\n\n```sh\nyarn fetch-tools disable-postinstall\n```\n\nand this revert it\n\n```sh\nyarn fetch-tools enable-postinstall\n```\n\n## yarn zero-install\n\nIf you opt for yarn zero install, you probably don't need this plugin, but you still need workspace-tools plugin for optimization. Here is an example of an optimized Dockerfile for this case:\n\n```Dockerfile\nFROM node:20-alpine AS node\n\nRUN mkdir /app \u0026\u0026 chown 1000:1000 /app\nUSER 1000\nWORKDIR /app\nENTRYPOINT [ \"node\", \"index.js\" ]\n\nFROM node AS build\nCOPY --chown=1000:1000 . .\nRUN yarn\nRUN yarn buil\nRUN yarn workspaces focus --production \u0026\u0026 yarn cache clean\n\nFROM node\nCOPY --from=build /app /app\n```\n\n## further documentation\n\n### this plugin is based on the work of [Rohit Gohri](https://github.com/rohit-gohri) on the great package [yarn-lock-to-package-json](https://github.com/rohit-gohri/yarn-lock-to-package-json)\n\n- https://github.com/rohit-gohri/yarn-lock-to-package-json/\n\n### yarn issues\n\n- [Install without package.json](https://github.com/yarnpkg/yarn/issues/4813)\n- [Fetch dependencies from yarn.lock only](https://github.com/yarnpkg/berry/issues/4529)\n- [A command to just download and cache dependencies from lockfile](https://github.com/yarnpkg/berry/discussions/4380)\n\n\n## Contributing:\n\nWe welcome contributions! If you encounter a bug or have a feature suggestion, please open an issue. To contribute code, simply fork the repository and submit a pull request.\n\nThis repository is mirrored on both GitHub and Codeberg. Contributions can be made on either platform, as the repositories are synchronized bidirectionally. \n- Codeberg: [https://codeberg.org/devthefuture/yarn-plugin-fetch](https://codeberg.org/devthefuture/yarn-plugin-fetch)\n- GitHub: [https://github.com/devthefuture-org/yarn-plugin-fetch](https://github.com/devthefuture-org/yarn-plugin-fetch)\n\nFor more information:\n- [Why mirror to Codeberg?](https://codeberg.org/Recommendations/Mirror_to_Codeberg#why-should-we-mirror-to-codeberg)\n- [GitHub to Codeberg mirroring tutorial](https://codeberg.org/Recommendations/Mirror_to_Codeberg#github-codeberg-mirroring-tutorial)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevthefuture-org%2Fyarn-plugin-fetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevthefuture-org%2Fyarn-plugin-fetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevthefuture-org%2Fyarn-plugin-fetch/lists"}