@rolldown/browser 1.0.0-beta.7-commit.a0a7d95 → 1.0.0-beta.7-commit.cef50bd

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/browser.js DELETED
@@ -1,4626 +0,0 @@
1
- import { BindingHookSideEffects, BindingLogLevel, BindingPluginOrder, BindingWatcher, Bundler, parseSync, shutdownAsyncRuntime, startAsyncRuntime } from "./rolldown-binding.wasi-browser.js";
2
-
3
- //#region rolldown:runtime
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __commonJS = (cb, mod) => function() {
11
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i$1 = 0, n$1 = keys.length, key; i$1 < n$1; i$1++) {
15
- key = keys[i$1];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k$1) => from[k$1]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
- value: mod,
25
- enumerable: true
26
- }) : target, mod));
27
-
28
- //#endregion
29
- //#region package.json
30
- var version = "1.0.0-beta.7-commit.a0a7d95";
31
-
32
- //#endregion
33
- //#region src/builtin-plugin/utils.ts
34
- function bindingifyBuiltInPlugin(plugin) {
35
- return {
36
- __name: plugin.name,
37
- options: plugin._options
38
- };
39
- }
40
-
41
- //#endregion
42
- //#region src/builtin-plugin/constructors.ts
43
- var BuiltinPlugin = class {
44
- constructor(name, _options) {
45
- this.name = name;
46
- this._options = _options;
47
- }
48
- };
49
-
50
- //#endregion
51
- //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
52
- let _lazyMatch = () => {
53
- var __lib__ = (() => {
54
- var m$1 = Object.defineProperty, V = Object.getOwnPropertyDescriptor, G = Object.getOwnPropertyNames, T$1 = Object.prototype.hasOwnProperty, q = (r$1, e$1) => {
55
- for (var n$1 in e$1) m$1(r$1, n$1, {
56
- get: e$1[n$1],
57
- enumerable: true
58
- });
59
- }, H = (r$1, e$1, n$1, a$1) => {
60
- if (e$1 && typeof e$1 == "object" || typeof e$1 == "function") for (let t$2 of G(e$1)) !T$1.call(r$1, t$2) && t$2 !== n$1 && m$1(r$1, t$2, {
61
- get: () => e$1[t$2],
62
- enumerable: !(a$1 = V(e$1, t$2)) || a$1.enumerable
63
- });
64
- return r$1;
65
- }, J = (r$1) => H(m$1({}, "__esModule", { value: true }), r$1), w$1 = {};
66
- q(w$1, { default: () => re });
67
- var A = (r$1) => Array.isArray(r$1), d$1 = (r$1) => typeof r$1 == "function", Q = (r$1) => r$1.length === 0, W = (r$1) => typeof r$1 == "number", K = (r$1) => typeof r$1 == "object" && r$1 !== null, X = (r$1) => r$1 instanceof RegExp, b$1 = (r$1) => typeof r$1 == "string", h$1 = (r$1) => r$1 === void 0, Y = (r$1) => {
68
- const e$1 = new Map();
69
- return (n$1) => {
70
- const a$1 = e$1.get(n$1);
71
- if (a$1) return a$1;
72
- const t$2 = r$1(n$1);
73
- return e$1.set(n$1, t$2), t$2;
74
- };
75
- }, rr = (r$1, e$1, n$1 = {}) => {
76
- const a$1 = {
77
- cache: {},
78
- input: r$1,
79
- index: 0,
80
- indexMax: 0,
81
- options: n$1,
82
- output: []
83
- };
84
- if (v$1(e$1)(a$1) && a$1.index === r$1.length) return a$1.output;
85
- throw new Error(`Failed to parse at index ${a$1.indexMax}`);
86
- }, i$1 = (r$1, e$1) => A(r$1) ? er(r$1, e$1) : b$1(r$1) ? ar(r$1, e$1) : nr(r$1, e$1), er = (r$1, e$1) => {
87
- const n$1 = {};
88
- for (const a$1 of r$1) {
89
- if (a$1.length !== 1) throw new Error(`Invalid character: "${a$1}"`);
90
- const t$2 = a$1.charCodeAt(0);
91
- n$1[t$2] = true;
92
- }
93
- return (a$1) => {
94
- const t$2 = a$1.index, o$1 = a$1.input;
95
- for (; a$1.index < o$1.length && o$1.charCodeAt(a$1.index) in n$1;) a$1.index += 1;
96
- const u$3 = a$1.index;
97
- if (u$3 > t$2) {
98
- if (!h$1(e$1) && !a$1.options.silent) {
99
- const s$1 = a$1.input.slice(t$2, u$3), c$1 = d$1(e$1) ? e$1(s$1, o$1, String(t$2)) : e$1;
100
- h$1(c$1) || a$1.output.push(c$1);
101
- }
102
- a$1.indexMax = Math.max(a$1.indexMax, a$1.index);
103
- }
104
- return true;
105
- };
106
- }, nr = (r$1, e$1) => {
107
- const n$1 = r$1.source, a$1 = r$1.flags.replace(/y|$/, "y"), t$2 = new RegExp(n$1, a$1);
108
- return g$1((o$1) => {
109
- t$2.lastIndex = o$1.index;
110
- const u$3 = t$2.exec(o$1.input);
111
- if (u$3) {
112
- if (!h$1(e$1) && !o$1.options.silent) {
113
- const s$1 = d$1(e$1) ? e$1(...u$3, o$1.input, String(o$1.index)) : e$1;
114
- h$1(s$1) || o$1.output.push(s$1);
115
- }
116
- return o$1.index += u$3[0].length, o$1.indexMax = Math.max(o$1.indexMax, o$1.index), true;
117
- } else return false;
118
- });
119
- }, ar = (r$1, e$1) => (n$1) => {
120
- if (n$1.input.startsWith(r$1, n$1.index)) {
121
- if (!h$1(e$1) && !n$1.options.silent) {
122
- const t$2 = d$1(e$1) ? e$1(r$1, n$1.input, String(n$1.index)) : e$1;
123
- h$1(t$2) || n$1.output.push(t$2);
124
- }
125
- return n$1.index += r$1.length, n$1.indexMax = Math.max(n$1.indexMax, n$1.index), true;
126
- } else return false;
127
- }, C$1 = (r$1, e$1, n$1, a$1) => {
128
- const t$2 = v$1(r$1);
129
- return g$1(_$1(M$1((o$1) => {
130
- let u$3 = 0;
131
- for (; u$3 < n$1;) {
132
- const s$1 = o$1.index;
133
- if (!t$2(o$1) || (u$3 += 1, o$1.index === s$1)) break;
134
- }
135
- return u$3 >= e$1;
136
- })));
137
- }, tr = (r$1, e$1) => C$1(r$1, 0, 1), f$1 = (r$1, e$1) => C$1(r$1, 0, Infinity), x$1 = (r$1, e$1) => {
138
- const n$1 = r$1.map(v$1);
139
- return g$1(_$1(M$1((a$1) => {
140
- for (let t$2 = 0, o$1 = n$1.length; t$2 < o$1; t$2++) if (!n$1[t$2](a$1)) return false;
141
- return true;
142
- })));
143
- }, l$1 = (r$1, e$1) => {
144
- const n$1 = r$1.map(v$1);
145
- return g$1(_$1((a$1) => {
146
- for (let t$2 = 0, o$1 = n$1.length; t$2 < o$1; t$2++) if (n$1[t$2](a$1)) return true;
147
- return false;
148
- }));
149
- }, M$1 = (r$1, e$1 = false) => {
150
- const n$1 = v$1(r$1);
151
- return (a$1) => {
152
- const t$2 = a$1.index, o$1 = a$1.output.length, u$3 = n$1(a$1);
153
- return (!u$3 || e$1) && (a$1.index = t$2, a$1.output.length !== o$1 && (a$1.output.length = o$1)), u$3;
154
- };
155
- }, _$1 = (r$1, e$1) => {
156
- const n$1 = v$1(r$1);
157
- return n$1;
158
- }, g$1 = (() => {
159
- let r$1 = 0;
160
- return (e$1) => {
161
- const n$1 = v$1(e$1), a$1 = r$1 += 1;
162
- return (t$2) => {
163
- var o$1;
164
- if (t$2.options.memoization === false) return n$1(t$2);
165
- const u$3 = t$2.index, s$1 = (o$1 = t$2.cache)[a$1] || (o$1[a$1] = new Map()), c$1 = s$1.get(u$3);
166
- if (c$1 === false) return false;
167
- if (W(c$1)) return t$2.index = c$1, true;
168
- if (c$1) return t$2.index = c$1.index, c$1.output?.length && t$2.output.push(...c$1.output), true;
169
- {
170
- const Z = t$2.output.length;
171
- if (n$1(t$2)) {
172
- const D = t$2.index, U = t$2.output.length;
173
- if (U > Z) {
174
- const ee = t$2.output.slice(Z, U);
175
- s$1.set(u$3, {
176
- index: D,
177
- output: ee
178
- });
179
- } else s$1.set(u$3, D);
180
- return true;
181
- } else return s$1.set(u$3, false), false;
182
- }
183
- };
184
- };
185
- })(), E$1 = (r$1) => {
186
- let e$1;
187
- return (n$1) => (e$1 || (e$1 = v$1(r$1())), e$1(n$1));
188
- }, v$1 = Y((r$1) => {
189
- if (d$1(r$1)) return Q(r$1) ? E$1(r$1) : r$1;
190
- if (b$1(r$1) || X(r$1)) return i$1(r$1);
191
- if (A(r$1)) return x$1(r$1);
192
- if (K(r$1)) return l$1(Object.values(r$1));
193
- throw new Error("Invalid rule");
194
- }), P = "abcdefghijklmnopqrstuvwxyz", ir = (r$1) => {
195
- let e$1 = "";
196
- for (; r$1 > 0;) {
197
- const n$1 = (r$1 - 1) % 26;
198
- e$1 = P[n$1] + e$1, r$1 = Math.floor((r$1 - 1) / 26);
199
- }
200
- return e$1;
201
- }, O$1 = (r$1) => {
202
- let e$1 = 0;
203
- for (let n$1 = 0, a$1 = r$1.length; n$1 < a$1; n$1++) e$1 = e$1 * 26 + P.indexOf(r$1[n$1]) + 1;
204
- return e$1;
205
- }, S = (r$1, e$1) => {
206
- if (e$1 < r$1) return S(e$1, r$1);
207
- const n$1 = [];
208
- for (; r$1 <= e$1;) n$1.push(r$1++);
209
- return n$1;
210
- }, or = (r$1, e$1, n$1) => S(r$1, e$1).map((a$1) => String(a$1).padStart(n$1, "0")), R$1 = (r$1, e$1) => S(O$1(r$1), O$1(e$1)).map(ir), p$1 = (r$1) => r$1, z = (r$1) => ur((e$1) => rr(e$1, r$1, { memoization: false }).join("")), ur = (r$1) => {
211
- const e$1 = {};
212
- return (n$1) => e$1[n$1] ?? (e$1[n$1] = r$1(n$1));
213
- }, sr = i$1(/^\*\*\/\*$/, ".*"), cr = i$1(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/, (r$1, e$1, n$1) => `.*${e$1 ? "" : "(?:^|/)"}${n$1.replaceAll(".", "\\.")}`), lr = i$1(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/, (r$1, e$1, n$1, a$1) => `.*${e$1 ? "" : "(?:^|/)"}${n$1.replaceAll(".", "\\.")}(?:${a$1.replaceAll(",", "|").replaceAll(".", "\\.")})`), y$1 = i$1(/\\./, p$1), pr = i$1(/[$.*+?^(){}[\]\|]/, (r$1) => `\\${r$1}`), vr = i$1(/./, p$1), hr = i$1(/^(?:!!)*!(.*)$/, (r$1, e$1) => `(?!^${L(e$1)}$).*?`), dr = i$1(/^(!!)+/, ""), fr = l$1([hr, dr]), xr = i$1(/\/(\*\*\/)+/, "(?:/.+/|/)"), gr = i$1(/^(\*\*\/)+/, "(?:^|.*/)"), mr = i$1(/\/(\*\*)$/, "(?:/.*|$)"), _r = i$1(/\*\*/, ".*"), j = l$1([
214
- xr,
215
- gr,
216
- mr,
217
- _r
218
- ]), Sr = i$1(/\*\/(?!\*\*\/)/, "[^/]*/"), yr = i$1(/\*/, "[^/]*"), N = l$1([Sr, yr]), k$1 = i$1("?", "[^/]"), $r = i$1("[", p$1), wr = i$1("]", p$1), Ar = i$1(/[!^]/, "^/"), br = i$1(/[a-z]-[a-z]|[0-9]-[0-9]/i, p$1), Cr = i$1(/[$.*+?^(){}[\|]/, (r$1) => `\\${r$1}`), Mr = i$1(/[^\]]/, p$1), Er = l$1([
219
- y$1,
220
- Cr,
221
- br,
222
- Mr
223
- ]), B = x$1([
224
- $r,
225
- tr(Ar),
226
- f$1(Er),
227
- wr
228
- ]), Pr = i$1("{", "(?:"), Or = i$1("}", ")"), Rr = i$1(/(\d+)\.\.(\d+)/, (r$1, e$1, n$1) => or(+e$1, +n$1, Math.min(e$1.length, n$1.length)).join("|")), zr = i$1(/([a-z]+)\.\.([a-z]+)/, (r$1, e$1, n$1) => R$1(e$1, n$1).join("|")), jr = i$1(/([A-Z]+)\.\.([A-Z]+)/, (r$1, e$1, n$1) => R$1(e$1.toLowerCase(), n$1.toLowerCase()).join("|").toUpperCase()), Nr = l$1([
229
- Rr,
230
- zr,
231
- jr
232
- ]), I$1 = x$1([
233
- Pr,
234
- Nr,
235
- Or
236
- ]), kr = i$1("{", "(?:"), Br = i$1("}", ")"), Ir = i$1(",", "|"), Fr = i$1(/[$.*+?^(){[\]\|]/, (r$1) => `\\${r$1}`), Lr = i$1(/[^}]/, p$1), Zr = E$1(() => F), Dr = l$1([
237
- j,
238
- N,
239
- k$1,
240
- B,
241
- I$1,
242
- Zr,
243
- y$1,
244
- Fr,
245
- Ir,
246
- Lr
247
- ]), F = x$1([
248
- kr,
249
- f$1(Dr),
250
- Br
251
- ]), Ur = f$1(l$1([
252
- sr,
253
- cr,
254
- lr,
255
- fr,
256
- j,
257
- N,
258
- k$1,
259
- B,
260
- I$1,
261
- F,
262
- y$1,
263
- pr,
264
- vr
265
- ])), Vr = Ur, Gr = z(Vr), L = Gr, Tr = i$1(/\\./, p$1), qr = i$1(/./, p$1), Hr = i$1(/\*\*\*+/, "*"), Jr = i$1(/([^/{[(!])\*\*/, (r$1, e$1) => `${e$1}*`), Qr = i$1(/(^|.)\*\*(?=[^*/)\]}])/, (r$1, e$1) => `${e$1}*`), Wr = f$1(l$1([
266
- Tr,
267
- Hr,
268
- Jr,
269
- Qr,
270
- qr
271
- ])), Kr = Wr, Xr = z(Kr), Yr = Xr, $$1 = (r$1, e$1) => {
272
- const n$1 = Array.isArray(r$1) ? r$1 : [r$1];
273
- if (!n$1.length) return false;
274
- const a$1 = n$1.map($$1.compile), t$2 = n$1.every((s$1) => /(\/(?:\*\*)?|\[\/\])$/.test(s$1)), o$1 = e$1.replace(/[\\\/]+/g, "/").replace(/\/$/, t$2 ? "/" : "");
275
- return a$1.some((s$1) => s$1.test(o$1));
276
- };
277
- $$1.compile = (r$1) => new RegExp(`^${L(Yr(r$1))}$`, "s");
278
- var re = $$1;
279
- return J(w$1);
280
- })();
281
- return __lib__.default || __lib__;
282
- };
283
- let _match;
284
- const zeptomatch = (path, pattern) => {
285
- if (!_match) {
286
- _match = _lazyMatch();
287
- _lazyMatch = null;
288
- }
289
- return _match(path, pattern);
290
- };
291
- const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
292
- function normalizeWindowsPath(input = "") {
293
- if (!input) return input;
294
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r$1) => r$1.toUpperCase());
295
- }
296
- const _UNC_REGEX = /^[/\\]{2}/;
297
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
298
- const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
299
- const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
300
- const _EXTNAME_RE = /.(\.[^./]+|\.)$/;
301
- const _PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/;
302
- const sep = "/";
303
- const normalize = function(path) {
304
- if (path.length === 0) return ".";
305
- path = normalizeWindowsPath(path);
306
- const isUNCPath = path.match(_UNC_REGEX);
307
- const isPathAbsolute = isAbsolute(path);
308
- const trailingSeparator = path[path.length - 1] === "/";
309
- path = normalizeString(path, !isPathAbsolute);
310
- if (path.length === 0) {
311
- if (isPathAbsolute) return "/";
312
- return trailingSeparator ? "./" : ".";
313
- }
314
- if (trailingSeparator) path += "/";
315
- if (_DRIVE_LETTER_RE.test(path)) path += "/";
316
- if (isUNCPath) {
317
- if (!isPathAbsolute) return `//./${path}`;
318
- return `//${path}`;
319
- }
320
- return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
321
- };
322
- const join = function(...segments) {
323
- let path = "";
324
- for (const seg of segments) {
325
- if (!seg) continue;
326
- if (path.length > 0) {
327
- const pathTrailing = path[path.length - 1] === "/";
328
- const segLeading = seg[0] === "/";
329
- const both = pathTrailing && segLeading;
330
- if (both) path += seg.slice(1);
331
- else path += pathTrailing || segLeading ? seg : `/${seg}`;
332
- } else path += seg;
333
- }
334
- return normalize(path);
335
- };
336
- function cwd() {
337
- if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
338
- return "/";
339
- }
340
- const resolve = function(...arguments_) {
341
- arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
342
- let resolvedPath = "";
343
- let resolvedAbsolute = false;
344
- for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
345
- const path = index >= 0 ? arguments_[index] : cwd();
346
- if (!path || path.length === 0) continue;
347
- resolvedPath = `${path}/${resolvedPath}`;
348
- resolvedAbsolute = isAbsolute(path);
349
- }
350
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
351
- if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
352
- return resolvedPath.length > 0 ? resolvedPath : ".";
353
- };
354
- function normalizeString(path, allowAboveRoot) {
355
- let res = "";
356
- let lastSegmentLength = 0;
357
- let lastSlash = -1;
358
- let dots = 0;
359
- let char = null;
360
- for (let index = 0; index <= path.length; ++index) {
361
- if (index < path.length) char = path[index];
362
- else if (char === "/") break;
363
- else char = "/";
364
- if (char === "/") {
365
- if (lastSlash === index - 1 || dots === 1);
366
- else if (dots === 2) {
367
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
368
- if (res.length > 2) {
369
- const lastSlashIndex = res.lastIndexOf("/");
370
- if (lastSlashIndex === -1) {
371
- res = "";
372
- lastSegmentLength = 0;
373
- } else {
374
- res = res.slice(0, lastSlashIndex);
375
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
376
- }
377
- lastSlash = index;
378
- dots = 0;
379
- continue;
380
- } else if (res.length > 0) {
381
- res = "";
382
- lastSegmentLength = 0;
383
- lastSlash = index;
384
- dots = 0;
385
- continue;
386
- }
387
- }
388
- if (allowAboveRoot) {
389
- res += res.length > 0 ? "/.." : "..";
390
- lastSegmentLength = 2;
391
- }
392
- } else {
393
- if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
394
- else res = path.slice(lastSlash + 1, index);
395
- lastSegmentLength = index - lastSlash - 1;
396
- }
397
- lastSlash = index;
398
- dots = 0;
399
- } else if (char === "." && dots !== -1) ++dots;
400
- else dots = -1;
401
- }
402
- return res;
403
- }
404
- const isAbsolute = function(p$1) {
405
- return _IS_ABSOLUTE_RE.test(p$1);
406
- };
407
- const toNamespacedPath = function(p$1) {
408
- return normalizeWindowsPath(p$1);
409
- };
410
- const extname = function(p$1) {
411
- if (p$1 === "..") return "";
412
- const match = _EXTNAME_RE.exec(normalizeWindowsPath(p$1));
413
- return match && match[1] || "";
414
- };
415
- const relative = function(from, to) {
416
- const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
417
- const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
418
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
419
- const _fromCopy = [..._from];
420
- for (const segment of _fromCopy) {
421
- if (_to[0] !== segment) break;
422
- _from.shift();
423
- _to.shift();
424
- }
425
- return [..._from.map(() => ".."), ..._to].join("/");
426
- };
427
- const dirname = function(p$1) {
428
- const segments = normalizeWindowsPath(p$1).replace(/\/$/, "").split("/").slice(0, -1);
429
- if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
430
- return segments.join("/") || (isAbsolute(p$1) ? "/" : ".");
431
- };
432
- const format = function(p$1) {
433
- const ext = p$1.ext ? p$1.ext.startsWith(".") ? p$1.ext : `.${p$1.ext}` : "";
434
- const segments = [
435
- p$1.root,
436
- p$1.dir,
437
- p$1.base ?? (p$1.name ?? "") + ext
438
- ].filter(Boolean);
439
- return normalizeWindowsPath(p$1.root ? resolve(...segments) : segments.join("/"));
440
- };
441
- const basename = function(p$1, extension) {
442
- const segments = normalizeWindowsPath(p$1).split("/");
443
- let lastSegment = "";
444
- for (let i$1 = segments.length - 1; i$1 >= 0; i$1--) {
445
- const val = segments[i$1];
446
- if (val) {
447
- lastSegment = val;
448
- break;
449
- }
450
- }
451
- return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
452
- };
453
- const parse = function(p$1) {
454
- const root = _PATH_ROOT_RE.exec(p$1)?.[0]?.replace(/\\/g, "/") || "";
455
- const base = basename(p$1);
456
- const extension = extname(base);
457
- return {
458
- root,
459
- dir: dirname(p$1),
460
- base,
461
- ext: extension,
462
- name: base.slice(0, base.length - extension.length)
463
- };
464
- };
465
- const matchesGlob = (path, pattern) => {
466
- return zeptomatch(pattern, normalize(path));
467
- };
468
- const _path = {
469
- __proto__: null,
470
- basename,
471
- dirname,
472
- extname,
473
- format,
474
- isAbsolute,
475
- join,
476
- matchesGlob,
477
- normalize,
478
- normalizeString,
479
- parse,
480
- relative,
481
- resolve,
482
- sep,
483
- toNamespacedPath
484
- };
485
-
486
- //#endregion
487
- //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs
488
- const delimiter = /* @__PURE__ */ (() => globalThis.process?.platform === "win32" ? ";" : ":")();
489
- const _platforms = {
490
- posix: void 0,
491
- win32: void 0
492
- };
493
- const mix = (del = delimiter) => {
494
- return new Proxy(_path, { get(_$1, prop) {
495
- if (prop === "delimiter") return del;
496
- if (prop === "posix") return posix;
497
- if (prop === "win32") return win32;
498
- return _platforms[prop] || _path[prop];
499
- } });
500
- };
501
- const posix = /* @__PURE__ */ mix(":");
502
- const win32 = /* @__PURE__ */ mix(";");
503
-
504
- //#endregion
505
- //#region src/utils/misc.ts
506
- function arraify(value) {
507
- return Array.isArray(value) ? value : [value];
508
- }
509
- function isNullish(value) {
510
- return value === null || value === void 0;
511
- }
512
- function isPromiseLike(value) {
513
- return value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
514
- }
515
- function unimplemented(info) {
516
- if (info) throw new Error(`unimplemented: ${info}`);
517
- throw new Error("unimplemented");
518
- }
519
- function unreachable(info) {
520
- if (info) throw new Error(`unreachable: ${info}`);
521
- throw new Error("unreachable");
522
- }
523
- function unsupported(info) {
524
- throw new Error(`UNSUPPORTED: ${info}`);
525
- }
526
- function noop(..._args) {}
527
-
528
- //#endregion
529
- //#region src/log/logging.ts
530
- const LOG_LEVEL_SILENT = "silent";
531
- const LOG_LEVEL_ERROR = "error";
532
- const LOG_LEVEL_WARN = "warn";
533
- const LOG_LEVEL_INFO = "info";
534
- const LOG_LEVEL_DEBUG = "debug";
535
- const logLevelPriority = {
536
- [LOG_LEVEL_DEBUG]: 0,
537
- [LOG_LEVEL_INFO]: 1,
538
- [LOG_LEVEL_WARN]: 2,
539
- [LOG_LEVEL_SILENT]: 3
540
- };
541
-
542
- //#endregion
543
- //#region ../../node_modules/.pnpm/ansis@3.17.0/node_modules/ansis/index.js
544
- var require_ansis = __commonJS({ "../../node_modules/.pnpm/ansis@3.17.0/node_modules/ansis/index.js"(exports, module) {
545
- let { defineProperty: e, setPrototypeOf: t$1, create: r, keys: n } = Object, l = "", { round: s, max: i } = Math, o = (e$1) => {
546
- let [, t$2] = /([a-f\d]{3,6})/i.exec(e$1) || [], r$1 = t$2 ? t$2.length : 0;
547
- if (3 === r$1) t$2 = t$2[0] + t$2[0] + t$2[1] + t$2[1] + t$2[2] + t$2[2];
548
- else if (6 ^ r$1) return [
549
- 0,
550
- 0,
551
- 0
552
- ];
553
- let n$1 = parseInt(t$2, 16);
554
- return [
555
- n$1 >> 16 & 255,
556
- n$1 >> 8 & 255,
557
- 255 & n$1
558
- ];
559
- }, a = (e$1, t$2, r$1) => e$1 === t$2 && t$2 === r$1 ? e$1 < 8 ? 16 : e$1 > 248 ? 231 : s((e$1 - 8) / 247 * 24) + 232 : 16 + 36 * s(e$1 / 51) + 6 * s(t$2 / 51) + s(r$1 / 51), c = (e$1) => {
560
- let t$2, r$1, n$1, l$1, o$1;
561
- return e$1 < 8 ? 30 + e$1 : e$1 < 16 ? e$1 - 8 + 90 : (e$1 >= 232 ? t$2 = r$1 = n$1 = (10 * (e$1 - 232) + 8) / 255 : (o$1 = (e$1 -= 16) % 36, t$2 = (e$1 / 36 | 0) / 5, r$1 = (o$1 / 6 | 0) / 5, n$1 = o$1 % 6 / 5), l$1 = 2 * i(t$2, r$1, n$1), l$1 ? 30 + (s(n$1) << 2 | s(r$1) << 1 | s(t$2)) + (2 ^ l$1 ? 0 : 60) : 30);
562
- }, u$2 = (() => {
563
- let e$1 = (e$2) => i$1.some((t$3) => e$2.test(t$3)), t$2 = globalThis, r$1 = t$2.Deno, l$1 = !!r$1, s$1 = t$2.process || r$1 || {}, i$1 = s$1.argv || s$1.args || [], o$1 = s$1.env || {}, a$1 = -1;
564
- if (l$1) try {
565
- o$1 = o$1.toObject();
566
- } catch (e$2) {
567
- a$1 = 0;
568
- }
569
- let c$1 = !!o$1.PM2_HOME && !!o$1.pm_id || o$1.NEXT_RUNTIME?.includes("edge") || (l$1 ? r$1.isatty(1) : !!s$1.stdout?.isTTY), u$3 = "FORCE_COLOR", p$1 = o$1[u$3], g$1 = parseInt(p$1), d$1 = isNaN(g$1) ? "false" === p$1 ? 0 : -1 : g$1, f$1 = u$3 in o$1 && d$1 || e$1(/^-{1,2}color=?(true|always)?$/);
570
- return f$1 && (a$1 = d$1), a$1 < 0 && (a$1 = ((e$2, t$3, r$2) => {
571
- let l$2 = e$2.TERM, s$2 = "," + n(e$2).join(",");
572
- return {
573
- "24bit": 3,
574
- truecolor: 3,
575
- ansi256: 2,
576
- ansi: 1
577
- }[e$2.COLORTERM] || (e$2.TF_BUILD ? 1 : /,TEAMCI/.test(s$2) ? 2 : e$2.CI ? /,GIT(HUB|EA)/.test(s$2) ? 3 : 1 : !t$3 || /-mono|dumb/i.test(l$2) ? 0 : r$2 || /term-(kit|dir)/.test(l$2) ? 3 : /-256/.test(l$2) ? 2 : /scr|xterm|tty|ansi|color|[nm]ux|vt|cyg/.test(l$2) ? 1 : 3);
578
- })(o$1, c$1, "win32" === (l$1 ? r$1.build.os : s$1.platform))), !d$1 || o$1.NO_COLOR || e$1(/^-{1,2}(no-color|color=(false|never))$/) ? 0 : f$1 && !a$1 || t$2.window?.chrome ? 3 : a$1;
579
- })(), p = u$2 > 0, g = {
580
- open: l,
581
- close: l
582
- }, d = p ? (e$1, t$2) => ({
583
- open: `[${e$1}m`,
584
- close: `[${t$2}m`
585
- }) : () => g, f = 39, b = 49, _ = (e$1, t$2) => (r$1, n$1, l$1) => d(((e$2, t$3, r$2) => c(a(e$2, t$3, r$2)))(r$1, n$1, l$1) + e$1, t$2), m = (e$1) => (t$2, r$1, n$1) => e$1(a(t$2, r$1, n$1)), y = (e$1) => (t$2) => e$1(...o(t$2)), h = (e$1, t$2, r$1) => d(`38;2;${e$1};${t$2};${r$1}`, f), O = (e$1, t$2, r$1) => d(`48;2;${e$1};${t$2};${r$1}`, b), $ = (e$1) => d(`38;5;${e$1}`, f), x = (e$1) => d(`48;5;${e$1}`, b);
586
- 2 === u$2 ? (h = m($), O = m(x)) : 1 === u$2 && (h = _(0, f), O = _(10, b), $ = (e$1) => d(c(e$1), f), x = (e$1) => d(c(e$1) + 10, b));
587
- let T, w = {
588
- ansi256: $,
589
- bgAnsi256: x,
590
- fg: $,
591
- bg: x,
592
- rgb: h,
593
- bgRgb: O,
594
- hex: y(h),
595
- bgHex: y(O),
596
- visible: g,
597
- reset: d(0, 0),
598
- bold: d(1, 22),
599
- dim: d(2, 22),
600
- italic: d(3, 23),
601
- underline: d(4, 24),
602
- inverse: d(7, 27),
603
- hidden: d(8, 28)
604
- }, R = "Bright", E = 30;
605
- "black,red,green,yellow,blue,magenta,cyan,white".split(",").map((e$1) => {
606
- T = "bg" + e$1[0].toUpperCase() + e$1.slice(1), w[e$1] = d(E, f), w[e$1 + R] = d(60 + E, f), w[T] = d(E + 10, b), w[T + R] = d(70 + E++, b);
607
- }), w.grey = w.gray = d(90, f), w.bgGrey = w.bgGray = d(100, b), w.strikethrough = w.strike = d(9, 29);
608
- let v, C = {}, I = ({ _p: e$1 }, { open: r$1, close: n$1 }) => {
609
- let s$1 = (e$2, ...t$2) => {
610
- if (!e$2) {
611
- if (r$1 && r$1 === n$1) return r$1;
612
- if (null == e$2 || l === e$2) return l;
613
- }
614
- let i$2 = e$2.raw ? String.raw(e$2, ...t$2).replace(/\\n/g, "\n") : l + e$2, o$2 = s$1._p, { _a: a$1, _b: c$1 } = o$2;
615
- if (i$2.includes("\x1B")) for (; o$2;) {
616
- let e$3, t$3 = o$2.close, r$2 = o$2.open, n$2 = t$3.length, s$2 = l, a$2 = 0;
617
- if (n$2) {
618
- for (; ~(e$3 = i$2.indexOf(t$3, a$2)); a$2 = e$3 + n$2) s$2 += i$2.slice(a$2, e$3) + r$2;
619
- i$2 = s$2 + i$2.slice(a$2);
620
- }
621
- o$2 = o$2._p;
622
- }
623
- return i$2.includes("\n") && (i$2 = i$2.replace(/(\r?\n)/g, c$1 + "$1" + a$1)), a$1 + i$2 + c$1;
624
- }, i$1 = r$1, o$1 = n$1;
625
- return e$1 && (i$1 = e$1._a + r$1, o$1 = n$1 + e$1._b), t$1(s$1, v), s$1._p = {
626
- open: r$1,
627
- close: n$1,
628
- _a: i$1,
629
- _b: o$1,
630
- _p: e$1
631
- }, s$1.open = i$1, s$1.close = o$1, s$1;
632
- };
633
- const M = function() {
634
- let n$1 = {
635
- Ansis: M,
636
- isSupported: () => p,
637
- strip: (e$1) => e$1.replace(/[›][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, l),
638
- extend(l$1) {
639
- for (let t$2 in l$1) {
640
- let r$1 = l$1[t$2], n$2 = (typeof r$1)[0], s$1 = "s" === n$2 ? h(...o(r$1)) : r$1;
641
- C[t$2] = "f" === n$2 ? { get() {
642
- return (...e$1) => I(this, r$1(...e$1));
643
- } } : { get() {
644
- let r$2 = I(this, s$1);
645
- return e(this, t$2, { value: r$2 }), r$2;
646
- } };
647
- }
648
- return v = r({}, C), t$1(n$1, v), n$1;
649
- }
650
- };
651
- return n$1.extend(w);
652
- }, k = new M();
653
- module.exports = k, k.default = k;
654
- } });
655
- var import_ansis = __toESM(require_ansis(), 1);
656
-
657
- //#endregion
658
- //#region ../../node_modules/.pnpm/ansis@3.17.0/node_modules/ansis/index.mjs
659
- var ansis_default = import_ansis.default;
660
- const { Ansis, ansi256, fg, bgAnsi256, bg, rgb, bgRgb, hex, bgHex, reset, inverse, hidden, visible, bold, dim, italic, underline, strikethrough, strike, black, red, green, yellow, blue, magenta, cyan, white, grey, gray, blackBright, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGrey, bgGray, bgBlackBright, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = import_ansis.default;
661
-
662
- //#endregion
663
- //#region src/utils/code-frame.ts
664
- function spaces(index) {
665
- let result = "";
666
- while (index--) result += " ";
667
- return result;
668
- }
669
- function tabsToSpaces(value) {
670
- return value.replace(/^\t+/, (match) => match.split(" ").join(" "));
671
- }
672
- const LINE_TRUNCATE_LENGTH = 120;
673
- const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
674
- const ELLIPSIS = "...";
675
- function getCodeFrame(source, line, column) {
676
- let lines = source.split("\n");
677
- if (line > lines.length) return "";
678
- const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
679
- const frameStart = Math.max(0, line - 3);
680
- let frameEnd = Math.min(line + 2, lines.length);
681
- lines = lines.slice(frameStart, frameEnd);
682
- while (!/\S/.test(lines[lines.length - 1])) {
683
- lines.pop();
684
- frameEnd -= 1;
685
- }
686
- const digits = String(frameEnd).length;
687
- return lines.map((sourceLine, index) => {
688
- const isErrorLine = frameStart + index + 1 === line;
689
- let lineNumber = String(index + frameStart + 1);
690
- while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
691
- let displayedLine = tabsToSpaces(sourceLine);
692
- if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
693
- if (isErrorLine) {
694
- const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
695
- return `${lineNumber}: ${displayedLine}\n${indicator}`;
696
- }
697
- return `${lineNumber}: ${displayedLine}`;
698
- }).join("\n");
699
- }
700
-
701
- //#endregion
702
- //#region src/log/locate-character/index.js
703
- /** @typedef {import('./types').Location} Location */
704
- /**
705
- * @param {import('./types').Range} range
706
- * @param {number} index
707
- */
708
- function rangeContains(range, index) {
709
- return range.start <= index && index < range.end;
710
- }
711
- function getLocator(source, options = {}) {
712
- const { offsetLine = 0, offsetColumn = 0 } = options;
713
- let start = 0;
714
- const ranges = source.split("\n").map((line, i$2) => {
715
- const end = start + line.length + 1;
716
- /** @type {import('./types').Range} */
717
- const range = {
718
- start,
719
- end,
720
- line: i$2
721
- };
722
- start = end;
723
- return range;
724
- });
725
- let i$1 = 0;
726
- /**
727
- * @param {string | number} search
728
- * @param {number} [index]
729
- * @returns {Location | undefined}
730
- */
731
- function locator(search, index) {
732
- if (typeof search === "string") search = source.indexOf(search, index ?? 0);
733
- if (search === -1) return void 0;
734
- let range = ranges[i$1];
735
- const d$1 = search >= range.end ? 1 : -1;
736
- while (range) {
737
- if (rangeContains(range, search)) return {
738
- line: offsetLine + range.line,
739
- column: offsetColumn + search - range.start,
740
- character: search
741
- };
742
- i$1 += d$1;
743
- range = ranges[i$1];
744
- }
745
- }
746
- return locator;
747
- }
748
- function locate(source, search, options) {
749
- return getLocator(source, options)(search, options && options.startIndex);
750
- }
751
-
752
- //#endregion
753
- //#region src/log/logs.ts
754
- const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING", MULTIPLY_NOTIFY_OPTION = "MULTIPLY_NOTIFY_OPTION", MINIFY_WARNING = "MINIFY_WARNING", PARSE_ERROR = "PARSE_ERROR";
755
- function logParseError(message) {
756
- return {
757
- code: PARSE_ERROR,
758
- message
759
- };
760
- }
761
- function logMinifyWarning() {
762
- return {
763
- code: MINIFY_WARNING,
764
- message: ansis_default.yellow("The built-in minifier is still under development. Setting \"minify: true\" is not recommended for production use.")
765
- };
766
- }
767
- function logInvalidLogPosition(pluginName) {
768
- return {
769
- code: INVALID_LOG_POSITION,
770
- message: `Plugin "${pluginName}" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.`
771
- };
772
- }
773
- function logInputHookInOutputPlugin(pluginName, hookName) {
774
- return {
775
- code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
776
- message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.`
777
- };
778
- }
779
- function logCycleLoading(pluginName, moduleId) {
780
- return {
781
- code: CYCLE_LOADING,
782
- message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
783
- };
784
- }
785
- function logMultiplyNotifyOption() {
786
- return {
787
- code: MULTIPLY_NOTIFY_OPTION,
788
- message: `Found multiply notify option at watch options, using first one to start notify watcher.`
789
- };
790
- }
791
- function logPluginError(error$1, plugin, { hook, id } = {}) {
792
- const code = error$1.code;
793
- if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
794
- error$1.code = PLUGIN_ERROR;
795
- error$1.plugin = plugin;
796
- if (hook) error$1.hook = hook;
797
- if (id) error$1.id = id;
798
- return error$1;
799
- }
800
- function error(base) {
801
- if (!(base instanceof Error)) {
802
- base = Object.assign(new Error(base.message), base);
803
- Object.defineProperty(base, "name", {
804
- value: "RollupError",
805
- writable: true
806
- });
807
- }
808
- throw base;
809
- }
810
- function augmentCodeLocation(properties, pos, source, id) {
811
- if (typeof pos === "object") {
812
- const { line, column } = pos;
813
- properties.loc = {
814
- column,
815
- file: id,
816
- line
817
- };
818
- } else {
819
- properties.pos = pos;
820
- const location = locate(source, pos, { offsetLine: 1 });
821
- if (!location) return;
822
- const { line, column } = location;
823
- properties.loc = {
824
- column,
825
- file: id,
826
- line
827
- };
828
- }
829
- if (properties.frame === void 0) {
830
- const { line, column } = properties.loc;
831
- properties.frame = getCodeFrame(source, line, column);
832
- }
833
- }
834
-
835
- //#endregion
836
- //#region src/log/log-handler.ts
837
- const normalizeLog = (log) => typeof log === "string" ? { message: log } : typeof log === "function" ? normalizeLog(log()) : log;
838
- function getLogHandler(level, code, logger, pluginName, logLevel) {
839
- if (logLevelPriority[level] < logLevelPriority[logLevel]) return noop;
840
- return (log, pos) => {
841
- if (pos != null) logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
842
- log = normalizeLog(log);
843
- if (log.code && !log.pluginCode) log.pluginCode = log.code;
844
- log.code = code;
845
- log.plugin = pluginName;
846
- logger(level, log);
847
- };
848
- }
849
-
850
- //#endregion
851
- //#region src/log/logger.ts
852
- function getLogger(plugins, onLog, logLevel, watchMode) {
853
- const minimalPriority = logLevelPriority[logLevel];
854
- const logger = (level, log, skipped = new Set()) => {
855
- const logPriority = logLevelPriority[level];
856
- if (logPriority < minimalPriority) return;
857
- for (const plugin of getSortedPlugins("onLog", plugins)) {
858
- if (skipped.has(plugin)) continue;
859
- const { onLog: pluginOnLog } = plugin;
860
- if (pluginOnLog) {
861
- const getLogHandler$1 = (level$1) => {
862
- if (logLevelPriority[level$1] < minimalPriority) return () => {};
863
- return (log$1) => logger(level$1, normalizeLog(log$1), new Set(skipped).add(plugin));
864
- };
865
- const handler = "handler" in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
866
- if (handler.call({
867
- debug: getLogHandler$1(LOG_LEVEL_DEBUG),
868
- error: (log$1) => error(normalizeLog(log$1)),
869
- info: getLogHandler$1(LOG_LEVEL_INFO),
870
- meta: {
871
- rollupVersion: "4.23.0",
872
- rolldownVersion: VERSION,
873
- watchMode
874
- },
875
- warn: getLogHandler$1(LOG_LEVEL_WARN),
876
- pluginName: plugin.name || "unknown"
877
- }, level, log) === false) return;
878
- }
879
- }
880
- onLog(level, log);
881
- };
882
- return logger;
883
- }
884
- const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
885
- const { onwarn, onLog } = config;
886
- const defaultOnLog = getDefaultOnLog(printLog, onwarn);
887
- if (onLog) {
888
- const minimalPriority = logLevelPriority[logLevel];
889
- return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => {
890
- if (level$1 === LOG_LEVEL_ERROR) return error(normalizeLog(handledLog));
891
- if (logLevelPriority[level$1] >= minimalPriority) defaultOnLog(level$1, normalizeLog(handledLog));
892
- });
893
- }
894
- return defaultOnLog;
895
- };
896
- const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
897
- if (level === LOG_LEVEL_WARN) onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
898
- else printLog(level, log);
899
- } : printLog;
900
- const addLogToString = (log) => {
901
- Object.defineProperty(log, "toString", {
902
- value: () => getExtendedLogMessage(log),
903
- writable: true
904
- });
905
- return log;
906
- };
907
- const defaultPrintLog = (level, log) => {
908
- const message = getExtendedLogMessage(log);
909
- switch (level) {
910
- case LOG_LEVEL_WARN: return console.warn(message);
911
- case LOG_LEVEL_DEBUG: return console.debug(message);
912
- default: return console.info(message);
913
- }
914
- };
915
- const getExtendedLogMessage = (log) => {
916
- let prefix = "";
917
- if (log.plugin) prefix += `(${log.plugin} plugin) `;
918
- if (log.loc) prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
919
- return prefix + log.message;
920
- };
921
- function relativeId(id) {
922
- if (!posix.isAbsolute(id)) return id;
923
- return posix.relative(posix.resolve(), id);
924
- }
925
-
926
- //#endregion
927
- //#region src/utils/normalize-hook.ts
928
- function normalizeHook(hook) {
929
- if (typeof hook === "function" || typeof hook === "string") return {
930
- handler: hook,
931
- options: {},
932
- meta: {}
933
- };
934
- if (typeof hook === "object" && hook !== null) {
935
- const { handler, order,...options } = hook;
936
- return {
937
- handler,
938
- options,
939
- meta: { order }
940
- };
941
- }
942
- unreachable("Invalid hook type");
943
- }
944
-
945
- //#endregion
946
- //#region src/constants/plugin.ts
947
- const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES = [
948
- "options",
949
- "buildStart",
950
- "resolveId",
951
- "load",
952
- "transform",
953
- "moduleParsed",
954
- "buildEnd",
955
- "onLog",
956
- "resolveDynamicImport",
957
- "closeBundle",
958
- "closeWatcher",
959
- "watchChange"
960
- ];
961
- const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES = [
962
- "augmentChunkHash",
963
- "outputOptions",
964
- "renderChunk",
965
- "renderStart",
966
- "renderError",
967
- "writeBundle",
968
- "generateBundle"
969
- ];
970
- const ENUMERATED_PLUGIN_HOOK_NAMES = [
971
- ...ENUMERATED_INPUT_PLUGIN_HOOK_NAMES,
972
- ...ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES,
973
- "footer",
974
- "banner",
975
- "intro",
976
- "outro"
977
- ];
978
- const DEFINED_HOOK_NAMES = {
979
- [ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0],
980
- [ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1],
981
- [ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2],
982
- [ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3],
983
- [ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4],
984
- [ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5],
985
- [ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6],
986
- [ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7],
987
- [ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8],
988
- [ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9],
989
- [ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10],
990
- [ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11],
991
- [ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12],
992
- [ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13],
993
- [ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14],
994
- [ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15],
995
- [ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16],
996
- [ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17],
997
- [ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18],
998
- [ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19],
999
- [ENUMERATED_PLUGIN_HOOK_NAMES[20]]: ENUMERATED_PLUGIN_HOOK_NAMES[20],
1000
- [ENUMERATED_PLUGIN_HOOK_NAMES[21]]: ENUMERATED_PLUGIN_HOOK_NAMES[21],
1001
- [ENUMERATED_PLUGIN_HOOK_NAMES[22]]: ENUMERATED_PLUGIN_HOOK_NAMES[22]
1002
- };
1003
-
1004
- //#endregion
1005
- //#region src/utils/async-flatten.ts
1006
- async function asyncFlatten(array$1) {
1007
- do
1008
- array$1 = (await Promise.all(array$1)).flat(Infinity);
1009
- while (array$1.some((v$1) => v$1?.then));
1010
- return array$1;
1011
- }
1012
-
1013
- //#endregion
1014
- //#region src/utils/normalize-plugin-option.ts
1015
- const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
1016
- function checkOutputPluginOption(plugins, onLog) {
1017
- for (const plugin of plugins) for (const hook of ENUMERATED_INPUT_PLUGIN_HOOK_NAMES) if (hook in plugin) {
1018
- delete plugin[hook];
1019
- onLog(LOG_LEVEL_WARN, logInputHookInOutputPlugin(plugin.name, hook));
1020
- }
1021
- return plugins;
1022
- }
1023
- function normalizePlugins(plugins, anonymousPrefix) {
1024
- for (const [index, plugin] of plugins.entries()) {
1025
- if ("_parallel" in plugin) continue;
1026
- if (plugin instanceof BuiltinPlugin) continue;
1027
- if (!plugin.name) plugin.name = `${anonymousPrefix}${index + 1}`;
1028
- }
1029
- return plugins;
1030
- }
1031
- const ANONYMOUS_PLUGIN_PREFIX = "at position ";
1032
- const ANONYMOUS_OUTPUT_PLUGIN_PREFIX = "at output position ";
1033
-
1034
- //#endregion
1035
- //#region src/plugin/minimal-plugin-context.ts
1036
- var MinimalPluginContextImpl = class {
1037
- info;
1038
- warn;
1039
- debug;
1040
- meta;
1041
- constructor(onLog, logLevel, pluginName, watchMode, hookName) {
1042
- this.pluginName = pluginName;
1043
- this.hookName = hookName;
1044
- this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
1045
- this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
1046
- this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
1047
- this.meta = {
1048
- rollupVersion: "4.23.0",
1049
- rolldownVersion: VERSION,
1050
- watchMode
1051
- };
1052
- }
1053
- error(e$1) {
1054
- return error(logPluginError(normalizeLog(e$1), this.pluginName, { hook: this.hookName }));
1055
- }
1056
- };
1057
-
1058
- //#endregion
1059
- //#region src/plugin/plugin-driver.ts
1060
- var PluginDriver = class {
1061
- static async callOptionsHook(inputOptions, watchMode = false) {
1062
- const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
1063
- const plugins = getSortedPlugins("options", getObjectPlugins(await normalizePluginOption(inputOptions.plugins)));
1064
- const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel, watchMode);
1065
- for (const plugin of plugins) {
1066
- const name = plugin.name || "unknown";
1067
- const options = plugin.options;
1068
- if (options) {
1069
- const { handler } = normalizeHook(options);
1070
- const result = await handler.call(new MinimalPluginContextImpl(logger, logLevel, name, watchMode, "onLog"), inputOptions);
1071
- if (result) inputOptions = result;
1072
- }
1073
- }
1074
- return inputOptions;
1075
- }
1076
- static callOutputOptionsHook(rawPlugins, outputOptions, onLog, logLevel, watchMode) {
1077
- const sortedPlugins = getSortedPlugins("outputOptions", getObjectPlugins(rawPlugins));
1078
- for (const plugin of sortedPlugins) {
1079
- const name = plugin.name || "unknown";
1080
- const options = plugin.outputOptions;
1081
- if (options) {
1082
- const { handler } = normalizeHook(options);
1083
- const result = handler.call(new MinimalPluginContextImpl(onLog, logLevel, name, watchMode), outputOptions);
1084
- if (result) outputOptions = result;
1085
- }
1086
- }
1087
- return outputOptions;
1088
- }
1089
- };
1090
- function getObjectPlugins(plugins) {
1091
- return plugins.filter((plugin) => {
1092
- if (!plugin) return void 0;
1093
- if ("_parallel" in plugin) return void 0;
1094
- if (plugin instanceof BuiltinPlugin) return void 0;
1095
- return plugin;
1096
- });
1097
- }
1098
- function getSortedPlugins(hookName, plugins) {
1099
- const pre = [];
1100
- const normal = [];
1101
- const post = [];
1102
- for (const plugin of plugins) {
1103
- const hook = plugin[hookName];
1104
- if (hook) {
1105
- if (typeof hook === "object") {
1106
- if (hook.order === "pre") {
1107
- pre.push(plugin);
1108
- continue;
1109
- }
1110
- if (hook.order === "post") {
1111
- post.push(plugin);
1112
- continue;
1113
- }
1114
- }
1115
- normal.push(plugin);
1116
- }
1117
- }
1118
- return [
1119
- ...pre,
1120
- ...normal,
1121
- ...post
1122
- ];
1123
- }
1124
-
1125
- //#endregion
1126
- //#region ../../node_modules/.pnpm/valibot@1.0.0_typescript@5.8.3/node_modules/valibot/dist/index.js
1127
- var store;
1128
- /* @__NO_SIDE_EFFECTS__ */
1129
- function getGlobalConfig(config2) {
1130
- return {
1131
- lang: config2?.lang ?? store?.lang,
1132
- message: config2?.message,
1133
- abortEarly: config2?.abortEarly ?? store?.abortEarly,
1134
- abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly
1135
- };
1136
- }
1137
- var store2;
1138
- /* @__NO_SIDE_EFFECTS__ */
1139
- function getGlobalMessage(lang) {
1140
- return store2?.get(lang);
1141
- }
1142
- var store3;
1143
- /* @__NO_SIDE_EFFECTS__ */
1144
- function getSchemaMessage(lang) {
1145
- return store3?.get(lang);
1146
- }
1147
- var store4;
1148
- /* @__NO_SIDE_EFFECTS__ */
1149
- function getSpecificMessage(reference, lang) {
1150
- return store4?.get(reference)?.get(lang);
1151
- }
1152
- /* @__NO_SIDE_EFFECTS__ */
1153
- function _stringify(input) {
1154
- const type = typeof input;
1155
- if (type === "string") return `"${input}"`;
1156
- if (type === "number" || type === "bigint" || type === "boolean") return `${input}`;
1157
- if (type === "object" || type === "function") return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
1158
- return type;
1159
- }
1160
- function _addIssue(context, label, dataset, config2, other) {
1161
- const input = other && "input" in other ? other.input : dataset.value;
1162
- const expected = other?.expected ?? context.expects ?? null;
1163
- const received = other?.received ?? /* @__PURE__ */ _stringify(input);
1164
- const issue = {
1165
- kind: context.kind,
1166
- type: context.type,
1167
- input,
1168
- expected,
1169
- received,
1170
- message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
1171
- requirement: context.requirement,
1172
- path: other?.path,
1173
- issues: other?.issues,
1174
- lang: config2.lang,
1175
- abortEarly: config2.abortEarly,
1176
- abortPipeEarly: config2.abortPipeEarly
1177
- };
1178
- const isSchema = context.kind === "schema";
1179
- const message = other?.message ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config2.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang);
1180
- if (message !== void 0) issue.message = typeof message === "function" ? message(issue) : message;
1181
- if (isSchema) dataset.typed = false;
1182
- if (dataset.issues) dataset.issues.push(issue);
1183
- else dataset.issues = [issue];
1184
- }
1185
- /* @__NO_SIDE_EFFECTS__ */
1186
- function _getStandardProps(context) {
1187
- return {
1188
- version: 1,
1189
- vendor: "valibot",
1190
- validate(value2) {
1191
- return context["~run"]({ value: value2 }, /* @__PURE__ */ getGlobalConfig());
1192
- }
1193
- };
1194
- }
1195
- /* @__NO_SIDE_EFFECTS__ */
1196
- function _isValidObjectKey(object2, key) {
1197
- return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
1198
- }
1199
- /* @__NO_SIDE_EFFECTS__ */
1200
- function _joinExpects(values2, separator) {
1201
- const list = [...new Set(values2)];
1202
- if (list.length > 1) return `(${list.join(` ${separator} `)})`;
1203
- return list[0] ?? "never";
1204
- }
1205
- var ValiError = class extends Error {
1206
- /**
1207
- * Creates a Valibot error with useful information.
1208
- *
1209
- * @param issues The error issues.
1210
- */
1211
- constructor(issues) {
1212
- super(issues[0].message);
1213
- this.name = "ValiError";
1214
- this.issues = issues;
1215
- }
1216
- };
1217
- /* @__NO_SIDE_EFFECTS__ */
1218
- function args(schema) {
1219
- return {
1220
- kind: "transformation",
1221
- type: "args",
1222
- reference: args,
1223
- async: false,
1224
- schema,
1225
- "~run"(dataset, config2) {
1226
- const func = dataset.value;
1227
- dataset.value = (...args_) => {
1228
- const argsDataset = this.schema["~run"]({ value: args_ }, config2);
1229
- if (argsDataset.issues) throw new ValiError(argsDataset.issues);
1230
- return func(...argsDataset.value);
1231
- };
1232
- return dataset;
1233
- }
1234
- };
1235
- }
1236
- /* @__NO_SIDE_EFFECTS__ */
1237
- function awaitAsync() {
1238
- return {
1239
- kind: "transformation",
1240
- type: "await",
1241
- reference: awaitAsync,
1242
- async: true,
1243
- async "~run"(dataset) {
1244
- dataset.value = await dataset.value;
1245
- return dataset;
1246
- }
1247
- };
1248
- }
1249
- /* @__NO_SIDE_EFFECTS__ */
1250
- function description(description_) {
1251
- return {
1252
- kind: "metadata",
1253
- type: "description",
1254
- reference: description,
1255
- description: description_
1256
- };
1257
- }
1258
- /* @__NO_SIDE_EFFECTS__ */
1259
- function returns(schema) {
1260
- return {
1261
- kind: "transformation",
1262
- type: "returns",
1263
- reference: returns,
1264
- async: false,
1265
- schema,
1266
- "~run"(dataset, config2) {
1267
- const func = dataset.value;
1268
- dataset.value = (...args_) => {
1269
- const returnsDataset = this.schema["~run"]({ value: func(...args_) }, config2);
1270
- if (returnsDataset.issues) throw new ValiError(returnsDataset.issues);
1271
- return returnsDataset.value;
1272
- };
1273
- return dataset;
1274
- }
1275
- };
1276
- }
1277
- /* @__NO_SIDE_EFFECTS__ */
1278
- function returnsAsync(schema) {
1279
- return {
1280
- kind: "transformation",
1281
- type: "returns",
1282
- reference: returnsAsync,
1283
- async: false,
1284
- schema,
1285
- "~run"(dataset, config2) {
1286
- const func = dataset.value;
1287
- dataset.value = async (...args_) => {
1288
- const returnsDataset = await this.schema["~run"]({ value: await func(...args_) }, config2);
1289
- if (returnsDataset.issues) throw new ValiError(returnsDataset.issues);
1290
- return returnsDataset.value;
1291
- };
1292
- return dataset;
1293
- }
1294
- };
1295
- }
1296
- /* @__NO_SIDE_EFFECTS__ */
1297
- function getFallback(schema, dataset, config2) {
1298
- return typeof schema.fallback === "function" ? schema.fallback(dataset, config2) : schema.fallback;
1299
- }
1300
- /* @__NO_SIDE_EFFECTS__ */
1301
- function getDefault(schema, dataset, config2) {
1302
- return typeof schema.default === "function" ? schema.default(dataset, config2) : schema.default;
1303
- }
1304
- /* @__NO_SIDE_EFFECTS__ */
1305
- function any() {
1306
- return {
1307
- kind: "schema",
1308
- type: "any",
1309
- reference: any,
1310
- expects: "any",
1311
- async: false,
1312
- get "~standard"() {
1313
- return /* @__PURE__ */ _getStandardProps(this);
1314
- },
1315
- "~run"(dataset) {
1316
- dataset.typed = true;
1317
- return dataset;
1318
- }
1319
- };
1320
- }
1321
- /* @__NO_SIDE_EFFECTS__ */
1322
- function array(item, message) {
1323
- return {
1324
- kind: "schema",
1325
- type: "array",
1326
- reference: array,
1327
- expects: "Array",
1328
- async: false,
1329
- item,
1330
- message,
1331
- get "~standard"() {
1332
- return /* @__PURE__ */ _getStandardProps(this);
1333
- },
1334
- "~run"(dataset, config2) {
1335
- const input = dataset.value;
1336
- if (Array.isArray(input)) {
1337
- dataset.typed = true;
1338
- dataset.value = [];
1339
- for (let key = 0; key < input.length; key++) {
1340
- const value2 = input[key];
1341
- const itemDataset = this.item["~run"]({ value: value2 }, config2);
1342
- if (itemDataset.issues) {
1343
- const pathItem = {
1344
- type: "array",
1345
- origin: "value",
1346
- input,
1347
- key,
1348
- value: value2
1349
- };
1350
- for (const issue of itemDataset.issues) {
1351
- if (issue.path) issue.path.unshift(pathItem);
1352
- else issue.path = [pathItem];
1353
- dataset.issues?.push(issue);
1354
- }
1355
- if (!dataset.issues) dataset.issues = itemDataset.issues;
1356
- if (config2.abortEarly) {
1357
- dataset.typed = false;
1358
- break;
1359
- }
1360
- }
1361
- if (!itemDataset.typed) dataset.typed = false;
1362
- dataset.value.push(itemDataset.value);
1363
- }
1364
- } else _addIssue(this, "type", dataset, config2);
1365
- return dataset;
1366
- }
1367
- };
1368
- }
1369
- /* @__NO_SIDE_EFFECTS__ */
1370
- function boolean(message) {
1371
- return {
1372
- kind: "schema",
1373
- type: "boolean",
1374
- reference: boolean,
1375
- expects: "boolean",
1376
- async: false,
1377
- message,
1378
- get "~standard"() {
1379
- return /* @__PURE__ */ _getStandardProps(this);
1380
- },
1381
- "~run"(dataset, config2) {
1382
- if (typeof dataset.value === "boolean") dataset.typed = true;
1383
- else _addIssue(this, "type", dataset, config2);
1384
- return dataset;
1385
- }
1386
- };
1387
- }
1388
- /* @__NO_SIDE_EFFECTS__ */
1389
- function custom(check2, message) {
1390
- return {
1391
- kind: "schema",
1392
- type: "custom",
1393
- reference: custom,
1394
- expects: "unknown",
1395
- async: false,
1396
- check: check2,
1397
- message,
1398
- get "~standard"() {
1399
- return /* @__PURE__ */ _getStandardProps(this);
1400
- },
1401
- "~run"(dataset, config2) {
1402
- if (this.check(dataset.value)) dataset.typed = true;
1403
- else _addIssue(this, "type", dataset, config2);
1404
- return dataset;
1405
- }
1406
- };
1407
- }
1408
- /* @__NO_SIDE_EFFECTS__ */
1409
- function enum_(enum__, message) {
1410
- const options = [];
1411
- for (const key in enum__) if (`${+key}` !== key || typeof enum__[key] !== "string" || !Object.is(enum__[enum__[key]], +key)) options.push(enum__[key]);
1412
- return {
1413
- kind: "schema",
1414
- type: "enum",
1415
- reference: enum_,
1416
- expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
1417
- async: false,
1418
- enum: enum__,
1419
- options,
1420
- message,
1421
- get "~standard"() {
1422
- return /* @__PURE__ */ _getStandardProps(this);
1423
- },
1424
- "~run"(dataset, config2) {
1425
- if (this.options.includes(dataset.value)) dataset.typed = true;
1426
- else _addIssue(this, "type", dataset, config2);
1427
- return dataset;
1428
- }
1429
- };
1430
- }
1431
- /* @__NO_SIDE_EFFECTS__ */
1432
- function function_(message) {
1433
- return {
1434
- kind: "schema",
1435
- type: "function",
1436
- reference: function_,
1437
- expects: "Function",
1438
- async: false,
1439
- message,
1440
- get "~standard"() {
1441
- return /* @__PURE__ */ _getStandardProps(this);
1442
- },
1443
- "~run"(dataset, config2) {
1444
- if (typeof dataset.value === "function") dataset.typed = true;
1445
- else _addIssue(this, "type", dataset, config2);
1446
- return dataset;
1447
- }
1448
- };
1449
- }
1450
- /* @__NO_SIDE_EFFECTS__ */
1451
- function instance(class_, message) {
1452
- return {
1453
- kind: "schema",
1454
- type: "instance",
1455
- reference: instance,
1456
- expects: class_.name,
1457
- async: false,
1458
- class: class_,
1459
- message,
1460
- get "~standard"() {
1461
- return /* @__PURE__ */ _getStandardProps(this);
1462
- },
1463
- "~run"(dataset, config2) {
1464
- if (dataset.value instanceof this.class) dataset.typed = true;
1465
- else _addIssue(this, "type", dataset, config2);
1466
- return dataset;
1467
- }
1468
- };
1469
- }
1470
- /* @__NO_SIDE_EFFECTS__ */
1471
- function literal(literal_, message) {
1472
- return {
1473
- kind: "schema",
1474
- type: "literal",
1475
- reference: literal,
1476
- expects: /* @__PURE__ */ _stringify(literal_),
1477
- async: false,
1478
- literal: literal_,
1479
- message,
1480
- get "~standard"() {
1481
- return /* @__PURE__ */ _getStandardProps(this);
1482
- },
1483
- "~run"(dataset, config2) {
1484
- if (dataset.value === this.literal) dataset.typed = true;
1485
- else _addIssue(this, "type", dataset, config2);
1486
- return dataset;
1487
- }
1488
- };
1489
- }
1490
- /* @__NO_SIDE_EFFECTS__ */
1491
- function looseObject(entries, message) {
1492
- return {
1493
- kind: "schema",
1494
- type: "loose_object",
1495
- reference: looseObject,
1496
- expects: "Object",
1497
- async: false,
1498
- entries,
1499
- message,
1500
- get "~standard"() {
1501
- return /* @__PURE__ */ _getStandardProps(this);
1502
- },
1503
- "~run"(dataset, config2) {
1504
- const input = dataset.value;
1505
- if (input && typeof input === "object") {
1506
- dataset.typed = true;
1507
- dataset.value = {};
1508
- for (const key in this.entries) {
1509
- const valueSchema = this.entries[key];
1510
- if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
1511
- const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
1512
- const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
1513
- if (valueDataset.issues) {
1514
- const pathItem = {
1515
- type: "object",
1516
- origin: "value",
1517
- input,
1518
- key,
1519
- value: value2
1520
- };
1521
- for (const issue of valueDataset.issues) {
1522
- if (issue.path) issue.path.unshift(pathItem);
1523
- else issue.path = [pathItem];
1524
- dataset.issues?.push(issue);
1525
- }
1526
- if (!dataset.issues) dataset.issues = valueDataset.issues;
1527
- if (config2.abortEarly) {
1528
- dataset.typed = false;
1529
- break;
1530
- }
1531
- }
1532
- if (!valueDataset.typed) dataset.typed = false;
1533
- dataset.value[key] = valueDataset.value;
1534
- } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
1535
- else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
1536
- _addIssue(this, "key", dataset, config2, {
1537
- input: void 0,
1538
- expected: `"${key}"`,
1539
- path: [{
1540
- type: "object",
1541
- origin: "key",
1542
- input,
1543
- key,
1544
- value: input[key]
1545
- }]
1546
- });
1547
- if (config2.abortEarly) break;
1548
- }
1549
- }
1550
- if (!dataset.issues || !config2.abortEarly) {
1551
- for (const key in input) if (/* @__PURE__ */ _isValidObjectKey(input, key) && !(key in this.entries)) dataset.value[key] = input[key];
1552
- }
1553
- } else _addIssue(this, "type", dataset, config2);
1554
- return dataset;
1555
- }
1556
- };
1557
- }
1558
- /* @__NO_SIDE_EFFECTS__ */
1559
- function never(message) {
1560
- return {
1561
- kind: "schema",
1562
- type: "never",
1563
- reference: never,
1564
- expects: "never",
1565
- async: false,
1566
- message,
1567
- get "~standard"() {
1568
- return /* @__PURE__ */ _getStandardProps(this);
1569
- },
1570
- "~run"(dataset, config2) {
1571
- _addIssue(this, "type", dataset, config2);
1572
- return dataset;
1573
- }
1574
- };
1575
- }
1576
- /* @__NO_SIDE_EFFECTS__ */
1577
- function nullish(wrapped, default_) {
1578
- return {
1579
- kind: "schema",
1580
- type: "nullish",
1581
- reference: nullish,
1582
- expects: `(${wrapped.expects} | null | undefined)`,
1583
- async: false,
1584
- wrapped,
1585
- default: default_,
1586
- get "~standard"() {
1587
- return /* @__PURE__ */ _getStandardProps(this);
1588
- },
1589
- "~run"(dataset, config2) {
1590
- if (dataset.value === null || dataset.value === void 0) {
1591
- if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
1592
- if (dataset.value === null || dataset.value === void 0) {
1593
- dataset.typed = true;
1594
- return dataset;
1595
- }
1596
- }
1597
- return this.wrapped["~run"](dataset, config2);
1598
- }
1599
- };
1600
- }
1601
- /* @__NO_SIDE_EFFECTS__ */
1602
- function number(message) {
1603
- return {
1604
- kind: "schema",
1605
- type: "number",
1606
- reference: number,
1607
- expects: "number",
1608
- async: false,
1609
- message,
1610
- get "~standard"() {
1611
- return /* @__PURE__ */ _getStandardProps(this);
1612
- },
1613
- "~run"(dataset, config2) {
1614
- if (typeof dataset.value === "number" && !isNaN(dataset.value)) dataset.typed = true;
1615
- else _addIssue(this, "type", dataset, config2);
1616
- return dataset;
1617
- }
1618
- };
1619
- }
1620
- /* @__NO_SIDE_EFFECTS__ */
1621
- function object(entries, message) {
1622
- return {
1623
- kind: "schema",
1624
- type: "object",
1625
- reference: object,
1626
- expects: "Object",
1627
- async: false,
1628
- entries,
1629
- message,
1630
- get "~standard"() {
1631
- return /* @__PURE__ */ _getStandardProps(this);
1632
- },
1633
- "~run"(dataset, config2) {
1634
- const input = dataset.value;
1635
- if (input && typeof input === "object") {
1636
- dataset.typed = true;
1637
- dataset.value = {};
1638
- for (const key in this.entries) {
1639
- const valueSchema = this.entries[key];
1640
- if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
1641
- const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
1642
- const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
1643
- if (valueDataset.issues) {
1644
- const pathItem = {
1645
- type: "object",
1646
- origin: "value",
1647
- input,
1648
- key,
1649
- value: value2
1650
- };
1651
- for (const issue of valueDataset.issues) {
1652
- if (issue.path) issue.path.unshift(pathItem);
1653
- else issue.path = [pathItem];
1654
- dataset.issues?.push(issue);
1655
- }
1656
- if (!dataset.issues) dataset.issues = valueDataset.issues;
1657
- if (config2.abortEarly) {
1658
- dataset.typed = false;
1659
- break;
1660
- }
1661
- }
1662
- if (!valueDataset.typed) dataset.typed = false;
1663
- dataset.value[key] = valueDataset.value;
1664
- } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
1665
- else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
1666
- _addIssue(this, "key", dataset, config2, {
1667
- input: void 0,
1668
- expected: `"${key}"`,
1669
- path: [{
1670
- type: "object",
1671
- origin: "key",
1672
- input,
1673
- key,
1674
- value: input[key]
1675
- }]
1676
- });
1677
- if (config2.abortEarly) break;
1678
- }
1679
- }
1680
- } else _addIssue(this, "type", dataset, config2);
1681
- return dataset;
1682
- }
1683
- };
1684
- }
1685
- /* @__NO_SIDE_EFFECTS__ */
1686
- function optional(wrapped, default_) {
1687
- return {
1688
- kind: "schema",
1689
- type: "optional",
1690
- reference: optional,
1691
- expects: `(${wrapped.expects} | undefined)`,
1692
- async: false,
1693
- wrapped,
1694
- default: default_,
1695
- get "~standard"() {
1696
- return /* @__PURE__ */ _getStandardProps(this);
1697
- },
1698
- "~run"(dataset, config2) {
1699
- if (dataset.value === void 0) {
1700
- if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
1701
- if (dataset.value === void 0) {
1702
- dataset.typed = true;
1703
- return dataset;
1704
- }
1705
- }
1706
- return this.wrapped["~run"](dataset, config2);
1707
- }
1708
- };
1709
- }
1710
- /* @__NO_SIDE_EFFECTS__ */
1711
- function promise(message) {
1712
- return {
1713
- kind: "schema",
1714
- type: "promise",
1715
- reference: promise,
1716
- expects: "Promise",
1717
- async: false,
1718
- message,
1719
- get "~standard"() {
1720
- return /* @__PURE__ */ _getStandardProps(this);
1721
- },
1722
- "~run"(dataset, config2) {
1723
- if (dataset.value instanceof Promise) dataset.typed = true;
1724
- else _addIssue(this, "type", dataset, config2);
1725
- return dataset;
1726
- }
1727
- };
1728
- }
1729
- /* @__NO_SIDE_EFFECTS__ */
1730
- function record(key, value2, message) {
1731
- return {
1732
- kind: "schema",
1733
- type: "record",
1734
- reference: record,
1735
- expects: "Object",
1736
- async: false,
1737
- key,
1738
- value: value2,
1739
- message,
1740
- get "~standard"() {
1741
- return /* @__PURE__ */ _getStandardProps(this);
1742
- },
1743
- "~run"(dataset, config2) {
1744
- const input = dataset.value;
1745
- if (input && typeof input === "object") {
1746
- dataset.typed = true;
1747
- dataset.value = {};
1748
- for (const entryKey in input) if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
1749
- const entryValue = input[entryKey];
1750
- const keyDataset = this.key["~run"]({ value: entryKey }, config2);
1751
- if (keyDataset.issues) {
1752
- const pathItem = {
1753
- type: "object",
1754
- origin: "key",
1755
- input,
1756
- key: entryKey,
1757
- value: entryValue
1758
- };
1759
- for (const issue of keyDataset.issues) {
1760
- issue.path = [pathItem];
1761
- dataset.issues?.push(issue);
1762
- }
1763
- if (!dataset.issues) dataset.issues = keyDataset.issues;
1764
- if (config2.abortEarly) {
1765
- dataset.typed = false;
1766
- break;
1767
- }
1768
- }
1769
- const valueDataset = this.value["~run"]({ value: entryValue }, config2);
1770
- if (valueDataset.issues) {
1771
- const pathItem = {
1772
- type: "object",
1773
- origin: "value",
1774
- input,
1775
- key: entryKey,
1776
- value: entryValue
1777
- };
1778
- for (const issue of valueDataset.issues) {
1779
- if (issue.path) issue.path.unshift(pathItem);
1780
- else issue.path = [pathItem];
1781
- dataset.issues?.push(issue);
1782
- }
1783
- if (!dataset.issues) dataset.issues = valueDataset.issues;
1784
- if (config2.abortEarly) {
1785
- dataset.typed = false;
1786
- break;
1787
- }
1788
- }
1789
- if (!keyDataset.typed || !valueDataset.typed) dataset.typed = false;
1790
- if (keyDataset.typed) dataset.value[keyDataset.value] = valueDataset.value;
1791
- }
1792
- } else _addIssue(this, "type", dataset, config2);
1793
- return dataset;
1794
- }
1795
- };
1796
- }
1797
- /* @__NO_SIDE_EFFECTS__ */
1798
- function strictObject(entries, message) {
1799
- return {
1800
- kind: "schema",
1801
- type: "strict_object",
1802
- reference: strictObject,
1803
- expects: "Object",
1804
- async: false,
1805
- entries,
1806
- message,
1807
- get "~standard"() {
1808
- return /* @__PURE__ */ _getStandardProps(this);
1809
- },
1810
- "~run"(dataset, config2) {
1811
- const input = dataset.value;
1812
- if (input && typeof input === "object") {
1813
- dataset.typed = true;
1814
- dataset.value = {};
1815
- for (const key in this.entries) {
1816
- const valueSchema = this.entries[key];
1817
- if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
1818
- const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
1819
- const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
1820
- if (valueDataset.issues) {
1821
- const pathItem = {
1822
- type: "object",
1823
- origin: "value",
1824
- input,
1825
- key,
1826
- value: value2
1827
- };
1828
- for (const issue of valueDataset.issues) {
1829
- if (issue.path) issue.path.unshift(pathItem);
1830
- else issue.path = [pathItem];
1831
- dataset.issues?.push(issue);
1832
- }
1833
- if (!dataset.issues) dataset.issues = valueDataset.issues;
1834
- if (config2.abortEarly) {
1835
- dataset.typed = false;
1836
- break;
1837
- }
1838
- }
1839
- if (!valueDataset.typed) dataset.typed = false;
1840
- dataset.value[key] = valueDataset.value;
1841
- } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
1842
- else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
1843
- _addIssue(this, "key", dataset, config2, {
1844
- input: void 0,
1845
- expected: `"${key}"`,
1846
- path: [{
1847
- type: "object",
1848
- origin: "key",
1849
- input,
1850
- key,
1851
- value: input[key]
1852
- }]
1853
- });
1854
- if (config2.abortEarly) break;
1855
- }
1856
- }
1857
- if (!dataset.issues || !config2.abortEarly) {
1858
- for (const key in input) if (!(key in this.entries)) {
1859
- _addIssue(this, "key", dataset, config2, {
1860
- input: key,
1861
- expected: "never",
1862
- path: [{
1863
- type: "object",
1864
- origin: "key",
1865
- input,
1866
- key,
1867
- value: input[key]
1868
- }]
1869
- });
1870
- break;
1871
- }
1872
- }
1873
- } else _addIssue(this, "type", dataset, config2);
1874
- return dataset;
1875
- }
1876
- };
1877
- }
1878
- /* @__NO_SIDE_EFFECTS__ */
1879
- function string(message) {
1880
- return {
1881
- kind: "schema",
1882
- type: "string",
1883
- reference: string,
1884
- expects: "string",
1885
- async: false,
1886
- message,
1887
- get "~standard"() {
1888
- return /* @__PURE__ */ _getStandardProps(this);
1889
- },
1890
- "~run"(dataset, config2) {
1891
- if (typeof dataset.value === "string") dataset.typed = true;
1892
- else _addIssue(this, "type", dataset, config2);
1893
- return dataset;
1894
- }
1895
- };
1896
- }
1897
- /* @__NO_SIDE_EFFECTS__ */
1898
- function tuple(items, message) {
1899
- return {
1900
- kind: "schema",
1901
- type: "tuple",
1902
- reference: tuple,
1903
- expects: "Array",
1904
- async: false,
1905
- items,
1906
- message,
1907
- get "~standard"() {
1908
- return /* @__PURE__ */ _getStandardProps(this);
1909
- },
1910
- "~run"(dataset, config2) {
1911
- const input = dataset.value;
1912
- if (Array.isArray(input)) {
1913
- dataset.typed = true;
1914
- dataset.value = [];
1915
- for (let key = 0; key < this.items.length; key++) {
1916
- const value2 = input[key];
1917
- const itemDataset = this.items[key]["~run"]({ value: value2 }, config2);
1918
- if (itemDataset.issues) {
1919
- const pathItem = {
1920
- type: "array",
1921
- origin: "value",
1922
- input,
1923
- key,
1924
- value: value2
1925
- };
1926
- for (const issue of itemDataset.issues) {
1927
- if (issue.path) issue.path.unshift(pathItem);
1928
- else issue.path = [pathItem];
1929
- dataset.issues?.push(issue);
1930
- }
1931
- if (!dataset.issues) dataset.issues = itemDataset.issues;
1932
- if (config2.abortEarly) {
1933
- dataset.typed = false;
1934
- break;
1935
- }
1936
- }
1937
- if (!itemDataset.typed) dataset.typed = false;
1938
- dataset.value.push(itemDataset.value);
1939
- }
1940
- } else _addIssue(this, "type", dataset, config2);
1941
- return dataset;
1942
- }
1943
- };
1944
- }
1945
- /* @__NO_SIDE_EFFECTS__ */
1946
- function _subIssues(datasets) {
1947
- let issues;
1948
- if (datasets) for (const dataset of datasets) if (issues) issues.push(...dataset.issues);
1949
- else issues = dataset.issues;
1950
- return issues;
1951
- }
1952
- /* @__NO_SIDE_EFFECTS__ */
1953
- function union(options, message) {
1954
- return {
1955
- kind: "schema",
1956
- type: "union",
1957
- reference: union,
1958
- expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
1959
- async: false,
1960
- options,
1961
- message,
1962
- get "~standard"() {
1963
- return /* @__PURE__ */ _getStandardProps(this);
1964
- },
1965
- "~run"(dataset, config2) {
1966
- let validDataset;
1967
- let typedDatasets;
1968
- let untypedDatasets;
1969
- for (const schema of this.options) {
1970
- const optionDataset = schema["~run"]({ value: dataset.value }, config2);
1971
- if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
1972
- else typedDatasets = [optionDataset];
1973
- else {
1974
- validDataset = optionDataset;
1975
- break;
1976
- }
1977
- else if (untypedDatasets) untypedDatasets.push(optionDataset);
1978
- else untypedDatasets = [optionDataset];
1979
- }
1980
- if (validDataset) return validDataset;
1981
- if (typedDatasets) {
1982
- if (typedDatasets.length === 1) return typedDatasets[0];
1983
- _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
1984
- dataset.typed = true;
1985
- } else if (untypedDatasets?.length === 1) return untypedDatasets[0];
1986
- else _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
1987
- return dataset;
1988
- }
1989
- };
1990
- }
1991
- /* @__NO_SIDE_EFFECTS__ */
1992
- function unionAsync(options, message) {
1993
- return {
1994
- kind: "schema",
1995
- type: "union",
1996
- reference: unionAsync,
1997
- expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
1998
- async: true,
1999
- options,
2000
- message,
2001
- get "~standard"() {
2002
- return /* @__PURE__ */ _getStandardProps(this);
2003
- },
2004
- async "~run"(dataset, config2) {
2005
- let validDataset;
2006
- let typedDatasets;
2007
- let untypedDatasets;
2008
- for (const schema of this.options) {
2009
- const optionDataset = await schema["~run"]({ value: dataset.value }, config2);
2010
- if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
2011
- else typedDatasets = [optionDataset];
2012
- else {
2013
- validDataset = optionDataset;
2014
- break;
2015
- }
2016
- else if (untypedDatasets) untypedDatasets.push(optionDataset);
2017
- else untypedDatasets = [optionDataset];
2018
- }
2019
- if (validDataset) return validDataset;
2020
- if (typedDatasets) {
2021
- if (typedDatasets.length === 1) return typedDatasets[0];
2022
- _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
2023
- dataset.typed = true;
2024
- } else if (untypedDatasets?.length === 1) return untypedDatasets[0];
2025
- else _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
2026
- return dataset;
2027
- }
2028
- };
2029
- }
2030
- /* @__NO_SIDE_EFFECTS__ */
2031
- function omit(schema, keys) {
2032
- const entries = { ...schema.entries };
2033
- for (const key of keys) delete entries[key];
2034
- return {
2035
- ...schema,
2036
- entries,
2037
- get "~standard"() {
2038
- return /* @__PURE__ */ _getStandardProps(this);
2039
- }
2040
- };
2041
- }
2042
- /* @__NO_SIDE_EFFECTS__ */
2043
- function pipe(...pipe2) {
2044
- return {
2045
- ...pipe2[0],
2046
- pipe: pipe2,
2047
- get "~standard"() {
2048
- return /* @__PURE__ */ _getStandardProps(this);
2049
- },
2050
- "~run"(dataset, config2) {
2051
- for (const item of pipe2) if (item.kind !== "metadata") {
2052
- if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
2053
- dataset.typed = false;
2054
- break;
2055
- }
2056
- if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) dataset = item["~run"](dataset, config2);
2057
- }
2058
- return dataset;
2059
- }
2060
- };
2061
- }
2062
- /* @__NO_SIDE_EFFECTS__ */
2063
- function pipeAsync(...pipe2) {
2064
- return {
2065
- ...pipe2[0],
2066
- pipe: pipe2,
2067
- async: true,
2068
- get "~standard"() {
2069
- return /* @__PURE__ */ _getStandardProps(this);
2070
- },
2071
- async "~run"(dataset, config2) {
2072
- for (const item of pipe2) if (item.kind !== "metadata") {
2073
- if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
2074
- dataset.typed = false;
2075
- break;
2076
- }
2077
- if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) dataset = await item["~run"](dataset, config2);
2078
- }
2079
- return dataset;
2080
- }
2081
- };
2082
- }
2083
- /* @__NO_SIDE_EFFECTS__ */
2084
- function safeParse(schema, input, config2) {
2085
- const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
2086
- return {
2087
- typed: dataset.typed,
2088
- success: !dataset.issues,
2089
- output: dataset.value,
2090
- issues: dataset.issues
2091
- };
2092
- }
2093
-
2094
- //#endregion
2095
- //#region src/utils/validator.ts
2096
- const StringOrRegExpSchema = union([string(), instance(RegExp)]);
2097
- const LogLevelSchema = union([
2098
- literal("debug"),
2099
- literal("info"),
2100
- literal("warn")
2101
- ]);
2102
- const LogLevelOptionSchema = union([LogLevelSchema, literal("silent")]);
2103
- const LogLevelWithErrorSchema = union([LogLevelSchema, literal("error")]);
2104
- const RollupLogSchema = any();
2105
- const RollupLogWithStringSchema = union([RollupLogSchema, string()]);
2106
- const InputOptionSchema = union([
2107
- string(),
2108
- array(string()),
2109
- record(string(), string())
2110
- ]);
2111
- const ExternalSchema = union([
2112
- StringOrRegExpSchema,
2113
- array(StringOrRegExpSchema),
2114
- pipe(function_(), args(tuple([
2115
- string(),
2116
- optional(string()),
2117
- boolean()
2118
- ])), returns(nullish(boolean())))
2119
- ]);
2120
- const ModuleTypesSchema = record(string(), union([
2121
- literal("base64"),
2122
- literal("binary"),
2123
- literal("css"),
2124
- literal("dataurl"),
2125
- literal("empty"),
2126
- literal("js"),
2127
- literal("json"),
2128
- literal("jsx"),
2129
- literal("text"),
2130
- literal("ts"),
2131
- literal("tsx")
2132
- ]));
2133
- const JsxOptionsSchema = strictObject({
2134
- development: pipe(optional(boolean()), description("Development specific information")),
2135
- factory: pipe(optional(string()), description("Jsx element transformation")),
2136
- fragment: pipe(optional(string()), description("Jsx fragment transformation")),
2137
- importSource: pipe(optional(string()), description("Import the factory of element and fragment if mode is classic")),
2138
- jsxImportSource: pipe(optional(string()), description("Import the factory of element and fragment if mode is automatic")),
2139
- mode: pipe(optional(union([
2140
- literal("classic"),
2141
- literal("automatic"),
2142
- literal("preserve")
2143
- ])), description("Jsx transformation mode")),
2144
- refresh: pipe(optional(boolean()), description("React refresh transformation"))
2145
- });
2146
- const HelperModeSchema = union([literal("Runtime"), literal("External")]);
2147
- const DecoratorOptionSchema = object({
2148
- legacy: optional(boolean()),
2149
- emitDecoratorMetadata: optional(boolean())
2150
- });
2151
- const HelpersSchema = object({ mode: optional(HelperModeSchema) });
2152
- const RewriteImportExtensionsSchema = union([
2153
- literal("rewrite"),
2154
- literal("remove"),
2155
- boolean()
2156
- ]);
2157
- const TypescriptSchema = object({
2158
- jsxPragma: optional(string()),
2159
- jsxPragmaFrag: optional(string()),
2160
- onlyRemoveTypeImports: optional(boolean()),
2161
- allowNamespaces: optional(boolean()),
2162
- allowDeclareFields: optional(boolean()),
2163
- declaration: optional(object({
2164
- stripInternal: optional(boolean()),
2165
- sourcemap: optional(boolean())
2166
- })),
2167
- rewriteImportExtensions: optional(RewriteImportExtensionsSchema)
2168
- });
2169
- const AssumptionsSchema = object({
2170
- ignoreFunctionLength: optional(boolean()),
2171
- noDocumentAll: optional(boolean()),
2172
- objectRestNoSymbols: optional(boolean()),
2173
- pureGetters: optional(boolean()),
2174
- setPublicClassFields: optional(boolean())
2175
- });
2176
- const TransformOptionsSchema = object({
2177
- assumptions: optional(AssumptionsSchema),
2178
- typescript: optional(TypescriptSchema),
2179
- helpers: optional(HelpersSchema),
2180
- decorators: optional(DecoratorOptionSchema)
2181
- });
2182
- const WatchOptionsSchema = strictObject({
2183
- chokidar: optional(never(`The "watch.chokidar" option is deprecated, please use "watch.notify" instead of it`)),
2184
- exclude: optional(union([StringOrRegExpSchema, array(StringOrRegExpSchema)])),
2185
- include: optional(union([StringOrRegExpSchema, array(StringOrRegExpSchema)])),
2186
- notify: pipe(optional(strictObject({
2187
- compareContents: optional(boolean()),
2188
- pollInterval: optional(number())
2189
- })), description("Notify options")),
2190
- skipWrite: pipe(optional(boolean()), description("Skip the bundle.write() step")),
2191
- buildDelay: pipe(optional(number()), description("Throttle watch rebuilds"))
2192
- });
2193
- const ChecksOptionsSchema = strictObject({
2194
- circularDependency: pipe(optional(boolean()), description("Whether to emit warning when detecting circular dependency")),
2195
- eval: pipe(optional(boolean()), description("Whether to emit warning when detecting eval")),
2196
- missingGlobalName: pipe(optional(boolean()), description("Whether to emit warning when detecting missing global name")),
2197
- missingNameOptionForIifeExport: pipe(optional(boolean()), description("Whether to emit warning when detecting missing name option for iife export")),
2198
- mixedExport: pipe(optional(boolean()), description("Whether to emit warning when detecting mixed export")),
2199
- unresolvedEntry: pipe(optional(boolean()), description("Whether to emit warning when detecting unresolved entry")),
2200
- unresolvedImport: pipe(optional(boolean()), description("Whether to emit warning when detecting unresolved import")),
2201
- filenameConflict: pipe(optional(boolean()), description("Whether to emit warning when detecting filename conflict")),
2202
- commonJsVariableInEsm: pipe(optional(boolean()), description("Whether to emit warning when detecting common js variable in esm")),
2203
- importIsUndefined: pipe(optional(boolean()), description("Whether to emit warning when detecting import is undefined")),
2204
- configurationFieldConflict: pipe(optional(boolean()), description("Whether to emit warning when detecting configuration field conflict"))
2205
- });
2206
- const MinifyOptionsSchema = strictObject({
2207
- mangle: boolean(),
2208
- compress: boolean(),
2209
- deadCodeElimination: boolean(),
2210
- removeWhitespace: boolean()
2211
- });
2212
- const ResolveOptionsSchema = strictObject({
2213
- alias: optional(record(string(), union([string(), array(string())]))),
2214
- aliasFields: optional(array(array(string()))),
2215
- conditionNames: optional(array(string())),
2216
- extensionAlias: optional(record(string(), array(string()))),
2217
- exportsFields: optional(array(array(string()))),
2218
- extensions: optional(array(string())),
2219
- mainFields: optional(array(string())),
2220
- mainFiles: optional(array(string())),
2221
- modules: optional(array(string())),
2222
- symlinks: optional(boolean()),
2223
- tsconfigFilename: optional(string())
2224
- });
2225
- const TreeshakingOptionsSchema = union([boolean(), looseObject({
2226
- annotations: optional(boolean()),
2227
- manualPureFunctions: optional(array(string())),
2228
- unknownGlobalSideEffects: optional(boolean())
2229
- })]);
2230
- const OnLogSchema = pipe(function_(), args(tuple([
2231
- LogLevelSchema,
2232
- RollupLogSchema,
2233
- pipe(function_(), args(tuple([LogLevelWithErrorSchema, RollupLogWithStringSchema])))
2234
- ])));
2235
- const OnwarnSchema = pipe(function_(), args(tuple([RollupLogSchema, pipe(function_(), args(tuple([union([RollupLogWithStringSchema, pipe(function_(), returns(RollupLogWithStringSchema))])])))])));
2236
- const HmrSchema = union([boolean(), strictObject({
2237
- port: optional(number()),
2238
- host: optional(string()),
2239
- implement: optional(string())
2240
- })]);
2241
- const InputOptionsSchema = strictObject({
2242
- input: optional(InputOptionSchema),
2243
- plugins: optional(custom(() => true)),
2244
- external: optional(ExternalSchema),
2245
- resolve: optional(ResolveOptionsSchema),
2246
- cwd: pipe(optional(string()), description("Current working directory")),
2247
- platform: pipe(optional(union([
2248
- literal("browser"),
2249
- literal("neutral"),
2250
- literal("node")
2251
- ])), description(`Platform for which the code should be generated (node, ${ansis_default.underline("browser")}, neutral)`)),
2252
- shimMissingExports: pipe(optional(boolean()), description("Create shim variables for missing exports")),
2253
- treeshake: optional(TreeshakingOptionsSchema),
2254
- logLevel: pipe(optional(LogLevelOptionSchema), description(`Log level (${ansis_default.dim("silent")}, ${ansis_default.underline(ansis_default.gray("info"))}, debug, ${ansis_default.yellow("warn")})`)),
2255
- onLog: optional(OnLogSchema),
2256
- onwarn: optional(OnwarnSchema),
2257
- moduleTypes: pipe(optional(ModuleTypesSchema), description("Module types for customized extensions")),
2258
- experimental: optional(strictObject({
2259
- disableLiveBindings: optional(boolean()),
2260
- enableComposingJsPlugins: optional(boolean()),
2261
- resolveNewUrlToAsset: optional(boolean()),
2262
- strictExecutionOrder: optional(boolean()),
2263
- hmr: optional(HmrSchema)
2264
- })),
2265
- define: pipe(optional(record(string(), string())), description("Define global variables")),
2266
- inject: optional(record(string(), union([string(), tuple([string(), string()])]))),
2267
- profilerNames: optional(boolean()),
2268
- jsx: optional(union([
2269
- boolean(),
2270
- JsxOptionsSchema,
2271
- string("react"),
2272
- string("react-jsx"),
2273
- string("preserve")
2274
- ])),
2275
- transform: optional(TransformOptionsSchema),
2276
- watch: optional(union([WatchOptionsSchema, literal(false)])),
2277
- dropLabels: pipe(optional(array(string())), description("Remove labeled statements with these label names")),
2278
- checks: optional(ChecksOptionsSchema),
2279
- keepNames: pipe(optional(boolean()), description("Keep function/class name")),
2280
- debug: pipe(optional(object({ buildId: pipe(optional(string()), description("Used to name the build.")) })), description("Enable debug mode. Emit debug information to disk. This might slow down the build process significantly."))
2281
- });
2282
- const InputCliOverrideSchema = strictObject({
2283
- external: pipe(optional(array(string())), description("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`")),
2284
- inject: pipe(optional(record(string(), string())), description("Inject import statements on demand")),
2285
- treeshake: pipe(optional(boolean()), description("enable treeshaking")),
2286
- jsx: pipe(optional(JsxOptionsSchema), description("enable jsx"))
2287
- });
2288
- const InputCliOptionsSchema = omit(strictObject({
2289
- ...InputOptionsSchema.entries,
2290
- ...InputCliOverrideSchema.entries
2291
- }), [
2292
- "input",
2293
- "plugins",
2294
- "onwarn",
2295
- "onLog",
2296
- "resolve",
2297
- "experimental",
2298
- "profilerNames",
2299
- "watch"
2300
- ]);
2301
- var ESTarget = /* @__PURE__ */ function(ESTarget$1) {
2302
- ESTarget$1["ES6"] = "es6";
2303
- ESTarget$1["ES2015"] = "es2015";
2304
- ESTarget$1["ES2016"] = "es2016";
2305
- ESTarget$1["ES2017"] = "es2017";
2306
- ESTarget$1["ES2018"] = "es2018";
2307
- ESTarget$1["ES2019"] = "es2019";
2308
- ESTarget$1["ES2020"] = "es2020";
2309
- ESTarget$1["ES2021"] = "es2021";
2310
- ESTarget$1["ES2022"] = "es2022";
2311
- ESTarget$1["ES2023"] = "es2023";
2312
- ESTarget$1["ES2024"] = "es2024";
2313
- ESTarget$1["ESNext"] = "esnext";
2314
- return ESTarget$1;
2315
- }(ESTarget || {});
2316
- const ModuleFormatSchema = union([
2317
- literal("es"),
2318
- literal("cjs"),
2319
- literal("esm"),
2320
- literal("module"),
2321
- literal("commonjs"),
2322
- literal("iife"),
2323
- literal("umd")
2324
- ]);
2325
- const AddonFunctionSchema = pipe(function_(), args(tuple([custom(() => true)])), returnsAsync(unionAsync([string(), pipeAsync(promise(), awaitAsync(), string())])));
2326
- const ChunkFileNamesSchema = union([string(), pipe(function_(), args(tuple([custom(() => true)])), returns(string()))]);
2327
- const AssetFileNamesSchema = union([string(), pipe(function_(), args(tuple([custom(() => true)])), returns(string()))]);
2328
- const SanitizeFileNameSchema = union([boolean(), pipe(function_(), args(tuple([string()])), returns(string()))]);
2329
- const GlobalsFunctionSchema = pipe(function_(), args(tuple([string()])), returns(string()));
2330
- const AdvancedChunksSchema = strictObject({
2331
- minSize: optional(number()),
2332
- maxSize: optional(number()),
2333
- minModuleSize: optional(number()),
2334
- maxModuleSize: optional(number()),
2335
- minShareCount: optional(number()),
2336
- groups: optional(array(strictObject({
2337
- name: string(),
2338
- test: optional(union([string(), instance(RegExp)])),
2339
- priority: optional(number()),
2340
- minSize: optional(number()),
2341
- minShareCount: optional(number()),
2342
- maxSize: optional(number()),
2343
- minModuleSize: optional(number()),
2344
- maxModuleSize: optional(number())
2345
- })))
2346
- });
2347
- const OutputOptionsSchema = strictObject({
2348
- dir: pipe(optional(string()), description("Output directory, defaults to `dist` if `file` is not set")),
2349
- file: pipe(optional(string()), description("Single output file")),
2350
- exports: pipe(optional(union([
2351
- literal("auto"),
2352
- literal("named"),
2353
- literal("default"),
2354
- literal("none")
2355
- ])), description(`Specify a export mode (${ansis_default.underline("auto")}, named, default, none)`)),
2356
- hashCharacters: pipe(optional(union([
2357
- literal("base64"),
2358
- literal("base36"),
2359
- literal("hex")
2360
- ])), description("Use the specified character set for file hashes")),
2361
- format: pipe(optional(ModuleFormatSchema), description(`Output format of the generated bundle (supports ${ansis_default.underline("esm")}, cjs, and iife)`)),
2362
- sourcemap: pipe(optional(union([
2363
- boolean(),
2364
- literal("inline"),
2365
- literal("hidden")
2366
- ])), description(`Generate sourcemap (\`-s inline\` for inline, or ${ansis_default.bold("pass the `-s` on the last argument if you want to generate `.map` file")})`)),
2367
- sourcemapDebugIds: pipe(optional(boolean()), description("Inject sourcemap debug IDs")),
2368
- sourcemapIgnoreList: optional(union([boolean(), custom(() => true)])),
2369
- sourcemapPathTransform: optional(custom(() => true)),
2370
- banner: optional(union([string(), AddonFunctionSchema])),
2371
- footer: optional(union([string(), AddonFunctionSchema])),
2372
- intro: optional(union([string(), AddonFunctionSchema])),
2373
- outro: optional(union([string(), AddonFunctionSchema])),
2374
- extend: pipe(optional(boolean()), description("Extend global variable defined by name in IIFE / UMD formats")),
2375
- esModule: optional(union([boolean(), literal("if-default-prop")])),
2376
- assetFileNames: optional(AssetFileNamesSchema),
2377
- entryFileNames: optional(ChunkFileNamesSchema),
2378
- chunkFileNames: optional(ChunkFileNamesSchema),
2379
- cssEntryFileNames: optional(ChunkFileNamesSchema),
2380
- cssChunkFileNames: optional(ChunkFileNamesSchema),
2381
- sanitizeFileName: optional(SanitizeFileNameSchema),
2382
- minify: pipe(optional(union([
2383
- boolean(),
2384
- string("dce-only"),
2385
- MinifyOptionsSchema
2386
- ])), description("Minify the bundled file")),
2387
- name: pipe(optional(string()), description("Name for UMD / IIFE format outputs")),
2388
- globals: pipe(optional(union([record(string(), string()), GlobalsFunctionSchema])), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
2389
- externalLiveBindings: pipe(optional(boolean()), description("external live bindings")),
2390
- inlineDynamicImports: pipe(optional(boolean()), description("Inline dynamic imports")),
2391
- advancedChunks: optional(AdvancedChunksSchema),
2392
- comments: pipe(optional(union([literal("none"), literal("preserve-legal")])), description("Control comments in the output")),
2393
- target: pipe(optional(enum_(ESTarget)), description("The JavaScript target environment")),
2394
- plugins: optional(custom(() => true))
2395
- });
2396
- const getAddonDescription = (placement, wrapper) => {
2397
- return `Code to insert the ${ansis_default.bold(placement)} of the bundled file (${ansis_default.bold(wrapper)} the wrapper function)`;
2398
- };
2399
- const OutputCliOverrideSchema = strictObject({
2400
- assetFileNames: pipe(optional(string()), description("Name pattern for asset files")),
2401
- entryFileNames: pipe(optional(string()), description("Name pattern for emitted entry chunks")),
2402
- chunkFileNames: pipe(optional(string()), description("Name pattern for emitted secondary chunks")),
2403
- cssEntryFileNames: pipe(optional(string()), description("Name pattern for emitted css entry chunks")),
2404
- cssChunkFileNames: pipe(optional(string()), description("Name pattern for emitted css secondary chunks")),
2405
- sanitizeFileName: pipe(optional(boolean()), description("Sanitize file name")),
2406
- banner: pipe(optional(string()), description(getAddonDescription("top", "outside"))),
2407
- footer: pipe(optional(string()), description(getAddonDescription("bottom", "outside"))),
2408
- intro: pipe(optional(string()), description(getAddonDescription("top", "inside"))),
2409
- outro: pipe(optional(string()), description(getAddonDescription("bottom", "inside"))),
2410
- esModule: pipe(optional(boolean()), description("Always generate `__esModule` marks in non-ESM formats, defaults to `if-default-prop` (use `--no-esModule` to always disable)")),
2411
- globals: pipe(optional(record(string(), string())), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
2412
- advancedChunks: pipe(optional(strictObject({
2413
- minSize: pipe(optional(number()), description("Minimum size of the chunk")),
2414
- minShareCount: pipe(optional(number()), description("Minimum share count of the chunk"))
2415
- })), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
2416
- minify: pipe(optional(boolean()), description("Minify the bundled file"))
2417
- });
2418
- const OutputCliOptionsSchema = omit(strictObject({
2419
- ...OutputOptionsSchema.entries,
2420
- ...OutputCliOverrideSchema.entries
2421
- }), [
2422
- "sourcemapIgnoreList",
2423
- "sourcemapPathTransform",
2424
- "plugins"
2425
- ]);
2426
- const CliOptionsSchema = strictObject({
2427
- config: pipe(optional(union([string(), boolean()])), description("Path to the config file (default: `rolldown.config.js`)")),
2428
- help: pipe(optional(boolean()), description("Show help")),
2429
- version: pipe(optional(boolean()), description("Show version number")),
2430
- watch: pipe(optional(boolean()), description("Watch files in bundle and rebuild on changes")),
2431
- ...InputCliOptionsSchema.entries,
2432
- ...OutputCliOptionsSchema.entries
2433
- });
2434
- const inputHelperMsgRecord = { output: { ignored: true } };
2435
- const outputHelperMsgRecord = {};
2436
- function validateOption(key, options) {
2437
- if (globalThis.process?.env?.ROLLDOWN_OPTIONS_VALIDATION === "loose") return;
2438
- let parsed = safeParse(key === "input" ? InputOptionsSchema : OutputOptionsSchema, options);
2439
- if (!parsed.success) {
2440
- const errors = parsed.issues.map((issue) => {
2441
- const issuePaths = issue.path.map((path) => path.key);
2442
- let issueMsg = issue.message;
2443
- if (issue.type === "union") {
2444
- const subIssue = issue.issues?.find((i$1) => !(i$1.type !== issue.received && i$1.input === issue.input));
2445
- if (subIssue) {
2446
- if (subIssue.path) issuePaths.push(subIssue.path.map((path) => path.key));
2447
- issueMsg = subIssue.message;
2448
- }
2449
- }
2450
- const stringPath = issuePaths.join(".");
2451
- const helper = key === "input" ? inputHelperMsgRecord[stringPath] : outputHelperMsgRecord[stringPath];
2452
- if (helper && helper.ignored) return "";
2453
- return `- For the "${stringPath}". ${issueMsg}. ${helper ? helper.msg : ""}`;
2454
- }).filter(Boolean);
2455
- if (errors.length) throw new Error(`Failed validate ${key} options.\n` + errors.join("\n"));
2456
- }
2457
- }
2458
-
2459
- //#endregion
2460
- //#region src/constants/plugin-context.ts
2461
- const SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF = Symbol("plugin-context-resolve-caller");
2462
-
2463
- //#endregion
2464
- //#region src/options/normalized-input-options.ts
2465
- var NormalizedInputOptionsImpl = class {
2466
- inner;
2467
- constructor(inner, onLog) {
2468
- this.onLog = onLog;
2469
- this.inner = inner;
2470
- }
2471
- get shimMissingExports() {
2472
- return this.inner.shimMissingExports;
2473
- }
2474
- get input() {
2475
- return this.inner.input;
2476
- }
2477
- get cwd() {
2478
- return this.inner.cwd ?? void 0;
2479
- }
2480
- get platform() {
2481
- return this.inner.platform;
2482
- }
2483
- };
2484
-
2485
- //#endregion
2486
- //#region src/types/sourcemap.ts
2487
- function bindingifySourcemap$1(map) {
2488
- if (map == null) return;
2489
- return { inner: typeof map === "string" ? map : {
2490
- file: map.file ?? void 0,
2491
- mappings: map.mappings,
2492
- sourceRoot: "sourceRoot" in map ? map.sourceRoot ?? void 0 : void 0,
2493
- sources: map.sources?.map((s$1) => s$1 ?? void 0),
2494
- sourcesContent: map.sourcesContent?.map((s$1) => s$1 ?? void 0),
2495
- names: map.names,
2496
- x_google_ignoreList: map.x_google_ignoreList,
2497
- debugId: "debugId" in map ? map.debugId : void 0
2498
- } };
2499
- }
2500
-
2501
- //#endregion
2502
- //#region src/utils/error.ts
2503
- function normalizeErrors(rawErrors) {
2504
- const errors = rawErrors.map((e$1) => e$1 instanceof Error ? e$1 : Object.assign(new Error(), {
2505
- kind: e$1.kind,
2506
- message: e$1.message,
2507
- stack: void 0
2508
- }));
2509
- let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
2510
- for (let i$1 = 0; i$1 < errors.length; i$1++) {
2511
- summary += "\n";
2512
- if (i$1 >= 5) {
2513
- summary += "...";
2514
- break;
2515
- }
2516
- summary += getErrorMessage(errors[i$1]);
2517
- }
2518
- const wrapper = new Error(summary);
2519
- Object.defineProperty(wrapper, "errors", {
2520
- configurable: true,
2521
- enumerable: true,
2522
- get: () => errors,
2523
- set: (value) => Object.defineProperty(wrapper, "errors", {
2524
- configurable: true,
2525
- enumerable: true,
2526
- value
2527
- })
2528
- });
2529
- return wrapper;
2530
- }
2531
- function getErrorMessage(e$1) {
2532
- if (Object.hasOwn(e$1, "kind")) return e$1.message;
2533
- let s$1 = "";
2534
- if (e$1.plugin) s$1 += `[plugin ${e$1.plugin}]`;
2535
- const id = e$1.id ?? e$1.loc?.file;
2536
- if (id) {
2537
- s$1 += " " + id;
2538
- if (e$1.loc) s$1 += `:${e$1.loc.line}:${e$1.loc.column}`;
2539
- }
2540
- if (s$1) s$1 += "\n";
2541
- const message = `${e$1.name ?? "Error"}: ${e$1.message}`;
2542
- s$1 += message;
2543
- if (e$1.frame) s$1 = joinNewLine(s$1, e$1.frame);
2544
- if (e$1.stack) s$1 = joinNewLine(s$1, e$1.stack.replace(message, ""));
2545
- return s$1;
2546
- }
2547
- function joinNewLine(s1, s2) {
2548
- return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
2549
- }
2550
-
2551
- //#endregion
2552
- //#region src/utils/resolved-external.ts
2553
- function transformResolvedExternal(bindingResolvedExternal$1) {
2554
- switch (bindingResolvedExternal$1.type) {
2555
- case "Bool": return bindingResolvedExternal$1.field0;
2556
- case "Absolute": return "absolute";
2557
- case "Relative": unreachable(`The PluginContext resolve result external couldn't be 'relative'`);
2558
- }
2559
- }
2560
- function bindingResolvedExternal(external) {
2561
- if (typeof external === "boolean") return {
2562
- type: "Bool",
2563
- field0: external
2564
- };
2565
- if (external === "absolute") return { type: "Absolute" };
2566
- if (external === "relative") return { type: "Relative" };
2567
- }
2568
-
2569
- //#endregion
2570
- //#region src/utils/transform-module-info.ts
2571
- function transformModuleInfo(info, option) {
2572
- return {
2573
- get ast() {
2574
- return unsupported("ModuleInfo#ast");
2575
- },
2576
- get code() {
2577
- return info.code;
2578
- },
2579
- id: info.id,
2580
- importers: info.importers,
2581
- dynamicImporters: info.dynamicImporters,
2582
- importedIds: info.importedIds,
2583
- dynamicallyImportedIds: info.dynamicallyImportedIds,
2584
- exports: info.exports,
2585
- isEntry: info.isEntry,
2586
- ...option
2587
- };
2588
- }
2589
-
2590
- //#endregion
2591
- //#region src/utils/transform-side-effects.ts
2592
- function bindingifySideEffects(sideEffects) {
2593
- switch (sideEffects) {
2594
- case true: return BindingHookSideEffects.True;
2595
- case false: return BindingHookSideEffects.False;
2596
- case "no-treeshake": return BindingHookSideEffects.NoTreeshake;
2597
- case null:
2598
- case void 0: return void 0;
2599
- default: throw new Error(`Unexpected side effects: ${sideEffects}`);
2600
- }
2601
- }
2602
-
2603
- //#endregion
2604
- //#region src/utils/transform-sourcemap.ts
2605
- function isEmptySourcemapFiled(array$1) {
2606
- if (!array$1) return true;
2607
- if (array$1.length === 0 || !array$1[0]) return true;
2608
- return false;
2609
- }
2610
- function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
2611
- if (!rawMap) return;
2612
- let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
2613
- if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
2614
- if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
2615
- return map;
2616
- }
2617
-
2618
- //#endregion
2619
- //#region src/plugin/bindingify-hook-filter.ts
2620
- function bindingifyStringFilter(matcher) {
2621
- if (typeof matcher === "string" || matcher instanceof RegExp) return { include: [matcher] };
2622
- if (Array.isArray(matcher)) return { include: matcher };
2623
- return {
2624
- include: matcher.include ? arraify(matcher.include) : void 0,
2625
- exclude: matcher.exclude ? arraify(matcher.exclude) : void 0
2626
- };
2627
- }
2628
- function bindingifyResolveIdFilter(filterOption) {
2629
- return filterOption?.id ? bindingifyStringFilter(filterOption.id) : void 0;
2630
- }
2631
- function bindingifyLoadFilter(filterOption) {
2632
- return filterOption?.id ? bindingifyStringFilter(filterOption.id) : void 0;
2633
- }
2634
- function bindingifyTransformFilter(filterOption) {
2635
- if (!filterOption) return void 0;
2636
- const { id, code, moduleType } = filterOption;
2637
- let moduleTypeRet;
2638
- if (moduleType) if (Array.isArray(moduleType)) moduleTypeRet = moduleType;
2639
- else moduleTypeRet = moduleType.include;
2640
- return {
2641
- id: id ? bindingifyStringFilter(id) : void 0,
2642
- code: code ? bindingifyStringFilter(code) : void 0,
2643
- moduleType: moduleTypeRet
2644
- };
2645
- }
2646
-
2647
- //#endregion
2648
- //#region src/plugin/bindingify-plugin-hook-meta.ts
2649
- function bindingifyPluginHookMeta(options) {
2650
- return { order: bindingPluginOrder(options.order) };
2651
- }
2652
- function bindingPluginOrder(order) {
2653
- switch (order) {
2654
- case "post": return BindingPluginOrder.Post;
2655
- case "pre": return BindingPluginOrder.Pre;
2656
- case null:
2657
- case void 0: return void 0;
2658
- default: throw new Error(`Unknown plugin order: ${order}`);
2659
- }
2660
- }
2661
-
2662
- //#endregion
2663
- //#region ../../node_modules/.pnpm/oxc-parser@0.63.0/node_modules/oxc-parser/wrap.mjs
2664
- function wrap$1(result) {
2665
- let program, module$1, comments, errors;
2666
- return {
2667
- get program() {
2668
- if (!program) program = jsonParseAst(result.program);
2669
- return program;
2670
- },
2671
- get module() {
2672
- if (!module$1) module$1 = result.module;
2673
- return module$1;
2674
- },
2675
- get comments() {
2676
- if (!comments) comments = result.comments;
2677
- return comments;
2678
- },
2679
- get errors() {
2680
- if (!errors) errors = result.errors;
2681
- return errors;
2682
- }
2683
- };
2684
- }
2685
- function jsonParseAst(ast) {
2686
- return JSON.parse(ast, function(key, value) {
2687
- if (value === null && key === "value" && Object.hasOwn(this, "type") && this.type === "Literal") {
2688
- if (Object.hasOwn(this, "bigint")) return BigInt(this.bigint);
2689
- if (Object.hasOwn(this, "regex")) {
2690
- const { regex } = this;
2691
- try {
2692
- return RegExp(regex.pattern, regex.flags);
2693
- } catch (_err) {}
2694
- }
2695
- }
2696
- return value;
2697
- });
2698
- }
2699
-
2700
- //#endregion
2701
- //#region src/parse-ast-index.ts
2702
- function wrap(result, sourceText) {
2703
- result = wrap$1(result);
2704
- if (result.errors.length > 0) return normalizeParseError(sourceText, result.errors);
2705
- return result.program;
2706
- }
2707
- function normalizeParseError(sourceText, errors) {
2708
- let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
2709
- for (let i$1 = 0; i$1 < errors.length; i$1++) {
2710
- if (i$1 >= 5) {
2711
- message += "\n...";
2712
- break;
2713
- }
2714
- const e$1 = errors[i$1];
2715
- message += e$1.message + "\n" + e$1.labels.map((label) => {
2716
- const location = locate(sourceText, label.start, { offsetLine: 1 });
2717
- if (!location) return;
2718
- return getCodeFrame(sourceText, location.line, location.column);
2719
- }).filter(Boolean).join("\n");
2720
- }
2721
- return error(logParseError(message));
2722
- }
2723
- const defaultParserOptions = {
2724
- lang: "js",
2725
- preserveParens: false
2726
- };
2727
- function parseAst(sourceText, options, filename) {
2728
- return wrap(parseSync(filename ?? "file.js", sourceText, {
2729
- ...defaultParserOptions,
2730
- ...options
2731
- }), sourceText);
2732
- }
2733
-
2734
- //#endregion
2735
- //#region src/utils/asset-source.ts
2736
- function transformAssetSource(bindingAssetSource$1) {
2737
- return bindingAssetSource$1.inner;
2738
- }
2739
- function bindingAssetSource(source) {
2740
- return { inner: source };
2741
- }
2742
-
2743
- //#endregion
2744
- //#region src/plugin/plugin-context.ts
2745
- var PluginContextImpl = class extends MinimalPluginContextImpl {
2746
- getModuleInfo;
2747
- constructor(outputOptions, context, plugin, data, onLog, logLevel, watchMode, currentLoadingModule) {
2748
- super(onLog, logLevel, plugin.name, watchMode);
2749
- this.outputOptions = outputOptions;
2750
- this.context = context;
2751
- this.data = data;
2752
- this.onLog = onLog;
2753
- this.currentLoadingModule = currentLoadingModule;
2754
- this.getModuleInfo = (id) => this.data.getModuleInfo(id, context);
2755
- }
2756
- async load(options) {
2757
- const id = options.id;
2758
- if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
2759
- const moduleInfo = this.data.getModuleInfo(id, this.context);
2760
- if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
2761
- const rawOptions = {
2762
- meta: options.meta || {},
2763
- moduleSideEffects: options.moduleSideEffects || null,
2764
- invalidate: false
2765
- };
2766
- this.data.updateModuleOption(id, rawOptions);
2767
- async function createLoadModulePromise(context, data) {
2768
- const loadPromise = data.loadModulePromiseMap.get(id);
2769
- if (loadPromise) return loadPromise;
2770
- let resolveFn;
2771
- const promise$1 = new Promise((resolve$1, _$1) => {
2772
- resolveFn = resolve$1;
2773
- });
2774
- data.loadModulePromiseMap.set(id, promise$1);
2775
- try {
2776
- await context.load(id, bindingifySideEffects(options.moduleSideEffects), (_success) => {
2777
- resolveFn();
2778
- });
2779
- } finally {
2780
- data.loadModulePromiseMap.delete(id);
2781
- }
2782
- return promise$1;
2783
- }
2784
- await createLoadModulePromise(this.context, this.data);
2785
- return this.data.getModuleInfo(id, this.context);
2786
- }
2787
- async resolve(source, importer, options) {
2788
- let receipt = void 0;
2789
- if (options != null) receipt = this.data.saveResolveOptions(options);
2790
- const res = await this.context.resolve(source, importer, {
2791
- custom: receipt,
2792
- skipSelf: options?.skipSelf
2793
- });
2794
- if (receipt != null) this.data.removeSavedResolveOptions(receipt);
2795
- if (res == null) return null;
2796
- const info = this.data.getModuleOption(res.id) || {};
2797
- return {
2798
- ...res,
2799
- external: transformResolvedExternal(res.external),
2800
- ...info
2801
- };
2802
- }
2803
- emitFile = (file) => {
2804
- if (file.type === "prebuilt-chunk") return unimplemented("PluginContext.emitFile with type prebuilt-chunk");
2805
- if (file.type === "chunk") return this.context.emitChunk(file);
2806
- const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== "function" ? void 0 : this.outputOptions.sanitizeFileName(file.name || "asset");
2807
- const filename = file.fileName ? void 0 : this.getAssetFileNames(file);
2808
- return this.context.emitFile({
2809
- ...file,
2810
- originalFileName: file.originalFileName || void 0,
2811
- source: bindingAssetSource(file.source)
2812
- }, filename, fnSanitizedFileName);
2813
- };
2814
- getAssetFileNames(file) {
2815
- if (typeof this.outputOptions.assetFileNames === "function") return this.outputOptions.assetFileNames({
2816
- names: file.name ? [file.name] : [],
2817
- originalFileNames: file.originalFileName ? [file.originalFileName] : [],
2818
- source: file.source,
2819
- type: "asset"
2820
- });
2821
- }
2822
- getFileName(referenceId) {
2823
- return this.context.getFileName(referenceId);
2824
- }
2825
- getModuleIds() {
2826
- return this.data.getModuleIds(this.context);
2827
- }
2828
- addWatchFile(id) {
2829
- this.context.addWatchFile(id);
2830
- }
2831
- parse(input, options) {
2832
- return parseAst(input, options);
2833
- }
2834
- };
2835
-
2836
- //#endregion
2837
- //#region src/plugin/transform-plugin-context.ts
2838
- var TransformPluginContextImpl = class extends PluginContextImpl {
2839
- constructor(outputOptions, context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption, watchMode) {
2840
- super(outputOptions, context, plugin, data, onLog, LogLevelOption, watchMode, moduleId);
2841
- this.inner = inner;
2842
- this.moduleId = moduleId;
2843
- this.moduleSource = moduleSource;
2844
- const getLogHandler$1 = (handler) => (log, pos) => {
2845
- log = normalizeLog(log);
2846
- if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
2847
- log.id = moduleId;
2848
- log.hook = "transform";
2849
- handler(log);
2850
- };
2851
- this.debug = getLogHandler$1(this.debug);
2852
- this.warn = getLogHandler$1(this.warn);
2853
- this.info = getLogHandler$1(this.info);
2854
- }
2855
- error(e$1, pos) {
2856
- if (typeof e$1 === "string") e$1 = { message: e$1 };
2857
- if (pos) augmentCodeLocation(e$1, pos, this.moduleSource, this.moduleId);
2858
- e$1.id = this.moduleId;
2859
- e$1.hook = "transform";
2860
- return error(logPluginError(normalizeLog(e$1), this.pluginName));
2861
- }
2862
- getCombinedSourcemap() {
2863
- return JSON.parse(this.inner.getCombinedSourcemap());
2864
- }
2865
- };
2866
-
2867
- //#endregion
2868
- //#region src/plugin/bindingify-build-hooks.ts
2869
- function bindingifyBuildStart(args$1) {
2870
- const hook = args$1.plugin.buildStart;
2871
- if (!hook) return {};
2872
- const { handler, meta } = normalizeHook(hook);
2873
- return {
2874
- plugin: async (ctx, opts) => {
2875
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), new NormalizedInputOptionsImpl(opts, args$1.onLog));
2876
- },
2877
- meta: bindingifyPluginHookMeta(meta)
2878
- };
2879
- }
2880
- function bindingifyBuildEnd(args$1) {
2881
- const hook = args$1.plugin.buildEnd;
2882
- if (!hook) return {};
2883
- const { handler, meta } = normalizeHook(hook);
2884
- return {
2885
- plugin: async (ctx, err) => {
2886
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), err ? normalizeErrors(err) : void 0);
2887
- },
2888
- meta: bindingifyPluginHookMeta(meta)
2889
- };
2890
- }
2891
- function bindingifyResolveId(args$1) {
2892
- const hook = args$1.plugin.resolveId;
2893
- if (!hook) return {};
2894
- const { handler, meta, options } = normalizeHook(hook);
2895
- return {
2896
- plugin: async (ctx, specifier, importer, extraOptions) => {
2897
- const contextResolveOptions = extraOptions.custom != null ? args$1.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
2898
- const newExtraOptions = {
2899
- ...extraOptions,
2900
- custom: contextResolveOptions?.custom,
2901
- [SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]: contextResolveOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]
2902
- };
2903
- const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), specifier, importer ?? void 0, newExtraOptions);
2904
- if (ret == null) return;
2905
- if (ret === false) return {
2906
- id: specifier,
2907
- external: bindingResolvedExternal(true),
2908
- normalizeExternalId: true
2909
- };
2910
- if (typeof ret === "string") return {
2911
- id: ret,
2912
- normalizeExternalId: true
2913
- };
2914
- let exist = args$1.pluginContextData.updateModuleOption(ret.id, {
2915
- meta: ret.meta || {},
2916
- moduleSideEffects: ret.moduleSideEffects ?? null,
2917
- invalidate: false
2918
- });
2919
- return {
2920
- id: ret.id,
2921
- external: bindingResolvedExternal(ret.external),
2922
- normalizeExternalId: false,
2923
- sideEffects: bindingifySideEffects(exist.moduleSideEffects)
2924
- };
2925
- },
2926
- meta: bindingifyPluginHookMeta(meta),
2927
- filter: bindingifyResolveIdFilter(options.filter)
2928
- };
2929
- }
2930
- function bindingifyResolveDynamicImport(args$1) {
2931
- const hook = args$1.plugin.resolveDynamicImport;
2932
- if (!hook) return {};
2933
- const { handler, meta } = normalizeHook(hook);
2934
- return {
2935
- plugin: async (ctx, specifier, importer) => {
2936
- const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), specifier, importer ?? void 0);
2937
- if (ret == null) return;
2938
- if (ret === false) return {
2939
- id: specifier,
2940
- external: bindingResolvedExternal(true)
2941
- };
2942
- if (typeof ret === "string") return { id: ret };
2943
- const result = {
2944
- id: ret.id,
2945
- external: bindingResolvedExternal(ret.external)
2946
- };
2947
- if (ret.moduleSideEffects !== null) result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
2948
- args$1.pluginContextData.updateModuleOption(ret.id, {
2949
- meta: ret.meta || {},
2950
- moduleSideEffects: ret.moduleSideEffects || null,
2951
- invalidate: false
2952
- });
2953
- return result;
2954
- },
2955
- meta: bindingifyPluginHookMeta(meta)
2956
- };
2957
- }
2958
- function bindingifyTransform(args$1) {
2959
- const hook = args$1.plugin.transform;
2960
- if (!hook) return {};
2961
- const { handler, meta, options } = normalizeHook(hook);
2962
- return {
2963
- plugin: async (ctx, code, id, meta$1) => {
2964
- const ret = await handler.call(new TransformPluginContextImpl(args$1.outputOptions, ctx.inner(), args$1.plugin, args$1.pluginContextData, ctx, id, code, args$1.onLog, args$1.logLevel, args$1.watchMode), code, id, meta$1);
2965
- if (ret == null) return void 0;
2966
- if (typeof ret === "string") return { code: ret };
2967
- let moduleOption = args$1.pluginContextData.updateModuleOption(id, {
2968
- meta: ret.meta ?? {},
2969
- moduleSideEffects: ret.moduleSideEffects ?? null,
2970
- invalidate: false
2971
- });
2972
- return {
2973
- code: ret.code,
2974
- map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id, code, ret.map)),
2975
- sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects),
2976
- moduleType: ret.moduleType
2977
- };
2978
- },
2979
- meta: bindingifyPluginHookMeta(meta),
2980
- filter: bindingifyTransformFilter(options.filter)
2981
- };
2982
- }
2983
- function bindingifyLoad(args$1) {
2984
- const hook = args$1.plugin.load;
2985
- if (!hook) return {};
2986
- const { handler, meta, options } = normalizeHook(hook);
2987
- return {
2988
- plugin: async (ctx, id) => {
2989
- const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode, id), id);
2990
- if (ret == null) return;
2991
- if (typeof ret === "string") return { code: ret };
2992
- let moduleOption = args$1.pluginContextData.updateModuleOption(id, {
2993
- meta: ret.meta || {},
2994
- moduleSideEffects: ret.moduleSideEffects ?? null,
2995
- invalidate: false
2996
- });
2997
- let map = preProcessSourceMap(ret, id);
2998
- return {
2999
- code: ret.code,
3000
- map: bindingifySourcemap$1(map),
3001
- moduleType: ret.moduleType,
3002
- sideEffects: bindingifySideEffects(moduleOption.moduleSideEffects)
3003
- };
3004
- },
3005
- meta: bindingifyPluginHookMeta(meta),
3006
- filter: bindingifyLoadFilter(options.filter)
3007
- };
3008
- }
3009
- function preProcessSourceMap(ret, id) {
3010
- if (!ret.map) return;
3011
- let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
3012
- if (!isEmptySourcemapFiled(map.sources)) {
3013
- const directory = posix.dirname(id) || ".";
3014
- const sourceRoot = map.sourceRoot || ".";
3015
- map.sources = map.sources.map((source) => posix.resolve(directory, sourceRoot, source));
3016
- }
3017
- return map;
3018
- }
3019
- function bindingifyModuleParsed(args$1) {
3020
- const hook = args$1.plugin.moduleParsed;
3021
- if (!hook) return {};
3022
- const { handler, meta } = normalizeHook(hook);
3023
- return {
3024
- plugin: async (ctx, moduleInfo) => {
3025
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformModuleInfo(moduleInfo, args$1.pluginContextData.getModuleOption(moduleInfo.id)));
3026
- },
3027
- meta: bindingifyPluginHookMeta(meta)
3028
- };
3029
- }
3030
-
3031
- //#endregion
3032
- //#region src/utils/transform-rendered-module.ts
3033
- function transformToRenderedModule(bindingRenderedModule) {
3034
- return {
3035
- get code() {
3036
- return bindingRenderedModule.code;
3037
- },
3038
- get renderedLength() {
3039
- return bindingRenderedModule.code?.length || 0;
3040
- },
3041
- get renderedExports() {
3042
- return bindingRenderedModule.renderedExports;
3043
- }
3044
- };
3045
- }
3046
-
3047
- //#endregion
3048
- //#region src/utils/transform-rendered-chunk.ts
3049
- function transformRenderedChunk(chunk) {
3050
- let modules = null;
3051
- return {
3052
- get name() {
3053
- return chunk.name;
3054
- },
3055
- get isEntry() {
3056
- return chunk.isEntry;
3057
- },
3058
- get isDynamicEntry() {
3059
- return chunk.isDynamicEntry;
3060
- },
3061
- get facadeModuleId() {
3062
- return chunk.facadeModuleId;
3063
- },
3064
- get moduleIds() {
3065
- return chunk.moduleIds;
3066
- },
3067
- get exports() {
3068
- return chunk.exports;
3069
- },
3070
- get fileName() {
3071
- return chunk.fileName;
3072
- },
3073
- get imports() {
3074
- return chunk.imports;
3075
- },
3076
- get dynamicImports() {
3077
- return chunk.dynamicImports;
3078
- },
3079
- get modules() {
3080
- if (!modules) modules = transformChunkModules(chunk.modules);
3081
- return modules;
3082
- }
3083
- };
3084
- }
3085
- function transformChunkModules(modules) {
3086
- const result = {};
3087
- for (let i$1 = 0; i$1 < modules.values.length; i$1++) {
3088
- let key = modules.keys[i$1];
3089
- const mod = modules.values[i$1];
3090
- result[key] = transformToRenderedModule(mod);
3091
- }
3092
- return result;
3093
- }
3094
-
3095
- //#endregion
3096
- //#region src/utils/bindingify-output-options.ts
3097
- function bindingifyOutputOptions(outputOptions) {
3098
- const { dir, format: format$1, exports, hashCharacters, sourcemap, sourcemapDebugIds, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, intro, outro, esModule, globals, file, sanitizeFileName } = outputOptions;
3099
- return {
3100
- dir,
3101
- file: file == null ? void 0 : file,
3102
- format: bindingifyFormat(format$1),
3103
- exports,
3104
- hashCharacters,
3105
- sourcemap: bindingifySourcemap(sourcemap),
3106
- sourcemapDebugIds,
3107
- sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
3108
- sourcemapPathTransform,
3109
- banner: bindingifyAddon(banner),
3110
- footer: bindingifyAddon(footer),
3111
- intro: bindingifyAddon(intro),
3112
- outro: bindingifyAddon(outro),
3113
- extend: outputOptions.extend,
3114
- globals,
3115
- esModule,
3116
- name,
3117
- assetFileNames: bindingifyAssetFilenames(assetFileNames),
3118
- entryFileNames,
3119
- chunkFileNames,
3120
- cssEntryFileNames,
3121
- cssChunkFileNames,
3122
- plugins: [],
3123
- minify: outputOptions.minify,
3124
- externalLiveBindings: outputOptions.externalLiveBindings,
3125
- inlineDynamicImports: outputOptions.inlineDynamicImports,
3126
- advancedChunks: outputOptions.advancedChunks,
3127
- polyfillRequire: outputOptions.polyfillRequire,
3128
- target: outputOptions.target,
3129
- sanitizeFileName
3130
- };
3131
- }
3132
- function bindingifyAddon(configAddon) {
3133
- return async (chunk) => {
3134
- if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
3135
- return configAddon || "";
3136
- };
3137
- }
3138
- function bindingifyFormat(format$1) {
3139
- switch (format$1) {
3140
- case void 0:
3141
- case "es":
3142
- case "esm":
3143
- case "module": return "es";
3144
- case "cjs":
3145
- case "commonjs": return "cjs";
3146
- case "iife": return "iife";
3147
- case "umd": return "umd";
3148
- case "experimental-app": return "app";
3149
- default: unimplemented(`output.format: ${format$1}`);
3150
- }
3151
- }
3152
- function bindingifySourcemap(sourcemap) {
3153
- switch (sourcemap) {
3154
- case true: return "file";
3155
- case "inline": return "inline";
3156
- case false:
3157
- case void 0: return void 0;
3158
- case "hidden": return "hidden";
3159
- default: throw new Error(`unknown sourcemap: ${sourcemap}`);
3160
- }
3161
- }
3162
- function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
3163
- return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
3164
- }
3165
- function bindingifyAssetFilenames(assetFileNames) {
3166
- if (typeof assetFileNames === "function") return (asset) => {
3167
- return assetFileNames({
3168
- names: asset.names,
3169
- originalFileNames: asset.originalFileNames,
3170
- source: transformAssetSource(asset.source),
3171
- type: "asset"
3172
- });
3173
- };
3174
- return assetFileNames;
3175
- }
3176
-
3177
- //#endregion
3178
- //#region src/options/normalized-output-options.ts
3179
- var NormalizedOutputOptionsImpl = class {
3180
- constructor(inner, outputOptions, normalizedOutputPlugins) {
3181
- this.inner = inner;
3182
- this.outputOptions = outputOptions;
3183
- this.normalizedOutputPlugins = normalizedOutputPlugins;
3184
- }
3185
- get dir() {
3186
- return this.inner.dir ?? void 0;
3187
- }
3188
- get entryFileNames() {
3189
- return this.inner.entryFilenames || this.outputOptions.entryFileNames;
3190
- }
3191
- get chunkFileNames() {
3192
- return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
3193
- }
3194
- get assetFileNames() {
3195
- return this.inner.assetFilenames || this.outputOptions.assetFileNames;
3196
- }
3197
- get format() {
3198
- return this.inner.format;
3199
- }
3200
- get exports() {
3201
- return this.inner.exports;
3202
- }
3203
- get sourcemap() {
3204
- return this.inner.sourcemap;
3205
- }
3206
- get cssEntryFileNames() {
3207
- return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
3208
- }
3209
- get cssChunkFileNames() {
3210
- return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
3211
- }
3212
- get shimMissingExports() {
3213
- return this.inner.shimMissingExports;
3214
- }
3215
- get name() {
3216
- return this.inner.name ?? void 0;
3217
- }
3218
- get file() {
3219
- return this.inner.file ?? void 0;
3220
- }
3221
- get inlineDynamicImports() {
3222
- return this.inner.inlineDynamicImports;
3223
- }
3224
- get externalLiveBindings() {
3225
- return this.inner.externalLiveBindings;
3226
- }
3227
- get banner() {
3228
- return normalizeAddon(this.outputOptions.banner);
3229
- }
3230
- get footer() {
3231
- return normalizeAddon(this.outputOptions.footer);
3232
- }
3233
- get intro() {
3234
- return normalizeAddon(this.outputOptions.intro);
3235
- }
3236
- get outro() {
3237
- return normalizeAddon(this.outputOptions.outro);
3238
- }
3239
- get esModule() {
3240
- return this.inner.esModule;
3241
- }
3242
- get extend() {
3243
- return this.inner.extend;
3244
- }
3245
- get globals() {
3246
- return this.inner.globals || this.outputOptions.globals;
3247
- }
3248
- get hashCharacters() {
3249
- return this.inner.hashCharacters;
3250
- }
3251
- get sourcemapDebugIds() {
3252
- return this.inner.sourcemapDebugIds;
3253
- }
3254
- get sourcemapIgnoreList() {
3255
- return bindingifySourcemapIgnoreList(this.outputOptions.sourcemapIgnoreList);
3256
- }
3257
- get sourcemapPathTransform() {
3258
- return this.outputOptions.sourcemapPathTransform;
3259
- }
3260
- get minify() {
3261
- return this.inner.minify;
3262
- }
3263
- get comments() {
3264
- return this.inner.comments;
3265
- }
3266
- get polyfillRequire() {
3267
- return this.inner.polyfillRequire;
3268
- }
3269
- get plugins() {
3270
- return this.normalizedOutputPlugins;
3271
- }
3272
- };
3273
- function normalizeAddon(value) {
3274
- if (typeof value === "function") return value;
3275
- return () => value || "";
3276
- }
3277
-
3278
- //#endregion
3279
- //#region src/utils/transform-to-rollup-output.ts
3280
- function transformToRollupSourceMap(map) {
3281
- const parsed = JSON.parse(map);
3282
- const obj = {
3283
- ...parsed,
3284
- toString() {
3285
- return JSON.stringify(obj);
3286
- },
3287
- toUrl() {
3288
- return `data:application/json;charset=utf-8;base64,${Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
3289
- }
3290
- };
3291
- return obj;
3292
- }
3293
- function transformToRollupOutputChunk(bindingChunk, changed) {
3294
- const chunk = {
3295
- type: "chunk",
3296
- get code() {
3297
- return bindingChunk.code;
3298
- },
3299
- fileName: bindingChunk.fileName,
3300
- name: bindingChunk.name,
3301
- get modules() {
3302
- return transformChunkModules(bindingChunk.modules);
3303
- },
3304
- get imports() {
3305
- return bindingChunk.imports;
3306
- },
3307
- get dynamicImports() {
3308
- return bindingChunk.dynamicImports;
3309
- },
3310
- exports: bindingChunk.exports,
3311
- isEntry: bindingChunk.isEntry,
3312
- facadeModuleId: bindingChunk.facadeModuleId || null,
3313
- isDynamicEntry: bindingChunk.isDynamicEntry,
3314
- get moduleIds() {
3315
- return bindingChunk.moduleIds;
3316
- },
3317
- get map() {
3318
- return bindingChunk.map ? transformToRollupSourceMap(bindingChunk.map) : null;
3319
- },
3320
- sourcemapFileName: bindingChunk.sourcemapFileName || null,
3321
- preliminaryFileName: bindingChunk.preliminaryFileName
3322
- };
3323
- const cache = {};
3324
- return new Proxy(chunk, {
3325
- get(target, p$1) {
3326
- if (p$1 in cache) return cache[p$1];
3327
- const value = target[p$1];
3328
- cache[p$1] = value;
3329
- return value;
3330
- },
3331
- set(target, p$1, newValue) {
3332
- cache[p$1] = newValue;
3333
- changed?.updated.add(bindingChunk.fileName);
3334
- return true;
3335
- },
3336
- has(target, p$1) {
3337
- if (p$1 in cache) return true;
3338
- return p$1 in target;
3339
- }
3340
- });
3341
- }
3342
- function transformToRollupOutputAsset(bindingAsset, changed) {
3343
- const asset = {
3344
- type: "asset",
3345
- fileName: bindingAsset.fileName,
3346
- originalFileName: bindingAsset.originalFileName || null,
3347
- originalFileNames: bindingAsset.originalFileNames,
3348
- get source() {
3349
- return transformAssetSource(bindingAsset.source);
3350
- },
3351
- name: bindingAsset.name ?? void 0,
3352
- names: bindingAsset.names
3353
- };
3354
- const cache = {};
3355
- return new Proxy(asset, {
3356
- get(target, p$1) {
3357
- if (p$1 in cache) return cache[p$1];
3358
- const value = target[p$1];
3359
- cache[p$1] = value;
3360
- return value;
3361
- },
3362
- set(target, p$1, newValue) {
3363
- cache[p$1] = newValue;
3364
- changed?.updated.add(bindingAsset.fileName);
3365
- return true;
3366
- }
3367
- });
3368
- }
3369
- function transformToRollupOutput(output, changed) {
3370
- handleOutputErrors(output);
3371
- const { chunks, assets } = output;
3372
- return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToRollupOutputAsset(asset, changed))] };
3373
- }
3374
- function handleOutputErrors(output) {
3375
- const rawErrors = output.errors;
3376
- if (rawErrors.length > 0) throw normalizeErrors(rawErrors);
3377
- }
3378
- function transformToOutputBundle(output, changed) {
3379
- const bundle = Object.fromEntries(transformToRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
3380
- return new Proxy(bundle, { deleteProperty(target, property) {
3381
- if (typeof property === "string") changed.deleted.add(property);
3382
- return true;
3383
- } });
3384
- }
3385
- function collectChangedBundle(changed, bundle) {
3386
- const assets = [];
3387
- const chunks = [];
3388
- for (const key in bundle) {
3389
- if (changed.deleted.has(key) || !changed.updated.has(key)) continue;
3390
- const item = bundle[key];
3391
- if (item.type === "asset") assets.push({
3392
- filename: item.fileName,
3393
- originalFileNames: item.originalFileNames,
3394
- source: bindingAssetSource(item.source),
3395
- names: item.names
3396
- });
3397
- else chunks.push({
3398
- code: item.code,
3399
- filename: item.fileName,
3400
- name: item.name,
3401
- isEntry: item.isEntry,
3402
- exports: item.exports,
3403
- modules: {},
3404
- imports: item.imports,
3405
- dynamicImports: item.dynamicImports,
3406
- facadeModuleId: item.facadeModuleId || void 0,
3407
- isDynamicEntry: item.isDynamicEntry,
3408
- moduleIds: item.moduleIds,
3409
- map: bindingifySourcemap$1(item.map),
3410
- sourcemapFilename: item.sourcemapFileName || void 0,
3411
- preliminaryFilename: item.preliminaryFileName
3412
- });
3413
- }
3414
- return {
3415
- assets,
3416
- chunks,
3417
- deleted: Array.from(changed.deleted)
3418
- };
3419
- }
3420
-
3421
- //#endregion
3422
- //#region src/plugin/bindingify-output-hooks.ts
3423
- function bindingifyRenderStart(args$1) {
3424
- const hook = args$1.plugin.renderStart;
3425
- if (!hook) return {};
3426
- const { handler, meta } = normalizeHook(hook);
3427
- return {
3428
- plugin: async (ctx, opts) => {
3429
- handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), new NormalizedOutputOptionsImpl(opts, args$1.outputOptions, args$1.normalizedOutputPlugins), new NormalizedInputOptionsImpl(opts, args$1.onLog));
3430
- },
3431
- meta: bindingifyPluginHookMeta(meta)
3432
- };
3433
- }
3434
- function bindingifyRenderChunk(args$1) {
3435
- const hook = args$1.plugin.renderChunk;
3436
- if (!hook) return {};
3437
- const { handler, meta } = normalizeHook(hook);
3438
- return {
3439
- plugin: async (ctx, code, chunk, opts, meta$1) => {
3440
- if (args$1.pluginContextData.getRenderChunkMeta() == null) args$1.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta$1.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
3441
- const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), code, transformRenderedChunk(chunk), new NormalizedOutputOptionsImpl(opts, args$1.outputOptions, args$1.normalizedOutputPlugins), args$1.pluginContextData.getRenderChunkMeta());
3442
- if (ret == null) return;
3443
- if (typeof ret === "string") return { code: ret };
3444
- if (!ret.map) return { code: ret.code };
3445
- return {
3446
- code: ret.code,
3447
- map: bindingifySourcemap$1(ret.map)
3448
- };
3449
- },
3450
- meta: bindingifyPluginHookMeta(meta)
3451
- };
3452
- }
3453
- function bindingifyAugmentChunkHash(args$1) {
3454
- const hook = args$1.plugin.augmentChunkHash;
3455
- if (!hook) return {};
3456
- const { handler, meta } = normalizeHook(hook);
3457
- return {
3458
- plugin: async (ctx, chunk) => {
3459
- return await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
3460
- },
3461
- meta: bindingifyPluginHookMeta(meta)
3462
- };
3463
- }
3464
- function bindingifyRenderError(args$1) {
3465
- const hook = args$1.plugin.renderError;
3466
- if (!hook) return {};
3467
- const { handler, meta } = normalizeHook(hook);
3468
- return {
3469
- plugin: async (ctx, err) => {
3470
- handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), normalizeErrors(err));
3471
- },
3472
- meta: bindingifyPluginHookMeta(meta)
3473
- };
3474
- }
3475
- function bindingifyGenerateBundle(args$1) {
3476
- const hook = args$1.plugin.generateBundle;
3477
- if (!hook) return {};
3478
- const { handler, meta } = normalizeHook(hook);
3479
- return {
3480
- plugin: async (ctx, bundle, isWrite, opts) => {
3481
- const changed = {
3482
- updated: new Set(),
3483
- deleted: new Set()
3484
- };
3485
- const output = transformToOutputBundle(bundle, changed);
3486
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), new NormalizedOutputOptionsImpl(opts, args$1.outputOptions, args$1.normalizedOutputPlugins), output, isWrite);
3487
- return collectChangedBundle(changed, output);
3488
- },
3489
- meta: bindingifyPluginHookMeta(meta)
3490
- };
3491
- }
3492
- function bindingifyWriteBundle(args$1) {
3493
- const hook = args$1.plugin.writeBundle;
3494
- if (!hook) return {};
3495
- const { handler, meta } = normalizeHook(hook);
3496
- return {
3497
- plugin: async (ctx, bundle, opts) => {
3498
- const changed = {
3499
- updated: new Set(),
3500
- deleted: new Set()
3501
- };
3502
- const output = transformToOutputBundle(bundle, changed);
3503
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), new NormalizedOutputOptionsImpl(opts, args$1.outputOptions, args$1.normalizedOutputPlugins), output);
3504
- return collectChangedBundle(changed, output);
3505
- },
3506
- meta: bindingifyPluginHookMeta(meta)
3507
- };
3508
- }
3509
- function bindingifyCloseBundle(args$1) {
3510
- const hook = args$1.plugin.closeBundle;
3511
- if (!hook) return {};
3512
- const { handler, meta } = normalizeHook(hook);
3513
- return {
3514
- plugin: async (ctx) => {
3515
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode));
3516
- },
3517
- meta: bindingifyPluginHookMeta(meta)
3518
- };
3519
- }
3520
- function bindingifyBanner(args$1) {
3521
- const hook = args$1.plugin.banner;
3522
- if (!hook) return {};
3523
- const { handler, meta } = normalizeHook(hook);
3524
- return {
3525
- plugin: async (ctx, chunk) => {
3526
- if (typeof handler === "string") return handler;
3527
- return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
3528
- },
3529
- meta: bindingifyPluginHookMeta(meta)
3530
- };
3531
- }
3532
- function bindingifyFooter(args$1) {
3533
- const hook = args$1.plugin.footer;
3534
- if (!hook) return {};
3535
- const { handler, meta } = normalizeHook(hook);
3536
- return {
3537
- plugin: async (ctx, chunk) => {
3538
- if (typeof handler === "string") return handler;
3539
- return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
3540
- },
3541
- meta: bindingifyPluginHookMeta(meta)
3542
- };
3543
- }
3544
- function bindingifyIntro(args$1) {
3545
- const hook = args$1.plugin.intro;
3546
- if (!hook) return {};
3547
- const { handler, meta } = normalizeHook(hook);
3548
- return {
3549
- plugin: async (ctx, chunk) => {
3550
- if (typeof handler === "string") return handler;
3551
- return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
3552
- },
3553
- meta: bindingifyPluginHookMeta(meta)
3554
- };
3555
- }
3556
- function bindingifyOutro(args$1) {
3557
- const hook = args$1.plugin.outro;
3558
- if (!hook) return {};
3559
- const { handler, meta } = normalizeHook(hook);
3560
- return {
3561
- plugin: async (ctx, chunk) => {
3562
- if (typeof handler === "string") return handler;
3563
- return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
3564
- },
3565
- meta: bindingifyPluginHookMeta(meta)
3566
- };
3567
- }
3568
-
3569
- //#endregion
3570
- //#region src/plugin/bindingify-watch-hooks.ts
3571
- function bindingifyWatchChange(args$1) {
3572
- const hook = args$1.plugin.watchChange;
3573
- if (!hook) return {};
3574
- const { handler, meta } = normalizeHook(hook);
3575
- return {
3576
- plugin: async (ctx, id, event) => {
3577
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), id, { event });
3578
- },
3579
- meta: bindingifyPluginHookMeta(meta)
3580
- };
3581
- }
3582
- function bindingifyCloseWatcher(args$1) {
3583
- const hook = args$1.plugin.closeWatcher;
3584
- if (!hook) return {};
3585
- const { handler, meta } = normalizeHook(hook);
3586
- return {
3587
- plugin: async (ctx) => {
3588
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode));
3589
- },
3590
- meta: bindingifyPluginHookMeta(meta)
3591
- };
3592
- }
3593
-
3594
- //#endregion
3595
- //#region src/plugin/bindingify-plugin.ts
3596
- function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
3597
- const args$1 = {
3598
- plugin,
3599
- options,
3600
- outputOptions,
3601
- pluginContextData,
3602
- onLog,
3603
- logLevel,
3604
- watchMode,
3605
- normalizedOutputPlugins
3606
- };
3607
- const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args$1);
3608
- const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args$1);
3609
- const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args$1);
3610
- const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args$1);
3611
- const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args$1);
3612
- const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args$1);
3613
- const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args$1);
3614
- const { plugin: renderChunk, meta: renderChunkMeta } = bindingifyRenderChunk(args$1);
3615
- const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args$1);
3616
- const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args$1);
3617
- const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args$1);
3618
- const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args$1);
3619
- const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args$1);
3620
- const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args$1);
3621
- const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args$1);
3622
- const { plugin: footer, meta: footerMeta } = bindingifyFooter(args$1);
3623
- const { plugin: intro, meta: introMeta } = bindingifyIntro(args$1);
3624
- const { plugin: outro, meta: outroMeta } = bindingifyOutro(args$1);
3625
- const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args$1);
3626
- const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args$1);
3627
- const result = {
3628
- name: plugin.name,
3629
- buildStart,
3630
- buildStartMeta,
3631
- resolveId,
3632
- resolveIdMeta,
3633
- resolveIdFilter,
3634
- resolveDynamicImport,
3635
- resolveDynamicImportMeta,
3636
- buildEnd,
3637
- buildEndMeta,
3638
- transform,
3639
- transformMeta,
3640
- transformFilter,
3641
- moduleParsed,
3642
- moduleParsedMeta,
3643
- load,
3644
- loadMeta,
3645
- loadFilter,
3646
- renderChunk,
3647
- renderChunkMeta,
3648
- augmentChunkHash,
3649
- augmentChunkHashMeta,
3650
- renderStart,
3651
- renderStartMeta,
3652
- renderError,
3653
- renderErrorMeta,
3654
- generateBundle,
3655
- generateBundleMeta,
3656
- writeBundle,
3657
- writeBundleMeta,
3658
- closeBundle,
3659
- closeBundleMeta,
3660
- banner,
3661
- bannerMeta,
3662
- footer,
3663
- footerMeta,
3664
- intro,
3665
- introMeta,
3666
- outro,
3667
- outroMeta,
3668
- watchChange,
3669
- watchChangeMeta,
3670
- closeWatcher,
3671
- closeWatcherMeta
3672
- };
3673
- return wrapHandlers(result);
3674
- }
3675
- function wrapHandlers(plugin) {
3676
- for (const hookName of [
3677
- "buildStart",
3678
- "resolveId",
3679
- "resolveDynamicImport",
3680
- "buildEnd",
3681
- "transform",
3682
- "moduleParsed",
3683
- "load",
3684
- "renderChunk",
3685
- "augmentChunkHash",
3686
- "renderStart",
3687
- "renderError",
3688
- "generateBundle",
3689
- "writeBundle",
3690
- "closeBundle",
3691
- "banner",
3692
- "footer",
3693
- "intro",
3694
- "outro",
3695
- "watchChange",
3696
- "closeWatcher"
3697
- ]) {
3698
- const handler = plugin[hookName];
3699
- if (handler) plugin[hookName] = async (...args$1) => {
3700
- try {
3701
- return await handler(...args$1);
3702
- } catch (e$1) {
3703
- return error(logPluginError(e$1, plugin.name, {
3704
- hook: hookName,
3705
- id: hookName === "transform" ? args$1[2] : void 0
3706
- }));
3707
- }
3708
- };
3709
- }
3710
- return plugin;
3711
- }
3712
-
3713
- //#endregion
3714
- //#region src/plugin/plugin-context-data.ts
3715
- var PluginContextData = class {
3716
- moduleOptionMap = new Map();
3717
- resolveOptionsMap = new Map();
3718
- loadModulePromiseMap = new Map();
3719
- meta = null;
3720
- updateModuleOption(id, option) {
3721
- const existing = this.moduleOptionMap.get(id);
3722
- if (existing) {
3723
- if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
3724
- if (option.meta != null) Object.assign(existing.meta, option.meta);
3725
- if (option.invalidate != null) existing.invalidate = option.invalidate;
3726
- } else {
3727
- this.moduleOptionMap.set(id, option);
3728
- return option;
3729
- }
3730
- return existing;
3731
- }
3732
- getModuleOption(id) {
3733
- const option = this.moduleOptionMap.get(id);
3734
- if (!option) {
3735
- const raw = {
3736
- moduleSideEffects: null,
3737
- meta: {}
3738
- };
3739
- this.moduleOptionMap.set(id, raw);
3740
- return raw;
3741
- }
3742
- return option;
3743
- }
3744
- getModuleInfo(id, context) {
3745
- const bindingInfo = context.getModuleInfo(id);
3746
- if (bindingInfo) {
3747
- const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
3748
- return this.proxyModuleInfo(id, info);
3749
- }
3750
- return null;
3751
- }
3752
- proxyModuleInfo(id, info) {
3753
- let moduleSideEffects = info.moduleSideEffects;
3754
- Object.defineProperty(info, "moduleSideEffects", {
3755
- get() {
3756
- return moduleSideEffects;
3757
- },
3758
- set: (v$1) => {
3759
- this.updateModuleOption(id, {
3760
- moduleSideEffects: v$1,
3761
- meta: info.meta,
3762
- invalidate: true
3763
- });
3764
- moduleSideEffects = v$1;
3765
- }
3766
- });
3767
- return info;
3768
- }
3769
- getModuleIds(context) {
3770
- const moduleIds = context.getModuleIds();
3771
- return moduleIds.values();
3772
- }
3773
- saveResolveOptions(options) {
3774
- const index = this.resolveOptionsMap.size;
3775
- this.resolveOptionsMap.set(index, options);
3776
- return index;
3777
- }
3778
- getSavedResolveOptions(receipt) {
3779
- return this.resolveOptionsMap.get(receipt);
3780
- }
3781
- removeSavedResolveOptions(receipt) {
3782
- this.resolveOptionsMap.delete(receipt);
3783
- }
3784
- setRenderChunkMeta(meta) {
3785
- this.meta = meta;
3786
- }
3787
- getRenderChunkMeta() {
3788
- return this.meta;
3789
- }
3790
- };
3791
-
3792
- //#endregion
3793
- //#region src/utils/normalize-string-or-regex.ts
3794
- function normalizedStringOrRegex(pattern) {
3795
- if (!pattern) return void 0;
3796
- if (!Array.isArray(pattern)) pattern = [pattern];
3797
- return pattern;
3798
- }
3799
-
3800
- //#endregion
3801
- //#region src/utils/bindingify-input-options.ts
3802
- function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode) {
3803
- const pluginContextData = new PluginContextData();
3804
- const plugins = rawPlugins.map((plugin) => {
3805
- if ("_parallel" in plugin) return void 0;
3806
- if (plugin instanceof BuiltinPlugin) return bindingifyBuiltInPlugin(plugin);
3807
- return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode);
3808
- });
3809
- return {
3810
- input: bindingifyInput(inputOptions.input),
3811
- plugins,
3812
- cwd: inputOptions.cwd ?? process.cwd(),
3813
- external: bindingifyExternal(inputOptions.external),
3814
- resolve: bindingifyResolve(inputOptions.resolve),
3815
- platform: inputOptions.platform,
3816
- shimMissingExports: inputOptions.shimMissingExports,
3817
- logLevel: bindingifyLogLevel(logLevel),
3818
- onLog,
3819
- treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
3820
- moduleTypes: inputOptions.moduleTypes,
3821
- define: inputOptions.define ? Object.entries(inputOptions.define) : void 0,
3822
- inject: bindingifyInject(inputOptions.inject),
3823
- experimental: {
3824
- strictExecutionOrder: inputOptions.experimental?.strictExecutionOrder,
3825
- disableLiveBindings: inputOptions.experimental?.disableLiveBindings,
3826
- viteMode: inputOptions.experimental?.viteMode,
3827
- resolveNewUrlToAsset: inputOptions.experimental?.resolveNewUrlToAsset,
3828
- hmr: bindingifyHmr(inputOptions.experimental?.hmr)
3829
- },
3830
- profilerNames: inputOptions?.profilerNames,
3831
- jsx: bindingifyJsx(inputOptions.jsx),
3832
- transform: inputOptions.transform,
3833
- watch: bindingifyWatch(inputOptions.watch),
3834
- dropLabels: inputOptions.dropLabels,
3835
- keepNames: inputOptions.keepNames,
3836
- checks: inputOptions.checks,
3837
- deferSyncScanData: () => {
3838
- let ret = [];
3839
- pluginContextData.moduleOptionMap.forEach((value, key) => {
3840
- if (value.invalidate) ret.push({
3841
- id: key,
3842
- sideEffects: bindingifySideEffects(value.moduleSideEffects)
3843
- });
3844
- });
3845
- return ret;
3846
- },
3847
- makeAbsoluteExternalsRelative: bindingifyMakeAbsoluteExternalsRelative(inputOptions.makeAbsoluteExternalsRelative),
3848
- debug: inputOptions.debug
3849
- };
3850
- }
3851
- function bindingifyHmr(hmr) {
3852
- if (hmr) {
3853
- if (typeof hmr === "boolean") return hmr ? {} : void 0;
3854
- return hmr;
3855
- }
3856
- }
3857
- function bindingifyExternal(external) {
3858
- if (external) {
3859
- if (typeof external === "function") return (id, importer, isResolved) => {
3860
- if (id.startsWith("\0")) return false;
3861
- return external(id, importer, isResolved) ?? false;
3862
- };
3863
- const externalArr = arraify(external);
3864
- return (id, _importer, _isResolved) => {
3865
- return externalArr.some((pat) => {
3866
- if (pat instanceof RegExp) return pat.test(id);
3867
- return id === pat;
3868
- });
3869
- };
3870
- }
3871
- }
3872
- function bindingifyResolve(resolve$1) {
3873
- if (resolve$1) {
3874
- const { alias, extensionAlias,...rest } = resolve$1;
3875
- return {
3876
- alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
3877
- find: name,
3878
- replacements: arraify(replacement)
3879
- })) : void 0,
3880
- extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
3881
- target: name,
3882
- replacements: value
3883
- })) : void 0,
3884
- ...rest
3885
- };
3886
- }
3887
- }
3888
- function bindingifyInject(inject) {
3889
- if (inject) return Object.entries(inject).map(([alias, item]) => {
3890
- if (Array.isArray(item)) {
3891
- if (item[1] === "*") return {
3892
- tagNamespace: true,
3893
- alias,
3894
- from: item[0]
3895
- };
3896
- return {
3897
- tagNamed: true,
3898
- alias,
3899
- from: item[0],
3900
- imported: item[1]
3901
- };
3902
- } else return {
3903
- tagNamed: true,
3904
- imported: "default",
3905
- alias,
3906
- from: item
3907
- };
3908
- });
3909
- }
3910
- function bindingifyLogLevel(logLevel) {
3911
- switch (logLevel) {
3912
- case "silent": return BindingLogLevel.Silent;
3913
- case "debug": return BindingLogLevel.Debug;
3914
- case "warn": return BindingLogLevel.Warn;
3915
- case "info": return BindingLogLevel.Info;
3916
- default: throw new Error(`Unexpected log level: ${logLevel}`);
3917
- }
3918
- }
3919
- function bindingifyInput(input) {
3920
- if (input === void 0) return [];
3921
- if (typeof input === "string") return [{ import: input }];
3922
- if (Array.isArray(input)) return input.map((src) => ({ import: src }));
3923
- return Object.entries(input).map(([name, import_path]) => {
3924
- return {
3925
- name,
3926
- import: import_path
3927
- };
3928
- });
3929
- }
3930
- function bindingifyJsx(input) {
3931
- switch (input) {
3932
- case false: return { type: "Disable" };
3933
- case "react": return { type: "React" };
3934
- case "react-jsx": return { type: "ReactJsx" };
3935
- case "preserve": return { type: "Preserve" };
3936
- case void 0: return void 0;
3937
- }
3938
- if (input.mode === "preserve") return { type: "Preserve" };
3939
- const mode = input.mode ?? "automatic";
3940
- return {
3941
- type: "Enable",
3942
- field0: {
3943
- runtime: mode,
3944
- importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : void 0,
3945
- pragma: input.factory,
3946
- pragmaFrag: input.fragment,
3947
- development: input.development,
3948
- refresh: input.refresh
3949
- }
3950
- };
3951
- }
3952
- function bindingifyWatch(watch$1) {
3953
- if (watch$1) return {
3954
- buildDelay: watch$1.buildDelay,
3955
- skipWrite: watch$1.skipWrite,
3956
- include: normalizedStringOrRegex(watch$1.include),
3957
- exclude: normalizedStringOrRegex(watch$1.exclude)
3958
- };
3959
- }
3960
- function bindingifyTreeshakeOptions(config) {
3961
- if (config === false) return void 0;
3962
- if (config === true || config === void 0) return { moduleSideEffects: true };
3963
- let normalizedConfig = {
3964
- moduleSideEffects: true,
3965
- annotations: config.annotations,
3966
- manualPureFunctions: config.manualPureFunctions,
3967
- unknownGlobalSideEffects: config.unknownGlobalSideEffects
3968
- };
3969
- if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
3970
- else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
3971
- external: true,
3972
- sideEffects: false
3973
- }, {
3974
- external: false,
3975
- sideEffects: true
3976
- }];
3977
- else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
3978
- return normalizedConfig;
3979
- }
3980
- function bindingifyMakeAbsoluteExternalsRelative(makeAbsoluteExternalsRelative) {
3981
- if (makeAbsoluteExternalsRelative === "ifRelativeSource") return { type: "IfRelativeSource" };
3982
- if (typeof makeAbsoluteExternalsRelative === "boolean") return {
3983
- type: "Bool",
3984
- field0: makeAbsoluteExternalsRelative
3985
- };
3986
- }
3987
-
3988
- //#endregion
3989
- //#region ../../node_modules/.pnpm/remeda@2.21.2/node_modules/remeda/dist/chunk-D6FCK2GA.js
3990
- function u$1(o$1, n$1, a$1) {
3991
- let t$2 = (r$1) => o$1(r$1, ...n$1);
3992
- return a$1 === void 0 ? t$2 : Object.assign(t$2, {
3993
- lazy: a$1,
3994
- lazyArgs: n$1
3995
- });
3996
- }
3997
-
3998
- //#endregion
3999
- //#region ../../node_modules/.pnpm/remeda@2.21.2/node_modules/remeda/dist/chunk-WIMGWYZL.js
4000
- function u(r$1, n$1, o$1) {
4001
- let a$1 = r$1.length - n$1.length;
4002
- if (a$1 === 0) return r$1(...n$1);
4003
- if (a$1 === 1) return u$1(r$1, n$1, o$1);
4004
- throw new Error("Wrong number of arguments");
4005
- }
4006
-
4007
- //#endregion
4008
- //#region ../../node_modules/.pnpm/remeda@2.21.2/node_modules/remeda/dist/chunk-5NQBDF4H.js
4009
- function t(...n$1) {
4010
- return u(Object.keys, n$1);
4011
- }
4012
-
4013
- //#endregion
4014
- //#region src/utils/plugin/index.ts
4015
- const isPluginHookName = function() {
4016
- const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
4017
- return function isPluginHookName$1(hookName) {
4018
- return PLUGIN_HOOK_NAMES_SET.has(hookName);
4019
- };
4020
- }();
4021
-
4022
- //#endregion
4023
- //#region src/utils/compose-js-plugins.ts
4024
- const unsupportedHookName = [
4025
- "augmentChunkHash",
4026
- "generateBundle",
4027
- "moduleParsed",
4028
- "onLog",
4029
- "options",
4030
- "outputOptions",
4031
- "renderError",
4032
- "renderStart",
4033
- "resolveDynamicImport",
4034
- "writeBundle"
4035
- ];
4036
- const unsupportedHooks = new Set(unsupportedHookName);
4037
- function isUnsupportedHooks(hookName) {
4038
- return unsupportedHooks.has(hookName);
4039
- }
4040
- function createComposedPlugin(plugins) {
4041
- const names = [];
4042
- const batchedHooks = {};
4043
- plugins.forEach((plugin, index) => {
4044
- const pluginName = plugin.name || `Anonymous(index: ${index})`;
4045
- names.push(pluginName);
4046
- t(plugin).forEach((pluginProp) => {
4047
- if (isUnsupportedHooks(pluginProp)) throw new Error(`Failed to compose js plugins. Plugin ${pluginName} has an unsupported hook: ${pluginProp}`);
4048
- if (!isPluginHookName(pluginProp)) return;
4049
- switch (pluginProp) {
4050
- case "buildStart": {
4051
- const handlers = batchedHooks.buildStart ?? [];
4052
- batchedHooks.buildStart = handlers;
4053
- if (plugin.buildStart) handlers.push([plugin.buildStart, plugin]);
4054
- break;
4055
- }
4056
- case "load": {
4057
- const handlers = batchedHooks.load ?? [];
4058
- batchedHooks.load = handlers;
4059
- if (plugin.load) handlers.push([plugin.load, plugin]);
4060
- break;
4061
- }
4062
- case "transform": {
4063
- const handlers = batchedHooks.transform ?? [];
4064
- batchedHooks.transform = handlers;
4065
- if (plugin.transform) handlers.push([plugin.transform, plugin]);
4066
- break;
4067
- }
4068
- case "resolveId": {
4069
- const handlers = batchedHooks.resolveId ?? [];
4070
- batchedHooks.resolveId = handlers;
4071
- if (plugin.resolveId) handlers.push([plugin.resolveId, plugin]);
4072
- break;
4073
- }
4074
- case "buildEnd": {
4075
- const handlers = batchedHooks.buildEnd ?? [];
4076
- batchedHooks.buildEnd = handlers;
4077
- if (plugin.buildEnd) handlers.push([plugin.buildEnd, plugin]);
4078
- break;
4079
- }
4080
- case "renderChunk": {
4081
- const handlers = batchedHooks.renderChunk ?? [];
4082
- batchedHooks.renderChunk = handlers;
4083
- if (plugin.renderChunk) handlers.push([plugin.renderChunk, plugin]);
4084
- break;
4085
- }
4086
- case "banner":
4087
- case "footer":
4088
- case "intro":
4089
- case "outro": {
4090
- const hook = plugin[pluginProp];
4091
- if (hook) (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
4092
- break;
4093
- }
4094
- case "closeBundle": {
4095
- const handlers = batchedHooks.closeBundle ?? [];
4096
- batchedHooks.closeBundle = handlers;
4097
- if (plugin.closeBundle) handlers.push([plugin.closeBundle, plugin]);
4098
- break;
4099
- }
4100
- case "watchChange": {
4101
- const handlers = batchedHooks.watchChange ?? [];
4102
- batchedHooks.watchChange = handlers;
4103
- if (plugin.watchChange) handlers.push([plugin.watchChange, plugin]);
4104
- break;
4105
- }
4106
- case "closeWatcher": {
4107
- const handlers = batchedHooks.closeWatcher ?? [];
4108
- batchedHooks.closeWatcher = handlers;
4109
- if (plugin.closeWatcher) handlers.push([plugin.closeWatcher, plugin]);
4110
- break;
4111
- }
4112
- default: {}
4113
- }
4114
- });
4115
- });
4116
- const composed = { name: `Composed(${names.join(", ")})` };
4117
- const createFixedPluginResolveFnMap = new Map();
4118
- function applyFixedPluginResolveFn(ctx, plugin) {
4119
- const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
4120
- if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
4121
- return ctx;
4122
- }
4123
- if (batchedHooks.resolveId) {
4124
- const batchedHandlers = batchedHooks.resolveId;
4125
- const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
4126
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
4127
- const [_handler, plugin] = batchedHandlers[handlerIdx];
4128
- const handlerSymbol = handlerSymbols[handlerIdx];
4129
- const createFixedPluginResolveFn = (ctx, resolve$1) => {
4130
- return (source, importer, rawContextResolveOptions) => {
4131
- const contextResolveOptions = rawContextResolveOptions ?? {};
4132
- if (contextResolveOptions.skipSelf) {
4133
- contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
4134
- contextResolveOptions.skipSelf = false;
4135
- }
4136
- return resolve$1(source, importer, contextResolveOptions);
4137
- };
4138
- };
4139
- createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
4140
- }
4141
- composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
4142
- const hookResolveIdOptions = rawHookResolveIdOptions;
4143
- const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
4144
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
4145
- const [handler, plugin] = batchedHandlers[handlerIdx];
4146
- const handlerSymbol = handlerSymbols[handlerIdx];
4147
- if (symbolForCallerThatSkipSelf === handlerSymbol) continue;
4148
- const { handler: handlerFn } = normalizeHook(handler);
4149
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
4150
- if (!isNullish(result)) return result;
4151
- }
4152
- };
4153
- }
4154
- t(batchedHooks).forEach((hookName) => {
4155
- switch (hookName) {
4156
- case "resolveId": break;
4157
- case "buildStart": {
4158
- if (batchedHooks.buildStart) {
4159
- const batchedHandlers = batchedHooks.buildStart;
4160
- composed.buildStart = async function(options) {
4161
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4162
- const { handler: handlerFn } = normalizeHook(handler);
4163
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), options);
4164
- }));
4165
- };
4166
- }
4167
- break;
4168
- }
4169
- case "load": {
4170
- if (batchedHooks.load) {
4171
- const batchedHandlers = batchedHooks.load;
4172
- composed.load = async function(id) {
4173
- for (const [handler, plugin] of batchedHandlers) {
4174
- const { handler: handlerFn } = normalizeHook(handler);
4175
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), id);
4176
- if (!isNullish(result)) return result;
4177
- }
4178
- };
4179
- }
4180
- break;
4181
- }
4182
- case "transform": {
4183
- if (batchedHooks.transform) {
4184
- const batchedHandlers = batchedHooks.transform;
4185
- composed.transform = async function(initialCode, id, moduleType) {
4186
- let code = initialCode;
4187
- let moduleSideEffects = void 0;
4188
- function updateOutput(newCode, newModuleSideEffects) {
4189
- code = newCode;
4190
- moduleSideEffects = newModuleSideEffects ?? void 0;
4191
- }
4192
- for (const [handler, plugin] of batchedHandlers) {
4193
- const { handler: handlerFn } = normalizeHook(handler);
4194
- this.getCombinedSourcemap = () => {
4195
- throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
4196
- };
4197
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
4198
- if (!isNullish(result)) {
4199
- if (typeof result === "string") updateOutput(result);
4200
- else if (result.code) updateOutput(result.code, result.moduleSideEffects);
4201
- }
4202
- }
4203
- return {
4204
- code,
4205
- moduleSideEffects
4206
- };
4207
- };
4208
- }
4209
- break;
4210
- }
4211
- case "buildEnd": {
4212
- if (batchedHooks.buildEnd) {
4213
- const batchedHandlers = batchedHooks.buildEnd;
4214
- composed.buildEnd = async function(err) {
4215
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4216
- const { handler: handlerFn } = normalizeHook(handler);
4217
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
4218
- }));
4219
- };
4220
- }
4221
- break;
4222
- }
4223
- case "renderChunk": {
4224
- if (batchedHooks.renderChunk) {
4225
- const batchedHandlers = batchedHooks.renderChunk;
4226
- composed.renderChunk = async function(code, chunk, options, meta) {
4227
- for (const [handler, plugin] of batchedHandlers) {
4228
- const { handler: handlerFn } = normalizeHook(handler);
4229
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options, meta);
4230
- if (!isNullish(result)) return result;
4231
- }
4232
- };
4233
- }
4234
- break;
4235
- }
4236
- case "banner":
4237
- case "footer":
4238
- case "intro":
4239
- case "outro": {
4240
- const hooks = batchedHooks[hookName];
4241
- if (hooks?.length) composed[hookName] = async function(chunk) {
4242
- const ret = [];
4243
- for (const [hook, plugin] of hooks) {
4244
- const { handler } = normalizeHook(hook);
4245
- ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
4246
- }
4247
- return ret.join("\n");
4248
- };
4249
- break;
4250
- }
4251
- case "closeBundle": {
4252
- if (batchedHooks.closeBundle) {
4253
- const batchedHandlers = batchedHooks.closeBundle;
4254
- composed.closeBundle = async function() {
4255
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4256
- const { handler: handlerFn } = normalizeHook(handler);
4257
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
4258
- }));
4259
- };
4260
- }
4261
- break;
4262
- }
4263
- case "watchChange": {
4264
- if (batchedHooks.watchChange) {
4265
- const batchedHandlers = batchedHooks.watchChange;
4266
- composed.watchChange = async function(id, event) {
4267
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4268
- const { handler: handlerFn } = normalizeHook(handler);
4269
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), id, event);
4270
- }));
4271
- };
4272
- }
4273
- break;
4274
- }
4275
- case "closeWatcher": {
4276
- if (batchedHooks.closeWatcher) {
4277
- const batchedHandlers = batchedHooks.closeWatcher;
4278
- composed.closeWatcher = async function() {
4279
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
4280
- const { handler: handlerFn } = normalizeHook(handler);
4281
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
4282
- }));
4283
- };
4284
- }
4285
- break;
4286
- }
4287
- default: {}
4288
- }
4289
- });
4290
- return composed;
4291
- }
4292
- function isComposablePlugin(plugin) {
4293
- if (plugin instanceof BuiltinPlugin) return false;
4294
- if ("_parallel" in plugin) return false;
4295
- const hasNotComposablePattern = t(plugin).some((hookName) => {
4296
- if (!isPluginHookName(hookName)) return false;
4297
- const OK_TO_COMPOSE = false;
4298
- if (isUnsupportedHooks(hookName)) return !OK_TO_COMPOSE;
4299
- if (plugin[hookName]) {
4300
- const { meta } = normalizeHook(plugin[hookName]);
4301
- if (meta.order === "pre" || meta.order === "post") return !OK_TO_COMPOSE;
4302
- }
4303
- return OK_TO_COMPOSE;
4304
- });
4305
- if (hasNotComposablePattern) return false;
4306
- return true;
4307
- }
4308
- function composeJsPlugins(plugins) {
4309
- const newPlugins = [];
4310
- const toBeComposed = [];
4311
- plugins.forEach((plugin) => {
4312
- if (isComposablePlugin(plugin)) toBeComposed.push(plugin);
4313
- else {
4314
- if (toBeComposed.length > 0) {
4315
- if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
4316
- else newPlugins.push(toBeComposed[0]);
4317
- toBeComposed.length = 0;
4318
- }
4319
- newPlugins.push(plugin);
4320
- }
4321
- });
4322
- if (toBeComposed.length > 0) {
4323
- if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
4324
- else newPlugins.push(toBeComposed[0]);
4325
- toBeComposed.length = 0;
4326
- }
4327
- return newPlugins;
4328
- }
4329
-
4330
- //#endregion
4331
- //#region src/utils/create-bundler-option.ts
4332
- async function createBundlerOptions(inputOptions, outputOptions, watchMode, isClose) {
4333
- const inputPlugins = await normalizePluginOption(inputOptions.plugins);
4334
- const outputPlugins = await normalizePluginOption(outputOptions.plugins);
4335
- const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
4336
- const onLog = getLogger(getObjectPlugins(inputPlugins), getOnLog(inputOptions, logLevel), logLevel, watchMode);
4337
- if (!isClose) outputOptions = PluginDriver.callOutputOptionsHook([...inputPlugins, ...outputPlugins], outputOptions, onLog, logLevel, watchMode);
4338
- if (outputOptions.minify === true) onLog(LOG_LEVEL_WARN, logMinifyWarning());
4339
- const normalizedOutputPlugins = await normalizePluginOption(outputOptions.plugins);
4340
- let plugins = [...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX), ...checkOutputPluginOption(normalizePlugins(normalizedOutputPlugins, ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)];
4341
- if (inputOptions.experimental?.enableComposingJsPlugins ?? false) plugins = composeJsPlugins(plugins);
4342
- const parallelPluginInitResult = void 0;
4343
- try {
4344
- const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode);
4345
- const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
4346
- return {
4347
- bundlerOptions: {
4348
- inputOptions: bindingInputOptions,
4349
- outputOptions: bindingOutputOptions,
4350
- parallelPluginsRegistry: parallelPluginInitResult?.registry
4351
- },
4352
- inputOptions,
4353
- onLog,
4354
- stopWorkers: parallelPluginInitResult?.stopWorkers
4355
- };
4356
- } catch (e$1) {
4357
- await parallelPluginInitResult?.stopWorkers();
4358
- throw e$1;
4359
- }
4360
- }
4361
-
4362
- //#endregion
4363
- //#region src/utils/create-bundler.ts
4364
- let asyncRuntimeShutdown = false;
4365
- async function createBundler(inputOptions, outputOptions, isClose) {
4366
- const option = await createBundlerOptions(inputOptions, outputOptions, false, isClose);
4367
- if (asyncRuntimeShutdown) startAsyncRuntime();
4368
- try {
4369
- return {
4370
- bundler: new Bundler(option.bundlerOptions),
4371
- stopWorkers: option.stopWorkers,
4372
- shutdown: () => {
4373
- shutdownAsyncRuntime();
4374
- asyncRuntimeShutdown = true;
4375
- }
4376
- };
4377
- } catch (e$1) {
4378
- await option.stopWorkers?.();
4379
- throw e$1;
4380
- }
4381
- }
4382
-
4383
- //#endregion
4384
- //#region src/api/rolldown/rolldown-build.ts
4385
- Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
4386
- var RolldownBuild = class {
4387
- #inputOptions;
4388
- #bundler;
4389
- constructor(inputOptions) {
4390
- this.#inputOptions = inputOptions;
4391
- }
4392
- get closed() {
4393
- return this.#bundler?.bundler.closed ?? false;
4394
- }
4395
- async #getBundlerWithStopWorker(outputOptions, isClose) {
4396
- if (this.#bundler) await this.#bundler.stopWorkers?.();
4397
- return this.#bundler = await createBundler(this.#inputOptions, outputOptions, isClose);
4398
- }
4399
- async generate(outputOptions = {}) {
4400
- validateOption("output", outputOptions);
4401
- const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
4402
- const output = await bundler.generate();
4403
- return transformToRollupOutput(output);
4404
- }
4405
- async write(outputOptions = {}) {
4406
- validateOption("output", outputOptions);
4407
- const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
4408
- const output = await bundler.write();
4409
- return transformToRollupOutput(output);
4410
- }
4411
- async close() {
4412
- const { bundler, stopWorkers, shutdown } = await this.#getBundlerWithStopWorker({}, true);
4413
- await stopWorkers?.();
4414
- await bundler.close();
4415
- shutdown();
4416
- }
4417
- async [Symbol.asyncDispose]() {
4418
- await this.close();
4419
- }
4420
- async generateHmrPatch(changedFiles) {
4421
- return this.#bundler?.bundler.generateHmrPatch(changedFiles);
4422
- }
4423
- get watchFiles() {
4424
- return this.#bundler?.bundler.watchFiles ?? [];
4425
- }
4426
- };
4427
-
4428
- //#endregion
4429
- //#region src/api/rolldown/index.ts
4430
- const rolldown = async (input) => {
4431
- validateOption("input", input);
4432
- const inputOptions = await PluginDriver.callOptionsHook(input);
4433
- return new RolldownBuild(inputOptions);
4434
- };
4435
-
4436
- //#endregion
4437
- //#region src/api/build.ts
4438
- async function build(options) {
4439
- if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
4440
- else {
4441
- const { output, write = true,...inputOptions } = options;
4442
- const build$1 = await rolldown(inputOptions);
4443
- try {
4444
- if (write) return await build$1.write(output);
4445
- else return await build$1.generate(output);
4446
- } finally {
4447
- await build$1.close();
4448
- }
4449
- }
4450
- }
4451
-
4452
- //#endregion
4453
- //#region src/api/watch/watch-emitter.ts
4454
- var WatcherEmitter = class {
4455
- listeners = new Map();
4456
- timer;
4457
- constructor() {
4458
- this.timer = setInterval(
4459
- () => {},
4460
- 1e9
4461
- /* Low power usage */
4462
- );
4463
- }
4464
- on(event, listener) {
4465
- const listeners = this.listeners.get(event);
4466
- if (listeners) listeners.push(listener);
4467
- else this.listeners.set(event, [listener]);
4468
- return this;
4469
- }
4470
- async onEvent(event) {
4471
- const listeners = this.listeners.get(event.eventKind());
4472
- if (listeners) switch (event.eventKind()) {
4473
- case "close":
4474
- case "restart":
4475
- for (const listener of listeners) await listener();
4476
- break;
4477
- case "event":
4478
- for (const listener of listeners) {
4479
- const code = event.bundleEventKind();
4480
- switch (code) {
4481
- case "BUNDLE_END":
4482
- const { duration, output } = event.bundleEndData();
4483
- await listener({
4484
- code: "BUNDLE_END",
4485
- duration,
4486
- output: [output]
4487
- });
4488
- break;
4489
- case "ERROR":
4490
- const errors = event.errors();
4491
- await listener({
4492
- code: "ERROR",
4493
- error: normalizeErrors(errors)
4494
- });
4495
- break;
4496
- default:
4497
- await listener({ code });
4498
- break;
4499
- }
4500
- }
4501
- break;
4502
- case "change":
4503
- for (const listener of listeners) {
4504
- const { path, kind } = event.watchChangeData();
4505
- await listener(path, { event: kind });
4506
- }
4507
- break;
4508
- default: throw new Error(`Unknown event: ${event}`);
4509
- }
4510
- }
4511
- async close() {
4512
- clearInterval(this.timer);
4513
- }
4514
- };
4515
-
4516
- //#endregion
4517
- //#region src/api/watch/watcher.ts
4518
- var Watcher = class {
4519
- closed;
4520
- inner;
4521
- emitter;
4522
- stopWorkers;
4523
- constructor(emitter, inner, stopWorkers) {
4524
- this.closed = false;
4525
- this.inner = inner;
4526
- this.emitter = emitter;
4527
- const originClose = emitter.close.bind(emitter);
4528
- emitter.close = async () => {
4529
- await this.close();
4530
- originClose();
4531
- };
4532
- this.stopWorkers = stopWorkers;
4533
- }
4534
- async close() {
4535
- if (this.closed) return;
4536
- this.closed = true;
4537
- for (const stop of this.stopWorkers) await stop?.();
4538
- await this.inner.close();
4539
- shutdownAsyncRuntime();
4540
- }
4541
- start() {
4542
- process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
4543
- }
4544
- };
4545
- async function createWatcher(emitter, input) {
4546
- const options = arraify(input);
4547
- const bundlerOptions = await Promise.all(options.map((option) => arraify(option.output || {}).map(async (output) => {
4548
- const inputOptions = await PluginDriver.callOptionsHook(option, true);
4549
- return createBundlerOptions(inputOptions, output, true);
4550
- })).flat());
4551
- const notifyOptions = getValidNotifyOption(bundlerOptions);
4552
- const bindingWatcher = new BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
4553
- const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
4554
- watcher.start();
4555
- }
4556
- function getValidNotifyOption(bundlerOptions) {
4557
- let result;
4558
- for (const option of bundlerOptions) if (option.inputOptions.watch) {
4559
- const notifyOption = option.inputOptions.watch.notify;
4560
- if (notifyOption) if (result) {
4561
- option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
4562
- return result;
4563
- } else result = notifyOption;
4564
- }
4565
- }
4566
-
4567
- //#endregion
4568
- //#region src/api/watch/index.ts
4569
- const watch = (input) => {
4570
- const emitter = new WatcherEmitter();
4571
- createWatcher(emitter, input);
4572
- return emitter;
4573
- };
4574
-
4575
- //#endregion
4576
- //#region src/plugin/with-filter.ts
4577
- function withFilterImpl(pluginOption, filterObjectList) {
4578
- if (isPromiseLike(pluginOption)) return pluginOption.then((p$1) => withFilter(p$1, filterObjectList));
4579
- if (pluginOption == false || pluginOption == null) return pluginOption;
4580
- if (Array.isArray(pluginOption)) return pluginOption.map((p$1) => withFilter(p$1, filterObjectList));
4581
- let plugin = pluginOption;
4582
- let filterObjectIndex = findMatchedFilterObject(plugin.name, filterObjectList);
4583
- if (filterObjectIndex === -1) return plugin;
4584
- let filterObject = filterObjectList[filterObjectIndex];
4585
- Object.keys(plugin).forEach((key) => {
4586
- switch (key) {
4587
- case "transform":
4588
- case "resolveId":
4589
- case "load":
4590
- if (!plugin[key]) return;
4591
- if (typeof plugin[key] === "object") plugin[key].filter = filterObject[key] ?? plugin[key].filter;
4592
- else plugin[key] = {
4593
- handler: plugin[key],
4594
- filter: filterObject[key]
4595
- };
4596
- break;
4597
- default: break;
4598
- }
4599
- });
4600
- return plugin;
4601
- }
4602
- function withFilter(pluginOption, filterObject) {
4603
- return withFilterImpl(pluginOption, arraify(filterObject));
4604
- }
4605
- function findMatchedFilterObject(pluginName, overrideFilterObjectList) {
4606
- if (overrideFilterObjectList.length === 1 && overrideFilterObjectList[0].pluginNamePattern === void 0) return 0;
4607
- for (let i$1 = 0; i$1 < overrideFilterObjectList.length; i$1++) for (let j = 0; j < (overrideFilterObjectList[i$1].pluginNamePattern ?? []).length; j++) {
4608
- let pattern = overrideFilterObjectList[i$1].pluginNamePattern[j];
4609
- if (typeof pattern === "string" && pattern === pluginName) return i$1;
4610
- else if (pattern instanceof RegExp && pattern.test(pluginName)) return i$1;
4611
- }
4612
- return -1;
4613
- }
4614
-
4615
- //#endregion
4616
- //#region src/utils/define-config.ts
4617
- function defineConfig(config) {
4618
- return config;
4619
- }
4620
-
4621
- //#endregion
4622
- //#region src/index.ts
4623
- const VERSION = version;
4624
-
4625
- //#endregion
4626
- export { VERSION, build, defineConfig, rolldown, watch, withFilter };