rolldown 0.14.0 → 0.15.0-snapshot-b2570e7-20241204003545

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/cjs/cli.cjs +782 -854
  2. package/dist/cjs/experimental-index.cjs +68 -26
  3. package/dist/cjs/index.cjs +6 -8
  4. package/dist/cjs/parallel-plugin-worker.cjs +20 -14
  5. package/dist/cjs/parallel-plugin.cjs +1 -3
  6. package/dist/esm/cli.mjs +722 -796
  7. package/dist/esm/experimental-index.mjs +44 -7
  8. package/dist/esm/index.mjs +2 -4
  9. package/dist/esm/parallel-plugin-worker.mjs +15 -10
  10. package/dist/esm/parallel-plugin.mjs +1 -3
  11. package/dist/shared/{chunk-JoMxl5V2.cjs → chunk-BK2Ye-xa.cjs} +19 -6
  12. package/dist/shared/{consola.36c0034f-Xyw7SC_7.mjs → consola_36c0034f-DWsVjwtA.mjs} +218 -283
  13. package/dist/shared/{consola.36c0034f-HcmWcfPe.cjs → consola_36c0034f-_8_dG1Nr.cjs} +249 -295
  14. package/dist/shared/{prompt-hoPhcrA-.mjs → prompt-DGW8ZJmn.mjs} +125 -174
  15. package/dist/shared/{prompt-9Ij3R3TG.cjs → prompt-RFvZMmjc.cjs} +157 -204
  16. package/dist/shared/src-1jxF0vle.cjs +2917 -0
  17. package/dist/shared/src-Cm19F5A9.mjs +2789 -0
  18. package/dist/types/api/build.d.ts +16 -0
  19. package/dist/types/api/experimental.d.ts +7 -0
  20. package/dist/types/api/rolldown/index.d.ts +3 -0
  21. package/dist/types/api/rolldown/rolldown-build.d.ts +12 -0
  22. package/dist/types/api/watch/index.d.ts +3 -0
  23. package/dist/types/{watcher.d.ts → api/watch/watch-emitter.d.ts} +17 -17
  24. package/dist/types/api/watch/watcher.d.ts +13 -0
  25. package/dist/types/binding.d.ts +175 -40
  26. package/dist/types/builtin-plugin/alias-plugin.d.ts +10 -0
  27. package/dist/types/builtin-plugin/constructors.d.ts +20 -0
  28. package/dist/types/builtin-plugin/replace-plugin.d.ts +28 -0
  29. package/dist/types/{options/normalized-ecma-transform-plugin-config.d.ts → builtin-plugin/transform-plugin.d.ts} +2 -1
  30. package/dist/types/builtin-plugin/utils.d.ts +8 -0
  31. package/dist/types/cli/arguments/normalize.d.ts +2 -6
  32. package/dist/types/cli/arguments/schema.d.ts +169 -81
  33. package/dist/types/constants/plugin.d.ts +3 -1
  34. package/dist/types/experimental-index.d.ts +5 -2
  35. package/dist/types/index.d.ts +13 -10
  36. package/dist/types/log/locate-character/index.d.ts +13 -0
  37. package/dist/types/log/logger.d.ts +2 -16
  38. package/dist/types/log/logging.d.ts +6 -3
  39. package/dist/types/log/logs.d.ts +2 -0
  40. package/dist/types/options/input-options-schema.d.ts +596 -0
  41. package/dist/types/options/input-options.d.ts +74 -430
  42. package/dist/types/options/normalized-input-options.d.ts +17 -11
  43. package/dist/types/options/normalized-output-options.d.ts +57 -21
  44. package/dist/types/options/output-options-schema.d.ts +147 -0
  45. package/dist/types/options/output-options.d.ts +72 -265
  46. package/dist/types/options/watch-options.d.ts +5 -0
  47. package/dist/types/plugin/bindingify-build-hooks.d.ts +9 -11
  48. package/dist/types/plugin/bindingify-hook-filter.d.ts +5 -5
  49. package/dist/types/plugin/bindingify-output-hooks.d.ts +13 -16
  50. package/dist/types/plugin/bindingify-plugin.d.ts +12 -3
  51. package/dist/types/plugin/bindingify-watch-hooks.d.ts +3 -5
  52. package/dist/types/plugin/hook-filter.d.ts +1 -1
  53. package/dist/types/plugin/index.d.ts +21 -18
  54. package/dist/types/plugin/minimal-plugin-context.d.ts +15 -0
  55. package/dist/types/plugin/plugin-context-data.d.ts +4 -5
  56. package/dist/types/plugin/plugin-context.d.ts +9 -4
  57. package/dist/types/plugin/plugin-driver.d.ts +4 -5
  58. package/dist/types/plugin/transform-plugin-context.d.ts +4 -3
  59. package/dist/types/rollup-types.d.ts +1 -1
  60. package/dist/types/treeshake/index.d.ts +0 -12
  61. package/dist/types/treeshake/module-side-effects.d.ts +111 -11
  62. package/dist/types/types/rolldown-output.d.ts +11 -2
  63. package/dist/types/types/utils.d.ts +1 -0
  64. package/dist/types/utils/bindingify-input-options.d.ts +7 -0
  65. package/dist/types/utils/bindingify-output-options.d.ts +3 -0
  66. package/dist/types/utils/define-config.d.ts +3 -0
  67. package/dist/types/utils/error.d.ts +1 -0
  68. package/dist/types/utils/normalize-hook.d.ts +1 -1
  69. package/dist/types/utils/normalize-plugin-option.d.ts +8 -3
  70. package/dist/types/{options/utils.d.ts → utils/normalize-string-or-regex.d.ts} +1 -1
  71. package/dist/types/utils/transform-rendered-chunk.d.ts +4 -0
  72. package/dist/types/utils/transform-rendered-module.d.ts +3 -0
  73. package/dist/types/utils/transform-sourcemap.d.ts +2 -0
  74. package/dist/types/utils/transform-to-rollup-output.d.ts +1 -0
  75. package/package.json +30 -22
  76. package/dist/shared/rolldown-binding.wasi.cjs +0 -187
  77. package/dist/shared/src_index-3pqhEViJ.cjs +0 -2785
  78. package/dist/shared/src_index-ywYMd4vB.mjs +0 -2786
  79. package/dist/shared/wasi-worker-browser.mjs +0 -39
  80. package/dist/shared/wasi-worker.mjs +0 -63
  81. package/dist/shared/watcher-worker.js +0 -1
  82. package/dist/types/constants/types.d.ts +0 -1
  83. package/dist/types/options/bindingify-input-options.d.ts +0 -4
  84. package/dist/types/options/bindingify-output-options.d.ts +0 -3
  85. package/dist/types/options/normalized-alias-plugin-config.d.ts +0 -8
  86. package/dist/types/options/watch-option.d.ts +0 -5
  87. package/dist/types/plugin/builtin-plugin.d.ts +0 -81
  88. package/dist/types/rolldown-build.d.ts +0 -10
  89. package/dist/types/rolldown.d.ts +0 -12
  90. package/dist/types/types/rendered-module.d.ts +0 -2
  91. package/dist/types/utils/normalize-input-options.d.ts +0 -3
  92. package/dist/types/utils/normalize-output-options.d.ts +0 -3
  93. package/dist/types/utils/normalize-tree-shake.d.ts +0 -3
  94. /package/dist/types/{utils/type-assert.d.ts → types/assert.d.ts} +0 -0
