rolldown 0.14.0 → 0.15.0-commit.1265c2c

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