@kubb/core 2.0.0-alpha.3 → 2.0.0-alpha.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.
Files changed (52) hide show
  1. package/dist/index.cjs +62 -74
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +18 -38
  4. package/dist/index.d.ts +18 -38
  5. package/dist/index.js +62 -72
  6. package/dist/index.js.map +1 -1
  7. package/dist/utils.cjs +12 -7
  8. package/dist/utils.cjs.map +1 -1
  9. package/dist/utils.d.cts +2 -1
  10. package/dist/utils.d.ts +2 -1
  11. package/dist/utils.js +12 -7
  12. package/dist/utils.js.map +1 -1
  13. package/package.json +8 -7
  14. package/src/BarrelManager.ts +123 -0
  15. package/src/FileManager.ts +482 -0
  16. package/src/Generator.ts +34 -0
  17. package/src/PackageManager.ts +163 -0
  18. package/src/PluginManager.ts +640 -0
  19. package/src/PromiseManager.ts +48 -0
  20. package/src/SchemaGenerator.ts +8 -0
  21. package/src/build.ts +198 -0
  22. package/src/config.ts +21 -0
  23. package/src/errors.ts +12 -0
  24. package/src/index.ts +28 -0
  25. package/src/plugin.ts +80 -0
  26. package/src/types.ts +370 -0
  27. package/src/utils/EventEmitter.ts +24 -0
  28. package/src/utils/FunctionParams.ts +85 -0
  29. package/src/utils/Queue.ts +110 -0
  30. package/src/utils/TreeNode.ts +122 -0
  31. package/src/utils/URLPath.ts +128 -0
  32. package/src/utils/cache.ts +35 -0
  33. package/src/utils/clean.ts +5 -0
  34. package/src/utils/executeStrategies.ts +71 -0
  35. package/src/utils/index.ts +19 -0
  36. package/src/utils/logger.ts +76 -0
  37. package/src/utils/promise.ts +13 -0
  38. package/src/utils/randomColour.ts +39 -0
  39. package/src/utils/read.ts +68 -0
  40. package/src/utils/renderTemplate.ts +31 -0
  41. package/src/utils/throttle.ts +30 -0
  42. package/src/utils/timeout.ts +7 -0
  43. package/src/utils/transformers/combineCodes.ts +3 -0
  44. package/src/utils/transformers/createJSDocBlockText.ts +15 -0
  45. package/src/utils/transformers/escape.ts +31 -0
  46. package/src/utils/transformers/indent.ts +3 -0
  47. package/src/utils/transformers/index.ts +20 -0
  48. package/src/utils/transformers/nameSorter.ts +9 -0
  49. package/src/utils/transformers/searchAndReplace.ts +25 -0
  50. package/src/utils/transformers/transformReservedWord.ts +97 -0
  51. package/src/utils/uniqueName.ts +20 -0
  52. package/src/utils/write.ts +63 -0
package/dist/index.cjs CHANGED
@@ -312,14 +312,19 @@ function combineCodes(codes) {
312
312
  }
313
313
 
314
314
  // src/utils/transformers/createJSDocBlockText.ts
