@kubb/agent 5.0.0-beta.4 → 5.0.0-beta.5

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 (38) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/server/chunks/nitro/nitro.mjs +57 -34
  3. package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
  4. package/.output/server/chunks/routes/api/health.get.mjs +1 -1
  5. package/.output/server/index.mjs +1 -1
  6. package/.output/server/node_modules/jiti/dist/jiti.cjs +1 -0
  7. package/.output/server/node_modules/jiti/lib/jiti.mjs +29 -0
  8. package/.output/server/node_modules/jiti/package.json +146 -0
  9. package/.output/server/package.json +2 -5
  10. package/README.md +2 -2
  11. package/package.json +8 -7
  12. package/.output/server/node_modules/@rolldown/binding-linux-x64-gnu/package.json +0 -40
  13. package/.output/server/node_modules/@rolldown/binding-linux-x64-gnu/rolldown-binding.linux-x64-gnu.node +0 -0
  14. package/.output/server/node_modules/@rolldown/pluginutils/dist/filter/composable-filters.js +0 -256
  15. package/.output/server/node_modules/@rolldown/pluginutils/dist/filter/filter-vite-plugins.js +0 -75
  16. package/.output/server/node_modules/@rolldown/pluginutils/dist/filter/index.js +0 -3
  17. package/.output/server/node_modules/@rolldown/pluginutils/dist/filter/simple-filters.js +0 -70
  18. package/.output/server/node_modules/@rolldown/pluginutils/dist/index.js +0 -1
  19. package/.output/server/node_modules/@rolldown/pluginutils/dist/utils.js +0 -17
  20. package/.output/server/node_modules/@rolldown/pluginutils/package.json +0 -37
  21. package/.output/server/node_modules/rolldown/dist/index.mjs +0 -50
  22. package/.output/server/node_modules/rolldown/dist/parse-ast-index.mjs +0 -60
  23. package/.output/server/node_modules/rolldown/dist/shared/binding-BeU_1iEk.mjs +0 -582
  24. package/.output/server/node_modules/rolldown/dist/shared/bindingify-input-options-DbbBhzky.mjs +0 -2211
  25. package/.output/server/node_modules/rolldown/dist/shared/define-config-DJOr6Iwt.mjs +0 -6
  26. package/.output/server/node_modules/rolldown/dist/shared/error-DL-e8-oE.mjs +0 -85
  27. package/.output/server/node_modules/rolldown/dist/shared/logs-D80CXhvg.mjs +0 -180
  28. package/.output/server/node_modules/rolldown/dist/shared/misc-DJYbNKZX.mjs +0 -21
  29. package/.output/server/node_modules/rolldown/dist/shared/normalize-string-or-regex-CbQQ69gT.mjs +0 -66
  30. package/.output/server/node_modules/rolldown/dist/shared/parse-B_ZnWxLZ.mjs +0 -74
  31. package/.output/server/node_modules/rolldown/dist/shared/prompt-U5ajztzG.mjs +0 -847
  32. package/.output/server/node_modules/rolldown/dist/shared/rolldown-D3JZ9rMt.mjs +0 -40
  33. package/.output/server/node_modules/rolldown/dist/shared/rolldown-build-DSxL8qiP.mjs +0 -3325
  34. package/.output/server/node_modules/rolldown/dist/shared/watch-Bd8v9ewv.mjs +0 -374
  35. package/.output/server/node_modules/rolldown/package.json +0 -153
  36. package/.output/server/node_modules/unrun/dist/index.mjs +0 -2
  37. package/.output/server/node_modules/unrun/dist/src-GU5PtktT.mjs +0 -887
  38. package/.output/server/node_modules/unrun/package.json +0 -125
