rolldown 1.0.0-beta.9-commit.0ec9e7d → 1.0.0-rc.1

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 (68) hide show
  1. package/README.md +11 -0
  2. package/bin/cli.mjs +1 -0
  3. package/dist/cli-setup.mjs +17 -0
  4. package/dist/cli.mjs +1085 -1281
  5. package/dist/config.d.mts +2 -4
  6. package/dist/config.mjs +8 -5
  7. package/dist/experimental-index.d.mts +161 -76
  8. package/dist/experimental-index.mjs +227 -61
  9. package/dist/experimental-runtime-types.d.ts +98 -0
  10. package/dist/filter-index.d.mts +196 -4
  11. package/dist/filter-index.mjs +328 -4
  12. package/dist/get-log-filter.d.mts +7 -0
  13. package/dist/get-log-filter.mjs +48 -0
  14. package/dist/index.d.mts +4 -4
  15. package/dist/index.mjs +56 -5
  16. package/dist/parallel-plugin-worker.mjs +27 -33
  17. package/dist/parallel-plugin.d.mts +7 -8
  18. package/dist/parse-ast-index.d.mts +4 -5
  19. package/dist/parse-ast-index.mjs +2 -2
  20. package/dist/plugins-index.d.mts +30 -0
  21. package/dist/plugins-index.mjs +40 -0
  22. package/dist/shared/binding-B92Lq__Q.d.mts +1687 -0
  23. package/dist/shared/binding-C-UNREnT.mjs +585 -0
  24. package/dist/shared/bindingify-input-options-Cb-01HR1.mjs +2233 -0
  25. package/dist/shared/constructors-D_KFsTQ-.d.mts +28 -0
  26. package/dist/shared/constructors-aZ82R2dj.mjs +61 -0
  27. package/dist/shared/define-config-BVG4QvnP.mjs +7 -0
  28. package/dist/shared/define-config-DO4TBkJV.d.mts +3457 -0
  29. package/dist/shared/{load-config-Dll-92l5.mjs → load-config-D6cey0o1.mjs} +23 -33
  30. package/dist/shared/logging-wIy4zY9I.d.mts +50 -0
  31. package/dist/shared/logs-NH298mHo.mjs +183 -0
  32. package/dist/shared/{misc-DGAe2XOW.mjs → misc-CCZIsXVO.mjs} +1 -7
  33. package/dist/shared/normalize-string-or-regex-Dq50a7l9.mjs +61 -0
  34. package/dist/shared/parse-ast-index-B6LAhWD8.mjs +99 -0
  35. package/dist/shared/{prompt-CxjDC0Gn.cjs → prompt-tlfjalEt.mjs} +301 -308
  36. package/dist/shared/rolldown-CIC_OHw3.mjs +42 -0
  37. package/dist/shared/rolldown-build-KB1YaNe-.mjs +2369 -0
  38. package/dist/shared/watch-B2WRkpw2.mjs +379 -0
  39. package/package.json +86 -98
  40. package/dist/cli.cjs +0 -1748
  41. package/dist/config.cjs +0 -12
  42. package/dist/config.d.cts +0 -12
  43. package/dist/experimental-index.cjs +0 -132
  44. package/dist/experimental-index.d.cts +0 -96
  45. package/dist/filter-index.cjs +0 -105
  46. package/dist/filter-index.d.cts +0 -5
  47. package/dist/index.cjs +0 -9
  48. package/dist/index.d.cts +0 -4
  49. package/dist/parallel-plugin-worker.cjs +0 -33
  50. package/dist/parallel-plugin-worker.d.cts +0 -1
  51. package/dist/parallel-plugin.cjs +0 -8
  52. package/dist/parallel-plugin.d.cts +0 -15
  53. package/dist/parse-ast-index.cjs +0 -4
  54. package/dist/parse-ast-index.d.cts +0 -9
  55. package/dist/shared/binding.d-Dz3qQrbl.d.mts +0 -1682
  56. package/dist/shared/binding.d-QXzDcVmm.d.cts +0 -1682
  57. package/dist/shared/chunk--iN_1bjD.mjs +0 -33
  58. package/dist/shared/chunk-DDkG_k5U.cjs +0 -39
  59. package/dist/shared/define-config.d-CUcDq_vm.d.cts +0 -1080
  60. package/dist/shared/define-config.d-qV1PzX_C.d.mts +0 -1080
  61. package/dist/shared/load-config-Bx9W9x2a.cjs +0 -125
  62. package/dist/shared/misc-BKp5iIef.cjs +0 -67
  63. package/dist/shared/parse-ast-index-0m6JgGc9.mjs +0 -655
  64. package/dist/shared/parse-ast-index-Cn_efzjO.cjs +0 -697
  65. package/dist/shared/prompt-uGrwvyp0.mjs +0 -854
  66. package/dist/shared/src-B4EklR3U.mjs +0 -4704
  67. package/dist/shared/src-BzFe16tX.cjs +0 -4654
  68. /package/dist/{cli.d.cts → cli-setup.d.mts} +0 -0
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @typedef {{ type: 'hmr:module-registered', modules: string[] }} DevRuntimeMessage
3
+ * @typedef {{ send(message: DevRuntimeMessage): void }} Messenger
4
+ */
5
+ export class DevRuntime {
6
+ /**
7
+ * @param {Messenger} messenger
8
+ * @param {string} clientId
9
+ */
10
+ constructor(messenger: Messenger, clientId: string);
11
+ /**
12
+ * Client ID generated at runtime initialization, used for lazy compilation requests.
13
+ * @type {string}
14
+ */
15
+ clientId: string;
16
+ messenger: Messenger;
17
+ /**
18
+ * @type {Record<string, Module>}
19
+ */
20
+ modules: Record<string, Module>;
21
+ /**
22
+ * @param {string} _moduleId
23
+ */
24
+ createModuleHotContext(_moduleId: string): void;
25
+ /**
26
+ * @param {[string, string][]} _boundaries
27
+ */
28
+ applyUpdates(_boundaries: [string, string][]): void;
29
+ /**
30
+ * @param {string} id
31
+ * @param {{ exports: any }} exportsHolder
32
+ */
33
+ registerModule(id: string, exportsHolder: {
34
+ exports: any;
35
+ }): void;
36
+ /**
37
+ * @param {string} id
38
+ */
39
+ loadExports(id: string): any;
40
+ /**
41
+ * __esmMin
42
+ *
43
+ * @type {<T>(fn: any, res: T) => () => T}
44
+ * @internal
45
+ */
46
+ createEsmInitializer: <T>(fn: any, res: T) => () => T;
47
+ /**
48
+ * __commonJSMin
49
+ *
50
+ * @type {<T extends { exports: any }>(cb: any, mod: { exports: any }) => () => T}
51
+ * @internal
52
+ */
53
+ createCjsInitializer: <T extends {
54
+ exports: any;
55
+ }>(cb: any, mod: {
56
+ exports: any;
57
+ }) => () => T;
58
+ /** @internal */
59
+ __toESM: any;
60
+ /** @internal */
61
+ __toCommonJS: any;
62
+ /** @internal */
63
+ __exportAll: any;
64
+ /**
65
+ * @param {boolean} [isNodeMode]
66
+ * @returns {(mod: any) => any}
67
+ * @internal
68
+ */
69
+ __toDynamicImportESM: (isNodeMode?: boolean) => (mod: any) => any;
70
+ /** @internal */
71
+ __reExport: any;
72
+ sendModuleRegisteredMessage: (module: string) => void;
73
+ }
74
+ export type DevRuntimeMessage = {
75
+ type: "hmr:module-registered";
76
+ modules: string[];
77
+ };
78
+ export type Messenger = {
79
+ send(message: DevRuntimeMessage): void;
80
+ };
81
+ declare class Module {
82
+ /**
83
+ * @param {string} id
84
+ */
85
+ constructor(id: string);
86
+ /**
87
+ * @type {{ exports: any }}
88
+ */
89
+ exportsHolder: {
90
+ exports: any;
91
+ };
92
+ /**
93
+ * @type {string}
94
+ */
95
+ id: string;
96
+ get exports(): any;
97
+ }
98
+ export {};
@@ -1,5 +1,197 @@
1
- import "./shared/binding.d-Dz3qQrbl.mjs";
2
- import { withFilter } from "./shared/define-config.d-qV1PzX_C.mjs";
3
- import { and, code, exclude, id, include, moduleType, not, or, queries, query } from "@rolldown/pluginutils";
1
+ import "./shared/binding-B92Lq__Q.mjs";
2
+ import { j as withFilter } from "./shared/define-config-DO4TBkJV.mjs";
4
3
 