315
- function createJSDocBlockText({ comments }) {
315
+ function createJSDocBlockText({ comments, newLine }) {
316
316
  const filteredComments = comments.filter(Boolean);
317
317
  if (!filteredComments.length) {
318
318
  return "";
319
319
  }
320
- return `/**
320
+ const source = `/**
321
321
  * ${filteredComments.join("\n * ")}
322
322
  */`;
323
+ if (newLine) {
324
+ return `${source}
325
+ `;
326
+ }
327
+ return source;
323
328
  }
324
329
 
325
330
  // src/utils/transformers/escape.ts
@@ -663,12 +668,12 @@ var BarrelManager = class {
663
668
  if (currentTree.children?.length > 1) {
664
669
  const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
665
670
  const exports = currentTree.children.filter(Boolean).map((file) => {
666
- const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
667
- if (importPath.includes("index") && indexPath.includes("index")) {
671
+ const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
672
+ if (importPath.includes("index") && file.data.type === "file") {
668
673
  return void 0;
669
674
  }
670
675
  return {
671
- path: includeExt ? file.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
676
+ path: includeExt ? `${importPath}${extName}` : importPath,
672
677
  isTypeOnly
673
678
  };
674
679
  }).filter(Boolean);
@@ -683,10 +688,10 @@ var BarrelManager = class {
683
688
  } else {
684
689
  currentTree.children?.forEach((child) => {
685
690
  const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
686
- const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
691
+ const importPath = child.data.type === "directory" ? `./${child.data.name}/index` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
687
692
  const exports = [
688
693
  {
689
- path: includeExt ? child.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
694
+ path: includeExt ? `${importPath}${extName}` : importPath,
690
695
  isTypeOnly
691
696
  }
692
697
  ];
@@ -1106,44 +1111,6 @@ function setUniqueName(originalName, data) {
1106
1111
  }
1107
1112
 
1108
1113
  // src/errors.ts
1109
- var PluginError = class extends Error {
1110
- constructor(message, options) {
1111
- super(message, { cause: options.cause });
1112
- this.name = "PluginError";
1113
- this.cause = options.cause;
1114
- this.pluginManager = options.pluginManager;
1115
- }
1116
- };
1117
- var ParallelPluginError = class extends Error {
1118
- constructor(message, options) {
1119
- super(message, { cause: options.cause });
1120
- this.errors = [];
1121
- this.name = "ParallelPluginError";
1122
- this.errors = options.errors;
1123
- this.pluginManager = options.pluginManager;
1124
- }
1125
- findError(searchError) {
1126
- if (!searchError) {
1127
- return void 0;
1128
- }
1129
- return this.errors.find((error) => {
1130
- if (error.cause) {
1131
- if (error.cause.name == searchError.name) {
1132
- return true;
1133
- }
1134
- return !!this.findError(error.cause);
1135
- }
1136
- return error.name === searchError.name;
1137
- })?.cause;
1138
- }
1139
- };
1140
- var SummaryError = class extends Error {
1141
- constructor(message, options) {
1142
- super(message, { cause: options.cause });
1143
- this.name = "SummaryError";
1144
- this.summary = options.summary || [];
1145
- }
1146
- };
1147
1114
  var Warning = class extends Error {
1148
1115
  constructor(message, options) {
1149
1116
  super(message, { cause: options?.cause });
@@ -1488,15 +1455,12 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1488
1455
  }
1489
1456
  }
1490
1457
  const results = await Promise.allSettled(parallelPromises);
1491
- const errors = results.map((result) => {
1492
- if (isPromiseRejectedResult(result) && result.reason instanceof PluginError) {
1493
- return result.reason;
1458
+ results.forEach((result, index) => {
1459
+ if (isPromiseRejectedResult(result)) {
1460
+ const plugin = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)[index];
1461
+ __privateMethod(this, _catcher, catcher_fn).call(this, result.reason, plugin, hookName);
1494
1462
  }
1495
- return void 0;
1496
- }).filter(Boolean);
1497
- if (errors.length) {
1498
- throw new ParallelPluginError("Error", { errors, pluginManager: this });
1499
- }
1463
+ });
1500
1464
  return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
1501
1465
  }
1502
1466
  /**
@@ -1630,11 +1594,6 @@ execute_fn = function({
1630
1594
  return hook;
1631
1595
  }).then((result) => {
1632
1596
  output = result;
1633
- return result;
1634
- }).catch((e) => {
1635
- __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1636
- return null;
1637
- }).finally(() => {
1638
1597
  __privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
1639
1598
  parameters,
1640
1599
  output,
@@ -1642,6 +1601,10 @@ execute_fn = function({
1642
1601
  hookName,
1643
1602
  plugin
1644
1603
  });
1604
+ return result;
1605
+ }).catch((e) => {
1606
+ __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1607
+ return null;
1645
1608
  });
1646
1609
  return task;
1647
1610
  };
@@ -1665,11 +1628,6 @@ executeSync_fn = function({
1665
1628
  return fn;
1666
1629
  }
1667
1630
  output = hook;
1668
- return hook;
1669
- } catch (e) {
1670
- __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1671
- return null;
1672
- } finally {
1673
1631
  __privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
1674
1632
  parameters,
1675
1633
  output,
@@ -1677,15 +1635,18 @@ executeSync_fn = function({
1677
1635
  hookName,
1678
1636
  plugin
1679
1637
  });
1638
+ return hook;
1639
+ } catch (e) {
1640
+ __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1641
+ return null;
1680
1642
  }
1681
1643
  };
1682
1644
  _catcher = new WeakSet();
1683
1645
  catcher_fn = function(e, plugin, hookName) {
1684
- const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
1646
+ const text = `${e.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})
1685
1647
  `;
1686
- const pluginError = new PluginError(text, { cause: e, pluginManager: this });
1687
- this.eventEmitter.emit("error", pluginError);
1688
- throw pluginError;
1648
+ this.logger.error(text);
1649
+ this.eventEmitter.emit("error", e);
1689
1650
  };
1690
1651
  _parse = new WeakSet();
1691
1652
  parse_fn = function(plugin, pluginManager, context) {
@@ -1718,7 +1679,7 @@ parse_fn = function(plugin, pluginManager, context) {
1718
1679
  async function transformReducer(_previousCode, result, _plugin) {
1719
1680
  return result;
1720
1681
  }
1721
- async function build(options) {
1682
+ async function setup(options) {
1722
1683
  const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
1723
1684
  try {
1724
1685
  if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
@@ -1772,7 +1733,6 @@ async function build(options) {
1772
1733
  }
1773
1734
  };
1774
1735
  const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
1775
- const { plugins, fileManager } = pluginManager;
1776
1736
  pluginManager.on("execute", (executer) => {
1777
1737
  const { hookName, parameters, plugin } = executer;
1778
1738
  if (hookName === "writeFile" && logger.spinner) {
@@ -1810,13 +1770,18 @@ ${code}`);
1810
1770
  console.log(logs.join("\n"));
