@kubb/core 2.0.0-alpha.9 → 2.0.0-beta.2

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
@@ -18,7 +18,7 @@
18
18
  </p>
19
19
 
20
20
  <h4>
21
- <a href="https://codesandbox.io/s/github/kubb-project/kubb/tree/main/examples/typescript" target="_blank">View Demo</a>
21
+ <a href="https://codesandbox.io/s/github/kubb-project/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a>
22
22
  <span> · </span>
23
23
  <a href="https://kubb.dev/" target="_blank">Documentation</a>
24
24
  <span> · </span>
package/dist/index.cjs CHANGED
@@ -1169,8 +1169,7 @@ var definePlugin = createPlugin((options) => {
1169
1169
  return {
1170
1170
  name: pluginName,
1171
1171
  options,
1172
- key: ["controller", "core"],
1173
- kind: "controller",
1172
+ key: ["core"],
1174
1173
  api() {
1175
1174
  return {
1176
1175
  get config() {
@@ -1237,6 +1236,9 @@ function hookFirst(promises, nullCheck = (state) => state !== null) {
1237
1236
  }
1238
1237
  return promise;
1239
1238
  }
1239
+ function hookParallel(promises) {
1240
+ return Promise.allSettled(promises.filter(Boolean).map((promise) => promise()));
1241
+ }
1240
1242
 
1241
1243
  // src/PromiseManager.ts
1242
1244
  var _options2;
@@ -1253,6 +1255,9 @@ var PromiseManager = class {
1253
1255
  if (strategy === "first") {
1254
1256
  return hookFirst(promises, __privateGet(this, _options2).nullCheck);
1255
1257
  }
1258
+ if (strategy === "parallel") {
1259
+ return hookParallel(promises);
1260
+ }
1256
1261
  throw new Error(`${strategy} not implemented`);
1257
1262
  }
1258
1263
  };
@@ -1457,14 +1462,10 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1457
1462
  hookName,
1458
1463
  parameters
1459
1464
  }) {
1460
- const parallelPromises = [];
1461
- for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1462
- const promise = __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
1463
- if (promise) {
1464
- parallelPromises.push(promise);
1465
- }
1466
- }
1467
- const results = await Promise.allSettled(parallelPromises);
1465
+ const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
1466
+ return () => __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
1467
+ });
1468
+ const results = await __privateGet(this, _promiseManager).run("parallel", promises);
1468
1469
  results.forEach((result, index) => {
1469
1470
  if (isPromiseRejectedResult(result)) {
1470
1471
  const plugin = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)[index];
@@ -1512,16 +1513,15 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1512
1513
  }
1513
1514
  getPluginsByKey(hookName, pluginKey) {
1514
1515
  const plugins = [...this.plugins];
1515
- const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
1516
+ const [searchPluginName, searchIdentifier] = pluginKey;
1516
1517
  const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
1517
- const [kind, name, identifier] = item.key;
1518
+ const [name, identifier] = item.key;
1518
1519
  const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
1519
- const kindCheck = kind === searchKind;
1520
1520
  const nameCheck = name === searchPluginName;
1521
1521
  if (searchIdentifier) {
1522
- return identifierCheck && kindCheck && nameCheck;
1522
+ return identifierCheck && nameCheck;
1523
1523
  }
1524
- return kindCheck && nameCheck;
1524
+ return nameCheck;
1525
1525
  });
1526
1526
  if (!pluginByPluginName?.length) {
1527
1527
  const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
@@ -1553,7 +1553,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1553
1553
  }
1554
1554
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1555
1555
  static get hooks() {
1556
- return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
1556
+ return ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
1557
1557
  }
1558
1558
  };
1559
1559
  _core = new WeakMap();
@@ -1571,7 +1571,23 @@ getSortedPlugins_fn = function(hookName) {
1571
1571
  }
1572
1572
  return plugins.filter((item) => item[hookName]);
1573
1573
  }
1574
- return plugins;
1574
+ return plugins.map((plugin) => {
1575
+ if (plugin.pre) {
1576
+ const isValid = plugin.pre.every((pluginName2) => plugins.find((pluginToFind) => pluginToFind.name === pluginName2));
1577
+ if (!isValid) {
1578
+ throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
1579
+ }
1580
+ }
1581
+ return plugin;
1582
+ }).sort((a, b) => {
1583
+ if (b.pre?.includes(a.name)) {
1584
+ return 1;
1585
+ }
1586
+ if (b.post?.includes(a.name)) {
1587
+ return -1;
1588
+ }
1589
+ return 0;
1590
+ });
1575
1591
  };
1576
1592
  _addExecutedToCallStack = new WeakSet();
1577
1593
  addExecutedToCallStack_fn = function(executer) {
@@ -1662,7 +1678,7 @@ _parse = new WeakSet();
1662
1678
  parse_fn = function(plugin, pluginManager, context) {
1663
1679
  const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
1664
1680
  setUniqueName(plugin.name, usedPluginNames);
1665
- const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
1681
+ const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
1666
1682
  if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
1667
1683
  pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
1668
1684
  }
@@ -1785,10 +1801,6 @@ ${code}`);
1785
1801
  async function build(options) {
1786
1802
  const pluginManager = await setup(options);
1787
1803
  const { fileManager, logger } = pluginManager;
1788
- await pluginManager.hookParallel({
1789
- hookName: "validate",
1790
- parameters: [pluginManager.plugins]
1791
- });
1792
1804
  await pluginManager.hookParallel({
1793
1805
  hookName: "buildStart",
1794
1806
  parameters: [options.config]
@@ -1804,10 +1816,6 @@ async function safeBuild(options) {
1804
1816
  const pluginManager = await setup(options);
1805
1817
  const { fileManager, logger } = pluginManager;
1806
1818
  try {
1807
- await pluginManager.hookParallel({
1808
- hookName: "validate",
1809
- parameters: [pluginManager.plugins]
1810
- });
1811
1819
  await pluginManager.hookParallel({
1812
1820
  hookName: "buildStart",
1813
1821
  parameters: [options.config]