@@ -0,0 +1,146 @@
1
+ {
2
+ "name": "jiti",
3
+ "version": "2.7.0",
4
+ "description": "Runtime typescript and ESM support for Node.js",
5
+ "repository": "unjs/jiti",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./lib/jiti.d.mts",
12
+ "default": "./lib/jiti.mjs"
13
+ },
14
+ "require": {
15
+ "types": "./lib/jiti.d.cts",
16
+ "default": "./lib/jiti.cjs"
17
+ }
18
+ },
19
+ "./register": {
20
+ "types": "./lib/jiti-register.d.mts",
21
+ "import": "./lib/jiti-register.mjs"
22
+ },
23
+ "./native": {
24
+ "types": "./lib/jiti.d.mts",
25
+ "import": "./lib/jiti-native.mjs"
26
+ },
27
+ "./static": {
28
+ "types": "./lib/jiti.d.mts",
29
+ "import": "./lib/jiti-static.mjs"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "main": "./lib/jiti.cjs",
34
+ "module": "./lib/jiti.mjs",
35
+ "types": "./lib/jiti.d.cts",
36
+ "typesVersions": {
37
+ "*": {
38
+ "register": [
39
+ "./lib/jiti-register.d.mts"
40
+ ],
41
+ "native": [
42
+ "./lib/jiti.d.mts"
43
+ ],
44
+ "static": [
45
+ "./lib/jiti.d.mts"
46
+ ]
47
+ }
48
+ },
49
+ "bin": {
50
+ "jiti": "./lib/jiti-cli.mjs"
51
+ },
52
+ "files": [
53
+ "lib",
54
+ "dist",
55
+ "register.cjs"
56
+ ],
57
+ "scripts": {
58
+ "bench": "node test/bench.mjs && deno -A test/bench.mjs && bun --bun test/bench.mjs",
59
+ "build": "pnpm clean && pnpm rspack",
60
+ "build:rolldown": "pnpm clean && pnpm rolldown -c rolldown.config.mjs",
61
+ "clean": "rm -rf dist",
62
+ "dev": "pnpm clean && pnpm rspack --watch",
63
+ "jiti": "JITI_DEBUG=1 JITI_JSX=1 lib/jiti-cli.mjs",
64
+ "lint": "eslint . && prettier -c src lib test stubs",
65
+ "lint:fix": "eslint --fix . && prettier -w src lib test stubs",
66
+ "prepack": "pnpm build",
67
+ "release": "pnpm build && pnpm test && changelogen --release --push && npm publish",
68
+ "test": "pnpm lint && pnpm test:types && vitest run --coverage && pnpm test:node-register && pnpm test:bun && pnpm test:native",
69
+ "test:bun": "bun --bun test test/bun",
70
+ "test:native": "pnpm test:native:bun && pnpm test:native:node && pnpm test:native:deno",
71
+ "test:native:bun": "bun --bun test test/native/bun.test.ts",
72
+ "test:native:deno": "deno test -A --no-check test/native/deno.test.ts",
73
+ "test:native:node": "node --test --experimental-strip-types test/native/node.test.ts",
74
+ "test:node-register": "JITI_JSX=1 node --test test/node-register.test.mjs",
75
+ "test:types": "tsgo --noEmit"
76
+ },
77
+ "devDependencies": {
78
+ "@babel/core": "^7.29.0",
79
+ "@babel/helper-module-imports": "^7.28.6",
80
+ "@babel/helper-module-transforms": "^7.28.6",
81
+ "@babel/helper-plugin-utils": "^7.28.6",
82
+ "@babel/helper-simple-access": "^7.27.1",
83
+ "@babel/plugin-proposal-decorators": "^7.29.0",
84
+ "@babel/plugin-syntax-class-properties": "^7.12.13",
85
+ "@babel/plugin-syntax-import-assertions": "^7.28.6",
86
+ "@babel/plugin-syntax-jsx": "^7.28.6",
87
+ "@babel/plugin-transform-explicit-resource-management": "^7.28.6",
88
+ "@babel/plugin-transform-export-namespace-from": "^7.27.1",
89
+ "@babel/plugin-transform-react-jsx": "^7.28.6",
90
+ "@babel/plugin-transform-typescript": "^7.28.6",
91
+ "@babel/preset-typescript": "^7.28.5",
92
+ "@babel/template": "^7.28.6",
93
+ "@babel/traverse": "^7.29.0",
94
+ "@babel/types": "^7.29.0",
95
+ "@rspack/cli": "^2.0.1",
96
+ "@rspack/core": "^2.0.1",
97
+ "@types/babel__core": "^7.20.5",
98
+ "@types/babel__helper-module-imports": "^7.18.3",
99
+ "@types/babel__helper-plugin-utils": "^7.10.3",
100
+ "@types/babel__template": "^7.4.4",
101
+ "@types/babel__traverse": "^7.28.0",
102
+ "@types/node": "^25.6.0",
103
+ "@typescript/native-preview": "7.0.0-dev.20260505.1",
104
+ "@vitest/coverage-v8": "^4.1.5",
105
+ "acorn": "^8.16.0",
106
+ "babel-plugin-parameter-decorator": "^1.0.16",
107
+ "changelogen": "^0.6.2",
108
+ "config": "^4.4.1",
109
+ "consola": "^3.4.2",
110
+ "defu": "^6.1.7",
111
+ "destr": "^2.0.5",
112
+ "escape-string-regexp": "^5.0.0",
113
+ "eslint": "^10.3.0",
114
+ "eslint-config-unjs": "^0.6.2",
115
+ "estree-walker": "^3.0.3",
116
+ "etag": "^1.8.1",
117
+ "fast-glob": "^3.3.3",
118
+ "get-tsconfig": "^4.14.0",
119
+ "is-installed-globally": "^1.0.0",
120
+ "mime": "^4.1.0",
121
+ "mitata": "^1.0.34",
122
+ "mlly": "^1.8.2",
123
+ "moment-timezone": "^0.6.2",
124
+ "nano-jsx": "^0.2.1",
125
+ "pathe": "^2.0.3",
126
+ "pkg-types": "^2.3.1",
127
+ "preact": "^10.29.1",
128
+ "preact-render-to-string": "^6.6.7",
129
+ "prettier": "^3.8.3",
130
+ "react": "^19.2.5",
131
+ "react-dom": "^19.2.5",
132
+ "reflect-metadata": "^0.2.2",
133
+ "rolldown": "1.0.0-rc.18",
134
+ "solid-js": "^1.9.12",
135
+ "std-env": "^4.1.0",
136
+ "terser-webpack-plugin": "^5.5.0",
137
+ "tinyexec": "^1.1.2",
138
+ "ts-loader": "^9.5.7",
139
+ "typescript": "^5.9.3",
140
+ "vitest": "^4.1.5",
141
+ "vue": "^3.5.33",
142
+ "yoctocolors": "^2.1.2",
143
+ "zod": "^4.4.3"
144
+ },
145
+ "packageManager": "pnpm@10.30.3"
146
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/agent-prod",
3
- "version": "5.0.0-beta.4",
3
+ "version": "5.0.0-beta.5",
4
4
  "type": "module",
5
5
  "private": true,
6
6
  "dependencies": {
@@ -9,21 +9,18 @@
9
9
  "@logtail/tools": "0.5.8",
10
10
  "@logtail/types": "0.5.8",
11
11
  "@msgpack/msgpack": "2.8.0",
12
- "@rolldown/binding-linux-x64-gnu": "1.0.0-rc.17",
13
- "@rolldown/pluginutils": "1.0.0-rc.17",
14
12
  "anymatch": "3.1.3",
15
13
  "chokidar": "5.0.0",
16
14
  "consola": "3.4.2",
17
15
  "fflate": "0.8.2",
16
+ "jiti": "2.7.0",
18
17
  "normalize-path": "3.0.0",
19
18
  "picomatch": "2.3.2",
20
19
  "readdirp": "5.0.0",
21
20
  "remeda": "2.34.0",
22
- "rolldown": "1.0.0-rc.17",
23
21
  "serialize-error": "8.1.0",
24
22
  "stack-trace": "0.0.10",
25
23
  "tinyexec": "1.1.2",
26
- "unrun": "0.2.37",
27
24
  "ws": "8.20.0"
28
25
  }
29
26
  }
