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