@ohos-ports/rolldown 1.2.6-beta.0
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/LICENSE +25 -0
- package/README.md +11 -0
- package/THIRD-PARTY-LICENSE +33 -0
- package/bin/cli.mjs +11 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1208 -0
- package/dist/config.d.mts +26 -0
- package/dist/config.mjs +4 -0
- package/dist/experimental-default-runtime.mjs +116 -0
- package/dist/experimental-index.d.mts +324 -0
- package/dist/experimental-index.mjs +383 -0
- package/dist/experimental-runtime-base.mjs +95 -0
- package/dist/experimental-runtime-types.d.ts +177 -0
- package/dist/experimental-runtime.d.ts +177 -0
- package/dist/experimental-runtime.mjs +257 -0
- package/dist/filter-index.d.mts +196 -0
- package/dist/filter-index.mjs +376 -0
- package/dist/get-log-filter.d.mts +3 -0
- package/dist/get-log-filter.mjs +68 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +56 -0
- package/dist/parallel-plugin-worker.d.mts +1 -0
- package/dist/parallel-plugin-worker.mjs +29 -0
- package/dist/parallel-plugin.d.mts +12 -0
- package/dist/parallel-plugin.mjs +6 -0
- package/dist/parse-ast-index.d.mts +30 -0
- package/dist/parse-ast-index.mjs +60 -0
- package/dist/plugins-index.d.mts +32 -0
- package/dist/plugins-index.mjs +40 -0
- package/dist/shared/binding-CtPG-2KR.mjs +675 -0
- package/dist/shared/binding-Og__jmUi.d.mts +2065 -0
- package/dist/shared/bindingify-input-options-4JJxbZl2.mjs +2416 -0
- package/dist/shared/constructors-Qrp2Xr6w.d.mts +35 -0
- package/dist/shared/constructors-ltBDfHX1.mjs +69 -0
- package/dist/shared/create-bundler-option-DSPiA5F7.mjs +3220 -0
- package/dist/shared/define-config-Demdg3_4.mjs +6 -0
- package/dist/shared/define-config-Nbz-lniw.d.mts +4101 -0
- package/dist/shared/dist-DKbukT1H.mjs +154 -0
- package/dist/shared/error-HDibX49O.mjs +85 -0
- package/dist/shared/get-log-filter-AjBknEEO.d.mts +34 -0
- package/dist/shared/load-config-BMUrE9HH.mjs +137 -0
- package/dist/shared/logging-xuHO4mAy.d.mts +50 -0
- package/dist/shared/logs-DmYCAKcW.mjs +192 -0
- package/dist/shared/misc-DOSKtd97.mjs +29 -0
- package/dist/shared/normalize-string-or-regex-DWz4it3p.mjs +68 -0
- package/dist/shared/parse-D0g29RgN.mjs +74 -0
- package/dist/shared/prompt-CH6TK0bC.mjs +885 -0
- package/dist/shared/resolve-tsconfig-CLYpUIZC.mjs +128 -0
- package/dist/shared/rolldown-C9Hfg50O.mjs +179 -0
- package/dist/shared/transform-DR4CXeQm.d.mts +152 -0
- package/dist/shared/watch-UbzgabQn.mjs +377 -0
- package/dist/utils-index.d.mts +375 -0
- package/dist/utils-index.mjs +2416 -0
- package/package.json +159 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { r as isPromiseLike, t as arraify } from "./shared/misc-DOSKtd97.mjs";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@rolldown+pluginutils@1.0.1/node_modules/@rolldown/pluginutils/dist/filter-B_mD-HGz.mjs
|
|
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
|
+
var And = class {
|
|
15
|
+
kind;
|
|
16
|
+
args;
|
|
17
|
+
constructor(...args) {
|
|
18
|
+
if (args.length === 0) throw new Error("`And` expects at least one operand");
|
|
19
|
+
this.args = args;
|
|
20
|
+
this.kind = "and";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var Or = class {
|
|
24
|
+
kind;
|
|
25
|
+
args;
|
|
26
|
+
constructor(...args) {
|
|
27
|
+
if (args.length === 0) throw new Error("`Or` expects at least one operand");
|
|
28
|
+
this.args = args;
|
|
29
|
+
this.kind = "or";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var Not = class {
|
|
33
|
+
kind;
|
|
34
|
+
expr;
|
|
35
|
+
constructor(expr) {
|
|
36
|
+
this.expr = expr;
|
|
37
|
+
this.kind = "not";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var Id = class {
|
|
41
|
+
kind;
|
|
42
|
+
pattern;
|
|
43
|
+
params;
|
|
44
|
+
constructor(pattern, params) {
|
|
45
|
+
this.pattern = pattern;
|
|
46
|
+
this.kind = "id";
|
|
47
|
+
this.params = params ?? { cleanUrl: false };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var ImporterId = class {
|
|
51
|
+
kind;
|
|
52
|
+
pattern;
|
|
53
|
+
params;
|
|
54
|
+
constructor(pattern, params) {
|
|
55
|
+
this.pattern = pattern;
|
|
56
|
+
this.kind = "importerId";
|
|
57
|
+
this.params = params ?? { cleanUrl: false };
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var ModuleType = class {
|
|
61
|
+
kind;
|
|
62
|
+
pattern;
|
|
63
|
+
constructor(pattern) {
|
|
64
|
+
this.pattern = pattern;
|
|
65
|
+
this.kind = "moduleType";
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var Code = class {
|
|
69
|
+
kind;
|
|
70
|
+
pattern;
|
|
71
|
+
constructor(expr) {
|
|
72
|
+
this.pattern = expr;
|
|
73
|
+
this.kind = "code";
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var Query = class {
|
|
77
|
+
kind;
|
|
78
|
+
key;
|
|
79
|
+
pattern;
|
|
80
|
+
constructor(key, pattern) {
|
|
81
|
+
this.pattern = pattern;
|
|
82
|
+
this.key = key;
|
|
83
|
+
this.kind = "query";
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var Include = class {
|
|
87
|
+
kind;
|
|
88
|
+
expr;
|
|
89
|
+
constructor(expr) {
|
|
90
|
+
this.expr = expr;
|
|
91
|
+
this.kind = "include";
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var Exclude = class {
|
|
95
|
+
kind;
|
|
96
|
+
expr;
|
|
97
|
+
constructor(expr) {
|
|
98
|
+
this.expr = expr;
|
|
99
|
+
this.kind = "exclude";
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
function and(...args) {
|
|
103
|
+
return new And(...args);
|
|
104
|
+
}
|
|
105
|
+
function or(...args) {
|
|
106
|
+
return new Or(...args);
|
|
107
|
+
}
|
|
108
|
+
function not(expr) {
|
|
109
|
+
return new Not(expr);
|
|
110
|
+
}
|
|
111
|
+
function id(pattern, params) {
|
|
112
|
+
return new Id(pattern, params);
|
|
113
|
+
}
|
|
114
|
+
function importerId(pattern, params) {
|
|
115
|
+
return new ImporterId(pattern, params);
|
|
116
|
+
}
|
|
117
|
+
function moduleType(pattern) {
|
|
118
|
+
return new ModuleType(pattern);
|
|
119
|
+
}
|
|
120
|
+
function code(pattern) {
|
|
121
|
+
return new Code(pattern);
|
|
122
|
+
}
|
|
123
|
+
function query(key, pattern) {
|
|
124
|
+
return new Query(key, pattern);
|
|
125
|
+
}
|
|
126
|
+
function include(expr) {
|
|
127
|
+
return new Include(expr);
|
|
128
|
+
}
|
|
129
|
+
function exclude(expr) {
|
|
130
|
+
return new Exclude(expr);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* convert a queryObject to FilterExpression like
|
|
134
|
+
* ```js
|
|
135
|
+
* and(query(k1, v1), query(k2, v2))
|
|
136
|
+
* ```
|
|
137
|
+
* @param queryFilterObject The query filter object needs to be matched.
|
|
138
|
+
* @returns a `And` FilterExpression
|
|
139
|
+
*/
|
|
140
|
+
function queries(queryFilter) {
|
|
141
|
+
return and(...Object.entries(queryFilter).map(([key, value]) => {
|
|
142
|
+
return new Query(key, value);
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
function interpreter(exprs, code, id, moduleType, importerId) {
|
|
146
|
+
let arr = [];
|
|
147
|
+
if (Array.isArray(exprs)) arr = exprs;
|
|
148
|
+
else arr = [exprs];
|
|
149
|
+
return interpreterImpl(arr, code, id, moduleType, importerId);
|
|
150
|
+
}
|
|
151
|
+
function interpreterImpl(expr, code, id, moduleType, importerId, ctx = {}) {
|
|
152
|
+
let hasInclude = false;
|
|
153
|
+
for (const e of expr) switch (e.kind) {
|
|
154
|
+
case "include":
|
|
155
|
+
hasInclude = true;
|
|
156
|
+
if (exprInterpreter(e.expr, code, id, moduleType, importerId, ctx)) return true;
|
|
157
|
+
break;
|
|
158
|
+
case "exclude": if (exprInterpreter(e.expr, code, id, moduleType, importerId, ctx)) return false;
|
|
159
|
+
}
|
|
160
|
+
return !hasInclude;
|
|
161
|
+
}
|
|
162
|
+
function exprInterpreter(expr, code, id, moduleType, importerId, ctx = {}) {
|
|
163
|
+
switch (expr.kind) {
|
|
164
|
+
case "and": return expr.args.every((e) => exprInterpreter(e, code, id, moduleType, importerId, ctx));
|
|
165
|
+
case "or": return expr.args.some((e) => exprInterpreter(e, code, id, moduleType, importerId, ctx));
|
|
166
|
+
case "not": return !exprInterpreter(expr.expr, code, id, moduleType, importerId, ctx);
|
|
167
|
+
case "id": {
|
|
168
|
+
if (id === void 0) throw new Error("`id` is required for `id` expression");
|
|
169
|
+
let idToMatch = id;
|
|
170
|
+
if (expr.params.cleanUrl) idToMatch = cleanUrl(idToMatch);
|
|
171
|
+
return typeof expr.pattern === "string" ? idToMatch === expr.pattern : expr.pattern.test(idToMatch);
|
|
172
|
+
}
|
|
173
|
+
case "importerId": {
|
|
174
|
+
if (importerId === void 0) return false;
|
|
175
|
+
let importerIdToMatch = importerId;
|
|
176
|
+
if (expr.params.cleanUrl) importerIdToMatch = cleanUrl(importerIdToMatch);
|
|
177
|
+
return typeof expr.pattern === "string" ? importerIdToMatch === expr.pattern : expr.pattern.test(importerIdToMatch);
|
|
178
|
+
}
|
|
179
|
+
case "moduleType":
|
|
180
|
+
if (moduleType === void 0) throw new Error("`moduleType` is required for `moduleType` expression");
|
|
181
|
+
return moduleType === expr.pattern;
|
|
182
|
+
case "code":
|
|
183
|
+
if (code === void 0) throw new Error("`code` is required for `code` expression");
|
|
184
|
+
return typeof expr.pattern === "string" ? code.includes(expr.pattern) : expr.pattern.test(code);
|
|
185
|
+
case "query": {
|
|
186
|
+
if (id === void 0) throw new Error("`id` is required for `Query` expression");
|
|
187
|
+
if (!ctx.urlSearchParamsCache) {
|
|
188
|
+
let queryString = extractQueryWithoutFragment(id);
|
|
189
|
+
ctx.urlSearchParamsCache = new URLSearchParams(queryString);
|
|
190
|
+
}
|
|
191
|
+
let urlParams = ctx.urlSearchParamsCache;
|
|
192
|
+
if (typeof expr.pattern === "boolean") if (expr.pattern) return urlParams.has(expr.key);
|
|
193
|
+
else return !urlParams.has(expr.key);
|
|
194
|
+
else if (typeof expr.pattern === "string") return urlParams.get(expr.key) === expr.pattern;
|
|
195
|
+
else return expr.pattern.test(urlParams.get(expr.key) ?? "");
|
|
196
|
+
}
|
|
197
|
+
default: throw new Error(`Expression ${JSON.stringify(expr)} is not expected.`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Filters out Vite plugins that have `apply: 'serve'` set.
|
|
202
|
+
*
|
|
203
|
+
* Since Rolldown operates in build mode, plugins marked with `apply: 'serve'`
|
|
204
|
+
* are intended only for Vite's dev server and should be excluded from the build process.
|
|
205
|
+
*
|
|
206
|
+
* @param plugins - Array of plugins (can include nested arrays)
|
|
207
|
+
* @returns Filtered array with serve-only plugins removed
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* import { defineConfig } from 'rolldown';
|
|
212
|
+
* import { filterVitePlugins } from '@rolldown/pluginutils';
|
|
213
|
+
* import viteReact from '@vitejs/plugin-react';
|
|
214
|
+
*
|
|
215
|
+
* export default defineConfig({
|
|
216
|
+
* plugins: filterVitePlugins([
|
|
217
|
+
* viteReact(),
|
|
218
|
+
* {
|
|
219
|
+
* name: 'dev-only',
|
|
220
|
+
* apply: 'serve', // This will be filtered out
|
|
221
|
+
* // ...
|
|
222
|
+
* }
|
|
223
|
+
* ])
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
function filterVitePlugins(plugins) {
|
|
228
|
+
if (!plugins) return [];
|
|
229
|
+
const pluginArray = Array.isArray(plugins) ? plugins : [plugins];
|
|
230
|
+
const result = [];
|
|
231
|
+
for (const plugin of pluginArray) {
|
|
232
|
+
if (!plugin) continue;
|
|
233
|
+
if (Array.isArray(plugin)) {
|
|
234
|
+
result.push(...filterVitePlugins(plugin));
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const pluginWithApply = plugin;
|
|
238
|
+
if ("apply" in pluginWithApply) {
|
|
239
|
+
const applyValue = pluginWithApply.apply;
|
|
240
|
+
if (typeof applyValue === "function") try {
|
|
241
|
+
if (applyValue({}, {
|
|
242
|
+
command: "build",
|
|
243
|
+
mode: "production"
|
|
244
|
+
})) result.push(plugin);
|
|
245
|
+
} catch {
|
|
246
|
+
result.push(plugin);
|
|
247
|
+
}
|
|
248
|
+
else if (applyValue === "serve") continue;
|
|
249
|
+
else result.push(plugin);
|
|
250
|
+
} else result.push(plugin);
|
|
251
|
+
}
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Constructs a RegExp that matches the exact string specified.
|
|
256
|
+
*
|
|
257
|
+
* This is useful for plugin hook filters.
|
|
258
|
+
*
|
|
259
|
+
* @param str the string to match.
|
|
260
|
+
* @param flags flags for the RegExp.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* import { exactRegex } from '@rolldown/pluginutils';
|
|
265
|
+
* const plugin = {
|
|
266
|
+
* name: 'plugin',
|
|
267
|
+
* resolveId: {
|
|
268
|
+
* filter: { id: exactRegex('foo') },
|
|
269
|
+
* handler(id) {} // will only be called for `foo`
|
|
270
|
+
* }
|
|
271
|
+
* }
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
function exactRegex(str, flags) {
|
|
275
|
+
return new RegExp(`^${escapeRegex(str)}$`, flags);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Constructs a RegExp that matches a value that has the specified prefix.
|
|
279
|
+
*
|
|
280
|
+
* This is useful for plugin hook filters.
|
|
281
|
+
*
|
|
282
|
+
* @param str the string to match.
|
|
283
|
+
* @param flags flags for the RegExp.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* import { prefixRegex } from '@rolldown/pluginutils';
|
|
288
|
+
* const plugin = {
|
|
289
|
+
* name: 'plugin',
|
|
290
|
+
* resolveId: {
|
|
291
|
+
* filter: { id: prefixRegex('foo') },
|
|
292
|
+
* handler(id) {} // will only be called for IDs starting with `foo`
|
|
293
|
+
* }
|
|
294
|
+
* }
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
function prefixRegex(str, flags) {
|
|
298
|
+
return new RegExp(`^${escapeRegex(str)}`, flags);
|
|
299
|
+
}
|
|
300
|
+
const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g;
|
|
301
|
+
function escapeRegex(str) {
|
|
302
|
+
return str.replace(escapeRegexRE, "\\$&");
|
|
303
|
+
}
|
|
304
|
+
function makeIdFiltersToMatchWithQuery(input) {
|
|
305
|
+
if (!Array.isArray(input)) return makeIdFilterToMatchWithQuery(input);
|
|
306
|
+
return input.map((i) => makeIdFilterToMatchWithQuery(i));
|
|
307
|
+
}
|
|
308
|
+
function makeIdFilterToMatchWithQuery(input) {
|
|
309
|
+
if (typeof input === "string") return `${input}{?*,}`;
|
|
310
|
+
return makeRegexIdFilterToMatchWithQuery(input);
|
|
311
|
+
}
|
|
312
|
+
function makeRegexIdFilterToMatchWithQuery(input) {
|
|
313
|
+
return new RegExp(input.source.replace(/(?<!\\)\$/g, "(?:\\?.*)?$"), input.flags);
|
|
314
|
+
}
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/plugin/with-filter.ts
|
|
317
|
+
function withFilterImpl(pluginOption, filterObjectList) {
|
|
318
|
+
if (isPromiseLike(pluginOption)) return pluginOption.then((p) => withFilter(p, filterObjectList));
|
|
319
|
+
if (pluginOption == false || pluginOption == null) return pluginOption;
|
|
320
|
+
if (Array.isArray(pluginOption)) return pluginOption.map((p) => withFilter(p, filterObjectList));
|
|
321
|
+
let plugin = pluginOption;
|
|
322
|
+
let filterObjectIndex = findMatchedFilterObject(plugin.name, filterObjectList);
|
|
323
|
+
if (filterObjectIndex === -1) return plugin;
|
|
324
|
+
let filterObject = filterObjectList[filterObjectIndex];
|
|
325
|
+
Object.keys(plugin).forEach((key) => {
|
|
326
|
+
switch (key) {
|
|
327
|
+
case "transform":
|
|
328
|
+
case "resolveId":
|
|
329
|
+
case "load":
|
|
330
|
+
if (!plugin[key]) return;
|
|
331
|
+
if (typeof plugin[key] === "object") plugin[key].filter = filterObject[key] ?? plugin[key].filter;
|
|
332
|
+
else plugin[key] = {
|
|
333
|
+
handler: plugin[key],
|
|
334
|
+
filter: filterObject[key]
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
return plugin;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* A helper function to add plugin hook filters to a plugin or an array of plugins.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* import yaml from '@rollup/plugin-yaml';
|
|
346
|
+
* import { defineConfig } from 'rolldown';
|
|
347
|
+
* import { withFilter } from 'rolldown/filter';
|
|
348
|
+
*
|
|
349
|
+
* export default defineConfig({
|
|
350
|
+
* plugins: [
|
|
351
|
+
* // Run the transform hook of the `yaml` plugin
|
|
352
|
+
* // only for modules which end in `.yaml`
|
|
353
|
+
* withFilter(
|
|
354
|
+
* yaml({}),
|
|
355
|
+
* { transform: { id: /\.yaml$/ } },
|
|
356
|
+
* ),
|
|
357
|
+
* ],
|
|
358
|
+
* });
|
|
359
|
+
* ```
|
|
360
|
+
*
|
|
361
|
+
* @category Config
|
|
362
|
+
*/
|
|
363
|
+
function withFilter(pluginOption, filterObject) {
|
|
364
|
+
return withFilterImpl(pluginOption, arraify(filterObject));
|
|
365
|
+
}
|
|
366
|
+
function findMatchedFilterObject(pluginName, overrideFilterObjectList) {
|
|
367
|
+
if (overrideFilterObjectList.length === 1 && overrideFilterObjectList[0].pluginNamePattern === void 0) return 0;
|
|
368
|
+
for (let i = 0; i < overrideFilterObjectList.length; i++) for (let j = 0; j < (overrideFilterObjectList[i].pluginNamePattern ?? []).length; j++) {
|
|
369
|
+
let pattern = overrideFilterObjectList[i].pluginNamePattern[j];
|
|
370
|
+
if (typeof pattern === "string" && pattern === pluginName) return i;
|
|
371
|
+
else if (pattern instanceof RegExp && pattern.test(pluginName)) return i;
|
|
372
|
+
}
|
|
373
|
+
return -1;
|
|
374
|
+
}
|
|
375
|
+
//#endregion
|
|
376
|
+
export { and, code, exactRegex, exclude, exprInterpreter, filterVitePlugins, id, importerId, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query, withFilter };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/get-log-filter.ts
|
|
2
|
+
/**
|
|
3
|
+
* A helper function to generate log filters using the same syntax as the CLI.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { defineConfig } from 'rolldown';
|
|
8
|
+
* import { getLogFilter } from 'rolldown/getLogFilter';
|
|
9
|
+
*
|
|
10
|
+
* const logFilter = getLogFilter(['code:FOO', 'code:BAR']);
|
|
11
|
+
*
|
|
12
|
+
* export default defineConfig({
|
|
13
|
+
* input: 'main.js',
|
|
14
|
+
* onLog(level, log, handler) {
|
|
15
|
+
* if (logFilter(log)) {
|
|
16
|
+
* handler(level, log);
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @category Config
|
|
23
|
+
*/
|
|
24
|
+
const getLogFilter = (filters) => {
|
|
25
|
+
if (filters.length === 0) return () => true;
|
|
26
|
+
const normalizedFilters = filters.map((filter) => filter.split("&").map((subFilter) => {
|
|
27
|
+
const inverted = subFilter.startsWith("!");
|
|
28
|
+
if (inverted) subFilter = subFilter.slice(1);
|
|
29
|
+
const [key, ...value] = subFilter.split(":");
|
|
30
|
+
return {
|
|
31
|
+
inverted,
|
|
32
|
+
key: key.split("."),
|
|
33
|
+
parts: value.join(":").split("*")
|
|
34
|
+
};
|
|
35
|
+
}));
|
|
36
|
+
return (log) => {
|
|
37
|
+
nextIntersectedFilter: for (const intersectedFilters of normalizedFilters) {
|
|
38
|
+
for (const { inverted, key, parts } of intersectedFilters) {
|
|
39
|
+
const isFilterSatisfied = testFilter(log, key, parts);
|
|
40
|
+
if (inverted ? isFilterSatisfied : !isFilterSatisfied) continue nextIntersectedFilter;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
const testFilter = (log, key, parts) => {
|
|
48
|
+
let rawValue = log;
|
|
49
|
+
for (let index = 0; index < key.length; index++) {
|
|
50
|
+
if (!rawValue) return false;
|
|
51
|
+
const part = key[index];
|
|
52
|
+
if (!(part in rawValue)) return false;
|
|
53
|
+
rawValue = rawValue[part];
|
|
54
|
+
}
|
|
55
|
+
let value = typeof rawValue === "object" ? JSON.stringify(rawValue) : String(rawValue);
|
|
56
|
+
if (parts.length === 1) return value === parts[0];
|
|
57
|
+
if (!value.startsWith(parts[0])) return false;
|
|
58
|
+
const lastPartIndex = parts.length - 1;
|
|
59
|
+
for (let index = 1; index < lastPartIndex; index++) {
|
|
60
|
+
const part = parts[index];
|
|
61
|
+
const position = value.indexOf(part);
|
|
62
|
+
if (position === -1) return false;
|
|
63
|
+
value = value.slice(position + part.length);
|
|
64
|
+
}
|
|
65
|
+
return value.endsWith(parts[lastPartIndex]);
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { getLogFilter as default };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { a as RolldownLog, i as RolldownError, n as LogLevelOption, o as RolldownLogWithString, r as LogOrStringHandler, t as LogLevel } from "./shared/logging-xuHO4mAy.mjs";
|
|
2
|
+
import { U as PreRenderedChunk } from "./shared/binding-Og__jmUi.mjs";
|
|
3
|
+
import { A as ResolvedId, At as ChunkFileNamesFunction, B as ExistingRawSourceMap, Bt as MinifyOptions, C as ParallelPluginHooks, Ct as RolldownBuild, D as ResolveFileUrlArgs, Dt as AdvancedChunksGroup, E as PluginMeta, Et as AddonFunction, Ft as CommentsOptions, G as EmittedAsset, Gt as PartialNull, H as OutputBundle, Ht as OutputOptions, It as GeneratedCodeOptions, J as EmittedPrebuiltChunk, Jt as OutputChunk, K as EmittedChunk, L as RUNTIME_MODULE_ID, Lt as GeneratedCodePreset, M as RolldownPluginOption, Mt as CodeSplittingGroup, N as SourceDescription, Nt as CodeSplittingNameFunction, O as ResolveIdExtraOptions, Ot as AdvancedChunksOptions, P as TransformResult, Pt as CodeSplittingOptions, Q as DefineParallelPluginResult, Qt as SourceMap, R as VERSION, Rt as GlobalsFunction, S as ObjectHook, St as rolldown, T as Plugin, Tt as build, U as TreeshakingOptions, Ut as PreRenderedAsset, V as SourceMapInput, Vt as ModuleFormat, W as TransformPluginContext, X as PluginContext, Xt as RenderedModule, Y as GetModuleInfo, Yt as RenderedChunk, Z as PluginContextResolveOptions, Zt as RolldownOutput, _ as HookFilterExtension, _t as watch, a as ChunkOptimizationOptions, at as BufferEncoding, b as ModuleOptions, bt as RolldownWatcherWatcherEventMap, c as InputOption, ct as RolldownFsModule, d as OptimizationOptions, dt as NormalizedInputOptions, en as ModuleInfo, et as MinimalPluginContext, f as WatcherFileWatcherOptions, ft as TransformOptions, g as FunctionPluginHooks, gt as RolldownMagicString, h as CustomPluginOptions, ht as WarningHandlerWithDefault, i as RolldownOptions, it as ModuleTypeFilter, j as RolldownPlugin, jt as ChunkingContext, k as ResolveIdResult, kt as BuiltinModuleTag, l as InputOptions, lt as InternalModuleFormat, m as AsyncPluginHooks, mt as LoggingFunction, n as RolldownOptionsFunction, nt as GeneralHookFilter, o as ExternalOption, ot as RolldownDirectoryEntry, p as WatcherOptions, pt as ChecksOptions, q as EmittedFile, qt as OutputAsset, r as defineConfig, rt as HookFilter, s as ExternalOptionFunction, st as RolldownFileStats, t as ConfigExport, tn as SourcemapIgnoreListOption, tt as PluginContextMeta, u as ModuleTypes, ut as NormalizedOutputOptions, v as ImportKind, vt as RolldownWatcher, w as PartialResolvedId, wt as BuildOptions, x as ModuleType, xt as WatchOptions, y as LoadResult, yt as RolldownWatcherEvent, z as BundleError, zt as ManglePropertiesOptions } from "./shared/define-config-Nbz-lniw.mjs";
|
|
4
|
+
export { type AddonFunction, type AdvancedChunksGroup, type AdvancedChunksOptions, type AsyncPluginHooks, type BufferEncoding, type BuildOptions, type BuiltinModuleTag, type BundleError, type ChecksOptions, type ChunkFileNamesFunction, type ChunkOptimizationOptions, type ChunkingContext, type CodeSplittingGroup, type CodeSplittingNameFunction, type CodeSplittingOptions, type CommentsOptions, type ConfigExport, type CustomPluginOptions, type DefineParallelPluginResult, type EmittedAsset, type EmittedChunk, type EmittedFile, type EmittedPrebuiltChunk, type ExistingRawSourceMap, type ExternalOption, type ExternalOptionFunction, type FunctionPluginHooks, type GeneralHookFilter, type GeneratedCodeOptions, type GeneratedCodePreset, type GetModuleInfo, type GlobalsFunction, type HookFilter, type HookFilterExtension, type ImportKind, type InputOption, type InputOptions, type InternalModuleFormat, type LoadResult, type LogLevel, type LogLevelOption, type LogOrStringHandler, type LoggingFunction, type ManglePropertiesOptions, type MinifyOptions, type MinimalPluginContext, type ModuleFormat, type ModuleInfo, type ModuleOptions, type ModuleType, type ModuleTypeFilter, type ModuleTypes, type NormalizedInputOptions, type NormalizedOutputOptions, type ObjectHook, type OptimizationOptions, type OutputAsset, type OutputBundle, type OutputChunk, type OutputOptions, type ParallelPluginHooks, type PartialNull, type PartialResolvedId, type Plugin, type PluginContext, type PluginContextMeta, type PluginContextResolveOptions, type PluginMeta, type PreRenderedAsset, type PreRenderedChunk, RUNTIME_MODULE_ID, type RenderedChunk, type RenderedModule, type ResolveFileUrlArgs, type ResolveIdExtraOptions, type ResolveIdResult, type ResolvedId, type RolldownBuild, type RolldownDirectoryEntry, type RolldownError, type RolldownError as RollupError, type RolldownFileStats, type RolldownFsModule, type RolldownLog, type RolldownLog as RollupLog, type RolldownLogWithString, type RolldownLogWithString as RollupLogWithString, RolldownMagicString, type RolldownOptions, type RolldownOptionsFunction, type RolldownOutput, type RolldownPlugin, type RolldownPluginOption, type RolldownWatcher, type RolldownWatcherEvent, type RolldownWatcherWatcherEventMap, type SourceDescription, type SourceMap, type SourceMapInput, type SourcemapIgnoreListOption, type TransformOptions, type TransformPluginContext, type TransformResult, type TreeshakingOptions, VERSION, type WarningHandlerWithDefault, type WatchOptions, type WatcherFileWatcherOptions, type WatcherOptions, build, defineConfig, rolldown, watch };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { n as __toESM, t as require_binding } from "./shared/binding-CtPG-2KR.mjs";
|
|
2
|
+
import { n as onExit, t as watch } from "./shared/watch-UbzgabQn.mjs";
|
|
3
|
+
import { T as VERSION, s as RolldownMagicString } from "./shared/bindingify-input-options-4JJxbZl2.mjs";
|
|
4
|
+
import { t as rolldown } from "./shared/rolldown-C9Hfg50O.mjs";
|
|
5
|
+
import { t as defineConfig } from "./shared/define-config-Demdg3_4.mjs";
|
|
6
|
+
import { isMainThread } from "node:worker_threads";
|
|
7
|
+
//#region src/setup.ts
|
|
8
|
+
var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
|
|
9
|
+
if (isMainThread) {
|
|
10
|
+
const subscriberGuard = (0, import_binding.initTraceSubscriber)();
|
|
11
|
+
onExit(() => {
|
|
12
|
+
subscriberGuard?.close();
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/constants/index.ts
|
|
17
|
+
/**
|
|
18
|
+
* Runtime helper module ID
|
|
19
|
+
*/
|
|
20
|
+
const RUNTIME_MODULE_ID = "\0rolldown/runtime.js";
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/api/build.ts
|
|
23
|
+
/**
|
|
24
|
+
* The API similar to esbuild's `build` function.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```js
|
|
28
|
+
* import { build } from 'rolldown';
|
|
29
|
+
*
|
|
30
|
+
* const result = await build({
|
|
31
|
+
* input: 'src/main.js',
|
|
32
|
+
* output: {
|
|
33
|
+
* file: 'bundle.js',
|
|
34
|
+
* },
|
|
35
|
+
* });
|
|
36
|
+
* console.log(result);
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @experimental
|
|
40
|
+
* @category Programmatic APIs
|
|
41
|
+
*/
|
|
42
|
+
async function build(options) {
|
|
43
|
+
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
44
|
+
else {
|
|
45
|
+
const { output, write = true, ...inputOptions } = options;
|
|
46
|
+
const build = await rolldown(inputOptions);
|
|
47
|
+
try {
|
|
48
|
+
if (write) return await build.write(output);
|
|
49
|
+
else return await build.generate(output);
|
|
50
|
+
} finally {
|
|
51
|
+
await build.close();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { RUNTIME_MODULE_ID, RolldownMagicString, VERSION, build, defineConfig, rolldown, watch };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { n as __toESM, t as require_binding } from "./shared/binding-CtPG-2KR.mjs";
|
|
2
|
+
import { c as PluginContextData, n as bindingifyPlugin } from "./shared/bindingify-input-options-4JJxbZl2.mjs";
|
|
3
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
4
|
+
//#region src/parallel-plugin-worker.ts
|
|
5
|
+
var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
|
|
6
|
+
const { registryId, pluginInfos, threadNumber } = workerData;
|
|
7
|
+
(async () => {
|
|
8
|
+
try {
|
|
9
|
+
const plugins = await Promise.all(pluginInfos.map(async (pluginInfo) => {
|
|
10
|
+
const definePluginImpl = (await import(pluginInfo.fileUrl)).default;
|
|
11
|
+
const plugin = await definePluginImpl(pluginInfo.options, { threadNumber });
|
|
12
|
+
return {
|
|
13
|
+
index: pluginInfo.index,
|
|
14
|
+
plugin: bindingifyPlugin(plugin, {}, {}, new PluginContextData(() => {}, {}, [], []), [], () => {}, "info", false, void 0)
|
|
15
|
+
};
|
|
16
|
+
}));
|
|
17
|
+
(0, import_binding.registerPlugins)(registryId, plugins);
|
|
18
|
+
parentPort.postMessage({ type: "success" });
|
|
19
|
+
} catch (error) {
|
|
20
|
+
parentPort.postMessage({
|
|
21
|
+
type: "error",
|
|
22
|
+
error
|
|
23
|
+
});
|
|
24
|
+
} finally {
|
|
25
|
+
parentPort.unref();
|
|
26
|
+
}
|
|
27
|
+
})();
|
|
28
|
+
//#endregion
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { T as Plugin, Wt as MaybePromise } from "./shared/define-config-Nbz-lniw.mjs";
|
|
2
|
+
//#region src/plugin/parallel-plugin-implementation.d.ts
|
|
3
|
+
type ParallelPluginImplementation = Plugin;
|
|
4
|
+
type Context = {
|
|
5
|
+
/**
|
|
6
|
+
* Thread number
|
|
7
|
+
*/
|
|
8
|
+
threadNumber: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function defineParallelPluginImplementation<Options>(plugin: (Options: Options, context: Context) => MaybePromise<ParallelPluginImplementation>): (Options: Options, context: Context) => MaybePromise<ParallelPluginImplementation>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export type { Context, ParallelPluginImplementation };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { H as ParserOptions$1, V as ParseResult$1 } from "./shared/binding-Og__jmUi.mjs";
|
|
2
|
+
import { Program } from "@oxc-project/types";
|
|
3
|
+
//#region src/parse-ast-index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @hidden
|
|
6
|
+
*/
|
|
7
|
+
export type ParseResult = ParseResult$1;
|
|
8
|
+
/**
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export type ParserOptions = ParserOptions$1;
|
|
12
|
+
/**
|
|
13
|
+
* Parse code synchronously and return the AST.
|
|
14
|
+
*
|
|
15
|
+
* This function is similar to Rollup's `parseAst` function.
|
|
16
|
+
* Prefer using {@linkcode parseSync} instead of this function as it has more information in the return value.
|
|
17
|
+
*
|
|
18
|
+
* @category Utilities
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseAst(sourceText: string, options?: ParserOptions | null, filename?: string): Program;
|
|
21
|
+
/**
|
|
22
|
+
* Parse code asynchronously and return the AST.
|
|
23
|
+
*
|
|
24
|
+
* This function is similar to Rollup's `parseAstAsync` function.
|
|
25
|
+
* Prefer using {@linkcode parseAsync} instead of this function as it has more information in the return value.
|
|
26
|
+
*
|
|
27
|
+
* @category Utilities
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseAstAsync(sourceText: string, options?: ParserOptions | null, filename?: string): Promise<Program>;
|
|
30
|
+
//#endregion
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { c as logParseError, d as getCodeFrame, n as error, t as augmentCodeLocation, u as locate } from "./shared/logs-DmYCAKcW.mjs";
|
|
2
|
+
import { n as parseSync, t as parse } from "./shared/parse-D0g29RgN.mjs";
|
|
3
|
+
//#region src/parse-ast-index.ts
|
|
4
|
+
function wrap(result, filename, sourceText) {
|
|
5
|
+
if (result.errors.length > 0) return normalizeParseError(filename, sourceText, result.errors);
|
|
6
|
+
return result.program;
|
|
7
|
+
}
|
|
8
|
+
function normalizeParseError(filename, sourceText, errors) {
|
|
9
|
+
let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
10
|
+
const pos = errors[0]?.labels?.[0]?.start;
|
|
11
|
+
for (let i = 0; i < errors.length; i++) {
|
|
12
|
+
if (i >= 5) {
|
|
13
|
+
message += "\n...";
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
const e = errors[i];
|
|
17
|
+
message += e.message + "\n" + e.labels.map((label) => {
|
|
18
|
+
const location = locate(sourceText, label.start, { offsetLine: 1 });
|
|
19
|
+
if (!location) return;
|
|
20
|
+
return getCodeFrame(sourceText, location.line, location.column);
|
|
21
|
+
}).filter(Boolean).join("\n");
|
|
22
|
+
}
|
|
23
|
+
const log = logParseError(message, filename, pos);
|
|
24
|
+
if (pos !== void 0 && filename) augmentCodeLocation(log, pos, sourceText, filename);
|
|
25
|
+
return error(log);
|
|
26
|
+
}
|
|
27
|
+
const defaultParserOptions = {
|
|
28
|
+
lang: "js",
|
|
29
|
+
preserveParens: false
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Parse code synchronously and return the AST.
|
|
33
|
+
*
|
|
34
|
+
* This function is similar to Rollup's `parseAst` function.
|
|
35
|
+
* Prefer using {@linkcode parseSync} instead of this function as it has more information in the return value.
|
|
36
|
+
*
|
|
37
|
+
* @category Utilities
|
|
38
|
+
*/
|
|
39
|
+
function parseAst(sourceText, options, filename) {
|
|
40
|
+
return wrap(parseSync(filename ?? "file.js", sourceText, {
|
|
41
|
+
...defaultParserOptions,
|
|
42
|
+
...options
|
|
43
|
+
}), filename, sourceText);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parse code asynchronously and return the AST.
|
|
47
|
+
*
|
|
48
|
+
* This function is similar to Rollup's `parseAstAsync` function.
|
|
49
|
+
* Prefer using {@linkcode parseAsync} instead of this function as it has more information in the return value.
|
|
50
|
+
*
|
|
51
|
+
* @category Utilities
|
|
52
|
+
*/
|
|
53
|
+
async function parseAstAsync(sourceText, options, filename) {
|
|
54
|
+
return wrap(await parse(filename ?? "file.js", sourceText, {
|
|
55
|
+
...defaultParserOptions,
|
|
56
|
+
...options
|
|
57
|
+
}), filename, sourceText);
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { parseAst, parseAstAsync };
|