package/README.md CHANGED
@@ -112,7 +112,7 @@ The `agent_kv` named volume persists the KV store (session cache, machine token)
112
112
  | `KUBB_AGENT_ROOT` | `/kubb/agent` (Docker) / `cwd` | Root directory for resolving relative paths. |
113
113
  | `PORT` | `3000` | Server port. |
114
114
  | `HOST` | `0.0.0.0` | Server host. |
115
- | `KUBB_STUDIO_URL` | `https://studio.kubb.dev` | Kubb Studio WebSocket URL. |
115
+ | `KUBB_STUDIO_URL` | `https://kubb.studio` | Kubb Studio WebSocket URL. |
116
116
  | `KUBB_AGENT_TOKEN` | _(empty)_ | Authentication token for Studio. Required to connect. |
117
117
  | `KUBB_AGENT_ALLOW_WRITE` | `false` | Set to `true` to allow writing generated files to disk. |
118
118
  | `KUBB_AGENT_ALLOW_ALL` | `false` | Set to `true` to grant all permissions (implies `KUBB_AGENT_ALLOW_WRITE=true`). |
@@ -132,7 +132,7 @@ PORT=3000
132
132
  KUBB_AGENT_ROOT=/path/to/your/project
133
133
  KUBB_AGENT_CONFIG=/path/to/your/project/kubb.config.ts
