{"_id":"@rolldown/pluginutils@1.1.1","bugs":{"url":"https://github.com/rolldown/plugins/issues"},"dist":{"shasum":"bdb13954851dc43ef5b03992618e0ed5e03c0598","tarball":"http://registry-npm.ywwl.com/@rolldown/pluginutils/download/@rolldown/pluginutils-1.1.1.tgz","fileCount":8,"integrity":"sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==","signatures":[{"sig":"MEUCIQDY+yGbSKWaNccSZY5yrW/C4KLBym3aVqDGQbp2uAJwoQIgC1/VdT5a9kX8AbR0s0iTgrQLJbfzfHxyaWJ6NH6T1o8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDM/cuP4pR43bkxJuHSfK2SGXddEXBqoejQmPn4oQ3JKAiEA8Zfwip8nI1lPc09AGaGtB1Dyumt1rndNpL1KcUNVQTg="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@rolldown%2fpluginutils@1.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":26794,"size":6884,"noattachment":false,"key":"/@rolldown/pluginutils/-/@rolldown/pluginutils-1.1.1.tgz"},"name":"@rolldown/pluginutils","type":"module","exports":{".":"./dist/index.mjs","./filter":"./dist/filter/index.mjs","./package.json":"./package.json"},"license":"MIT","scripts":{"dev":"tsdown --watch","test":"vitest --project pluginutils","build":"tsdown","test:types":"vitest --project pluginutils --typecheck.only"},"version":"1.1.1","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"77656156-ea92-4b3d-8eeb-e1d4ecbcd46d"}},"homepage":"https://github.com/rolldown/plugins/tree/main/packages/pluginutils#readme","keywords":["filter","plugin","rolldown"],"repository":{"url":"git+https://github.com/rolldown/plugins.git","type":"git","directory":"packages/pluginutils"},"description":"Plugin utilities for Rolldown","directories":{},"maintainers":[{"name":"broooooklyn","email":"lynweklm@gmail.com"},{"name":"yyx990803","email":"yyx990803@gmail.com"},{"name":"rolldownbot","email":"rolldown@voidzero.dev"},{"name":"sapphi-red","email":"green@sapphi.red"}],"_hasShrinkwrap":false,"devDependencies":{"picomatch":"^4.0.7","typescript":"^7.0.2","@types/picomatch":"^4.0.3"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pluginutils_1.1.1_1794559739495_0.5580460399836077"},"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 {\n  exactRegex,\n  prefixRegex,\n  wordRegex,\n  makeIdFiltersToMatchWithQuery,\n} 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### `wordRegex`\n\n- **Type:** `(str: string, flags?: string) => RegExp`\n\nConstructs a `RegExp` that matches a standalone word-like token.\nUseful when you want to match `node_modules` but not `node_modulesa`.\n\n```ts\nimport { wordRegex } from '@rolldown/pluginutils'\n\nconst plugin = {\n  name: 'plugin',\n  resolveId: {\n    filter: { id: wordRegex('node_modules') },\n    handler(id) {}, // called for IDs containing standalone `node_modules`\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":1794559739591,"_cnpm_publish_time":1794559739591,"dist-tags":{"canary":"1.0.0-beta.31-commit.832324a","latest":"1.1.1","nightly":"1.0.0-beta.13-commit.024b632"}}