@rolldown/pluginutils 1.0.0-beta.27 → 1.0.0-beta.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +85 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # @rolldown/pluginutils
2
+
3
+ A utility library for building flexible, composable filter expressions that can be used in plugin hook filters of Rolldown/Vite/Rollup/Unplugin plugins.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ pnpm add @rolldown/pluginutils
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Simple Filters
14
+
15
+ ```ts
16
+ import {
17
+ exactRegex,
18
+ makeIdFiltersToMatchWithQuery,
19
+ prefixRegex,
20
+ } from '@rolldown/pluginutils';
21
+
22
+ // Match exactly 'foo.js'
23
+ const filter = exactRegex('foo.js');
24
+
25
+ // Match any id starting with 'lib/'
26
+ const prefix = prefixRegex('lib/');
27
+
28
+ // Match ids with query params (e.g. 'foo.js?bar')
29
+ const idFilters = makeIdFiltersToMatchWithQuery(['**/*.js', /\.ts$/]);
30
+
31
+ // Usage in a plugin to define a hook filter
32
+ const myPlugin = {
33
+ resolveId: {
34
+ filter: {
35
+ id: [exactRegex('MY_ID_TO_CHECK'), /some-other-regex/],
36
+ },
37
+ handler(id) {
38
+ // Your code here
39
+ },
40
+ },
41
+ };
42
+ ```
43
+
44
+ ### Composable Filters
45
+
46
+ > [!WARNING] Composable filters are not yet supported in Vite, Rolldown-Vite or unplugin. They can be used in Rolldown plugins only.
47
+
48
+ ```ts
49
+ import { and, id, include, moduleType, query } from '@rolldown/pluginutils';
50
+
51
+ // Build a filter expression
52
+ const filterExpr = and(
53
+ id(/\.ts$/),
54
+ moduleType('ts'),
55
+ query('foo', true),
56
+ );
57
+
58
+ // Usage in a plugin to define a hook filter
59
+ const myPlugin = {
60
+ transform: {
61
+ filter: [include(filterExpr)],
62
+ handler(code, id, options) {
63
+ // Your code here
64
+ },
65
+ },
66
+ };
67
+ ```
68
+
69
+ ## API Reference
70
+
71
+ ### Simple Filters
72
+
73
+ - `exactRegex(str: string, flags?: string): RegExp` — Matches the exact string.
74
+ - `prefixRegex(str: string, flags?: string): RegExp` — Matches values with the given prefix.
75
+ - `makeIdFiltersToMatchWithQuery(input: string | RegExp | (string | RegExp)[]): string | RegExp | (string | RegExp)[]` — Adapts filters to match ids with query params.
76
+
77
+ ### Composable Filters
78
+
79
+ - `and(...exprs)` / `or(...exprs)` / `not(expr)` — Logical composition of filter expressions.
80
+ - `id(pattern, params?)` — Filter by id (string or RegExp).
81
+ - `moduleType(type)` — Filter by module type (e.g. 'js', 'tsx', or 'json').
82
+ - `code(pattern)` — Filter by code content.
83
+ - `query(key, pattern)` — Filter by query parameter.
84
+ - `include(expr)` / `exclude(expr)` — Top-level include/exclude wrappers.
85
+ - `queries(obj)` — Compose multiple query filters.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolldown/pluginutils",
3
- "version": "1.0.0-beta.27",
3
+ "version": "1.0.0-beta.28",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {