@kubb/core 3.16.2 → 3.16.3

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 (106) hide show
  1. package/dist/FileManager-Dk759iZ3.js +918 -0
  2. package/dist/FileManager-Dk759iZ3.js.map +1 -0
  3. package/dist/FileManager-DsRjYJa_.cjs +1031 -0
  4. package/dist/FileManager-DsRjYJa_.cjs.map +1 -0
  5. package/dist/PluginManager-1jPxuyQK.d.ts +511 -0
  6. package/dist/PluginManager-Cvj5AlsU.d.cts +511 -0
  7. package/dist/chunk-DWy1uDak.cjs +39 -0
  8. package/dist/chunk-DbvY3SJr.js +33 -0
  9. package/dist/fs-BacxV1CO.js +87 -0
  10. package/dist/fs-BacxV1CO.js.map +1 -0
  11. package/dist/fs-BazSaf2y.cjs +129 -0
  12. package/dist/fs-BazSaf2y.cjs.map +1 -0
  13. package/dist/fs.cjs +15 -39
  14. package/dist/fs.d.cts +2 -19
  15. package/dist/fs.d.ts +2 -19
  16. package/dist/fs.js +4 -3
  17. package/dist/index-BKHQGQVq.d.ts +140 -0
  18. package/dist/index-BfD6z1P5.d.cts +141 -0
  19. package/dist/index-Cb4pChs8.d.ts +180 -0
  20. package/dist/index-D2ptHzfn.d.cts +180 -0
  21. package/dist/index.cjs +997 -1077
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +107 -89
  24. package/dist/index.d.ts +107 -89
  25. package/dist/index.js +1020 -864
  26. package/dist/index.js.map +1 -1
  27. package/dist/logger-BxvJpQMX.cjs +1115 -0
  28. package/dist/logger-BxvJpQMX.cjs.map +1 -0
  29. package/dist/logger-Cs45J4yy.js +1085 -0
  30. package/dist/logger-Cs45J4yy.js.map +1 -0
  31. package/dist/logger-OWS6fqk0.d.cts +69 -0
  32. package/dist/logger-xcdTETKy.d.ts +69 -0
  33. package/dist/logger.cjs +6 -24
  34. package/dist/logger.d.cts +2 -3
  35. package/dist/logger.d.ts +2 -3
  36. package/dist/logger.js +4 -4
  37. package/dist/mocks.cjs +49 -65
  38. package/dist/mocks.cjs.map +1 -1
  39. package/dist/mocks.d.cts +6 -6
  40. package/dist/mocks.d.ts +6 -6
  41. package/dist/mocks.js +48 -59
  42. package/dist/mocks.js.map +1 -1
  43. package/dist/prompt-DwEAzq0q.js +853 -0
  44. package/dist/prompt-DwEAzq0q.js.map +1 -0
  45. package/dist/prompt-qiwl6Be9.cjs +855 -0
  46. package/dist/prompt-qiwl6Be9.cjs.map +1 -0
  47. package/dist/transformers-B3CHtwuB.cjs +948 -0
  48. package/dist/transformers-B3CHtwuB.cjs.map +1 -0
  49. package/dist/transformers-CJqBQFIl.js +829 -0
  50. package/dist/transformers-CJqBQFIl.js.map +1 -0
  51. package/dist/transformers.cjs +33 -88
  52. package/dist/transformers.d.cts +75 -54
  53. package/dist/transformers.d.ts +75 -54
  54. package/dist/transformers.js +4 -3
  55. package/dist/utils.cjs +20 -73
  56. package/dist/utils.d.cts +5 -126
  57. package/dist/utils.d.ts +5 -126
  58. package/dist/utils.js +6 -5
  59. package/dist/write-CLTPlucv.js +42 -0
  60. package/dist/write-CLTPlucv.js.map +1 -0
  61. package/dist/write-l_NzIqyy.cjs +48 -0
  62. package/dist/write-l_NzIqyy.cjs.map +1 -0
  63. package/package.json +25 -32
  64. package/src/BarrelManager.ts +1 -0
  65. package/src/PromiseManager.ts +1 -7
  66. package/src/build.ts +9 -11
  67. package/src/index.ts +5 -5
  68. package/src/logger.ts +10 -10
  69. package/src/utils/FunctionParams.ts +3 -1
  70. package/src/utils/TreeNode.ts +3 -1
  71. package/dist/PluginManager-E3SghPP9.d.cts +0 -458
  72. package/dist/PluginManager-PDmRCu9k.d.ts +0 -458
  73. package/dist/chunk-4V7HK7PT.js +0 -1199
  74. package/dist/chunk-4V7HK7PT.js.map +0 -1
  75. package/dist/chunk-BHSTNFNQ.cjs +0 -701
  76. package/dist/chunk-BHSTNFNQ.cjs.map +0 -1
  77. package/dist/chunk-CAZ37TGB.js +0 -918
  78. package/dist/chunk-CAZ37TGB.js.map +0 -1
  79. package/dist/chunk-E4XLCCPK.cjs +0 -170
  80. package/dist/chunk-E4XLCCPK.cjs.map +0 -1
  81. package/dist/chunk-GBYHPDPK.js +0 -595
  82. package/dist/chunk-GBYHPDPK.js.map +0 -1
  83. package/dist/chunk-L3A3DTAX.cjs +0 -1074
  84. package/dist/chunk-L3A3DTAX.cjs.map +0 -1
  85. package/dist/chunk-MCNA6SYG.cjs +0 -1231
  86. package/dist/chunk-MCNA6SYG.cjs.map +0 -1
  87. package/dist/chunk-YRPOID7E.js +0 -157
  88. package/dist/chunk-YRPOID7E.js.map +0 -1
  89. package/dist/fs.cjs.map +0 -1
  90. package/dist/fs.js.map +0 -1
  91. package/dist/logger-BWq-oJU_.d.cts +0 -63
  92. package/dist/logger-BWq-oJU_.d.ts +0 -63
  93. package/dist/logger.cjs.map +0 -1
  94. package/dist/logger.js.map +0 -1
  95. package/dist/parser-C1vOjVEd.d.ts +0 -41
  96. package/dist/parser-D6vU1kA9.d.cts +0 -41
  97. package/dist/prompt-ELTHGQK6.js +0 -753
  98. package/dist/prompt-ELTHGQK6.js.map +0 -1
  99. package/dist/prompt-U7M5G25C.cjs +0 -761
  100. package/dist/prompt-U7M5G25C.cjs.map +0 -1
  101. package/dist/transformers.cjs.map +0 -1
  102. package/dist/transformers.js.map +0 -1
  103. package/dist/types-CA8nQKwM.d.cts +0 -132
  104. package/dist/types-CA8nQKwM.d.ts +0 -132
  105. package/dist/utils.cjs.map +0 -1
  106. package/dist/utils.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,894 +1,1050 @@
1
- import { EventEmitter, createLogger, consola, colors } from './chunk-4V7HK7PT.js';
2
- import { FileManager, setUniqueName, URLPath } from './chunk-CAZ37TGB.js';
3
- export { FileManager, getDefaultBanner, getSource } from './chunk-CAZ37TGB.js';
4
- import { trim, transformReservedWord } from './chunk-GBYHPDPK.js';
5
- import { exists, clean, getRelativePath, read, readSync } from './chunk-YRPOID7E.js';
6
- import pLimit from 'p-limit';
7
- import path, { join, resolve } from 'path';
8
- import { isDeepEqual } from 'remeda';
9
- import mod from 'module';
10
- import os from 'os';
11
- import { pathToFileURL } from 'url';
12
- import { findUp, findUpSync } from 'find-up';
13
- import { coerce, satisfies } from 'semver';
1
+ import { clean, exists, getRelativePath, read, readSync } from "./fs-BacxV1CO.js";
2
+ import "./write-CLTPlucv.js";
3
+ import { EventEmitter, createLogger } from "./logger-Cs45J4yy.js";
4
+ import { transformReservedWord, trim } from "./transformers-CJqBQFIl.js";
5
+ import { FileManager, URLPath, getDefaultBanner, getSource, pLimit, setUniqueName } from "./FileManager-Dk759iZ3.js";
6
+ import mod from "node:module";
7
+ import path, { join, resolve } from "node:path";
8
+ import pc from "picocolors";
9
+ import { isDeepEqual } from "remeda";
10
+ import g$1 from "node:process";
11
+ import os from "node:os";
12
+ import { fileURLToPath, pathToFileURL } from "node:url";
13
+ import fs, { promises } from "node:fs";
14
+ import { coerce, satisfies } from "semver";
14
15
 
