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