{"name":"@rolldown/pluginutils","version":"1.0.0-beta.8-commit.a29b7fb","license":"MIT","_id":"@rolldown/pluginutils@1.0.0-beta.8-commit.a29b7fb","maintainers":[{"name":"broooooklyn","email":"lynweklm@gmail.com"},{"name":"yyx990803","email":"yyx990803@gmail.com"},{"name":"rolldownbot","email":"rolldown@voidzero.dev"}],"homepage":"https://github.com/rolldown/rolldown#readme","bugs":{"url":"https://github.com/rolldown/rolldown/issues"},"dist":{"shasum":"93d8a70530d0d33b65b32a458fc71ac6e95c5b8b","tarball":"http://registry-npm.ywwl.com/@rolldown/pluginutils/download/@rolldown/pluginutils-1.0.0-beta.8-commit.a29b7fb.tgz","fileCount":6,"integrity":"sha512-s5nJ3TK5IjznUXCY5njlgYUgWjIdaQYYdZX5zz8EML5+RX0YVS++tN4RNfhtPQrbrzpA7ANjUTH+aJeqgr0mbQ==","signatures":[{"sig":"MEYCIQCXMC03lRiTfEZsCzv8I9TcjhKbYHkmhs9N+uqukWH7VQIhAOBBR2oP81Hax0Yab3cDvtkd5GWb23otXCxvHfBhjrz3","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@rolldown%2fpluginutils@1.0.0-beta.8-commit.a29b7fb","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":23858,"size":4140,"noattachment":false,"key":"/@rolldown/pluginutils/-/@rolldown/pluginutils-1.0.0-beta.8-commit.a29b7fb.tgz"},"main":"./dist/index.cjs","type":"module","_from":"file:rolldown-pluginutils-1.0.0-beta.8-commit.a29b7fb.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs"}},"scripts":{"test":"vitest --typecheck","build":"tsdown"},"_npmUser":{"name":"rolldownbot","email":"rolldown@voidzero.dev"},"_resolved":"/tmp/2069d8ae6234c717e2e5e1abcb85c4ee/rolldown-pluginutils-1.0.0-beta.8-commit.a29b7fb.tgz","_integrity":"sha512-s5nJ3TK5IjznUXCY5njlgYUgWjIdaQYYdZX5zz8EML5+RX0YVS++tN4RNfhtPQrbrzpA7ANjUTH+aJeqgr0mbQ==","repository":{"url":"git+https://github.com/rolldown/rolldown.git","type":"git","directory":"packages/pluginutils"},"_npmVersion":"10.9.2","directories":{},"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"0.11.1","vitest":"^3.0.1","picomatch":"^4.0.2","@types/picomatch":"^4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/pluginutils_1.0.0-beta.8-commit.a29b7fb_1747504971855_0.7615483775274374","host":"s3://npm-registry-packages-npm-production"},"readme":"# @rolldown/pluginutils [![npm](https://img.shields.io/npm/v/@rolldown/pluginutils.svg)](https://npmx.dev/package/@rolldown/pluginutils)\n\nPlugin utilities for [Rolldown](https://rolldown.rs).\n\nIncludes regex helpers for plugin hook filters, composable filter expressions, and a helper for filtering out Vite-serve-only plugins.\n\n## Install\n\n```bash\npnpm add -D @rolldown/pluginutils\n```\n\n## Usage\n\n```ts\nimport { exactRegex, prefixRegex, makeIdFiltersToMatchWithQuery } from '@rolldown/pluginutils'\n```\n\nAll filter helpers are also exposed via the `/filter` subpath:\n\n```ts\nimport { and, or, id, include } from '@rolldown/pluginutils/filter'\n```\n\n## Regex helpers\n\n### `exactRegex`\n\n- **Type:** `(str: string, flags?: string) => RegExp`\n\nConstructs a `RegExp` that matches the exact string specified. Useful as a plugin hook filter.\n\n```ts\nimport { exactRegex } from '@rolldown/pluginutils'\n\nconst plugin = {\n  name: 'plugin',\n  resolveId: {\n    filter: { id: exactRegex('foo') },\n    handler(id) {}, // only called for `foo`\n  },\n}\n```\n\n### `prefixRegex`\n\n- **Type:** `(str: string, flags?: string) => RegExp`\n\nConstructs a `RegExp` that matches values starting with the specified prefix.\n\n```ts\nimport { prefixRegex } from '@rolldown/pluginutils'\n\nconst plugin = {\n  name: 'plugin',\n  resolveId: {\n    filter: { id: prefixRegex('foo') },\n    handler(id) {}, // called for IDs starting with `foo`\n  },\n}\n```\n\n### `makeIdFiltersToMatchWithQuery`\n\n- **Type:** `(input: string | RegExp | (string | RegExp)[]) => string | RegExp | (string | RegExp)[]`\n\nConverts an id filter so that it also matches ids that include a query string.\n\n```ts\nimport { makeIdFiltersToMatchWithQuery } from '@rolldown/pluginutils'\n\nconst plugin = {\n  name: 'plugin',\n  transform: {\n    filter: { id: makeIdFiltersToMatchWithQuery(['**/*.js', /\\.ts$/]) },\n    // Matches:\n    //   foo.js, foo.js?foo, foo.txt?foo.js,\n    //   foo.ts, foo.ts?foo, foo.txt?foo.ts\n    handler(code, id) {},\n  },\n}\n```\n\n## Composable filters\n\n[Composable filter expressions](https://rolldown.rs/apis/plugin-api/hook-filters#composable-filters) for use cases where a simple `id`/`include`/`exclude` is not enough. For example, when a plugin needs to combine `id`, `moduleType`, `code`, and `query` conditions.\n\n```ts\nimport { and, code, id, include, interpreter, moduleType, or } from '@rolldown/pluginutils'\n\nconst expr = include(and(or(id(/\\.tsx?$/), id(/\\.jsx?$/)), moduleType('tsx'), code(/import React/)))\n\ninterpreter(expr, sourceCode, sourceId, 'tsx') // boolean\n```\n\n### Builders\n\n| Builder                        | Description                                                                                                                                              |\n| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `and(...exprs)`                | All operands must match.                                                                                                                                 |\n| `or(...exprs)`                 | At least one operand must match.                                                                                                                         |\n| `not(expr)`                    | Negates the operand.                                                                                                                                     |\n| `id(pattern, params?)`         | Match the module id. `pattern` is `string` or `RegExp`. `params.cleanUrl` strips the query/hash before matching.                                         |\n| `importerId(pattern, params?)` | Match the importer's id. Same shape as `id`.                                                                                                             |\n| `moduleType(type)`             | Match Rolldown's module type (`'js'`, `'jsx'`, `'ts'`, `'tsx'`, `'json'`, `'text'`, `'base64'`, `'dataurl'`, `'binary'`, `'empty'`, or a custom string). |\n| `code(pattern)`                | Match the module source. `string` matches with `includes`; `RegExp` with `test`.                                                                         |\n| `query(key, pattern)`          | Match a single query parameter. `pattern` is `boolean` (key presence/truthiness), `string` (exact value), or `RegExp` (value pattern).                   |\n| `queries(obj)`                 | Shorthand for `and(...)` over multiple `query` entries.                                                                                                  |\n| `include(expr)`                | Top-level wrapper marking `expr` as an inclusion rule.                                                                                                   |\n| `exclude(expr)`                | Top-level wrapper marking `expr` as an exclusion rule.                                                                                                   |\n\n### `interpreter`\n\n- **Type:** `(exprs, code?, id?, moduleType?, importerId?) => boolean`\n\nEvaluates one or more top-level expressions against the given inputs. Returns `true` when at least one `include` matches and no `exclude` matches; when no `include` is present, defaults to `true` unless an `exclude` matches.\n\nThe argument required by each expression must be provided. For example, evaluating an `id(...)` expression without passing `id` will throw.\n\n## `filterVitePlugins`\n\n- **Type:** `<T>(plugins: T | T[] | null | undefined | false) => T[]`\n\nRemoves Vite plugins that target the dev server (`apply: 'serve'`) from a (possibly nested) plugin array. Plugins whose `apply` is a function are invoked with a `command: 'build'` context to decide. Useful when reusing a Vite plugin array inside a Rolldown config.\n\n```ts\nimport { defineConfig } from 'rolldown'\nimport { filterVitePlugins } from '@rolldown/pluginutils'\nimport viteReact from '@vitejs/plugin-react'\n\nexport default defineConfig({\n  plugins: filterVitePlugins([\n    viteReact(),\n    {\n      name: 'dev-only',\n      apply: 'serve', // filtered out\n      // ...\n    },\n  ]),\n})\n```\n\n## License\n\nMIT\n","publish_time":1747504972051,"_cnpm_publish_time":1747504972051,"dist-tags":{"canary":"1.0.0-beta.31-commit.832324a","latest":"1.1.1","nightly":"1.0.0-beta.13-commit.024b632"}}