15
- function hookSeq(promises) {
16
- return promises.filter(Boolean).reduce(
17
- (promise, func) => {
18
- if (typeof func !== "function") {
19
- throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
20
- }
21
- return promise.then((state) => {
22
- const calledFunc = func(state);
23
- if (calledFunc) {
24
- return calledFunc.then(Array.prototype.concat.bind(state));
25
- }
26
- });
27
- },
28
- Promise.resolve([])
29
- );
16
+ //#region src/BaseGenerator.ts
17
+ /**
18
+ * Abstract class that contains the building blocks for plugins to create their own Generator
19
+ * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
20
+ */
21
+ var BaseGenerator = class {
22
+ #options = {};
23
+ #context = {};
24
+ constructor(options, context) {
25
+ if (context) this.#context = context;
26
+ if (options) this.#options = options;
27
+ return this;
28
+ }
29
+ get options() {
30
+ return this.#options;
31
+ }
32
+ get context() {
33
+ return this.#context;
34
+ }
35
+ set options(options) {
36
+ this.#options = {
37
+ ...this.#options,
38
+ ...options
39
+ };
40
+ }
41
+ };
42
+
43
+ //#endregion
44
+ //#region src/config.ts
45
+ /**
46
+ * Type helper to make it easier to use vite.config.ts accepts a direct UserConfig object, or a function that returns it. The function receives a ConfigEnv object.
47
+ */
48
+ function defineConfig(options) {
49
+ return options;
30
50
  }
