@rollipop/rolldown 0.0.0 → 1.0.0-rc.10

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 (50) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +11 -1
  3. package/bin/cli.mjs +2 -0
  4. package/dist/cli.d.mts +1 -0
  5. package/dist/cli.mjs +1191 -0
  6. package/dist/config.d.mts +14 -0
  7. package/dist/config.mjs +4 -0
  8. package/dist/experimental-index.d.mts +316 -0
  9. package/dist/experimental-index.mjs +350 -0
  10. package/dist/experimental-runtime-types.d.ts +98 -0
  11. package/dist/filter-index.d.mts +196 -0
  12. package/dist/filter-index.mjs +386 -0
  13. package/dist/get-log-filter.d.mts +3 -0
  14. package/dist/get-log-filter.mjs +68 -0
  15. package/dist/index.d.mts +4 -0
  16. package/dist/index.mjs +50 -0
  17. package/dist/parallel-plugin-worker.d.mts +1 -0
  18. package/dist/parallel-plugin-worker.mjs +28 -0
  19. package/dist/parallel-plugin.d.mts +13 -0
  20. package/dist/parallel-plugin.mjs +6 -0
  21. package/dist/parse-ast-index.d.mts +32 -0
  22. package/dist/parse-ast-index.mjs +60 -0
  23. package/dist/plugins-index.d.mts +33 -0
  24. package/dist/plugins-index.mjs +40 -0
  25. package/dist/shared/binding-D_jQsHun.mjs +583 -0
  26. package/dist/shared/binding-hSQGgsUz.d.mts +1877 -0
  27. package/dist/shared/bindingify-input-options-DfXGy4QO.mjs +2193 -0
  28. package/dist/shared/constructors-B-HbV10G.mjs +68 -0
  29. package/dist/shared/constructors-DMl58KN5.d.mts +37 -0
  30. package/dist/shared/define-config-BSxBeCq6.d.mts +3810 -0
  31. package/dist/shared/define-config-DJOr6Iwt.mjs +6 -0
  32. package/dist/shared/error-D5tMcn3l.mjs +85 -0
  33. package/dist/shared/get-log-filter-semyr3Lj.d.mts +35 -0
  34. package/dist/shared/load-config-CNjYgiQv.mjs +120 -0
  35. package/dist/shared/logging-C6h4g8dA.d.mts +50 -0
  36. package/dist/shared/logs-D80CXhvg.mjs +180 -0
  37. package/dist/shared/misc-DJYbNKZX.mjs +21 -0
  38. package/dist/shared/normalize-string-or-regex-B8PEhdn1.mjs +66 -0
  39. package/dist/shared/parse-iQx2ihYn.mjs +74 -0
  40. package/dist/shared/prompt-BYQIwEjg.mjs +845 -0
  41. package/dist/shared/resolve-tsconfig-CxoM-bno.mjs +113 -0
  42. package/dist/shared/rolldown-C0o3hS3w.mjs +40 -0
  43. package/dist/shared/rolldown-build-80GULIOI.mjs +3326 -0
  44. package/dist/shared/transform-DY2pi3Qm.d.mts +149 -0
  45. package/dist/shared/watch-C2am0Ahc.mjs +374 -0
  46. package/dist/utils-index.d.mts +376 -0
  47. package/dist/utils-index.mjs +2414 -0
  48. package/package.json +130 -2
  49. package/.editorconfig +0 -10
  50. package/.gitattributes +0 -4
