@rolldown/pluginutils 1.0.0-beta.42 → 1.0.0-beta.43
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.
- package/dist/index.d.mts +31 -1
- package/dist/index.mjs +60 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -82,6 +82,36 @@ interface InterpreterCtx {
|
|
|
82
82
|
declare function interpreterImpl(expr: TopLevelFilterExpression[], code?: string, id?: string, moduleType?: PluginModuleType, ctx?: InterpreterCtx): boolean;
|
|
83
83
|
declare function exprInterpreter(expr: FilterExpression, code?: string, id?: string, moduleType?: PluginModuleType, ctx?: InterpreterCtx): boolean;
|
|
84
84
|
//#endregion
|
|
85
|
+
//#region src/filter-vite-plugins.d.ts
|
|
86
|
+
/**
|
|
87
|
+
* Filters out Vite plugins that have `apply: 'serve'` set.
|
|
88
|
+
*
|
|
89
|
+
* Since Rolldown operates in build mode, plugins marked with `apply: 'serve'`
|
|
90
|
+
* are intended only for Vite's dev server and should be excluded from the build process.
|
|
91
|
+
*
|
|
92
|
+
* @param plugins - Array of plugins (can include nested arrays)
|
|
93
|
+
* @returns Filtered array with serve-only plugins removed
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { defineConfig } from 'rolldown';
|
|
98
|
+
* import { filterVitePlugins } from '@rolldown/pluginutils';
|
|
99
|
+
* import viteReact from '@vitejs/plugin-react';
|
|
100
|
+
*
|
|
101
|
+
* export default defineConfig({
|
|
102
|
+
* plugins: filterVitePlugins([
|
|
103
|
+
* viteReact(),
|
|
104
|
+
* {
|
|
105
|
+
* name: 'dev-only',
|
|
106
|
+
* apply: 'serve', // This will be filtered out
|
|
107
|
+
* // ...
|
|
108
|
+
* }
|
|
109
|
+
* ])
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function filterVitePlugins<T = any>(plugins: T | T[] | null | undefined | false): T[];
|
|
114
|
+
//#endregion
|
|
85
115
|
//#region src/simple-filters.d.ts
|
|
86
116
|
/**
|
|
87
117
|
* Constructs a RegExp that matches the exact string specified.
|
|
@@ -154,4 +184,4 @@ declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input:
|
|
|
154
184
|
declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: readonly T[]): WidenString<T>[];
|
|
155
185
|
declare function makeIdFiltersToMatchWithQuery(input: string | RegExp | readonly (string | RegExp)[]): string | RegExp | (string | RegExp)[];
|
|
156
186
|
//#endregion
|
|
157
|
-
export { FilterExpression, FilterExpressionKind, QueryFilterObject, TopLevelFilterExpression, and, code, exactRegex, exclude, exprInterpreter, id, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query };
|
|
187
|
+
export { FilterExpression, FilterExpressionKind, QueryFilterObject, TopLevelFilterExpression, and, code, exactRegex, exclude, exprInterpreter, filterVitePlugins, id, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query };
|
package/dist/index.mjs
CHANGED
|
@@ -127,10 +127,9 @@ function exclude(expr) {
|
|
|
127
127
|
* @returns a `And` FilterExpression
|
|
128
128
|
*/
|
|
129
129
|
function queries(queryFilter) {
|
|
130
|
-
|
|
130
|
+
return and(...Object.entries(queryFilter).map(([key, value]) => {
|
|
131
131
|
return new Query(key, value);
|
|
132
|
-
});
|
|
133
|
-
return and(...arr);
|
|
132
|
+
}));
|
|
134
133
|
}
|
|
135
134
|
function interpreter(exprs, code$1, id$1, moduleType$1) {
|
|
136
135
|
let arr = [];
|
|
@@ -182,6 +181,63 @@ function exprInterpreter(expr, code$1, id$1, moduleType$1, ctx = {}) {
|
|
|
182
181
|
}
|
|
183
182
|
}
|
|
184
183
|
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/filter-vite-plugins.ts
|
|
186
|
+
/**
|
|
187
|
+
* Filters out Vite plugins that have `apply: 'serve'` set.
|
|
188
|
+
*
|
|
189
|
+
* Since Rolldown operates in build mode, plugins marked with `apply: 'serve'`
|
|
190
|
+
* are intended only for Vite's dev server and should be excluded from the build process.
|
|
191
|
+
*
|
|
192
|
+
* @param plugins - Array of plugins (can include nested arrays)
|
|
193
|
+
* @returns Filtered array with serve-only plugins removed
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* import { defineConfig } from 'rolldown';
|
|
198
|
+
* import { filterVitePlugins } from '@rolldown/pluginutils';
|
|
199
|
+
* import viteReact from '@vitejs/plugin-react';
|
|
200
|
+
*
|
|
201
|
+
* export default defineConfig({
|
|
202
|
+
* plugins: filterVitePlugins([
|
|
203
|
+
* viteReact(),
|
|
204
|
+
* {
|
|
205
|
+
* name: 'dev-only',
|
|
206
|
+
* apply: 'serve', // This will be filtered out
|
|
207
|
+
* // ...
|
|
208
|
+
* }
|
|
209
|
+
* ])
|
|
210
|
+
* });
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
function filterVitePlugins(plugins) {
|
|
214
|
+
if (!plugins) return [];
|
|
215
|
+
const pluginArray = Array.isArray(plugins) ? plugins : [plugins];
|
|
216
|
+
const result = [];
|
|
217
|
+
for (const plugin of pluginArray) {
|
|
218
|
+
if (!plugin) continue;
|
|
219
|
+
if (Array.isArray(plugin)) {
|
|
220
|
+
result.push(...filterVitePlugins(plugin));
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const pluginWithApply = plugin;
|
|
224
|
+
if ("apply" in pluginWithApply) {
|
|
225
|
+
const applyValue = pluginWithApply.apply;
|
|
226
|
+
if (typeof applyValue === "function") try {
|
|
227
|
+
if (applyValue({}, {
|
|
228
|
+
command: "build",
|
|
229
|
+
mode: "production"
|
|
230
|
+
})) result.push(plugin);
|
|
231
|
+
} catch {
|
|
232
|
+
result.push(plugin);
|
|
233
|
+
}
|
|
234
|
+
else if (applyValue === "serve") continue;
|
|
235
|
+
else result.push(plugin);
|
|
236
|
+
} else result.push(plugin);
|
|
237
|
+
}
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
|
|
185
241
|
//#endregion
|
|
186
242
|
//#region src/simple-filters.ts
|
|
187
243
|
/**
|
|
@@ -247,4 +303,4 @@ function makeRegexIdFilterToMatchWithQuery(input) {
|
|
|
247
303
|
}
|
|
248
304
|
|
|
249
305
|
//#endregion
|
|
250
|
-
export { and, code, exactRegex, exclude, exprInterpreter, id, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query };
|
|
306
|
+
export { and, code, exactRegex, exclude, exprInterpreter, filterVitePlugins, id, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query };
|