@kubb/core 1.12.0 → 1.13.0-canary.20231018T144635

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/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var pc3 = require('picocolors');
6
6
  var crypto = require('crypto');
7
- var pathParser2 = require('path');
7
+ var path2 = require('path');
8
8
  var fs = require('fs-extra');
9
9
  var jsRuntime = require('js-runtime');
10
10
  var perf_hooks = require('perf_hooks');
@@ -18,20 +18,31 @@ var naturalOrderby = require('natural-orderby');
18
18
  var parser = require('@kubb/parser');
19
19
  var isEqual = require('lodash.isequal');
20
20
  var events = require('events');
21
+ var process2 = require('process');
22
+ var fs3 = require('fs');
23
+ var semver = require('semver');
21
24
 
22
25
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
23
26
 
24
27
  var pc3__default = /*#__PURE__*/_interopDefault(pc3);
25
28
  var crypto__default = /*#__PURE__*/_interopDefault(crypto);
26
- var pathParser2__default = /*#__PURE__*/_interopDefault(pathParser2);
29
+ var path2__default = /*#__PURE__*/_interopDefault(path2);
27
30
  var fs__default = /*#__PURE__*/_interopDefault(fs);
28
31
  var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
29
32
  var mod__default = /*#__PURE__*/_interopDefault(mod);
30
33
  var os__default = /*#__PURE__*/_interopDefault(os);
31
34
  var seedrandom__default = /*#__PURE__*/_interopDefault(seedrandom);
32
35
  var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
36
+ var process2__default = /*#__PURE__*/_interopDefault(process2);
37
+ var fs3__default = /*#__PURE__*/_interopDefault(fs3);
33
38
 
34
- // src/build.ts
39
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
40
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
41
+ }) : x)(function(x) {
42
+ if (typeof require !== "undefined")
43
+ return require.apply(this, arguments);
44
+ throw Error('Dynamic require of "' + x + '" is not supported');
45
+ });
35
46
 
36
47
  // src/utils/isPromise.ts
