rolldown 0.12.2 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/cjs/cli.cjs +1552 -584
  2. package/dist/cjs/experimental-index.cjs +40 -0
  3. package/dist/cjs/index.cjs +5 -22
  4. package/dist/cjs/parallel-plugin-worker.cjs +7 -7
  5. package/dist/cjs/parallel-plugin.cjs +1 -1
  6. package/dist/esm/cli.mjs +1549 -583
  7. package/dist/esm/experimental-index.mjs +23 -0
  8. package/dist/esm/index.mjs +5 -17
  9. package/dist/esm/parallel-plugin-worker.mjs +6 -6
  10. package/dist/esm/parallel-plugin.mjs +1 -1
  11. package/dist/shared/{chunk-1xb6WR3y.cjs → chunk-gQ4GMlVi.cjs} +3 -2
  12. package/dist/shared/{consola.36c0034f-N8xiTrv3.cjs → consola.36c0034f-eps_ogJv.cjs} +188 -188
  13. package/dist/shared/{consola.36c0034f-jtHhMkSX.mjs → consola.36c0034f-m5cABVv4.mjs} +187 -187
  14. package/dist/shared/package-3VR4tEG7.mjs +9 -0
  15. package/dist/shared/package-OJCNSbf0.cjs +11 -0
  16. package/dist/shared/plugin-context-data-dIOrw9yH.cjs +1436 -0
  17. package/dist/shared/plugin-context-data-nhjzqlNd.mjs +1444 -0
  18. package/dist/shared/{prompt-pjyLzLci.mjs → prompt-9VjtYvi_.mjs} +182 -182
  19. package/dist/shared/{prompt-1K6oCkIU.cjs → prompt-Ah5G71p-.cjs} +183 -183
  20. package/dist/shared/rolldown-KvxnG5lF.mjs +1107 -0
  21. package/dist/shared/rolldown-PHdfa5m8.cjs +1123 -0
  22. package/dist/shared/rolldown-binding.wasi.cjs +70 -51
  23. package/dist/types/binding.d.ts +329 -14
  24. package/dist/types/cli/arguments/alias.d.ts +8 -0
  25. package/dist/types/cli/arguments/index.d.ts +13 -0
  26. package/dist/types/cli/arguments/normalize.d.ts +15 -0
  27. package/dist/types/cli/arguments/schema.d.ts +161 -0
  28. package/dist/types/cli/arguments/utils.d.ts +6 -0
  29. package/dist/types/cli/commands/bundle.d.ts +3 -1
  30. package/dist/types/cli/commands/help.d.ts +1 -0
  31. package/dist/types/cli/utils.d.ts +1 -1
  32. package/dist/types/constants/plugin-context.d.ts +7 -0
  33. package/dist/types/constants/plugin.d.ts +36 -0
  34. package/dist/types/experimental-index.d.ts +5 -0
  35. package/dist/types/index.d.ts +8 -8
  36. package/dist/types/options/input-options.d.ts +139 -27
  37. package/dist/types/options/normalized-alias-plugin-config.d.ts +10 -0
  38. package/dist/types/options/normalized-ecma-transform-plugin-config.d.ts +8 -0
  39. package/dist/types/options/normalized-output-options.d.ts +8 -3
  40. package/dist/types/options/output-options.d.ts +102 -11
  41. package/dist/types/options/utils.d.ts +2 -0
  42. package/dist/types/plugin/bindingify-build-hooks.d.ts +9 -8
  43. package/dist/types/plugin/bindingify-hook-filter.d.ts +5 -0
  44. package/dist/types/plugin/bindingify-output-hooks.d.ts +11 -7
  45. package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +8 -0
  46. package/dist/types/plugin/bindingify-plugin.d.ts +2 -1
  47. package/dist/types/plugin/builtin-plugin.d.ts +75 -7
  48. package/dist/types/plugin/index.d.ts +68 -28
  49. package/dist/types/plugin/plugin-context-data.d.ts +6 -0
  50. package/dist/types/plugin/plugin-context.d.ts +18 -8
  51. package/dist/types/plugin/plugin-driver.d.ts +2 -2
  52. package/dist/types/rollup.d.ts +1 -0
  53. package/dist/types/types/rolldown-output.d.ts +1 -0
  54. package/dist/types/utils/compose-js-plugins.d.ts +2 -0
  55. package/dist/types/utils/misc.d.ts +1 -0
  56. package/dist/types/utils/normalize-hook.d.ts +7 -5
  57. package/dist/types/utils/plugin/index.d.ts +2 -0
  58. package/dist/types/utils/type-assert.d.ts +1 -0
  59. package/package.json +30 -22
  60. package/dist/shared/rolldown-SCF5NBN_.cjs +0 -49
  61. package/dist/shared/rolldown-kYz4BvAA.mjs +0 -48
  62. package/dist/shared/utils_index-_DFpKlu1.mjs +0 -1582
  63. package/dist/shared/utils_index-xb2NoRNm.cjs +0 -1557
  64. package/dist/types/cli/constants.d.ts +0 -1
  65. package/dist/types/utils/ensure-array.d.ts +0 -1
  66. package/dist/types/utils/index.d.ts +0 -9
  67. /package/dist/types/plugin/{transfrom-plugin-context.d.ts → transform-plugin-context.d.ts} +0 -0
