v1.0 with SW PWA enabled

This commit is contained in:
Blomios
2026-01-01 17:40:53 +01:00
parent 1c0e22aac1
commit 3c8bebb2ad
29775 changed files with 2197201 additions and 119080 deletions

View File

@ -1,85 +0,0 @@
# @rolldown/pluginutils
A utility library for building flexible, composable filter expressions that can be used in plugin hook filters of Rolldown/Vite/Rollup/Unplugin plugins.
## Installation
```sh
pnpm add @rolldown/pluginutils
```
## Usage
### Simple Filters
```ts
import {
exactRegex,
makeIdFiltersToMatchWithQuery,
prefixRegex,
} from '@rolldown/pluginutils';
// Match exactly 'foo.js'
const filter = exactRegex('foo.js');
// Match any id starting with 'lib/'
const prefix = prefixRegex('lib/');
// Match ids with query params (e.g. 'foo.js?bar')
const idFilters = makeIdFiltersToMatchWithQuery(['**/*.js', /\.ts$/]);
// Usage in a plugin to define a hook filter
const myPlugin = {
resolveId: {
filter: {
id: [exactRegex('MY_ID_TO_CHECK'), /some-other-regex/],
},
handler(id) {
// Your code here
},
},
};
```
### Composable Filters
> [!WARNING] Composable filters are not yet supported in Vite, Rolldown-Vite or unplugin. They can be used in Rolldown plugins only.
```ts
import { and, id, include, moduleType, query } from '@rolldown/pluginutils';
// Build a filter expression
const filterExpr = and(
id(/\.ts$/),
moduleType('ts'),
query('foo', true),
);
// Usage in a plugin to define a hook filter
const myPlugin = {
transform: {
filter: [include(filterExpr)],
handler(code, id, options) {
// Your code here
},
},
};
```
## API Reference
### Simple Filters
- `exactRegex(str: string, flags?: string): RegExp` — Matches the exact string.
- `prefixRegex(str: string, flags?: string): RegExp` — Matches values with the given prefix.
- `makeIdFiltersToMatchWithQuery(input: string | RegExp | (string | RegExp)[]): string | RegExp | (string | RegExp)[]` — Adapts filters to match ids with query params.
### Composable Filters
- `and(...exprs)` / `or(...exprs)` / `not(expr)` — Logical composition of filter expressions.
- `id(pattern, params?)` — Filter by id (string or RegExp).
- `moduleType(type)` — Filter by module type (e.g. 'js', 'tsx', or 'json').
- `code(pattern)` — Filter by code content.
- `query(key, pattern)` — Filter by query parameter.
- `include(expr)` / `exclude(expr)` — Top-level include/exclude wrappers.
- `queries(obj)` — Compose multiple query filters.

View File

@ -142,13 +142,15 @@ function interpreter(exprs, code$1, id$1, moduleType$1) {
function interpreterImpl(expr, code$1, id$1, moduleType$1, ctx = {}) {
let hasInclude = false;
for (const e of expr) switch (e.kind) {
case "include":
case "include": {
hasInclude = true;
if (exprInterpreter(e.expr, code$1, id$1, moduleType$1, ctx)) return true;
break;
case "exclude":
}
case "exclude": {
if (exprInterpreter(e.expr, code$1, id$1, moduleType$1)) return false;
break;
}
}
return !hasInclude;
}
@ -157,16 +159,19 @@ function exprInterpreter(expr, code$1, id$1, moduleType$1, ctx = {}) {
case "and": return expr.args.every((e) => exprInterpreter(e, code$1, id$1, moduleType$1, ctx));
case "or": return expr.args.some((e) => exprInterpreter(e, code$1, id$1, moduleType$1, ctx));
case "not": return !exprInterpreter(expr.expr, code$1, id$1, moduleType$1, ctx);
case "id":
case "id": {
if (id$1 === void 0) throw new Error("`id` is required for `id` expression");
if (expr.params.cleanUrl) id$1 = cleanUrl(id$1);
return typeof expr.pattern === "string" ? id$1 === expr.pattern : expr.pattern.test(id$1);
case "moduleType":
}
case "moduleType": {
if (moduleType$1 === void 0) throw new Error("`moduleType` is required for `moduleType` expression");
return moduleType$1 === expr.pattern;
case "code":
}
case "code": {
if (code$1 === void 0) throw new Error("`code` is required for `code` expression");
return typeof expr.pattern === "string" ? code$1.includes(expr.pattern) : expr.pattern.test(code$1);
}
case "query": {
if (id$1 === void 0) throw new Error("`id` is required for `Query` expression");
if (!ctx.urlSearchParamsCache) {

View File

@ -141,13 +141,15 @@ function interpreter(exprs, code$1, id$1, moduleType$1) {
function interpreterImpl(expr, code$1, id$1, moduleType$1, ctx = {}) {
let hasInclude = false;
for (const e of expr) switch (e.kind) {
case "include":
case "include": {
hasInclude = true;
if (exprInterpreter(e.expr, code$1, id$1, moduleType$1, ctx)) return true;
break;
case "exclude":
}
case "exclude": {
if (exprInterpreter(e.expr, code$1, id$1, moduleType$1)) return false;
break;
}
}
return !hasInclude;
}
@ -156,16 +158,19 @@ function exprInterpreter(expr, code$1, id$1, moduleType$1, ctx = {}) {
case "and": return expr.args.every((e) => exprInterpreter(e, code$1, id$1, moduleType$1, ctx));
case "or": return expr.args.some((e) => exprInterpreter(e, code$1, id$1, moduleType$1, ctx));
case "not": return !exprInterpreter(expr.expr, code$1, id$1, moduleType$1, ctx);
case "id":
case "id": {
if (id$1 === void 0) throw new Error("`id` is required for `id` expression");
if (expr.params.cleanUrl) id$1 = cleanUrl(id$1);
return typeof expr.pattern === "string" ? id$1 === expr.pattern : expr.pattern.test(id$1);
case "moduleType":
}
case "moduleType": {
if (moduleType$1 === void 0) throw new Error("`moduleType` is required for `moduleType` expression");
return moduleType$1 === expr.pattern;
case "code":
}
case "code": {
if (code$1 === void 0) throw new Error("`code` is required for `code` expression");
return typeof expr.pattern === "string" ? code$1.includes(expr.pattern) : expr.pattern.test(code$1);
}
case "query": {
if (id$1 === void 0) throw new Error("`id` is required for `Query` expression");
if (!ctx.urlSearchParamsCache) {

View File

@ -1,6 +1,6 @@
{
"name": "@rolldown/pluginutils",
"version": "1.0.0-beta.34",
"version": "1.0.0-beta.27",
"license": "MIT",
"type": "module",
"repository": {
@ -26,7 +26,7 @@
"devDependencies": {
"@types/picomatch": "^4.0.0",
"picomatch": "^4.0.2",
"tsdown": "0.14.1",
"tsdown": "0.12.9",
"vitest": "^3.0.1"
},
"scripts": {