31
- function hookFirst(promises, nullCheck = (state) => state !== null) {
32
- let promise = Promise.resolve(null);
33
- for (const func of promises.filter(Boolean)) {
34
- promise = promise.then((state) => {
35
- if (nullCheck(state)) {
36
- return state;
37
- }
38
- return func(state);
39
- });
40
- }
41
- return promise;
51
+ function isInputPath(result) {
52
+ return !!result && "path" in result?.input;
42
53
  }
43
- function hookParallel(promises, concurrency = Number.POSITIVE_INFINITY) {
44
- const limit = pLimit(concurrency);
45
- const tasks = promises.filter(Boolean).map((promise) => limit(() => promise()));
46
- return Promise.allSettled(tasks);
54
+
55
+ //#endregion
56
+ //#region src/utils/executeStrategies.ts
57
+ /**
58
+ * Chains promises
59
+ */
60
+ function hookSeq(promises$1) {
61
+ return promises$1.filter(Boolean).reduce((promise, func) => {
62
+ if (typeof func !== "function") throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
63
+ return promise.then((state) => {
64
+ const calledFunc = func(state);
65
+ if (calledFunc) return calledFunc.then(Array.prototype.concat.bind(state));
66
+ });
67
+ }, Promise.resolve([]));
68
+ }
69
+ /**
70
+ * Chains promises, first non-null result stops and returns
71
+ */
72
+ function hookFirst(promises$1, nullCheck = (state) => state !== null) {
73
+ let promise = Promise.resolve(null);
74
+ for (const func of promises$1.filter(Boolean)) promise = promise.then((state) => {
75
+ if (nullCheck(state)) return state;
76
+ return func(state);
77
+ });
78
+ return promise;
79
+ }
80
+ /**
81
+ * Runs an array of promise functions with optional concurrency limit.
82
+ */
83
+ function hookParallel(promises$1, concurrency = Number.POSITIVE_INFINITY) {
84
+ const limit = pLimit(concurrency);
85
+ const tasks = promises$1.filter(Boolean).map((promise) => limit(() => promise()));
86
+ return Promise.allSettled(tasks);
47
87
  }
48
88
 
49
- // src/PromiseManager.ts
89
+ //#endregion
90
+ //#region src/PromiseManager.ts
50
91
  var PromiseManager = class {
51
- #options = {};
52
- constructor(options = {}) {
53
- this.#options = options;
54
- return this;
55
- }
56
- run(strategy, promises, { concurrency = Number.POSITIVE_INFINITY } = {}) {
57
- if (strategy === "seq") {
58
- return hookSeq(promises);
59
- }
60
- if (strategy === "first") {
61
- return hookFirst(promises, this.#options.nullCheck);
62
- }
63
- if (strategy === "parallel") {
64
- return hookParallel(promises, concurrency);
65
- }
66
- throw new Error(`${strategy} not implemented`);
67
- }
92
+ #options = {};
93
+ constructor(options = {}) {
94
+ this.#options = options;
95
+ return this;
96
+ }
97
+ run(strategy, promises$1, { concurrency = Number.POSITIVE_INFINITY } = {}) {
98
+ if (strategy === "seq") return hookSeq(promises$1);
99
+ if (strategy === "first") return hookFirst(promises$1, this.#options.nullCheck);
100
+ if (strategy === "parallel") return hookParallel(promises$1, concurrency);
101
+ throw new Error(`${strategy} not implemented`);
102
+ }
68
103
  };
69
104
  function isPromiseRejectedResult(result) {
70
- return result.status === "rejected";
105
+ return result.status === "rejected";
71
106
  }
72
107
 
73
- // src/errors.ts
74
- var ValidationPluginError = class extends Error {
75
- };
108
+ //#endregion
109
+ //#region src/errors.ts
110
+ var ValidationPluginError = class extends Error {};
111
+
112
+ //#endregion
113
+ //#region src/plugin.ts
76
114
  function createPlugin(factory) {
77
- return (options = {}) => {
78
- return factory(options);
79
- };
115
+ return (options = {}) => {
116
+ return factory(options);
117
+ };
80
118
  }
81
- var pluginCore = createPlugin((options) => {
82
- const { fileManager, pluginManager, resolvePath, resolveName, logger } = options;
83
- return {
84
- name: "core",
85
- options,
86
- key: ["core"],
87
- context() {
88
- return {
89
- get config() {
90
- return options.config;
91
- },
92
- get plugins() {
93
- return options.getPlugins();
94
- },
95
- get plugin() {
96
- return options.plugin;
97
- },
98
- logger,
99
- fileManager,
100
- pluginManager,
101
- async addFile(...files) {
102
- const resolvedFiles = await fileManager.add(...files);
103
- if (!Array.isArray(resolvedFiles)) {
104
- return [resolvedFiles];
105
- }
106
- return resolvedFiles;
107
- },
108
- resolvePath,
109
- resolveName
110
- };
111
- },
112
- resolvePath(baseName) {
113
- const root = path.resolve(options.config.root, options.config.output.path);
114
- return path.resolve(root, baseName);
115
- },
116
- resolveName(name) {
117
- return name;
118
- }
119
- };
119
+ const pluginCore = createPlugin((options) => {
120
+ const { fileManager, pluginManager, resolvePath, resolveName, logger } = options;
121
+ return {
122
+ name: "core",
123
+ options,
124
+ key: ["core"],
125
+ context() {
126
+ return {
127
+ get config() {
128
+ return options.config;
129
+ },
130
+ get plugins() {
131
+ return options.getPlugins();
132
+ },
133
+ get plugin() {
134
+ return options.plugin;
135
+ },
136
+ logger,
137
+ fileManager,
138
+ pluginManager,
139
+ async addFile(...files) {
140
+ const resolvedFiles = await fileManager.add(...files);
141
+ if (!Array.isArray(resolvedFiles)) return [resolvedFiles];
142
+ return resolvedFiles;
143
+ },
144
+ resolvePath,
145
+ resolveName
146
+ };
147
+ },
148
+ resolvePath(baseName) {
149
+ const root = path.resolve(options.config.root, options.config.output.path);
150
+ return path.resolve(root, baseName);
151
+ },
152
+ resolveName(name) {
153
+ return name;
154
+ }
155
+ };
120
156
  });
121
157
 
122
- // src/PluginManager.ts
158
+ //#endregion
159
+ //#region src/PluginManager.ts
123
160
  var PluginManager = class {
124
- plugins = /* @__PURE__ */ new Set();
125
- fileManager;
126
- events = new EventEmitter();
127
- config;
128
- executed = [];
129
- logger;
130
- options;
131
- #core;
132
- #usedPluginNames = {};
133
- #promiseManager;
134
- constructor(config, options) {
135
- this.config = config;
136
- this.options = options;
137
- this.logger = options.logger;
138
- this.fileManager = new FileManager();
139
- this.#promiseManager = new PromiseManager({
140
- nullCheck: (state) => !!state?.result
141
- });
142
- const core = pluginCore({
143
- config,
144
- logger: this.logger,
145
- pluginManager: this,
146
- fileManager: this.fileManager,
147
- resolvePath: this.resolvePath.bind(this),
148
- resolveName: this.resolveName.bind(this),
149
- getPlugins: this.#getSortedPlugins.bind(this)
150
- });
151
- this.#core = this.#parse(core, this, core.context.call(null));
152
- [this.#core, ...config.plugins || []].forEach((plugin) => {
153
- const parsedPlugin = this.#parse(plugin, this, this.#core.context);
154
- this.plugins.add(parsedPlugin);
155
- });
156
- return this;
157
- }
158
- getFile({ name, mode, extname, pluginKey, options }) {
159
- const baseName = `${name}${extname}`;
160
- const path2 = this.resolvePath({ baseName, mode, pluginKey, options });
161
- if (!path2) {
162
- throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`);
163
- }
164
- return {
165
- path: path2,
166
- baseName,
167
- meta: {
168
- pluginKey
169
- },
170
- sources: []
171
- };
172
- }
173
- resolvePath = (params) => {
174
- if (params.pluginKey) {
175
- const paths = this.hookForPluginSync({
176
- pluginKey: params.pluginKey,
177
- hookName: "resolvePath",
178
- parameters: [params.baseName, params.mode, params.options],
179
- message: `Resolving path '${params.baseName}'`
180
- });
181
- if (paths && paths?.length > 1) {
182
- this.logger.emit("debug", {
183
- date: /* @__PURE__ */ new Date(),
184
- logs: [
185
- `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
161
+ plugins = /* @__PURE__ */ new Set();
162
+ fileManager;
163
+ events = new EventEmitter();
164
+ config;
165
+ executed = [];
166
+ logger;
167
+ options;
168
+ #core;
169
+ #usedPluginNames = {};
170
+ #promiseManager;
171
+ constructor(config, options) {
172
+ this.config = config;
173
+ this.options = options;
174
+ this.logger = options.logger;
175
+ this.fileManager = new FileManager();
176
+ this.#promiseManager = new PromiseManager({ nullCheck: (state) => !!state?.result });
177
+ const core = pluginCore({
178
+ config,
179
+ logger: this.logger,
180
+ pluginManager: this,
181
+ fileManager: this.fileManager,
182
+ resolvePath: this.resolvePath.bind(this),
183
+ resolveName: this.resolveName.bind(this),
184
+ getPlugins: this.#getSortedPlugins.bind(this)
185
+ });
186
+ this.#core = this.#parse(core, this, core.context.call(null));
187
+ [this.#core, ...config.plugins || []].forEach((plugin) => {
188
+ const parsedPlugin = this.#parse(plugin, this, this.#core.context);
189
+ this.plugins.add(parsedPlugin);
190
+ });
191
+ return this;
192
+ }
193
+ getFile({ name, mode, extname: extname$1, pluginKey, options }) {
194
+ const baseName = `${name}${extname$1}`;
195
+ const path$1 = this.resolvePath({
196
+ baseName,
197
+ mode,
198
+ pluginKey,
199
+ options
200
+ });
201
+ if (!path$1) throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`);
202
+ return {
203
+ path: path$1,
204
+ baseName,
205
+ meta: { pluginKey },
206
+ sources: []
207
+ };
208
+ }
209
+ resolvePath = (params) => {
210
+ if (params.pluginKey) {
211
+ const paths = this.hookForPluginSync({
212
+ pluginKey: params.pluginKey,
213
+ hookName: "resolvePath",
214
+ parameters: [
215
+ params.baseName,
216
+ params.mode,
217
+ params.options
218
+ ],
219
+ message: `Resolving path '${params.baseName}'`
220
+ });
221
+ if (paths && paths?.length > 1) this.logger.emit("debug", {
222
+ date: /* @__PURE__ */ new Date(),
223
+ logs: [`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : "\""} is not unique enough\n\nPaths: ${JSON.stringify(paths, void 0, 2)}\n\nFalling back on the first item.\n`]
224
+ });
225
+ return paths?.at(0);
226
+ }
227
+ return this.hookFirstSync({
228
+ hookName: "resolvePath",
229
+ parameters: [
230
+ params.baseName,
231
+ params.mode,
232
+ params.options
233
+ ],
234
+ message: `Resolving path '${params.baseName}'`
235
+ }).result;
236
+ };
237
+ resolveName = (params) => {
238
+ if (params.pluginKey) {
239
+ const names = this.hookForPluginSync({
240
+ pluginKey: params.pluginKey,
241
+ hookName: "resolveName",
242
+ parameters: [trim(params.name), params.type],
243
+ message: `Resolving name '${params.name}' and type '${params.type}'`
244
+ });
245
+ if (names && names?.length > 1) this.logger.emit("debug", {
246
+ date: /* @__PURE__ */ new Date(),
247
+ logs: [`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : "\""} is not unique enough\n\nNames: ${JSON.stringify(names, void 0, 2)}\n\nFalling back on the first item.\n`]
248
+ });
249
+ return transformReservedWord(names?.at(0) || params.name);
250
+ }
251
+ const name = this.hookFirstSync({
252
+ hookName: "resolveName",
253
+ parameters: [trim(params.name), params.type],
254
+ message: `Resolving name '${params.name}' and type '${params.type}'`
255
+ }).result;
256
+ return transformReservedWord(name);
257
+ };
258
+ /**
259
+ * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
260
+ */
261
+ on(eventName, handler) {
262
+ this.events.on(eventName, handler);
263
+ }
264
+ /**
265
+ * Run a specific hookName for plugin x.
266
+ */
267
+ async hookForPlugin({ pluginKey, hookName, parameters, message }) {
268
+ const plugins = this.getPluginsByKey(hookName, pluginKey);
269
+ this.logger.emit("progress_start", {
270
+ id: hookName,
271
+ size: plugins.length,
272
+ message: "Running plugins..."
273
+ });
274
+ const items = [];
275
+ for (const plugin of plugins) {
276
+ const result = await this.#execute({
277
+ strategy: "hookFirst",
278
+ hookName,
279
+ parameters,
280
+ plugin,
281
+ message
282
+ });
283
+ if (result !== void 0 && result !== null) items.push(result);
284
+ }
285
+ this.logger.emit("progress_stop", { id: hookName });
286
+ return items;
287
+ }
288
+ /**
289
+ * Run a specific hookName for plugin x.
290
+ */
291
+ hookForPluginSync({ pluginKey, hookName, parameters, message }) {
292
+ const plugins = this.getPluginsByKey(hookName, pluginKey);
293
+ const result = plugins.map((plugin) => {
294
+ return this.#executeSync({
295
+ strategy: "hookFirst",
296
+ hookName,
297
+ parameters,
298
+ plugin,
299
+ message
300
+ });
301
+ }).filter(Boolean);
302
+ return result;
303
+ }
304
+ /**
305
+ * First non-null result stops and will return it's value.
306
+ */
307
+ async hookFirst({ hookName, parameters, skipped, message }) {
308
+ const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
309
+ return skipped ? skipped.has(plugin) : true;
310
+ });
311
+ this.logger.emit("progress_start", {
312
+ id: hookName,
313
+ size: plugins.length
314
+ });
315
+ const promises$1 = plugins.map((plugin) => {
316
+ return async () => {
317
+ const value = await this.#execute({
318
+ strategy: "hookFirst",
319
+ hookName,
320
+ parameters,
321
+ plugin,
322
+ message
323
+ });
324
+ return Promise.resolve({
325
+ plugin,
326
+ result: value
327
+ });
328
+ };
329
+ });
330
+ const result = await this.#promiseManager.run("first", promises$1);
331
+ this.logger.emit("progress_stop", { id: hookName });
332
+ return result;
333
+ }
334
+ /**
335
+ * First non-null result stops and will return it's value.
336
+ */
337
+ hookFirstSync({ hookName, parameters, skipped, message }) {
338
+ let parseResult = null;
339
+ const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
340
+ return skipped ? skipped.has(plugin) : true;
341
+ });
342
+ for (const plugin of plugins) {
343
+ parseResult = {
344
+ result: this.#executeSync({
345
+ strategy: "hookFirst",
346
+ hookName,
347
+ parameters,
348
+ plugin,
349
+ message
350
+ }),
351
+ plugin
352
+ };
353
+ if (parseResult?.result != null) break;
354
+ }
355
+ return parseResult;
356
+ }
357
+ /**
358
+ * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
359
+ */
360
+ async hookParallel({ hookName, parameters, message }) {
361
+ const plugins = this.#getSortedPlugins(hookName);
362
+ this.logger.emit("progress_start", {
363
+ id: hookName,
364
+ size: plugins.length
365
+ });
366
+ const promises$1 = plugins.map((plugin) => {
367
+ return () => this.#execute({
368
+ strategy: "hookParallel",
369
+ hookName,
370
+ parameters,
371
+ plugin,
372
+ message
373
+ });
374
+ });
375
+ const results = await this.#promiseManager.run("parallel", promises$1, { concurrency: this.options.concurrency });
376
+ results.forEach((result, index) => {
377
+ if (isPromiseRejectedResult(result)) {
378
+ const plugin = this.#getSortedPlugins(hookName)[index];
379
+ this.#catcher(result.reason, plugin, hookName);
380
+ }
381
+ });
382
+ this.logger.emit("progress_stop", { id: hookName });
383
+ return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
384
+ }
385
+ /**
386
+ * Chains plugins
387
+ */
388
+ async hookSeq({ hookName, parameters, message }) {
389
+ const plugins = this.#getSortedPlugins(hookName);
390
+ this.logger.emit("progress_start", {
391
+ id: hookName,
392
+ size: plugins.length
393
+ });
394
+ const promises$1 = plugins.map((plugin) => {
395
+ return () => this.#execute({
396
+ strategy: "hookSeq",
397
+ hookName,
398
+ parameters,
399
+ plugin,
400
+ message
401
+ });
402
+ });
403
+ await this.#promiseManager.run("seq", promises$1);
404
+ this.logger.emit("progress_stop", { id: hookName });
405
+ }
406
+ #getSortedPlugins(hookName) {
407
+ const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
408
+ if (hookName) return plugins.filter((plugin) => hookName in plugin);
409
+ return plugins.map((plugin) => {
410
+ if (plugin.pre) {
411
+ const isValid = plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName));
412
+ if (!isValid) throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
413
+ }
414
+ return plugin;
415
+ }).sort((a, b) => {
416
+ if (b.pre?.includes(a.name)) return 1;
417
+ if (b.post?.includes(a.name)) return -1;
418
+ return 0;
419
+ });
420
+ }
421
+ getPluginByKey(pluginKey) {
422
+ const plugins = [...this.plugins];
423
+ const [searchPluginName] = pluginKey;
424
+ return plugins.find((item) => {
425
+ const [name] = item.key;
426
+ return name === searchPluginName;
427
+ });
428
+ }
429
+ getPluginsByKey(hookName, pluginKey) {
430
+ const plugins = [...this.plugins];
431
+ const [searchPluginName, searchIdentifier] = pluginKey;
432
+ const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => {
433
+ const [name, identifier] = item.key;
434
+ const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
435
+ const nameCheck = name === searchPluginName;
436
+ if (searchIdentifier) return identifierCheck && nameCheck;
437
+ return nameCheck;
438
+ });
439
+ if (!pluginByPluginName?.length) {
440
+ const corePlugin = plugins.find((plugin) => plugin.name === "core" && hookName in plugin);
441
+ if (corePlugin) this.logger.emit("debug", {
442
+ date: /* @__PURE__ */ new Date(),
443
+ logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`]
444
+ });
445
+ else this.logger.emit("debug", {
446
+ date: /* @__PURE__ */ new Date(),
447
+ logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`]
448
+ });
449
+ return corePlugin ? [corePlugin] : [];
450
+ }
451
+ return pluginByPluginName;
452
+ }
453
+ #addExecutedToCallStack(executer) {
454
+ if (executer) {
455
+ this.events.emit("executed", executer);
456
+ this.executed.push(executer);
457
+ this.logger.emit("progressed", {
458
+ id: executer.hookName,
459
+ message: `${executer.plugin.name}: ${executer.message}`
460
+ });
461
+ }
462
+ }
463
+ /**
464
+ * Run an async plugin hook and return the result.
465
+ * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
466
+ * @param args Arguments passed to the plugin hook.
467
+ * @param plugin The actual pluginObject to run.
468
+ */
469
+ #execute({ strategy, hookName, parameters, plugin, message }) {
470
+ const hook = plugin[hookName];
471
+ let output;
472
+ if (!hook) return null;
473
+ this.events.emit("executing", {
474
+ strategy,
475
+ hookName,
476
+ parameters,
477
+ plugin,
478
+ message
479
+ });
480
+ const task = (async () => {
481
+ try {
482
+ if (typeof hook === "function") {
483
+ const result = await Promise.resolve(hook.apply({
484
+ ...this.#core.context,
485
+ plugin
486
+ }, parameters));
487
+ output = result;
488
+ this.#addExecutedToCallStack({
489
+ parameters,
490
+ output,
491
+ strategy,
492
+ hookName,
493
+ plugin,
494
+ message
495
+ });
496
+ return result;
497
+ }
498
+ output = hook;
499
+ this.#addExecutedToCallStack({
500
+ parameters,
501
+ output,
502
+ strategy,
503
+ hookName,
504
+ plugin,
505
+ message
506
+ });
507
+ return hook;
508
+ } catch (e) {
509
+ this.#catcher(e, plugin, hookName);
510
+ return null;
511
+ }
512
+ })();
513
+ return task;
514
+ }
515
+ /**
516
+ * Run a sync plugin hook and return the result.
517
+ * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
518
+ * @param args Arguments passed to the plugin hook.
519
+ * @param plugin The acutal plugin
520
+ * @param replaceContext When passed, the plugin context can be overridden.
521
+ */
522
+ #executeSync({ strategy, hookName, parameters, plugin, message }) {
523
+ const hook = plugin[hookName];
524
+ let output;
525
+ if (!hook) return null;
526
+ this.events.emit("executing", {
527
+ strategy,
528
+ hookName,
529
+ parameters,
530
+ plugin,
531
+ message
532
+ });
533
+ try {
534
+ if (typeof hook === "function") {
535
+ const fn = hook.apply({
536
+ ...this.#core.context,
537
+ plugin
538
+ }, parameters);
539
+ output = fn;
540
+ this.#addExecutedToCallStack({
541
+ parameters,
542
+ output,
543
+ strategy,
544
+ hookName,
545
+ plugin,
546
+ message
547
+ });
548
+ return fn;
549
+ }
550
+ output = hook;
551
+ this.#addExecutedToCallStack({
552
+ parameters,
553
+ output,
554
+ strategy,
555
+ hookName,
556
+ plugin,
557
+ message
558
+ });
559
+ return hook;
560
+ } catch (e) {
561
+ this.#catcher(e, plugin, hookName);
562
+ return null;
563
+ }
564
+ }
565
+ #catcher(cause, plugin, hookName) {
566
+ const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
567
+ this.logger.emit("error", text, cause);
568
+ this.events.emit("error", cause);
569
+ }
570
+ #parse(plugin, pluginManager, context) {
571
+ const usedPluginNames = pluginManager.#usedPluginNames;
572
+ setUniqueName(plugin.name, usedPluginNames);
573
+ const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
574
+ if (plugin.context && typeof plugin.context === "function") return {
575
+ ...plugin,
576
+ key,
577
+ context: plugin.context.call(context)
578
+ };
579
+ return {
580
+ ...plugin,
581
+ key
582
+ };
583
+ }
584
+ static getDependedPlugins(plugins, dependedPluginNames) {
585
+ let pluginNames = [];
586
+ if (typeof dependedPluginNames === "string") pluginNames = [dependedPluginNames];
587
+ else pluginNames = dependedPluginNames;
588
+ return pluginNames.map((pluginName) => {
589
+ const plugin = plugins.find((plugin$1) => plugin$1.name === pluginName);
590
+ if (!plugin) throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`);
591
+ return plugin;
592
+ });
593
+ }
594
+ static get hooks() {
595
+ return [
596
+ "buildStart",
597
+ "resolvePath",
598
+ "resolveName",
599
+ "buildEnd"
600
+ ];
601
+ }
602
+ };
186
603
 