5
- export { and, code, exclude, id, include, moduleType, not, or, queries, query, withFilter };
4
+ //#region ../pluginutils/dist/filter/composable-filters.d.ts
5
+ type StringOrRegExp = string | RegExp;
6
+ type PluginModuleType = 'js' | 'jsx' | 'ts' | 'tsx' | 'json' | 'text' | 'base64' | 'dataurl' | 'binary' | 'empty' | (string & {});
7
+ type FilterExpressionKind = FilterExpression['kind'];
8
+ type FilterExpression = And | Or | Not | Id | ImporterId | ModuleType | Code | Query;
9
+ type TopLevelFilterExpression = Include | Exclude;
10
+ declare class And {
11
+ kind: 'and';
12
+ args: FilterExpression[];
13
+ constructor(...args: FilterExpression[]);
14
+ }
15
+ declare class Or {
16
+ kind: 'or';
17
+ args: FilterExpression[];
18
+ constructor(...args: FilterExpression[]);
19
+ }
20
+ declare class Not {
21
+ kind: 'not';
22
+ expr: FilterExpression;
23
+ constructor(expr: FilterExpression);
24
+ }
25
+ interface QueryFilterObject {
26
+ [key: string]: StringOrRegExp | boolean;
27
+ }
28
+ interface IdParams {
29
+ cleanUrl?: boolean;
30
+ }
31
+ declare class Id {
32
+ kind: 'id';
33
+ pattern: StringOrRegExp;
34
+ params: IdParams;
35
+ constructor(pattern: StringOrRegExp, params?: IdParams);
36
+ }
37
+ declare class ImporterId {
38
+ kind: 'importerId';
39
+ pattern: StringOrRegExp;
40
+ params: IdParams;
41
+ constructor(pattern: StringOrRegExp, params?: IdParams);
42
+ }
43
+ declare class ModuleType {
44
+ kind: 'moduleType';
45
+ pattern: PluginModuleType;
46
+ constructor(pattern: PluginModuleType);
47
+ }
48
+ declare class Code {
49
+ kind: 'code';
50
+ pattern: StringOrRegExp;
51
+ constructor(expr: StringOrRegExp);
52
+ }
53
+ declare class Query {
54
+ kind: 'query';
55
+ key: string;
56
+ pattern: StringOrRegExp | boolean;
57
+ constructor(key: string, pattern: StringOrRegExp | boolean);
58
+ }
59
+ declare class Include {
60
+ kind: 'include';
61
+ expr: FilterExpression;
62
+ constructor(expr: FilterExpression);
63
+ }
64
+ declare class Exclude {
65
+ kind: 'exclude';
66
+ expr: FilterExpression;
67
+ constructor(expr: FilterExpression);
68
+ }
69
+ declare function and(...args: FilterExpression[]): And;
70
+ declare function or(...args: FilterExpression[]): Or;
71
+ declare function not(expr: FilterExpression): Not;
72
+ declare function id(pattern: StringOrRegExp, params?: IdParams): Id;
73
+ declare function importerId(pattern: StringOrRegExp, params?: IdParams): ImporterId;
74
+ declare function moduleType(pattern: PluginModuleType): ModuleType;
75
+ declare function code(pattern: StringOrRegExp): Code;
76
+ declare function query(key: string, pattern: StringOrRegExp | boolean): Query;
77
+ declare function include(expr: FilterExpression): Include;
78
+ declare function exclude(expr: FilterExpression): Exclude;
79
+ /**
80
+ * convert a queryObject to FilterExpression like
81
+ * ```js
82
+ * and(query(k1, v1), query(k2, v2))
83
+ * ```
84
+ * @param queryFilterObject The query filter object needs to be matched.
85
+ * @returns a `And` FilterExpression
86
+ */
87
+ declare function queries(queryFilter: QueryFilterObject): And;
88
+ declare function interpreter(exprs: TopLevelFilterExpression | TopLevelFilterExpression[], code?: string, id?: string, moduleType?: PluginModuleType, importerId?: string): boolean;
89
+ interface InterpreterCtx {
90
+ urlSearchParamsCache?: URLSearchParams;
91
+ }
92
+ declare function interpreterImpl(expr: TopLevelFilterExpression[], code?: string, id?: string, moduleType?: PluginModuleType, importerId?: string, ctx?: InterpreterCtx): boolean;
93
+ declare function exprInterpreter(expr: FilterExpression, code?: string, id?: string, moduleType?: PluginModuleType, importerId?: string, ctx?: InterpreterCtx): boolean;
94
+ //#endregion
95
+ //#region ../pluginutils/dist/filter/filter-vite-plugins.d.ts
96
+ /**
97
+ * Filters out Vite plugins that have `apply: 'serve'` set.
98
+ *
99
+ * Since Rolldown operates in build mode, plugins marked with `apply: 'serve'`
100
+ * are intended only for Vite's dev server and should be excluded from the build process.
101
+ *
102
+ * @param plugins - Array of plugins (can include nested arrays)
103
+ * @returns Filtered array with serve-only plugins removed
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * import { defineConfig } from 'rolldown';
108
+ * import { filterVitePlugins } from '@rolldown/pluginutils';
109
+ * import viteReact from '@vitejs/plugin-react';
110
+ *
111
+ * export default defineConfig({
112
+ * plugins: filterVitePlugins([
113
+ * viteReact(),
114
+ * {
115
+ * name: 'dev-only',
116
+ * apply: 'serve', // This will be filtered out
117
+ * // ...
118
+ * }
119
+ * ])
120
+ * });
121
+ * ```
122
+ */
123
+ declare function filterVitePlugins<T = any>(plugins: T | T[] | null | undefined | false): T[];
124
+ //#endregion
125
+ //#region ../pluginutils/dist/filter/simple-filters.d.ts
126
+ /**
127
+ * Constructs a RegExp that matches the exact string specified.
128
+ *
129
+ * This is useful for plugin hook filters.
130
+ *
131
+ * @param str the string to match.
132
+ * @param flags flags for the RegExp.
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * import { exactRegex } from '@rolldown/pluginutils';
137
+ * const plugin = {
138
+ * name: 'plugin',
139
+ * resolveId: {
140
+ * filter: { id: exactRegex('foo') },
141
+ * handler(id) {} // will only be called for `foo`
142
+ * }
143
+ * }
144
+ * ```
145
+ */
146
+ declare function exactRegex(str: string, flags?: string): RegExp;
147
+ /**
148
+ * Constructs a RegExp that matches a value that has the specified prefix.
149
+ *
150
+ * This is useful for plugin hook filters.
151
+ *
152
+ * @param str the string to match.
153
+ * @param flags flags for the RegExp.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * import { prefixRegex } from '@rolldown/pluginutils';
158
+ * const plugin = {
159
+ * name: 'plugin',
160
+ * resolveId: {
161
+ * filter: { id: prefixRegex('foo') },
162
+ * handler(id) {} // will only be called for IDs starting with `foo`
163
+ * }
164
+ * }
165
+ * ```
166
+ */
167
+ declare function prefixRegex(str: string, flags?: string): RegExp;
168
+ type WidenString<T> = T extends string ? string : T;
169
+ /**
170
+ * Converts a id filter to match with an id with a query.
171
+ *
172
+ * @param input the id filters to convert.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * import { makeIdFiltersToMatchWithQuery } from '@rolldown/pluginutils';
177
+ * const plugin = {
178
+ * name: 'plugin',
179
+ * transform: {
180
+ * filter: { id: makeIdFiltersToMatchWithQuery(['**' + '/*.js', /\.ts$/]) },
181
+ * // The handler will be called for IDs like:
182
+ * // - foo.js
183
+ * // - foo.js?foo
184
+ * // - foo.txt?foo.js
185
+ * // - foo.ts
186
+ * // - foo.ts?foo
187
+ * // - foo.txt?foo.ts
188
+ * handler(code, id) {}
189
+ * }
190
+ * }
191
+ * ```
192
+ */
193
+ declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: T): WidenString<T>;
194
+ declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: readonly T[]): WidenString<T>[];
195
+ declare function makeIdFiltersToMatchWithQuery(input: string | RegExp | readonly (string | RegExp)[]): string | RegExp | (string | RegExp)[];
196
+ //#endregion
197
+ export { FilterExpression, FilterExpressionKind, QueryFilterObject, TopLevelFilterExpression, and, code, exactRegex, exclude, exprInterpreter, filterVitePlugins, id, importerId, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query, withFilter };
@@ -1,8 +1,332 @@
1
- import { arraify, init_misc, isPromiseLike } from "./shared/misc-DGAe2XOW.mjs";
2
- import { and, code, exclude, id, include, moduleType, not, or, queries, query } from "@rolldown/pluginutils";
1
+ import { n as isPromiseLike, t as arraify } from "./shared/misc-CCZIsXVO.mjs";
3
2
 