@@ -0,0 +1,2789 @@
1
+ import { createRequire as createRequire$1 } from "module";
2
+ import { z, z as z$1 } from "zod";
3
+ import path, { default as path$1 } from "node:path";
4
+ import { Worker } from "node:worker_threads";
5
+ import { availableParallelism } from "node:os";
6
+
7
+ //#region rolldown:runtime
8
+ var __create = Object.create;
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __getProtoOf = Object.getPrototypeOf;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __commonJS = (cb, mod) => function() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __export = (target, all) => {
18
+ for (var name in all) __defProp(target, name, {
19
+ get: all[name],
20
+ enumerable: true
21
+ });
22
+ };
23
+ var __copyProps = (to, from, except, desc) => {
24
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
25
+ key = keys[i];
26
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
27
+ get: ((k) => from[k]).bind(null, key),
28
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
+ });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
34
+ value: mod,
35
+ enumerable: true
36
+ }) : target, mod));
37
+ var __require = /* @__PURE__ */ createRequire$1(import.meta.url);
38
+
39
+ //#endregion
40
+ //#region src/utils/define-config.ts
41
+ function defineConfig(config) {
42
+ return config;
43
+ }
44
+
45
+ //#endregion
46
+ //#region src/utils/asset-source.ts
47
+ function transformAssetSource(bindingAssetSource$1) {
48
+ return bindingAssetSource$1.inner;
49
+ }
50
+ function bindingAssetSource(source) {
51
+ return { inner: source };
52
+ }
53
+
54
+ //#endregion
55
+ //#region src/types/sourcemap.ts
56
+ function bindingifySourcemap$1(map) {
57
+ if (map == null) return;
58
+ return { inner: typeof map === "string" ? map : {
59
+ file: map.file ?? undefined,
60
+ mappings: map.mappings,
61
+ sourceRoot: map.sourceRoot,
62
+ sources: map.sources?.map((s) => s ?? undefined),
63
+ sourcesContent: map.sourcesContent?.map((s) => s ?? undefined),
64
+ names: map.names
65
+ } };
66
+ }
67
+
68
+ //#endregion
69
+ //#region src/utils/error.ts
70
+ function normalizeErrors(rawErrors) {
71
+ const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(), e, { stack: undefined }));
72
+ let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
73
+ for (let i = 0; i < errors.length; i++) {
74
+ if (i >= 5) {
75
+ summary += "\n...";
76
+ break;
77
+ }
78
+ summary += getErrorMessage(errors[i]) + "\n";
79
+ }
80
+ const wrapper = new Error(summary);
81
+ Object.defineProperty(wrapper, "errors", {
82
+ configurable: true,
83
+ enumerable: true,
84
+ get: () => errors,
85
+ set: (value) => Object.defineProperty(wrapper, "errors", {
86
+ configurable: true,
87
+ enumerable: true,
88
+ value
89
+ })
90
+ });
91
+ return wrapper;
92
+ }
93
+ function getErrorMessage(e) {
94
+ let s = "";
95
+ if (e.plugin) s += `[plugin ${e.plugin}]`;
96
+ const id = e.id ?? e.loc?.file;
97
+ if (id) {
98
+ s += " " + id;
99
+ if (e.loc) s += `:${e.loc.line}:${e.loc.column}`;
100
+ }
101
+ if (s) s += "\n";
102
+ const message = `${e.name ?? "Error"}: ${e.message}`;
103
+ s += message;
104
+ if (e.frame) s = joinNewLine(s, e.frame);
105
+ if (e.stack) s = joinNewLine(s, e.stack.replace(message, ""));
106
+ return s;
107
+ }
108
+ function joinNewLine(s1, s2) {
109
+ return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
110
+ }
111
+
112
+ //#endregion
113
+ //#region src/utils/transform-rendered-module.ts
114
+ function transformToRenderedModule(bindingRenderedModule) {
115
+ return {
116
+ get code() {
117
+ return bindingRenderedModule.code;
118
+ },
119
+ get renderedLength() {
120
+ return bindingRenderedModule.code?.length || 0;
121
+ }
122
+ };
123
+ }
124
+
125
+ //#endregion
126
+ //#region src/utils/transform-rendered-chunk.ts
127
+ function transformRenderedChunk(chunk) {
128
+ return {
129
+ ...chunk,
130
+ get modules() {
131
+ return transformChunkModules(chunk.modules);
132
+ }
133
+ };
134
+ }
135
+ function transformChunkModules(modules) {
136
+ const result = {};
137
+ for (const [id, mod] of Object.entries(modules)) result[id] = transformToRenderedModule(mod);
138
+ return result;
139
+ }
140
+
141
+ //#endregion
142
+ //#region src/utils/transform-to-rollup-output.ts
143
+ function transformToRollupOutputChunk(bindingChunk, changed) {
144
+ const chunk = {
145
+ type: "chunk",
146
+ get code() {
147
+ return bindingChunk.code;
148
+ },
149
+ fileName: bindingChunk.fileName,
150
+ name: bindingChunk.name,
151
+ get modules() {
152
+ return transformChunkModules(bindingChunk.modules);
153
+ },
154
+ get imports() {
155
+ return bindingChunk.imports;
156
+ },
157
+ get dynamicImports() {
158
+ return bindingChunk.dynamicImports;
159
+ },
160
+ exports: bindingChunk.exports,
161
+ isEntry: bindingChunk.isEntry,
162
+ facadeModuleId: bindingChunk.facadeModuleId || null,
163
+ isDynamicEntry: bindingChunk.isDynamicEntry,
164
+ get moduleIds() {
165
+ return bindingChunk.moduleIds;
166
+ },
167
+ get map() {
168
+ return bindingChunk.map ? JSON.parse(bindingChunk.map) : null;
169
+ },
170
+ sourcemapFileName: bindingChunk.sourcemapFileName || null,
171
+ preliminaryFileName: bindingChunk.preliminaryFileName
172
+ };
173
+ const cache = {};
174
+ return new Proxy(chunk, {
175
+ get(target, p) {
176
+ if (p in cache) return cache[p];
177
+ return target[p];
178
+ },
179
+ set(target, p, newValue) {
180
+ cache[p] = newValue;
181
+ changed?.updated.add(bindingChunk.fileName);
182
+ return true;
183
+ }
184
+ });
185
+ }
186
+ function transformToRollupOutputAsset(bindingAsset, changed) {
187
+ const asset = {
188
+ type: "asset",
189
+ fileName: bindingAsset.fileName,
190
+ originalFileName: bindingAsset.originalFileName || null,
191
+ get source() {
192
+ return transformAssetSource(bindingAsset.source);
193
+ },
194
+ name: bindingAsset.name ?? undefined
195
+ };
196
+ const cache = {};
197
+ return new Proxy(asset, {
198
+ get(target, p) {
199
+ if (p in cache) return cache[p];
200
+ return target[p];
201
+ },
202
+ set(target, p, newValue) {
203
+ cache[p] = newValue;
204
+ changed?.updated.add(bindingAsset.fileName);
205
+ return true;
206
+ }
207
+ });
208
+ }
209
+ function transformToRollupOutput(output, changed) {
210
+ handleOutputErrors(output);
211
+ const { chunks, assets } = output;
212
+ return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToRollupOutputAsset(asset, changed))] };
213
+ }
214
+ function handleOutputErrors(output) {
215
+ const rawErrors = output.errors;
216
+ if (rawErrors.length > 0) throw normalizeErrors(rawErrors);
217
+ }
218
+ function transformToOutputBundle(output, changed) {
219
+ const bundle = Object.fromEntries(transformToRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
220
+ return new Proxy(bundle, { deleteProperty(target, property) {
221
+ if (typeof property === "string") changed.deleted.add(property);
222
+ return true;
223
+ } });
224
+ }
225
+ function collectChangedBundle(changed, bundle) {
226
+ const assets = [];
227
+ const chunks = [];
228
+ for (const key in bundle) {
229
+ if (changed.deleted.has(key) || !changed.updated.has(key)) continue;
230
+ const item = bundle[key];
231
+ if (item.type === "asset") assets.push({
232
+ filename: item.fileName,
233
+ originalFileName: item.originalFileName || undefined,
234
+ source: bindingAssetSource(item.source),
235
+ name: item.name
236
+ });
237
+ else chunks.push({
238
+ code: item.code,
239
+ filename: item.fileName,
240
+ name: item.name,
241
+ isEntry: item.isEntry,
242
+ exports: item.exports,
243
+ modules: {},
244
+ imports: item.imports,
245
+ dynamicImports: item.dynamicImports,
246
+ facadeModuleId: item.facadeModuleId || undefined,
247
+ isDynamicEntry: item.isDynamicEntry,
248
+ moduleIds: item.moduleIds,
249
+ map: bindingifySourcemap$1(item.map),
250
+ sourcemapFilename: item.sourcemapFileName || undefined,
251
+ preliminaryFilename: item.preliminaryFileName
252
+ });
253
+ }
254
+ return {
255
+ assets,
256
+ chunks,
257
+ deleted: Array.from(changed.deleted)
258
+ };
259
+ }
260
+
261
+ //#endregion
262
+ //#region src/binding.js
263
+ var require_binding = __commonJS({ "src/binding.js"(exports, module) {
264
+ const { createRequire } = __require("node:module");
265
+ const { readFileSync } = __require("node:fs");
266
+ let nativeBinding = null;
267
+ const loadErrors = [];
268
+ const isMusl = () => {
269
+ let musl = false;
270
+ if (process.platform === "linux") {
271
+ musl = isMuslFromFilesystem();
272
+ if (musl === null) musl = isMuslFromReport();
273
+ if (musl === null) musl = isMuslFromChildProcess();
274
+ }
275
+ return musl;
276
+ };
277
+ const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
278
+ const isMuslFromFilesystem = () => {
279
+ try {
280
+ return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
281
+ } catch {
282
+ return null;
283
+ }
284
+ };
285
+ const isMuslFromReport = () => {
286
+ const report = typeof process.report.getReport === "function" ? process.report.getReport() : null;
287
+ if (!report) return null;
288
+ if (report.header && report.header.glibcVersionRuntime) return false;
289
+ if (Array.isArray(report.sharedObjects)) {
290
+ if (report.sharedObjects.some(isFileMusl)) return true;
291
+ }
292
+ return false;
293
+ };
294
+ const isMuslFromChildProcess = () => {
295
+ try {
296
+ return __require("child_process").execSync("ldd --version", { encoding: "utf8" }).includes("musl");
297
+ } catch (e) {
298
+ return false;
299
+ }
300
+ };
301
+ function requireNative() {
302
+ if (process.platform === "android") if (process.arch === "arm64") {
303
+ try {
304
+ return __require("./rolldown-binding.android-arm64.node");
305
+ } catch (e) {
306
+ loadErrors.push(e);
307
+ }
308
+ try {
309
+ return __require("@rolldown/binding-android-arm64");
310
+ } catch (e) {
311
+ loadErrors.push(e);
312
+ }
313
+ } else if (process.arch === "arm") {
314
+ try {
315
+ return __require("./rolldown-binding.android-arm-eabi.node");
316
+ } catch (e) {
317
+ loadErrors.push(e);
318
+ }
319
+ try {
320
+ return __require("@rolldown/binding-android-arm-eabi");
321
+ } catch (e) {
322
+ loadErrors.push(e);
323
+ }
324
+ } else loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`));
325
+ else if (process.platform === "win32") if (process.arch === "x64") {
326
+ try {
327
+ return __require("./rolldown-binding.win32-x64-msvc.node");
328
+ } catch (e) {
329
+ loadErrors.push(e);
330
+ }
331
+ try {
332
+ return __require("@rolldown/binding-win32-x64-msvc");
333
+ } catch (e) {
334
+ loadErrors.push(e);
335
+ }
336
+ } else if (process.arch === "ia32") {
337
+ try {
338
+ return __require("./rolldown-binding.win32-ia32-msvc.node");
339
+ } catch (e) {
340
+ loadErrors.push(e);
341
+ }
342
+ try {
343
+ return __require("@rolldown/binding-win32-ia32-msvc");
344
+ } catch (e) {
345
+ loadErrors.push(e);
346
+ }
347
+ } else if (process.arch === "arm64") {
348
+ try {
349
+ return __require("./rolldown-binding.win32-arm64-msvc.node");
350
+ } catch (e) {
351
+ loadErrors.push(e);
352
+ }
353
+ try {
354
+ return __require("@rolldown/binding-win32-arm64-msvc");
355
+ } catch (e) {
356
+ loadErrors.push(e);
357
+ }
358
+ } else loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));
359
+ else if (process.platform === "darwin") {
360
+ try {
361
+ return __require("./rolldown-binding.darwin-universal.node");
362
+ } catch (e) {
363
+ loadErrors.push(e);
364
+ }
365
+ try {
366
+ return __require("@rolldown/binding-darwin-universal");
367
+ } catch (e) {
368
+ loadErrors.push(e);
369
+ }
370
+ if (process.arch === "x64") {
371
+ try {
372
+ return __require("./rolldown-binding.darwin-x64.node");
373
+ } catch (e) {
374
+ loadErrors.push(e);
375
+ }
376
+ try {
377
+ return __require("@rolldown/binding-darwin-x64");
378
+ } catch (e) {
379
+ loadErrors.push(e);
380
+ }
381
+ } else if (process.arch === "arm64") {
382
+ try {
383
+ return __require("./rolldown-binding.darwin-arm64.node");
384
+ } catch (e) {
385
+ loadErrors.push(e);
386
+ }
387
+ try {
388
+ return __require("@rolldown/binding-darwin-arm64");
389
+ } catch (e) {
390
+ loadErrors.push(e);
391
+ }
392
+ } else loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`));
393
+ } else if (process.platform === "freebsd") if (process.arch === "x64") {
394
+ try {
395
+ return __require("./rolldown-binding.freebsd-x64.node");
396
+ } catch (e) {
397
+ loadErrors.push(e);
398
+ }
399
+ try {
400
+ return __require("@rolldown/binding-freebsd-x64");
401
+ } catch (e) {
402
+ loadErrors.push(e);
403
+ }
404
+ } else if (process.arch === "arm64") {
405
+ try {
406
+ return __require("./rolldown-binding.freebsd-arm64.node");
407
+ } catch (e) {
408
+ loadErrors.push(e);
409
+ }
410
+ try {
411
+ return __require("@rolldown/binding-freebsd-arm64");
412
+ } catch (e) {
413
+ loadErrors.push(e);
414
+ }
415
+ } else loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
416
+ else if (process.platform === "linux") if (process.arch === "x64") if (isMusl()) {
417
+ try {
418
+ return __require("./rolldown-binding.linux-x64-musl.node");
419
+ } catch (e) {
420
+ loadErrors.push(e);
421
+ }
422
+ try {
423
+ return __require("@rolldown/binding-linux-x64-musl");
424
+ } catch (e) {
425
+ loadErrors.push(e);
426
+ }
427
+ } else {
428
+ try {
429
+ return __require("./rolldown-binding.linux-x64-gnu.node");
430
+ } catch (e) {
431
+ loadErrors.push(e);
432
+ }
433
+ try {
434
+ return __require("@rolldown/binding-linux-x64-gnu");
435
+ } catch (e) {
436
+ loadErrors.push(e);
437
+ }
438
+ }
439
+ else if (process.arch === "arm64") if (isMusl()) {
440
+ try {
441
+ return __require("./rolldown-binding.linux-arm64-musl.node");
442
+ } catch (e) {
443
+ loadErrors.push(e);
444
+ }
445
+ try {
446
+ return __require("@rolldown/binding-linux-arm64-musl");
447
+ } catch (e) {
448
+ loadErrors.push(e);
449
+ }
450
+ } else {
451
+ try {
452
+ return __require("./rolldown-binding.linux-arm64-gnu.node");
453
+ } catch (e) {
454
+ loadErrors.push(e);
455
+ }
456
+ try {
457
+ return __require("@rolldown/binding-linux-arm64-gnu");
458
+ } catch (e) {
459
+ loadErrors.push(e);
460
+ }
461
+ }
462
+ else if (process.arch === "arm") if (isMusl()) {
463
+ try {
464
+ return __require("./rolldown-binding.linux-arm-musleabihf.node");
465
+ } catch (e) {
466
+ loadErrors.push(e);
467
+ }
468
+ try {
469
+ return __require("@rolldown/binding-linux-arm-musleabihf");
470
+ } catch (e) {
471
+ loadErrors.push(e);
472
+ }
473
+ } else {
474
+ try {
475
+ return __require("./rolldown-binding.linux-arm-gnueabihf.node");
476
+ } catch (e) {
477
+ loadErrors.push(e);
478
+ }
479
+ try {
480
+ return __require("@rolldown/binding-linux-arm-gnueabihf");
481
+ } catch (e) {
482
+ loadErrors.push(e);
483
+ }
484
+ }
485
+ else if (process.arch === "riscv64") if (isMusl()) {
486
+ try {
487
+ return __require("./rolldown-binding.linux-riscv64-musl.node");
488
+ } catch (e) {
489
+ loadErrors.push(e);
490
+ }
491
+ try {
492
+ return __require("@rolldown/binding-linux-riscv64-musl");
493
+ } catch (e) {
494
+ loadErrors.push(e);
495
+ }
496
+ } else {
497
+ try {
498
+ return __require("./rolldown-binding.linux-riscv64-gnu.node");
499
+ } catch (e) {
500
+ loadErrors.push(e);
501
+ }
502
+ try {
503
+ return __require("@rolldown/binding-linux-riscv64-gnu");
504
+ } catch (e) {
505
+ loadErrors.push(e);
506
+ }
507
+ }
508
+ else if (process.arch === "ppc64") {
509
+ try {
510
+ return __require("./rolldown-binding.linux-ppc64-gnu.node");
511
+ } catch (e) {
512
+ loadErrors.push(e);
513
+ }
514
+ try {
515
+ return __require("@rolldown/binding-linux-ppc64-gnu");
516
+ } catch (e) {
517
+ loadErrors.push(e);
518
+ }
519
+ } else if (process.arch === "s390x") {
520
+ try {
521
+ return __require("./rolldown-binding.linux-s390x-gnu.node");
522
+ } catch (e) {
523
+ loadErrors.push(e);
524
+ }
525
+ try {
526
+ return __require("@rolldown/binding-linux-s390x-gnu");
527
+ } catch (e) {
528
+ loadErrors.push(e);
529
+ }
530
+ } else loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`));
531
+ else loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`));
532
+ }
533
+ nativeBinding = requireNative();
534
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
535
+ try {
536
+ nativeBinding = __require("./rolldown-binding.wasi.cjs");
537
+ } catch (err) {
538
+ if (process.env.NAPI_RS_FORCE_WASI) loadErrors.push(err);
539
+ }
540
+ if (!nativeBinding) try {
541
+ nativeBinding = __require("@rolldown/binding-wasm32-wasi");
542
+ } catch (err) {
543
+ if (process.env.NAPI_RS_FORCE_WASI) loadErrors.push(err);
544
+ }
545
+ }
546
+ if (!nativeBinding) {
547
+ if (loadErrors.length > 0) throw new Error("Failed to load native binding", { cause: loadErrors });
548
+ throw new Error(`Failed to load native binding`);
549
+ }
550
+ module.exports.BindingBundleEndEventData = nativeBinding.BindingBundleEndEventData;
551
+ module.exports.BindingCallableBuiltinPlugin = nativeBinding.BindingCallableBuiltinPlugin;
552
+ module.exports.BindingHookError = nativeBinding.BindingHookError;
553
+ module.exports.BindingLog = nativeBinding.BindingLog;
554
+ module.exports.BindingModuleInfo = nativeBinding.BindingModuleInfo;
555
+ module.exports.BindingNormalizedOptions = nativeBinding.BindingNormalizedOptions;
556
+ module.exports.BindingOutputAsset = nativeBinding.BindingOutputAsset;
557
+ module.exports.BindingOutputChunk = nativeBinding.BindingOutputChunk;
558
+ module.exports.BindingOutputs = nativeBinding.BindingOutputs;
559
+ module.exports.BindingPluginContext = nativeBinding.BindingPluginContext;
560
+ module.exports.BindingRenderedModule = nativeBinding.BindingRenderedModule;
561
+ module.exports.BindingTransformPluginContext = nativeBinding.BindingTransformPluginContext;
562
+ module.exports.BindingWatcher = nativeBinding.BindingWatcher;
563
+ module.exports.BindingWatcherChangeData = nativeBinding.BindingWatcherChangeData;
564
+ module.exports.BindingWatcherEvent = nativeBinding.BindingWatcherEvent;
565
+ module.exports.Bundler = nativeBinding.Bundler;
566
+ module.exports.ParallelJsPluginRegistry = nativeBinding.ParallelJsPluginRegistry;
567
+ module.exports.BindingBuiltinPluginName = nativeBinding.BindingBuiltinPluginName;
568
+ module.exports.BindingHookSideEffects = nativeBinding.BindingHookSideEffects;
569
+ module.exports.BindingLogLevel = nativeBinding.BindingLogLevel;
570
+ module.exports.BindingPluginOrder = nativeBinding.BindingPluginOrder;
571
+ module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration;
572
+ module.exports.registerPlugins = nativeBinding.registerPlugins;
573
+ module.exports.transform = nativeBinding.transform;
574
+ } });
575
+
576
+ //#endregion
577
+ //#region src/utils/misc.ts
578
+ function arraify(value) {
579
+ return Array.isArray(value) ? value : [value];
580
+ }
581
+ function isNullish(value) {
582
+ return value === null || value === undefined;
583
+ }
584
+ function unimplemented(info) {
585
+ if (info) throw new Error(`unimplemented: ${info}`);
586
+ throw new Error("unimplemented");
587
+ }
588
+ function unreachable(info) {
589
+ if (info) throw new Error(`unreachable: ${info}`);
590
+ throw new Error("unreachable");
591
+ }
592
+ function unsupported(info) {
593
+ return () => {
594
+ throw new Error(`UNSUPPORTED: ${info}`);
595
+ };
596
+ }
597
+ function noop(..._args) {}
598
+
599
+ //#endregion
600
+ //#region src/log/logging.ts
601
+ const LogLevelSchema = z$1.literal("info").or(z$1.literal("debug")).or(z$1.literal("warn"));
602
+ const LogLevelOptionSchema = LogLevelSchema.or(z$1.literal("silent"));
603
+ const LogLevelWithErrorSchema = LogLevelSchema.or(z$1.literal("error"));
604
+ const LOG_LEVEL_SILENT = "silent";
605
+ const LOG_LEVEL_ERROR = "error";
606
+ const LOG_LEVEL_WARN = "warn";
607
+ const LOG_LEVEL_INFO = "info";
608
+ const LOG_LEVEL_DEBUG = "debug";
609
+ const logLevelPriority = {
610
+ [LOG_LEVEL_DEBUG]: 0,
611
+ [LOG_LEVEL_INFO]: 1,
612
+ [LOG_LEVEL_WARN]: 2,
613
+ [LOG_LEVEL_SILENT]: 3
614
+ };
615
+ const RollupLogSchema = z$1.any();
616
+ const RollupLogWithStringSchema = RollupLogSchema.or(z$1.string());
617
+
618
+ //#endregion
619
+ //#region src/utils/code-frame.ts
620
+ function spaces(index) {
621
+ let result = "";
622
+ while (index--) result += " ";
623
+ return result;
624
+ }
625
+ function tabsToSpaces(value) {
626
+ return value.replace(/^\t+/, (match) => match.split(" ").join(" "));
627
+ }
628
+ const LINE_TRUNCATE_LENGTH = 120;
629
+ const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
630
+ const ELLIPSIS = "...";
631
+ function getCodeFrame(source, line, column) {
632
+ let lines = source.split("\n");
633
+ if (line > lines.length) return "";
634
+ const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
635
+ const frameStart = Math.max(0, line - 3);
636
+ let frameEnd = Math.min(line + 2, lines.length);
637
+ lines = lines.slice(frameStart, frameEnd);
638
+ while (!/\S/.test(lines[lines.length - 1])) {
639
+ lines.pop();
640
+ frameEnd -= 1;
641
+ }
642
+ const digits = String(frameEnd).length;
643
+ return lines.map((sourceLine, index) => {
644
+ const isErrorLine = frameStart + index + 1 === line;
645
+ let lineNumber = String(index + frameStart + 1);
646
+ while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
647
+ let displayedLine = tabsToSpaces(sourceLine);
648
+ if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
649
+ if (isErrorLine) {
650
+ const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
651
+ return `${lineNumber}: ${displayedLine}\n${indicator}`;
652
+ }
653
+ return `${lineNumber}: ${displayedLine}`;
654
+ }).join("\n");
655
+ }
656
+
657
+ //#endregion
658
+ //#region src/log/locate-character/index.js
659
+ /** @typedef {import('./types').Location} Location */
660
+ /**
661
+ * @param {import('./types').Range} range
662
+ * @param {number} index
663
+ */
664
+ function rangeContains(range, index) {
665
+ return range.start <= index && index < range.end;
666
+ }
667
+ function getLocator(source, options = {}) {
668
+ const { offsetLine = 0, offsetColumn = 0 } = options;
669
+ let start = 0;
670
+ const ranges = source.split("\n").map((line, i$1) => {
671
+ const end = start + line.length + 1;
672
+ /** @type {import('./types').Range} */
673
+ const range = {
674
+ start,
675
+ end,
676
+ line: i$1
677
+ };
678
+ start = end;
679
+ return range;
680
+ });
681
+ let i = 0;
682
+ /**
683
+ * @param {string | number} search
684
+ * @param {number} [index]
685
+ * @returns {Location | undefined}
686
+ */
687
+ function locator(search, index) {
688
+ if (typeof search === "string") search = source.indexOf(search, index ?? 0);
689
+ if (search === -1) return undefined;
690
+ let range = ranges[i];
691
+ const d = search >= range.end ? 1 : -1;
692
+ while (range) {
693
+ if (rangeContains(range, search)) return {
694
+ line: offsetLine + range.line,
695
+ column: offsetColumn + search - range.start,
696
+ character: search
697
+ };
698
+ i += d;
699
+ range = ranges[i];
700
+ }
701
+ }
702
+ return locator;
703
+ }
704
+ function locate(source, search, options) {
705
+ return getLocator(source, options)(search, options && options.startIndex);
706
+ }
707
+
708
+ //#endregion
709
+ //#region src/log/logs.ts
710
+ 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";
711
+ function logInvalidLogPosition(pluginName) {
712
+ return {
713
+ code: INVALID_LOG_POSITION,
714
+ 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.`
715
+ };
716
+ }
717
+ function logInputHookInOutputPlugin(pluginName, hookName) {
718
+ return {
719
+ code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
720
+ 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.`
721
+ };
722
+ }
723
+ function logCycleLoading(pluginName, moduleId) {
724
+ return {
725
+ code: CYCLE_LOADING,
726
+ message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
727
+ };
728
+ }
729
+ function logPluginError(error$1, plugin, { hook, id } = {}) {
730
+ const code = error$1.code;
731
+ if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
732
+ error$1.code = PLUGIN_ERROR;
733
+ error$1.plugin = plugin;
734
+ if (hook) error$1.hook = hook;
735
+ if (id) error$1.id = id;
736
+ return error$1;
737
+ }
738
+ function error(base) {
739
+ if (!(base instanceof Error)) {
740
+ base = Object.assign(new Error(base.message), base);
741
+ Object.defineProperty(base, "name", {
742
+ value: "RollupError",
743
+ writable: true
744
+ });
745
+ }
746
+ throw base;
747
+ }
748
+ function augmentCodeLocation(properties, pos, source, id) {
749
+ if (typeof pos === "object") {
750
+ const { line, column } = pos;
751
+ properties.loc = {
752
+ column,
753
+ file: id,
754
+ line
755
+ };
756
+ } else {
757
+ properties.pos = pos;
758
+ const location = locate(source, pos, { offsetLine: 1 });
759
+ if (!location) return;
760
+ const { line, column } = location;
761
+ properties.loc = {
762
+ column,
763
+ file: id,
764
+ line
765
+ };
766
+ }
767
+ if (properties.frame === undefined) {
768
+ const { line, column } = properties.loc;
769
+ properties.frame = getCodeFrame(source, line, column);
770
+ }
771
+ }
772
+
773
+ //#endregion
774
+ //#region src/log/logHandler.ts
775
+ const normalizeLog = (log) => typeof log === "string" ? { message: log } : typeof log === "function" ? normalizeLog(log()) : log;
776
+ function getLogHandler(level, code, logger, pluginName, logLevel) {
777
+ if (logLevelPriority[level] < logLevelPriority[logLevel]) return noop;
778
+ return (log, pos) => {
779
+ if (pos != null) logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
780
+ log = normalizeLog(log);
781
+ if (log.code && !log.pluginCode) log.pluginCode = log.code;
782
+ log.code = code;
783
+ log.plugin = pluginName;
784
+ logger(level, log);
785
+ };
786
+ }
787
+
788
+ //#endregion
789
+ //#region src/utils/normalize-hook.ts
790
+ function normalizeHook(hook) {
791
+ if (typeof hook === "function" || typeof hook === "string") return {
792
+ handler: hook,
793
+ options: {},
794
+ meta: {}
795
+ };
796
+ if (typeof hook === "object" && hook !== null) {
797
+ const { handler, order,...options } = hook;
798
+ return {
799
+ handler,
800
+ options,
801
+ meta: { order }
802
+ };
803
+ }
804
+ unreachable("Invalid hook type");
805
+ }
806
+
807
+ //#endregion
808
+ //#region src/log/logger.ts
809
+ function getLogger(plugins, onLog, logLevel) {
810
+ const minimalPriority = logLevelPriority[logLevel];
811
+ const logger = (level, log, skipped = new Set()) => {
812
+ const logPriority = logLevelPriority[level];
813
+ if (logPriority < minimalPriority) return;
814
+ for (const plugin of getSortedPlugins("onLog", plugins)) {
815
+ if (skipped.has(plugin)) continue;
816
+ const { onLog: pluginOnLog } = plugin;
817
+ if (pluginOnLog) {
818
+ const getLogHandler$1 = (level$1) => {
819
+ if (logLevelPriority[level$1] < minimalPriority) return () => {};
820
+ return (log$1) => logger(level$1, normalizeLog(log$1), new Set(skipped).add(plugin));
821
+ };
822
+ const handler = "handler" in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
823
+ if (handler.call({
824
+ debug: getLogHandler$1(LOG_LEVEL_DEBUG),
825
+ error: (log$1) => error(normalizeLog(log$1)),
826
+ info: getLogHandler$1(LOG_LEVEL_INFO),
827
+ meta: {
828
+ rollupVersion: "4.23.0",
829
+ rolldownVersion: VERSION,
830
+ watchMode: false
831
+ },
832
+ warn: getLogHandler$1(LOG_LEVEL_WARN)
833
+ }, level, log) === false) return;
834
+ }
835
+ }
836
+ onLog(level, log);
837
+ };
838
+ return logger;
839
+ }
840
+ const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
841
+ const { onwarn, onLog } = config;
842
+ const defaultOnLog = getDefaultOnLog(printLog, onwarn);
843
+ if (onLog) {
844
+ const minimalPriority = logLevelPriority[logLevel];
845
+ return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => {
846
+ if (level$1 === LOG_LEVEL_ERROR) return error(normalizeLog(handledLog));
847
+ if (logLevelPriority[level$1] >= minimalPriority) defaultOnLog(level$1, normalizeLog(handledLog));
848
+ });
849
+ }
850
+ return defaultOnLog;
851
+ };
852
+ const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
853
+ if (level === LOG_LEVEL_WARN) onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
854
+ else printLog(level, log);
855
+ } : printLog;
856
+ const addLogToString = (log) => {
857
+ Object.defineProperty(log, "toString", {
858
+ value: () => getExtendedLogMessage(log),
859
+ writable: true
860
+ });
861
+ return log;
862
+ };
863
+ const defaultPrintLog = (level, log) => {
864
+ const message = getExtendedLogMessage(log);
865
+ switch (level) {
866
+ case LOG_LEVEL_WARN: return console.warn(message);
867
+ case LOG_LEVEL_DEBUG: return console.debug(message);
868
+ default: return console.info(message);
869
+ }
870
+ };
871
+ const getExtendedLogMessage = (log) => {
872
+ let prefix = "";
873
+ if (log.plugin) prefix += `(${log.plugin} plugin) `;
874
+ if (log.loc) prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
875
+ return prefix + log.message;
876
+ };
877
+ function relativeId(id) {
878
+ if (!path$1.isAbsolute(id)) return id;
879
+ return path$1.relative(path$1.resolve(), id);
880
+ }
881
+
882
+ //#endregion
883
+ //#region src/builtin-plugin/utils.ts
884
+ var import_binding$5 = __toESM(require_binding());
885
+ function makeBuiltinPluginCallable(plugin) {
886
+ let callablePlugin = new import_binding$5.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
887
+ const wrappedPlugin = plugin;
888
+ for (const key in callablePlugin) wrappedPlugin[key] = function(...args) {
889
+ return callablePlugin[key](...args);
890
+ };
891
+ return wrappedPlugin;
892
+ }
893
+ function bindingifyBuiltInPlugin(plugin) {
894
+ return {
895
+ __name: plugin.name,
896
+ options: plugin._options
897
+ };
898
+ }
899
+
900
+ //#endregion
901
+ //#region src/builtin-plugin/constructors.ts
902
+ var BuiltinPlugin = class {
903
+ constructor(name, _options) {
904
+ this.name = name;
905
+ this._options = _options;
906
+ this.name = name;
907
+ this._options = _options;
908
+ }
909
+ };
910
+ function modulePreloadPolyfillPlugin(config) {
911
+ return new BuiltinPlugin("builtin:module-preload-polyfill", config);
912
+ }
913
+ function dynamicImportVarsPlugin() {
914
+ return new BuiltinPlugin("builtin:dynamic-import-vars");
915
+ }
916
+ function importGlobPlugin(config) {
917
+ return new BuiltinPlugin("builtin:import-glob", config);
918
+ }
919
+ function manifestPlugin(config) {
920
+ return new BuiltinPlugin("builtin:manifest", config);
921
+ }
922
+ function wasmHelperPlugin() {
923
+ return new BuiltinPlugin("builtin:wasm-helper");
924
+ }
925
+ function wasmFallbackPlugin() {
926
+ return new BuiltinPlugin("builtin:wasm-fallback");
927
+ }
928
+ function loadFallbackPlugin() {
929
+ return new BuiltinPlugin("builtin:load-fallback");
930
+ }
931
+ function jsonPlugin(config) {
932
+ return new BuiltinPlugin("builtin:json", config);
933
+ }
934
+ function buildImportAnalysisPlugin(config) {
935
+ return new BuiltinPlugin("builtin:build-import-analysis", config);
936
+ }
937
+ function viteResolvePlugin(config) {
938
+ const builtinPlugin = new BuiltinPlugin("builtin:vite-resolve", {
939
+ ...config,
940
+ runtime: process.versions.deno ? "deno" : process.versions.bun ? "bun" : "node"
941
+ });
942
+ return makeBuiltinPluginCallable(builtinPlugin);
943
+ }
944
+
945
+ //#endregion
946
+ //#region src/utils/async-flatten.ts
947
+ async function asyncFlatten(array) {
948
+ do
949
+ array = (await Promise.all(array)).flat(Infinity);
950
+ while (array.some((v) => v?.then));
951
+ return array;
952
+ }
953
+
954
+ //#endregion
955
+ //#region src/constants/plugin.ts
956
+ const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES = [
957
+ "options",
958
+ "buildStart",
959
+ "resolveId",
960
+ "load",
961
+ "transform",
962
+ "moduleParsed",
963
+ "buildEnd",
964
+ "onLog",
965
+ "resolveDynamicImport",
966
+ "closeBundle",
967
+ "closeWatcher",
968
+ "watchChange"
969
+ ];
970
+ const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES = [
971
+ "augmentChunkHash",
972
+ "outputOptions",
973
+ "renderChunk",
974
+ "renderStart",
975
+ "renderError",
976
+ "writeBundle",
977
+ "generateBundle"
978
+ ];
979
+ const ENUMERATED_PLUGIN_HOOK_NAMES = [
980
+ ...ENUMERATED_INPUT_PLUGIN_HOOK_NAMES,
981
+ ...ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES,
982
+ "footer",
983
+ "banner",
984
+ "intro",
985
+ "outro"
986
+ ];
987
+ const DEFINED_HOOK_NAMES = {
988
+ [ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0],
989
+ [ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1],
990
+ [ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2],
991
+ [ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3],
992
+ [ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4],
993
+ [ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5],
994
+ [ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6],
995
+ [ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7],
996
+ [ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8],
997
+ [ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9],
998
+ [ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10],
999
+ [ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11],
1000
+ [ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12],
1001
+ [ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13],
1002
+ [ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14],
1003
+ [ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15],
1004
+ [ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16],
1005
+ [ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17],
1006
+ [ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18],
1007
+ [ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19],
1008
+ [ENUMERATED_PLUGIN_HOOK_NAMES[20]]: ENUMERATED_PLUGIN_HOOK_NAMES[20],
1009
+ [ENUMERATED_PLUGIN_HOOK_NAMES[21]]: ENUMERATED_PLUGIN_HOOK_NAMES[21],
1010
+ [ENUMERATED_PLUGIN_HOOK_NAMES[22]]: ENUMERATED_PLUGIN_HOOK_NAMES[22]
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/plugin-driver.ts
1036
+ var PluginDriver = class {
1037
+ async callOptionsHook(inputOptions) {
1038
+ const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
1039
+ const plugins = getSortedPlugins("options", getObjectPlugins(await normalizePluginOption(inputOptions.plugins)));
1040
+ const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel);
1041
+ for (const plugin of plugins) {
1042
+ const name = plugin.name || "unknown";
1043
+ const options = plugin.options;
1044
+ if (options) {
1045
+ const { handler } = normalizeHook(options);
1046
+ const result = await handler.call({
1047
+ debug: getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", logger, name, logLevel),
1048
+ error: (e) => error(logPluginError(normalizeLog(e), name, { hook: "onLog" })),
1049
+ info: getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", logger, name, logLevel),
1050
+ meta: {
1051
+ rollupVersion: "4.23.0",
1052
+ rolldownVersion: VERSION,
1053
+ watchMode: false
1054
+ },
1055
+ warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel)
1056
+ }, inputOptions);
1057
+ if (result) inputOptions = result;
1058
+ }
1059
+ }
1060
+ return inputOptions;
1061
+ }
1062
+ callOutputOptionsHook(rawPlugins, outputOptions) {
1063
+ const sortedPlugins = getSortedPlugins("outputOptions", getObjectPlugins(rawPlugins));
1064
+ for (const plugin of sortedPlugins) {
1065
+ const options = plugin.outputOptions;
1066
+ if (options) {
1067
+ const { handler } = normalizeHook(options);
1068
+ const result = handler.call(null, outputOptions);
1069
+ if (result) outputOptions = result;
1070
+ }
1071
+ }
1072
+ return outputOptions;
1073
+ }
1074
+ };
1075
+ function getObjectPlugins(plugins) {
1076
+ return plugins.filter((plugin) => {
1077
+ if (!plugin) return undefined;
1078
+ if ("_parallel" in plugin) return undefined;
1079
+ if (plugin instanceof BuiltinPlugin) return undefined;
1080
+ return plugin;
1081
+ });
1082
+ }
1083
+ function getSortedPlugins(hookName, plugins) {
1084
+ const pre = [];
1085
+ const normal = [];
1086
+ const post = [];
1087
+ for (const plugin of plugins) {
1088
+ const hook = plugin[hookName];
1089
+ if (hook) {
1090
+ if (typeof hook === "object") {
1091
+ if (hook.order === "pre") {
1092
+ pre.push(plugin);
1093
+ continue;
1094
+ }
1095
+ if (hook.order === "post") {
1096
+ post.push(plugin);
1097
+ continue;
1098
+ }
1099
+ }
1100
+ normal.push(plugin);
1101
+ }
1102
+ }
1103
+ return [
1104
+ ...pre,
1105
+ ...normal,
1106
+ ...post
1107
+ ];
1108
+ }
1109
+
1110
+ //#endregion
1111
+ //#region src/treeshake/module-side-effects.ts
1112
+ const ModuleSideEffectsRuleSchema = z.object({
1113
+ test: z.instanceof(RegExp).optional(),
1114
+ external: z.boolean().optional(),
1115
+ sideEffects: z.boolean()
1116
+ }).refine((data) => {
1117
+ return data.test !== undefined || data.external !== undefined;
1118
+ }, "Either `test` or `external` should be set.");
1119
+ const ModuleSideEffectsOptionSchema = z.boolean().or(z.array(ModuleSideEffectsRuleSchema)).or(z.literal("no-external"));
1120
+ const TreeshakingOptionsSchema = z.object({
1121
+ moduleSideEffects: ModuleSideEffectsOptionSchema.optional(),
1122
+ annotations: z.boolean().optional()
1123
+ }).passthrough().or(z.boolean());
1124
+
1125
+ //#endregion
1126
+ //#region src/utils/transform-sourcemap.ts
1127
+ function isEmptySourcemapFiled(array) {
1128
+ if (!array) return true;
1129
+ if (array.length === 0 || !array[0]) return true;
1130
+ return false;
1131
+ }
1132
+ function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
1133
+ if (!rawMap) return;
1134
+ let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
1135
+ if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
1136
+ if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
1137
+ return map;
1138
+ }
1139
+
1140
+ //#endregion
1141
+ //#region src/utils/transform-module-info.ts
1142
+ function transformModuleInfo(info, option) {
1143
+ return {
1144
+ get ast() {
1145
+ return unsupported("ModuleInfo#ast");
1146
+ },
1147
+ get code() {
1148
+ return info.code;
1149
+ },
1150
+ id: info.id,
1151
+ importers: info.importers,
1152
+ dynamicImporters: info.dynamicImporters,
1153
+ importedIds: info.importedIds,
1154
+ dynamicallyImportedIds: info.dynamicallyImportedIds,
1155
+ isEntry: info.isEntry,
1156
+ ...option
1157
+ };
1158
+ }
1159
+
1160
+ //#endregion
1161
+ //#region src/plugin/minimal-plugin-context.ts
1162
+ var MinimalPluginContext = class {
1163
+ info;
1164
+ warn;
1165
+ debug;
1166
+ meta;
1167
+ error;
1168
+ constructor(onLog, logLevel, plugin) {
1169
+ const pluginName = plugin.name || "unknown";
1170
+ this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
1171
+ this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
1172
+ this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
1173
+ this.error = (e) => {
1174
+ return error(logPluginError(normalizeLog(e), pluginName));
1175
+ };
1176
+ this.meta = {
1177
+ rollupVersion: "4.23.0",
1178
+ rolldownVersion: VERSION,
1179
+ watchMode: false
1180
+ };
1181
+ }
1182
+ };
1183
+
1184
+ //#endregion
1185
+ //#region src/utils/transform-side-effects.ts
1186
+ var import_binding$4 = __toESM(require_binding());
1187
+ function bindingifySideEffects(sideEffects) {
1188
+ switch (sideEffects) {
1189
+ case true: return import_binding$4.BindingHookSideEffects.True;
1190
+ case false: return import_binding$4.BindingHookSideEffects.False;
1191
+ case "no-treeshake": return import_binding$4.BindingHookSideEffects.NoTreeshake;
1192
+ case null:
1193
+ case undefined: return undefined;
1194
+ default: throw new Error(`Unexpected side effects: ${sideEffects}`);
1195
+ }
1196
+ }
1197
+
1198
+ //#endregion
1199
+ //#region src/plugin/plugin-context.ts
1200
+ var PluginContext = class extends MinimalPluginContext {
1201
+ load;
1202
+ resolve;
1203
+ emitFile;
1204
+ getFileName;
1205
+ getModuleInfo;
1206
+ getModuleIds;
1207
+ addWatchFile;
1208
+ /**
1209
+ * @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
1210
+ */
1211
+ parse;
1212
+ constructor(context, plugin, data, onLog, logLevel, currentLoadingModule) {
1213
+ super(onLog, logLevel, plugin);
1214
+ this.load = async ({ id,...options }) => {
1215
+ if (id === currentLoadingModule) onLog(LOG_LEVEL_WARN, logCycleLoading(plugin.name, currentLoadingModule));
1216
+ const moduleInfo = data.getModuleInfo(id, context);
1217
+ if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
1218
+ const rawOptions = {
1219
+ meta: options.meta || {},
1220
+ moduleSideEffects: options.moduleSideEffects || null
1221
+ };
1222
+ data.updateModuleOption(id, rawOptions);
1223
+ async function createLoadModulePromise() {
1224
+ const loadPromise = data.loadModulePromiseMap.get(id);
1225
+ if (loadPromise) return loadPromise;
1226
+ let resolveFn;
1227
+ const promise = new Promise((resolve, _) => {
1228
+ resolveFn = resolve;
1229
+ });
1230
+ data.loadModulePromiseMap.set(id, promise);
1231
+ try {
1232
+ await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
1233
+ } finally {
1234
+ data.loadModulePromiseMap.delete(id);
1235
+ }
1236
+ return promise;
1237
+ }
1238
+ await createLoadModulePromise();
1239
+ return data.getModuleInfo(id, context);
1240
+ };
1241
+ this.resolve = async (source, importer, options) => {
1242
+ let receipt = undefined;
1243
+ if (options != null) receipt = data.saveResolveOptions(options);
1244
+ const res = await context.resolve(source, importer, {
1245
+ custom: receipt,
1246
+ skipSelf: options?.skipSelf
1247
+ });
1248
+ if (receipt != null) data.removeSavedResolveOptions(receipt);
1249
+ if (res == null) return null;
1250
+ const info = data.getModuleOption(res.id) || {};
1251
+ return {
1252
+ ...res,
1253
+ ...info
1254
+ };
1255
+ };
1256
+ this.emitFile = (file) => {
1257
+ if (file.type !== "asset") return unimplemented("PluginContext.emitFile: only asset type is supported");
1258
+ return context.emitFile({
1259
+ ...file,
1260
+ originalFileName: file.originalFileName || undefined,
1261
+ source: bindingAssetSource(file.source)
1262
+ });
1263
+ };
1264
+ this.getFileName = context.getFileName.bind(context);
1265
+ this.getModuleInfo = (id) => data.getModuleInfo(id, context);
1266
+ this.getModuleIds = () => data.getModuleIds(context);
1267
+ this.parse = unsupported("`PluginContext#parse` is not supported by rolldown.");
1268
+ this.addWatchFile = context.addWatchFile.bind(context);
1269
+ }
1270
+ };
1271
+
1272
+ //#endregion
1273
+ //#region src/plugin/transform-plugin-context.ts
1274
+ var TransformPluginContext = class extends PluginContext {
1275
+ error;
1276
+ getCombinedSourcemap;
1277
+ constructor(context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption) {
1278
+ super(context, plugin, data, onLog, LogLevelOption, moduleId);
1279
+ const getLogHandler$1 = (handler) => (log, pos) => {
1280
+ log = normalizeLog(log);
1281
+ if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
1282
+ log.id = moduleId;
1283
+ log.hook = "transform";
1284
+ handler(log);
1285
+ };
1286
+ this.debug = getLogHandler$1(this.debug);
1287
+ this.warn = getLogHandler$1(this.warn);
1288
+ this.info = getLogHandler$1(this.info);
1289
+ this.error = (e, pos) => {
1290
+ if (typeof e === "string") e = { message: e };
1291
+ if (pos) augmentCodeLocation(e, pos, moduleSource, moduleId);
1292
+ e.id = moduleId;
1293
+ e.hook = "transform";
1294
+ return error(logPluginError(normalizeLog(e), plugin.name || "unknown"));
1295
+ };
1296
+ this.getCombinedSourcemap = () => JSON.parse(inner.getCombinedSourcemap());
1297
+ }
1298
+ };
1299
+
1300
+ //#endregion
1301
+ //#region src/plugin/bindingify-plugin-hook-meta.ts
1302
+ var import_binding$3 = __toESM(require_binding());
1303
+ function bindingifyPluginHookMeta(options) {
1304
+ return { order: bindingPluginOrder(options.order) };
1305
+ }
1306
+ function bindingPluginOrder(order) {
1307
+ switch (order) {
1308
+ case "post": return import_binding$3.BindingPluginOrder.Post;
1309
+ case "pre": return import_binding$3.BindingPluginOrder.Pre;
1310
+ case null:
1311
+ case undefined: return undefined;
1312
+ default: throw new Error(`Unknown plugin order: ${order}`);
1313
+ }
1314
+ }
1315
+
1316
+ //#endregion
1317
+ //#region src/constants/plugin-context.ts
1318
+ const SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF = Symbol("plugin-context-resolve-caller");
1319
+
1320
+ //#endregion
1321
+ //#region src/plugin/bindingify-hook-filter.ts
1322
+ function bindingifyStringFilter(matcher) {
1323
+ if (typeof matcher === "string" || matcher instanceof RegExp) return { include: [matcher] };
1324
+ if (Array.isArray(matcher)) return { include: matcher };
1325
+ return {
1326
+ include: matcher.include ? arraify(matcher.include) : undefined,
1327
+ exclude: matcher.exclude ? arraify(matcher.exclude) : undefined
1328
+ };
1329
+ }
1330
+ function bindingifyResolveIdFilter(filterOption) {
1331
+ return filterOption?.id ? bindingifyStringFilter(filterOption.id) : undefined;
1332
+ }
1333
+ function bindingifyLoadFilter(filterOption) {
1334
+ return filterOption?.id ? bindingifyStringFilter(filterOption.id) : undefined;
1335
+ }
1336
+ function bindingifyTransformFilter(filterOption) {
1337
+ if (!filterOption) return undefined;
1338
+ const { id, code, moduleType } = filterOption;
1339
+ let moduleTypeRet;
1340
+ if (moduleType) if (Array.isArray(moduleType)) moduleTypeRet = moduleType;
1341
+ else moduleTypeRet = moduleType.include;
1342
+ return {
1343
+ id: id ? bindingifyStringFilter(id) : undefined,
1344
+ code: code ? bindingifyStringFilter(code) : undefined,
1345
+ moduleType: moduleTypeRet
1346
+ };
1347
+ }
1348
+
1349
+ //#endregion
1350
+ //#region src/options/normalized-input-options.ts
1351
+ var NormalizedInputOptionsImpl = class {
1352
+ inner;
1353
+ constructor(inner, onLog) {
1354
+ this.onLog = onLog;
1355
+ this.inner = inner;
1356
+ }
1357
+ get shimMissingExports() {
1358
+ return this.inner.shimMissingExports;
1359
+ }
1360
+ get input() {
1361
+ return this.inner.input;
1362
+ }
1363
+ get cwd() {
1364
+ return this.inner.cwd ?? undefined;
1365
+ }
1366
+ get platform() {
1367
+ return this.inner.platform;
1368
+ }
1369
+ };
1370
+
1371
+ //#endregion
1372
+ //#region src/plugin/bindingify-build-hooks.ts
1373
+ function bindingifyBuildStart(args) {
1374
+ const hook = args.plugin.buildStart;
1375
+ if (!hook) return {};
1376
+ const { handler, meta } = normalizeHook(hook);
1377
+ return {
1378
+ plugin: async (ctx, opts) => {
1379
+ await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedInputOptionsImpl(opts, args.onLog));
1380
+ },
1381
+ meta: bindingifyPluginHookMeta(meta)
1382
+ };
1383
+ }
1384
+ function bindingifyBuildEnd(args) {
1385
+ const hook = args.plugin.buildEnd;
1386
+ if (!hook) return {};
1387
+ const { handler, meta } = normalizeHook(hook);
1388
+ return {
1389
+ plugin: async (ctx, err) => {
1390
+ await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err.errors) : undefined);
1391
+ },
1392
+ meta: bindingifyPluginHookMeta(meta)
1393
+ };
1394
+ }
1395
+ function bindingifyResolveId(args) {
1396
+ const hook = args.plugin.resolveId;
1397
+ if (!hook) return {};
1398
+ const { handler, meta, options } = normalizeHook(hook);
1399
+ return {
1400
+ plugin: async (ctx, specifier, importer, extraOptions) => {
1401
+ const contextResolveOptions = extraOptions.custom != null ? args.pluginContextData.getSavedResolveOptions(extraOptions.custom) : undefined;
1402
+ const newExtraOptions = {
1403
+ ...extraOptions,
1404
+ custom: contextResolveOptions?.custom,
1405
+ [SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]: contextResolveOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]
1406
+ };
1407
+ const ret = await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), specifier, importer ?? undefined, newExtraOptions);
1408
+ if (ret == null) return;
1409
+ if (ret === false) return {
1410
+ id: specifier,
1411
+ external: true
1412
+ };
1413
+ if (typeof ret === "string") return { id: ret };
1414
+ args.pluginContextData.updateModuleOption(ret.id, {
1415
+ meta: ret.meta || {},
1416
+ moduleSideEffects: ret.moduleSideEffects || null
1417
+ });
1418
+ return {
1419
+ id: ret.id,
1420
+ external: ret.external,
1421
+ sideEffects: bindingifySideEffects(ret.moduleSideEffects)
1422
+ };
1423
+ },
1424
+ meta: bindingifyPluginHookMeta(meta),
1425
+ filter: bindingifyResolveIdFilter(options.filter)
1426
+ };
1427
+ }
1428
+ function bindingifyResolveDynamicImport(args) {
1429
+ const hook = args.plugin.resolveDynamicImport;
1430
+ if (!hook) return {};
1431
+ const { handler, meta } = normalizeHook(hook);
1432
+ return {
1433
+ plugin: async (ctx, specifier, importer) => {
1434
+ const ret = await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), specifier, importer ?? undefined);
1435
+ if (ret == null) return;
1436
+ if (ret === false) return {
1437
+ id: specifier,
1438
+ external: true
1439
+ };
1440
+ if (typeof ret === "string") return { id: ret };
1441
+ const result = {
1442
+ id: ret.id,
1443
+ external: ret.external
1444
+ };
1445
+ if (ret.moduleSideEffects !== null) result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
1446
+ args.pluginContextData.updateModuleOption(ret.id, {
1447
+ meta: ret.meta || {},
1448
+ moduleSideEffects: ret.moduleSideEffects || null
1449
+ });
1450
+ return result;
1451
+ },
1452
+ meta: bindingifyPluginHookMeta(meta)
1453
+ };
1454
+ }
1455
+ function bindingifyTransform(args) {
1456
+ const hook = args.plugin.transform;
1457
+ if (!hook) return {};
1458
+ const { handler, meta, options } = normalizeHook(hook);
1459
+ return {
1460
+ plugin: async (ctx, code, id, meta$1) => {
1461
+ const ret = await handler.call(new TransformPluginContext(ctx.inner(), args.plugin, args.pluginContextData, ctx, id, code, args.onLog, args.logLevel), code, id, meta$1);
1462
+ if (ret == null) return undefined;
1463
+ if (typeof ret === "string") return { code: ret };
1464
+ args.pluginContextData.updateModuleOption(id, {
1465
+ meta: ret.meta || {},
1466
+ moduleSideEffects: ret.moduleSideEffects || null
1467
+ });
1468
+ return {
1469
+ code: ret.code,
1470
+ map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id, code, ret.map)),
1471
+ sideEffects: bindingifySideEffects(ret.moduleSideEffects),
1472
+ moduleType: ret.moduleType
1473
+ };
1474
+ },
1475
+ meta: bindingifyPluginHookMeta(meta),
1476
+ filter: bindingifyTransformFilter(options.filter)
1477
+ };
1478
+ }
1479
+ function bindingifyLoad(args) {
1480
+ const hook = args.plugin.load;
1481
+ if (!hook) return {};
1482
+ const { handler, meta, options } = normalizeHook(hook);
1483
+ return {
1484
+ plugin: async (ctx, id) => {
1485
+ const ret = await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, id), id);
1486
+ if (ret == null) return;
1487
+ if (typeof ret === "string") return { code: ret };
1488
+ args.pluginContextData.updateModuleOption(id, {
1489
+ meta: ret.meta || {},
1490
+ moduleSideEffects: ret.moduleSideEffects || null
1491
+ });
1492
+ let map = preProcessSourceMap(ret, id);
1493
+ return {
1494
+ code: ret.code,
1495
+ map: bindingifySourcemap$1(map),
1496
+ moduleType: ret.moduleType,
1497
+ sideEffects: bindingifySideEffects(ret.moduleSideEffects)
1498
+ };
1499
+ },
1500
+ meta: bindingifyPluginHookMeta(meta),
1501
+ filter: bindingifyLoadFilter(options.filter)
1502
+ };
1503
+ }
1504
+ function preProcessSourceMap(ret, id) {
1505
+ if (!ret.map) return;
1506
+ let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
1507
+ if (!isEmptySourcemapFiled(map.sources)) {
1508
+ const directory = path.dirname(id) || ".";
1509
+ const sourceRoot = map.sourceRoot || ".";
1510
+ map.sources = map.sources.map((source) => path.resolve(directory, sourceRoot, source));
1511
+ }
1512
+ return map;
1513
+ }
1514
+ function bindingifyModuleParsed(args) {
1515
+ const hook = args.plugin.moduleParsed;
1516
+ if (!hook) return {};
1517
+ const { handler, meta } = normalizeHook(hook);
1518
+ return {
1519
+ plugin: async (ctx, moduleInfo) => {
1520
+ await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
1521
+ },
1522
+ meta: bindingifyPluginHookMeta(meta)
1523
+ };
1524
+ }
1525
+
1526
+ //#endregion
1527
+ //#region src/options/normalized-output-options.ts
1528
+ function mapFunctionOption(option, name) {
1529
+ return typeof option === "undefined" ? unsupported(`You should not take \`NormalizedOutputOptions#${name}\` and call it directly`) : option;
1530
+ }
1531
+ var NormalizedOutputOptionsImpl = class {
1532
+ inner;
1533
+ constructor(inner) {
1534
+ this.inner = inner;
1535
+ }
1536
+ get dir() {
1537
+ return this.inner.dir ?? undefined;
1538
+ }
1539
+ get entryFileNames() {
1540
+ return mapFunctionOption(this.inner.entryFilenames, "entryFileNames");
1541
+ }
1542
+ get chunkFileNames() {
1543
+ return mapFunctionOption(this.inner.chunkFilenames, "chunkFileNames");
1544
+ }
1545
+ get assetFileNames() {
1546
+ return this.inner.assetFilenames;
1547
+ }
1548
+ get format() {
1549
+ return this.inner.format;
1550
+ }
1551
+ get exports() {
1552
+ return this.inner.exports;
1553
+ }
1554
+ get sourcemap() {
1555
+ return this.inner.sourcemap;
1556
+ }
1557
+ get cssEntryFileNames() {
1558
+ return mapFunctionOption(this.inner.cssEntryFilenames, "cssEntryFileNames");
1559
+ }
1560
+ get cssChunkFileNames() {
1561
+ return mapFunctionOption(this.inner.cssChunkFilenames, "cssChunkFileNames");
1562
+ }
1563
+ get shimMissingExports() {
1564
+ return this.inner.shimMissingExports;
1565
+ }
1566
+ get name() {
1567
+ return this.inner.name ?? undefined;
1568
+ }
1569
+ get file() {
1570
+ return this.inner.file ?? undefined;
1571
+ }
1572
+ get inlineDynamicImports() {
1573
+ return this.inner.inlineDynamicImports;
1574
+ }
1575
+ get externalLiveBindings() {
1576
+ return this.inner.externalLiveBindings;
1577
+ }
1578
+ get banner() {
1579
+ return mapFunctionOption(this.inner.banner, "banner") ?? undefined;
1580
+ }
1581
+ get footer() {
1582
+ return mapFunctionOption(this.inner.footer, "footer") ?? undefined;
1583
+ }
1584
+ get intro() {
1585
+ return mapFunctionOption(this.inner.intro, "intro") ?? undefined;
1586
+ }
1587
+ get outro() {
1588
+ return mapFunctionOption(this.inner.outro, "outro") ?? undefined;
1589
+ }
1590
+ get esModule() {
1591
+ return this.inner.esModule;
1592
+ }
1593
+ get extend() {
1594
+ return this.inner.extend;
1595
+ }
1596
+ get globals() {
1597
+ return mapFunctionOption(this.inner.globals, "globals");
1598
+ }
1599
+ get hashCharacters() {
1600
+ return this.inner.hashCharacters;
1601
+ }
1602
+ get sourcemapDebugIds() {
1603
+ return this.inner.sourcemapDebugIds;
1604
+ }
1605
+ get sourcemapIgnoreList() {
1606
+ return mapFunctionOption(void 0, "sourcemapIgnoreList");
1607
+ }
1608
+ get sourcemapPathTransform() {
1609
+ return mapFunctionOption(void 0, "sourcemapPathTransform");
1610
+ }
1611
+ get minify() {
1612
+ return this.inner.minify;
1613
+ }
1614
+ get comments() {
1615
+ return this.inner.comments;
1616
+ }
1617
+ };
1618
+
1619
+ //#endregion
1620
+ //#region src/plugin/bindingify-output-hooks.ts
1621
+ function bindingifyRenderStart(args) {
1622
+ const hook = args.plugin.renderStart;
1623
+ if (!hook) return {};
1624
+ const { handler, meta } = normalizeHook(hook);
1625
+ return {
1626
+ plugin: async (ctx, opts) => {
1627
+ handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), new NormalizedInputOptionsImpl(opts, args.onLog));
1628
+ },
1629
+ meta: bindingifyPluginHookMeta(meta)
1630
+ };
1631
+ }
1632
+ function bindingifyRenderChunk(args) {
1633
+ const hook = args.plugin.renderChunk;
1634
+ if (!hook) return {};
1635
+ const { handler, meta } = normalizeHook(hook);
1636
+ return {
1637
+ plugin: async (ctx, code, chunk, opts) => {
1638
+ const ret = await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), code, transformRenderedChunk(chunk), new NormalizedOutputOptionsImpl(opts));
1639
+ if (ret == null) return;
1640
+ if (typeof ret === "string") return { code: ret };
1641
+ if (!ret.map) return { code: ret.code };
1642
+ return {
1643
+ code: ret.code,
1644
+ map: bindingifySourcemap$1(ret.map)
1645
+ };
1646
+ },
1647
+ meta: bindingifyPluginHookMeta(meta)
1648
+ };
1649
+ }
1650
+ function bindingifyAugmentChunkHash(args) {
1651
+ const hook = args.plugin.augmentChunkHash;
1652
+ if (!hook) return {};
1653
+ const { handler, meta } = normalizeHook(hook);
1654
+ return {
1655
+ plugin: async (ctx, chunk) => {
1656
+ return await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
1657
+ },
1658
+ meta: bindingifyPluginHookMeta(meta)
1659
+ };
1660
+ }
1661
+ function bindingifyRenderError(args) {
1662
+ const hook = args.plugin.renderError;
1663
+ if (!hook) return {};
1664
+ const { handler, meta } = normalizeHook(hook);
1665
+ return {
1666
+ plugin: async (ctx, err) => {
1667
+ handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new Error(err));
1668
+ },
1669
+ meta: bindingifyPluginHookMeta(meta)
1670
+ };
1671
+ }
1672
+ function bindingifyGenerateBundle(args) {
1673
+ const hook = args.plugin.generateBundle;
1674
+ if (!hook) return {};
1675
+ const { handler, meta } = normalizeHook(hook);
1676
+ return {
1677
+ plugin: async (ctx, bundle, isWrite, opts) => {
1678
+ const changed = {
1679
+ updated: new Set(),
1680
+ deleted: new Set()
1681
+ };
1682
+ const output = transformToOutputBundle(bundle, changed);
1683
+ await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), output, isWrite);
1684
+ return collectChangedBundle(changed, output);
1685
+ },
1686
+ meta: bindingifyPluginHookMeta(meta)
1687
+ };
1688
+ }
1689
+ function bindingifyWriteBundle(args) {
1690
+ const hook = args.plugin.writeBundle;
1691
+ if (!hook) return {};
1692
+ const { handler, meta } = normalizeHook(hook);
1693
+ return {
1694
+ plugin: async (ctx, bundle, opts) => {
1695
+ const changed = {
1696
+ updated: new Set(),
1697
+ deleted: new Set()
1698
+ };
1699
+ const output = transformToOutputBundle(bundle, changed);
1700
+ await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), output);
1701
+ return collectChangedBundle(changed, output);
1702
+ },
1703
+ meta: bindingifyPluginHookMeta(meta)
1704
+ };
1705
+ }
1706
+ function bindingifyCloseBundle(args) {
1707
+ const hook = args.plugin.closeBundle;
1708
+ if (!hook) return {};
1709
+ const { handler, meta } = normalizeHook(hook);
1710
+ return {
1711
+ plugin: async (ctx) => {
1712
+ await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel));
1713
+ },
1714
+ meta: bindingifyPluginHookMeta(meta)
1715
+ };
1716
+ }
1717
+ function bindingifyBanner(args) {
1718
+ const hook = args.plugin.banner;
1719
+ if (!hook) return {};
1720
+ const { handler, meta } = normalizeHook(hook);
1721
+ return {
1722
+ plugin: async (ctx, chunk) => {
1723
+ if (typeof handler === "string") return handler;
1724
+ return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
1725
+ },
1726
+ meta: bindingifyPluginHookMeta(meta)
1727
+ };
1728
+ }
1729
+ function bindingifyFooter(args) {
1730
+ const hook = args.plugin.footer;
1731
+ if (!hook) return {};
1732
+ const { handler, meta } = normalizeHook(hook);
1733
+ return {
1734
+ plugin: async (ctx, chunk) => {
1735
+ if (typeof handler === "string") return handler;
1736
+ return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
1737
+ },
1738
+ meta: bindingifyPluginHookMeta(meta)
1739
+ };
1740
+ }
1741
+ function bindingifyIntro(args) {
1742
+ const hook = args.plugin.intro;
1743
+ if (!hook) return {};
1744
+ const { handler, meta } = normalizeHook(hook);
1745
+ return {
1746
+ plugin: async (ctx, chunk) => {
1747
+ if (typeof handler === "string") return handler;
1748
+ return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
1749
+ },
1750
+ meta: bindingifyPluginHookMeta(meta)
1751
+ };
1752
+ }
1753
+ function bindingifyOutro(args) {
1754
+ const hook = args.plugin.outro;
1755
+ if (!hook) return {};
1756
+ const { handler, meta } = normalizeHook(hook);
1757
+ return {
1758
+ plugin: async (ctx, chunk) => {
1759
+ if (typeof handler === "string") return handler;
1760
+ return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
1761
+ },
1762
+ meta: bindingifyPluginHookMeta(meta)
1763
+ };
1764
+ }
1765
+
1766
+ //#endregion
1767
+ //#region src/plugin/bindingify-watch-hooks.ts
1768
+ function bindingifyWatchChange(args) {
1769
+ const hook = args.plugin.watchChange;
1770
+ if (!hook) return {};
1771
+ const { handler, meta } = normalizeHook(hook);
1772
+ return {
1773
+ plugin: async (ctx, id, event) => {
1774
+ await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), id, { event });
1775
+ },
1776
+ meta: bindingifyPluginHookMeta(meta)
1777
+ };
1778
+ }
1779
+ function bindingifyCloseWatcher(args) {
1780
+ const hook = args.plugin.closeWatcher;
1781
+ if (!hook) return {};
1782
+ const { handler, meta } = normalizeHook(hook);
1783
+ return {
1784
+ plugin: async (ctx) => {
1785
+ await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel));
1786
+ },
1787
+ meta: bindingifyPluginHookMeta(meta)
1788
+ };
1789
+ }
1790
+
1791
+ //#endregion
1792
+ //#region src/plugin/bindingify-plugin.ts
1793
+ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, onLog, logLevel) {
1794
+ const args = {
1795
+ plugin,
1796
+ options,
1797
+ outputOptions,
1798
+ pluginContextData,
1799
+ onLog,
1800
+ logLevel
1801
+ };
1802
+ const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
1803
+ const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args);
1804
+ const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
1805
+ const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
1806
+ const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args);
1807
+ const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
1808
+ const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
1809
+ const { plugin: renderChunk, meta: renderChunkMeta } = bindingifyRenderChunk(args);
1810
+ const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
1811
+ const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
1812
+ const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
1813
+ const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
1814
+ const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
1815
+ const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
1816
+ const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
1817
+ const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
1818
+ const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
1819
+ const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
1820
+ const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
1821
+ const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
1822
+ const result = {
1823
+ name: plugin.name,
1824
+ buildStart,
1825
+ buildStartMeta,
1826
+ resolveId,
1827
+ resolveIdMeta,
1828
+ resolveIdFilter,
1829
+ resolveDynamicImport,
1830
+ resolveDynamicImportMeta,
1831
+ buildEnd,
1832
+ buildEndMeta,
1833
+ transform,
1834
+ transformMeta,
1835
+ transformFilter,
1836
+ moduleParsed,
1837
+ moduleParsedMeta,
1838
+ load,
1839
+ loadMeta,
1840
+ loadFilter,
1841
+ renderChunk,
1842
+ renderChunkMeta,
1843
+ augmentChunkHash,
1844
+ augmentChunkHashMeta,
1845
+ renderStart,
1846
+ renderStartMeta,
1847
+ renderError,
1848
+ renderErrorMeta,
1849
+ generateBundle,
1850
+ generateBundleMeta,
1851
+ writeBundle,
1852
+ writeBundleMeta,
1853
+ closeBundle,
1854
+ closeBundleMeta,
1855
+ banner,
1856
+ bannerMeta,
1857
+ footer,
1858
+ footerMeta,
1859
+ intro,
1860
+ introMeta,
1861
+ outro,
1862
+ outroMeta,
1863
+ watchChange,
1864
+ watchChangeMeta,
1865
+ closeWatcher,
1866
+ closeWatcherMeta
1867
+ };
1868
+ return wrapHandlers(result);
1869
+ }
1870
+ function wrapHandlers(plugin) {
1871
+ for (const hookName of [
1872
+ "buildStart",
1873
+ "resolveId",
1874
+ "resolveDynamicImport",
1875
+ "buildEnd",
1876
+ "transform",
1877
+ "moduleParsed",
1878
+ "load",
1879
+ "renderChunk",
1880
+ "augmentChunkHash",
1881
+ "renderStart",
1882
+ "renderError",
1883
+ "generateBundle",
1884
+ "writeBundle",
1885
+ "closeBundle",
1886
+ "banner",
1887
+ "footer",
1888
+ "intro",
1889
+ "outro",
1890
+ "watchChange",
1891
+ "closeWatcher"
1892
+ ]) {
1893
+ const handler = plugin[hookName];
1894
+ if (handler) plugin[hookName] = async (...args) => {
1895
+ try {
1896
+ return await handler(...args);
1897
+ } catch (e) {
1898
+ return error(logPluginError(e, plugin.name, {
1899
+ hook: hookName,
1900
+ id: hookName === "transform" ? args[2] : undefined
1901
+ }));
1902
+ }
1903
+ };
1904
+ }
1905
+ return plugin;
1906
+ }
1907
+
1908
+ //#endregion
1909
+ //#region src/plugin/plugin-context-data.ts
1910
+ var PluginContextData = class {
1911
+ moduleOptionMap = new Map();
1912
+ resolveOptionsMap = new Map();
1913
+ loadModulePromiseMap = new Map();
1914
+ updateModuleOption(id, option) {
1915
+ const existing = this.moduleOptionMap.get(id);
1916
+ if (existing) {
1917
+ if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
1918
+ if (option.meta != null) Object.assign(existing.meta, option.meta);
1919
+ } else this.moduleOptionMap.set(id, option);
1920
+ }
1921
+ getModuleOption(id) {
1922
+ const option = this.moduleOptionMap.get(id);
1923
+ if (!option) {
1924
+ const raw = {
1925
+ moduleSideEffects: null,
1926
+ meta: {}
1927
+ };
1928
+ this.moduleOptionMap.set(id, raw);
1929
+ return raw;
1930
+ }
1931
+ return option;
1932
+ }
1933
+ getModuleInfo(id, context) {
1934
+ const bindingInfo = context.getModuleInfo(id);
1935
+ if (bindingInfo) {
1936
+ const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
1937
+ return info;
1938
+ }
1939
+ return null;
1940
+ }
1941
+ getModuleIds(context) {
1942
+ const moduleIds = context.getModuleIds();
1943
+ return moduleIds.values();
1944
+ }
1945
+ saveResolveOptions(options) {
1946
+ const index = this.resolveOptionsMap.size;
1947
+ this.resolveOptionsMap.set(index, options);
1948
+ return index;
1949
+ }
1950
+ getSavedResolveOptions(receipt) {
1951
+ return this.resolveOptionsMap.get(receipt);
1952
+ }
1953
+ removeSavedResolveOptions(receipt) {
1954
+ this.resolveOptionsMap.delete(receipt);
1955
+ }
1956
+ };
1957
+
1958
+ //#endregion
1959
+ //#region src/utils/normalize-string-or-regex.ts
1960
+ function normalizedStringOrRegex(pattern) {
1961
+ if (!pattern) return undefined;
1962
+ if (!Array.isArray(pattern)) pattern = [pattern];
1963
+ return pattern;
1964
+ }
1965
+
1966
+ //#endregion
1967
+ //#region src/utils/bindingify-input-options.ts
1968
+ var import_binding$2 = __toESM(require_binding());
1969
+ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog, logLevel) {
1970
+ const pluginContextData = new PluginContextData();
1971
+ const plugins = rawPlugins.map((plugin) => {
1972
+ if ("_parallel" in plugin) return undefined;
1973
+ if (plugin instanceof BuiltinPlugin) return bindingifyBuiltInPlugin(plugin);
1974
+ return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, onLog, logLevel);
1975
+ });
1976
+ return {
1977
+ input: bindingifyInput(inputOptions.input),
1978
+ plugins,
1979
+ cwd: inputOptions.cwd ?? process.cwd(),
1980
+ external: bindingifyExternal(inputOptions.external),
1981
+ resolve: bindingifyResolve(inputOptions.resolve),
1982
+ platform: inputOptions.platform,
1983
+ shimMissingExports: inputOptions.shimMissingExports,
1984
+ logLevel: bindingifyLogLevel(logLevel),
1985
+ onLog,
1986
+ treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
1987
+ moduleTypes: inputOptions.moduleTypes,
1988
+ define: inputOptions.define ? Object.entries(inputOptions.define) : undefined,
1989
+ inject: bindingifyInject(inputOptions.inject),
1990
+ experimental: {
1991
+ strictExecutionOrder: inputOptions.experimental?.strictExecutionOrder,
1992
+ disableLiveBindings: inputOptions.experimental?.disableLiveBindings,
1993
+ viteMode: inputOptions.experimental?.viteMode,
1994
+ resolveNewUrlToAsset: inputOptions.experimental?.resolveNewUrlToAsset
1995
+ },
1996
+ profilerNames: inputOptions?.profilerNames,
1997
+ jsx: bindingifyJsx(inputOptions.jsx),
1998
+ watch: bindingifyWatch(inputOptions.watch),
1999
+ dropLabels: inputOptions.dropLabels
2000
+ };
2001
+ }
2002
+ function bindingifyExternal(external) {
2003
+ if (external) {
2004
+ if (typeof external === "function") return (id, importer, isResolved) => {
2005
+ if (id.startsWith("\0")) return false;
2006
+ return external(id, importer, isResolved) ?? false;
2007
+ };
2008
+ const externalArr = arraify(external);
2009
+ return (id, _importer, _isResolved) => {
2010
+ return externalArr.some((pat) => {
2011
+ if (pat instanceof RegExp) return pat.test(id);
2012
+ return id === pat;
2013
+ });
2014
+ };
2015
+ }
2016
+ }
2017
+ function bindingifyResolve(resolve) {
2018
+ if (resolve) {
2019
+ const { alias, extensionAlias,...rest } = resolve;
2020
+ return {
2021
+ alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
2022
+ find: name,
2023
+ replacements: [replacement]
2024
+ })) : undefined,
2025
+ extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
2026
+ target: name,
2027
+ replacements: value
2028
+ })) : undefined,
2029
+ ...rest
2030
+ };
2031
+ }
2032
+ }
2033
+ function bindingifyInject(inject) {
2034
+ if (inject) return Object.entries(inject).map(([alias, item]) => {
2035
+ if (Array.isArray(item)) {
2036
+ if (item[1] === "*") return {
2037
+ tagNamespace: true,
2038
+ alias,
2039
+ from: item[0]
2040
+ };
2041
+ return {
2042
+ tagNamed: true,
2043
+ alias,
2044
+ from: item[0],
2045
+ imported: item[1]
2046
+ };
2047
+ } else return {
2048
+ tagNamed: true,
2049
+ imported: "default",
2050
+ alias,
2051
+ from: item
2052
+ };
2053
+ });
2054
+ }
2055
+ function bindingifyLogLevel(logLevel) {
2056
+ switch (logLevel) {
2057
+ case "silent": return import_binding$2.BindingLogLevel.Silent;
2058
+ case "debug": return import_binding$2.BindingLogLevel.Debug;
2059
+ case "warn": return import_binding$2.BindingLogLevel.Warn;
2060
+ case "info": return import_binding$2.BindingLogLevel.Info;
2061
+ default: throw new Error(`Unexpected log level: ${logLevel}`);
2062
+ }
2063
+ }
2064
+ function bindingifyInput(input) {
2065
+ if (input === undefined) return [];
2066
+ if (typeof input === "string") return [{ import: input }];
2067
+ if (Array.isArray(input)) return input.map((src) => ({ import: src }));
2068
+ return Object.entries(input).map((value) => {
2069
+ return {
2070
+ name: value[0],
2071
+ import: value[1]
2072
+ };
2073
+ });
2074
+ }
2075
+ function bindingifyJsx(input) {
2076
+ if (input) {
2077
+ const mode = input.mode ?? "classic";
2078
+ return {
2079
+ runtime: mode,
2080
+ importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : undefined,
2081
+ pragma: input.factory,
2082
+ pragmaFrag: input.fragment,
2083
+ development: input.development,
2084
+ refresh: input.refresh
2085
+ };
2086
+ }
2087
+ }
2088
+ function bindingifyWatch(watch$1) {
2089
+ if (watch$1) {
2090
+ let value = {
2091
+ skipWrite: watch$1.skipWrite,
2092
+ include: normalizedStringOrRegex(watch$1.include),
2093
+ exclude: normalizedStringOrRegex(watch$1.exclude)
2094
+ };
2095
+ if (watch$1.notify) value.notify = {
2096
+ pollInterval: watch$1.notify.pollInterval,
2097
+ compareContents: watch$1.notify.compareContents
2098
+ };
2099
+ if (watch$1.chokidar) unsupported("The watch chokidar option is deprecated, please use notify options instead of it.");
2100
+ return value;
2101
+ }
2102
+ }
2103
+ function bindingifyTreeshakeOptions(config) {
2104
+ if (config === false) return undefined;
2105
+ if (config === true || config === undefined) return {
2106
+ moduleSideEffects: true,
2107
+ annotations: true
2108
+ };
2109
+ let normalizedConfig = { moduleSideEffects: true };
2110
+ if (config.moduleSideEffects === undefined) normalizedConfig.moduleSideEffects = true;
2111
+ else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
2112
+ external: true,
2113
+ sideEffects: false
2114
+ }, {
2115
+ external: false,
2116
+ sideEffects: true
2117
+ }];
2118
+ else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
2119
+ normalizedConfig.annotations = config.annotations ?? true;
2120
+ return normalizedConfig;
2121
+ }
2122
+
2123
+ //#endregion
2124
+ //#region src/utils/bindingify-output-options.ts
2125
+ function bindingifyOutputOptions(outputOptions) {
2126
+ const { dir, format, exports, hashCharacters, sourcemap, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, intro, outro, esModule, globals, file } = outputOptions;
2127
+ return {
2128
+ dir,
2129
+ file: file == null ? undefined : file,
2130
+ format: bindingifyFormat(format),
2131
+ exports,
2132
+ hashCharacters,
2133
+ sourcemap: bindingifySourcemap(sourcemap),
2134
+ sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
2135
+ sourcemapPathTransform,
2136
+ banner: bindingifyAddon(banner),
2137
+ footer: bindingifyAddon(footer),
2138
+ intro: bindingifyAddon(intro),
2139
+ outro: bindingifyAddon(outro),
2140
+ extend: outputOptions.extend,
2141
+ globals,
2142
+ esModule,
2143
+ name,
2144
+ assetFileNames,
2145
+ entryFileNames,
2146
+ chunkFileNames,
2147
+ cssEntryFileNames,
2148
+ cssChunkFileNames,
2149
+ plugins: [],
2150
+ minify: outputOptions.minify,
2151
+ externalLiveBindings: outputOptions.externalLiveBindings,
2152
+ inlineDynamicImports: outputOptions.inlineDynamicImports,
2153
+ advancedChunks: outputOptions.advancedChunks
2154
+ };
2155
+ }
2156
+ function bindingifyAddon(configAddon) {
2157
+ return async (chunk) => {
2158
+ if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
2159
+ return configAddon || "";
2160
+ };
2161
+ }
2162
+ function bindingifyFormat(format) {
2163
+ switch (format) {
2164
+ case undefined:
2165
+ case "es":
2166
+ case "esm":
2167
+ case "module": return "es";
2168
+ case "cjs":
2169
+ case "commonjs": return "cjs";
2170
+ case "iife": return "iife";
2171
+ case "umd": return "umd";
2172
+ case "experimental-app": return "app";
2173
+ default: unimplemented(`output.format: ${format}`);
2174
+ }
2175
+ }
2176
+ function bindingifySourcemap(sourcemap) {
2177
+ switch (sourcemap) {
2178
+ case true: return "file";
2179
+ case "inline": return "inline";
2180
+ case false:
2181
+ case undefined: return undefined;
2182
+ case "hidden": return "hidden";
2183
+ default: throw new Error(`unknown sourcemap: ${sourcemap}`);
2184
+ }
2185
+ }
2186
+ function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
2187
+ return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
2188
+ }
2189
+
2190
+ //#endregion
2191
+ //#region ../../node_modules/.pnpm/remeda@2.16.0/node_modules/remeda/dist/chunk-K26VP6CL.js
2192
+ function u$1(t$1, n, a) {
2193
+ let o = (r) => t$1(r, ...n);
2194
+ return a === void 0 ? o : Object.assign(o, {
2195
+ lazy: a,
2196
+ lazyArgs: n
2197
+ });
2198
+ }
2199
+
2200
+ //#endregion
2201
+ //#region ../../node_modules/.pnpm/remeda@2.16.0/node_modules/remeda/dist/chunk-RAAYCPUM.js
2202
+ function u(r, n, a) {
2203
+ let o = r.length - n.length;
2204
+ if (o === 0) return r(...n);
2205
+ if (o === 1) return u$1(r, n, a);
2206
+ throw new Error("Wrong number of arguments");
2207
+ }
2208
+
2209
+ //#endregion
2210
+ //#region ../../node_modules/.pnpm/remeda@2.16.0/node_modules/remeda/dist/chunk-NMJS7ULY.js
2211
+ function t(...n) {
2212
+ return u(Object.keys, n);
2213
+ }
2214
+
2215
+ //#endregion
2216
+ //#region src/utils/plugin/index.ts
2217
+ const isPluginHookName = function() {
2218
+ const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
2219
+ return function isPluginHookName$1(hookName) {
2220
+ return PLUGIN_HOOK_NAMES_SET.has(hookName);
2221
+ };
2222
+ }();
2223
+
2224
+ //#endregion
2225
+ //#region src/utils/compose-js-plugins.ts
2226
+ const unsupportedHookName = [
2227
+ "augmentChunkHash",
2228
+ "generateBundle",
2229
+ "moduleParsed",
2230
+ "onLog",
2231
+ "options",
2232
+ "outputOptions",
2233
+ "renderError",
2234
+ "renderStart",
2235
+ "resolveDynamicImport",
2236
+ "writeBundle"
2237
+ ];
2238
+ const unsupportedHooks = new Set(unsupportedHookName);
2239
+ function isUnsupportedHooks(hookName) {
2240
+ return unsupportedHooks.has(hookName);
2241
+ }
2242
+ function createComposedPlugin(plugins) {
2243
+ const names = [];
2244
+ const batchedHooks = {};
2245
+ plugins.forEach((plugin, index) => {
2246
+ const pluginName = plugin.name || `Anonymous(index: ${index})`;
2247
+ names.push(pluginName);
2248
+ t(plugin).forEach((pluginProp) => {
2249
+ if (isUnsupportedHooks(pluginProp)) throw new Error(`Failed to compose js plugins. Plugin ${pluginName} has an unsupported hook: ${pluginProp}`);
2250
+ if (!isPluginHookName(pluginProp)) return;
2251
+ switch (pluginProp) {
2252
+ case "buildStart": {
2253
+ const handlers = batchedHooks.buildStart ?? [];
2254
+ batchedHooks.buildStart = handlers;
2255
+ if (plugin.buildStart) handlers.push([plugin.buildStart, plugin]);
2256
+ break;
2257
+ }
2258
+ case "load": {
2259
+ const handlers = batchedHooks.load ?? [];
2260
+ batchedHooks.load = handlers;
2261
+ if (plugin.load) handlers.push([plugin.load, plugin]);
2262
+ break;
2263
+ }
2264
+ case "transform": {
2265
+ const handlers = batchedHooks.transform ?? [];
2266
+ batchedHooks.transform = handlers;
2267
+ if (plugin.transform) handlers.push([plugin.transform, plugin]);
2268
+ break;
2269
+ }
2270
+ case "resolveId": {
2271
+ const handlers = batchedHooks.resolveId ?? [];
2272
+ batchedHooks.resolveId = handlers;
2273
+ if (plugin.resolveId) handlers.push([plugin.resolveId, plugin]);
2274
+ break;
2275
+ }
2276
+ case "buildEnd": {
2277
+ const handlers = batchedHooks.buildEnd ?? [];
2278
+ batchedHooks.buildEnd = handlers;
2279
+ if (plugin.buildEnd) handlers.push([plugin.buildEnd, plugin]);
2280
+ break;
2281
+ }
2282
+ case "renderChunk": {
2283
+ const handlers = batchedHooks.renderChunk ?? [];
2284
+ batchedHooks.renderChunk = handlers;
2285
+ if (plugin.renderChunk) handlers.push([plugin.renderChunk, plugin]);
2286
+ break;
2287
+ }
2288
+ case "banner":
2289
+ case "footer":
2290
+ case "intro":
2291
+ case "outro": {
2292
+ const hook = plugin[pluginProp];
2293
+ if (hook) (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
2294
+ break;
2295
+ }
2296
+ case "closeBundle": {
2297
+ const handlers = batchedHooks.closeBundle ?? [];
2298
+ batchedHooks.closeBundle = handlers;
2299
+ if (plugin.closeBundle) handlers.push([plugin.closeBundle, plugin]);
2300
+ break;
2301
+ }
2302
+ case "watchChange": {
2303
+ const handlers = batchedHooks.watchChange ?? [];
2304
+ batchedHooks.watchChange = handlers;
2305
+ if (plugin.watchChange) handlers.push([plugin.watchChange, plugin]);
2306
+ break;
2307
+ }
2308
+ case "closeWatcher": {
2309
+ const handlers = batchedHooks.closeWatcher ?? [];
2310
+ batchedHooks.closeWatcher = handlers;
2311
+ if (plugin.closeWatcher) handlers.push([plugin.closeWatcher, plugin]);
2312
+ break;
2313
+ }
2314
+ default: {}
2315
+ }
2316
+ });
2317
+ });
2318
+ const composed = { name: `Composed(${names.join(", ")})` };
2319
+ const createFixedPluginResolveFnMap = new Map();
2320
+ function applyFixedPluginResolveFn(ctx, plugin) {
2321
+ const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
2322
+ if (createFixedPluginResolveFn) return {
2323
+ ...ctx,
2324
+ resolve: createFixedPluginResolveFn(ctx)
2325
+ };
2326
+ return ctx;
2327
+ }
2328
+ if (batchedHooks.resolveId) {
2329
+ const batchedHandlers = batchedHooks.resolveId;
2330
+ const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
2331
+ for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
2332
+ const [_handler, plugin] = batchedHandlers[handlerIdx];
2333
+ const handlerSymbol = handlerSymbols[handlerIdx];
2334
+ const createFixedPluginResolveFn = (ctx) => {
2335
+ return (source, importer, rawContextResolveOptions) => {
2336
+ const contextResolveOptions = rawContextResolveOptions ?? {};
2337
+ if (contextResolveOptions.skipSelf) {
2338
+ contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
2339
+ contextResolveOptions.skipSelf = false;
2340
+ }
2341
+ return ctx.resolve(source, importer, contextResolveOptions);
2342
+ };
2343
+ };
2344
+ createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
2345
+ }
2346
+ composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
2347
+ const hookResolveIdOptions = rawHookResolveIdOptions;
2348
+ const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
2349
+ for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
2350
+ const [handler, plugin] = batchedHandlers[handlerIdx];
2351
+ const handlerSymbol = handlerSymbols[handlerIdx];
2352
+ if (symbolForCallerThatSkipSelf === handlerSymbol) continue;
2353
+ const { handler: handlerFn } = normalizeHook(handler);
2354
+ const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
2355
+ if (!isNullish(result)) return result;
2356
+ }
2357
+ };
2358
+ }
2359
+ t(batchedHooks).forEach((hookName) => {
2360
+ switch (hookName) {
2361
+ case "resolveId": break;
2362
+ case "buildStart": {
2363
+ if (batchedHooks.buildStart) {
2364
+ const batchedHandlers = batchedHooks.buildStart;
2365
+ composed.buildStart = async function(options) {
2366
+ await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2367
+ const { handler: handlerFn } = normalizeHook(handler);
2368
+ return handlerFn.call(applyFixedPluginResolveFn(this, plugin), options);
2369
+ }));
2370
+ };
2371
+ }
2372
+ break;
2373
+ }
2374
+ case "load": {
2375
+ if (batchedHooks.load) {
2376
+ const batchedHandlers = batchedHooks.load;
2377
+ composed.load = async function(id) {
2378
+ for (const [handler, plugin] of batchedHandlers) {
2379
+ const { handler: handlerFn } = normalizeHook(handler);
2380
+ const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), id);
2381
+ if (!isNullish(result)) return result;
2382
+ }
2383
+ };
2384
+ }
2385
+ break;
2386
+ }
2387
+ case "transform": {
2388
+ if (batchedHooks.transform) {
2389
+ const batchedHandlers = batchedHooks.transform;
2390
+ composed.transform = async function(initialCode, id, moduleType) {
2391
+ let code = initialCode;
2392
+ let moduleSideEffects = undefined;
2393
+ function updateOutput(newCode, newModuleSideEffects) {
2394
+ code = newCode;
2395
+ moduleSideEffects = newModuleSideEffects ?? undefined;
2396
+ }
2397
+ for (const [handler, plugin] of batchedHandlers) {
2398
+ const { handler: handlerFn } = normalizeHook(handler);
2399
+ const result = await handlerFn.call({
2400
+ ...applyFixedPluginResolveFn(this, plugin),
2401
+ getCombinedSourcemap() {
2402
+ throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
2403
+ }
2404
+ }, code, id, moduleType);
2405
+ if (!isNullish(result)) {
2406
+ if (typeof result === "string") updateOutput(result);
2407
+ else if (result.code) updateOutput(result.code, result.moduleSideEffects);
2408
+ }
2409
+ }
2410
+ return {
2411
+ code,
2412
+ moduleSideEffects
2413
+ };
2414
+ };
2415
+ }
2416
+ break;
2417
+ }
2418
+ case "buildEnd": {
2419
+ if (batchedHooks.buildEnd) {
2420
+ const batchedHandlers = batchedHooks.buildEnd;
2421
+ composed.buildEnd = async function(err) {
2422
+ await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2423
+ const { handler: handlerFn } = normalizeHook(handler);
2424
+ return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
2425
+ }));
2426
+ };
2427
+ }
2428
+ break;
2429
+ }
2430
+ case "renderChunk": {
2431
+ if (batchedHooks.renderChunk) {
2432
+ const batchedHandlers = batchedHooks.renderChunk;
2433
+ composed.renderChunk = async function(code, chunk, options) {
2434
+ for (const [handler, plugin] of batchedHandlers) {
2435
+ const { handler: handlerFn } = normalizeHook(handler);
2436
+ const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options);
2437
+ if (!isNullish(result)) return result;
2438
+ }
2439
+ };
2440
+ }
2441
+ break;
2442
+ }
2443
+ case "banner":
2444
+ case "footer":
2445
+ case "intro":
2446
+ case "outro": {
2447
+ const hooks = batchedHooks[hookName];
2448
+ if (hooks?.length) composed[hookName] = async function(chunk) {
2449
+ const ret = [];
2450
+ for (const [hook, plugin] of hooks) {
2451
+ const { handler } = normalizeHook(hook);
2452
+ ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
2453
+ }
2454
+ return ret.join("\n");
2455
+ };
2456
+ break;
2457
+ }
2458
+ case "closeBundle": {
2459
+ if (batchedHooks.closeBundle) {
2460
+ const batchedHandlers = batchedHooks.closeBundle;
2461
+ composed.closeBundle = async function() {
2462
+ await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2463
+ const { handler: handlerFn } = normalizeHook(handler);
2464
+ return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
2465
+ }));
2466
+ };
2467
+ }
2468
+ break;
2469
+ }
2470
+ case "watchChange": {
2471
+ if (batchedHooks.watchChange) {
2472
+ const batchedHandlers = batchedHooks.watchChange;
2473
+ composed.watchChange = async function(id, event) {
2474
+ await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2475
+ const { handler: handlerFn } = normalizeHook(handler);
2476
+ return handlerFn.call(applyFixedPluginResolveFn(this, plugin), id, event);
2477
+ }));
2478
+ };
2479
+ }
2480
+ break;
2481
+ }
2482
+ case "closeWatcher": {
2483
+ if (batchedHooks.closeWatcher) {
2484
+ const batchedHandlers = batchedHooks.closeWatcher;
2485
+ composed.closeWatcher = async function() {
2486
+ await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2487
+ const { handler: handlerFn } = normalizeHook(handler);
2488
+ return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
2489
+ }));
2490
+ };
2491
+ }
2492
+ break;
2493
+ }
2494
+ default: {}
2495
+ }
2496
+ });
2497
+ return composed;
2498
+ }
2499
+ function isComposablePlugin(plugin) {
2500
+ if (plugin instanceof BuiltinPlugin) return false;
2501
+ if ("_parallel" in plugin) return false;
2502
+ const hasNotComposablePattern = t(plugin).some((hookName) => {
2503
+ if (!isPluginHookName(hookName)) return false;
2504
+ const OK_TO_COMPOSE = false;
2505
+ if (isUnsupportedHooks(hookName)) return !OK_TO_COMPOSE;
2506
+ if (plugin[hookName]) {
2507
+ const { meta } = normalizeHook(plugin[hookName]);
2508
+ if (meta.order === "pre" || meta.order === "post") return !OK_TO_COMPOSE;
2509
+ }
2510
+ return OK_TO_COMPOSE;
2511
+ });
2512
+ if (hasNotComposablePattern) return false;
2513
+ return true;
2514
+ }
2515
+ function composeJsPlugins(plugins) {
2516
+ const newPlugins = [];
2517
+ const toBeComposed = [];
2518
+ plugins.forEach((plugin) => {
2519
+ if (isComposablePlugin(plugin)) toBeComposed.push(plugin);
2520
+ else {
2521
+ if (toBeComposed.length > 0) {
2522
+ if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
2523
+ else newPlugins.push(toBeComposed[0]);
2524
+ toBeComposed.length = 0;
2525
+ }
2526
+ newPlugins.push(plugin);
2527
+ }
2528
+ });
2529
+ if (toBeComposed.length > 0) {
2530
+ if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
2531
+ else newPlugins.push(toBeComposed[0]);
2532
+ toBeComposed.length = 0;
2533
+ }
2534
+ return newPlugins;
2535
+ }
2536
+
2537
+ //#endregion
2538
+ //#region src/utils/initialize-parallel-plugins.ts
2539
+ var import_binding$1 = __toESM(require_binding());
2540
+ async function initializeParallelPlugins(plugins) {
2541
+ const pluginInfos = [];
2542
+ for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
2543
+ const { fileUrl, options } = plugin._parallel;
2544
+ pluginInfos.push({
2545
+ index,
2546
+ fileUrl,
2547
+ options
2548
+ });
2549
+ }
2550
+ if (pluginInfos.length <= 0) return undefined;
2551
+ const count = Math.min(availableParallelism(), 8);
2552
+ const parallelJsPluginRegistry = new import_binding$1.ParallelJsPluginRegistry(count);
2553
+ const registryId = parallelJsPluginRegistry.id;
2554
+ const workers = await initializeWorkers(registryId, count, pluginInfos);
2555
+ const stopWorkers = async () => {
2556
+ await Promise.all(workers.map((worker) => worker.terminate()));
2557
+ };
2558
+ return {
2559
+ registry: parallelJsPluginRegistry,
2560
+ stopWorkers
2561
+ };
2562
+ }
2563
+ function initializeWorkers(registryId, count, pluginInfos) {
2564
+ return Promise.all(Array.from({ length: count }, (_, i) => initializeWorker(registryId, pluginInfos, i)));
2565
+ }
2566
+ async function initializeWorker(registryId, pluginInfos, threadNumber) {
2567
+ const urlString = import.meta.resolve("#parallel-plugin-worker");
2568
+ const workerData = {
2569
+ registryId,
2570
+ pluginInfos,
2571
+ threadNumber
2572
+ };
2573
+ let worker;
2574
+ try {
2575
+ worker = new Worker(new URL(urlString), { workerData });
2576
+ worker.unref();
2577
+ await new Promise((resolve, reject) => {
2578
+ worker.once("message", async (message) => {
2579
+ if (message.type === "error") reject(message.error);
2580
+ else resolve();
2581
+ });
2582
+ });
2583
+ return worker;
2584
+ } catch (e) {
2585
+ worker?.terminate();
2586
+ throw e;
2587
+ }
2588
+ }
2589
+
2590
+ //#endregion
2591
+ //#region src/utils/create-bundler.ts
2592
+ var import_binding = __toESM(require_binding());
2593
+ async function createBundler(inputOptions, outputOptions) {
2594
+ const pluginDriver = new PluginDriver();
2595
+ inputOptions = await pluginDriver.callOptionsHook(inputOptions);
2596
+ if (inputOptions.treeshake !== undefined) TreeshakingOptionsSchema.parse(inputOptions.treeshake);
2597
+ const inputPlugins = await normalizePluginOption(inputOptions.plugins);
2598
+ const outputPlugins = await normalizePluginOption(outputOptions.plugins);
2599
+ outputOptions = pluginDriver.callOutputOptionsHook([...inputPlugins, ...outputPlugins], outputOptions);
2600
+ const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
2601
+ const onLog = getLogger(getObjectPlugins(inputPlugins), getOnLog(inputOptions, logLevel), logLevel);
2602
+ let plugins = [...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX), ...checkOutputPluginOption(normalizePlugins(await normalizePluginOption(outputOptions.plugins), ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)];
2603
+ if (inputOptions.experimental?.enableComposingJsPlugins ?? false) plugins = composeJsPlugins(plugins);
2604
+ const parallelPluginInitResult = await initializeParallelPlugins(plugins);
2605
+ try {
2606
+ const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, onLog, logLevel);
2607
+ const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
2608
+ return {
2609
+ bundler: new import_binding.Bundler(bindingInputOptions, bindingOutputOptions, parallelPluginInitResult?.registry),
2610
+ stopWorkers: parallelPluginInitResult?.stopWorkers
2611
+ };
2612
+ } catch (e) {
2613
+ await parallelPluginInitResult?.stopWorkers();
2614
+ throw e;
2615
+ }
2616
+ }
2617
+
2618
+ //#endregion
2619
+ //#region src/api/rolldown/rolldown-build.ts
2620
+ Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
2621
+ var RolldownBuild = class {
2622
+ #inputOptions;
2623
+ #bundler;
2624
+ constructor(inputOptions) {
2625
+ this.#inputOptions = inputOptions;
2626
+ }
2627
+ get closed() {
2628
+ return this.#bundler ? this.#bundler.bundler.closed : false;
2629
+ }
2630
+ async #getBundlerWithStopWorker(outputOptions) {
2631
+ if (this.#bundler) this.#bundler.stopWorkers?.();
2632
+ return this.#bundler = await createBundler(this.#inputOptions, outputOptions);
2633
+ }
2634
+ async generate(outputOptions = {}) {
2635
+ const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
2636
+ const output = await bundler.generate();
2637
+ return transformToRollupOutput(output);
2638
+ }
2639
+ async write(outputOptions = {}) {
2640
+ const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
2641
+ const output = await bundler.write();
2642
+ return transformToRollupOutput(output);
2643
+ }
2644
+ async close() {
2645
+ const { bundler, stopWorkers } = await this.#getBundlerWithStopWorker({});
2646
+ await stopWorkers?.();
2647
+ await bundler.close();
2648
+ }
2649
+ async [Symbol.asyncDispose]() {
2650
+ await this.close();
2651
+ }
2652
+ };
2653
+
2654
+ //#endregion
2655
+ //#region src/api/rolldown/index.ts
2656
+ const rolldown = async (input) => {
2657
+ return new RolldownBuild(input);
2658
+ };
2659
+
2660
+ //#endregion
2661
+ //#region src/api/watch/watch-emitter.ts
2662
+ var WatcherEmitter = class {
2663
+ listeners = new Map();
2664
+ timer;
2665
+ constructor() {
2666
+ this.timer = setInterval(
2667
+ () => {},
2668
+ 1e9
2669
+ /* Low power usage */
2670
+ );
2671
+ }
2672
+ on(event, listener) {
2673
+ const listeners = this.listeners.get(event);
2674
+ if (listeners) listeners.push(listener);
2675
+ else this.listeners.set(event, [listener]);
2676
+ return this;
2677
+ }
2678
+ async onEvent(event) {
2679
+ const listeners = this.listeners.get(event.eventKind());
2680
+ if (listeners) switch (event.eventKind()) {
2681
+ case "close":
2682
+ case "restart":
2683
+ for (const listener of listeners) await listener();
2684
+ break;
2685
+ case "event":
2686
+ for (const listener of listeners) {
2687
+ const code = event.bundleEventKind();
2688
+ switch (code) {
2689
+ case "BUNDLE_END":
2690
+ const { duration, output } = event.bundleEndData();
2691
+ await listener({
2692
+ code: "BUNDLE_END",
2693
+ duration,
2694
+ output: [output]
2695
+ });
2696
+ break;
2697
+ case "ERROR":
2698
+ const errors = event.errors();
2699
+ await listener({
2700
+ code: "ERROR",
2701
+ error: normalizeErrors(errors)
2702
+ });
2703
+ break;
2704
+ default:
2705
+ await listener({ code });
2706
+ break;
2707
+ }
2708
+ }
2709
+ break;
2710
+ case "change":
2711
+ for (const listener of listeners) {
2712
+ const { path: path$2, kind } = event.watchChangeData();
2713
+ await listener(path$2, { event: kind });
2714
+ }
2715
+ break;
2716
+ default: throw new Error(`Unknown event: ${event}`);
2717
+ }
2718
+ }
2719
+ async close() {
2720
+ clearInterval(this.timer);
2721
+ }
2722
+ };
2723
+
2724
+ //#endregion
2725
+ //#region src/api/watch/watcher.ts
2726
+ var Watcher = class {
2727
+ closed;
2728
+ inner;
2729
+ emitter;
2730
+ stopWorkers;
2731
+ constructor(emitter, inner, stopWorkers) {
2732
+ this.closed = false;
2733
+ this.inner = inner;
2734
+ this.emitter = emitter;
2735
+ const originClose = emitter.close.bind(emitter);
2736
+ emitter.close = async () => {
2737
+ await this.close();
2738
+ originClose();
2739
+ };
2740
+ this.stopWorkers = stopWorkers;
2741
+ }
2742
+ async close() {
2743
+ if (this.closed) return;
2744
+ this.closed = true;
2745
+ await this.stopWorkers?.();
2746
+ await this.inner.close();
2747
+ }
2748
+ start() {
2749
+ process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
2750
+ }
2751
+ };
2752
+ async function createWatcher(emitter, input) {
2753
+ const { bundler, stopWorkers } = await createBundler(input, input.output || {});
2754
+ const bindingWatcher = await bundler.watch();
2755
+ const watcher = new Watcher(emitter, bindingWatcher, stopWorkers);
2756
+ watcher.start();
2757
+ }
2758
+
2759
+ //#endregion
2760
+ //#region src/api/watch/index.ts
2761
+ const watch = (input) => {
2762
+ const emitter = new WatcherEmitter();
2763
+ createWatcher(emitter, input);
2764
+ return emitter;
2765
+ };
2766
+
2767
+ //#endregion
2768
+ //#region package.json
2769
+ var version = "0.15.0";
2770
+ var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
2771
+
2772
+ //#endregion
2773
+ //#region src/api/build.ts
2774
+ async function build(options) {
2775
+ if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
2776
+ else {
2777
+ const { output, write = true,...inputOptions } = options;
2778
+ const build$1 = await rolldown(inputOptions);
2779
+ if (write) return build$1.write(output);
2780
+ else return build$1.generate(output);
2781
+ }
2782
+ }
2783
+
2784
+ //#endregion
2785
+ //#region src/index.ts
2786
+ const VERSION = version;
2787
+
2788
+ //#endregion
2789
+ export { BuiltinPlugin, LogLevelOptionSchema, LogLevelSchema, LogLevelWithErrorSchema, PluginContextData, RollupLogSchema, RollupLogWithStringSchema, TreeshakingOptionsSchema, VERSION, __export, __toESM, arraify, bindingifyPlugin, build, buildImportAnalysisPlugin, composeJsPlugins, createBundler, defineConfig, description, dynamicImportVarsPlugin, handleOutputErrors, importGlobPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, require_binding, rolldown, version, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin, watch };