@storm-software/unbuild 0.38.5 → 0.38.7

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.
package/README.md CHANGED
@@ -21,7 +21,7 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages
21
21
 
22
22
  <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
23
23
 
24
- [![Version](https://img.shields.io/badge/version-0.38.4-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
24
+ [![Version](https://img.shields.io/badge/version-0.38.5-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
25
25
 
26
26
  <!-- prettier-ignore-start -->
27
27
  <!-- markdownlint-disable -->
package/bin/unbuild.cjs CHANGED
@@ -1373,9 +1373,9 @@ var getConfig = /* @__PURE__ */ __name((workspaceRoot, skipLogs = false) => {
1373
1373
  var import_commander = require("commander");
1374
1374
 
1375
1375
  // src/build.ts
1376
- var import_devkit3 = require("@nx/devkit");
1376
+ var import_devkit4 = require("@nx/devkit");
1377
1377
  var import_js = require("@nx/js");
1378
- var import_buildable_libs_utils3 = require("@nx/js/src/utils/buildable-libs-utils");
1378
+ var import_buildable_libs_utils4 = require("@nx/js/src/utils/buildable-libs-utils");
1379
1379
 
1380
1380
  // ../build-tools/src/plugins/swc.ts
1381
1381
  var import_core = require("@swc/core");
@@ -1491,13 +1491,13 @@ var addPackageDependencies = /* @__PURE__ */ __name(async (workspaceRoot, projec
1491
1491
  return ret;
1492
1492
  }, []);
1493
1493
  packageJson.dependencies = localPackages.reduce((ret, localPackage) => {
1494
- if (!ret[localPackage.name] && !implicitDependencies?.includes(localPackage.name)) {
1495
- ret[localPackage.name] = `>=${localPackage.version || "0.0.1"}`;
1494
+ if (!ret[localPackage.name] && !implicitDependencies?.includes(localPackage.name) && packageJson.devDependencies?.[localPackage.name] === void 0) {
1495
+ ret[localPackage.name] = `^${localPackage.version || "0.0.1"}`;
1496
1496
  }
1497
1497
  return ret;
1498
1498
  }, packageJson.dependencies ?? {});
1499
1499
  packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
1500
- if (!ret[localPackage.name] && implicitDependencies?.includes(localPackage.name)) {
1500
+ if (!ret[localPackage.name] && implicitDependencies?.includes(localPackage.name) && packageJson.dependencies?.[localPackage.name] === void 0) {
1501
1501
  ret[localPackage.name] = localPackage.version || "0.0.1";
1502
1502
  }
1503
1503
  return ret;
@@ -1570,7 +1570,6 @@ var import_node_fs6 = require("fs");
1570
1570
  var import_promises6 = require("fs/promises");
1571
1571
  var import_node_path5 = require("path");
1572
1572
  var import_find_workspace_root5 = require("nx/src/utils/find-workspace-root");
1573
- var import_pkg_types = require("pkg-types");
1574
1573
  var import_unbuild = require("unbuild");
1575
1574
 
1576
1575
  // src/clean.ts
@@ -1590,6 +1589,58 @@ async function cleanDirectories(name = "Unbuild", directory, config) {
1590
1589
  }
1591
1590
  __name(cleanDirectories, "cleanDirectories");
1592
1591
 
1592
+ // src/plugins/analyze.ts
1593
+ var formatBytes = /* @__PURE__ */ __name((bytes) => {
1594
+ if (bytes === 0) return "0 Byte";
1595
+ const k = 1e3;
1596
+ const dm = 3;
1597
+ const sizes = [
1598
+ "Bytes",
1599
+ "KB",
1600
+ "MB",
1601
+ "GB"
1602
+ ];
1603
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
1604
+ return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
1605
+ }, "formatBytes");
1606
+ var analyzePlugin = /* @__PURE__ */ __name((options) => {
1607
+ return {
1608
+ name: "storm:analyzer",
1609
+ renderChunk(source, chunk) {
1610
+ const sourceBytes = formatBytes(source.length);
1611
+ const fileName = chunk.fileName;
1612
+ writeInfo(` - ${fileName} ${sourceBytes}`, options.config);
1613
+ }
1614
+ };
1615
+ }, "analyzePlugin");
1616
+
1617
+ // src/plugins/on-error.ts
1618
+ var onErrorPlugin = /* @__PURE__ */ __name((options) => ({
1619
+ name: "storm:on-error",
1620
+ buildEnd(error) {
1621
+ if (error) {
1622
+ writeError(`The following errors occurred during the build:
1623
+ ${error ? error.message : "Unknown build error"}
1624
+
1625
+ `, options.config);
1626
+ throw new Error("Storm unbuild process failed with errors.");
1627
+ }
1628
+ },
1629
+ renderError(error) {
1630
+ writeError(`The following errors occurred during the build:
1631
+ ${error ? error.message : "Unknown build error"}
1632
+
1633
+ `, options.config);
1634
+ throw new Error("Storm unbuild process failed with errors.");
1635
+ }
1636
+ }), "onErrorPlugin");
1637
+
1638
+ // src/plugins/tsc.ts
1639
+ var import_devkit3 = require("@nx/devkit");
1640
+ var import_buildable_libs_utils3 = require("@nx/js/src/utils/buildable-libs-utils");
1641
+ var import_compiler_helper_dependency = require("@nx/js/src/utils/compiler-helper-dependency");
1642
+ var import_rollup_plugin_typescript2 = __toESM(require("rollup-plugin-typescript2"), 1);
1643
+
1593
1644
  // src/utilities/helpers.ts
1594
1645
  var import_devkit2 = require("@nx/devkit");
1595
1646
  var import_buildable_libs_utils2 = require("@nx/js/src/utils/buildable-libs-utils");
@@ -1603,6 +1654,36 @@ async function loadConfig2(configPath) {
1603
1654
  return import((0, import_node_url.pathToFileURL)(configPath).toString()).then((config) => config.default);
1604
1655
  }
1605
1656
  __name(loadConfig2, "loadConfig");
1657
+ async function createTsCompilerOptions(config, tsConfigPath, projectRoot, dependencies) {
1658
+ const tsConfigFile = import_typescript.default.readConfigFile((0, import_devkit2.joinPathFragments)(config.workspaceRoot, projectRoot, tsConfigPath), import_typescript.default.sys.readFile);
1659
+ const tsConfig = import_typescript.default.parseJsonConfigFileContent(tsConfigFile.config, import_typescript.default.sys, (0, import_node_path4.dirname)((0, import_devkit2.joinPathFragments)(config.workspaceRoot, projectRoot, tsConfigPath)));
1660
+ const compilerOptions = {
1661
+ rootDir: projectRoot,
1662
+ declaration: true,
1663
+ paths: (0, import_buildable_libs_utils2.computeCompilerOptionsPaths)(tsConfig, dependencies ?? [])
1664
+ };
1665
+ writeTrace(compilerOptions, config);
1666
+ return compilerOptions;
1667
+ }
1668
+ __name(createTsCompilerOptions, "createTsCompilerOptions");
1669
+
1670
+ // src/plugins/tsc.ts
1671
+ var tscPlugin = /* @__PURE__ */ __name(async (options) => {
1672
+ const projectGraph = (0, import_devkit3.readCachedProjectGraph)();
1673
+ const result = (0, import_buildable_libs_utils3.calculateProjectBuildableDependencies)(void 0, projectGraph, options.config.workspaceRoot, options.projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
1674
+ let dependencies = result.dependencies;
1675
+ const tsLibDependency = (0, import_compiler_helper_dependency.getHelperDependency)(import_compiler_helper_dependency.HelperDependency.tsc, options.tsconfig, dependencies, projectGraph, true);
1676
+ if (tsLibDependency) {
1677
+ dependencies = dependencies.filter((deps) => deps.name !== tsLibDependency.name);
1678
+ dependencies.push(tsLibDependency);
1679
+ }
1680
+ const compilerOptions = await createTsCompilerOptions(options.config, options.tsconfig, options.projectRoot, dependencies);
1681
+ return (0, import_rollup_plugin_typescript2.default)({
1682
+ check: options.declaration !== false,
1683
+ tsconfig: options.tsconfig,
1684
+ tsconfigOverride: compilerOptions
1685
+ });
1686
+ }, "tscPlugin");
1606
1687
 
1607
1688
  // src/build.ts
1608
1689
  async function resolveOptions(options, config) {
@@ -1615,7 +1696,7 @@ async function resolveOptions(options, config) {
1615
1696
  }
1616
1697
  }
1617
1698
  const outputPath = options.outputPath || joinPaths("dist", options.projectRoot);
1618
- const projectGraph = (0, import_devkit3.readCachedProjectGraph)();
1699
+ const projectGraph = (0, import_devkit4.readCachedProjectGraph)();
1619
1700
  const projectJsonPath = joinPaths(config.workspaceRoot, options.projectRoot, "project.json");
1620
1701
  if (!(0, import_node_fs6.existsSync)(projectJsonPath)) {
1621
1702
  throw new Error("Cannot find project.json configuration");
@@ -1639,7 +1720,6 @@ async function resolveOptions(options, config) {
1639
1720
  if (!(0, import_node_fs6.existsSync)(tsconfig)) {
1640
1721
  throw new Error("Cannot find tsconfig.json configuration");
1641
1722
  }
1642
- const tsconfigFile = await (0, import_pkg_types.readTSConfig)(tsconfig);
1643
1723
  let sourceRoot = projectJson.sourceRoot;
1644
1724
  if (!sourceRoot) {
1645
1725
  sourceRoot = joinPaths(options.projectRoot, "src");
@@ -1647,7 +1727,7 @@ async function resolveOptions(options, config) {
1647
1727
  if (!(0, import_node_fs6.existsSync)(sourceRoot)) {
1648
1728
  throw new Error("Cannot find sourceRoot directory");
1649
1729
  }
1650
- const result = (0, import_buildable_libs_utils3.calculateProjectBuildableDependencies)(void 0, projectGraph, config.workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
1730
+ const result = (0, import_buildable_libs_utils4.calculateProjectBuildableDependencies)(void 0, projectGraph, config.workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
1651
1731
  let dependencies = result.dependencies;
1652
1732
  const tsLibDependency = (0, import_js.getHelperDependency)(import_js.HelperDependency.tsc, tsconfig, dependencies, projectGraph, true);
1653
1733
  if (tsLibDependency) {
@@ -1683,26 +1763,18 @@ async function resolveOptions(options, config) {
1683
1763
  builder: "mkdist",
1684
1764
  input: `./${entryPath}`,
1685
1765
  outDir,
1686
- declaration: options.emitTypes !== false,
1687
- addRelativeDeclarationExtensions: true,
1766
+ declaration: options.emitTypes !== false ? "compatible" : false,
1688
1767
  format: "esm",
1689
- ext: "mjs",
1690
- typescript: {
1691
- compilerOptions: tsconfigFile.compilerOptions
1692
- }
1768
+ ext: "mjs"
1693
1769
  });
1694
1770
  ret.push({
1695
1771
  name: `${name}-cjs`,
1696
1772
  builder: "mkdist",
1697
1773
  input: `./${entryPath}`,
1698
1774
  outDir,
1699
- declaration: options.emitTypes !== false,
1700
- addRelativeDeclarationExtensions: true,
1775
+ declaration: options.emitTypes !== false ? "compatible" : false,
1701
1776
  format: "cjs",
1702
- ext: "cjs",
1703
- typescript: {
1704
- compilerOptions: tsconfigFile.compilerOptions
1705
- }
1777
+ ext: "cjs"
1706
1778
  });
1707
1779
  return ret;
1708
1780
  }, []),
@@ -1787,6 +1859,17 @@ async function resolveOptions(options, config) {
1787
1859
  }
1788
1860
  resolvedOptions.hooks = {
1789
1861
  "rollup:options": /* @__PURE__ */ __name(async (ctx, opts) => {
1862
+ if (options.plugins && options.plugins.length > 0) {
1863
+ writeDebug(` \u{1F9E9} Found ${options.plugins.length} plugins in provided build options`, config);
1864
+ opts.plugins = options.plugins;
1865
+ } else {
1866
+ writeDebug(` \u{1F9E9} No plugins found in provided build options, using default plugins`, config);
1867
+ opts.plugins = await Promise.all([
1868
+ analyzePlugin(resolvedOptions),
1869
+ tscPlugin(resolvedOptions),
1870
+ onErrorPlugin(resolvedOptions)
1871
+ ]);
1872
+ }
1790
1873
  }, "rollup:options"),
1791
1874
  "mkdist:entry:options": /* @__PURE__ */ __name(async (ctx, entry, opts) => {
1792
1875
  opts.esbuild ||= {};
@@ -1892,7 +1975,7 @@ async function generatePackageJson(options) {
1892
1975
  }, packageJson.exports);
1893
1976
  packageJson.exports["./package.json"] ??= "./package.json";
1894
1977
  packageJson.exports["."] ??= addPackageJsonExport("index", packageJson.type, options.sourceRoot, options.projectRoot);
1895
- await (0, import_devkit3.writeJsonFile)(joinPaths(options.outDir, "package.json"), packageJson);
1978
+ await (0, import_devkit4.writeJsonFile)(joinPaths(options.outDir, "package.json"), packageJson);
1896
1979
  stopwatch();
1897
1980
  }
1898
1981
  return options;
package/bin/unbuild.js CHANGED
@@ -1352,9 +1352,9 @@ var getConfig = /* @__PURE__ */ __name((workspaceRoot, skipLogs = false) => {
1352
1352
  import { Command, Option } from "commander";
1353
1353
 
1354
1354
  // src/build.ts
1355
- import { readCachedProjectGraph as readCachedProjectGraph2, writeJsonFile } from "@nx/devkit";
1356
- import { getHelperDependency, HelperDependency } from "@nx/js";
1357
- import { calculateProjectBuildableDependencies as calculateProjectBuildableDependencies2 } from "@nx/js/src/utils/buildable-libs-utils";
1355
+ import { readCachedProjectGraph as readCachedProjectGraph3, writeJsonFile } from "@nx/devkit";
1356
+ import { getHelperDependency as getHelperDependency2, HelperDependency as HelperDependency2 } from "@nx/js";
1357
+ import { calculateProjectBuildableDependencies as calculateProjectBuildableDependencies3 } from "@nx/js/src/utils/buildable-libs-utils";
1358
1358
 
1359
1359
  // ../build-tools/src/plugins/swc.ts
1360
1360
  import { transform } from "@swc/core";
@@ -1470,13 +1470,13 @@ var addPackageDependencies = /* @__PURE__ */ __name(async (workspaceRoot, projec
1470
1470
  return ret;
1471
1471
  }, []);
1472
1472
  packageJson.dependencies = localPackages.reduce((ret, localPackage) => {
1473
- if (!ret[localPackage.name] && !implicitDependencies?.includes(localPackage.name)) {
1474
- ret[localPackage.name] = `>=${localPackage.version || "0.0.1"}`;
1473
+ if (!ret[localPackage.name] && !implicitDependencies?.includes(localPackage.name) && packageJson.devDependencies?.[localPackage.name] === void 0) {
1474
+ ret[localPackage.name] = `^${localPackage.version || "0.0.1"}`;
1475
1475
  }
1476
1476
  return ret;
1477
1477
  }, packageJson.dependencies ?? {});
1478
1478
  packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
1479
- if (!ret[localPackage.name] && implicitDependencies?.includes(localPackage.name)) {
1479
+ if (!ret[localPackage.name] && implicitDependencies?.includes(localPackage.name) && packageJson.dependencies?.[localPackage.name] === void 0) {
1480
1480
  ret[localPackage.name] = localPackage.version || "0.0.1";
1481
1481
  }
1482
1482
  return ret;
@@ -1549,7 +1549,6 @@ import { existsSync as existsSync5 } from "node:fs";
1549
1549
  import { readFile as readFile5 } from "node:fs/promises";
1550
1550
  import { relative as relative2 } from "node:path";
1551
1551
  import { findWorkspaceRoot as findWorkspaceRoot2 } from "nx/src/utils/find-workspace-root";
1552
- import { readTSConfig } from "pkg-types";
1553
1552
  import { build as unbuild } from "unbuild";
1554
1553
 
1555
1554
  // src/clean.ts
@@ -1569,6 +1568,58 @@ async function cleanDirectories(name = "Unbuild", directory, config) {
1569
1568
  }
1570
1569
  __name(cleanDirectories, "cleanDirectories");
1571
1570
 
1571
+ // src/plugins/analyze.ts
1572
+ var formatBytes = /* @__PURE__ */ __name((bytes) => {
1573
+ if (bytes === 0) return "0 Byte";
1574
+ const k = 1e3;
1575
+ const dm = 3;
1576
+ const sizes = [
1577
+ "Bytes",
1578
+ "KB",
1579
+ "MB",
1580
+ "GB"
1581
+ ];
1582
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
1583
+ return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
1584
+ }, "formatBytes");
1585
+ var analyzePlugin = /* @__PURE__ */ __name((options) => {
1586
+ return {
1587
+ name: "storm:analyzer",
1588
+ renderChunk(source, chunk) {
1589
+ const sourceBytes = formatBytes(source.length);
1590
+ const fileName = chunk.fileName;
1591
+ writeInfo(` - ${fileName} ${sourceBytes}`, options.config);
1592
+ }
1593
+ };
1594
+ }, "analyzePlugin");
1595
+
1596
+ // src/plugins/on-error.ts
1597
+ var onErrorPlugin = /* @__PURE__ */ __name((options) => ({
1598
+ name: "storm:on-error",
1599
+ buildEnd(error) {
1600
+ if (error) {
1601
+ writeError(`The following errors occurred during the build:
1602
+ ${error ? error.message : "Unknown build error"}
1603
+
1604
+ `, options.config);
1605
+ throw new Error("Storm unbuild process failed with errors.");
1606
+ }
1607
+ },
1608
+ renderError(error) {
1609
+ writeError(`The following errors occurred during the build:
1610
+ ${error ? error.message : "Unknown build error"}
1611
+
1612
+ `, options.config);
1613
+ throw new Error("Storm unbuild process failed with errors.");
1614
+ }
1615
+ }), "onErrorPlugin");
1616
+
1617
+ // src/plugins/tsc.ts
1618
+ import { readCachedProjectGraph as readCachedProjectGraph2 } from "@nx/devkit";
1619
+ import { calculateProjectBuildableDependencies as calculateProjectBuildableDependencies2 } from "@nx/js/src/utils/buildable-libs-utils";
1620
+ import { getHelperDependency, HelperDependency } from "@nx/js/src/utils/compiler-helper-dependency";
1621
+ import ts2Plugin from "rollup-plugin-typescript2";
1622
+
1572
1623
  // src/utilities/helpers.ts
1573
1624
  import { joinPathFragments } from "@nx/devkit";
1574
1625
  import { computeCompilerOptionsPaths } from "@nx/js/src/utils/buildable-libs-utils";
@@ -1582,6 +1633,36 @@ async function loadConfig2(configPath) {
1582
1633
  return import(pathToFileURL(configPath).toString()).then((config) => config.default);
1583
1634
  }
1584
1635
  __name(loadConfig2, "loadConfig");
1636
+ async function createTsCompilerOptions(config, tsConfigPath, projectRoot, dependencies) {
1637
+ const tsConfigFile = ts.readConfigFile(joinPathFragments(config.workspaceRoot, projectRoot, tsConfigPath), ts.sys.readFile);
1638
+ const tsConfig = ts.parseJsonConfigFileContent(tsConfigFile.config, ts.sys, dirname(joinPathFragments(config.workspaceRoot, projectRoot, tsConfigPath)));
1639
+ const compilerOptions = {
1640
+ rootDir: projectRoot,
1641
+ declaration: true,
1642
+ paths: computeCompilerOptionsPaths(tsConfig, dependencies ?? [])
1643
+ };
1644
+ writeTrace(compilerOptions, config);
1645
+ return compilerOptions;
1646
+ }
1647
+ __name(createTsCompilerOptions, "createTsCompilerOptions");
1648
+
1649
+ // src/plugins/tsc.ts
1650
+ var tscPlugin = /* @__PURE__ */ __name(async (options) => {
1651
+ const projectGraph = readCachedProjectGraph2();
1652
+ const result = calculateProjectBuildableDependencies2(void 0, projectGraph, options.config.workspaceRoot, options.projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
1653
+ let dependencies = result.dependencies;
1654
+ const tsLibDependency = getHelperDependency(HelperDependency.tsc, options.tsconfig, dependencies, projectGraph, true);
1655
+ if (tsLibDependency) {
1656
+ dependencies = dependencies.filter((deps) => deps.name !== tsLibDependency.name);
1657
+ dependencies.push(tsLibDependency);
1658
+ }
1659
+ const compilerOptions = await createTsCompilerOptions(options.config, options.tsconfig, options.projectRoot, dependencies);
1660
+ return ts2Plugin({
1661
+ check: options.declaration !== false,
1662
+ tsconfig: options.tsconfig,
1663
+ tsconfigOverride: compilerOptions
1664
+ });
1665
+ }, "tscPlugin");
1585
1666
 
1586
1667
  // src/build.ts
1587
1668
  async function resolveOptions(options, config) {
@@ -1594,7 +1675,7 @@ async function resolveOptions(options, config) {
1594
1675
  }
1595
1676
  }
1596
1677
  const outputPath = options.outputPath || joinPaths("dist", options.projectRoot);
1597
- const projectGraph = readCachedProjectGraph2();
1678
+ const projectGraph = readCachedProjectGraph3();
1598
1679
  const projectJsonPath = joinPaths(config.workspaceRoot, options.projectRoot, "project.json");
1599
1680
  if (!existsSync5(projectJsonPath)) {
1600
1681
  throw new Error("Cannot find project.json configuration");
@@ -1618,7 +1699,6 @@ async function resolveOptions(options, config) {
1618
1699
  if (!existsSync5(tsconfig)) {
1619
1700
  throw new Error("Cannot find tsconfig.json configuration");
1620
1701
  }
1621
- const tsconfigFile = await readTSConfig(tsconfig);
1622
1702
  let sourceRoot = projectJson.sourceRoot;
1623
1703
  if (!sourceRoot) {
1624
1704
  sourceRoot = joinPaths(options.projectRoot, "src");
@@ -1626,9 +1706,9 @@ async function resolveOptions(options, config) {
1626
1706
  if (!existsSync5(sourceRoot)) {
1627
1707
  throw new Error("Cannot find sourceRoot directory");
1628
1708
  }
1629
- const result = calculateProjectBuildableDependencies2(void 0, projectGraph, config.workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
1709
+ const result = calculateProjectBuildableDependencies3(void 0, projectGraph, config.workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
1630
1710
  let dependencies = result.dependencies;
1631
- const tsLibDependency = getHelperDependency(HelperDependency.tsc, tsconfig, dependencies, projectGraph, true);
1711
+ const tsLibDependency = getHelperDependency2(HelperDependency2.tsc, tsconfig, dependencies, projectGraph, true);
1632
1712
  if (tsLibDependency) {
1633
1713
  dependencies = dependencies.filter((deps) => deps.name !== tsLibDependency.name);
1634
1714
  dependencies.push(tsLibDependency);
@@ -1662,26 +1742,18 @@ async function resolveOptions(options, config) {
1662
1742
  builder: "mkdist",
1663
1743
  input: `./${entryPath}`,
1664
1744
  outDir,
1665
- declaration: options.emitTypes !== false,
1666
- addRelativeDeclarationExtensions: true,
1745
+ declaration: options.emitTypes !== false ? "compatible" : false,
1667
1746
  format: "esm",
1668
- ext: "mjs",
1669
- typescript: {
1670
- compilerOptions: tsconfigFile.compilerOptions
1671
- }
1747
+ ext: "mjs"
1672
1748
  });
1673
1749
  ret.push({
1674
1750
  name: `${name}-cjs`,
1675
1751
  builder: "mkdist",
1676
1752
  input: `./${entryPath}`,
1677
1753
  outDir,
1678
- declaration: options.emitTypes !== false,
1679
- addRelativeDeclarationExtensions: true,
1754
+ declaration: options.emitTypes !== false ? "compatible" : false,
1680
1755
  format: "cjs",
1681
- ext: "cjs",
1682
- typescript: {
1683
- compilerOptions: tsconfigFile.compilerOptions
1684
- }
1756
+ ext: "cjs"
1685
1757
  });
1686
1758
  return ret;
1687
1759
  }, []),
@@ -1766,6 +1838,17 @@ async function resolveOptions(options, config) {
1766
1838
  }
1767
1839
  resolvedOptions.hooks = {
1768
1840
  "rollup:options": /* @__PURE__ */ __name(async (ctx, opts) => {
1841
+ if (options.plugins && options.plugins.length > 0) {
1842
+ writeDebug(` \u{1F9E9} Found ${options.plugins.length} plugins in provided build options`, config);
1843
+ opts.plugins = options.plugins;
1844
+ } else {
1845
+ writeDebug(` \u{1F9E9} No plugins found in provided build options, using default plugins`, config);
1846
+ opts.plugins = await Promise.all([
1847
+ analyzePlugin(resolvedOptions),
1848
+ tscPlugin(resolvedOptions),
1849
+ onErrorPlugin(resolvedOptions)
1850
+ ]);
1851
+ }
1769
1852
  }, "rollup:options"),
1770
1853
  "mkdist:entry:options": /* @__PURE__ */ __name(async (ctx, entry, opts) => {
1771
1854
  opts.esbuild ||= {};
package/dist/build.cjs CHANGED
@@ -5,9 +5,11 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkPZ266WAXcjs = require('./chunk-PZ266WAX.cjs');
8
+ var _chunkNZEFFUTWcjs = require('./chunk-NZEFFUTW.cjs');
9
9
  require('./chunk-WGGER7UI.cjs');
10
- require('./chunk-YC7U7HH4.cjs');
10
+ require('./chunk-OOFPXPRC.cjs');
11
+ require('./chunk-X25DCA4T.cjs');
12
+ require('./chunk-VPCO2H3G.cjs');
11
13
  require('./chunk-K5SEKFQA.cjs');
12
14
  require('./chunk-BGYQAVKQ.cjs');
13
15
 
@@ -17,4 +19,4 @@ require('./chunk-BGYQAVKQ.cjs');
17
19
 
18
20
 
19
21
 
20
- exports.build = _chunkPZ266WAXcjs.build; exports.cleanOutputPath = _chunkPZ266WAXcjs.cleanOutputPath; exports.copyBuildAssets = _chunkPZ266WAXcjs.copyBuildAssets; exports.executeUnbuild = _chunkPZ266WAXcjs.executeUnbuild; exports.generatePackageJson = _chunkPZ266WAXcjs.generatePackageJson; exports.resolveOptions = _chunkPZ266WAXcjs.resolveOptions;
22
+ exports.build = _chunkNZEFFUTWcjs.build; exports.cleanOutputPath = _chunkNZEFFUTWcjs.cleanOutputPath; exports.copyBuildAssets = _chunkNZEFFUTWcjs.copyBuildAssets; exports.executeUnbuild = _chunkNZEFFUTWcjs.executeUnbuild; exports.generatePackageJson = _chunkNZEFFUTWcjs.generatePackageJson; exports.resolveOptions = _chunkNZEFFUTWcjs.resolveOptions;
package/dist/build.js CHANGED
@@ -5,9 +5,11 @@ import {
5
5
  executeUnbuild,
6
6
  generatePackageJson,
7
7
  resolveOptions
8
- } from "./chunk-LPAU53JZ.js";
8
+ } from "./chunk-CYDK2RIH.js";
9
9
  import "./chunk-JLKMLDBA.js";
10
- import "./chunk-QOHGN7PS.js";
10
+ import "./chunk-5XTPDLOE.js";
11
+ import "./chunk-2FX3WQNK.js";
12
+ import "./chunk-IYFBAI6G.js";
11
13
  import "./chunk-EJVOWVIQ.js";
12
14
  import "./chunk-3GQAWCBQ.js";
13
15
  export {
@@ -0,0 +1,31 @@
1
+ import {
2
+ writeError
3
+ } from "./chunk-EJVOWVIQ.js";
4
+ import {
5
+ __name
6
+ } from "./chunk-3GQAWCBQ.js";
7
+
8
+ // src/plugins/on-error.ts
9
+ var onErrorPlugin = /* @__PURE__ */ __name((options) => ({
10
+ name: "storm:on-error",
11
+ buildEnd(error) {
12
+ if (error) {
13
+ writeError(`The following errors occurred during the build:
14
+ ${error ? error.message : "Unknown build error"}
15
+
16
+ `, options.config);
17
+ throw new Error("Storm unbuild process failed with errors.");
18
+ }
19
+ },
20
+ renderError(error) {
21
+ writeError(`The following errors occurred during the build:
22
+ ${error ? error.message : "Unknown build error"}
23
+
24
+ `, options.config);
25
+ throw new Error("Storm unbuild process failed with errors.");
26
+ }
27
+ }), "onErrorPlugin");
28
+
29
+ export {
30
+ onErrorPlugin
31
+ };
@@ -0,0 +1,35 @@
1
+ import {
2
+ writeInfo
3
+ } from "./chunk-EJVOWVIQ.js";
4
+ import {
5
+ __name
6
+ } from "./chunk-3GQAWCBQ.js";
7
+
8
+ // src/plugins/analyze.ts
9
+ var formatBytes = /* @__PURE__ */ __name((bytes) => {
10
+ if (bytes === 0) return "0 Byte";
11
+ const k = 1e3;
12
+ const dm = 3;
13
+ const sizes = [
14
+ "Bytes",
15
+ "KB",
16
+ "MB",
17
+ "GB"
18
+ ];
19
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
20
+ return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
21
+ }, "formatBytes");
22
+ var analyzePlugin = /* @__PURE__ */ __name((options) => {
23
+ return {
24
+ name: "storm:analyzer",
25
+ renderChunk(source, chunk) {
26
+ const sourceBytes = formatBytes(source.length);
27
+ const fileName = chunk.fileName;
28
+ writeInfo(` - ${fileName} ${sourceBytes}`, options.config);
29
+ }
30
+ };
31
+ }, "analyzePlugin");
32
+
33
+ export {
34
+ analyzePlugin
35
+ };
@@ -2,8 +2,15 @@ import {
2
2
  cleanDirectories
3
3
  } from "./chunk-JLKMLDBA.js";
4
4
  import {
5
- loadConfig
6
- } from "./chunk-QOHGN7PS.js";
5
+ analyzePlugin
6
+ } from "./chunk-5XTPDLOE.js";
7
+ import {
8
+ onErrorPlugin
9
+ } from "./chunk-2FX3WQNK.js";
10
+ import {
11
+ loadConfig,
12
+ tscPlugin
13
+ } from "./chunk-IYFBAI6G.js";
7
14
  import {
8
15
  COLOR_KEYS,
9
16
  LogLevel,
@@ -150,13 +157,13 @@ var addPackageDependencies = /* @__PURE__ */ __name(async (workspaceRoot, projec
150
157
  return ret;
151
158
  }, []);
152
159
  packageJson.dependencies = localPackages.reduce((ret, localPackage) => {
153
- if (!ret[localPackage.name] && !implicitDependencies?.includes(localPackage.name)) {
154
- ret[localPackage.name] = `>=${localPackage.version || "0.0.1"}`;
160
+ if (!ret[localPackage.name] && !implicitDependencies?.includes(localPackage.name) && packageJson.devDependencies?.[localPackage.name] === void 0) {
161
+ ret[localPackage.name] = `^${localPackage.version || "0.0.1"}`;
155
162
  }
156
163
  return ret;
157
164
  }, packageJson.dependencies ?? {});
158
165
  packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
159
- if (!ret[localPackage.name] && implicitDependencies?.includes(localPackage.name)) {
166
+ if (!ret[localPackage.name] && implicitDependencies?.includes(localPackage.name) && packageJson.dependencies?.[localPackage.name] === void 0) {
160
167
  ret[localPackage.name] = localPackage.version || "0.0.1";
161
168
  }
162
169
  return ret;
@@ -805,7 +812,6 @@ import { existsSync as existsSync3 } from "node:fs";
805
812
  import { readFile as readFile4 } from "node:fs/promises";
806
813
  import { relative as relative2 } from "node:path";
807
814
  import { findWorkspaceRoot as findWorkspaceRoot2 } from "nx/src/utils/find-workspace-root";
808
- import { readTSConfig } from "pkg-types";
809
815
  import { build as unbuild } from "unbuild";
810
816
  async function resolveOptions(options, config) {
811
817
  writeDebug(" \u2699\uFE0F Resolving build options", config);
@@ -841,7 +847,6 @@ async function resolveOptions(options, config) {
841
847
  if (!existsSync3(tsconfig)) {
842
848
  throw new Error("Cannot find tsconfig.json configuration");
843
849
  }
844
- const tsconfigFile = await readTSConfig(tsconfig);
845
850
  let sourceRoot = projectJson.sourceRoot;
846
851
  if (!sourceRoot) {
847
852
  sourceRoot = joinPaths(options.projectRoot, "src");
@@ -885,26 +890,18 @@ async function resolveOptions(options, config) {
885
890
  builder: "mkdist",
886
891
  input: `./${entryPath}`,
887
892
  outDir,
888
- declaration: options.emitTypes !== false,
889
- addRelativeDeclarationExtensions: true,
893
+ declaration: options.emitTypes !== false ? "compatible" : false,
890
894
  format: "esm",
891
- ext: "mjs",
892
- typescript: {
893
- compilerOptions: tsconfigFile.compilerOptions
894
- }
895
+ ext: "mjs"
895
896
  });
896
897
  ret.push({
897
898
  name: `${name}-cjs`,
898
899
  builder: "mkdist",
899
900
  input: `./${entryPath}`,
900
901
  outDir,
901
- declaration: options.emitTypes !== false,
902
- addRelativeDeclarationExtensions: true,
902
+ declaration: options.emitTypes !== false ? "compatible" : false,
903
903
  format: "cjs",
904
- ext: "cjs",
905
- typescript: {
906
- compilerOptions: tsconfigFile.compilerOptions
907
- }
904
+ ext: "cjs"
908
905
  });
909
906
  return ret;
910
907
  }, []),
@@ -989,6 +986,17 @@ async function resolveOptions(options, config) {
989
986
  }
990
987
  resolvedOptions.hooks = {
991
988
  "rollup:options": /* @__PURE__ */ __name(async (ctx, opts) => {
989
+ if (options.plugins && options.plugins.length > 0) {
990
+ writeDebug(` \u{1F9E9} Found ${options.plugins.length} plugins in provided build options`, config);
991
+ opts.plugins = options.plugins;
992
+ } else {
993
+ writeDebug(` \u{1F9E9} No plugins found in provided build options, using default plugins`, config);
994
+ opts.plugins = await Promise.all([
995
+ analyzePlugin(resolvedOptions),
996
+ tscPlugin(resolvedOptions),
997
+ onErrorPlugin(resolvedOptions)
998
+ ]);
999
+ }
992
1000
  }, "rollup:options"),
993
1001
  "mkdist:entry:options": /* @__PURE__ */ __name(async (ctx, entry, opts) => {
994
1002
  opts.esbuild ||= {};