3
+ //#region ../pluginutils/dist/utils.js
4
+ const postfixRE = /[?#].*$/;
5
+ function cleanUrl(url) {
6
+ return url.replace(postfixRE, "");
7
+ }
8
+ function extractQueryWithoutFragment(url) {
9
+ const questionMarkIndex = url.indexOf("?");
10
+ if (questionMarkIndex === -1) return "";
11
+ const fragmentIndex = url.indexOf("#", questionMarkIndex);
12
+ if (fragmentIndex === -1) return url.substring(questionMarkIndex);
13
+ else return url.substring(questionMarkIndex, fragmentIndex);
14
+ }
15
+
16
+ //#endregion
17
+ //#region ../pluginutils/dist/filter/composable-filters.js
18
+ var And = class {
19
+ kind;
20
+ args;
21
+ constructor(...args) {
22
+ if (args.length === 0) throw new Error("`And` expects at least one operand");
23
+ this.args = args;
24
+ this.kind = "and";
25
+ }
26
+ };
27
+ var Or = class {
28
+ kind;
29
+ args;
30
+ constructor(...args) {
31
+ if (args.length === 0) throw new Error("`Or` expects at least one operand");
32
+ this.args = args;
33
+ this.kind = "or";
34
+ }
35
+ };
36
+ var Not = class {
37
+ kind;
38
+ expr;
39
+ constructor(expr) {
40
+ this.expr = expr;
41
+ this.kind = "not";
42
+ }
43
+ };
44
+ var Id = class {
45
+ kind;
46
+ pattern;
47
+ params;
48
+ constructor(pattern, params) {
49
+ this.pattern = pattern;
50
+ this.kind = "id";
51
+ this.params = params ?? { cleanUrl: false };
52
+ }
53
+ };
54
+ var ImporterId = class {
55
+ kind;
56
+ pattern;
57
+ params;
58
+ constructor(pattern, params) {
59
+ this.pattern = pattern;
60
+ this.kind = "importerId";
61
+ this.params = params ?? { cleanUrl: false };
62
+ }
63
+ };
64
+ var ModuleType = class {
65
+ kind;
66
+ pattern;
67
+ constructor(pattern) {
68
+ this.pattern = pattern;
69
+ this.kind = "moduleType";
70
+ }
71
+ };
72
+ var Code = class {
73
+ kind;
74
+ pattern;
75
+ constructor(expr) {
76
+ this.pattern = expr;
77
+ this.kind = "code";
78
+ }
79
+ };
80
+ var Query = class {
81
+ kind;
82
+ key;
83
+ pattern;
84
+ constructor(key, pattern) {
85
+ this.pattern = pattern;
86
+ this.key = key;
87
+ this.kind = "query";
88
+ }
89
+ };
90
+ var Include = class {
91
+ kind;
92
+ expr;
93
+ constructor(expr) {
94
+ this.expr = expr;
95
+ this.kind = "include";
96
+ }
97
+ };
98
+ var Exclude = class {
99
+ kind;
100
+ expr;
101
+ constructor(expr) {
102
+ this.expr = expr;
103
+ this.kind = "exclude";
104
+ }
105
+ };
106
+ function and(...args) {
107
+ return new And(...args);
108
+ }
109
+ function or(...args) {
110
+ return new Or(...args);
111
+ }
112
+ function not(expr) {
113
+ return new Not(expr);
114
+ }
115
+ function id(pattern, params) {
116
+ return new Id(pattern, params);
117
+ }
118
+ function importerId(pattern, params) {
119
+ return new ImporterId(pattern, params);
120
+ }
121
+ function moduleType(pattern) {
122
+ return new ModuleType(pattern);
123
+ }
124
+ function code(pattern) {
125
+ return new Code(pattern);
126
+ }
127
+ function query(key, pattern) {
128
+ return new Query(key, pattern);
129
+ }
130
+ function include(expr) {
131
+ return new Include(expr);
132
+ }
133
+ function exclude(expr) {
134
+ return new Exclude(expr);
135
+ }
136
+ /**
137
+ * convert a queryObject to FilterExpression like
138
+ * ```js
139
+ * and(query(k1, v1), query(k2, v2))
140
+ * ```
141
+ * @param queryFilterObject The query filter object needs to be matched.
142
+ * @returns a `And` FilterExpression
143
+ */
144
+ function queries(queryFilter) {
145
+ return and(...Object.entries(queryFilter).map(([key, value]) => {
146
+ return new Query(key, value);
147
+ }));
148
+ }
149
+ function interpreter(exprs, code, id, moduleType, importerId) {
150
+ let arr = [];
151
+ if (Array.isArray(exprs)) arr = exprs;
152
+ else arr = [exprs];
153
+ return interpreterImpl(arr, code, id, moduleType, importerId);
154
+ }
155
+ function interpreterImpl(expr, code, id, moduleType, importerId, ctx = {}) {
156
+ let hasInclude = false;
157
+ for (const e of expr) switch (e.kind) {
158
+ case "include":
159
+ hasInclude = true;
160
+ if (exprInterpreter(e.expr, code, id, moduleType, importerId, ctx)) return true;
161
+ break;
162
+ case "exclude":
163
+ if (exprInterpreter(e.expr, code, id, moduleType, importerId, ctx)) return false;
164
+ break;
165
+ }
166
+ return !hasInclude;
167
+ }
168
+ function exprInterpreter(expr, code, id, moduleType, importerId, ctx = {}) {
169
+ switch (expr.kind) {
170
+ case "and": return expr.args.every((e) => exprInterpreter(e, code, id, moduleType, importerId, ctx));
171
+ case "or": return expr.args.some((e) => exprInterpreter(e, code, id, moduleType, importerId, ctx));
172
+ case "not": return !exprInterpreter(expr.expr, code, id, moduleType, importerId, ctx);
173
+ case "id": {
174
+ if (id === void 0) throw new Error("`id` is required for `id` expression");
175
+ let idToMatch = id;
176
+ if (expr.params.cleanUrl) idToMatch = cleanUrl(idToMatch);
177
+ return typeof expr.pattern === "string" ? idToMatch === expr.pattern : expr.pattern.test(idToMatch);
178
+ }
179
+ case "importerId": {
180
+ if (importerId === void 0) return false;
181
+ let importerIdToMatch = importerId;
182
+ if (expr.params.cleanUrl) importerIdToMatch = cleanUrl(importerIdToMatch);
183
+ return typeof expr.pattern === "string" ? importerIdToMatch === expr.pattern : expr.pattern.test(importerIdToMatch);
184
+ }
185
+ case "moduleType":
186
+ if (moduleType === void 0) throw new Error("`moduleType` is required for `moduleType` expression");
187
+ return moduleType === expr.pattern;
188
+ case "code":
189
+ if (code === void 0) throw new Error("`code` is required for `code` expression");
190
+ return typeof expr.pattern === "string" ? code.includes(expr.pattern) : expr.pattern.test(code);
191
+ case "query": {
192
+ if (id === void 0) throw new Error("`id` is required for `Query` expression");
193
+ if (!ctx.urlSearchParamsCache) {
194
+ let queryString = extractQueryWithoutFragment(id);
195
+ ctx.urlSearchParamsCache = new URLSearchParams(queryString);
196
+ }
197
+ let urlParams = ctx.urlSearchParamsCache;
198
+ if (typeof expr.pattern === "boolean") if (expr.pattern) return urlParams.has(expr.key);
199
+ else return !urlParams.has(expr.key);
200
+ else if (typeof expr.pattern === "string") return urlParams.get(expr.key) === expr.pattern;
201
+ else return expr.pattern.test(urlParams.get(expr.key) ?? "");
202
+ }
203
+ default: throw new Error(`Expression ${JSON.stringify(expr)} is not expected.`);
204
+ }
205
+ }
206
+
207
+ //#endregion
208
+ //#region ../pluginutils/dist/filter/filter-vite-plugins.js
209
+ /**
210
+ * Filters out Vite plugins that have `apply: 'serve'` set.
211
+ *
212
+ * Since Rolldown operates in build mode, plugins marked with `apply: 'serve'`
213
+ * are intended only for Vite's dev server and should be excluded from the build process.
214
+ *
215
+ * @param plugins - Array of plugins (can include nested arrays)
216
+ * @returns Filtered array with serve-only plugins removed
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * import { defineConfig } from 'rolldown';
221
+ * import { filterVitePlugins } from '@rolldown/pluginutils';
222
+ * import viteReact from '@vitejs/plugin-react';
223
+ *
224
+ * export default defineConfig({
225
+ * plugins: filterVitePlugins([
226
+ * viteReact(),
227
+ * {
228
+ * name: 'dev-only',
229
+ * apply: 'serve', // This will be filtered out
230
+ * // ...
231
+ * }
232
+ * ])
233
+ * });
234
+ * ```
235
+ */
236
+ function filterVitePlugins(plugins) {
237
+ if (!plugins) return [];
238
+ const pluginArray = Array.isArray(plugins) ? plugins : [plugins];
239
+ const result = [];
240
+ for (const plugin of pluginArray) {
241
+ if (!plugin) continue;
242
+ if (Array.isArray(plugin)) {
243
+ result.push(...filterVitePlugins(plugin));
244
+ continue;
245
+ }
246
+ const pluginWithApply = plugin;
247
+ if ("apply" in pluginWithApply) {
248
+ const applyValue = pluginWithApply.apply;
249
+ if (typeof applyValue === "function") try {
250
+ if (applyValue({}, {
251
+ command: "build",
252
+ mode: "production"
253
+ })) result.push(plugin);
254
+ } catch {
255
+ result.push(plugin);
256
+ }
257
+ else if (applyValue === "serve") continue;
258
+ else result.push(plugin);
259
+ } else result.push(plugin);
260
+ }
261
+ return result;
262
+ }
263
+
264
+ //#endregion
265
+ //#region ../pluginutils/dist/filter/simple-filters.js
266
+ /**
267
+ * Constructs a RegExp that matches the exact string specified.
268
+ *
269
+ * This is useful for plugin hook filters.
270
+ *
271
+ * @param str the string to match.
272
+ * @param flags flags for the RegExp.
273
+ *
274
+ * @example
275
+ * ```ts
276
+ * import { exactRegex } from '@rolldown/pluginutils';
277
+ * const plugin = {
278
+ * name: 'plugin',
279
+ * resolveId: {
280
+ * filter: { id: exactRegex('foo') },
281
+ * handler(id) {} // will only be called for `foo`
282
+ * }
283
+ * }
284
+ * ```
285
+ */
286
+ function exactRegex(str, flags) {
287
+ return new RegExp(`^${escapeRegex(str)}$`, flags);
288
+ }
289
+ /**
290
+ * Constructs a RegExp that matches a value that has the specified prefix.
291
+ *
292
+ * This is useful for plugin hook filters.
293
+ *
294
+ * @param str the string to match.
295
+ * @param flags flags for the RegExp.
296
+ *
297
+ * @example
298
+ * ```ts
299
+ * import { prefixRegex } from '@rolldown/pluginutils';
300
+ * const plugin = {
301
+ * name: 'plugin',
302
+ * resolveId: {
303
+ * filter: { id: prefixRegex('foo') },
304
+ * handler(id) {} // will only be called for IDs starting with `foo`
305
+ * }
306
+ * }
307
+ * ```
308
+ */
309
+ function prefixRegex(str, flags) {
310
+ return new RegExp(`^${escapeRegex(str)}`, flags);
311
+ }
312
+ const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g;
313
+ function escapeRegex(str) {
314
+ return str.replace(escapeRegexRE, "\\$&");
315
+ }
316
+ function makeIdFiltersToMatchWithQuery(input) {
317
+ if (!Array.isArray(input)) return makeIdFilterToMatchWithQuery(input);
318
+ return input.map((i) => makeIdFilterToMatchWithQuery(i));
319
+ }
320
+ function makeIdFilterToMatchWithQuery(input) {
321
+ if (typeof input === "string") return `${input}{?*,}`;
322
+ return makeRegexIdFilterToMatchWithQuery(input);
323
+ }
324
+ function makeRegexIdFilterToMatchWithQuery(input) {
325
+ return new RegExp(input.source.replace(/(?<!\\)\$/g, "(?:\\?.*)?$"), input.flags);
326
+ }
327
+
328
+ //#endregion
4
329
  //#region src/plugin/with-filter.ts
5
- init_misc();
6
330
  function withFilterImpl(pluginOption, filterObjectList) {
7
331
  if (isPromiseLike(pluginOption)) return pluginOption.then((p) => withFilter(p, filterObjectList));
8
332
  if (pluginOption == false || pluginOption == null) return pluginOption;
@@ -42,4 +366,4 @@ function findMatchedFilterObject(pluginName, overrideFilterObjectList) {
42
366
  }
43
367
 
44
368
  //#endregion
45
- export { and, code, exclude, id, include, moduleType, not, or, queries, query, withFilter };
369
+ export { and, code, exactRegex, exclude, exprInterpreter, filterVitePlugins, id, importerId, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query, withFilter };
@@ -0,0 +1,7 @@
1
+ import { a as RolldownLog } from "./shared/logging-wIy4zY9I.mjs";
2
+
3
+ //#region src/get-log-filter.d.ts
4
+ type GetLogFilter = (filters: string[]) => (log: RolldownLog) => boolean;
5
+ declare const getLogFilter: GetLogFilter;
6
+ //#endregion
7
+ export { GetLogFilter, type RolldownLog, type RolldownLog as RollupLog, getLogFilter as default };
@@ -0,0 +1,48 @@
1
+ //#region src/get-log-filter.ts
2
+ const getLogFilter = (filters) => {
3
+ if (filters.length === 0) return () => true;
4
+ const normalizedFilters = filters.map((filter) => filter.split("&").map((subFilter) => {
5
+ const inverted = subFilter.startsWith("!");
6
+ if (inverted) subFilter = subFilter.slice(1);
7
+ const [key, ...value] = subFilter.split(":");
8
+ return {
9
+ inverted,
10
+ key: key.split("."),
11
+ parts: value.join(":").split("*")
12
+ };
13
+ }));
14
+ return (log) => {
15
+ nextIntersectedFilter: for (const intersectedFilters of normalizedFilters) {
16
+ for (const { inverted, key, parts } of intersectedFilters) {
17
+ const isFilterSatisfied = testFilter(log, key, parts);
18
+ if (inverted ? isFilterSatisfied : !isFilterSatisfied) continue nextIntersectedFilter;
19
+ }
20
+ return true;
21
+ }
22
+ return false;
23
+ };
24
+ };
25
+ const testFilter = (log, key, parts) => {
26
+ let rawValue = log;
27
+ for (let index = 0; index < key.length; index++) {
28
+ if (!rawValue) return false;
29
+ const part = key[index];
30
+ if (!(part in rawValue)) return false;
31
+ rawValue = rawValue[part];
32
+ }
33
+ let value = typeof rawValue === "object" ? JSON.stringify(rawValue) : String(rawValue);
34
+ if (parts.length === 1) return value === parts[0];
35
+ if (!value.startsWith(parts[0])) return false;
36
+ const lastPartIndex = parts.length - 1;
37
+ for (let index = 1; index < lastPartIndex; index++) {
38
+ const part = parts[index];
39
+ const position = value.indexOf(part);
40
+ if (position === -1) return false;
41
+ value = value.slice(position + part.length);
42
+ }
43
+ return value.endsWith(parts[lastPartIndex]);
44
+ };
45
+ var get_log_filter_default = getLogFilter;
46
+
47
+ //#endregion
48
+ export { get_log_filter_default as default };