134
134
  KUBB_AGENT_TOKEN=your-token-here
135
- KUBB_STUDIO_URL=https://studio.kubb.dev
135
+ KUBB_STUDIO_URL=https://kubb.studio
136
136
  ```
137
137
 
138
138
  2. **Run the agent:**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/agent",
3
- "version": "5.0.0-beta.4",
3
+ "version": "5.0.0-beta.5",
4
4
  "description": "Agent server for Kubb, enabling HTTP-based access to code generation capabilities.",
5
5
  "keywords": [
6
6
  "agent",
@@ -38,22 +38,23 @@
38
38
  "dependencies": {
39
39
  "@logtail/node": "^0.5.8",
40
40
  "consola": "^3.4.2",
41
+ "jiti": "^2.7.0",
41
42
  "remeda": "^2.34.0",
42
43
  "tinyexec": "^1.1.2",
43
- "unrun": "^0.2.37",
44
44
  "unstorage": "^1.17.5",
45
45
  "ws": "^8.20.0",
46
- "@kubb/ast": "5.0.0-beta.4",
47
- "@kubb/core": "5.0.0-beta.4"
46
+ "@kubb/ast": "5.0.0-beta.5",
47
+ "@kubb/core": "5.0.0-beta.5"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/ws": "^8.18.1",
51
- "msw": "^2.14.2",
51
+ "msw": "^2.14.3",
52
52
  "nitropack": "^2.13.4",
53
53
  "vite": "^8.0.10",
54
54
  "@internals/utils": "0.0.0",
55
- "@kubb/adapter-oas": "5.0.0-beta.4",
56
- "@kubb/parser-ts": "5.0.0-beta.4"
55
+ "@kubb/parser-ts": "5.0.0-beta.5",
56
+ "@kubb/adapter-oas": "5.0.0-beta.5",
57
+ "@kubb/renderer-jsx": "5.0.0-beta.5"
57
58
  },
58
59
  "engines": {
59
60
  "node": ">=22"
@@ -1,40 +0,0 @@
1
- {
2
- "name": "@rolldown/binding-linux-x64-gnu",
3
- "version": "1.0.0-rc.17",
4
- "cpu": [
5
- "x64"
6
- ],
7
- "main": "rolldown-binding.linux-x64-gnu.node",
8
- "files": [
9
- "rolldown-binding.linux-x64-gnu.node"
10
- ],
11
- "description": "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.",
12
- "keywords": [
13
- "bundler",
14
- "esbuild",
15
- "parcel",
16
- "rolldown",
17
- "rollup",
18
- "webpack"
19
- ],
20
- "homepage": "https://rolldown.rs/",
21
- "license": "MIT",
22
- "engines": {
23
- "node": "^20.19.0 || >=22.12.0"
24
- },
25
- "repository": {
26
- "type": "git",
27
- "url": "git+https://github.com/rolldown/rolldown.git",
28
- "directory": "packages/rolldown"
29
- },
30
- "publishConfig": {
31
- "registry": "https://registry.npmjs.org/",
32
- "access": "public"
33
- },
34
- "os": [
35
- "linux"
36
- ],
37
- "libc": [
38
- "glibc"
39
- ]
40
- }
@@ -1,256 +0,0 @@
1
- import { cleanUrl, extractQueryWithoutFragment } from "../utils.js";
2
- class And {
3
- kind;
4
- args;
5
- constructor(...args) {
6
- if (args.length === 0) {
7
- throw new Error('`And` expects at least one operand');
8
- }
9
- this.args = args;
10
- this.kind = 'and';
11
- }
12
- }
13
- class Or {
14
- kind;
15
- args;
16
- constructor(...args) {
17
- if (args.length === 0) {
18
- throw new Error('`Or` expects at least one operand');
19
- }
20
- this.args = args;
21
- this.kind = 'or';
22
- }
23
- }
24
- class Not {
25
- kind;
26
- expr;
27
- constructor(expr) {
28
- this.expr = expr;
29
- this.kind = 'not';
30
- }
31
- }
32
- class Id {
33
- kind;
34
- pattern;
35
- params;
36
- constructor(pattern, params) {
37
- this.pattern = pattern;
38
- this.kind = 'id';
39
- this.params = params ?? {
40
- cleanUrl: false,
41
- };
42
- }
43
- }
44
- class ImporterId {
45
- kind;
46
- pattern;
47
- params;
48
- constructor(pattern, params) {
49
- this.pattern = pattern;
50
- this.kind = 'importerId';
51
- this.params = params ?? {
52
- cleanUrl: false,
53
- };
54
- }
55
- }
56
- class ModuleType {
57
- kind;
58
- pattern;
59
- constructor(pattern) {
60
- this.pattern = pattern;
61
- this.kind = 'moduleType';
62
- }
63
- }
64
- class Code {
65
- kind;
66
- pattern;
67
- constructor(expr) {
68
- this.pattern = expr;
69
- this.kind = 'code';
70
- }
71
- }
72
- class Query {
73
- kind;
74
- key;
75
- pattern;
76
- constructor(key, pattern) {
77
- this.pattern = pattern;
78
- this.key = key;
79
- this.kind = 'query';
80
- }
81
- }
82
- class Include {
83
- kind;
84
- expr;
85
- constructor(expr) {
86
- this.expr = expr;
87
- this.kind = 'include';
88
- }
89
- }
90
- class Exclude {
91
- kind;
92
- expr;
93
- constructor(expr) {
94
- this.expr = expr;
95
- this.kind = 'exclude';
96
- }
97
- }
98
- export function and(...args) {
99
- return new And(...args);
100
- }
101
- export function or(...args) {
102
- return new Or(...args);
103
- }
104
- export function not(expr) {
105
- return new Not(expr);
106
- }
107
- export function id(pattern, params) {
108
- return new Id(pattern, params);
109
- }
110
- export function importerId(pattern, params) {
111
- return new ImporterId(pattern, params);
112
- }
113
- export function moduleType(pattern) {
114
- return new ModuleType(pattern);
115
- }
116
- export function code(pattern) {
117
- return new Code(pattern);
118
- }
119
- /*
120
- * There are three kinds of conditions are supported:
121
- * 1. `boolean`: if the value is `true`, the key must exist and be truthy. if the value is `false`, the key must not exist or be falsy.
122
- * 2. `string`: the key must exist and be equal to the value.
123
- * 3. `RegExp`: the key must exist and match the value.
124
- */
125
- export function query(key, pattern) {
126
- return new Query(key, pattern);
127
- }
128
- export function include(expr) {
129
- return new Include(expr);
130
- }
131
- export function exclude(expr) {
132
- return new Exclude(expr);
133
- }
134
- /**
135
- * convert a queryObject to FilterExpression like
136
- * ```js
137
- * and(query(k1, v1), query(k2, v2))
138
- * ```
139
- * @param queryFilterObject The query filter object needs to be matched.
140
- * @returns a `And` FilterExpression
141
- */
142
- export function queries(queryFilter) {
143
- let arr = Object.entries(queryFilter).map(([key, value]) => {
144
- return new Query(key, value);
145
- });
146
- return and(...arr);
147
- }
148
- export function interpreter(exprs, code, id, moduleType, importerId) {
149
- let arr = [];
150
- if (Array.isArray(exprs)) {
151
- arr = exprs;
152
- }
153
- else {
154
- arr = [exprs];
155
- }
156
- return interpreterImpl(arr, code, id, moduleType, importerId);
157
- }
158
- export function interpreterImpl(expr, code, id, moduleType, importerId, ctx = {}) {
159
- let hasInclude = false;
160
- for (const e of expr) {
161
- switch (e.kind) {
162
- case 'include': {
163
- hasInclude = true;
164
- if (exprInterpreter(e.expr, code, id, moduleType, importerId, ctx)) {
165
- return true;
166
- }
167
- break;
168
- }
169
- case 'exclude': {
170
- if (exprInterpreter(e.expr, code, id, moduleType, importerId, ctx)) {
171
- return false;
172
- }
173
- break;
174
- }
175
- }
176
- }
177
- return !hasInclude;
178
- }
179
- export function exprInterpreter(expr, code, id, moduleType, importerId, ctx = {}) {
180
- switch (expr.kind) {
181
- case 'and': {
182
- return expr.args.every((e) => exprInterpreter(e, code, id, moduleType, importerId, ctx));
183
- }
184
- case 'or': {
185
- return expr.args.some((e) => exprInterpreter(e, code, id, moduleType, importerId, ctx));
186
- }
187
- case 'not': {
188
- return !exprInterpreter(expr.expr, code, id, moduleType, importerId, ctx);
189
- }
190
- case 'id': {
191
- if (id === undefined) {
192
- throw new Error('`id` is required for `id` expression');
193
- }
194
- let idToMatch = id;
195
- if (expr.params.cleanUrl) {
196
- idToMatch = cleanUrl(idToMatch);
197
- }
198
- return typeof expr.pattern === 'string'
199
- ? idToMatch === expr.pattern
200
- : expr.pattern.test(idToMatch);
201
- }
202
- case 'importerId': {
203
- if (importerId === undefined) {
204
- return false; // Entry files have no importer, so no match
205
- }
206
- let importerIdToMatch = importerId;
207
- if (expr.params.cleanUrl) {
208
- importerIdToMatch = cleanUrl(importerIdToMatch);
209
- }
210
- return typeof expr.pattern === 'string'
211
- ? importerIdToMatch === expr.pattern
212
- : expr.pattern.test(importerIdToMatch);
213
- }
214
- case 'moduleType': {
215
- if (moduleType === undefined) {
216
- throw new Error('`moduleType` is required for `moduleType` expression');
217
- }
218
- return moduleType === expr.pattern;
219
- }
220
- case 'code': {
221
- if (code === undefined) {
222
- throw new Error('`code` is required for `code` expression');
223
- }
224
- return typeof expr.pattern === 'string'
225
- ? code.includes(expr.pattern)
226
- : expr.pattern.test(code);
227
- }
228
- case 'query': {
229
- if (id === undefined) {
230
- throw new Error('`id` is required for `Query` expression');
231
- }
232
- if (!ctx.urlSearchParamsCache) {
233
- let queryString = extractQueryWithoutFragment(id);
234
- ctx.urlSearchParamsCache = new URLSearchParams(queryString);
235
- }
236
- let urlParams = ctx.urlSearchParamsCache;
237
- if (typeof expr.pattern === 'boolean') {
238
- if (expr.pattern) {
239
- return urlParams.has(expr.key);
240
- }
241
- else {
242
- return !urlParams.has(expr.key);
243
- }
244
- }
245
- else if (typeof expr.pattern === 'string') {
246
- return urlParams.get(expr.key) === expr.pattern;
247
- }
248
- else {
249
- return expr.pattern.test(urlParams.get(expr.key) ?? '');
250
- }
251
- }
252
- default: {
253
- throw new Error(`Expression ${JSON.stringify(expr)} is not expected.`);
254
- }
255
- }
256
- }
@@ -1,75 +0,0 @@
1
- /**
2
- * Filters out Vite plugins that have `apply: 'serve'` set.
3
- *
4
- * Since Rolldown operates in build mode, plugins marked with `apply: 'serve'`
5
- * are intended only for Vite's dev server and should be excluded from the build process.
6
- *
7
- * @param plugins - Array of plugins (can include nested arrays)
8
- * @returns Filtered array with serve-only plugins removed
9
- *
10
- * @example
11
- * ```ts
12
- * import { defineConfig } from 'rolldown';
13
- * import { filterVitePlugins } from '@rolldown/pluginutils';
14
- * import viteReact from '@vitejs/plugin-react';
15
- *
16
- * export default defineConfig({
17
- * plugins: filterVitePlugins([
18
- * viteReact(),
19
- * {
20
- * name: 'dev-only',
21
- * apply: 'serve', // This will be filtered out
22
- * // ...
23
- * }
24
- * ])
25
- * });
26
- * ```
27
- */
28
- export function filterVitePlugins(plugins) {
29
- if (!plugins) {
30
- return [];
31
- }
32
- const pluginArray = Array.isArray(plugins) ? plugins : [plugins];
33
- const result = [];
34
- for (const plugin of pluginArray) {
35
- // Skip falsy values
36
- if (!plugin) {
37
- continue;
38
- }
39
- // Handle nested arrays recursively
40
- if (Array.isArray(plugin)) {
41
- result.push(...filterVitePlugins(plugin));
42
- continue;
43
- }
44
- // Check if plugin has apply property
45
- const pluginWithApply = plugin;
46
- if ('apply' in pluginWithApply) {
47
- const applyValue = pluginWithApply.apply;
48
- // If apply is a function, call it with build mode
49
- if (typeof applyValue === 'function') {
50
- try {
51
- const shouldApply = applyValue({}, // config object
52
- { command: 'build', mode: 'production' });
53
- if (shouldApply) {
54
- result.push(plugin);
55
- }
56
- }
57
- catch {
58
- // If function throws, include the plugin to be safe
59
- result.push(plugin);
60
- }
61
- } // If apply is 'serve', skip this plugin
62
- else if (applyValue === 'serve') {
63
- continue;
64
- } // If apply is 'build' or anything else, include it
65
- else {
66
- result.push(plugin);
67
- }
68
- }
69
- else {
70
- // No apply property, include the plugin
71
- result.push(plugin);
72
- }
73
- }
74
- return result;
75
- }
@@ -1,3 +0,0 @@
1
- export * from "./composable-filters.js";
2
- export * from "./filter-vite-plugins.js";
3
- export * from "./simple-filters.js";
@@ -1,70 +0,0 @@
1
- /**
2
- * Constructs a RegExp that matches the exact string specified.
3
- *
4
- * This is useful for plugin hook filters.
5
- *
6
- * @param str the string to match.
7
- * @param flags flags for the RegExp.
8
- *
9
- * @example
10
- * ```ts
11
- * import { exactRegex } from '@rolldown/pluginutils';
12
- * const plugin = {
13
- * name: 'plugin',
14
- * resolveId: {
15
- * filter: { id: exactRegex('foo') },
16
- * handler(id) {} // will only be called for `foo`
17
- * }
18
- * }
19
- * ```
20
- */
21
- export function exactRegex(str, flags) {
22
- return new RegExp(`^${escapeRegex(str)}$`, flags);
23
- }
24
- /**
25
- * Constructs a RegExp that matches a value that has the specified prefix.
26
- *
27
- * This is useful for plugin hook filters.
28
- *
29
- * @param str the string to match.
30
- * @param flags flags for the RegExp.
31
- *
32
- * @example
33
- * ```ts
34
- * import { prefixRegex } from '@rolldown/pluginutils';
35
- * const plugin = {
36
- * name: 'plugin',
37
- * resolveId: {
38
- * filter: { id: prefixRegex('foo') },
39
- * handler(id) {} // will only be called for IDs starting with `foo`
40
- * }
41
- * }
42
- * ```
43
- */
44
- export function prefixRegex(str, flags) {
45
- return new RegExp(`^${escapeRegex(str)}`, flags);
46
- }
47
- const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g;
48
- function escapeRegex(str) {
49
- return str.replace(escapeRegexRE, '\\$&');
50
- }
51
- export function makeIdFiltersToMatchWithQuery(input) {
52
- if (!Array.isArray(input)) {
53
- return makeIdFilterToMatchWithQuery(
54
- // Array.isArray cannot narrow the type
55
- // https://github.com/microsoft/TypeScript/issues/17002
56
- input);
57
- }
58
- return input.map((i) => makeIdFilterToMatchWithQuery(i));
59
- }
60
- function makeIdFilterToMatchWithQuery(input) {
61
- if (typeof input === 'string') {
62
- return `${input}{?*,}`;
63
- }
64
- return makeRegexIdFilterToMatchWithQuery(input);
65
- }
66
- function makeRegexIdFilterToMatchWithQuery(input) {
67
- return new RegExp(
68
- // replace `$` with `(?:\?.*)?$` (ignore `\$`)
69
- input.source.replace(/(?<!\\)\$/g, '(?:\\?.*)?$'), input.flags);
70
- }
@@ -1 +0,0 @@
1
- export * from "./filter/index.js";