1811
1771
  }
1812
1772
  });
1773
+ return pluginManager;
1774
+ }
1775
+ async function build(options) {
1776
+ const pluginManager = await setup(options);
1777
+ const { fileManager, logger } = pluginManager;
1813
1778
  await pluginManager.hookParallel({
1814
1779
  hookName: "validate",
1815
- parameters: [plugins]
1780
+ parameters: [pluginManager.plugins]
1816
1781
  });
1817
1782
  await pluginManager.hookParallel({
1818
1783
  hookName: "buildStart",
1819
- parameters: [config]
1784
+ parameters: [options.config]
1820
1785
  });
1821
1786
  await pluginManager.hookParallel({ hookName: "buildEnd" });
1822
1787
  if (!fileManager.isExecuting && logger.spinner) {
@@ -1825,6 +1790,28 @@ ${code}`);
1825
1790
  }
1826
1791
  return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
1827
1792
  }
1793
+ async function safeBuild(options) {
1794
+ const pluginManager = await setup(options);
1795
+ const { fileManager, logger } = pluginManager;
1796
+ try {
1797
+ await pluginManager.hookParallel({
1798
+ hookName: "validate",
1799
+ parameters: [pluginManager.plugins]
1800
+ });
1801
+ await pluginManager.hookParallel({
1802
+ hookName: "buildStart",
1803
+ parameters: [options.config]
1804
+ });
1805
+ await pluginManager.hookParallel({ hookName: "buildEnd" });
1806
+ if (!fileManager.isExecuting && logger.spinner) {
1807
+ logger.spinner.suffixText = "";
1808
+ logger.spinner.succeed(`\u{1F4BE} Writing completed`);
1809
+ }
1810
+ } catch (e) {
1811
+ return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager, error: e };
1812
+ }
1813
+ return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
1814
+ }
1828
1815
 
1829
1816
  // src/Generator.ts
1830
1817
  var _options3, _context;
@@ -2212,6 +2199,9 @@ var _PackageManager = class _PackageManager {
2212
2199
  if (!packageVersion) {
2213
2200
  return false;
2214
2201
  }
2202
+ if (packageVersion === version) {
2203
+ return true;
2204
+ }
2215
2205
  const semVer = semver.coerce(packageVersion);
2216
2206
  if (!semVer) {
2217
2207
  throw new Error(`${packageVersion} is not valid`);
@@ -2246,12 +2236,9 @@ var src_default = build;
2246
2236
  exports.FileManager = FileManager;
2247
2237
  exports.Generator = Generator;
2248
2238
  exports.PackageManager = PackageManager;
2249
- exports.ParallelPluginError = ParallelPluginError;
2250
- exports.PluginError = PluginError;
2251
2239
  exports.PluginManager = PluginManager;
2252
2240
  exports.PromiseManager = PromiseManager;
2253
2241
  exports.SchemaGenerator = SchemaGenerator;
2254
- exports.SummaryError = SummaryError;
2255
2242
  exports.ValidationPluginError = ValidationPluginError;
2256
2243
  exports.Warning = Warning;
2257
2244
  exports.build = build;
@@ -2263,5 +2250,6 @@ exports.defineConfig = defineConfig;
2263
2250
  exports.isInputPath = isInputPath;
2264
2251
  exports.name = pluginName;
2265
2252
  exports.pluginName = pluginName;
2253
+ exports.safeBuild = safeBuild;
2266
2254
  //# sourceMappingURL=out.js.map
2267
2255
  //# sourceMappingURL=index.cjs.map