@@ -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 {};
@@ -0,0 +1,196 @@
1
+ import { M as withFilter } from "./shared/define-config-BSxBeCq6.mjs";
2
+
3
+ //#region ../pluginutils/dist/filter/composable-filters.d.ts
4
+ type StringOrRegExp = string | RegExp;
5
+ type PluginModuleType = 'js' | 'jsx' | 'ts' | 'tsx' | 'json' | 'text' | 'base64' | 'dataurl' | 'binary' | 'empty' | (string & {});
6
+ type FilterExpressionKind = FilterExpression['kind'];
7
+ type FilterExpression = And | Or | Not | Id | ImporterId | ModuleType | Code | Query;
8
+ type TopLevelFilterExpression = Include | Exclude;
9
+ declare class And {
10
+ kind: 'and';
11
+ args: FilterExpression[];
12
+ constructor(...args: FilterExpression[]);
13
+ }
14
+ declare class Or {
15
+ kind: 'or';
16
+ args: FilterExpression[];
17
+ constructor(...args: FilterExpression[]);
18
+ }
19
+ declare class Not {
20
+ kind: 'not';
21
+ expr: FilterExpression;
22
+ constructor(expr: FilterExpression);
23
+ }
24
+ interface QueryFilterObject {
25
+ [key: string]: StringOrRegExp | boolean;
26
+ }
27
+ interface IdParams {
28
+ cleanUrl?: boolean;
29
+ }
30
+ declare class Id {
31
+ kind: 'id';
32
+ pattern: StringOrRegExp;
33
+ params: IdParams;
34
+ constructor(pattern: StringOrRegExp, params?: IdParams);
35
+ }
36
+ declare class ImporterId {
37
+ kind: 'importerId';
38
+ pattern: StringOrRegExp;
39
+ params: IdParams;
40
+ constructor(pattern: StringOrRegExp, params?: IdParams);
41
+ }
42
+ declare class ModuleType {
43
+ kind: 'moduleType';
44
+ pattern: PluginModuleType;
45
+ constructor(pattern: PluginModuleType);
46
+ }
47
+ declare class Code {
48
+ kind: 'code';
49
+ pattern: StringOrRegExp;
50
+ constructor(expr: StringOrRegExp);
51
+ }
52
+ declare class Query {
53
+ kind: 'query';
54
+ key: string;
55
+ pattern: StringOrRegExp | boolean;
56
+ constructor(key: string, pattern: StringOrRegExp | boolean);
57
+ }
58
+ declare class Include {
59
+ kind: 'include';
60
+ expr: FilterExpression;
61
+ constructor(expr: FilterExpression);
62
+ }
63
+ declare class Exclude {
64
+ kind: 'exclude';
65
+ expr: FilterExpression;
66
+ constructor(expr: FilterExpression);
67
+ }
68
+ declare function and(...args: FilterExpression[]): And;
69
+ declare function or(...args: FilterExpression[]): Or;
70
+ declare function not(expr: FilterExpression): Not;
71
+ declare function id(pattern: StringOrRegExp, params?: IdParams): Id;
72
+ declare function importerId(pattern: StringOrRegExp, params?: IdParams): ImporterId;
73
+ declare function moduleType(pattern: PluginModuleType): ModuleType;
74
+ declare function code(pattern: StringOrRegExp): Code;
75
+ declare function query(key: string, pattern: StringOrRegExp | boolean): Query;
76
+ declare function include(expr: FilterExpression): Include;
77
+ declare function exclude(expr: FilterExpression): Exclude;
78
+ /**
79
+ * convert a queryObject to FilterExpression like
80
+ * ```js
81
+ * and(query(k1, v1), query(k2, v2))
82
+ * ```
83
+ * @param queryFilterObject The query filter object needs to be matched.
84
+ * @returns a `And` FilterExpression
85
+ */
86
+ declare function queries(queryFilter: QueryFilterObject): And;
87
+ declare function interpreter(exprs: TopLevelFilterExpression | TopLevelFilterExpression[], code?: string, id?: string, moduleType?: PluginModuleType, importerId?: string): boolean;
88
+ interface InterpreterCtx {
89
+ urlSearchParamsCache?: URLSearchParams;
90
+ }
91
+ declare function interpreterImpl(expr: TopLevelFilterExpression[], code?: string, id?: string, moduleType?: PluginModuleType, importerId?: string, ctx?: InterpreterCtx): boolean;
92
+ declare function exprInterpreter(expr: FilterExpression, code?: string, id?: string, moduleType?: PluginModuleType, importerId?: string, ctx?: InterpreterCtx): boolean;
93
+ //#endregion
94
+ //#region ../pluginutils/dist/filter/filter-vite-plugins.d.ts
95
+ /**
96
+ * Filters out Vite plugins that have `apply: 'serve'` set.
97
+ *
98
+ * Since Rolldown operates in build mode, plugins marked with `apply: 'serve'`
99
+ * are intended only for Vite's dev server and should be excluded from the build process.
100
+ *
101
+ * @param plugins - Array of plugins (can include nested arrays)
102
+ * @returns Filtered array with serve-only plugins removed
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * import { defineConfig } from '@rollipop/rolldown';
107
+ * import { filterVitePlugins } from '@rolldown/pluginutils';
108
+ * import viteReact from '@vitejs/plugin-react';
109
+ *
110
+ * export default defineConfig({
111
+ * plugins: filterVitePlugins([
112
+ * viteReact(),
113
+ * {
114
+ * name: 'dev-only',
115
+ * apply: 'serve', // This will be filtered out
116
+ * // ...
117
+ * }
118
+ * ])
119
+ * });
120
+ * ```
121
+ */
122
+ declare function filterVitePlugins<T = any>(plugins: T | T[] | null | undefined | false): T[];
123
+ //#endregion
124
+ //#region ../pluginutils/dist/filter/simple-filters.d.ts
125
+ /**
126
+ * Constructs a RegExp that matches the exact string specified.
127
+ *
128
+ * This is useful for plugin hook filters.
129
+ *
130
+ * @param str the string to match.
131
+ * @param flags flags for the RegExp.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * import { exactRegex } from '@rolldown/pluginutils';
136
+ * const plugin = {
137
+ * name: 'plugin',
138
+ * resolveId: {
139
+ * filter: { id: exactRegex('foo') },
140
+ * handler(id) {} // will only be called for `foo`
141
+ * }
142
+ * }
143
+ * ```
144
+ */
145
+ declare function exactRegex(str: string, flags?: string): RegExp;
146
+ /**
147
+ * Constructs a RegExp that matches a value that has the specified prefix.
148
+ *
149
+ * This is useful for plugin hook filters.
150
+ *
151
+ * @param str the string to match.
152
+ * @param flags flags for the RegExp.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * import { prefixRegex } from '@rolldown/pluginutils';
157
+ * const plugin = {
158
+ * name: 'plugin',
159
+ * resolveId: {
160
+ * filter: { id: prefixRegex('foo') },
161
+ * handler(id) {} // will only be called for IDs starting with `foo`
162
+ * }
163
+ * }
164
+ * ```
165
+ */
166
+ declare function prefixRegex(str: string, flags?: string): RegExp;
167
+ type WidenString<T> = T extends string ? string : T;
168
+ /**
169
+ * Converts a id filter to match with an id with a query.
170
+ *
171
+ * @param input the id filters to convert.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * import { makeIdFiltersToMatchWithQuery } from '@rolldown/pluginutils';
176
+ * const plugin = {
177
+ * name: 'plugin',
178
+ * transform: {
179
+ * filter: { id: makeIdFiltersToMatchWithQuery(['**' + '/*.js', /\.ts$/]) },
180
+ * // The handler will be called for IDs like:
181
+ * // - foo.js
182
+ * // - foo.js?foo
183
+ * // - foo.txt?foo.js
184
+ * // - foo.ts
185
+ * // - foo.ts?foo
186
+ * // - foo.txt?foo.ts
187
+ * handler(code, id) {}
188
+ * }
189
+ * }
190
+ * ```
191
+ */
192
+ declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: T): WidenString<T>;
193
+ declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: readonly T[]): WidenString<T>[];
194
+ declare function makeIdFiltersToMatchWithQuery(input: string | RegExp | readonly (string | RegExp)[]): string | RegExp | (string | RegExp)[];
195
+ //#endregion
196
+ export { FilterExpression, FilterExpressionKind, QueryFilterObject, TopLevelFilterExpression, and, code, exactRegex, exclude, exprInterpreter, filterVitePlugins, id, importerId, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query, withFilter };
@@ -0,0 +1,386 @@
1
+ import { n as isPromiseLike, t as arraify } from "./shared/misc-DJYbNKZX.mjs";
2
+ //#region ../pluginutils/dist/utils.js
3
+ const postfixRE = /[?#].*$/;
4
+ function cleanUrl(url) {
5
+ return url.replace(postfixRE, "");
6
+ }
7
+ function extractQueryWithoutFragment(url) {
8
+ const questionMarkIndex = url.indexOf("?");
9
+ if (questionMarkIndex === -1) return "";
10
+ const fragmentIndex = url.indexOf("#", questionMarkIndex);
11
+ if (fragmentIndex === -1) return url.substring(questionMarkIndex);
12
+ else return url.substring(questionMarkIndex, fragmentIndex);
13
+ }
14
+ //#endregion
15
+ //#region ../pluginutils/dist/filter/composable-filters.js
16
+ var And = class {
17
+ kind;
18
+ args;
19
+ constructor(...args) {
20
+ if (args.length === 0) throw new Error("`And` expects at least one operand");
21
+ this.args = args;
22
+ this.kind = "and";
23
+ }
24
+ };
25
+ var Or = class {
26
+ kind;
27
+ args;
28
+ constructor(...args) {
29
+ if (args.length === 0) throw new Error("`Or` expects at least one operand");
30
+ this.args = args;
31
+ this.kind = "or";
32
+ }
33
+ };
34
+ var Not = class {
35
+ kind;
36
+ expr;
37
+ constructor(expr) {
38
+ this.expr = expr;
39
+ this.kind = "not";
40
+ }
41
+ };
42
+ var Id = class {
43
+ kind;
44
+ pattern;
45
+ params;
46
+ constructor(pattern, params) {
47
+ this.pattern = pattern;
48
+ this.kind = "id";
49
+ this.params = params ?? { cleanUrl: false };
50
+ }
51
+ };
52
+ var ImporterId = class {
53
+ kind;
54
+ pattern;
55
+ params;
56
+ constructor(pattern, params) {
57
+ this.pattern = pattern;
58
+ this.kind = "importerId";
59
+ this.params = params ?? { cleanUrl: false };
60
+ }
61
+ };
62
+ var ModuleType = class {
63
+ kind;
64
+ pattern;
65
+ constructor(pattern) {
66
+ this.pattern = pattern;
67
+ this.kind = "moduleType";
68
+ }
69
+ };
70
+ var Code = class {
71
+ kind;
72
+ pattern;
73
+ constructor(expr) {
74
+ this.pattern = expr;
75
+ this.kind = "code";
76
+ }
77
+ };
78
+ var Query = class {
79
+ kind;
80
+ key;
81
+ pattern;
82
+ constructor(key, pattern) {
83
+ this.pattern = pattern;
84
+ this.key = key;
85
+ this.kind = "query";
86
+ }
87
+ };
88
+ var Include = class {
89
+ kind;
90
+ expr;
91
+ constructor(expr) {
92
+ this.expr = expr;
93
+ this.kind = "include";
94
+ }
95
+ };
96
+ var Exclude = class {
97
+ kind;
98
+ expr;
99
+ constructor(expr) {
100
+ this.expr = expr;
101
+ this.kind = "exclude";
102
+ }
103
+ };
104
+ function and(...args) {
105
+ return new And(...args);
106
+ }
107
+ function or(...args) {
108
+ return new Or(...args);
109
+ }
110
+ function not(expr) {
111
+ return new Not(expr);
112
+ }
113
+ function id(pattern, params) {
114
+ return new Id(pattern, params);
115
+ }
116
+ function importerId(pattern, params) {
117
+ return new ImporterId(pattern, params);
118
+ }
119
+ function moduleType(pattern) {
120
+ return new ModuleType(pattern);
121
+ }
122
+ function code(pattern) {
123
+ return new Code(pattern);
124
+ }
125
+ function query(key, pattern) {
126
+ return new Query(key, pattern);
127
+ }
128
+ function include(expr) {
129
+ return new Include(expr);
130
+ }
131
+ 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
+ function queries(queryFilter) {
143
+ return and(...Object.entries(queryFilter).map(([key, value]) => {
144
+ return new Query(key, value);
145
+ }));
146
+ }
147
+ function interpreter(exprs, code, id, moduleType, importerId) {
148
+ let arr = [];
149
+ if (Array.isArray(exprs)) arr = exprs;
150
+ else arr = [exprs];
151
+ return interpreterImpl(arr, code, id, moduleType, importerId);
152
+ }
153
+ function interpreterImpl(expr, code, id, moduleType, importerId, ctx = {}) {
154
+ let hasInclude = false;
155
+ for (const e of expr) switch (e.kind) {
156
+ case "include":
157
+ hasInclude = true;
158
+ if (exprInterpreter(e.expr, code, id, moduleType, importerId, ctx)) return true;
159
+ break;
160
+ case "exclude":
161
+ if (exprInterpreter(e.expr, code, id, moduleType, importerId, ctx)) return false;
162
+ break;
163
+ }
164
+ return !hasInclude;
165
+ }
166
+ function exprInterpreter(expr, code, id, moduleType, importerId, ctx = {}) {
167
+ switch (expr.kind) {
168
+ case "and": return expr.args.every((e) => exprInterpreter(e, code, id, moduleType, importerId, ctx));
169
+ case "or": return expr.args.some((e) => exprInterpreter(e, code, id, moduleType, importerId, ctx));
170
+ case "not": return !exprInterpreter(expr.expr, code, id, moduleType, importerId, ctx);
171
+ case "id": {
172
+ if (id === void 0) throw new Error("`id` is required for `id` expression");
173
+ let idToMatch = id;
174
+ if (expr.params.cleanUrl) idToMatch = cleanUrl(idToMatch);
175
+ return typeof expr.pattern === "string" ? idToMatch === expr.pattern : expr.pattern.test(idToMatch);
176
+ }
177
+ case "importerId": {
178
+ if (importerId === void 0) return false;
179
+ let importerIdToMatch = importerId;
180
+ if (expr.params.cleanUrl) importerIdToMatch = cleanUrl(importerIdToMatch);
181
+ return typeof expr.pattern === "string" ? importerIdToMatch === expr.pattern : expr.pattern.test(importerIdToMatch);
182
+ }
183
+ case "moduleType":
184
+ if (moduleType === void 0) throw new Error("`moduleType` is required for `moduleType` expression");
185
+ return moduleType === expr.pattern;
186
+ case "code":
187
+ if (code === void 0) throw new Error("`code` is required for `code` expression");
188
+ return typeof expr.pattern === "string" ? code.includes(expr.pattern) : expr.pattern.test(code);
189
+ case "query": {
190
+ if (id === void 0) throw new Error("`id` is required for `Query` expression");
191
+ if (!ctx.urlSearchParamsCache) {
192
+ let queryString = extractQueryWithoutFragment(id);
193
+ ctx.urlSearchParamsCache = new URLSearchParams(queryString);
194
+ }
195
+ let urlParams = ctx.urlSearchParamsCache;
196
+ if (typeof expr.pattern === "boolean") if (expr.pattern) return urlParams.has(expr.key);
197
+ else return !urlParams.has(expr.key);
198
+ else if (typeof expr.pattern === "string") return urlParams.get(expr.key) === expr.pattern;
199
+ else return expr.pattern.test(urlParams.get(expr.key) ?? "");
200
+ }
201
+ default: throw new Error(`Expression ${JSON.stringify(expr)} is not expected.`);
202
+ }
203
+ }
204
+ //#endregion
205
+ //#region ../pluginutils/dist/filter/filter-vite-plugins.js
206
+ /**
207
+ * Filters out Vite plugins that have `apply: 'serve'` set.
208
+ *
209
+ * Since Rolldown operates in build mode, plugins marked with `apply: 'serve'`
210
+ * are intended only for Vite's dev server and should be excluded from the build process.
211
+ *
212
+ * @param plugins - Array of plugins (can include nested arrays)
213
+ * @returns Filtered array with serve-only plugins removed
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * import { defineConfig } from '@rollipop/rolldown';
218
+ * import { filterVitePlugins } from '@rolldown/pluginutils';
219
+ * import viteReact from '@vitejs/plugin-react';
220
+ *
221
+ * export default defineConfig({
222
+ * plugins: filterVitePlugins([
223
+ * viteReact(),
224
+ * {
225
+ * name: 'dev-only',
226
+ * apply: 'serve', // This will be filtered out
227
+ * // ...
228
+ * }
229
+ * ])
230
+ * });
231
+ * ```
232
+ */
233
+ function filterVitePlugins(plugins) {
234
+ if (!plugins) return [];
235
+ const pluginArray = Array.isArray(plugins) ? plugins : [plugins];
236
+ const result = [];
237
+ for (const plugin of pluginArray) {
238
+ if (!plugin) continue;
239
+ if (Array.isArray(plugin)) {
240
+ result.push(...filterVitePlugins(plugin));
241
+ continue;
242
+ }
243
+ const pluginWithApply = plugin;
244
+ if ("apply" in pluginWithApply) {
245
+ const applyValue = pluginWithApply.apply;
246
+ if (typeof applyValue === "function") try {
247
+ if (applyValue({}, {
248
+ command: "build",
249
+ mode: "production"
250
+ })) result.push(plugin);
251
+ } catch {
252
+ result.push(plugin);
253
+ }
254
+ else if (applyValue === "serve") continue;
255
+ else result.push(plugin);
256
+ } else result.push(plugin);
257
+ }
258
+ return result;
259
+ }
260
+ //#endregion
261
+ //#region ../pluginutils/dist/filter/simple-filters.js
262
+ /**
263
+ * Constructs a RegExp that matches the exact string specified.
264
+ *
265
+ * This is useful for plugin hook filters.
266
+ *
267
+ * @param str the string to match.
268
+ * @param flags flags for the RegExp.
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * import { exactRegex } from '@rolldown/pluginutils';
273
+ * const plugin = {
274
+ * name: 'plugin',
275
+ * resolveId: {
276
+ * filter: { id: exactRegex('foo') },
277
+ * handler(id) {} // will only be called for `foo`
278
+ * }
279
+ * }
280
+ * ```
281
+ */
282
+ function exactRegex(str, flags) {
283
+ return new RegExp(`^${escapeRegex(str)}$`, flags);
284
+ }
285
+ /**
286
+ * Constructs a RegExp that matches a value that has the specified prefix.
287
+ *
288
+ * This is useful for plugin hook filters.
289
+ *
290
+ * @param str the string to match.
291
+ * @param flags flags for the RegExp.
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * import { prefixRegex } from '@rolldown/pluginutils';
296
+ * const plugin = {
297
+ * name: 'plugin',
298
+ * resolveId: {
299
+ * filter: { id: prefixRegex('foo') },
300
+ * handler(id) {} // will only be called for IDs starting with `foo`
301
+ * }
302
+ * }
303
+ * ```
304
+ */
305
+ function prefixRegex(str, flags) {
306
+ return new RegExp(`^${escapeRegex(str)}`, flags);
307
+ }
308
+ const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g;
309
+ function escapeRegex(str) {
310
+ return str.replace(escapeRegexRE, "\\$&");
311
+ }
312
+ function makeIdFiltersToMatchWithQuery(input) {
313
+ if (!Array.isArray(input)) return makeIdFilterToMatchWithQuery(input);
314
+ return input.map((i) => makeIdFilterToMatchWithQuery(i));
315
+ }
316
+ function makeIdFilterToMatchWithQuery(input) {
317
+ if (typeof input === "string") return `${input}{?*,}`;
318
+ return makeRegexIdFilterToMatchWithQuery(input);
319
+ }
320
+ function makeRegexIdFilterToMatchWithQuery(input) {
321
+ return new RegExp(input.source.replace(/(?<!\\)\$/g, "(?:\\?.*)?$"), input.flags);
322
+ }
323
+ //#endregion
324
+ //#region src/plugin/with-filter.ts
325
+ function withFilterImpl(pluginOption, filterObjectList) {
326
+ if (isPromiseLike(pluginOption)) return pluginOption.then((p) => withFilter(p, filterObjectList));
327
+ if (pluginOption == false || pluginOption == null) return pluginOption;
328
+ if (Array.isArray(pluginOption)) return pluginOption.map((p) => withFilter(p, filterObjectList));
329
+ let plugin = pluginOption;
330
+ let filterObjectIndex = findMatchedFilterObject(plugin.name, filterObjectList);
331
+ if (filterObjectIndex === -1) return plugin;
332
+ let filterObject = filterObjectList[filterObjectIndex];
333
+ Object.keys(plugin).forEach((key) => {
334
+ switch (key) {
335
+ case "transform":
336
+ case "resolveId":
337
+ case "load":
338
+ if (!plugin[key]) return;
339
+ if (typeof plugin[key] === "object") plugin[key].filter = filterObject[key] ?? plugin[key].filter;
340
+ else plugin[key] = {
341
+ handler: plugin[key],
342
+ filter: filterObject[key]
343
+ };
344
+ break;
345
+ default: break;
346
+ }
347
+ });
348
+ return plugin;
349
+ }
350
+ /**
351
+ * A helper function to add plugin hook filters to a plugin or an array of plugins.
352
+ *
353
+ * @example
354
+ * ```ts
355
+ * import yaml from '@rollup/plugin-yaml';
356
+ * import { defineConfig } from 'rolldown';
357
+ * import { withFilter } from 'rolldown/filter';
358
+ *
359
+ * export default defineConfig({
360
+ * plugins: [
361
+ * // Run the transform hook of the `yaml` plugin
362
+ * // only for modules which end in `.yaml`
363
+ * withFilter(
364
+ * yaml({}),
365
+ * { transform: { id: /\.yaml$/ } },
366
+ * ),
367
+ * ],
368
+ * });
369
+ * ```
370
+ *
371
+ * @category Config
372
+ */
373
+ function withFilter(pluginOption, filterObject) {
374
+ return withFilterImpl(pluginOption, arraify(filterObject));
375
+ }
376
+ function findMatchedFilterObject(pluginName, overrideFilterObjectList) {
377
+ if (overrideFilterObjectList.length === 1 && overrideFilterObjectList[0].pluginNamePattern === void 0) return 0;
378
+ for (let i = 0; i < overrideFilterObjectList.length; i++) for (let j = 0; j < (overrideFilterObjectList[i].pluginNamePattern ?? []).length; j++) {
379
+ let pattern = overrideFilterObjectList[i].pluginNamePattern[j];
380
+ if (typeof pattern === "string" && pattern === pluginName) return i;
381
+ else if (pattern instanceof RegExp && pattern.test(pluginName)) return i;
382
+ }
383
+ return -1;
384
+ }
385
+ //#endregion
386
+ export { and, code, exactRegex, exclude, exprInterpreter, filterVitePlugins, id, importerId, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query, withFilter };
@@ -0,0 +1,3 @@
1
+ import { a as RolldownLog } from "./shared/logging-C6h4g8dA.mjs";
2
+ import { n as getLogFilter, t as GetLogFilter } from "./shared/get-log-filter-semyr3Lj.mjs";
3
+ export { GetLogFilter, RolldownLog, RolldownLog as RollupLog, getLogFilter as default };