robuild 0.0.16 → 0.0.18

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.
@@ -0,0 +1,4 @@
1
+ import { build, performBuild } from "./build-omZA_xD-.mjs";
2
+ import "./plugin-manager-w5yRGJRn.mjs";
3
+
4
+ export { performBuild };
@@ -1,3 +1,4 @@
1
+ import { RobuildPluginManager } from "./plugin-manager-w5yRGJRn.mjs";
1
2
  import { builtinModules } from "node:module";
2
3
  import { basename, dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
3
4
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -138,7 +139,7 @@ function updateImportExtension(importPath, entry) {
138
139
  * Get output extension for unbundle mode
139
140
  */
140
141
  function getUnbundleOutputExtension(inputExt, entry) {
141
- const format = Array.isArray(entry.format) ? entry.format[0] : entry.format || "esm";
142
+ const format = Array.isArray(entry.format) ? entry.format[0] : entry.format || "es";
142
143
  switch (inputExt) {
143
144
  case ".ts":
144
145
  case ".tsx": return format === "cjs" ? ".cjs" : ".mjs";
@@ -160,7 +161,7 @@ function getUnbundleOutputExtension(inputExt, entry) {
160
161
  function resolveChunkAddon(addon, format) {
161
162
  if (!addon) return void 0;
162
163
  if (typeof addon === "string") return addon;
163
- const formatKey = format === "esm" ? "js" : format;
164
+ const formatKey = format === "es" ? "js" : format;
164
165
  return addon[formatKey] || addon.js;
165
166
  }
166
167
  /**
@@ -346,340 +347,6 @@ function hasHash(filename) {
346
347
  return /-[a-f0-9]{8}(?:\.|$)/.test(filename);
347
348
  }
348
349
 
349
- //#endregion
350
- //#region src/features/loaders.ts
351
- /**
352
- * Default loader mappings for common file extensions
353
- */
354
- const DEFAULT_LOADERS = {
355
- ".js": "js",
356
- ".mjs": "js",
357
- ".cjs": "js",
358
- ".jsx": "jsx",
359
- ".ts": "ts",
360
- ".mts": "ts",
361
- ".cts": "ts",
362
- ".tsx": "tsx",
363
- ".json": "json",
364
- ".css": "css",
365
- ".scss": "css",
366
- ".sass": "css",
367
- ".less": "css",
368
- ".styl": "css",
369
- ".txt": "text",
370
- ".md": "text",
371
- ".html": "text",
372
- ".xml": "text",
373
- ".svg": "text",
374
- ".png": "file",
375
- ".jpg": "file",
376
- ".jpeg": "file",
377
- ".gif": "file",
378
- ".webp": "file",
379
- ".ico": "file",
380
- ".woff": "file",
381
- ".woff2": "file",
382
- ".ttf": "file",
383
- ".eot": "file",
384
- ".mp4": "file",
385
- ".webm": "file",
386
- ".wav": "file",
387
- ".mp3": "file",
388
- ".flac": "file",
389
- ".aac": "file",
390
- ".zip": "binary",
391
- ".tar": "binary",
392
- ".gz": "binary",
393
- ".br": "binary"
394
- };
395
- /**
396
- * Get loader type for a file based on its extension
397
- */
398
- function getLoaderForFile(filePath, loaders) {
399
- const ext = extname(filePath).toLowerCase();
400
- if (loaders?.[ext]) return loaders[ext].loader;
401
- return DEFAULT_LOADERS[ext] || "file";
402
- }
403
- /**
404
- * Transform file content based on loader type
405
- */
406
- async function transformWithLoader(filePath, content, loader, options) {
407
- switch (loader) {
408
- case "js":
409
- case "jsx":
410
- case "ts":
411
- case "tsx": return content;
412
- case "json": try {
413
- const parsed = JSON.parse(content);
414
- return `export default ${JSON.stringify(parsed)}`;
415
- } catch {
416
- return `export default ${JSON.stringify(content)}`;
417
- }
418
- case "css": return transformCssContent(content, options);
419
- case "text": return `export default ${JSON.stringify(content)}`;
420
- case "file": return transformFileContent(filePath, options);
421
- case "dataurl": return transformDataUrlContent(filePath, content, options);
422
- case "binary": return transformBinaryContent(filePath, options);
423
- case "empty": return "export default {}";
424
- default: throw new Error(`Unknown loader type: ${loader}`);
425
- }
426
- }
427
- /**
428
- * Transform CSS content
429
- */
430
- function transformCssContent(content, options) {
431
- if (options?.modules) {
432
- const classNames = extractCssClassNames(content);
433
- const moduleExports = classNames.reduce((acc, className) => {
434
- acc[className] = className;
435
- return acc;
436
- }, {});
437
- return `export default ${JSON.stringify(moduleExports)}`;
438
- }
439
- return `export default ${JSON.stringify(content)}`;
440
- }
441
- /**
442
- * Transform file content to URL
443
- */
444
- function transformFileContent(filePath, options) {
445
- const publicPath = options?.publicPath || "/";
446
- const fileName = filePath.split("/").pop() || "file";
447
- const url = `${publicPath}${fileName}`;
448
- return `export default ${JSON.stringify(url)}`;
449
- }
450
- /**
451
- * Transform file content to data URL
452
- */
453
- function transformDataUrlContent(filePath, content, _options) {
454
- const ext = extname(filePath).toLowerCase();
455
- const mimeType = getMimeType(ext);
456
- const base64 = Buffer.from(content).toString("base64");
457
- const dataUrl = `data:${mimeType};base64,${base64}`;
458
- return `export default ${JSON.stringify(dataUrl)}`;
459
- }
460
- /**
461
- * Transform binary file content
462
- */
463
- function transformBinaryContent(filePath, _options) {
464
- const fileName = filePath.split("/").pop() || "binary";
465
- return `export default ${JSON.stringify(fileName)}`;
466
- }
467
- /**
468
- * Extract CSS class names (simplified implementation)
469
- */
470
- function extractCssClassNames(content) {
471
- const classRegex = /\.([a-z_-][\w-]*)/gi;
472
- const matches = content.match(classRegex) || [];
473
- return Array.from(new Set(matches.map((match) => match.slice(1))));
474
- }
475
- /**
476
- * Get MIME type for file extension
477
- */
478
- function getMimeType(ext) {
479
- const mimeTypes = {
480
- ".png": "image/png",
481
- ".jpg": "image/jpeg",
482
- ".jpeg": "image/jpeg",
483
- ".gif": "image/gif",
484
- ".webp": "image/webp",
485
- ".svg": "image/svg+xml",
486
- ".ico": "image/x-icon",
487
- ".woff": "font/woff",
488
- ".woff2": "font/woff2",
489
- ".ttf": "font/ttf",
490
- ".eot": "application/vnd.ms-fontobject",
491
- ".mp4": "video/mp4",
492
- ".webm": "video/webm",
493
- ".wav": "audio/wav",
494
- ".mp3": "audio/mpeg",
495
- ".flac": "audio/flac",
496
- ".aac": "audio/aac",
497
- ".txt": "text/plain",
498
- ".md": "text/markdown",
499
- ".html": "text/html",
500
- ".xml": "application/xml",
501
- ".css": "text/css",
502
- ".js": "application/javascript",
503
- ".json": "application/json"
504
- };
505
- return mimeTypes[ext] || "application/octet-stream";
506
- }
507
- /**
508
- * Create a loader plugin for robuild
509
- */
510
- function createLoaderPlugin(loaders) {
511
- return {
512
- name: "loaders",
513
- load: async (id) => {
514
- const ext = extname(id);
515
- const loader = getLoaderForFile(id, loaders);
516
- if (loader === "js" || loader === "jsx" || loader === "ts" || loader === "tsx") return null;
517
- if (loader === "json" && !loaders?.[ext]) return null;
518
- try {
519
- const content = await readFile(id, "utf-8");
520
- const options = loaders?.[ext]?.options;
521
- return await transformWithLoader(id, content, loader, options);
522
- } catch {
523
- return null;
524
- }
525
- }
526
- };
527
- }
528
-
529
- //#endregion
530
- //#region src/features/plugin-manager.ts
531
- /**
532
- * Simplified plugin manager that leverages rolldown's plugin system
533
- */
534
- var RobuildPluginManager = class {
535
- plugins = [];
536
- context;
537
- constructor(config, entry, pkgDir) {
538
- this.context = {
539
- config,
540
- entry,
541
- pkgDir,
542
- outDir: entry.outDir || "dist",
543
- format: entry.format || "esm",
544
- platform: entry.platform || "node",
545
- target: entry.target || "es2022"
546
- };
547
- this.plugins = this.normalizePlugins(config.plugins || []);
548
- }
549
- /**
550
- * Normalize plugin options to RobuildPlugin instances
551
- */
552
- normalizePlugins(pluginOptions) {
553
- return pluginOptions.map((pluginOption) => this.normalizePlugin(pluginOption));
554
- }
555
- /**
556
- * Normalize a single plugin option
557
- */
558
- normalizePlugin(pluginOption) {
559
- if (typeof pluginOption === "function") return this.normalizePlugin(pluginOption());
560
- if (typeof pluginOption === "object" && pluginOption !== null) {
561
- if (this.isRobuildPlugin(pluginOption)) return pluginOption;
562
- if (this.isRolldownPlugin(pluginOption)) return this.adaptRolldownPlugin(pluginOption);
563
- if (this.isVitePlugin(pluginOption)) return this.adaptVitePlugin(pluginOption);
564
- if (this.isUnplugin(pluginOption)) return this.adaptUnplugin(pluginOption);
565
- return this.adaptRolldownPlugin(pluginOption);
566
- }
567
- throw new Error(`Invalid plugin option: ${typeof pluginOption}`);
568
- }
569
- /**
570
- * Check if plugin is already a RobuildPlugin
571
- */
572
- isRobuildPlugin(plugin) {
573
- return plugin.meta?.robuild === true || plugin.robuildSetup || plugin.robuildBuildStart || plugin.robuildBuildEnd;
574
- }
575
- /**
576
- * Check if plugin is a rolldown/rollup plugin
577
- */
578
- isRolldownPlugin(plugin) {
579
- return plugin.name && (plugin.buildStart || plugin.buildEnd || plugin.resolveId || plugin.load || plugin.transform || plugin.generateBundle || plugin.writeBundle);
580
- }
581
- /**
582
- * Check if plugin is a Vite plugin
583
- */
584
- isVitePlugin(plugin) {
585
- return plugin.config || plugin.configResolved || plugin.configureServer || plugin.meta?.vite === true;
586
- }
587
- /**
588
- * Check if plugin is an Unplugin
589
- */
590
- isUnplugin(plugin) {
591
- return plugin.unplugin === true || plugin.meta?.unplugin === true;
592
- }
593
- /**
594
- * Adapt rolldown plugin to RobuildPlugin
595
- */
596
- adaptRolldownPlugin(plugin) {
597
- return {
598
- ...plugin,
599
- meta: {
600
- ...plugin.meta,
601
- framework: "rolldown",
602
- robuild: true,
603
- rollup: true
604
- }
605
- };
606
- }
607
- /**
608
- * Adapt Vite plugin to RobuildPlugin
609
- */
610
- adaptVitePlugin(plugin) {
611
- return {
612
- ...plugin,
613
- meta: {
614
- ...plugin.meta,
615
- framework: "vite",
616
- robuild: true,
617
- vite: true
618
- }
619
- };
620
- }
621
- /**
622
- * Adapt Unplugin to RobuildPlugin
623
- */
624
- adaptUnplugin(plugin) {
625
- return {
626
- ...plugin,
627
- meta: {
628
- ...plugin.meta,
629
- framework: "unplugin",
630
- robuild: true,
631
- unplugin: true,
632
- rollup: true,
633
- vite: true,
634
- webpack: true,
635
- esbuild: true
636
- }
637
- };
638
- }
639
- /**
640
- * Initialize robuild-specific plugin hooks
641
- */
642
- async initializeRobuildHooks() {
643
- for (const plugin of this.plugins) if (plugin.robuildSetup) await plugin.robuildSetup(this.context);
644
- }
645
- /**
646
- * Execute robuild buildStart hooks
647
- */
648
- async executeRobuildBuildStart() {
649
- for (const plugin of this.plugins) if (plugin.robuildBuildStart) await plugin.robuildBuildStart(this.context);
650
- }
651
- /**
652
- * Execute robuild buildEnd hooks
653
- */
654
- async executeRobuildBuildEnd(result) {
655
- for (const plugin of this.plugins) if (plugin.robuildBuildEnd) await plugin.robuildBuildEnd(this.context, result);
656
- }
657
- /**
658
- * Get rolldown-compatible plugins for direct use
659
- */
660
- getRolldownPlugins() {
661
- return this.plugins.map((plugin) => {
662
- const { robuildSetup, robuildBuildStart, robuildBuildEnd,...rolldownPlugin } = plugin;
663
- return rolldownPlugin;
664
- });
665
- }
666
- /**
667
- * Get all plugins
668
- */
669
- getPlugins() {
670
- return this.plugins;
671
- }
672
- /**
673
- * Update context (useful when build parameters change)
674
- */
675
- updateContext(updates) {
676
- this.context = {
677
- ...this.context,
678
- ...updates
679
- };
680
- }
681
- };
682
-
683
350
  //#endregion
684
351
  //#region src/features/shims.ts
685
352
  /**
@@ -1027,25 +694,16 @@ async function sideEffectSize(dir, entry) {
1027
694
  //#endregion
1028
695
  //#region src/builders/bundle.ts
1029
696
  /**
1030
- * Convert OutputFormat to Rolldown ModuleFormat
1031
- */
1032
- function formatToRolldownFormat(format) {
1033
- switch (format) {
1034
- case "esm": return "es";
1035
- case "cjs": return "cjs";
1036
- case "iife": return "iife";
1037
- case "umd": return "umd";
1038
- default: return "es";
1039
- }
1040
- }
1041
- /**
1042
697
  * Get file extension for format
1043
698
  */
1044
699
  function getFormatExtension(format, platform, fixedExtension = false) {
1045
700
  if (fixedExtension) return format === "cjs" ? ".cjs" : ".mjs";
1046
701
  switch (format) {
1047
- case "esm": return ".mjs";
1048
- case "cjs": return platform === "node" ? ".cjs" : ".js";
702
+ case "es":
703
+ case "esm":
704
+ case "module": return ".mjs";
705
+ case "cjs":
706
+ case "commonjs": return platform === "node" ? ".cjs" : ".js";
1049
707
  case "iife":
1050
708
  case "umd": return ".js";
1051
709
  default: return ".js";
@@ -1083,7 +741,7 @@ async function rolldownBuild(ctx, entry, hooks, config) {
1083
741
  const inputs = normalizeBundleInputs(entryInput, ctx);
1084
742
  const pluginManager = new RobuildPluginManager(config || {}, entry, ctx.pkgDir);
1085
743
  await pluginManager.initializeRobuildHooks();
1086
- const formats = Array.isArray(entry.format) ? entry.format : [entry.format || "esm"];
744
+ const formats = Array.isArray(entry.format) ? entry.format : [entry.format || "es"];
1087
745
  const platform = entry.platform || "node";
1088
746
  const target = entry.target || "es2022";
1089
747
  const outDir = entry.outDir || "dist";
@@ -1175,13 +833,6 @@ async function rolldownBuild(ctx, entry, hooks, config) {
1175
833
  }
1176
834
  });
1177
835
  }
1178
- if (entry.loaders) {
1179
- const loaderPlugin = createLoaderPlugin(entry.loaders);
1180
- if (loaderPlugin.load) rolldownPlugins.push({
1181
- name: "loaders",
1182
- load: loaderPlugin.load
1183
- });
1184
- }
1185
836
  if (entry.shims) {
1186
837
  const shimsPlugin = createShimsPlugin(entry.shims);
1187
838
  if (shimsPlugin.transform) rolldownPlugins.push({
@@ -1200,6 +851,8 @@ async function rolldownBuild(ctx, entry, hooks, config) {
1200
851
  });
1201
852
  }
1202
853
  rolldownPlugins.push(...pluginManager.getRolldownPlugins());
854
+ const moduleTypes = {};
855
+ if (entry.loaders) for (const [ext, config$1] of Object.entries(entry.loaders)) moduleTypes[ext] = config$1.loader;
1203
856
  const robuildGeneratedConfig = {
1204
857
  cwd: ctx.pkgDir,
1205
858
  input: inputs,
@@ -1208,7 +861,8 @@ async function rolldownBuild(ctx, entry, hooks, config) {
1208
861
  external: typeof entry.external === "function" ? entry.external : externalDeps,
1209
862
  define: defineOptions,
1210
863
  resolve: { alias: entry.alias || {} },
1211
- transform: { target }
864
+ transform: { target },
865
+ ...Object.keys(moduleTypes).length > 0 ? { moduleTypes } : {}
1212
866
  };
1213
867
  if (entry.treeshake !== void 0) if (typeof entry.treeshake === "boolean") robuildGeneratedConfig.treeshake = entry.treeshake;
1214
868
  else robuildGeneratedConfig.treeshake = entry.treeshake;
@@ -1222,10 +876,9 @@ async function rolldownBuild(ctx, entry, hooks, config) {
1222
876
  const allOutputEntries = [];
1223
877
  const filePathMap = /* @__PURE__ */ new Map();
1224
878
  for (const format of formats) {
1225
- const rolldownFormat = formatToRolldownFormat(format);
1226
879
  const extension = getFormatExtension(format, platform, entry.fixedExtension);
1227
880
  const formatConfig = { ...baseRolldownConfig };
1228
- if (entry.dts !== false && format === "esm") {
881
+ if (entry.dts !== false && (format === "es" || format === "esm" || format === "module")) {
1229
882
  const dtsPlugins = dts({ ...entry.dts });
1230
883
  formatConfig.plugins = [...Array.isArray(formatConfig.plugins) ? formatConfig.plugins : [formatConfig.plugins], ...Array.isArray(dtsPlugins) ? dtsPlugins : [dtsPlugins]];
1231
884
  }
@@ -1233,13 +886,13 @@ async function rolldownBuild(ctx, entry, hooks, config) {
1233
886
  const formatOutDir = fullOutDir;
1234
887
  let entryFileName = `[name]${extension}`;
1235
888
  if (isMultiFormat) {
1236
- if (format === "cjs") entryFileName = `[name].cjs`;
1237
- else if (format === "esm") entryFileName = `[name].mjs`;
889
+ if (format === "cjs" || format === "commonjs") entryFileName = `[name].cjs`;
890
+ else if (format === "es" || format === "esm" || format === "module") entryFileName = `[name].mjs`;
1238
891
  else if (format === "iife" || format === "umd") entryFileName = `[name].js`;
1239
892
  }
1240
893
  const robuildOutputConfig = {
1241
894
  dir: formatOutDir,
1242
- format: rolldownFormat,
895
+ format,
1243
896
  entryFileNames: entryFileName,
1244
897
  chunkFileNames: `_chunks/[name]-[hash]${extension}`,
1245
898
  minify: entry.minify,
@@ -1359,7 +1012,7 @@ function normalizeBundleInputs(input, ctx) {
1359
1012
  function resolveJsOutputExtension(format, platform = "node", fixedExtension = false) {
1360
1013
  if (fixedExtension) return format === "cjs" ? "cjs" : "mjs";
1361
1014
  switch (format) {
1362
- case "esm": return platform === "browser" ? "js" : "mjs";
1015
+ case "es": return platform === "browser" ? "js" : "mjs";
1363
1016
  case "cjs": return platform === "browser" ? "js" : "cjs";
1364
1017
  case "iife":
1365
1018
  case "umd": return "js";
@@ -1372,7 +1025,7 @@ function resolveJsOutputExtension(format, platform = "node", fixedExtension = fa
1372
1025
  function resolveDtsOutputExtension(format, fixedExtension = false) {
1373
1026
  if (fixedExtension) return format === "cjs" ? "d.cts" : "d.mts";
1374
1027
  switch (format) {
1375
- case "esm": return "d.mts";
1028
+ case "es": return "d.mts";
1376
1029
  case "cjs": return "d.cts";
1377
1030
  default: return "d.ts";
1378
1031
  }
@@ -1472,7 +1125,7 @@ async function transformDir(ctx, entry) {
1472
1125
  case ".jsx": {
1473
1126
  const transformed = await transformModule(entryPath, entry);
1474
1127
  const baseName = entryName.replace(/\.(ts|tsx|jsx)$/, "");
1475
- const outputFileName = createFilename(baseName, "esm", false, {
1128
+ const outputFileName = createFilename(baseName, "es", false, {
1476
1129
  platform: entry.platform,
1477
1130
  fixedExtension: entry.fixedExtension,
1478
1131
  outExtensions: entry.outExtensions
@@ -1493,7 +1146,7 @@ async function transformDir(ctx, entry) {
1493
1146
  }
1494
1147
  if (SHEBANG_RE.test(transformed.code)) await makeExecutable(entryDistPath);
1495
1148
  if (transformed.declaration) {
1496
- const dtsFileName = createFilename(baseName, "esm", true, {
1149
+ const dtsFileName = createFilename(baseName, "es", true, {
1497
1150
  platform: entry.platform,
1498
1151
  fixedExtension: entry.fixedExtension,
1499
1152
  outExtensions: entry.outExtensions
@@ -1594,8 +1247,8 @@ async function transformModule(entryPath, entry) {
1594
1247
  transformed.code = res.code;
1595
1248
  transformed.map = res.map;
1596
1249
  }
1597
- const banner = resolveChunkAddon(entry.banner, "esm");
1598
- const footer = resolveChunkAddon(entry.footer, "esm");
1250
+ const banner = resolveChunkAddon(entry.banner, "es");
1251
+ const footer = resolveChunkAddon(entry.footer, "es");
1599
1252
  transformed.code = addBannerFooter(transformed.code, banner, footer);
1600
1253
  if (entry.nodeProtocol) transformed.code = transformNodeProtocol(transformed.code, entry.nodeProtocol);
1601
1254
  return transformed;
@@ -1803,7 +1456,7 @@ function convertViteConfig(viteConfig) {
1803
1456
  function convertFormats(formats) {
1804
1457
  if (!formats) return void 0;
1805
1458
  const formatMap = {
1806
- es: "esm",
1459
+ es: "es",
1807
1460
  cjs: "cjs",
1808
1461
  umd: "umd",
1809
1462
  iife: "iife"
@@ -1844,13 +1497,13 @@ function normalizePath$1(path, resolveFrom) {
1844
1497
  * Perform watch build using rolldown's built-in watch mode
1845
1498
  */
1846
1499
  async function performWatchBuild(config, ctx, startTime) {
1847
- const { performBuild: performBuild$1 } = await import("./build-DsPSXoU-.mjs");
1500
+ const { performBuild: performBuild$1 } = await import("./build-S2eglIZn.mjs");
1848
1501
  await performBuild$1(config, ctx, startTime);
1849
1502
  const bundleEntries = (config.entries || []).filter((entry) => {
1850
1503
  if (typeof entry === "string") return !entry.endsWith("/");
1851
1504
  return entry.type === "bundle";
1852
1505
  });
1853
- if (bundleEntries.length > 0) await startRolldownWatch(ctx, bundleEntries);
1506
+ if (bundleEntries.length > 0) await startRolldownWatch(config, ctx, bundleEntries);
1854
1507
  else {
1855
1508
  logger.warn("Transform-only watch mode not yet implemented with rolldown");
1856
1509
  return new Promise(() => {});
@@ -1863,8 +1516,9 @@ async function performWatchBuild(config, ctx, startTime) {
1863
1516
  * For full feature parity with build mode, the initial build is performed first.
1864
1517
  * The watch mode then monitors for file changes and triggers rebuilds.
1865
1518
  */
1866
- async function startRolldownWatch(ctx, bundleEntries) {
1519
+ async function startRolldownWatch(config, ctx, bundleEntries) {
1867
1520
  logger.info("🚧 Using rolldown built-in watch mode...");
1521
+ const { RobuildPluginManager: RobuildPluginManager$1 } = await import("./plugin-manager-WN1-NA--.mjs");
1868
1522
  const watchConfigs = [];
1869
1523
  for (const rawEntry of bundleEntries) {
1870
1524
  let entry;
@@ -1876,13 +1530,24 @@ async function startRolldownWatch(ctx, bundleEntries) {
1876
1530
  outDir: outDir || "dist"
1877
1531
  };
1878
1532
  } else entry = rawEntry;
1879
- entry.input = Array.isArray(entry.input) ? entry.input.map((i) => normalizePath$1(i, ctx.pkgDir)) : normalizePath$1(entry.input, ctx.pkgDir);
1533
+ const entryInput = entry.input || entry.entry;
1534
+ if (!entryInput) {
1535
+ logger.warn("Skipping entry without input:", entry);
1536
+ continue;
1537
+ }
1538
+ let normalizedInput;
1539
+ if (typeof entryInput === "object" && !Array.isArray(entryInput)) {
1540
+ const normalizedObj = {};
1541
+ for (const [key, value] of Object.entries(entryInput)) normalizedObj[key] = normalizePath$1(value, ctx.pkgDir);
1542
+ normalizedInput = normalizedObj;
1543
+ } else if (Array.isArray(entryInput)) normalizedInput = entryInput.map((i) => normalizePath$1(i, ctx.pkgDir));
1544
+ else normalizedInput = normalizePath$1(entryInput, ctx.pkgDir);
1880
1545
  const target = entry.target || "es2022";
1881
1546
  const platform = entry.platform || "node";
1882
- const format = entry.format || "esm";
1547
+ const format = entry.format || "es";
1883
1548
  const getExtension = (fmt) => {
1884
1549
  switch (fmt) {
1885
- case "esm": return ".mjs";
1550
+ case "es": return ".mjs";
1886
1551
  case "cjs": return ".cjs";
1887
1552
  case "iife":
1888
1553
  case "umd": return ".js";
@@ -1897,8 +1562,14 @@ async function startRolldownWatch(ctx, bundleEntries) {
1897
1562
  iife: "iife",
1898
1563
  umd: "umd"
1899
1564
  };
1565
+ let rolldownInput;
1566
+ if (Array.isArray(normalizedInput)) rolldownInput = normalizedInput[0];
1567
+ else if (typeof normalizedInput === "object") rolldownInput = normalizedInput;
1568
+ else rolldownInput = normalizedInput;
1569
+ const pluginManager = new RobuildPluginManager$1(config, entry, ctx.pkgDir);
1570
+ const rolldownPlugins = [...pluginManager.getRolldownPlugins(), ...entry.rolldown?.plugins || []];
1900
1571
  const watchConfig = {
1901
- input: Array.isArray(entry.input) ? entry.input[0] : entry.input,
1572
+ input: rolldownInput,
1902
1573
  output: {
1903
1574
  dir: entry.outDir,
1904
1575
  format: formatMap[rolldownFormat] || "es",
@@ -1906,7 +1577,8 @@ async function startRolldownWatch(ctx, bundleEntries) {
1906
1577
  sourcemap: entry.sourcemap
1907
1578
  },
1908
1579
  platform: platform === "node" ? "node" : "neutral",
1909
- transform: { target }
1580
+ transform: { target },
1581
+ plugins: rolldownPlugins
1910
1582
  };
1911
1583
  watchConfigs.push(watchConfig);
1912
1584
  }
@@ -1943,34 +1615,51 @@ async function startRolldownWatch(ctx, bundleEntries) {
1943
1615
  //#endregion
1944
1616
  //#region src/build.ts
1945
1617
  /**
1618
+ * Shared configuration fields between BuildConfig and BuildEntry
1619
+ */
1620
+ const SHARED_CONFIG_FIELDS = [
1621
+ "format",
1622
+ "outDir",
1623
+ "platform",
1624
+ "target",
1625
+ "minify",
1626
+ "dts",
1627
+ "dtsOnly",
1628
+ "splitting",
1629
+ "treeshake",
1630
+ "sourcemap",
1631
+ "external",
1632
+ "noExternal",
1633
+ "env",
1634
+ "alias",
1635
+ "banner",
1636
+ "footer",
1637
+ "shims",
1638
+ "rolldown",
1639
+ "loaders"
1640
+ ];
1641
+ /**
1642
+ * Inherit configuration from parent config to entry
1643
+ * Only inherits fields that are not already set in the entry
1644
+ */
1645
+ function inheritConfig(entry, config, additionalMappings) {
1646
+ const result = { ...entry };
1647
+ for (const field of SHARED_CONFIG_FIELDS) if (result[field] === void 0 && config[field] !== void 0) result[field] = config[field];
1648
+ if (additionalMappings) {
1649
+ for (const [configKey, entryKey] of Object.entries(additionalMappings)) if (result[entryKey] === void 0 && config[configKey] !== void 0) result[entryKey] = config[configKey];
1650
+ }
1651
+ return result;
1652
+ }
1653
+ /**
1946
1654
  * Normalize tsup-style config to entries-based config
1947
1655
  */
1948
1656
  function normalizeTsupConfig(config) {
1949
1657
  if (config.entries && config.entries.length > 0) return config;
1950
1658
  if (config.entry) {
1951
- const entry = {
1659
+ const entry = inheritConfig({
1952
1660
  type: "bundle",
1953
- entry: config.entry,
1954
- format: config.format,
1955
- outDir: config.outDir,
1956
- platform: config.platform,
1957
- target: config.target,
1958
- globalName: config.name,
1959
- minify: config.minify,
1960
- dts: config.dts,
1961
- dtsOnly: config.dtsOnly,
1962
- splitting: config.splitting,
1963
- treeshake: config.treeshake,
1964
- sourcemap: config.sourcemap,
1965
- external: config.external,
1966
- noExternal: config.noExternal,
1967
- env: config.env,
1968
- alias: config.alias,
1969
- banner: config.banner,
1970
- footer: config.footer,
1971
- shims: config.shims,
1972
- rolldown: config.rolldown
1973
- };
1661
+ entry: config.entry
1662
+ }, config, { name: "globalName" });
1974
1663
  return {
1975
1664
  ...config,
1976
1665
  entries: [entry]
@@ -2030,6 +1719,8 @@ async function performBuild(config, ctx, startTime) {
2030
1719
  outDir
2031
1720
  };
2032
1721
  } else entry = rawEntry;
1722
+ if (entry.type === "bundle") entry = inheritConfig(entry, config);
1723
+ else if (entry.type === "transform") entry = inheritConfig(entry, config);
2033
1724
  const hasInput = entry.type === "transform" ? !!entry.input : !!(entry.input || entry.entry);
2034
1725
  if (!hasInput) throw new Error(`Build entry missing \`input\` or \`entry\`: ${JSON.stringify(entry, null, 2)}`);
2035
1726
  entry = { ...entry };
@@ -1,12 +1,18 @@
1
1
  import { ResolveOptions } from "exsolve";
2
- import { InputOptions, MinifyOptions, OutputOptions, Plugin, RolldownBuild, RolldownPluginOption } from "rolldown";
2
+ import { InputOptions, MinifyOptions, ModuleFormat, ModuleType, OutputOptions, Plugin, RolldownBuild, RolldownPluginOption } from "rolldown";
3
3
  import { Options } from "rolldown-plugin-dts";
4
4
  import { MinifyOptions as MinifyOptions$1 } from "oxc-minify";
5
5
  import { TransformOptions } from "oxc-transform";
6
6
 
7
7
  //#region src/types.d.ts
8
- type OutputFormat = 'esm' | 'cjs' | 'iife' | 'umd';
8
+
9
+ /**
10
+ * Target platform
11
+ */
9
12
  type Platform = 'browser' | 'node' | 'neutral';
13
+ /**
14
+ * Target ES version
15
+ */
10
16
  type Target = 'es5' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext';
11
17
  interface CopyEntry {
12
18
  from: string;
@@ -14,11 +20,28 @@ interface CopyEntry {
14
20
  }
15
21
  type CopyOptions = Array<string | CopyEntry>;
16
22
  type ChunkAddon = string | Record<string, string>;
17
- type OutExtensionFactory = (format: OutputFormat) => {
23
+ type OutExtensionFactory = (format: ModuleFormat) => {
18
24
  js?: string;
19
25
  dts?: string;
20
26
  };
21
- type LoaderType = 'js' | 'jsx' | 'ts' | 'tsx' | 'json' | 'css' | 'text' | 'binary' | 'file' | 'dataurl' | 'empty';
27
+ /**
28
+ * Loader types for robuild.
29
+ *
30
+ * Rolldown native types:
31
+ * - 'js', 'jsx', 'ts', 'tsx' - JavaScript/TypeScript files
32
+ * - 'json' - JSON files
33
+ * - 'text' - Text files (imported as string)
34
+ * - 'base64' - Files imported as base64 data URL
35
+ * - 'file' - Files imported as file path (copied to output)
36
+ * - 'empty' - Empty module
37
+ * - 'binary' - Binary files
38
+ * - 'css' - CSS files
39
+ * - 'asset' - Asset files (Rolldown decides between file/base64 based on size)
40
+ *
41
+ * Robuild extensions:
42
+ * - 'dataurl' - Alias for 'base64'
43
+ */
44
+ type LoaderType = ModuleType | 'dataurl';
22
45
  interface LoaderConfig {
23
46
  loader: LoaderType;
24
47
  options?: Record<string, any>;
@@ -69,9 +92,15 @@ interface _BuildEntry {
69
92
  /**
70
93
  * Output format(s) for the build.
71
94
  *
72
- * Defaults to `['esm']` if not provided.
95
+ * Uses Rolldown's ModuleFormat:
96
+ * - 'es' / 'esm' / 'module': ES modules (default)
97
+ * - 'cjs' / 'commonjs': CommonJS
98
+ * - 'iife': Immediately Invoked Function Expression
99
+ * - 'umd': Universal Module Definition
100
+ *
101
+ * @default ['es']
73
102
  */
74
- format?: OutputFormat | OutputFormat[];
103
+ format?: ModuleFormat | ModuleFormat[];
75
104
  /**
76
105
  * Target platform for the build.
77
106
  *
@@ -172,6 +201,18 @@ interface _BuildEntry {
172
201
  noExternal?: (string | RegExp)[] | ((id: string, importer?: string) => boolean);
173
202
  /**
174
203
  * File type loaders configuration.
204
+ *
205
+ * Maps file extensions to loader types. Uses Rolldown's native moduleTypes.
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * loaders: {
210
+ * '.png': { loader: 'asset' }, // Auto base64 for small files, file path for large
211
+ * '.jpg': { loader: 'file' }, // Always emit as file
212
+ * '.svg': { loader: 'text' }, // Import as string
213
+ * '.woff': { loader: 'base64' }, // Import as data URL
214
+ * }
215
+ * ```
175
216
  */
176
217
  loaders?: Record<string, LoaderConfig>;
177
218
  /**
@@ -354,7 +395,7 @@ interface RobuildPluginContext {
354
395
  entry: BuildEntry;
355
396
  pkgDir: string;
356
397
  outDir: string;
357
- format: OutputFormat | OutputFormat[];
398
+ format: ModuleFormat | ModuleFormat[];
358
399
  platform: Platform;
359
400
  target: string;
360
401
  }
@@ -452,7 +493,7 @@ type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'verbose';
452
493
  type OnSuccessCallback = string | ((result: BuildResult) => void | Promise<void>);
453
494
  interface BuildResult {
454
495
  entries: Array<{
455
- format: OutputFormat;
496
+ format: ModuleFormat;
456
497
  name: string;
457
498
  exports: string[];
458
499
  deps: string[];
@@ -482,7 +523,7 @@ interface BuildConfig {
482
523
  * ```ts
483
524
  * {
484
525
  * entry: ['src/index.ts', 'src/cli.ts'],
485
- * format: ['esm', 'cjs'],
526
+ * format: ['es', 'cjs'],
486
527
  * dts: true
487
528
  * }
488
529
  * ```
@@ -491,9 +532,9 @@ interface BuildConfig {
491
532
  /**
492
533
  * Output format(s) for tsup-style configuration.
493
534
  *
494
- * @default ['esm']
535
+ * @default ['es']
495
536
  */
496
- format?: OutputFormat | OutputFormat[];
537
+ format?: ModuleFormat | ModuleFormat[];
497
538
  /**
498
539
  * Output directory for tsup-style configuration.
499
540
  *
@@ -552,6 +593,12 @@ interface BuildConfig {
552
593
  * @default false
553
594
  */
554
595
  sourcemap?: boolean | 'inline' | 'hidden';
596
+ /**
597
+ * File type loaders configuration (tsup-style).
598
+ *
599
+ * @see _BuildEntry.loaders
600
+ */
601
+ loaders?: Record<string, LoaderConfig>;
555
602
  /**
556
603
  * External dependencies (tsup-style).
557
604
  */
@@ -1,7 +1,7 @@
1
1
  //#region package.json
2
2
  var name = "robuild";
3
3
  var type = "module";
4
- var version = "0.0.16";
4
+ var version = "0.0.18";
5
5
  var packageManager = "pnpm@10.11.1";
6
6
  var description = "Zero-config ESM/TS package builder. Powered by Rolldown and Oxc";
7
7
  var license = "MIT";
@@ -0,0 +1,3 @@
1
+ import { RobuildPluginManager } from "./plugin-manager-w5yRGJRn.mjs";
2
+
3
+ export { RobuildPluginManager };
@@ -0,0 +1,155 @@
1
+ //#region src/features/plugin-manager.ts
2
+ /**
3
+ * Simplified plugin manager that leverages rolldown's plugin system
4
+ */
5
+ var RobuildPluginManager = class {
6
+ plugins = [];
7
+ context;
8
+ constructor(config, entry, pkgDir) {
9
+ this.context = {
10
+ config,
11
+ entry,
12
+ pkgDir,
13
+ outDir: entry.outDir || "dist",
14
+ format: entry.format || "es",
15
+ platform: entry.platform || "node",
16
+ target: entry.target || "es2022"
17
+ };
18
+ this.plugins = this.normalizePlugins(config.plugins || []);
19
+ }
20
+ /**
21
+ * Normalize plugin options to RobuildPlugin instances
22
+ */
23
+ normalizePlugins(pluginOptions) {
24
+ return pluginOptions.map((pluginOption) => this.normalizePlugin(pluginOption));
25
+ }
26
+ /**
27
+ * Normalize a single plugin option
28
+ */
29
+ normalizePlugin(pluginOption) {
30
+ if (typeof pluginOption === "function") return this.normalizePlugin(pluginOption());
31
+ if (typeof pluginOption === "object" && pluginOption !== null) {
32
+ if (this.isRobuildPlugin(pluginOption)) return pluginOption;
33
+ if (this.isRolldownPlugin(pluginOption)) return this.adaptRolldownPlugin(pluginOption);
34
+ if (this.isVitePlugin(pluginOption)) return this.adaptVitePlugin(pluginOption);
35
+ if (this.isUnplugin(pluginOption)) return this.adaptUnplugin(pluginOption);
36
+ return this.adaptRolldownPlugin(pluginOption);
37
+ }
38
+ throw new Error(`Invalid plugin option: ${typeof pluginOption}`);
39
+ }
40
+ /**
41
+ * Check if plugin is already a RobuildPlugin
42
+ */
43
+ isRobuildPlugin(plugin) {
44
+ return plugin.meta?.robuild === true || plugin.robuildSetup || plugin.robuildBuildStart || plugin.robuildBuildEnd;
45
+ }
46
+ /**
47
+ * Check if plugin is a rolldown/rollup plugin
48
+ */
49
+ isRolldownPlugin(plugin) {
50
+ return plugin.name && (plugin.buildStart || plugin.buildEnd || plugin.resolveId || plugin.load || plugin.transform || plugin.generateBundle || plugin.writeBundle);
51
+ }
52
+ /**
53
+ * Check if plugin is a Vite plugin
54
+ */
55
+ isVitePlugin(plugin) {
56
+ return plugin.config || plugin.configResolved || plugin.configureServer || plugin.meta?.vite === true;
57
+ }
58
+ /**
59
+ * Check if plugin is an Unplugin
60
+ */
61
+ isUnplugin(plugin) {
62
+ return plugin.unplugin === true || plugin.meta?.unplugin === true;
63
+ }
64
+ /**
65
+ * Adapt rolldown plugin to RobuildPlugin
66
+ */
67
+ adaptRolldownPlugin(plugin) {
68
+ return {
69
+ ...plugin,
70
+ meta: {
71
+ ...plugin.meta,
72
+ framework: "rolldown",
73
+ robuild: true,
74
+ rollup: true
75
+ }
76
+ };
77
+ }
78
+ /**
79
+ * Adapt Vite plugin to RobuildPlugin
80
+ */
81
+ adaptVitePlugin(plugin) {
82
+ return {
83
+ ...plugin,
84
+ meta: {
85
+ ...plugin.meta,
86
+ framework: "vite",
87
+ robuild: true,
88
+ vite: true
89
+ }
90
+ };
91
+ }
92
+ /**
93
+ * Adapt Unplugin to RobuildPlugin
94
+ */
95
+ adaptUnplugin(plugin) {
96
+ return {
97
+ ...plugin,
98
+ meta: {
99
+ ...plugin.meta,
100
+ framework: "unplugin",
101
+ robuild: true,
102
+ unplugin: true,
103
+ rollup: true,
104
+ vite: true,
105
+ webpack: true,
106
+ esbuild: true
107
+ }
108
+ };
109
+ }
110
+ /**
111
+ * Initialize robuild-specific plugin hooks
112
+ */
113
+ async initializeRobuildHooks() {
114
+ for (const plugin of this.plugins) if (plugin.robuildSetup) await plugin.robuildSetup(this.context);
115
+ }
116
+ /**
117
+ * Execute robuild buildStart hooks
118
+ */
119
+ async executeRobuildBuildStart() {
120
+ for (const plugin of this.plugins) if (plugin.robuildBuildStart) await plugin.robuildBuildStart(this.context);
121
+ }
122
+ /**
123
+ * Execute robuild buildEnd hooks
124
+ */
125
+ async executeRobuildBuildEnd(result) {
126
+ for (const plugin of this.plugins) if (plugin.robuildBuildEnd) await plugin.robuildBuildEnd(this.context, result);
127
+ }
128
+ /**
129
+ * Get rolldown-compatible plugins for direct use
130
+ */
131
+ getRolldownPlugins() {
132
+ return this.plugins.map((plugin) => {
133
+ const { robuildSetup, robuildBuildStart, robuildBuildEnd,...rolldownPlugin } = plugin;
134
+ return rolldownPlugin;
135
+ });
136
+ }
137
+ /**
138
+ * Get all plugins
139
+ */
140
+ getPlugins() {
141
+ return this.plugins;
142
+ }
143
+ /**
144
+ * Update context (useful when build parameters change)
145
+ */
146
+ updateContext(updates) {
147
+ this.context = {
148
+ ...this.context,
149
+ ...updates
150
+ };
151
+ }
152
+ };
153
+
154
+ //#endregion
155
+ export { RobuildPluginManager };
package/dist/cli.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { build } from "./_chunks/build-yvhsAebv.mjs";
2
+ import { build } from "./_chunks/build-omZA_xD-.mjs";
3
+ import "./_chunks/plugin-manager-w5yRGJRn.mjs";
3
4
  import { colors } from "consola/utils";
4
5
  import { consola } from "consola";
5
6
  import process from "node:process";
package/dist/config.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { defineConfig } from "./_chunks/config-_iCJoeRz.mjs";
1
+ import { defineConfig } from "./_chunks/config-2CRkKJ3l.mjs";
2
2
  export { defineConfig };
package/dist/config.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { defineConfig } from "./_chunks/config-C1aXyI1S.mjs";
1
+ import { defineConfig } from "./_chunks/config-BsKCDKT5.mjs";
2
2
 
3
3
  export { defineConfig };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { BuildConfig, BuildEntry, BundleEntry, RobuildPlugin, TransformEntry, defineConfig } from "./_chunks/config-_iCJoeRz.mjs";
1
+ import { BuildConfig, BuildEntry, BundleEntry, RobuildPlugin, TransformEntry, defineConfig } from "./_chunks/config-2CRkKJ3l.mjs";
2
2
  import { Plugin } from "rolldown";
3
3
 
4
4
  //#region src/build.d.ts
@@ -14,12 +14,6 @@ declare function build(config: BuildConfig): Promise<void>;
14
14
  */
15
15
  declare function combinePlugins(name: string, plugins: RobuildPlugin[]): RobuildPlugin;
16
16
  //#endregion
17
- //#region src/plugins/css.d.ts
18
- /**
19
- * Built-in plugin for CSS imports
20
- */
21
- declare function cssPlugin(): RobuildPlugin;
22
- //#endregion
23
17
  //#region src/plugins/node-polyfills.d.ts
24
18
  /**
25
19
  * Built-in plugin for Node.js polyfills
@@ -56,4 +50,4 @@ declare function urlPlugin(extensions?: string[]): RobuildPlugin;
56
50
  */
57
51
  declare function virtualPlugin(modules: Record<string, string>): RobuildPlugin;
58
52
  //#endregion
59
- export { type BuildConfig, type BuildEntry, type BundleEntry, type RobuildPlugin, SHEBANG_RE, type TransformEntry, build, combinePlugins, cssPlugin, defineConfig, hasShebang, makeExecutable, nodePolyfillsPlugin, nodeProtocolPlugin, shebangPlugin, textPlugin, urlPlugin, virtualPlugin };
53
+ export { type BuildConfig, type BuildEntry, type BundleEntry, type RobuildPlugin, SHEBANG_RE, type TransformEntry, build, combinePlugins, defineConfig, hasShebang, makeExecutable, nodePolyfillsPlugin, nodeProtocolPlugin, shebangPlugin, textPlugin, urlPlugin, virtualPlugin };
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { SHEBANG_RE, build, hasShebang, makeExecutable, nodeProtocolPlugin, shebangPlugin } from "./_chunks/build-yvhsAebv.mjs";
2
- import { defineConfig } from "./_chunks/config-C1aXyI1S.mjs";
1
+ import { SHEBANG_RE, build, hasShebang, makeExecutable, nodeProtocolPlugin, shebangPlugin } from "./_chunks/build-omZA_xD-.mjs";
2
+ import "./_chunks/plugin-manager-w5yRGJRn.mjs";
3
+ import { defineConfig } from "./_chunks/config-BsKCDKT5.mjs";
3
4
 
4
5
  //#region src/features/plugin-utils.ts
5
6
  /**
@@ -93,36 +94,6 @@ function combinePlugins(name, plugins) {
93
94
  return combinedPlugin;
94
95
  }
95
96
 
96
- //#endregion
97
- //#region src/plugins/css.ts
98
- /**
99
- * Built-in plugin for CSS imports
100
- */
101
- function cssPlugin() {
102
- return {
103
- name: "css",
104
- load: async (id) => {
105
- if (id.endsWith(".css")) try {
106
- const { readFile } = await import("node:fs/promises");
107
- const content = await readFile(id, "utf-8");
108
- return `
109
- const css = ${JSON.stringify(content)};
110
- if (typeof document !== 'undefined') {
111
- const style = document.createElement('style');
112
- style.textContent = css;
113
- document.head.appendChild(style);
114
- }
115
- export default css;
116
- `;
117
- } catch (error) {
118
- console.error(`Failed to load CSS file ${id}:`, error);
119
- return null;
120
- }
121
- return null;
122
- }
123
- };
124
- }
125
-
126
97
  //#endregion
127
98
  //#region src/plugins/node-polyfills.ts
128
99
  /**
@@ -217,4 +188,4 @@ function virtualPlugin(modules) {
217
188
  }
218
189
 
219
190
  //#endregion
220
- export { SHEBANG_RE, build, combinePlugins, cssPlugin, defineConfig, hasShebang, makeExecutable, nodePolyfillsPlugin, nodeProtocolPlugin, shebangPlugin, textPlugin, urlPlugin, virtualPlugin };
191
+ export { SHEBANG_RE, build, combinePlugins, defineConfig, hasShebang, makeExecutable, nodePolyfillsPlugin, nodeProtocolPlugin, shebangPlugin, textPlugin, urlPlugin, virtualPlugin };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "robuild",
3
3
  "type": "module",
4
- "version": "0.0.16",
4
+ "version": "0.0.18",
5
5
  "packageManager": "pnpm@10.11.1",
6
6
  "description": "Zero-config ESM/TS package builder. Powered by Rolldown and Oxc",
7
7
  "license": "MIT",
@@ -1,3 +0,0 @@
1
- import { build, performBuild } from "./build-yvhsAebv.mjs";
2
-
3
- export { performBuild };