robuild 0.0.15 → 0.0.16

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,3 @@
1
+ import { build, performBuild } from "./build-yvhsAebv.mjs";
2
+
3
+ export { performBuild };
@@ -944,9 +944,9 @@ function analyzeDir(dir) {
944
944
  let totalSize$1 = 0;
945
945
  let totalFiles = 0;
946
946
  for (const d of dir) {
947
- const { size, files: files$1 } = analyzeDir(d);
947
+ const { size, files } = analyzeDir(d);
948
948
  totalSize$1 += size;
949
- totalFiles += files$1;
949
+ totalFiles += files;
950
950
  }
951
951
  return {
952
952
  size: totalSize$1,
@@ -954,21 +954,29 @@ function analyzeDir(dir) {
954
954
  };
955
955
  }
956
956
  let totalSize = 0;
957
- const files = readdirSync(dir, {
958
- withFileTypes: true,
959
- recursive: true
960
- });
961
- for (const file of files) {
962
- const fullPath = join(file.parentPath, file.name);
963
- if (file.isFile()) {
964
- const { size } = statSync(fullPath);
965
- totalSize += size;
957
+ try {
958
+ const files = readdirSync(dir, {
959
+ withFileTypes: true,
960
+ recursive: true
961
+ });
962
+ for (const file of files) {
963
+ const fullPath = join(file.parentPath, file.name);
964
+ if (file.isFile()) {
965
+ const { size } = statSync(fullPath);
966
+ totalSize += size;
967
+ }
966
968
  }
969
+ return {
970
+ size: totalSize,
971
+ files: files.length
972
+ };
973
+ } catch (error) {
974
+ if (error.code === "ENOENT" || error.code === "ENOTDIR") return {
975
+ size: 0,
976
+ files: 0
977
+ };
978
+ throw error;
967
979
  }
968
- return {
969
- size: totalSize,
970
- files: files.length
971
- };
972
980
  }
973
981
  async function distSize(dir, entry) {
974
982
  const build$1 = await rolldown({
@@ -979,7 +987,7 @@ async function distSize(dir, entry) {
979
987
  });
980
988
  const { output } = await build$1.generate({ inlineDynamicImports: true });
981
989
  const code = output[0].code;
982
- const { code: minified } = minify(entry, code);
990
+ const { code: minified } = await minify(entry, code);
983
991
  return {
984
992
  size: Buffer.byteLength(code),
985
993
  minSize: Buffer.byteLength(minified),
@@ -1222,19 +1230,12 @@ async function rolldownBuild(ctx, entry, hooks, config) {
1222
1230
  formatConfig.plugins = [...Array.isArray(formatConfig.plugins) ? formatConfig.plugins : [formatConfig.plugins], ...Array.isArray(dtsPlugins) ? dtsPlugins : [dtsPlugins]];
1223
1231
  }
1224
1232
  const res = await rolldown(formatConfig);
1225
- let formatOutDir = fullOutDir;
1233
+ const formatOutDir = fullOutDir;
1226
1234
  let entryFileName = `[name]${extension}`;
1227
1235
  if (isMultiFormat) {
1228
- if (format === "cjs") {
1229
- formatOutDir = join(fullOutDir, "cjs");
1230
- entryFileName = `[name].cjs`;
1231
- } else if (format === "iife" || format === "umd") {
1232
- formatOutDir = join(fullOutDir, platform === "browser" ? "browser" : format);
1233
- entryFileName = `[name].js`;
1234
- }
1235
- } else if ((format === "iife" || format === "umd") && platform === "browser") {
1236
- formatOutDir = join(fullOutDir, "browser");
1237
- entryFileName = `[name].js`;
1236
+ if (format === "cjs") entryFileName = `[name].cjs`;
1237
+ else if (format === "esm") entryFileName = `[name].mjs`;
1238
+ else if (format === "iife" || format === "umd") entryFileName = `[name].js`;
1238
1239
  }
1239
1240
  const robuildOutputConfig = {
1240
1241
  dir: formatOutDir,
@@ -1449,14 +1450,28 @@ async function transformDir(ctx, entry) {
1449
1450
  }
1450
1451
  const fullOutDir = resolve(ctx.pkgDir, entry.outDir);
1451
1452
  await cleanOutputDir(ctx.pkgDir, fullOutDir, entry.clean ?? true);
1453
+ const { statSync: statSync$1 } = await import("node:fs");
1454
+ let inputDir = entry.input;
1455
+ try {
1456
+ const stats = statSync$1(inputDir);
1457
+ if (stats.isFile()) {
1458
+ inputDir = dirname(inputDir);
1459
+ consola.warn(`Transform input should be a directory, not a file. Using directory: ${fmtPath(inputDir)}`);
1460
+ }
1461
+ } catch (error) {
1462
+ if (error.code !== "ENOENT") throw error;
1463
+ }
1452
1464
  const promises$1 = [];
1453
- for await (const entryName of await glob$1("**/*.*", { cwd: entry.input })) promises$1.push((async () => {
1454
- const entryPath = join(entry.input, entryName);
1465
+ const files = await glob$1("**/*.*", { cwd: inputDir });
1466
+ for await (const entryName of files) promises$1.push((async () => {
1467
+ const entryPath = join(inputDir, entryName);
1455
1468
  const ext = extname(entryPath);
1456
1469
  switch (ext) {
1457
- case ".ts": {
1470
+ case ".ts":
1471
+ case ".tsx":
1472
+ case ".jsx": {
1458
1473
  const transformed = await transformModule(entryPath, entry);
1459
- const baseName = entryName.replace(/\.ts$/, "");
1474
+ const baseName = entryName.replace(/\.(ts|tsx|jsx)$/, "");
1460
1475
  const outputFileName = createFilename(baseName, "esm", false, {
1461
1476
  platform: entry.platform,
1462
1477
  fixedExtension: entry.fixedExtension,
@@ -1465,6 +1480,11 @@ async function transformDir(ctx, entry) {
1465
1480
  let entryDistPath = join(entry.outDir, outputFileName);
1466
1481
  await mkdir(dirname(entryDistPath), { recursive: true });
1467
1482
  await writeFile(entryDistPath, transformed.code, "utf8");
1483
+ if (entry.sourcemap && transformed.map) {
1484
+ const mapPath = `${entryDistPath}.map`;
1485
+ const mapContent = typeof transformed.map === "string" ? transformed.map : JSON.stringify(transformed.map);
1486
+ await writeFile(mapPath, mapContent, "utf8");
1487
+ }
1468
1488
  if (entry.hash && !hasHash(entryDistPath)) {
1469
1489
  const hashedPath = addHashToFilename(entryDistPath, transformed.code);
1470
1490
  const { rename } = await import("node:fs/promises");
@@ -1502,8 +1522,10 @@ async function transformDir(ctx, entry) {
1502
1522
  */
1503
1523
  async function transformModule(entryPath, entry) {
1504
1524
  let sourceText = await readFile(entryPath, "utf8");
1525
+ const ext = extname(entryPath);
1526
+ const lang = ext === ".tsx" || ext === ".jsx" ? "tsx" : "ts";
1505
1527
  const sourceOptions = {
1506
- lang: "ts",
1528
+ lang,
1507
1529
  sourceType: "module"
1508
1530
  };
1509
1531
  const parsed = parseSync(entryPath, sourceText, { ...sourceOptions });
@@ -1517,6 +1539,8 @@ async function transformModule(entryPath, entry) {
1517
1539
  from: pathToFileURL(entryPath),
1518
1540
  extensions: entry.resolve?.extensions ?? [
1519
1541
  ".ts",
1542
+ ".tsx",
1543
+ ".jsx",
1520
1544
  ".js",
1521
1545
  ".mjs",
1522
1546
  ".cjs",
@@ -1540,18 +1564,19 @@ async function transformModule(entryPath, entry) {
1540
1564
  if (updatedStarts.has(req.start)) return;
1541
1565
  updatedStarts.add(req.start);
1542
1566
  const resolvedAbsolute = resolveModulePath(moduleId, resolveOptions);
1543
- const newId = relative(dirname(entryPath), resolvedAbsolute.replace(/\.ts$/, ".mjs"));
1567
+ const newId = relative(dirname(entryPath), resolvedAbsolute.replace(/\.(ts|tsx|jsx)$/, ".mjs"));
1544
1568
  magicString.remove(req.start, req.end);
1545
1569
  magicString.prependLeft(req.start, JSON.stringify(newId.startsWith(".") ? newId : `./${newId}`));
1546
1570
  };
1547
1571
  for (const staticImport of parsed.module.staticImports) rewriteSpecifier(staticImport.moduleRequest);
1548
1572
  for (const staticExport of parsed.module.staticExports) for (const staticExportEntry of staticExport.entries) if (staticExportEntry.moduleRequest) rewriteSpecifier(staticExportEntry.moduleRequest);
1549
1573
  sourceText = magicString.toString();
1550
- const transformed = transform(entryPath, sourceText, {
1574
+ const transformed = await transform(entryPath, sourceText, {
1551
1575
  ...entry.oxc,
1552
1576
  ...sourceOptions,
1553
1577
  cwd: dirname(entryPath),
1554
1578
  target: entry.target || "es2022",
1579
+ sourcemap: !!entry.sourcemap,
1555
1580
  typescript: {
1556
1581
  declaration: { stripInternal: true },
1557
1582
  ...entry.oxc?.typescript
@@ -1565,7 +1590,7 @@ async function transformModule(entryPath, entry) {
1565
1590
  throw error;
1566
1591
  }
1567
1592
  if (entry.minify) {
1568
- const res = minify(entryPath, transformed.code, entry.minify === true ? {} : entry.minify);
1593
+ const res = await minify(entryPath, transformed.code, entry.minify === true ? {} : entry.minify);
1569
1594
  transformed.code = res.code;
1570
1595
  transformed.map = res.map;
1571
1596
  }
@@ -1819,7 +1844,7 @@ function normalizePath$1(path, resolveFrom) {
1819
1844
  * Perform watch build using rolldown's built-in watch mode
1820
1845
  */
1821
1846
  async function performWatchBuild(config, ctx, startTime) {
1822
- const { performBuild: performBuild$1 } = await import("./build-yfn0_Gzc.mjs");
1847
+ const { performBuild: performBuild$1 } = await import("./build-DsPSXoU-.mjs");
1823
1848
  await performBuild$1(config, ctx, startTime);
1824
1849
  const bundleEntries = (config.entries || []).filter((entry) => {
1825
1850
  if (typeof entry === "string") return !entry.endsWith("/");
@@ -1833,6 +1858,10 @@ async function performWatchBuild(config, ctx, startTime) {
1833
1858
  }
1834
1859
  /**
1835
1860
  * Start rolldown watch mode for bundle entries
1861
+ *
1862
+ * Note: Watch mode currently uses simplified rolldown configuration.
1863
+ * For full feature parity with build mode, the initial build is performed first.
1864
+ * The watch mode then monitors for file changes and triggers rebuilds.
1836
1865
  */
1837
1866
  async function startRolldownWatch(ctx, bundleEntries) {
1838
1867
  logger.info("🚧 Using rolldown built-in watch mode...");
@@ -1848,12 +1877,36 @@ async function startRolldownWatch(ctx, bundleEntries) {
1848
1877
  };
1849
1878
  } else entry = rawEntry;
1850
1879
  entry.input = Array.isArray(entry.input) ? entry.input.map((i) => normalizePath$1(i, ctx.pkgDir)) : normalizePath$1(entry.input, ctx.pkgDir);
1880
+ const target = entry.target || "es2022";
1881
+ const platform = entry.platform || "node";
1882
+ const format = entry.format || "esm";
1883
+ const getExtension = (fmt) => {
1884
+ switch (fmt) {
1885
+ case "esm": return ".mjs";
1886
+ case "cjs": return ".cjs";
1887
+ case "iife":
1888
+ case "umd": return ".js";
1889
+ default: return ".mjs";
1890
+ }
1891
+ };
1892
+ const extension = getExtension(Array.isArray(format) ? format[0] : format);
1893
+ const rolldownFormat = Array.isArray(format) ? format[0] : format;
1894
+ const formatMap = {
1895
+ esm: "es",
1896
+ cjs: "cjs",
1897
+ iife: "iife",
1898
+ umd: "umd"
1899
+ };
1851
1900
  const watchConfig = {
1852
1901
  input: Array.isArray(entry.input) ? entry.input[0] : entry.input,
1853
1902
  output: {
1854
1903
  dir: entry.outDir,
1855
- format: "esm"
1856
- }
1904
+ format: formatMap[rolldownFormat] || "es",
1905
+ entryFileNames: `[name]${extension}`,
1906
+ sourcemap: entry.sourcemap
1907
+ },
1908
+ platform: platform === "node" ? "node" : "neutral",
1909
+ transform: { target }
1857
1910
  };
1858
1911
  watchConfigs.push(watchConfig);
1859
1912
  }
@@ -1981,13 +2034,17 @@ async function performBuild(config, ctx, startTime) {
1981
2034
  if (!hasInput) throw new Error(`Build entry missing \`input\` or \`entry\`: ${JSON.stringify(entry, null, 2)}`);
1982
2035
  entry = { ...entry };
1983
2036
  entry.outDir = normalizePath(entry.outDir || "dist", ctx.pkgDir);
1984
- const entryInput = entry.input || entry.entry;
1985
- if (entryInput) if (typeof entryInput === "object" && !Array.isArray(entryInput)) {
1986
- const normalizedInput = {};
1987
- for (const [key, value] of Object.entries(entryInput)) normalizedInput[key] = normalizePath(value, ctx.pkgDir);
1988
- entry.input = normalizedInput;
1989
- } else if (Array.isArray(entryInput)) entry.input = entryInput.map((p) => normalizePath(p, ctx.pkgDir));
1990
- else entry.input = normalizePath(entryInput, ctx.pkgDir);
2037
+ if (entry.type === "transform") {
2038
+ if (entry.input) entry.input = normalizePath(entry.input, ctx.pkgDir);
2039
+ } else {
2040
+ const entryInput = entry.input || entry.entry;
2041
+ if (entryInput) if (typeof entryInput === "object" && !Array.isArray(entryInput)) {
2042
+ const normalizedInput = {};
2043
+ for (const [key, value] of Object.entries(entryInput)) normalizedInput[key] = normalizePath(value, ctx.pkgDir);
2044
+ entry.input = normalizedInput;
2045
+ } else if (Array.isArray(entryInput)) entry.input = entryInput.map((p) => normalizePath(p, ctx.pkgDir));
2046
+ else entry.input = normalizePath(entryInput, ctx.pkgDir);
2047
+ }
1991
2048
  return entry;
1992
2049
  });
1993
2050
  await hooks.entries?.(entries, ctx);
@@ -1,7 +1,7 @@
1
1
  //#region package.json
2
2
  var name = "robuild";
3
3
  var type = "module";
4
- var version = "0.0.15";
4
+ var version = "0.0.16";
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";
@@ -24,6 +24,9 @@ var scripts = {
24
24
  "release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
25
25
  "test": "vitest run",
26
26
  "test:watch": "vitest",
27
+ "test:coverage": "vitest run --coverage",
28
+ "test:coverage:watch": "vitest --coverage",
29
+ "test:ui": "vitest --ui",
27
30
  "test:types": "tsc --noEmit --skipLibCheck src/**/*.ts",
28
31
  "docs:dev": "vitepress dev docs",
29
32
  "docs:build": "vitepress build docs",
@@ -35,15 +38,14 @@ var dependencies = {
35
38
  "cac": "^6.7.14",
36
39
  "chokidar": "^3.0.3",
37
40
  "consola": "^3.4.2",
38
- "defu": "^6.1.4",
39
41
  "exsolve": "^1.0.5",
40
42
  "glob": "^11.0.3",
41
43
  "js-yaml": "^4.1.0",
42
44
  "magic-string": "^0.30.17",
43
45
  "minimatch": "^10.0.3",
44
- "oxc-minify": "^0.89.0",
45
- "oxc-parser": "^0.89.0",
46
- "oxc-transform": "^0.89.0",
46
+ "oxc-minify": "^0.98.0",
47
+ "oxc-parser": "^0.98.0",
48
+ "oxc-transform": "^0.98.0",
47
49
  "pretty-bytes": "^7.0.1",
48
50
  "rolldown": "1.0.0-beta.30",
49
51
  "rolldown-plugin-dts": "^0.16.5",
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { build } from "./_chunks/build-BzBhuQnI.mjs";
2
+ import { build } from "./_chunks/build-yvhsAebv.mjs";
3
3
  import { colors } from "consola/utils";
4
4
  import { consola } from "consola";
5
5
  import process from "node:process";
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { SHEBANG_RE, build, hasShebang, makeExecutable, nodeProtocolPlugin, shebangPlugin } from "./_chunks/build-BzBhuQnI.mjs";
1
+ import { SHEBANG_RE, build, hasShebang, makeExecutable, nodeProtocolPlugin, shebangPlugin } from "./_chunks/build-yvhsAebv.mjs";
2
2
  import { defineConfig } from "./_chunks/config-C1aXyI1S.mjs";
3
3
 
4
4
  //#region src/features/plugin-utils.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "robuild",
3
3
  "type": "module",
4
- "version": "0.0.15",
4
+ "version": "0.0.16",
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",
@@ -26,6 +26,9 @@
26
26
  "release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
27
27
  "test": "vitest run",
28
28
  "test:watch": "vitest",
29
+ "test:coverage": "vitest run --coverage",
30
+ "test:coverage:watch": "vitest --coverage",
31
+ "test:ui": "vitest --ui",
29
32
  "test:types": "tsc --noEmit --skipLibCheck src/**/*.ts",
30
33
  "docs:dev": "vitepress dev docs",
31
34
  "docs:build": "vitepress build docs",
@@ -37,15 +40,14 @@
37
40
  "cac": "^6.7.14",
38
41
  "chokidar": "^3.0.3",
39
42
  "consola": "^3.4.2",
40
- "defu": "^6.1.4",
41
43
  "exsolve": "^1.0.5",
42
44
  "glob": "^11.0.3",
43
45
  "js-yaml": "^4.1.0",
44
46
  "magic-string": "^0.30.17",
45
47
  "minimatch": "^10.0.3",
46
- "oxc-minify": "^0.89.0",
47
- "oxc-parser": "^0.89.0",
48
- "oxc-transform": "^0.89.0",
48
+ "oxc-minify": "^0.98.0",
49
+ "oxc-parser": "^0.98.0",
50
+ "oxc-transform": "^0.98.0",
49
51
  "pretty-bytes": "^7.0.1",
50
52
  "rolldown": "1.0.0-beta.30",
51
53
  "rolldown-plugin-dts": "^0.16.5",
@@ -1,3 +0,0 @@
1
- import { build, performBuild } from "./build-BzBhuQnI.mjs";
2
-
3
- export { performBuild };