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