robuild 0.1.3 → 0.1.4

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 { n as performBuild, t as build } from "./build-UBcR7iC8.mjs";
2
+
3
+ export { performBuild };
@@ -1,4 +1,4 @@
1
- import { t as RobuildPluginManager } from "./manager-DyYf90Z5.mjs";
1
+ import { t as RobuildPluginManager } from "./manager-uQxDLzY6.mjs";
2
2
  import { builtinModules } from "node:module";
3
3
  import { basename, dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
4
4
  import { colors } from "consola/utils";
@@ -8,7 +8,7 @@ import { resolveModulePath } from "exsolve";
8
8
  import { parseSync } from "oxc-parser";
9
9
  import { rolldown, watch } from "rolldown";
10
10
  import { dts } from "rolldown-plugin-dts";
11
- import { existsSync, promises, readdirSync, statSync } from "node:fs";
11
+ import { existsSync, promises, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
12
12
  import { fileURLToPath, pathToFileURL } from "node:url";
13
13
  import { gzipSync } from "node:zlib";
14
14
  import { minify } from "oxc-minify";
@@ -839,7 +839,7 @@ function createNodeShimsPlugin() {
839
839
  return {
840
840
  name: "node-shims",
841
841
  transform: async (code, id) => {
842
- if (!/\.mjs$/.test(id) && !/\.js$/.test(id)) return null;
842
+ if (!id.endsWith(".mjs") && !id.endsWith(".js")) return null;
843
843
  const needs = detectShimNeeds(code);
844
844
  const shims = [];
845
845
  if (needs.needsDirname || needs.needsRequire) shims.push(NODE_GLOBALS_SHIM);
@@ -1104,7 +1104,7 @@ async function rolldownBuild(ctx, entry, hooks, config) {
1104
1104
  if (entry.sourcemap !== void 0) robuildOutputConfig.sourcemap = entry.sourcemap;
1105
1105
  const outConfig = {
1106
1106
  ...robuildOutputConfig,
1107
- ...userOutputConfig || {}
1107
+ ...userOutputConfig
1108
1108
  };
1109
1109
  await hooks.rolldownOutput?.(outConfig, res, ctx);
1110
1110
  const { output } = await res.write(outConfig);
@@ -1576,6 +1576,150 @@ function convertExternal(external) {
1576
1576
  return external;
1577
1577
  }
1578
1578
 
1579
+ //#endregion
1580
+ //#region src/transforms/exports.ts
1581
+ /**
1582
+ * Generate package.json exports field based on build configuration
1583
+ */
1584
+ function generatePackageExports(ctx, exportsConfig = { enabled: true }) {
1585
+ if (!exportsConfig.enabled) return {};
1586
+ const exports = {};
1587
+ const includeTypes = exportsConfig.includeTypes !== false;
1588
+ if (exportsConfig.custom) Object.assign(exports, exportsConfig.custom);
1589
+ for (const entry of ctx.entries) if (entry.type === "bundle") {
1590
+ const bundleEntry = entry;
1591
+ if (!bundleEntry.generateExports && !exportsConfig.enabled) continue;
1592
+ const exportEntries = generateExportFromBundleEntry(ctx.pkgDir, bundleEntry, includeTypes);
1593
+ for (const exportEntry of exportEntries) exports[exportEntry.key] = createExportValue(exportEntry);
1594
+ } else if (entry.type === "transform") {
1595
+ const transformEntry = entry;
1596
+ if (!exportsConfig.enabled) continue;
1597
+ const exportEntries = generateExportFromTransformEntry(ctx.pkgDir, transformEntry, includeTypes);
1598
+ for (const exportEntry of exportEntries) exports[exportEntry.key] = createExportValue(exportEntry);
1599
+ }
1600
+ return exports;
1601
+ }
1602
+ /**
1603
+ * Generate export entries from a bundle entry
1604
+ */
1605
+ function generateExportFromBundleEntry(pkgDir, entry, includeTypes) {
1606
+ const exports = [];
1607
+ const inputValue = entry.input ?? entry.entry ?? "src/index.ts";
1608
+ const rawOutDir = entry.outDir || "dist";
1609
+ const outDir = isAbsolute(rawOutDir) ? relative(pkgDir, rawOutDir) : rawOutDir;
1610
+ const formats = Array.isArray(entry.format) ? entry.format : [entry.format || "es"];
1611
+ const platform = entry.platform || "node";
1612
+ const isMultiFormat = formats.length > 1;
1613
+ const inputs = normalizeInput(inputValue, pkgDir);
1614
+ for (const [name, _srcPath] of Object.entries(inputs)) {
1615
+ let exportKey;
1616
+ if (entry.exportPath) exportKey = entry.exportPath;
1617
+ else exportKey = getExportKeyFromName(name);
1618
+ const exportEntry = { key: exportKey };
1619
+ for (const format of formats) {
1620
+ const outputPath = `./${join(outDir, `${name}${getOutputExtension(format, isMultiFormat, platform, entry.fixedExtension)}`)}`;
1621
+ if (format === "es" || format === "esm" || format === "module") exportEntry.import = outputPath;
1622
+ else if (format === "cjs" || format === "commonjs") exportEntry.require = outputPath;
1623
+ else if (!exportEntry.import) exportEntry.import = outputPath;
1624
+ }
1625
+ if (includeTypes && entry.dts !== false) exportEntry.types = `./${join(outDir, `${name}${entry.fixedExtension ? ".d.mts" : ".d.mts"}`)}`;
1626
+ exports.push(exportEntry);
1627
+ }
1628
+ return exports;
1629
+ }
1630
+ /**
1631
+ * Generate export entries from a transform entry
1632
+ */
1633
+ function generateExportFromTransformEntry(pkgDir, entry, includeTypes) {
1634
+ const exports = [];
1635
+ const rawOutDir = entry.outDir || "dist";
1636
+ const outDir = isAbsolute(rawOutDir) ? relative(pkgDir, rawOutDir) : rawOutDir;
1637
+ const exportEntry = {
1638
+ key: ".",
1639
+ import: `./${join(outDir, "index.mjs")}`
1640
+ };
1641
+ if (includeTypes) exportEntry.types = `./${join(outDir, "index.d.mts")}`;
1642
+ exports.push(exportEntry);
1643
+ return exports;
1644
+ }
1645
+ /**
1646
+ * Normalize input to a Record<string, string> format
1647
+ */
1648
+ function normalizeInput(input, pkgDir) {
1649
+ if (typeof input === "object" && !Array.isArray(input)) {
1650
+ const result = {};
1651
+ for (const [key, value] of Object.entries(input)) result[key] = value;
1652
+ return result;
1653
+ }
1654
+ const result = {};
1655
+ const inputs = Array.isArray(input) ? input : [input];
1656
+ for (const src of inputs) {
1657
+ const name = getNameFromPath(src, pkgDir);
1658
+ result[name] = src;
1659
+ }
1660
+ return result;
1661
+ }
1662
+ /**
1663
+ * Get name from source path
1664
+ */
1665
+ function getNameFromPath(srcPath, pkgDir) {
1666
+ let path = srcPath;
1667
+ if (pkgDir && isAbsolute(srcPath)) path = relative(pkgDir, srcPath);
1668
+ path = path.replace(/^\.\//, "");
1669
+ path = path.replace(/^src\//, "");
1670
+ path = path.replace(/\.(ts|js|tsx|jsx|mts|mjs|cts|cjs)$/, "");
1671
+ const dir = dirname(path);
1672
+ const base = basename(path);
1673
+ if (dir === "." || dir === "") return base;
1674
+ return join(dir, base);
1675
+ }
1676
+ /**
1677
+ * Get export key from entry name
1678
+ */
1679
+ function getExportKeyFromName(name) {
1680
+ if (name === "index") return ".";
1681
+ if (name.endsWith("/index")) return `./${name.replace(/\/index$/, "")}`;
1682
+ return `./${name}`;
1683
+ }
1684
+ /**
1685
+ * Get output file extension
1686
+ */
1687
+ function getOutputExtension(format, isMultiFormat, platform, fixedExtension) {
1688
+ if (isMultiFormat) {
1689
+ if (format === "cjs" || format === "commonjs") return ".cjs";
1690
+ else if (format === "es" || format === "esm" || format === "module") return ".mjs";
1691
+ else if (format === "iife" || format === "umd") return ".js";
1692
+ }
1693
+ return getFormatExtension(format, platform, fixedExtension);
1694
+ }
1695
+ /**
1696
+ * Create export value from export entry
1697
+ */
1698
+ function createExportValue(entry) {
1699
+ const value = {};
1700
+ if (entry.types) value.types = entry.types;
1701
+ if (entry.import) value.import = entry.import;
1702
+ if (entry.require) value.require = entry.require;
1703
+ const nonTypeKeys = Object.keys(value).filter((k) => k !== "types");
1704
+ if (nonTypeKeys.length === 1 && !entry.types) return value[nonTypeKeys[0]];
1705
+ return value;
1706
+ }
1707
+ /**
1708
+ * Update package.json with generated exports
1709
+ */
1710
+ function updatePackageJsonExports(packageRoot, exports) {
1711
+ const packageJsonPath = join(packageRoot, "package.json");
1712
+ try {
1713
+ const content = readFileSync(packageJsonPath, "utf-8");
1714
+ const packageJson = JSON.parse(content);
1715
+ packageJson.exports = exports;
1716
+ writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`, "utf-8");
1717
+ logger.info(`${colors.cyan("Exports")} Updated package.json exports field`);
1718
+ } catch (error) {
1719
+ throw new Error(`Failed to update package.json: ${error}`);
1720
+ }
1721
+ }
1722
+
1579
1723
  //#endregion
1580
1724
  //#region src/transforms/on-success.ts
1581
1725
  const execAsync = promisify(exec);
@@ -1619,7 +1763,7 @@ function createBuildResult(entries, startTime) {
1619
1763
  * Perform watch build using rolldown's built-in watch mode
1620
1764
  */
1621
1765
  async function performWatchBuild(config, ctx, startTime) {
1622
- const { performBuild } = await import("./build-DsVOIGdc.mjs");
1766
+ const { performBuild } = await import("./build-BY2-r2pO.mjs");
1623
1767
  await performBuild(config, ctx, startTime);
1624
1768
  const bundleEntries = (config.entries || []).filter((entry) => {
1625
1769
  if (typeof entry === "string") return !entry.endsWith("/");
@@ -1640,7 +1784,7 @@ async function performWatchBuild(config, ctx, startTime) {
1640
1784
  */
1641
1785
  async function startRolldownWatch(config, ctx, bundleEntries) {
1642
1786
  logger.info("Watching for changes...");
1643
- const { RobuildPluginManager } = await import("./manager-CnmjrU85.mjs");
1787
+ const { RobuildPluginManager } = await import("./manager-7_zLtHqz.mjs");
1644
1788
  const watchConfigs = [];
1645
1789
  for (const rawEntry of bundleEntries) {
1646
1790
  const entry = typeof rawEntry === "string" ? parseEntryString(rawEntry) : rawEntry;
@@ -1823,6 +1967,14 @@ async function performBuild(config, ctx, startTime) {
1823
1967
  for (const outDir of entries.map((e) => e.outDir).sort()) if (!outDirs.some((dir) => outDir.startsWith(dir))) outDirs.push(outDir);
1824
1968
  for (const entry of entries) await (entry.type === "bundle" ? rolldownBuild(ctx, entry, hooks, config) : transformDir(ctx, entry));
1825
1969
  await hooks.end?.(ctx);
1970
+ if (config.exports?.enabled) {
1971
+ const packageExports = generatePackageExports({
1972
+ pkgDir: ctx.pkgDir,
1973
+ config,
1974
+ entries
1975
+ }, config.exports);
1976
+ if (Object.keys(packageExports).length > 0 && config.exports.autoUpdate !== false) updatePackageJsonExports(ctx.pkgDir, packageExports);
1977
+ }
1826
1978
  if (shouldFailOnWarnings(config.failOnWarn || false)) throw new Error("Build failed due to warnings");
1827
1979
  const dirSize = analyzeDir(outDirs);
1828
1980
  logger.info(colors.dim(`\nTotal: ${colors.bold(prettyBytes(dirSize.size))} (${dirSize.files} files)`));
@@ -0,0 +1,3 @@
1
+ import { t as RobuildPluginManager } from "./manager-uQxDLzY6.mjs";
2
+
3
+ export { RobuildPluginManager };
@@ -130,7 +130,7 @@ var RobuildPluginManager = class {
130
130
  */
131
131
  getRolldownPlugins() {
132
132
  return this.plugins.map((plugin) => {
133
- const { robuildSetup, robuildBuildStart, robuildBuildEnd, ...rolldownPlugin } = plugin;
133
+ const { robuildSetup: _setup, robuildBuildStart: _start, robuildBuildEnd: _end, ...rolldownPlugin } = plugin;
134
134
  return rolldownPlugin;
135
135
  });
136
136
  }
@@ -2,7 +2,7 @@
2
2
  var package_default = {
3
3
  name: "robuild",
4
4
  type: "module",
5
- version: "0.1.3",
5
+ version: "0.1.4",
6
6
  packageManager: "pnpm@10.11.1",
7
7
  description: "Zero-config ESM/TS package builder. Powered by Rolldown and Oxc",
8
8
  license: "MIT",
@@ -20,8 +20,9 @@ var package_default = {
20
20
  "build:raw": "pnpm test:types && pnpm robuild",
21
21
  "dev": "pnpm test:raw",
22
22
  "lint": "turbo lint:raw --filter=robuild",
23
- "lint:raw": "eslint .",
24
- "lint:fix": "automd && eslint . --fix",
23
+ "lint:raw": "oxlint -c oxlint.json .",
24
+ "lint:fix": "automd && oxlint -c oxlint.json --fix .",
25
+ "format": "oxlint -c oxlint.json --fix .",
25
26
  "robuild": "esno src/cli.ts",
26
27
  "prepack": "pnpm build",
27
28
  "release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
@@ -60,16 +61,14 @@ var package_default = {
60
61
  "typescript": "^5.9.3"
61
62
  },
62
63
  devDependencies: {
63
- "@antfu/eslint-config": "^7.4.3",
64
64
  "@types/js-yaml": "^4.0.9",
65
65
  "@types/node": "^25.2.3",
66
66
  "@vitest/coverage-v8": "^4.0.18",
67
67
  "automd": "^0.4.3",
68
68
  "changelogen": "^0.6.2",
69
- "eslint": "^10.0.0",
70
69
  "esno": "^4.8.0",
71
70
  "git-cz": "^4.9.0",
72
- "prettier": "^3.8.1",
71
+ "oxlint": "^1.49.0",
73
72
  "turbo": "^2.8.7",
74
73
  "vitepress": "^1.6.4",
75
74
  "vitest": "^4.0.18"
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { g as logger, h as configureLogger, t as build } from "./_chunks/build-ZPgEqYgE.mjs";
2
+ import { g as logger, h as configureLogger, t as build } from "./_chunks/build-UBcR7iC8.mjs";
3
3
  import { colors } from "consola/utils";
4
4
  import process from "node:process";
5
5
  import { loadConfig } from "c12";
package/dist/config.d.mts CHANGED
@@ -342,6 +342,29 @@ type BundleEntry = _BuildEntry & {
342
342
  * @default false
343
343
  */
344
344
  dtsOnly?: boolean;
345
+ /**
346
+ * Generate package.json exports entry for this entry.
347
+ *
348
+ * When enabled, this entry will be included in the generated exports field.
349
+ *
350
+ * @default false
351
+ */
352
+ generateExports?: boolean;
353
+ /**
354
+ * Custom export path for this entry.
355
+ *
356
+ * If not specified, the export path will be derived from the input path.
357
+ * Use '.' for the main export, or './subpath' for subpath exports.
358
+ *
359
+ * @example
360
+ * ```ts
361
+ * {
362
+ * input: './src/utils/index.ts',
363
+ * exportPath: './utils'
364
+ * }
365
+ * ```
366
+ */
367
+ exportPath?: string;
345
368
  };
346
369
  type TransformEntry = _BuildEntry & {
347
370
  type: 'transform';
@@ -722,4 +745,4 @@ interface ExportsConfig {
722
745
  //#region src/config.d.ts
723
746
  declare function defineConfig(config: BuildConfig): BuildConfig;
724
747
  //#endregion
725
- export { GlobImportOptions as a, RobuildPlugin as c, ShimsConfig as d, TransformEntry as f, BundleEntry as i, RobuildPluginContext as l, BuildConfig as n, LoaderConfig as o, BuildEntry as r, LoaderType as s, defineConfig as t, RobuildPluginFactory as u };
748
+ export { ExportsConfig as a, LoaderType as c, RobuildPluginFactory as d, ShimsConfig as f, BundleEntry as i, RobuildPlugin as l, BuildConfig as n, GlobImportOptions as o, TransformEntry as p, BuildEntry as r, LoaderConfig as s, defineConfig as t, RobuildPluginContext as u };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as GlobImportOptions, c as RobuildPlugin, d as ShimsConfig, f as TransformEntry, i as BundleEntry, l as RobuildPluginContext, n as BuildConfig, o as LoaderConfig, r as BuildEntry, s as LoaderType, t as defineConfig, u as RobuildPluginFactory } from "./config.mjs";
1
+ import { a as ExportsConfig, c as LoaderType, d as RobuildPluginFactory, f as ShimsConfig, i as BundleEntry, l as RobuildPlugin, n as BuildConfig, o as GlobImportOptions, p as TransformEntry, r as BuildEntry, s as LoaderConfig, t as defineConfig, u as RobuildPluginContext } from "./config.mjs";
2
2
  import { Plugin } from "rolldown";
3
3
 
4
4
  //#region src/build.d.ts
@@ -209,4 +209,4 @@ declare class RobuildPluginManager {
209
209
  updateContext(updates: Partial<RobuildPluginContext>): void;
210
210
  }
211
211
  //#endregion
212
- export { type BuildConfig, type BuildEntry, type BundleEntry, DEFAULT_LOADERS, DEFAULT_SHIMS_CONFIG, type RobuildPlugin, RobuildPluginManager, SHEBANG_RE, type TransformEntry, build, combinePlugins, createBrowserShimsPlugin, createCjsDefaultPlugin, createGlobImportPlugin, createLoadPlugin, createLoaderPlugin, createNodeShimsPlugin, createPluginFactory, createResolvePlugin, createRobuildPlugin, createShimsPlugin, createSkipNodeModulesPlugin, createTransformPlugin, defineConfig, extendRolldownPlugin, getLoaderForFile, hasGlobImports, hasShebang, makeExecutable, nodePolyfillsPlugin, nodeProtocolPlugin, shebangPlugin, textPlugin, urlPlugin, virtualPlugin };
212
+ export { type BuildConfig, type BuildEntry, type BundleEntry, DEFAULT_LOADERS, DEFAULT_SHIMS_CONFIG, type ExportsConfig, type RobuildPlugin, RobuildPluginManager, SHEBANG_RE, type TransformEntry, build, combinePlugins, createBrowserShimsPlugin, createCjsDefaultPlugin, createGlobImportPlugin, createLoadPlugin, createLoaderPlugin, createNodeShimsPlugin, createPluginFactory, createResolvePlugin, createRobuildPlugin, createShimsPlugin, createSkipNodeModulesPlugin, createTransformPlugin, defineConfig, extendRolldownPlugin, getLoaderForFile, hasGlobImports, hasShebang, makeExecutable, nodePolyfillsPlugin, nodeProtocolPlugin, shebangPlugin, textPlugin, urlPlugin, virtualPlugin };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { a as createBrowserShimsPlugin, c as SHEBANG_RE, d as shebangPlugin, f as nodeProtocolPlugin, g as logger, i as DEFAULT_SHIMS_CONFIG, l as hasShebang, m as hasGlobImports, o as createNodeShimsPlugin, p as createGlobImportPlugin, r as createSkipNodeModulesPlugin, s as createShimsPlugin, t as build, u as makeExecutable } from "./_chunks/build-ZPgEqYgE.mjs";
2
- import { t as RobuildPluginManager } from "./_chunks/manager-DyYf90Z5.mjs";
1
+ import { a as createBrowserShimsPlugin, c as SHEBANG_RE, d as shebangPlugin, f as nodeProtocolPlugin, g as logger, i as DEFAULT_SHIMS_CONFIG, l as hasShebang, m as hasGlobImports, o as createNodeShimsPlugin, p as createGlobImportPlugin, r as createSkipNodeModulesPlugin, s as createShimsPlugin, t as build, u as makeExecutable } from "./_chunks/build-UBcR7iC8.mjs";
2
+ import { t as RobuildPluginManager } from "./_chunks/manager-uQxDLzY6.mjs";
3
3
  import { defineConfig } from "./config.mjs";
4
4
  import { extname } from "node:path";
5
5
  import { readFile } from "node:fs/promises";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "robuild",
3
3
  "type": "module",
4
- "version": "0.1.3",
4
+ "version": "0.1.4",
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",
@@ -21,8 +21,9 @@
21
21
  "build:raw": "pnpm test:types && pnpm robuild",
22
22
  "dev": "pnpm test:raw",
23
23
  "lint": "turbo lint:raw --filter=robuild",
24
- "lint:raw": "eslint .",
25
- "lint:fix": "automd && eslint . --fix",
24
+ "lint:raw": "oxlint -c oxlint.json .",
25
+ "lint:fix": "automd && oxlint -c oxlint.json --fix .",
26
+ "format": "oxlint -c oxlint.json --fix .",
26
27
  "robuild": "esno src/cli.ts",
27
28
  "prepack": "pnpm build",
28
29
  "release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
@@ -61,16 +62,14 @@
61
62
  "typescript": "^5.9.3"
62
63
  },
63
64
  "devDependencies": {
64
- "@antfu/eslint-config": "^7.4.3",
65
65
  "@types/js-yaml": "^4.0.9",
66
66
  "@types/node": "^25.2.3",
67
67
  "@vitest/coverage-v8": "^4.0.18",
68
68
  "automd": "^0.4.3",
69
69
  "changelogen": "^0.6.2",
70
- "eslint": "^10.0.0",
71
70
  "esno": "^4.8.0",
72
71
  "git-cz": "^4.9.0",
73
- "prettier": "^3.8.1",
72
+ "oxlint": "^1.49.0",
74
73
  "turbo": "^2.8.7",
75
74
  "vitepress": "^1.6.4",
76
75
  "vitest": "^4.0.18"
@@ -1,3 +0,0 @@
1
- import { n as performBuild, t as build } from "./build-ZPgEqYgE.mjs";
2
-
3
- export { performBuild };
@@ -1,3 +0,0 @@
1
- import { t as RobuildPluginManager } from "./manager-DyYf90Z5.mjs";
2
-
3
- export { RobuildPluginManager };