187
- Paths: ${JSON.stringify(paths, void 0, 2)}
604
+ //#endregion
605
+ //#region src/build.ts
606
+ async function setup(options) {
607
+ if (options.pluginManager) return options.pluginManager;
608
+ const { config: userConfig, logger = createLogger() } = options;
609
+ if (Array.isArray(userConfig.input)) console.warn(pc.yellow("This feature is still under development — use with caution"));
610
+ try {
611
+ if (isInputPath(userConfig) && !new URLPath(userConfig.input.path).isURL) await exists(userConfig.input.path);
612
+ } catch (e) {
613
+ if (isInputPath(userConfig)) throw new Error(`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`, { cause: e });
614
+ }
615
+ const definedConfig = {
616
+ root: userConfig.root || process.cwd(),
617
+ ...userConfig,
618
+ output: {
619
+ write: true,
620
+ barrelType: "named",
621
+ extension: { ".ts": ".ts" },
622
+ defaultBanner: "simple",
623
+ ...userConfig.output
624
+ },
625
+ plugins: userConfig.plugins
626
+ };
627
+ if (definedConfig.output.clean) {
628
+ await clean(definedConfig.output.path);
629
+ await clean(join(definedConfig.root, ".kubb"));
630
+ }
631
+ return new PluginManager(definedConfig, {
632
+ logger,
633
+ concurrency: 5
634
+ });
635
+ }
636
+ async function build(options) {
637
+ const { files, pluginManager, error } = await safeBuild(options);
638
+ if (error) throw error;
639
+ return {
640
+ files,
641
+ pluginManager,
642
+ error
643
+ };
644
+ }
645
+ async function safeBuild(options) {
646
+ const pluginManager = await setup(options);
647
+ const config = pluginManager.config;
648
+ try {
649
+ pluginManager.events.on("executing", ({ plugin, message }) => {
650
+ pluginManager.logger.emit("debug", {
651
+ date: /* @__PURE__ */ new Date(),
652
+ logs: [`Executing pluginKey ${plugin.key?.join(".")} | ${message}`]
653
+ });
654
+ });
655
+ pluginManager.events.on("executed", ({ plugin, message, output }) => {
656
+ pluginManager.logger.emit("debug", {
657
+ date: /* @__PURE__ */ new Date(),
658
+ logs: [`Executed pluginKey ${plugin.key?.join(".")} | ${message} | ${JSON.stringify(output, void 0, 2)}`]
659
+ });
660
+ });
661
+ await pluginManager.hookParallel({
662
+ hookName: "buildStart",
663
+ parameters: [config],
664
+ message: "buildStart"
665
+ });
666
+ if (config.output.barrelType) {
667
+ const root = resolve(config.root);
668
+ const rootPath = resolve(root, config.output.path, "index.ts");
669
+ const files$1 = await pluginManager.fileManager.getFiles();
670
+ const barrelFiles = files$1.filter((file) => {
671
+ return file.sources.some((source) => source.isIndexable);
672
+ });
673
+ const rootFile = {
674
+ path: rootPath,
675
+ baseName: "index.ts",
676
+ exports: barrelFiles.flatMap((file) => {
677
+ const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly);
678
+ return file.sources?.map((source) => {
679
+ if (!file.path || !source.isIndexable) return void 0;
680
+ const plugin = [...pluginManager.plugins].find((item) => {
681
+ const meta = file.meta;
682
+ return isDeepEqual(item.key, meta?.pluginKey);
683
+ });
684
+ const pluginOptions = plugin?.options;
685
+ if (!pluginOptions || pluginOptions?.output?.barrelType === false) return void 0;
686
+ return {
687
+ name: config.output.barrelType === "all" ? void 0 : [source.name],
688
+ path: getRelativePath(rootPath, file.path),
689
+ isTypeOnly: config.output.barrelType === "all" ? containsOnlyTypes : source.isTypeOnly
690
+ };
691
+ }).filter(Boolean);
692
+ }).filter(Boolean),
693
+ sources: [],
694
+ meta: {}
695
+ };
696
+ await pluginManager.fileManager.add(rootFile);
697
+ }
698
+ const files = await pluginManager.fileManager.processFiles({
699
+ root: config.root,
700
+ extension: config.output.extension,
701
+ dryRun: !config.output.write,
702
+ logger: pluginManager.logger
703
+ });
704
+ await pluginManager.hookParallel({
705
+ hookName: "buildEnd",
706
+ message: `Build stopped for ${config.name}`
707
+ });
708
+ await pluginManager.fileManager.clear();
709
+ return {
710
+ files,
711
+ pluginManager
712
+ };
713
+ } catch (e) {
714
+ return {
715
+ files: [],
716
+ pluginManager,
717
+ error: e
718
+ };
719
+ }
720
+ }
188
721
 