@@ -0,0 +1,1107 @@
1
+ import __node_module__ from 'node:module';
2
+ const require = __node_module__.createRequire(import.meta.url)
3
+ import { LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_WARN, PluginContextData, SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF, __toESM, arraify, bindingifyPlugin, error, getLogHandler, isNullish, logLevelPriority, logPluginError, normalizeHook, normalizeLog, require_binding, transformToRollupOutput, unimplemented } from "./plugin-context-data-nhjzqlNd.mjs";
4
+ import { default as path } from "node:path";
5
+ import { isRegExp, isRegExp as isRegExp$1, isRegExp as isRegExp$2 } from "node:util/types";
6
+ import { Worker } from "node:worker_threads";
7
+ import { availableParallelism } from "node:os";
8
+
9
+ //#region src/options/normalized-ecma-transform-plugin-config.ts
10
+ function normalizeEcmaTransformPluginConfig(config) {
11
+ if (!config) {
12
+ return undefined;
13
+ }
14
+ let normalizedConfig = {jsxInject: config?.jsxInject};
15
+ if (config?.exclude) {
16
+ let exclude = [];
17
+ if (isRegExp$2(config.exclude)) {
18
+ exclude = [config.exclude];
19
+ } else if (typeof config.exclude === "string") {
20
+ exclude = [config.exclude];
21
+ } else {
22
+ exclude = config.exclude;
23
+ }
24
+ normalizedConfig.exclude = [];
25
+ for (let item of exclude) {
26
+ if (isRegExp$2(item)) {
27
+ normalizedConfig.exclude.push({
28
+ value: item.source,
29
+ flag: item.flags
30
+ });
31
+ } else {
32
+ normalizedConfig.exclude.push({value: item});
33
+ }
34
+ }
35
+ }
36
+ if (config?.include) {
37
+ let include = [];
38
+ if (isRegExp$2(config.include)) {
39
+ include = [config.include];
40
+ } else if (typeof config.include === "string") {
41
+ include = [config.include];
42
+ } else {
43
+ include = config.include;
44
+ }
45
+ normalizedConfig.include = [];
46
+ for (let item of include) {
47
+ if (isRegExp$2(item)) {
48
+ normalizedConfig.include.push({
49
+ value: item.source,
50
+ flag: item.flags
51
+ });
52
+ } else {
53
+ normalizedConfig.include.push({value: item});
54
+ }
55
+ }
56
+ }
57
+ return normalizedConfig;
58
+ }
59
+
60
+ //#endregion
61
+ //#region src/options/normalized-alias-plugin-config.ts
62
+ function normalizeAliasPluginConfig(config) {
63
+ if (!config) {
64
+ return undefined;
65
+ }
66
+ let entries = config.entries.map((entry) => {
67
+ if (isRegExp$1(entry.find)) {
68
+ return {
69
+ find: {
70
+ value: entry.find.source,
71
+ flag: entry.find.flags
72
+ },
73
+ replacement: entry.replacement
74
+ };
75
+ } else {
76
+ return {
77
+ find: {value: entry.find},
78
+ replacement: entry.replacement
79
+ };
80
+ }
81
+ });
82
+ return {entries};
83
+ }
84
+
85
+ //#endregion
86
+ //#region src/plugin/builtin-plugin.ts
87
+ var import_binding$3 = __toESM(require_binding());
88
+ class BuiltinPlugin {
89
+ constructor(name, options) {
90
+ this.name = name;
91
+ this.options = options;
92
+ this.name = name;
93
+ this.options = options;
94
+ }
95
+ }
96
+ class ModulePreloadPolyfillPlugin extends BuiltinPlugin {
97
+ constructor(config) {
98
+ super(import_binding$3.BindingBuiltinPluginName.ModulePreloadPolyfillPlugin, config);
99
+ }
100
+ }
101
+ class DynamicImportVarsPlugin extends BuiltinPlugin {
102
+ constructor() {
103
+ super(import_binding$3.BindingBuiltinPluginName.DynamicImportVarsPlugin);
104
+ }
105
+ }
106
+ class ImportGlobPlugin extends BuiltinPlugin {
107
+ constructor(config) {
108
+ super(import_binding$3.BindingBuiltinPluginName.ImportGlobPlugin, config);
109
+ }
110
+ }
111
+ class ManifestPlugin extends BuiltinPlugin {
112
+ constructor(config) {
113
+ super(import_binding$3.BindingBuiltinPluginName.ManifestPlugin, config);
114
+ }
115
+ }
116
+ class WasmHelperPlugin extends BuiltinPlugin {
117
+ constructor() {
118
+ super(import_binding$3.BindingBuiltinPluginName.WasmHelperPlugin);
119
+ }
120
+ }
121
+ class WasmFallbackPlugin extends BuiltinPlugin {
122
+ constructor() {
123
+ super(import_binding$3.BindingBuiltinPluginName.WasmFallbackPlugin);
124
+ }
125
+ }
126
+ class LoadFallbackPlugin extends BuiltinPlugin {
127
+ constructor() {
128
+ super(import_binding$3.BindingBuiltinPluginName.LoadFallbackPlugin);
129
+ }
130
+ }
131
+ class AliasPlugin extends BuiltinPlugin {
132
+ constructor(config) {
133
+ let normalizedAliasPluginConfig = normalizeAliasPluginConfig(config);
134
+ super(import_binding$3.BindingBuiltinPluginName.AliasPlugin, normalizedAliasPluginConfig);
135
+ }
136
+ }
137
+ class TransformPlugin extends BuiltinPlugin {
138
+ constructor(config) {
139
+ let normalizedConfig = normalizeEcmaTransformPluginConfig(config);
140
+ super(import_binding$3.BindingBuiltinPluginName.TransformPlugin, normalizedConfig);
141
+ }
142
+ }
143
+ class JsonPlugin extends BuiltinPlugin {
144
+ constructor(config) {
145
+ super(import_binding$3.BindingBuiltinPluginName.JsonPlugin, config);
146
+ }
147
+ }
148
+ class BuildImportAnalysisPlugin extends BuiltinPlugin {
149
+ constructor(config) {
150
+ super(import_binding$3.BindingBuiltinPluginName.BuildImportAnalysisPlugin, config);
151
+ }
152
+ }
153
+ class ReplacePlugin extends BuiltinPlugin {
154
+ constructor(config) {
155
+ super(import_binding$3.BindingBuiltinPluginName.ReplacePlugin, config);
156
+ }
157
+ }
158
+ function modulePreloadPolyfillPlugin(config) {
159
+ return new ModulePreloadPolyfillPlugin(config);
160
+ }
161
+ function dynamicImportVarsPlugin() {
162
+ return new DynamicImportVarsPlugin();
163
+ }
164
+ function importGlobPlugin(config) {
165
+ return new ImportGlobPlugin(config);
166
+ }
167
+ function manifestPlugin(config) {
168
+ return new ManifestPlugin(config);
169
+ }
170
+ function wasmHelperPlugin() {
171
+ return new WasmHelperPlugin();
172
+ }
173
+ function wasmFallbackPlugin() {
174
+ return new WasmFallbackPlugin();
175
+ }
176
+ function transformPlugin(config) {
177
+ return new TransformPlugin(config);
178
+ }
179
+ function loadFallbackPlugin() {
180
+ return new LoadFallbackPlugin();
181
+ }
182
+ function aliasPlugin(config) {
183
+ return new AliasPlugin(config);
184
+ }
185
+ function jsonPlugin(config) {
186
+ return new JsonPlugin(config);
187
+ }
188
+ function buildImportAnalysisPlugin(config) {
189
+ return new BuildImportAnalysisPlugin(config);
190
+ }
191
+ function replacePlugin(values = {}, options = {}) {
192
+ return new ReplacePlugin({
193
+ ...options,
194
+ values
195
+ });
196
+ }
197
+ function bindingifyBuiltInPlugin(plugin) {
198
+ return {
199
+ __name: plugin.name,
200
+ options: plugin.options
201
+ };
202
+ }
203
+
204
+ //#endregion
205
+ //#region src/options/bindingify-input-options.ts
206
+ var import_binding$2 = __toESM(require_binding());
207
+ function bindingifyInputOptions(options, outputOptions) {
208
+ const pluginContextData = new PluginContextData();
209
+ return {
210
+ input: bindingifyInput(options.input),
211
+ plugins: options.plugins.map((plugin) => {
212
+ if ("_parallel"in plugin) {
213
+ return undefined;
214
+ }
215
+ if (plugin instanceof BuiltinPlugin) {
216
+ return bindingifyBuiltInPlugin(plugin);
217
+ }
218
+ return bindingifyPlugin(plugin, options, outputOptions, pluginContextData);
219
+ }),
220
+ cwd: options.cwd ?? process.cwd(),
221
+ external: options.external ? function bindingifyExternal() {
222
+ const external = options.external;
223
+ if (typeof external === "function") {
224
+ return (id, importer, isResolved) => {
225
+ if (id.startsWith("\0")) return false;
226
+ return external(id, importer, isResolved) ?? false;
227
+ };
228
+ }
229
+ const externalArr = arraify(external);
230
+ return (id, _importer, _isResolved) => {
231
+ return externalArr.some((pat) => {
232
+ if (pat instanceof RegExp) {
233
+ return pat.test(id);
234
+ }
235
+ return id === pat;
236
+ });
237
+ };
238
+ }() : undefined,
239
+ resolve: options.resolve ? function bindingifyResolve() {
240
+ const { alias: alias,...rest } = options.resolve;
241
+ return {
242
+ alias: alias ? (Object.entries(alias)).map(([name, replacement]) => ({
243
+ find: name,
244
+ replacements: [replacement]
245
+ })) : undefined,
246
+ ...rest
247
+ };
248
+ }() : undefined,
249
+ platform: options.platform,
250
+ shimMissingExports: options.shimMissingExports,
251
+ logLevel: bindingifyLogLevel(options.logLevel),
252
+ onLog: (level, log) => {
253
+ options.onLog(level, {
254
+ code: log.code,
255
+ message: log.message
256
+ });
257
+ },
258
+ treeshake: options.treeshake,
259
+ moduleTypes: options.moduleTypes,
260
+ define: options.define ? Object.entries(options.define) : undefined,
261
+ inject: options.inject ? (Object.entries(options.inject)).map(([alias, item]) => {
262
+ if (Array.isArray(item)) {
263
+ if (item[1] === "*") {
264
+ return {
265
+ tagNamespace: true,
266
+ alias,
267
+ from: item[0]
268
+ };
269
+ }
270
+ return {
271
+ tagNamed: true,
272
+ alias,
273
+ from: item[0],
274
+ imported: item[1]
275
+ };
276
+ } else {
277
+ return {
278
+ tagNamed: true,
279
+ imported: "default",
280
+ alias,
281
+ from: item
282
+ };
283
+ }
284
+ }) : undefined
285
+ };
286
+ }
287
+ function bindingifyLogLevel(logLevel) {
288
+ switch (logLevel) {
289
+ case "silent": return import_binding$2.BindingLogLevel.Silent;
290
+ case "warn": return import_binding$2.BindingLogLevel.Warn;
291
+ case "info": return import_binding$2.BindingLogLevel.Info;
292
+ case "debug": return import_binding$2.BindingLogLevel.Debug;
293
+ default: throw new Error(`Unexpected log level: ${logLevel}`);
294
+ }
295
+ }
296
+ function bindingifyInput(input) {
297
+ if (Array.isArray(input)) {
298
+ return input.map((src) => {
299
+ return {import: src};
300
+ });
301
+ } else {
302
+ return (Object.entries(input)).map((value) => {
303
+ return {
304
+ name: value[0],
305
+ import: value[1]
306
+ };
307
+ });
308
+ }
309
+ }
310
+
311
+ //#endregion
312
+ //#region src/utils/initialize-parallel-plugins.ts
313
+ var import_binding$1 = __toESM(require_binding());
314
+ async function initializeParallelPlugins(plugins) {
315
+ const pluginInfos = [];
316
+ for (const [index, plugin] of plugins.entries()) {
317
+ if ("_parallel"in plugin) {
318
+ const { fileUrl: fileUrl, options: options } = plugin._parallel;
319
+ pluginInfos.push({
320
+ index,
321
+ fileUrl,
322
+ options
323
+ });
324
+ }
325
+ }
326
+ if (pluginInfos.length <= 0) {
327
+ return undefined;
328
+ }
329
+ const count = Math.min(availableParallelism(), 8);
330
+ const parallelJsPluginRegistry = new import_binding$1.ParallelJsPluginRegistry(count);
331
+ const registryId = parallelJsPluginRegistry.id;
332
+ const workers = await initializeWorkers(registryId, count, pluginInfos);
333
+ const stopWorkers = async () => {
334
+ await Promise.all(workers.map((worker) => worker.terminate()));
335
+ };
336
+ return {
337
+ registry: parallelJsPluginRegistry,
338
+ stopWorkers
339
+ };
340
+ }
341
+ function initializeWorkers(registryId, count, pluginInfos) {
342
+ return Promise.all(Array.from({length: count}, (_, i) => initializeWorker(registryId, pluginInfos, i)));
343
+ }
344
+ async function initializeWorker(registryId, pluginInfos, threadNumber) {
345
+ const urlString = import.meta.resolve("#parallel-plugin-worker");
346
+ const workerData = {
347
+ registryId,
348
+ pluginInfos,
349
+ threadNumber
350
+ };
351
+ let worker;
352
+ try {
353
+ worker = new Worker(new URL(urlString), {workerData});
354
+ worker.unref();
355
+ await new Promise((resolve, reject) => {
356
+ worker.once("message", async (message) => {
357
+ if (message.type === "error") {
358
+ reject(message.error);
359
+ } else {
360
+ resolve();
361
+ }
362
+ });
363
+ });
364
+ return worker;
365
+ } catch (e) {
366
+ worker?.terminate();
367
+ throw e;
368
+ }
369
+ }
370
+
371
+ //#endregion
372
+ //#region src/log/logger.ts
373
+ function getLogger(plugins, onLog, logLevel) {
374
+ const minimalPriority = logLevelPriority[logLevel];
375
+ const logger = (level, log, skipped = new Set()) => {
376
+ const logPriority = logLevelPriority[level];
377
+ if (logPriority < minimalPriority) {
378
+ return;
379
+ }
380
+ for (const plugin of plugins) {
381
+ if (skipped.has(plugin)) continue;
382
+ const { onLog: pluginOnLog } = plugin;
383
+ if (pluginOnLog) {
384
+ const getLogHandler$1 = (level$1) => {
385
+ if (logLevelPriority[level$1] < minimalPriority) {
386
+ return () => {};
387
+ }
388
+ return (log$1) => logger(level$1, normalizeLog(log$1), (new Set(skipped)).add(plugin));
389
+ };
390
+ const handler = "handler"in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
391
+ if (handler.call({
392
+ debug: getLogHandler$1(LOG_LEVEL_DEBUG),
393
+ error: (log$1) => error(normalizeLog(log$1)),
394
+ info: getLogHandler$1(LOG_LEVEL_INFO),
395
+ warn: getLogHandler$1(LOG_LEVEL_WARN)
396
+ }, level, log) === false) {
397
+ return;
398
+ }
399
+ }
400
+ }
401
+ onLog(level, log);
402
+ };
403
+ return logger;
404
+ }
405
+ const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
406
+ const { onwarn: onwarn, onLog: onLog } = config;
407
+ const defaultOnLog = getDefaultOnLog(printLog, onwarn);
408
+ if (onLog) {
409
+ const minimalPriority = logLevelPriority[logLevel];
410
+ return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => {
411
+ if (level$1 === LOG_LEVEL_ERROR) {
412
+ return error(normalizeLog(handledLog));
413
+ }
414
+ if (logLevelPriority[level$1] >= minimalPriority) {
415
+ defaultOnLog(level$1, normalizeLog(handledLog));
416
+ }
417
+ });
418
+ }
419
+ return defaultOnLog;
420
+ };
421
+ const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
422
+ if (level === LOG_LEVEL_WARN) {
423
+ onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
424
+ } else {
425
+ printLog(level, log);
426
+ }
427
+ } : printLog;
428
+ const addLogToString = (log) => {
429
+ Object.defineProperty(log, "toString", {
430
+ value: () => getExtendedLogMessage(log),
431
+ writable: true
432
+ });
433
+ return log;
434
+ };
435
+ const defaultPrintLog = (level, log) => {
436
+ const message = getExtendedLogMessage(log);
437
+ switch (level) {
438
+ case LOG_LEVEL_WARN: {
439
+ return console.warn(message);
440
+ }
441
+ case LOG_LEVEL_DEBUG: {
442
+ return console.debug(message);
443
+ }
444
+ default: {
445
+ return console.info(message);
446
+ }
447
+ }
448
+ };
449
+ const getExtendedLogMessage = (log) => {
450
+ let prefix = "";
451
+ if (log.plugin) {
452
+ prefix += `(${log.plugin} plugin) `;
453
+ }
454
+ if (log.loc) {
455
+ prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
456
+ }
457
+ return prefix + log.message;
458
+ };
459
+ function relativeId(id) {
460
+ if (!path.isAbsolute(id)) return id;
461
+ return path.relative(path.resolve(), id);
462
+ }
463
+
464
+ //#endregion
465
+ //#region src/plugin/plugin-driver.ts
466
+ class PluginDriver {
467
+ async callOptionsHook(inputOptions) {
468
+ const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
469
+ const plugins = getObjectPlugins(inputOptions.plugins ?? []);
470
+ const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel);
471
+ for (const plugin of plugins) {
472
+ const name = plugin.name || "unknown";
473
+ const options = plugin.options;
474
+ if (options) {
475
+ const { handler: handler } = normalizeHook(options);
476
+ const result = await handler.call({
477
+ debug: getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", logger, name, logLevel),
478
+ error: (e) => error(logPluginError(normalizeLog(e), name, {hook: "onLog"})),
479
+ info: getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", logger, name, logLevel),
480
+ warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel)
481
+ }, inputOptions);
482
+ if (result) {
483
+ inputOptions = result;
484
+ }
485
+ }
486
+ }
487
+ return inputOptions;
488
+ }
489
+ callOutputOptionsHook(inputOptions, outputOptions) {
490
+ const plugins = getObjectPlugins(inputOptions.plugins);
491
+ for (const plugin of plugins) {
492
+ const options = plugin.outputOptions;
493
+ if (options) {
494
+ const { handler: handler } = normalizeHook(options);
495
+ const result = handler.call(null, outputOptions);
496
+ if (result) {
497
+ outputOptions = result;
498
+ }
499
+ }
500
+ }
501
+ return outputOptions;
502
+ }
503
+ }
504
+ function getObjectPlugins(plugins) {
505
+ return plugins.filter((plugin) => {
506
+ if ("_parallel"in plugin) {
507
+ return undefined;
508
+ }
509
+ if (plugin instanceof BuiltinPlugin) {
510
+ return undefined;
511
+ }
512
+ return plugin;
513
+ });
514
+ }
515
+
516
+ //#endregion
517
+ //#region src/utils/async-flatten.ts
518
+ async function asyncFlatten(array) {
519
+ do {
520
+ array = (await Promise.all(array)).flat(Infinity);
521
+ } while (array.some((v) => v?.then));
522
+ return array;
523
+ }
524
+
525
+ //#endregion
526
+ //#region src/utils/normalize-plugin-option.ts
527
+ const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
528
+
529
+ //#endregion
530
+ //#region src/utils/normalize-tree-shake.ts
531
+ function normalizeTreeshakeOptions(config) {
532
+ if (config === false) {
533
+ return undefined;
534
+ }
535
+ if (config === true || config === undefined) {
536
+ return {moduleSideEffects: "true"};
537
+ }
538
+ let normalizedConfig = {moduleSideEffects: ""};
539
+ if (config.moduleSideEffects === undefined) {
540
+ normalizedConfig.moduleSideEffects = "true";
541
+ } else if (isRegExp(config.moduleSideEffects)) {
542
+ normalizedConfig.moduleSideEffects = config.moduleSideEffects.source;
543
+ } else {
544
+ normalizedConfig.moduleSideEffects = config.moduleSideEffects.toString();
545
+ }
546
+ return normalizedConfig;
547
+ }
548
+
549
+ //#endregion
550
+ //#region ../../node_modules/.pnpm/remeda@2.11.0/node_modules/remeda/dist/chunk-K26VP6CL.js
551
+ function u$1(t$1, n, a) {
552
+ let o = (r) => t$1(r, ...n);
553
+ return a === void 0 ? o : Object.assign(o, {
554
+ lazy: a,
555
+ lazyArgs: n
556
+ });
557
+ }
558
+
559
+ //#endregion
560
+ //#region ../../node_modules/.pnpm/remeda@2.11.0/node_modules/remeda/dist/chunk-RAAYCPUM.js
561
+ function u(r, n, a) {
562
+ let o = r.length - n.length;
563
+ if (o === 0) return r(...n);
564
+ if (o === 1) return u$1(r, n, a);
565
+ throw new Error("Wrong number of arguments");
566
+ }
567
+
568
+ //#endregion
569
+ //#region ../../node_modules/.pnpm/remeda@2.11.0/node_modules/remeda/dist/chunk-NMJS7ULY.js
570
+ function t(...n) {
571
+ return u(Object.keys, n);
572
+ }
573
+
574
+ //#endregion
575
+ //#region src/constants/plugin.ts
576
+ const ENUMERATED_PLUGIN_HOOK_NAMES = ["options", "buildStart", "resolveId", "load", "transform", "moduleParsed", "augmentChunkHash", "buildEnd", "onLog", "resolveDynamicImport", "generateBundle", "outputOptions", "renderChunk", "renderStart", "renderError", "writeBundle", "footer", "banner", "intro", "outro",];
577
+ const DEFINED_HOOK_NAMES = {
578
+ [ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0],
579
+ [ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1],
580
+ [ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2],
581
+ [ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3],
582
+ [ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4],
583
+ [ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5],
584
+ [ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6],
585
+ [ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7],
586
+ [ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8],
587
+ [ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9],
588
+ [ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10],
589
+ [ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11],
590
+ [ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12],
591
+ [ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13],
592
+ [ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14],
593
+ [ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15],
594
+ [ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16],
595
+ [ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17],
596
+ [ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18],
597
+ [ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19]
598
+ };
599
+
600
+ //#endregion
601
+ //#region src/utils/plugin/index.ts
602
+ const isPluginHookName = function() {
603
+ const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
604
+ return function isPluginHookName$1(hookName) {
605
+ return PLUGIN_HOOK_NAMES_SET.has(hookName);
606
+ };
607
+ }();
608
+
609
+ //#endregion
610
+ //#region src/utils/compose-js-plugins.ts
611
+ const unsupportedHookName = ["augmentChunkHash", "generateBundle", "moduleParsed", "onLog", "options", "outputOptions", "renderError", "renderStart", "resolveDynamicImport", "writeBundle",];
612
+ const unsupportedHooks = new Set(unsupportedHookName);
613
+ function isUnsupportedHooks(hookName) {
614
+ return unsupportedHooks.has(hookName);
615
+ }
616
+ function createComposedPlugin(plugins) {
617
+ const names = [];
618
+ const batchedHooks = {};
619
+ plugins.forEach((plugin, index) => {
620
+ const pluginName = plugin.name || `Anonymous(index: ${index})`;
621
+ names.push(pluginName);
622
+ (t(plugin)).forEach((pluginProp) => {
623
+ if (isUnsupportedHooks(pluginProp)) {
624
+ throw new Error(`Failed to compose js plugins. Plugin ${pluginName} has an unsupported hook: ${pluginProp}`);
625
+ }
626
+ if (!isPluginHookName(pluginProp)) {
627
+ return;
628
+ }
629
+ switch (pluginProp) {
630
+ case "buildStart": {
631
+ const handlers = batchedHooks.buildStart ?? [];
632
+ batchedHooks.buildStart = handlers;
633
+ if (plugin.buildStart) {
634
+ handlers.push([plugin.buildStart, plugin]);
635
+ }
636
+ break;
637
+ }
638
+ case "load": {
639
+ const handlers = batchedHooks.load ?? [];
640
+ batchedHooks.load = handlers;
641
+ if (plugin.load) {
642
+ handlers.push([plugin.load, plugin]);
643
+ }
644
+ break;
645
+ }
646
+ case "transform": {
647
+ const handlers = batchedHooks.transform ?? [];
648
+ batchedHooks.transform = handlers;
649
+ if (plugin.transform) {
650
+ handlers.push([plugin.transform, plugin]);
651
+ }
652
+ break;
653
+ }
654
+ case "resolveId": {
655
+ const handlers = batchedHooks.resolveId ?? [];
656
+ batchedHooks.resolveId = handlers;
657
+ if (plugin.resolveId) {
658
+ handlers.push([plugin.resolveId, plugin]);
659
+ }
660
+ break;
661
+ }
662
+ case "buildEnd": {
663
+ const handlers = batchedHooks.buildEnd ?? [];
664
+ batchedHooks.buildEnd = handlers;
665
+ if (plugin.buildEnd) {
666
+ handlers.push([plugin.buildEnd, plugin]);
667
+ }
668
+ break;
669
+ }
670
+ case "renderChunk": {
671
+ const handlers = batchedHooks.renderChunk ?? [];
672
+ batchedHooks.renderChunk = handlers;
673
+ if (plugin.renderChunk) {
674
+ handlers.push([plugin.renderChunk, plugin]);
675
+ }
676
+ break;
677
+ }
678
+ case "banner":
679
+ case "footer":
680
+ case "intro":
681
+ case "outro": {
682
+ const hook = plugin[pluginProp];
683
+ if (hook) {
684
+ ;
685
+ (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
686
+ }
687
+ break;
688
+ }
689
+ default: {}
690
+ }
691
+ });
692
+ });
693
+ const composed = {name: `Composed(${names.join(", ")})`};
694
+ const createFixedPluginResolveFnMap = new Map();
695
+ function applyFixedPluginResolveFn(ctx, plugin) {
696
+ const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
697
+ if (createFixedPluginResolveFn) {
698
+ return {
699
+ ...ctx,
700
+ resolve: createFixedPluginResolveFn(ctx)
701
+ };
702
+ }
703
+ return ctx;
704
+ }
705
+ if (batchedHooks.resolveId) {
706
+ const batchedHandlers = batchedHooks.resolveId;
707
+ const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
708
+ for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
709
+ const [_handler, plugin] = batchedHandlers[handlerIdx];
710
+ const handlerSymbol = handlerSymbols[handlerIdx];
711
+ const createFixedPluginResolveFn = (ctx) => {
712
+ return (source, importer, rawContextResolveOptions) => {
713
+ const contextResolveOptions = rawContextResolveOptions ?? {};
714
+ if (contextResolveOptions.skipSelf) {
715
+ contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
716
+ contextResolveOptions.skipSelf = false;
717
+ }
718
+ return ctx.resolve(source, importer, contextResolveOptions);
719
+ };
720
+ };
721
+ createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
722
+ }
723
+ composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
724
+ const hookResolveIdOptions = rawHookResolveIdOptions;
725
+ const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
726
+ for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
727
+ const [handler, plugin] = batchedHandlers[handlerIdx];
728
+ const handlerSymbol = handlerSymbols[handlerIdx];
729
+ if (symbolForCallerThatSkipSelf === handlerSymbol) {
730
+ continue;
731
+ }
732
+ const { handler: handlerFn } = normalizeHook(handler);
733
+ const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
734
+ if (!isNullish(result)) {
735
+ return result;
736
+ }
737
+ }
738
+ };
739
+ }
740
+ (t(batchedHooks)).forEach((hookName) => {
741
+ switch (hookName) {
742
+ case "resolveId": {
743
+ break;
744
+ }
745
+ case "buildStart": {
746
+ if (batchedHooks.buildStart) {
747
+ const batchedHandlers = batchedHooks.buildStart;
748
+ composed.buildStart = async function(options) {
749
+ await Promise.all(batchedHandlers.map(([handler, plugin]) => {
750
+ const { handler: handlerFn } = normalizeHook(handler);
751
+ return handlerFn.call(applyFixedPluginResolveFn(this, plugin), options);
752
+ }));
753
+ };
754
+ }
755
+ break;
756
+ }
757
+ case "load": {
758
+ if (batchedHooks.load) {
759
+ const batchedHandlers = batchedHooks.load;
760
+ composed.load = async function(id) {
761
+ for (const [handler, plugin] of batchedHandlers) {
762
+ const { handler: handlerFn } = normalizeHook(handler);
763
+ const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), id);
764
+ if (!isNullish(result)) {
765
+ return result;
766
+ }
767
+ }
768
+ };
769
+ }
770
+ break;
771
+ }
772
+ case "transform": {
773
+ if (batchedHooks.transform) {
774
+ const batchedHandlers = batchedHooks.transform;
775
+ composed.transform = async function(initialCode, id, moduleType) {
776
+ let code = initialCode;
777
+ let moduleSideEffects = undefined;
778
+ function updateOutput(newCode, newModuleSideEffects) {
779
+ code = newCode;
780
+ moduleSideEffects = newModuleSideEffects ?? undefined;
781
+ }
782
+ for (const [handler, plugin] of batchedHandlers) {
783
+ const { handler: handlerFn } = normalizeHook(handler);
784
+ const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
785
+ if (!isNullish(result)) {
786
+ if (typeof result === "string") {
787
+ updateOutput(result);
788
+ } else {
789
+ if (result.code) {
790
+ updateOutput(result.code, result.moduleSideEffects);
791
+ }
792
+ }
793
+ }
794
+ }
795
+ return {
796
+ code,
797
+ moduleSideEffects
798
+ };
799
+ };
800
+ }
801
+ break;
802
+ }
803
+ case "buildEnd": {
804
+ if (batchedHooks.buildEnd) {
805
+ const batchedHandlers = batchedHooks.buildEnd;
806
+ composed.buildEnd = async function(err) {
807
+ await Promise.all(batchedHandlers.map(([handler, plugin]) => {
808
+ const { handler: handlerFn } = normalizeHook(handler);
809
+ return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
810
+ }));
811
+ };
812
+ }
813
+ break;
814
+ }
815
+ case "renderChunk": {
816
+ if (batchedHooks.renderChunk) {
817
+ const batchedHandlers = batchedHooks.renderChunk;
818
+ composed.renderChunk = async function(code, chunk, options) {
819
+ for (const [handler, plugin] of batchedHandlers) {
820
+ const { handler: handlerFn } = normalizeHook(handler);
821
+ const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options);
822
+ if (!isNullish(result)) {
823
+ return result;
824
+ }
825
+ }
826
+ };
827
+ }
828
+ break;
829
+ }
830
+ case "banner":
831
+ case "footer":
832
+ case "intro":
833
+ case "outro": {
834
+ const hooks = batchedHooks[hookName];
835
+ if (hooks?.length) {
836
+ composed[hookName] = async function(chunk) {
837
+ const ret = [];
838
+ for (const [hook, plugin] of hooks) {
839
+ {
840
+ const { handler: handler } = normalizeHook(hook);
841
+ ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
842
+ }
843
+ }
844
+ return ret.join("\n");
845
+ };
846
+ }
847
+ break;
848
+ }
849
+ default: {}
850
+ }
851
+ });
852
+ return composed;
853
+ }
854
+ function isComposablePlugin(plugin) {
855
+ if (plugin instanceof BuiltinPlugin) {
856
+ return false;
857
+ }
858
+ if ("_parallel"in plugin) {
859
+ return false;
860
+ }
861
+ const hasNotComposablePattern = (t(plugin)).some((hookName) => {
862
+ if (!isPluginHookName(hookName)) {
863
+ return false;
864
+ }
865
+ const OK_TO_COMPOSE = false;
866
+ if (isUnsupportedHooks(hookName)) {
867
+ return !OK_TO_COMPOSE;
868
+ }
869
+ if (plugin[hookName]) {
870
+ const { meta: meta } = normalizeHook(plugin[hookName]);
871
+ if (meta.order === "pre" || meta.order === "post") {
872
+ return !OK_TO_COMPOSE;
873
+ }
874
+ }
875
+ return OK_TO_COMPOSE;
876
+ });
877
+ if (hasNotComposablePattern) {
878
+ return false;
879
+ }
880
+ return true;
881
+ }
882
+ function composeJsPlugins(plugins) {
883
+ const newPlugins = [];
884
+ const toBeComposed = [];
885
+ plugins.forEach((plugin) => {
886
+ if (isComposablePlugin(plugin)) {
887
+ toBeComposed.push(plugin);
888
+ } else {
889
+ if (toBeComposed.length > 0) {
890
+ if (toBeComposed.length > 1) {
891
+ newPlugins.push(createComposedPlugin(toBeComposed));
892
+ } else {
893
+ newPlugins.push(toBeComposed[0]);
894
+ }
895
+ toBeComposed.length = 0;
896
+ }
897
+ newPlugins.push(plugin);
898
+ }
899
+ });
900
+ if (toBeComposed.length > 0) {
901
+ if (toBeComposed.length > 1) {
902
+ newPlugins.push(createComposedPlugin(toBeComposed));
903
+ } else {
904
+ newPlugins.push(toBeComposed[0]);
905
+ }
906
+ toBeComposed.length = 0;
907
+ }
908
+ return newPlugins;
909
+ }
910
+
911
+ //#endregion
912
+ //#region src/utils/normalize-input-options.ts
913
+ async function normalizeInputOptions(config) {
914
+ const { input: input,...rest } = config;
915
+ let plugins = await normalizePluginOption(config.plugins);
916
+ if (rest.experimental?.enableComposingJsPlugins ?? false) {
917
+ plugins = composeJsPlugins(plugins);
918
+ }
919
+ const treeshake = normalizeTreeshakeOptions(config.treeshake);
920
+ const logLevel = config.logLevel || LOG_LEVEL_INFO;
921
+ const onLog = getLogger(getObjectPlugins(plugins), getOnLog(config, logLevel), logLevel);
922
+ return {
923
+ ...rest,
924
+ input: input ? typeof input === "string" ? [input] : input : [],
925
+ plugins,
926
+ logLevel,
927
+ onLog,
928
+ treeshake
929
+ };
930
+ }
931
+
932
+ //#endregion
933
+ //#region src/utils/normalize-output-options.ts
934
+ function normalizeOutputOptions(opts) {
935
+ const { dir: dir, format: format, exports: exports, sourcemap: sourcemap, sourcemapIgnoreList: sourcemapIgnoreList, sourcemapPathTransform: sourcemapPathTransform, globals: globals, entryFileNames: entryFileNames, chunkFileNames: chunkFileNames, assetFileNames: assetFileNames, name: name, esModule: esModule } = opts;
936
+ return {
937
+ dir: dir,
938
+ format: getFormat(format),
939
+ exports: exports ?? "auto",
940
+ sourcemap: sourcemap ?? false,
941
+ sourcemapIgnoreList: typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules"),
942
+ sourcemapPathTransform,
943
+ banner: getAddon(opts, "banner"),
944
+ footer: getAddon(opts, "footer"),
945
+ intro: getAddon(opts, "intro"),
946
+ outro: getAddon(opts, "outro"),
947
+ esModule: esModule ?? "if-default-prop",
948
+ globals: globals ?? {},
949
+ entryFileNames: entryFileNames ?? "[name].js",
950
+ chunkFileNames: chunkFileNames ?? "[name]-[hash].js",
951
+ assetFileNames: assetFileNames ?? "assets/[name]-[hash][extname]",
952
+ plugins: [],
953
+ minify: opts.minify,
954
+ extend: opts.extend,
955
+ name,
956
+ externalLiveBindings: opts.externalLiveBindings ?? true,
957
+ inlineDynamicImports: opts.inlineDynamicImports ?? false
958
+ };
959
+ }
960
+ function getFormat(format) {
961
+ switch (format) {
962
+ case undefined:
963
+ case "es":
964
+ case "esm":
965
+ case "module": {
966
+ return "es";
967
+ }
968
+ case "cjs":
969
+ case "commonjs": {
970
+ return "cjs";
971
+ }
972
+ case "iife": {
973
+ return "iife";
974
+ }
975
+ default: unimplemented(`output.format: ${format}`);
976
+ }
977
+ }
978
+ const getAddon = (config, name) => {
979
+ return async (chunk) => {
980
+ const configAddon = config[name];
981
+ if (typeof configAddon === "function") {
982
+ return configAddon(chunk);
983
+ }
984
+ return configAddon || "";
985
+ };
986
+ };
987
+
988
+ //#endregion
989
+ //#region src/options/bindingify-output-options.ts
990
+ function bindingifyOutputOptions(outputOptions) {
991
+ const { dir: dir, format: format, exports: exports, sourcemap: sourcemap, sourcemapIgnoreList: sourcemapIgnoreList, sourcemapPathTransform: sourcemapPathTransform, name: name, entryFileNames: entryFileNames, chunkFileNames: chunkFileNames, assetFileNames: assetFileNames, banner: banner, footer: footer, intro: intro, outro: outro, esModule: esModule, globals: globals } = outputOptions;
992
+ return {
993
+ dir,
994
+ format: function() {
995
+ switch (format) {
996
+ case "es": return "es";
997
+ case "cjs": return "cjs";
998
+ case "iife": return "iife";
999
+ }
1000
+ }(),
1001
+ exports,
1002
+ sourcemap: bindingifySourcemap(sourcemap),
1003
+ sourcemapIgnoreList,
1004
+ sourcemapPathTransform,
1005
+ banner,
1006
+ footer,
1007
+ intro,
1008
+ outro,
1009
+ extend: outputOptions.extend,
1010
+ globals,
1011
+ esModule: bindingifyEsModule(esModule),
1012
+ name,
1013
+ entryFileNames,
1014
+ chunkFileNames,
1015
+ assetFileNames,
1016
+ plugins: [],
1017
+ minify: outputOptions.minify,
1018
+ externalLiveBindings: outputOptions.externalLiveBindings,
1019
+ inlineDynamicImports: outputOptions.inlineDynamicImports
1020
+ };
1021
+ }
1022
+ function bindingifySourcemap(sourcemap) {
1023
+ switch (sourcemap) {
1024
+ case true: return "file";
1025
+ case "inline": return "inline";
1026
+ case false:
1027
+ case undefined:
1028
+ case "hidden": return "hidden";
1029
+ default: throw new Error(`unknown sourcemap: ${sourcemap}`);
1030
+ }
1031
+ }
1032
+ function bindingifyEsModule(esModule) {
1033
+ switch (esModule) {
1034
+ case true:
1035
+ case false:
1036
+ case "if-default-prop": return esModule;
1037
+ default: throw new Error(`unknown esModule: ${esModule}`);
1038
+ }
1039
+ }
1040
+
1041
+ //#endregion
1042
+ //#region src/utils/create-bundler.ts
1043
+ var import_binding = __toESM(require_binding());
1044
+ async function createBundler(inputOptions, outputOptions) {
1045
+ const pluginDriver = new PluginDriver();
1046
+ inputOptions = await pluginDriver.callOptionsHook(inputOptions);
1047
+ const normalizedInputOptions = await normalizeInputOptions(inputOptions);
1048
+ const parallelPluginInitResult = await initializeParallelPlugins(normalizedInputOptions.plugins);
1049
+ try {
1050
+ outputOptions = pluginDriver.callOutputOptionsHook(normalizedInputOptions, outputOptions);
1051
+ const normalizedOutputOptions = normalizeOutputOptions(outputOptions);
1052
+ const bindingInputOptions = bindingifyInputOptions(normalizedInputOptions, normalizedOutputOptions);
1053
+ return {
1054
+ bundler: new import_binding.Bundler(bindingInputOptions, bindingifyOutputOptions(normalizedOutputOptions), parallelPluginInitResult?.registry),
1055
+ stopWorkers: parallelPluginInitResult?.stopWorkers
1056
+ };
1057
+ } catch (e) {
1058
+ await parallelPluginInitResult?.stopWorkers();
1059
+ throw e;
1060
+ }
1061
+ }
1062
+
1063
+ //#endregion
1064
+ //#region src/rolldown-build.ts
1065
+ class RolldownBuild {
1066
+ #inputOptions;
1067
+ #bundler;
1068
+ #stopWorkers;
1069
+ constructor(inputOptions) {
1070
+ this.#inputOptions = inputOptions;
1071
+ }
1072
+ async #getBundler(outputOptions) {
1073
+ if (typeof this.#bundler === "undefined") {
1074
+ const { bundler: bundler, stopWorkers: stopWorkers } = await createBundler(this.#inputOptions, outputOptions);
1075
+ this.#bundler = bundler;
1076
+ this.#stopWorkers = stopWorkers;
1077
+ }
1078
+ return this.#bundler;
1079
+ }
1080
+ async generate(outputOptions = {}) {
1081
+ const bundler = await this.#getBundler(outputOptions);
1082
+ const output = await bundler.generate();
1083
+ return transformToRollupOutput(output);
1084
+ }
1085
+ async write(outputOptions = {}) {
1086
+ const bundler = await this.#getBundler(outputOptions);
1087
+ const output = await bundler.write();
1088
+ return transformToRollupOutput(output);
1089
+ }
1090
+ async destroy() {
1091
+ await this.#stopWorkers?.();
1092
+ }
1093
+ }
1094
+
1095
+ //#endregion
1096
+ //#region src/rolldown.ts
1097
+ const rolldown = async (input) => {
1098
+ return new RolldownBuild(input);
1099
+ };
1100
+ const experimental_scan = async (input) => {
1101
+ const { bundler: bundler, stopWorkers: stopWorkers } = await createBundler(input, {});
1102
+ await bundler.scan();
1103
+ await stopWorkers?.();
1104
+ };
1105
+
1106
+ //#endregion
1107
+ export { aliasPlugin, buildImportAnalysisPlugin, composeJsPlugins, dynamicImportVarsPlugin, experimental_scan, importGlobPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, replacePlugin, rolldown, transformPlugin, wasmFallbackPlugin, wasmHelperPlugin };