{"id":34996408,"url":"https://github.com/avisek/rollup-patch-seamless-default-export","last_synced_at":"2025-12-27T02:16:14.408Z","repository":{"id":198953864,"uuid":"701881560","full_name":"avisek/rollup-patch-seamless-default-export","owner":"avisek","description":"Rollup patch for adding `module.exports = defaultExport`","archived":false,"fork":false,"pushed_at":"2023-10-07T21:49:28.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"npm","last_synced_at":"2025-03-02T00:06:58.305Z","etag":null,"topics":["default","exports","module-exports","named","patch","rollup"],"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/avisek.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}},"created_at":"2023-10-07T20:53:50.000Z","updated_at":"2023-12-07T02:43:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"4f435e4a-3fa8-40e0-81aa-4cd72fb57160","html_url":"https://github.com/avisek/rollup-patch-seamless-default-export","commit_stats":null,"previous_names":["avisek/rollup-patch-seamless-default-export"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/avisek/rollup-patch-seamless-default-export","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avisek%2Frollup-patch-seamless-default-export","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avisek%2Frollup-patch-seamless-default-export/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avisek%2Frollup-patch-seamless-default-export/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avisek%2Frollup-patch-seamless-default-export/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avisek","download_url":"https://codeload.github.com/avisek/rollup-patch-seamless-default-export/tar.gz/refs/heads/npm","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avisek%2Frollup-patch-seamless-default-export/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28069258,"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","status":"online","status_checked_at":"2025-12-27T02:00:05.897Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["default","exports","module-exports","named","patch","rollup"],"created_at":"2025-12-27T02:16:05.581Z","updated_at":"2025-12-27T02:16:14.403Z","avatar_url":"https://github.com/avisek.png","language":"JavaScript","readme":"# A patch for `rollup` that allows you to consume `default` and `named` exports from your library like this,\n\n```js\n// Default export\nconst lib = require('your-library')\nlib('Hello') // \u003c-- instead of using `.default` property\n\n// Named exports\nconst { namedExport1, namedExport2 } = lib\n\n// One liner syntex. This is also supported.\nconst { default: defaultExport, namedExport1, namedExport2 } = require('your-library')\n```\n\nYour library (sample code for context):\n\n```js\nexport default function defaultExport(msg) {\n  console.log(`${msg} from default export`)\n}\n\nexport const namedExport1 = 'named export 1'\nexport const namedExport2 = 'named export 2'\n```\n\n## Why?\n\nFor syntactic sugar.\n\n```js\n// Without this patch if you transform ESM to CJS\n// and have both `default` and `named` exports in a single file,\n// whatever you export as default will get assigned to\n// `module.exports.default` instead of `module.exports`.\n// So if somebody `require()`s your module they'll have to\n// access your default export like this,\nconst lib = require('your-library').default // \u003c-- it looks bad\n//                                  ^^^^^^^\n```\n\nRead [this](https://stackoverflow.com/questions/58246998/mixing-default-and-named-exports-with-rollup) and [this thread](https://github.com/rollup/rollup/issues/1961) for more context.\n\n## How to use the patch? \u003csub\u003e\u003csup\u003e(\u003c/sub\u003e\u003c/sup\u003e[\u003csub\u003e\u003csup\u003epnpm version\u003c/sub\u003e\u003c/sup\u003e](https://github.com/avisek/rollup-patch-seamless-default-export/tree/pnpm#how-to-use-the-patch-npm-version)\u003csub\u003e\u003csup\u003e)\u003c/sub\u003e\u003c/sup\u003e\n\nDownload and include the [patch file](https://github.com/avisek/rollup-patch-seamless-default-export/blob/npm/patches/rollup+3.29.4.patch)\n\n```diff\n  .\n  ├── ...\n+ ├── patches\n+ │   └── rollup+3.29.4.patch\n  └── package.json\n```\n\nAdd `postinstall` script in `package.json`\n\n```diff\n  ...\n  \"scripts\": {\n    \"build\": \"rollup -c\",\n+   \"postinstall\": \"patch-package\"\n  },\n  \"devDependencies\": {\n    \"rollup\": \"^3.29.4\"   \u003c-- Make sure rollup's version is the same as the patch\n  }\n  ...\n```\n\nInstall `patch-package`\n\n```sh\nnpm install patch-package --save-dev\n```\nDone.\n\n## How does it work?\n\nIt modifies `rollup`'s output like this,\n\n```diff\n+ exports = module.exports = defaultExport;\n+ exports.default = defaultExport;\n  exports.namedExport1 = namedExport1;\n  exports.namedExport2 = namedExport2;\n- exports.default = defaultExport;\n```\n\n## Caveats\n\nYou can not use primitive type values (e.g. `string`, `number`, `boolean`) as your `defaut` export. If you do, then your `named` exports will not work.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favisek%2Frollup-patch-seamless-default-export","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favisek%2Frollup-patch-seamless-default-export","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favisek%2Frollup-patch-seamless-default-export/lists"}