189
- Falling back on the first item.
190
- `
191
- ]
192
- });
193
- }
194
- return paths?.at(0);
195
- }
196
- return this.hookFirstSync({
197
- hookName: "resolvePath",
198
- parameters: [params.baseName, params.mode, params.options],
199
- message: `Resolving path '${params.baseName}'`
200
- }).result;
201
- };
202
- //TODO refactor by using the order of plugins and the cache of the fileManager instead of guessing and recreating the name/path
203
- resolveName = (params) => {
204
- if (params.pluginKey) {
205
- const names = this.hookForPluginSync({
206
- pluginKey: params.pluginKey,
207
- hookName: "resolveName",
208
- parameters: [trim(params.name), params.type],
209
- message: `Resolving name '${params.name}' and type '${params.type}'`
210
- });
211
- if (names && names?.length > 1) {
212
- this.logger.emit("debug", {
213
- date: /* @__PURE__ */ new Date(),
214
- logs: [
215
- `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
722
+ //#endregion
723
+ //#region ../../node_modules/.pnpm/yocto-queue@1.1.1/node_modules/yocto-queue/index.js
724
+ var Node = class {
725
+ value;
726
+ next;
727
+ constructor(value) {
728
+ this.value = value;
729
+ }
730
+ };
731
+ var Queue = class {
732
+ #head;
733
+ #tail;
734
+ #size;
735
+ constructor() {
736
+ this.clear();
737
+ }
738
+ enqueue(value) {
739
+ const node = new Node(value);
740
+ if (this.#head) {
741
+ this.#tail.next = node;
742
+ this.#tail = node;
743
+ } else {
744
+ this.#head = node;
745
+ this.#tail = node;
746
+ }
747
+ this.#size++;
748
+ }
749
+ dequeue() {
750
+ const current = this.#head;
751
+ if (!current) return;
752
+ this.#head = this.#head.next;
753
+ this.#size--;
754
+ return current.value;
755
+ }
756
+ peek() {
757
+ if (!this.#head) return;
758
+ return this.#head.value;
759
+ }
760
+ clear() {
761
+ this.#head = void 0;
762
+ this.#tail = void 0;
763
+ this.#size = 0;
764
+ }
765
+ get size() {
766
+ return this.#size;
767
+ }
768
+ *[Symbol.iterator]() {
769
+ let current = this.#head;
770
+ while (current) {
771
+ yield current.value;
772
+ current = current.next;
773
+ }
774
+ }
775
+ };
216
776
 
217
- Names: ${JSON.stringify(names, void 0, 2)}
777
+ //#endregion
778
+ //#region ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
779
+ function pLimit$1(concurrency) {
780
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
781
+ const queue = new Queue();
782
+ let activeCount = 0;
783
+ const next = () => {
784
+ activeCount--;
785
+ if (queue.size > 0) queue.dequeue()();
786
+ };
787
+ const run = async (fn, resolve$1, args) => {
788
+ activeCount++;
789
+ const result = (async () => fn(...args))();
790
+ resolve$1(result);
791
+ try {
792
+ await result;
793
+ } catch {}
794
+ next();
795
+ };
796
+ const enqueue = (fn, resolve$1, args) => {
797
+ queue.enqueue(run.bind(void 0, fn, resolve$1, args));
798
+ (async () => {
799
+ await Promise.resolve();
800
+ if (activeCount < concurrency && queue.size > 0) queue.dequeue()();
801
+ })();
802
+ };
803
+ const generator = (fn, ...args) => new Promise((resolve$1) => {
804
+ enqueue(fn, resolve$1, args);
805
+ });
806
+ Object.defineProperties(generator, {
807
+ activeCount: { get: () => activeCount },
808
+ pendingCount: { get: () => queue.size },
809
+ clearQueue: { value: () => {
810
+ queue.clear();
811
+ } }
812
+ });
813
+ return generator;
814
+ }
218
815
 
219
- Falling back on the first item.
220
- `
221
- ]
222
- });
223
- }
224
- return transformReservedWord(names?.at(0) || params.name);
225
- }
226
- const name = this.hookFirstSync({
227
- hookName: "resolveName",
228
- parameters: [trim(params.name), params.type],
229
- message: `Resolving name '${params.name}' and type '${params.type}'`
230
- }).result;
231
- return transformReservedWord(name);
232
- };
233
- /**
234
- * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
235
- */
236
- on(eventName, handler) {
237
- this.events.on(eventName, handler);
238
- }
239
- /**
240
- * Run a specific hookName for plugin x.
241
- */
242
- async hookForPlugin({
243
- pluginKey,
244
- hookName,
245
- parameters,
246
- message
247
- }) {
248
- const plugins = this.getPluginsByKey(hookName, pluginKey);
249
- this.logger.emit("progress_start", { id: hookName, size: plugins.length, message: "Running plugins..." });
250
- const items = [];
251
- for (const plugin of plugins) {
252
- const result = await this.#execute({
253
- strategy: "hookFirst",
254
- hookName,
255
- parameters,
256
- plugin,
257
- message
258
- });
259
- if (result !== void 0 && result !== null) {
260
- items.push(result);
261
- }
262
- }
263
- this.logger.emit("progress_stop", { id: hookName });
264
- return items;
265
- }
266
- /**
267
- * Run a specific hookName for plugin x.
268
- */
269
- hookForPluginSync({
270
- pluginKey,
271
- hookName,
272
- parameters,
273
- message
274
- }) {
275
- const plugins = this.getPluginsByKey(hookName, pluginKey);
276
- const result = plugins.map((plugin) => {
277
- return this.#executeSync({
278
- strategy: "hookFirst",
279
- hookName,
280
- parameters,
281
- plugin,
282
- message
283
- });
284
- }).filter(Boolean);
285
- return result;
286
- }
287
- /**
288
- * First non-null result stops and will return it's value.
289
- */
290
- async hookFirst({
291
- hookName,
292
- parameters,
293
- skipped,
294
- message
295
- }) {
296
- const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
297
- return skipped ? skipped.has(plugin) : true;
298
- });
299
- this.logger.emit("progress_start", { id: hookName, size: plugins.length });
300
- const promises = plugins.map((plugin) => {
301
- return async () => {
302
- const value = await this.#execute({
303
- strategy: "hookFirst",
304
- hookName,
305
- parameters,
306
- plugin,
307
- message
308
- });
309
- return Promise.resolve({
310
- plugin,
311
- result: value
312
- });
313
- };
314
- });
315
- const result = await this.#promiseManager.run("first", promises);
316
- this.logger.emit("progress_stop", { id: hookName });
317
- return result;
318
- }
319
- /**
320
- * First non-null result stops and will return it's value.
321
- */
322
- hookFirstSync({
323
- hookName,
324
- parameters,
325
- skipped,
326
- message
327
- }) {
328
- let parseResult = null;
329
- const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
330
- return skipped ? skipped.has(plugin) : true;
331
- });
332
- for (const plugin of plugins) {
333
- parseResult = {
334
- result: this.#executeSync({
335
- strategy: "hookFirst",
336
- hookName,
337
- parameters,
338
- plugin,
339
- message
340
- }),
341
- plugin
342
- };
343
- if (parseResult?.result != null) {
344
- break;
345
- }
346
- }
347
- return parseResult;
348
- }
349
- /**
350
- * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
351
- */
352
- async hookParallel({
353
- hookName,
354
- parameters,
355
- message
356
- }) {
357
- const plugins = this.#getSortedPlugins(hookName);
358
- this.logger.emit("progress_start", { id: hookName, size: plugins.length });
359
- const promises = plugins.map((plugin) => {
360
- return () => this.#execute({
361
- strategy: "hookParallel",
362
- hookName,
363
- parameters,
364
- plugin,
365
- message
366
- });
367
- });
368
- const results = await this.#promiseManager.run("parallel", promises, { concurrency: this.options.concurrency });
369
- results.forEach((result, index) => {
370
- if (isPromiseRejectedResult(result)) {
371
- const plugin = this.#getSortedPlugins(hookName)[index];
372
- this.#catcher(result.reason, plugin, hookName);
373
- }
374
- });
375
- this.logger.emit("progress_stop", { id: hookName });
376
- return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
377
- }
378
- /**
379
- * Chains plugins
380
- */
381
- async hookSeq({
382
- hookName,
383
- parameters,
384
- message
385
- }) {
386
- const plugins = this.#getSortedPlugins(hookName);
387
- this.logger.emit("progress_start", { id: hookName, size: plugins.length });
388
- const promises = plugins.map((plugin) => {
389
- return () => this.#execute({
390
- strategy: "hookSeq",
391
- hookName,
392
- parameters,
393
- plugin,
394
- message
395
- });
396
- });
397
- await this.#promiseManager.run("seq", promises);
398
- this.logger.emit("progress_stop", { id: hookName });
399
- }
400
- #getSortedPlugins(hookName) {
401
- const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
402
- if (hookName) {
403
- return plugins.filter((plugin) => hookName in plugin);
404
- }
405
- return plugins.map((plugin) => {
406
- if (plugin.pre) {
407
- const isValid = plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName));
408
- if (!isValid) {
409
- throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
410
- }
411
- }
412
- return plugin;
413
- }).sort((a, b) => {
414
- if (b.pre?.includes(a.name)) {
415
- return 1;
416
- }
417
- if (b.post?.includes(a.name)) {
418
- return -1;
419
- }
420
- return 0;
421
- });
422
- }
423
- getPluginByKey(pluginKey) {
424
- const plugins = [...this.plugins];
425
- const [searchPluginName] = pluginKey;
426
- return plugins.find((item) => {
427
- const [name] = item.key;
428
- return name === searchPluginName;
429
- });
430
- }
431
- getPluginsByKey(hookName, pluginKey) {
432
- const plugins = [...this.plugins];
433
- const [searchPluginName, searchIdentifier] = pluginKey;
434
- const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => {
435
- const [name, identifier] = item.key;
436
- const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
437
- const nameCheck = name === searchPluginName;
438
- if (searchIdentifier) {
439
- return identifierCheck && nameCheck;
440
- }
441
- return nameCheck;
442
- });
443
- if (!pluginByPluginName?.length) {
444
- const corePlugin = plugins.find((plugin) => plugin.name === "core" && hookName in plugin);
445
- if (corePlugin) {
446
- this.logger.emit("debug", {
447
- date: /* @__PURE__ */ new Date(),
448
- logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`]
449
- });
450
- } else {
451
- this.logger.emit("debug", {
452
- date: /* @__PURE__ */ new Date(),
453
- logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`]
454
- });
455
- }
456
- return corePlugin ? [corePlugin] : [];
457
- }
458
- return pluginByPluginName;
459
- }
460
- #addExecutedToCallStack(executer) {
461
- if (executer) {
462
- this.events.emit("executed", executer);
463
- this.executed.push(executer);
464
- this.logger.emit("progressed", { id: executer.hookName, message: `${executer.plugin.name}: ${executer.message}` });
465
- }
466
- }
467
- /**
468
- * Run an async plugin hook and return the result.
469
- * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
470
- * @param args Arguments passed to the plugin hook.
471
- * @param plugin The actual pluginObject to run.
472
- */
473
- // Implementation signature
474
- #execute({
475
- strategy,
476
- hookName,
477
- parameters,
478
- plugin,
479
- message
480
- }) {
481
- const hook = plugin[hookName];
482
- let output;
483
- if (!hook) {
484
- return null;
485
- }
486
- this.events.emit("executing", { strategy, hookName, parameters, plugin, message });
487
- const task = (async () => {
488
- try {
489
- if (typeof hook === "function") {
490
- const result = await Promise.resolve(hook.apply({ ...this.#core.context, plugin }, parameters));
491
- output = result;
492
- this.#addExecutedToCallStack({
493
- parameters,
494
- output,
495
- strategy,
496
- hookName,
497
- plugin,
498
- message
499
- });
500
- return result;
501
- }
502
- output = hook;
503
- this.#addExecutedToCallStack({
504
- parameters,
505
- output,
506
- strategy,
507
- hookName,
508
- plugin,
509
- message
510
- });
511
- return hook;
512
- } catch (e) {
513
- this.#catcher(e, plugin, hookName);
514
- return null;
515
- }
516
- })();
517
- return task;
518
- }
519
- /**
520
- * Run a sync plugin hook and return the result.
521
- * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
522
- * @param args Arguments passed to the plugin hook.
523
- * @param plugin The acutal plugin
524
- * @param replaceContext When passed, the plugin context can be overridden.
525
- */
526
- #executeSync({
527
- strategy,
528
- hookName,
529
- parameters,
530
- plugin,
531
- message
532
- }) {
533
- const hook = plugin[hookName];
534
- let output;
535
- if (!hook) {
536
- return null;
537
- }
538
- this.events.emit("executing", { strategy, hookName, parameters, plugin, message });
539
- try {
540
- if (typeof hook === "function") {
541
- const fn = hook.apply({ ...this.#core.context, plugin }, parameters);
542
- output = fn;
543
- this.#addExecutedToCallStack({
544
- parameters,
545
- output,
546
- strategy,
547
- hookName,
548
- plugin,
549
- message
550
- });
551
- return fn;
552
- }
553
- output = hook;
554
- this.#addExecutedToCallStack({
555
- parameters,
556
- output,
557
- strategy,
558
- hookName,
559
- plugin,
560
- message
561
- });
562
- return hook;
563
- } catch (e) {
564
- this.#catcher(e, plugin, hookName);
565
- return null;
566
- }
567
- }
568
- #catcher(cause, plugin, hookName) {
569
- const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
570
- this.logger.emit("error", text, cause);
571
- this.events.emit("error", cause);
572
- }
573
- #parse(plugin, pluginManager, context) {
574
- const usedPluginNames = pluginManager.#usedPluginNames;
575
- setUniqueName(plugin.name, usedPluginNames);
576
- const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
577
- if (plugin.context && typeof plugin.context === "function") {
578
- return {
579
- ...plugin,
580
- key,
581
- context: plugin.context.call(context)
582
- };
583
- }
584
- return {
585
- ...plugin,
586
- key
587
- };
588
- }
589
- static getDependedPlugins(plugins, dependedPluginNames) {
590
- let pluginNames = [];
591
- if (typeof dependedPluginNames === "string") {
592
- pluginNames = [dependedPluginNames];
593
- } else {
594
- pluginNames = dependedPluginNames;
595
- }
596
- return pluginNames.map((pluginName) => {
597
- const plugin = plugins.find((plugin2) => plugin2.name === pluginName);
598
- if (!plugin) {
599
- throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`);
600
- }
601
- return plugin;
602
- });
603
- }
604
- static get hooks() {
605
- return ["buildStart", "resolvePath", "resolveName", "buildEnd"];
606
- }
816
+ //#endregion
817
+ //#region ../../node_modules/.pnpm/p-locate@6.0.0/node_modules/p-locate/index.js
818
+ var EndError = class extends Error {
819
+ constructor(value) {
820
+ super();
821
+ this.value = value;
822
+ }
823
+ };
824
+ const testElement = async (element, tester) => tester(await element);
825
+ const finder = async (element) => {
826
+ const values = await Promise.all(element);
827
+ if (values[1] === true) throw new EndError(values[0]);
828
+ return false;
607
829
  };
