{"id":26552734,"url":"https://github.com/codex-/rollup-plugin-conditional-exec","last_synced_at":"2025-03-22T08:49:24.521Z","repository":{"id":38848847,"uuid":"462939476","full_name":"Codex-/rollup-plugin-conditional-exec","owner":"Codex-","description":"Execute a given command after a bundle has been written, with optional conditions","archived":false,"fork":false,"pushed_at":"2025-03-20T02:24:16.000Z","size":1482,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-20T03:31:39.688Z","etag":null,"topics":["plugin","rollup","shell","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Codex-.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"ko_fi":"codex0","open_collective":"codex-nz"}},"created_at":"2022-02-23T23:24:08.000Z","updated_at":"2025-02-28T21:46:54.000Z","dependencies_parsed_at":"2023-02-19T12:01:24.108Z","dependency_job_id":"52b59a27-df40-43f3-aa8a-ce936bcbdef4","html_url":"https://github.com/Codex-/rollup-plugin-conditional-exec","commit_stats":{"total_commits":113,"total_committers":3,"mean_commits":"37.666666666666664","dds":0.6106194690265487,"last_synced_commit":"720807fdce8f103a9944b282fb0708f51a3344b7"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-%2Frollup-plugin-conditional-exec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-%2Frollup-plugin-conditional-exec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-%2Frollup-plugin-conditional-exec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-%2Frollup-plugin-conditional-exec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Codex-","download_url":"https://codeload.github.com/Codex-/rollup-plugin-conditional-exec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244931591,"owners_count":20534011,"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":["plugin","rollup","shell","typescript"],"created_at":"2025-03-22T08:49:23.945Z","updated_at":"2025-03-22T08:49:24.495Z","avatar_url":"https://github.com/Codex-.png","language":"TypeScript","funding_links":["https://ko-fi.com/codex0","https://opencollective.com/codex-nz"],"categories":[],"sub_categories":[],"readme":"# rollup-plugin-conditional-exec\n\n\u003e ⚙️🚀 Execute commands after writing a bundle with optionally provided conditions\n\n[![build](https://github.com/Codex-/rollup-plugin-conditional-exec/actions/workflows/build.yml/badge.svg)](https://github.com/Codex-/rollup-plugin-conditional-exec/actions/workflows/build.yml)\n[![codecov](https://codecov.io/gh/Codex-/rollup-plugin-conditional-exec/branch/main/graph/badge.svg?token=WWGNIPC249)](https://codecov.io/gh/Codex-/rollup-plugin-conditional-exec)\n[![npm](https://img.shields.io/npm/v/rollup-plugin-conditional-exec.svg)](https://www.npmjs.com/package/rollup-plugin-conditional-exec)\n\nThis package facilitates executing a given command after a bundle has been written by Rollup. The timing of the execution of the given command can be leveraged by providing a condition to satisfy before performing the command.\n\nFor example, if you are a Vite user and you generate bundled code for `es` \u0026 `umd`, you can write a condition function in your `vite.config.ts` that will only return true once both values have been observed, as Vite will run rollup twice to generate both of these.\n\nI built this primarily so that after each successful bundle had been generated, `yalc push` would be called.\n\n## Usage\n\nCreate a `rollup.config.js` configuration file and import this plugin:\n\n```ts\nimport conditionalExec from \"rollup-plugin-conditional-exec\";\n\nexport default {\n  input: \"src/index.js\",\n  output: {\n    file: \"dist/index.js\",\n    format: \"cjs\",\n  },\n  plugins: [\n    conditionalExec({\n      command: \"yalc push\",\n    }),\n  ],\n};\n```\n\n## Options\n\nTypings for the options are available by importing `RollupConditionalExecOptions`.\n\n### `command`\n\nType: `string`\nRequired: `true`\n\nThis is the command you want to be executed after a bundle has been written.\n\n### `options`\n\nType: `object`\nDefault: `{ stdio: \"inherit\" }`\n\nSee [`CommonExecOptions`](https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback) for available options.\n\nIf an options object is provided, it will override the default.\n\n### `condition`\n\nType: `() =\u003e Promise\u003cboolean\u003e | boolean` | `(outputOpts: OutputOptions) =\u003e Promise\u003cboolean\u003e | boolean`\nDefault: `() =\u003e true`\n\nProvide an optional condition to satisfy before a given command is executed. The condition command is passed in the `OutputOptions` that are give to `writeBundle` to allow you to leverage build time specific options. i.e. which bundle you are currently generating in a series of bundling operations.\n\n### `afterExec`\n\nType: `() =\u003e Promise\u003cvoid\u003e | void`\nDefault: `() =\u003e undefined`\n\nProvide an optional function to be executed after the command has been executed successfully. This can allow you to tidy up state, where you need to reset a state between bundles when running in a build watch mode or similar.\n\n### `onError`\n\nType: `(error: Error) =\u003e Promise\u003cvoid\u003e | void`\nDefault:\n\n```ts\n(error: Error) =\u003e {\n  console.error(`Exec has failed: ${error.message}`);\n  console.debug(error.stack);\n  throw error;\n};\n```\n\nProvide an optional function to be executed should your provided command fail to execute successfully. By default, this will log your error and then rethrow the error to prevent a silent failure.\n\n## How it works\n\n### This plugin leverages the following hooks provided by Rollup\n\n- Build Hooks\n  - [`buildStart`](https://rollupjs.org/guide/en/#buildstart)\n    - An assertion is completed here to validate that the command itself is both provided and not an empty string.\n- Output Generation Hooks\n  - [`writeBundle`](https://rollupjs.org/guide/en/#writebundle)\n    - It is at this stage that commands are executed via Nodes `exec` function.\n\n### Simplified Flow of used hooks\n\n```ascii\n┌──────────────── Rollup ────────────────┐\n│                                        │\n│                                        │\n│   ┌──────────────┐                     │\n│   │  buildStart  │                     │\n│   └───────┬──────┘                     │\n│           │                            │\n│           │                            │\n│           ▼                            │\n│   ┌──────────────┐                     │\n│   │  Assert cmd  │                     │\n│   │              ├─── false ──┐        │\n│   │  is defined  │            │        │\n│   └───────┬──────┘            │        │\n│           │                   │        │\n│           │                   │        │\n│         true                  │        │\n│           │                   ▼        │\n│           ▼              ┌─────────┐   │\n│   ┌───────────────┐      │  Fail   │   │\n│   │  writeBundle  │      │         │   │\n│   └───────┬───────┘      │  Build  │   │\n│           │              └─────────┘   │\n│           │                   ▲        │\n│           ▼                   │        │\n│     ┌───────────┐             │        │\n│     │  execute  │             │        │\n│     │           ├──── error ──┘        │\n│     │  command  │                      │\n│     └─────┬─────┘                      │\n│           │                            │\n│           │                            │\n│        success                         │\n│           │                            │\n│           │                            │\n│           ▼                            │\n│    ┌─────────────┐                     │\n│    │  Completed  │                     │\n│    └─────────────┘                     │\n│                                        │\n│                                        │\n└────────────────────────────────────────┘\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodex-%2Frollup-plugin-conditional-exec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodex-%2Frollup-plugin-conditional-exec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodex-%2Frollup-plugin-conditional-exec/lists"}