37
48
  function isPromise(result) {
@@ -43,37 +54,37 @@ function isPromiseFulfilledResult(result) {
43
54
  function isPromiseRejectedResult(result) {
44
55
  return result.status === "rejected";
45
56
  }
46
- async function saveCreateDirectory(path) {
47
- const passedPath = pathParser2__default.default.dirname(pathParser2__default.default.resolve(path));
57
+ async function saveCreateDirectory(path3) {
58
+ const passedPath = path2__default.default.dirname(path2__default.default.resolve(path3));
48
59
  await fs__default.default.mkdir(passedPath, { recursive: true });
49
60
  }
50
61
  var writer = jsRuntime.switcher(
51
62
  {
52
- node: async (path, data) => {
63
+ node: async (path3, data) => {
53
64
  try {
54
- await fs__default.default.stat(path);
55
- const oldContent = await fs__default.default.readFile(path, { encoding: "utf-8" });
65
+ await fs__default.default.stat(path3);
66
+ const oldContent = await fs__default.default.readFile(path3, { encoding: "utf-8" });
56
67
  if (oldContent?.toString() === data) {
57
68
  return;
58
69
  }
59
70
  } catch (_err) {
60
71
  }
61
- await saveCreateDirectory(path);
62
- return fs__default.default.writeFile(pathParser2__default.default.resolve(path), data, { encoding: "utf-8" });
72
+ await saveCreateDirectory(path3);
73
+ return fs__default.default.writeFile(path2__default.default.resolve(path3), data, { encoding: "utf-8" });
63
74
  },
64
- bun: async (path, data) => {
75
+ bun: async (path3, data) => {
65
76
  try {
66
- await saveCreateDirectory(path);
67
- await Bun.write(pathParser2__default.default.resolve(path), data);
77
+ await saveCreateDirectory(path3);
78
+ await Bun.write(path2__default.default.resolve(path3), data);
68
79
  } catch (e) {
69
- console.log(e, pathParser2__default.default.resolve(path));
80
+ console.log(e, path2__default.default.resolve(path3));
70
81
  }
71
82
  }
72
83
  },
73
84
  "node"
74
85
  );
75
- async function write(data, path) {
76
- return writer(path, data);
86
+ async function write(data, path3) {
87
+ return writer(path3, data);
77
88
  }
78
89
 
79
90
  // src/utils/cache.ts
@@ -103,37 +114,37 @@ function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
103
114
  }
104
115
  };
105
116
  }
106
- function slash(path, platform = "linux") {
107
- const isWindowsPath = /^\\\\\?\\/.test(path);
117
+ function slash(path3, platform = "linux") {
118
+ const isWindowsPath = /^\\\\\?\\/.test(path3);
108
119
  if (["linux", "mac"].includes(platform) && !isWindowsPath) {
109
- return path.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
120
+ return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
110
121
  }
111
- return path.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
122
+ return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
112
123
  }
113
124
  function getRelativePath(rootDir, filePath, platform = "linux") {
114
125
  if (!rootDir || !filePath) {
115
126
  throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
116
127
  }
117
- const relativePath = pathParser2__default.default.relative(rootDir, filePath);
118
- const path = slash(relativePath, platform);
119
- if (path.startsWith("../")) {
120
- return path.replace(pathParser2__default.default.basename(path), pathParser2__default.default.basename(path, pathParser2__default.default.extname(filePath)));
128
+ const relativePath = path2__default.default.relative(rootDir, filePath);
129
+ const path3 = slash(relativePath, platform);
130
+ if (path3.startsWith("../")) {
131
+ return path3.replace(path2__default.default.basename(path3), path2__default.default.basename(path3, path2__default.default.extname(filePath)));
121
132
  }
122
- return `./${path.replace(pathParser2__default.default.basename(path), pathParser2__default.default.basename(path, pathParser2__default.default.extname(filePath)))}`;
133
+ return `./${path3.replace(path2__default.default.basename(path3), path2__default.default.basename(path3, path2__default.default.extname(filePath)))}`;
123
134
  }
124
- function getPathMode(path) {
125
- if (!path) {
135
+ function getPathMode(path3) {
136
+ if (!path3) {
126
137
  return "directory";
127
138
  }
128
- return pathParser2__default.default.extname(path) ? "file" : "directory";
139
+ return path2__default.default.extname(path3) ? "file" : "directory";
129
140
  }
130
141
  var reader = jsRuntime.switcher(
131
142
  {
132
- node: async (path) => {
133
- return fs__default.default.readFile(path, { encoding: "utf8" });
143
+ node: async (path3) => {
144
+ return fs__default.default.readFile(path3, { encoding: "utf8" });
134
145
  },
135
- bun: async (path) => {
136
- const file = Bun.file(path);
146
+ bun: async (path3) => {
147
+ const file = Bun.file(path3);
137
148
  return file.text();
138
149
  }
139
150
  },
@@ -141,8 +152,8 @@ var reader = jsRuntime.switcher(
141
152
  );
142
153
  var syncReader = jsRuntime.switcher(
143
154
  {
144
- node: (path) => {
145
- return fs__default.default.readFileSync(path, { encoding: "utf8" });
155
+ node: (path3) => {
156
+ return fs__default.default.readFileSync(path3, { encoding: "utf8" });
146
157
  },
147
158
  bun: () => {
148
159
  throw new Error("Bun cannot read sync");
@@ -150,11 +161,11 @@ var syncReader = jsRuntime.switcher(
150
161
  },
151
162
  "node"
152
163
  );
153
- async function read(path) {
154
- return reader(path);
164
+ async function read(path3) {
165
+ return reader(path3);
155
166
  }
156
- function readSync(path) {
157
- return syncReader(path);
167
+ function readSync(path3) {
168
+ return syncReader(path3);
158
169
  }
159
170
 
160
171
  // src/utils/nameSorter.ts
@@ -403,8 +414,8 @@ function renderTemplate(template, data = void 0) {
403
414
  }).trim();
404
415
  }, template) || "";
405
416
  }
406
- async function clean(path) {
407
- return fs.remove(path);
417
+ async function clean(path3) {
418
+ return fs.remove(path3);
408
419
  }
409
420
  var TreeNode = class _TreeNode {
410
421
  data;
@@ -470,10 +481,10 @@ var TreeNode = class _TreeNode {
470
481
  }
471
482
  return this;
472
483
  }
473
- static build(path, options = {}) {
484
+ static build(path3, options = {}) {
474
485
  try {
475
486
  const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
476
- const filteredTree = dirTree__default.default(path, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
487
+ const filteredTree = dirTree__default.default(path3, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
477
488
  if (!filteredTree) {
478
489
  return null;
479
490
  }
@@ -503,17 +514,17 @@ function normalizeDirectory(directory) {
503
514
  }
504
515
  return directory;
505
516
  }
506
- function getLocation(path, cwd) {
507
- let location = path;
517
+ function getLocation(path3, cwd) {
518
+ let location = path3;
508
519
  if (cwd) {
509
520
  const require2 = mod__default.default.createRequire(normalizeDirectory(cwd));
510
- location = require2.resolve(path);
521
+ location = require2.resolve(path3);
511
522
  }
512
523
  return location;
513
524
  }
514
- async function importModule(path, cwd) {
525
+ async function importModule(path3, cwd) {
515
526
  try {
516
- let location = getLocation(path, cwd);
527
+ let location = getLocation(path3, cwd);
517
528
  if (os__default.default.platform() == "win32") {
518
529
  location = url.pathToFileURL(location).href;
519
530
  }
@@ -632,8 +643,8 @@ function randomPicoColour(text, colors = defaultColours) {
632
643
  }
633
644
  var URLPath = class _URLPath {
634
645
  path;
635
- constructor(path) {
636
- this.path = path;
646
+ constructor(path3) {
647
+ this.path = path3;
637
648
  }
638
649
  /**
639
650
  * Convert Swagger path to URLPath(syntax of Express)
@@ -678,25 +689,25 @@ var URLPath = class _URLPath {
678
689
  * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
679
690
  * @example /account/userID => `/account/${userId}`
680
691
  */
681
- static toTemplateString(path, replacer) {
692
+ static toTemplateString(path3, replacer) {
682
693
  const regex = /{(\w|-)*}/g;
683
- const found = path.match(regex);
684
- let newPath = path.replaceAll("{", "${");
694
+ const found = path3.match(regex);
695
+ let newPath = path3.replaceAll("{", "${");
685
696
  if (found) {
686
697
  newPath = found.reduce((prev, curr) => {
687
698
  const pathParam = replacer ? replacer(changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
688
699
  const replacement = `\${${pathParam}}`;
689
700
  return prev.replace(curr, replacement);
690
- }, path);
701
+ }, path3);
691
702
  }
692
703
  return `\`${newPath}\``;
693
704
  }
694
705
  getParams(replacer) {
695
706
  return _URLPath.getParams(this.path, replacer);
696
707
  }
697
- static getParams(path, replacer) {
708
+ static getParams(path3, replacer) {
698
709
  const regex = /{(\w|-)*}/g;
699
- const found = path.match(regex);
710
+ const found = path3.match(regex);
700
711
  if (!found) {
701
712
  return void 0;
702
713
  }
@@ -705,7 +716,7 @@ var URLPath = class _URLPath {
705
716
  item = item.replaceAll("{", "").replaceAll("}", "");
706
717
  const pathParam = replacer ? replacer(changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
707
718
  params[pathParam] = pathParam;
708
- }, path);
719
+ }, path3);
709
720
  return params;
710
721
  }
711
722
  /**
@@ -715,13 +726,13 @@ var URLPath = class _URLPath {
715
726
  toURLPath() {
716
727
  return _URLPath.toURLPath(this.path);
717
728
  }
718
- static toURLPath(path) {
719
- return path.replaceAll("{", ":").replaceAll("}", "");
729
+ static toURLPath(path3) {
730
+ return path3.replaceAll("{", ":").replaceAll("}", "");
720
731
  }
721
- static toObject(path, { type = "path", replacer, stringify } = {}) {
732
+ static toObject(path3, { type = "path", replacer, stringify } = {}) {
722
733
  const object = {
723
- url: type === "path" ? _URLPath.toURLPath(path) : _URLPath.toTemplateString(path, replacer),
724
- params: _URLPath.getParams(path)
734
+ url: type === "path" ? _URLPath.toURLPath(path3) : _URLPath.toTemplateString(path3, replacer),
735
+ params: _URLPath.getParams(path3)
725
736
  };
726
737
  if (stringify) {
727
738
  if (type !== "template") {
@@ -731,9 +742,9 @@ var URLPath = class _URLPath {
731
742
  }
732
743
  return object;
733
744
  }
734
- static isURL(path) {
745
+ static isURL(path3) {
735
746
  try {
736
- const url = new URL(path);
747
+ const url = new URL(path3);
737
748
  if (url?.href) {
738
749
  return true;
739
750
  }
@@ -792,29 +803,29 @@ function getIndexes(root, options = {}) {
792
803
  return [];
793
804
  }
794
805
  if (currentTree.children?.length > 1) {
795
- const path = pathParser2__default.default.resolve(currentTree.data.path, "index.ts");
806
+ const path3 = path2__default.default.resolve(currentTree.data.path, "index.ts");
796
807
  const exports = currentTree.children.map((file) => {
797
808
  if (!file) {
798
809
  return void 0;
799
810
  }
800
811
  const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
801
- if (importPath.includes("index") && path.includes("index")) {
812
+ if (importPath.includes("index") && path3.includes("index")) {
802
813
  return void 0;
803
814
  }
804
815
  return { path: importPath };
805
816
  }).filter(Boolean);
806
817
  files2.push({
807
- path,
818
+ path: path3,
808
819
  baseName: "index.ts",
809
820
  source: "",
810
821
  exports
811
822
  });
812
823
  } else {
813
824
  currentTree.children?.forEach((child) => {
814
- const path = pathParser2__default.default.resolve(currentTree.data.path, "index.ts");
825
+ const path3 = path2__default.default.resolve(currentTree.data.path, "index.ts");
815
826
  const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
816
827
  files2.push({
817
- path,
828
+ path: path3,
818
829
  baseName: "index.ts",
819
830
  source: "",
820
831
  exports: [{ path: importPath }]
@@ -1032,9 +1043,9 @@ ${file.source}` : "",
1032
1043
  }
1033
1044
  return this.add(file);
1034
1045
  }
1035
- append(path, file) {
1036
- const previousFiles = this.cache.get(path) || [];
1037
- this.cache.set(path, [...previousFiles, file]);
1046
+ append(path3, file) {
1047
+ const previousFiles = this.cache.get(path3) || [];
1048
+ this.cache.set(path3, [...previousFiles, file]);
1038
1049
  }
1039
1050
  getCacheByUUID(UUID) {
1040
1051
  let cache;
@@ -1043,15 +1054,15 @@ ${file.source}` : "",
1043
1054
  });
1044
1055
  return cache;
1045
1056
  }
1046
- get(path) {
1047
- return this.cache.get(path);
1057
+ get(path3) {
1058
+ return this.cache.get(path3);
1048
1059
  }
1049
- remove(path) {
1050
- const cacheItem = this.get(path);
1060
+ remove(path3) {
1061
+ const cacheItem = this.get(path3);
1051
1062
  if (!cacheItem) {
1052
1063
  return;
1053
1064
  }
1054
- this.cache.delete(path);
1065
+ this.cache.delete(path3);
1055
1066
  }
1056
1067
  async write(...params) {
1057
1068
  if (this.queue) {
@@ -1117,8 +1128,8 @@ var definePlugin = createPlugin((options) => {
1117
1128
  };
1118
1129
  },
1119
1130
  resolvePath(baseName) {
1120
- const root = pathParser2__default.default.resolve(this.config.root, this.config.output.path);
1121
- return pathParser2__default.default.resolve(root, baseName);
1131
+ const root = path2__default.default.resolve(this.config.root, this.config.output.path);
1132
+ return path2__default.default.resolve(root, baseName);
1122
1133
  },
1123
1134
  resolveName(name) {
1124
1135
  return name;
@@ -1591,11 +1602,11 @@ async function build(options) {
1591
1602
  await clean(config.output.path);
1592
1603
  }
1593
1604
  const queueTask = async (file) => {
1594
- const { path } = file;
1605
+ const { path: path3 } = file;
1595
1606
  let code = createFileSource(file);
1596
1607
  const { result: loadedResult } = await pluginManager.hookFirst({
1597
1608
  hookName: "load",
1598
- parameters: [path]
1609
+ parameters: [path3]
1599
1610
  });
1600
1611
  if (loadedResult && isPromise(loadedResult)) {
1601
1612
  code = await loadedResult;
@@ -1606,13 +1617,13 @@ async function build(options) {
1606
1617
  if (code) {
1607
1618
  const transformedCode = await pluginManager.hookReduceArg0({
1608
1619
  hookName: "transform",
1609
- parameters: [code, path],
1620
+ parameters: [code, path3],
1610
1621
  reduce: transformReducer
1611
1622
  });
1612
1623
  if (config.output.write || config.output.write === void 0) {
1613
1624
  await pluginManager.hookParallel({
1614
1625
  hookName: "writeFile",
1615
- parameters: [transformedCode, path]
1626
+ parameters: [transformedCode, path3]
1616
1627
  });
1617
1628
  }
1618
1629
  }
@@ -1655,6 +1666,334 @@ function defineConfig(options) {
1655
1666
  return options;
1656
1667
  }
1657
1668
 
1669
+ // ../../node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
1670
+ var Node = class {
1671
+ value;
1672
+ next;
1673
+ constructor(value) {
1674
+ this.value = value;
1675
+ }
1676
+ };
1677
+ var Queue2 = class {
1678
+ #head;
1679
+ #tail;
1680
+ #size;
1681
+ constructor() {
1682
+ this.clear();
1683
+ }
1684
+ enqueue(value) {
1685
+ const node = new Node(value);
1686
+ if (this.#head) {
1687
+ this.#tail.next = node;
1688
+ this.#tail = node;
1689
+ } else {
1690
+ this.#head = node;
1691
+ this.#tail = node;
1692
+ }
1693
+ this.#size++;
1694
+ }
1695
+ dequeue() {
1696
+ const current = this.#head;
1697
+ if (!current) {
1698
+ return;
1699
+ }
1700
+ this.#head = this.#head.next;
1701
+ this.#size--;
1702
+ return current.value;
1703
+ }
1704
+ clear() {
1705
+ this.#head = void 0;
1706
+ this.#tail = void 0;
1707
+ this.#size = 0;
1708
+ }
1709
+ get size() {
1710
+ return this.#size;
1711
+ }
1712
+ *[Symbol.iterator]() {
1713
+ let current = this.#head;
1714
+ while (current) {
1715
+ yield current.value;
1716
+ current = current.next;
1717
+ }
1718
+ }
1719
+ };
1720
+
1721
+ // ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
1722
+ function pLimit(concurrency) {
1723
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
1724
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
1725
+ }
1726
+ const queue = new Queue2();
1727
+ let activeCount = 0;
1728
+ const next = () => {
1729
+ activeCount--;
1730
+ if (queue.size > 0) {
1731
+ queue.dequeue()();
1732
+ }
1733
+ };
1734
+ const run = async (fn, resolve, args) => {
1735
+ activeCount++;
1736
+ const result = (async () => fn(...args))();
1737
+ resolve(result);
1738
+ try {
1739
+ await result;
1740
+ } catch {
1741
+ }
1742
+ next();
1743
+ };
1744
+ const enqueue = (fn, resolve, args) => {
1745
+ queue.enqueue(run.bind(void 0, fn, resolve, args));
1746
+ (async () => {
1747
+ await Promise.resolve();
1748
+ if (activeCount < concurrency && queue.size > 0) {
1749
+ queue.dequeue()();
1750
+ }
1751
+ })();
1752
+ };
1753
+ const generator = (fn, ...args) => new Promise((resolve) => {
1754
+ enqueue(fn, resolve, args);
1755
+ });
1756
+ Object.defineProperties(generator, {
1757
+ activeCount: {
1758
+ get: () => activeCount
1759
+ },
1760
+ pendingCount: {
1761
+ get: () => queue.size
1762
+ },
1763
+ clearQueue: {
1764
+ value: () => {
1765
+ queue.clear();
1766
+ }
1767
+ }
1768
+ });
1769
+ return generator;
1770
+ }
1771
+
1772
+ // ../../node_modules/.pnpm/p-locate@6.0.0/node_modules/p-locate/index.js
1773
+ var EndError = class extends Error {
1774
+ constructor(value) {
1775
+ super();
1776
+ this.value = value;
1777
+ }
1778
+ };
1779
+ var testElement = async (element, tester) => tester(await element);
1780
+ var finder = async (element) => {
1781
+ const values = await Promise.all(element);
1782
+ if (values[1] === true) {
1783
+ throw new EndError(values[0]);
1784
+ }
1785
+ return false;
1786
+ };
1787
+ async function pLocate(iterable, tester, {
1788
+ concurrency = Number.POSITIVE_INFINITY,
1789
+ preserveOrder = true
1790
+ } = {}) {
1791
+ const limit = pLimit(concurrency);
1792
+ const items = [...iterable].map((element) => [element, limit(testElement, element, tester)]);
1793
+ const checkLimit = pLimit(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
1794
+ try {
1795
+ await Promise.all(items.map((element) => checkLimit(finder, element)));
1796
+ } catch (error) {
1797
+ if (error instanceof EndError) {
1798
+ return error.value;
1799
+ }
1800
+ throw error;
1801
+ }
1802
+ }
1803
+
1804
+ // ../../node_modules/.pnpm/locate-path@7.2.0/node_modules/locate-path/index.js
1805
+ var typeMappings = {
1806
+ directory: "isDirectory",
1807
+ file: "isFile"
1808
+ };
1809
+ function checkType(type) {
1810
+ if (Object.hasOwnProperty.call(typeMappings, type)) {
1811
+ return;
1812
+ }
1813
+ throw new Error(`Invalid type specified: ${type}`);
1814
+ }
1815
+ var matchType = (type, stat) => stat[typeMappings[type]]();
1816
+ var toPath = (urlOrPath) => urlOrPath instanceof URL ? url.fileURLToPath(urlOrPath) : urlOrPath;
1817
+ async function locatePath(paths, {
1818
+ cwd = process2__default.default.cwd(),
1819
+ type = "file",
1820
+ allowSymlinks = true,
1821
+ concurrency,
1822
+ preserveOrder
1823
+ } = {}) {
1824
+ checkType(type);
1825
+ cwd = toPath(cwd);
1826
+ const statFunction = allowSymlinks ? fs3.promises.stat : fs3.promises.lstat;
1827
+ return pLocate(paths, async (path_) => {
1828
+ try {
1829
+ const stat = await statFunction(path2__default.default.resolve(cwd, path_));
1830
+ return matchType(type, stat);
1831
+ } catch {
1832
+ return false;
1833
+ }
1834
+ }, { concurrency, preserveOrder });
1835
+ }
1836
+ function locatePathSync(paths, {
1837
+ cwd = process2__default.default.cwd(),
1838
+ type = "file",
1839
+ allowSymlinks = true
1840
+ } = {}) {
1841
+ checkType(type);
1842
+ cwd = toPath(cwd);
1843
+ const statFunction = allowSymlinks ? fs3__default.default.statSync : fs3__default.default.lstatSync;
1844
+ for (const path_ of paths) {
1845
+ try {
1846
+ const stat = statFunction(path2__default.default.resolve(cwd, path_), {
1847
+ throwIfNoEntry: false
1848
+ });
1849
+ if (!stat) {
1850
+ continue;
1851
+ }
1852
+ if (matchType(type, stat)) {
1853
+ return path_;
1854
+ }
1855
+ } catch {
1856
+ }
1857
+ }
1858
+ }
1859
+
1860
+ // ../../node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
1861
+ var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? url.fileURLToPath(urlOrPath) : urlOrPath;
1862
+ var findUpStop = Symbol("findUpStop");
1863
+ async function findUpMultiple(name, options = {}) {
1864
+ let directory = path2__default.default.resolve(toPath2(options.cwd) || "");
1865
+ const { root } = path2__default.default.parse(directory);
1866
+ const stopAt = path2__default.default.resolve(directory, options.stopAt || root);
1867
+ const limit = options.limit || Number.POSITIVE_INFINITY;
1868
+ const paths = [name].flat();
1869
+ const runMatcher = async (locateOptions) => {
1870
+ if (typeof name !== "function") {
1871
+ return locatePath(paths, locateOptions);
1872
+ }
1873
+ const foundPath = await name(locateOptions.cwd);
1874
+ if (typeof foundPath === "string") {
1875
+ return locatePath([foundPath], locateOptions);
1876
+ }
1877
+ return foundPath;
1878
+ };
1879
+ const matches = [];
1880
+ while (true) {
1881
+ const foundPath = await runMatcher({ ...options, cwd: directory });
1882
+ if (foundPath === findUpStop) {
1883
+ break;
1884
+ }
1885
+ if (foundPath) {
1886
+ matches.push(path2__default.default.resolve(directory, foundPath));
1887
+ }
1888
+ if (directory === stopAt || matches.length >= limit) {
1889
+ break;
1890
+ }
1891
+ directory = path2__default.default.dirname(directory);
1892
+ }
1893
+ return matches;
1894
+ }
1895
+ function findUpMultipleSync(name, options = {}) {
1896
+ let directory = path2__default.default.resolve(toPath2(options.cwd) || "");
1897
+ const { root } = path2__default.default.parse(directory);
1898
+ const stopAt = options.stopAt || root;
1899
+ const limit = options.limit || Number.POSITIVE_INFINITY;
1900
+ const paths = [name].flat();
1901
+ const runMatcher = (locateOptions) => {
1902
+ if (typeof name !== "function") {
1903
+ return locatePathSync(paths, locateOptions);
1904
+ }
1905
+ const foundPath = name(locateOptions.cwd);
1906
+ if (typeof foundPath === "string") {
1907
+ return locatePathSync([foundPath], locateOptions);
1908
+ }
1909
+ return foundPath;
1910
+ };
1911
+ const matches = [];
1912
+ while (true) {
1913
+ const foundPath = runMatcher({ ...options, cwd: directory });
1914
+ if (foundPath === findUpStop) {
1915
+ break;
1916
+ }
1917
+ if (foundPath) {
1918
+ matches.push(path2__default.default.resolve(directory, foundPath));
1919
+ }
1920
+ if (directory === stopAt || matches.length >= limit) {
1921
+ break;
1922
+ }
1923
+ directory = path2__default.default.dirname(directory);
1924
+ }
1925
+ return matches;
1926
+ }
1927
+ async function findUp(name, options = {}) {
1928
+ const matches = await findUpMultiple(name, { ...options, limit: 1 });
1929
+ return matches[0];
1930
+ }
1931
+ function findUpSync(name, options = {}) {
1932
+ const matches = findUpMultipleSync(name, { ...options, limit: 1 });
1933
+ return matches[0];
1934
+ }
1935
+ var PackageManager = class {
1936
+ cwd;
1937
+ constructor(workspace = process.cwd()) {
1938
+ this.cwd = workspace;
1939
+ return this;
1940
+ }
1941
+ async getPackageJSON() {
1942
+ const pkgPath = await findUp(["package.json"], {
1943
+ cwd: this.cwd
1944
+ });
1945
+ if (!pkgPath) {
1946
+ return void 0;
1947
+ }
1948
+ return __require(pkgPath);
1949
+ }
1950
+ getPackageJSONSync() {
1951
+ const pkgPath = findUpSync(["package.json"], {
1952
+ cwd: this.cwd
1953
+ });
1954
+ if (!pkgPath) {
1955
+ return void 0;
1956
+ }
1957
+ return __require(pkgPath);
1958
+ }
1959
+ async getVersion(dependency) {
1960
+ const packageJSON = await this.getPackageJSON();
1961
+ if (!packageJSON) {
1962
+ return void 0;
1963
+ }
1964
+ return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
1965
+ }
1966
+ getVersionSync(dependency) {
1967
+ const packageJSON = this.getPackageJSONSync();
1968
+ if (!packageJSON) {
1969
+ return void 0;
1970
+ }
1971
+ return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
1972
+ }
1973
+ async isValid(dependency, version) {
1974
+ const packageVersion = await this.getVersion(dependency);
1975
+ if (!packageVersion) {
1976
+ return false;
1977
+ }
1978
+ const semVer = semver.coerce(packageVersion);
1979
+ if (!semVer) {
1980
+ throw new Error(`${packageVersion} is not valid`);
1981
+ }
1982
+ return semver.satisfies(semVer, version);
1983
+ }
1984
+ isValidSync(dependency, version) {
1985
+ const packageVersion = this.getVersionSync(dependency);
1986
+ if (!packageVersion) {
1987
+ return false;
1988
+ }
1989
+ const semVer = semver.coerce(packageVersion);
1990
+ if (!semVer) {
1991
+ throw new Error(`${packageVersion} is not valid`);
1992
+ }
1993
+ return semver.satisfies(semVer, version);
1994
+ }
1995
+ };
1996
+
1658
1997
  // src/generators/Generator.ts
1659
1998
  var Generator = class {
1660
1999
  _options = {};
@@ -1687,6 +2026,7 @@ exports.FileManager = FileManager;
1687
2026
  exports.FunctionParams = FunctionParams;
1688
2027
  exports.Generator = Generator;
1689
2028
  exports.LogLevel = LogLevel;
2029
+ exports.PackageManager = PackageManager;
1690
2030
  exports.ParallelPluginError = ParallelPluginError;
1691
2031
  exports.PluginError = PluginError;
1692
2032
  exports.PluginManager = PluginManager;