{"id":13565943,"url":"https://github.com/Andarist/cherry-pick","last_synced_at":"2025-04-03T23:30:46.967Z","repository":{"id":33765851,"uuid":"133144979","full_name":"Andarist/cherry-pick","owner":"Andarist","description":"🍒⛏📦 Build tool to generate proxy directories.","archived":false,"fork":false,"pushed_at":"2022-05-02T16:34:42.000Z","size":38,"stargazers_count":57,"open_issues_count":7,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T14:52:24.331Z","etag":null,"topics":["build","build-tool","tool"],"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/Andarist.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}},"created_at":"2018-05-12T12:41:13.000Z","updated_at":"2025-02-19T06:45:51.000Z","dependencies_parsed_at":"2022-08-08T05:15:18.284Z","dependency_job_id":null,"html_url":"https://github.com/Andarist/cherry-pick","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andarist%2Fcherry-pick","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andarist%2Fcherry-pick/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andarist%2Fcherry-pick/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andarist%2Fcherry-pick/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Andarist","download_url":"https://codeload.github.com/Andarist/cherry-pick/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247097616,"owners_count":20883121,"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":["build","build-tool","tool"],"created_at":"2024-08-01T13:01:58.512Z","updated_at":"2025-04-03T23:30:46.389Z","avatar_url":"https://github.com/Andarist.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# cherry-pick 🍒⛏📦\n\nBuild tool to generate proxy directories with `package.json` files such as this:\n\n```json\n{\n  \"name\": \"redux-saga/effects\",\n  \"private\": true,\n  \"main\": \"../lib/effects.js\",\n  \"module\": \"../es/effects.js\"\n}\n```\n\n## Why?\n\nWhen it comes to \"main\" entry points of our libraries we have an _easy_ way for\nsupporting both CJS \u0026 ESM files with respectively `\"main\"` and `\"module\"` fields\nin `package.json`. This allows resolution algorithms to chose a file with the\nbest format _automatically_. However if we have multiple files in a package and\nwe want all of them to be importable we often suggest to users doing it like\nthis:\n\n```js\nimport module from \"package/lib/module\";\n```\n\nThere are problems with this approach:\n\n* it is often encouraging people to import files authored in CJS format, which\n  if produced with tools like [`babel`](https://github.com/babel/babel) has i.e.\n  interop helper functions deoptimizing imported file size when comparing to the\n  same file authored in ESM format. Also `webpack` just bails out on CJS files\n  when trying to optimize your application size with techniques such as\n  tree-shaking \u0026 scope hoisting (a.k.a module concatenation).\n* it is exposing **internal directory structure** to the user. Why `lib` is in\n  the requested path? If you ship both CJS \u0026 ESM directories to `npm` and if\n  users would like to import appropriate file depending on the tool they are\n  \"forced\" to remember this and switch between importing the same thing with\n  paths like `package/lib/module` and `package/es/module`. This is a mental\n  overhead that can be avoided.\n\nThis technique was also described by me in more details in\n[this article](https://developers.livechatinc.com/blog/how-to-create-javascript-libraries-in-2018-part-2#proxy-directories).\n\n## CLI Options\n\n### default\n\n```\ncherry-pick [input-dir]\n\nCreate proxy directories\n\nCommands:\n  cherry-pick [input-dir]        Create proxy directories              [default]\n  cherry-pick clean [input-dir]  Cleanup generated directories\n\nOptions:\n  --help, -h     Show help                                             [boolean]\n  --version, -v  Show version number                                   [boolean]\n  --cjs-dir                                                     [default: \"lib\"]\n  --esm-dir                                                      [default: \"es\"]\n  --types-dir\n  --cwd                                                           [default: \".\"]\n  --input-dir                                                   [default: \"src\"]\n```\n\n### clean\n\n```\ncherry-pick clean [input-dir]\n\nCleanup generated directories\n\nOptions:\n  --help, -h     Show help                                             [boolean]\n  --version, -v  Show version number                                   [boolean]\n  --cwd                                                           [default: \".\"]\n  --input-dir                                                   [default: \"src\"]\n```\n\n## JS API\n\n`cherry-pick` exports a `default` method which creates proxy directories and\n`clean` which removes them. Both accepts the same options as corresponding CLI\ncommands, only they are camelCased.\n\n```js\nconst { default: cherryPick, clean } = require(\"cherry-pick\");\n\ncherryPick({ inputDir: \"source\" })\n  .then(cherryPicked =\u003e\n    console.log(`Created proxy directories: ${cherryPicked.join(\", \")}`)\n  )\n  .then(() =\u003e clean({ inputDir: \"source\" }))\n  .then(removed =\u003e\n    console.log(`Removed proxy directories: ${Removed.join(\", \")}`)\n  );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAndarist%2Fcherry-pick","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAndarist%2Fcherry-pick","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAndarist%2Fcherry-pick/lists"}