830
+ async function pLocate(iterable, tester, { concurrency = Number.POSITIVE_INFINITY, preserveOrder = true } = {}) {
831
+ const limit = pLimit$1(concurrency);
832
+ const items = [...iterable].map((element) => [element, limit(testElement, element, tester)]);
833
+ const checkLimit = pLimit$1(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
834
+ try {
835
+ await Promise.all(items.map((element) => checkLimit(finder, element)));
836
+ } catch (error) {
837
+ if (error instanceof EndError) return error.value;
838
+ throw error;
839
+ }
840
+ }
608
841
 
609
- // src/config.ts
610
- function defineConfig(options) {
611
- return options;
842
+ //#endregion
843
+ //#region ../../node_modules/.pnpm/locate-path@7.2.0/node_modules/locate-path/index.js
844
+ const typeMappings = {
845
+ directory: "isDirectory",
846
+ file: "isFile"
847
+ };
848
+ function checkType(type) {
849
+ if (Object.hasOwnProperty.call(typeMappings, type)) return;
850
+ throw new Error(`Invalid type specified: ${type}`);
612
851
  }
613
- function isInputPath(result) {
614
- return !!result && "path" in result?.input;
852
+ const matchType = (type, stat) => stat[typeMappings[type]]();
853
+ const toPath$1 = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
854
+ async function locatePath(paths, { cwd = g$1.cwd(), type = "file", allowSymlinks = true, concurrency, preserveOrder } = {}) {
855
+ checkType(type);
856
+ cwd = toPath$1(cwd);
857
+ const statFunction = allowSymlinks ? promises.stat : promises.lstat;
858
+ return pLocate(paths, async (path_) => {
859
+ try {
860
+ const stat = await statFunction(path.resolve(cwd, path_));
861
+ return matchType(type, stat);
862
+ } catch {
863
+ return false;
864
+ }
865
+ }, {
866
+ concurrency,
867
+ preserveOrder
868
+ });
615
869
  }
616
- async function setup(options) {
617
- if (options.pluginManager) {
618
- return options.pluginManager;
619
- }
620
- const { config: userConfig, logger = createLogger() } = options;
621
- if (Array.isArray(userConfig.input)) {
622
- consola.warn(colors.yellow("This feature is still under development \u2014 use with caution"));
623
- }
624
- try {
625
- if (isInputPath(userConfig) && !new URLPath(userConfig.input.path).isURL) {
626
- await exists(userConfig.input.path);
627
- }
628
- } catch (e) {
629
- if (isInputPath(userConfig)) {
630
- throw new Error(
631
- `Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`,
632
- {
633
- cause: e
634
- }
635
- );
636
- }
637
- }
638
- const definedConfig = {
639
- root: userConfig.root || process.cwd(),
640
- ...userConfig,
641
- output: {
642
- write: true,
643
- barrelType: "named",
644
- extension: {
645
- ".ts": ".ts"
646
- },
647
- defaultBanner: "simple",
648
- ...userConfig.output
649
- },
650
- plugins: userConfig.plugins
651
- };
652
- if (definedConfig.output.clean) {
653
- await clean(definedConfig.output.path);
654
- await clean(join(definedConfig.root, ".kubb"));
655
- }
656
- return new PluginManager(definedConfig, { logger, concurrency: 5 });
870
+ function locatePathSync(paths, { cwd = g$1.cwd(), type = "file", allowSymlinks = true } = {}) {
871
+ checkType(type);
872
+ cwd = toPath$1(cwd);
873
+ const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
874
+ for (const path_ of paths) try {
875
+ const stat = statFunction(path.resolve(cwd, path_), { throwIfNoEntry: false });
876
+ if (!stat) continue;
877
+ if (matchType(type, stat)) return path_;
878
+ } catch {}
657
879
  }
658
- async function build(options) {
659
- const { files, pluginManager, error } = await safeBuild(options);
660
- if (error) throw error;
661
- return {
662
- files,
663
- pluginManager,
664
- error
665
- };
880
+
881
+ //#endregion
882
+ //#region ../../node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/node.js
883
+ function toPath(urlOrPath) {
884
+ return urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
666
885
  }
667
- async function safeBuild(options) {
668
- const pluginManager = await setup(options);
669
- const config = pluginManager.config;
670
- try {
671
- pluginManager.events.on("executing", ({ plugin, message }) => {
672
- pluginManager.logger.emit("debug", { date: /* @__PURE__ */ new Date(), logs: [`Executing pluginKey ${plugin.key?.join(".")} | ${message}`] });
673
- });
674
- pluginManager.events.on("executed", ({ plugin, message, output }) => {
675
- pluginManager.logger.emit("debug", {
676
- date: /* @__PURE__ */ new Date(),
677
- logs: [`Executed pluginKey ${plugin.key?.join(".")} | ${message} | ${JSON.stringify(output, void 0, 2)}`]
678
- });
679
- });
680
- await pluginManager.hookParallel({
681
- hookName: "buildStart",
682
- parameters: [config],
683
- message: "buildStart"
684
- });
685
- if (config.output.barrelType) {
686
- const root = resolve(config.root);
687
- const rootPath = resolve(root, config.output.path, "index.ts");
688
- const files2 = await pluginManager.fileManager.getFiles();
689
- const barrelFiles = files2.filter((file) => {
690
- return file.sources.some((source) => source.isIndexable);
691
- });
692
- const rootFile = {
693
- path: rootPath,
694
- baseName: "index.ts",
695
- exports: barrelFiles.flatMap((file) => {
696
- const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly);
697
- return file.sources?.map((source) => {
698
- if (!file.path || !source.isIndexable) {
699
- return void 0;
700
- }
701
- const plugin = [...pluginManager.plugins].find((item) => {
702
- const meta = file.meta;
703
- return isDeepEqual(item.key, meta?.pluginKey);
704
- });
705
- const pluginOptions = plugin?.options;
706
- if (!pluginOptions || pluginOptions?.output?.barrelType === false) {
707
- return void 0;
708
- }
709
- return {
710
- name: config.output.barrelType === "all" ? void 0 : [source.name],
711
- path: getRelativePath(rootPath, file.path),
712
- isTypeOnly: config.output.barrelType === "all" ? containsOnlyTypes : source.isTypeOnly
713
- };
714
- }).filter(Boolean);
715
- }).filter(Boolean),
716
- sources: [],
717
- meta: {}
718
- };
719
- await pluginManager.fileManager.add(rootFile);
720
- }
721
- const files = await pluginManager.fileManager.processFiles({
722
- root: config.root,
723
- extension: config.output.extension,
724
- dryRun: !config.output.write,
725
- logger: pluginManager.logger
726
- });
727
- await pluginManager.hookParallel({ hookName: "buildEnd", message: `Build stopped for ${config.name}` });
728
- await pluginManager.fileManager.clear();
729
- return {
730
- files,
731
- pluginManager
732
- };
733
- } catch (e) {
734
- return {
735
- files: [],
736
- pluginManager,
737
- error: e
738
- };
739
- }
886
+
887
+ //#endregion
888
+ //#region ../../node_modules/.pnpm/find-up@7.0.0/node_modules/find-up/index.js
889
+ const findUpStop = Symbol("findUpStop");
890
+ async function findUpMultiple(name, options = {}) {
891
+ let directory = path.resolve(toPath(options.cwd) ?? "");
892
+ const { root } = path.parse(directory);
893
+ const stopAt = path.resolve(directory, toPath(options.stopAt ?? root));
894
+ const limit = options.limit ?? Number.POSITIVE_INFINITY;
895
+ const paths = [name].flat();
896
+ const runMatcher = async (locateOptions) => {
897
+ if (typeof name !== "function") return locatePath(paths, locateOptions);
898
+ const foundPath = await name(locateOptions.cwd);
899
+ if (typeof foundPath === "string") return locatePath([foundPath], locateOptions);
900
+ return foundPath;
901
+ };
902
+ const matches = [];
903
+ while (true) {
904
+ const foundPath = await runMatcher({
905
+ ...options,
906
+ cwd: directory
907
+ });
908
+ if (foundPath === findUpStop) break;
909
+ if (foundPath) matches.push(path.resolve(directory, foundPath));
910
+ if (directory === stopAt || matches.length >= limit) break;
911
+ directory = path.dirname(directory);
912
+ }
913
+ return matches;
914
+ }
915
+ function findUpMultipleSync(name, options = {}) {
916
+ let directory = path.resolve(toPath(options.cwd) ?? "");
917
+ const { root } = path.parse(directory);
918
+ const stopAt = path.resolve(directory, toPath(options.stopAt) ?? root);
919
+ const limit = options.limit ?? Number.POSITIVE_INFINITY;
920
+ const paths = [name].flat();
921
+ const runMatcher = (locateOptions) => {
922
+ if (typeof name !== "function") return locatePathSync(paths, locateOptions);
923
+ const foundPath = name(locateOptions.cwd);
924
+ if (typeof foundPath === "string") return locatePathSync([foundPath], locateOptions);
925
+ return foundPath;
926
+ };
927
+ const matches = [];
928
+ while (true) {
929
+ const foundPath = runMatcher({
930
+ ...options,
931
+ cwd: directory
932
+ });
933
+ if (foundPath === findUpStop) break;
934
+ if (foundPath) matches.push(path.resolve(directory, foundPath));
935
+ if (directory === stopAt || matches.length >= limit) break;
936
+ directory = path.dirname(directory);
937
+ }
938
+ return matches;
939
+ }
940
+ async function findUp(name, options = {}) {
941
+ const matches = await findUpMultiple(name, {
942
+ ...options,
943
+ limit: 1
944
+ });
945
+ return matches[0];
946
+ }
947
+ function findUpSync(name, options = {}) {
948
+ const matches = findUpMultipleSync(name, {
949
+ ...options,
950
+ limit: 1
951
+ });
952
+ return matches[0];
740
953
  }
741
954
 
742
- // src/BaseGenerator.ts
743
- var BaseGenerator = class {
744
- #options = {};
745
- #context = {};
746
- constructor(options, context) {
747
- if (context) {
748
- this.#context = context;
749
- }
750
- if (options) {
751
- this.#options = options;
752
- }
753
- return this;
754
- }
755
- get options() {
756
- return this.#options;
757
- }
758
- get context() {
759
- return this.#context;
760
- }
761
- set options(options) {
762
- this.#options = { ...this.#options, ...options };
763
- }
764
- };
765
- var PackageManager = class _PackageManager {
766
- static #cache = {};
767
- #cwd;
768
- #SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
769
- constructor(workspace) {
770
- if (workspace) {
771
- this.#cwd = workspace;
772
- }
773
- return this;
774
- }
775
- set workspace(workspace) {
776
- this.#cwd = workspace;
777
- }
778
- get workspace() {
779
- return this.#cwd;
780
- }
781
- normalizeDirectory(directory) {
782
- if (!this.#SLASHES.has(directory[directory.length - 1])) {
783
- return `${directory}/`;
784
- }
785
- return directory;
786
- }
787
- getLocation(path2) {
788
- let location = path2;
789
- if (this.#cwd) {
790
- const require2 = mod.createRequire(this.normalizeDirectory(this.#cwd));
791
- location = require2.resolve(path2);
792
- }
793
- return location;
794
- }
795
- async import(path2) {
796
- try {
797
- let location = this.getLocation(path2);
798
- if (os.platform() === "win32") {
799
- location = pathToFileURL(location).href;
800
- }
801
- const module = await import(location);
802
- return module?.default ?? module;
803
- } catch (e) {
804
- console.error(e);
805
- return void 0;
806
- }
807
- }
808
- async getPackageJSON() {
809
- const pkgPath = await findUp(["package.json"], {
810
- cwd: this.#cwd
811
- });
812
- if (!pkgPath) {
813
- return void 0;
814
- }
815
- const json = await read(pkgPath);
816
- return JSON.parse(json);
817
- }
818
- getPackageJSONSync() {
819
- const pkgPath = findUpSync(["package.json"], {
820
- cwd: this.#cwd
821
- });
822
- if (!pkgPath) {
823
- return void 0;
824
- }
825
- const json = readSync(pkgPath);
826
- return JSON.parse(json);
827
- }
828
- static setVersion(dependency, version) {
829
- _PackageManager.#cache[dependency] = version;
830
- }
831
- #match(packageJSON, dependency) {
832
- const dependencies = {
833
- ...packageJSON["dependencies"] || {},
834
- ...packageJSON["devDependencies"] || {}
835
- };
836
- if (typeof dependency === "string" && dependencies[dependency]) {
837
- return dependencies[dependency];
838
- }
839
- const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
840
- return matchedDependency ? dependencies[matchedDependency] : void 0;
841
- }
842
- async getVersion(dependency) {
843
- if (typeof dependency === "string" && _PackageManager.#cache[dependency]) {
844
- return _PackageManager.#cache[dependency];
845
- }
846
- const packageJSON = await this.getPackageJSON();
847
- if (!packageJSON) {
848
- return void 0;
849
- }
850
- return this.#match(packageJSON, dependency);
851
- }
852
- getVersionSync(dependency) {
853
- if (typeof dependency === "string" && _PackageManager.#cache[dependency]) {
854
- return _PackageManager.#cache[dependency];
855
- }
856
- const packageJSON = this.getPackageJSONSync();
857
- if (!packageJSON) {
858
- return void 0;
859
- }
860
- return this.#match(packageJSON, dependency);
861
- }
862
- async isValid(dependency, version) {
863
- const packageVersion = await this.getVersion(dependency);
864
- if (!packageVersion) {
865
- return false;
866
- }
867
- if (packageVersion === version) {
868
- return true;
869
- }
870
- const semVer = coerce(packageVersion);
871
- if (!semVer) {
872
- throw new Error(`${packageVersion} is not valid`);
873
- }
874
- return satisfies(semVer, version);
875
- }
876
- isValidSync(dependency, version) {
877
- const packageVersion = this.getVersionSync(dependency);
878
- if (!packageVersion) {
879
- return false;
880
- }
881
- if (version === "next" && packageVersion === version) {
882
- return true;
883
- }
884
- const semVer = coerce(packageVersion);
885
- if (!semVer) {
886
- return false;
887
- }
888
- return satisfies(semVer, version);
889
- }
955
+ //#endregion
956
+ //#region src/PackageManager.ts
957
+ var PackageManager = class PackageManager {
958
+ static #cache = {};
959
+ #cwd;
960
+ #SLASHES = new Set(["/", "\\"]);
961
+ constructor(workspace) {
962
+ if (workspace) this.#cwd = workspace;
963
+ return this;
964
+ }
965
+ set workspace(workspace) {
966
+ this.#cwd = workspace;
967
+ }
968
+ get workspace() {
969
+ return this.#cwd;
970
+ }
971
+ normalizeDirectory(directory) {
972
+ if (!this.#SLASHES.has(directory[directory.length - 1])) return `${directory}/`;
973
+ return directory;
974
+ }
975
+ getLocation(path$1) {
976
+ let location = path$1;
977
+ if (this.#cwd) {
978
+ const require = mod.createRequire(this.normalizeDirectory(this.#cwd));
979
+ location = require.resolve(path$1);
980
+ }
981
+ return location;
982
+ }
983
+ async import(path$1) {
984
+ try {
985
+ let location = this.getLocation(path$1);
986
+ if (os.platform() === "win32") location = pathToFileURL(location).href;
987
+ const module = await import(location);
988
+ return module?.default ?? module;
989
+ } catch (e) {
990
+ console.error(e);
991
+ return void 0;
992
+ }
993
+ }
994
+ async getPackageJSON() {
995
+ const pkgPath = await findUp(["package.json"], { cwd: this.#cwd });
996
+ if (!pkgPath) return void 0;
997
+ const json = await read(pkgPath);
998
+ return JSON.parse(json);
999
+ }
1000
+ getPackageJSONSync() {
1001
+ const pkgPath = findUpSync(["package.json"], { cwd: this.#cwd });
1002
+ if (!pkgPath) return void 0;
1003
+ const json = readSync(pkgPath);
1004
+ return JSON.parse(json);
1005
+ }
1006
+ static setVersion(dependency, version) {
1007
+ PackageManager.#cache[dependency] = version;
1008
+ }
1009
+ #match(packageJSON, dependency) {
1010
+ const dependencies = {
1011
+ ...packageJSON["dependencies"] || {},
1012
+ ...packageJSON["devDependencies"] || {}
1013
+ };
1014
+ if (typeof dependency === "string" && dependencies[dependency]) return dependencies[dependency];
1015
+ const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
1016
+ return matchedDependency ? dependencies[matchedDependency] : void 0;
1017
+ }
1018
+ async getVersion(dependency) {
1019
+ if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
1020
+ const packageJSON = await this.getPackageJSON();
1021
+ if (!packageJSON) return void 0;
1022
+ return this.#match(packageJSON, dependency);
1023
+ }
1024
+ getVersionSync(dependency) {
1025
+ if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
1026
+ const packageJSON = this.getPackageJSONSync();
1027
+ if (!packageJSON) return void 0;
1028
+ return this.#match(packageJSON, dependency);
1029
+ }
1030
+ async isValid(dependency, version) {
1031
+ const packageVersion = await this.getVersion(dependency);
1032
+ if (!packageVersion) return false;
1033
+ if (packageVersion === version) return true;
1034
+ const semVer = coerce(packageVersion);
1035
+ if (!semVer) throw new Error(`${packageVersion} is not valid`);
1036
+ return satisfies(semVer, version);
1037
+ }
1038
+ isValidSync(dependency, version) {
1039
+ const packageVersion = this.getVersionSync(dependency);
1040
+ if (!packageVersion) return false;
1041
+ if (version === "next" && packageVersion === version) return true;
1042
+ const semVer = coerce(packageVersion);
1043
+ if (!semVer) return false;
1044
+ return satisfies(semVer, version);
1045
+ }
890
1046
  };
891
1047
 
892
- export { BaseGenerator, PackageManager, PluginManager, PromiseManager, build, createPlugin, build as default, defineConfig, isInputPath, safeBuild, setup };
893
- //# sourceMappingURL=index.js.map
1048
+ //#endregion
1049
+ export { BaseGenerator, FileManager, PackageManager, PluginManager, PromiseManager, build, createPlugin, build as default, defineConfig, getDefaultBanner, getSource, isInputPath, safeBuild, setup };
894
1050
  //# sourceMappingURL=index.js.map