@kubb/core 1.15.0-canary.20231027T174910 → 1.15.0-canary.20231027T185539

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
@@ -3,19 +3,18 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var pc3 = require('picocolors');
6
+ var crypto = require('crypto');
6
7
  var fs2 = require('fs-extra');
8
+ var changeCase = require('change-case');
9
+ var naturalOrderby = require('natural-orderby');
10
+ var perf_hooks = require('perf_hooks');
7
11
  var seedrandom = require('seedrandom');
8
- var path4 = require('path');
12
+ var path2 = require('path');
9
13
  var jsRuntime = require('js-runtime');
10
- var changeCase = require('change-case');
11
- var crypto2 = require('crypto');
14
+ var dirTree = require('directory-tree');
12
15
  var parser = require('@kubb/parser');
13
- var factory = require('@kubb/parser/factory');
14
16
  var isEqual = require('lodash.isequal');
15
- var naturalOrderby = require('natural-orderby');
16
- var dirTree = require('directory-tree');
17
17
  var events = require('events');
18
- var perf_hooks = require('perf_hooks');
19
18
  var mod = require('module');
20
19
  var os = require('os');
21
20
  var url = require('url');
@@ -25,39 +24,18 @@ var semver = require('semver');
25
24
 
26
25
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
27
26
 
28
- function _interopNamespace(e) {
29
- if (e && e.__esModule) return e;
30
- var n = Object.create(null);
31
- if (e) {
32
- Object.keys(e).forEach(function (k) {
33
- if (k !== 'default') {
34
- var d = Object.getOwnPropertyDescriptor(e, k);
35
- Object.defineProperty(n, k, d.get ? d : {
36
- enumerable: true,
37
- get: function () { return e[k]; }
38
- });
39
- }
40
- });
41
- }
42
- n.default = e;
43
- return Object.freeze(n);
44
- }
45
-
46
27
  var pc3__default = /*#__PURE__*/_interopDefault(pc3);
28
+ var crypto__default = /*#__PURE__*/_interopDefault(crypto);
47
29
  var fs2__default = /*#__PURE__*/_interopDefault(fs2);
48
30
  var seedrandom__default = /*#__PURE__*/_interopDefault(seedrandom);
49
- var path4__default = /*#__PURE__*/_interopDefault(path4);
50
- var crypto2__default = /*#__PURE__*/_interopDefault(crypto2);
51
- var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
52
- var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
31
+ var path2__default = /*#__PURE__*/_interopDefault(path2);
53
32
  var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
33
+ var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
54
34
  var mod__default = /*#__PURE__*/_interopDefault(mod);
55
35
  var os__default = /*#__PURE__*/_interopDefault(os);
56
36
  var process__default = /*#__PURE__*/_interopDefault(process);
57
37
  var fs3__default = /*#__PURE__*/_interopDefault(fs3);
58
38
 
59
- var __defProp = Object.defineProperty;
60
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
61
39
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
62
40
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
63
41
  }) : x)(function(x) {
@@ -65,49 +43,110 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
65
43
  return require.apply(this, arguments);
66
44
  throw Error('Dynamic require of "' + x + '" is not supported');
67
45
  });
68
- var __publicField = (obj, key, value) => {
69
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
70
- return value;
71
- };
72
- var __accessCheck = (obj, member, msg) => {
73
- if (!member.has(obj))
74
- throw TypeError("Cannot " + msg);
75
- };
76
- var __privateGet = (obj, member, getter) => {
77
- __accessCheck(obj, member, "read from private field");
78
- return getter ? getter.call(obj) : member.get(obj);
79
- };
80
- var __privateAdd = (obj, member, value) => {
81
- if (member.has(obj))
82
- throw TypeError("Cannot add the same private member more than once");
83
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
84
- };
85
- var __privateSet = (obj, member, value, setter) => {
86
- __accessCheck(obj, member, "write to private field");
87
- setter ? setter.call(obj, value) : member.set(obj, value);
88
- return value;
89
- };
90
- var __privateWrapper = (obj, member, setter, getter) => ({
91
- set _(value) {
92
- __privateSet(obj, member, value, setter);
93
- },
94
- get _() {
95
- return __privateGet(obj, member, getter);
46
+
47
+ // src/utils/cache.ts
48
+ function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
49
+ return {
50
+ set(id, value) {
51
+ Store[id] = [0, value];
52
+ },
53
+ get(id) {
54
+ const item = Store[id];
55
+ if (!item) {
56
+ return null;
57
+ }
58
+ item[0] = 0;
59
+ return item[1];
60
+ },
61
+ has(id) {
62
+ const item = Store[id];
63
+ if (!item) {
64
+ return false;
65
+ }
66
+ item[0] = 0;
67
+ return true;
68
+ },
69
+ delete(id) {
70
+ return delete Store[id];
71
+ }
72
+ };
73
+ }
74
+ async function clean(path3) {
75
+ return fs2.remove(path3);
76
+ }
77
+ var FunctionParams = class {
78
+ type;
79
+ items = [];
80
+ constructor(type) {
81
+ this.type = type;
82
+ return this;
83
+ }
84
+ add(item) {
85
+ if (!item) {
86
+ return this;
87
+ }
88
+ if (Array.isArray(item)) {
89
+ item.filter(Boolean).forEach((it) => this.items.push(it));
90
+ return this;
91
+ }
92
+ this.items.push(item);
93
+ return this;
94
+ }
95
+ toString() {
96
+ const sortedData = naturalOrderby.orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ["desc", "desc"]);
97
+ return sortedData.filter(({ enabled = true }) => enabled).reduce((acc, { name, type, required = true, ...rest }) => {
98
+ if (!name) {
99
+ acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
100
+ return acc;
101
+ }
102
+ const parameterName = name.startsWith("{") ? name : changeCase.camelCase(name, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
103
+ if (type) {
104
+ if (required) {
105
+ acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
106
+ } else {
107
+ acc.push(`${parameterName}?: ${type}`);
108
+ }
109
+ } else {
110
+ acc.push(`${parameterName}`);
111
+ }
112
+ return acc;
113
+ }, []).join(", ");
96
114
  }
97
- });
98
- var __privateMethod = (obj, member, method) => {
99
- __accessCheck(obj, member, "access private method");
100
- return method;
101
115
  };
102
- async function clean(path5) {
103
- return fs2.remove(path5);
116
+
117
+ // src/utils/getUniqueName.ts
118
+ function getUniqueName(originalName, data) {
119
+ let used = data[originalName] || 0;
120
+ if (used) {
121
+ data[originalName] = ++used;
122
+ originalName += used;
123
+ }
124
+ data[originalName] = 1;
125
+ return originalName;
104
126
  }
105
- var LogLevel = {
106
- silent: "silent",
107
- info: "info",
108
- debug: "debug"
109
- };
110
- function createLogger({ logLevel, name, spinner }) {
127
+
128
+ // src/utils/isPromise.ts
129
+ function isPromise(result) {
130
+ return typeof result?.then === "function";
131
+ }
132
+ function isPromiseFulfilledResult(result) {
133
+ return result.status === "fulfilled";
134
+ }
135
+ function isPromiseRejectedResult(result) {
136
+ return result.status === "rejected";
137
+ }
138
+
139
+ // src/utils/jsdoc.ts
140
+ function createJSDocBlockText({ comments }) {
141
+ const filteredComments = comments.filter(Boolean);
142
+ if (!filteredComments.length) {
143
+ return "";
144
+ }
145
+ return `/**
146
+ * ${filteredComments.join("\n * ")}
147
+ */`;
148
+ }
149
+ function createLogger(spinner) {
111
150
  const logs = [];
112
151
  const log = (message) => {
113
152
  if (message && spinner) {
@@ -133,8 +172,6 @@ function createLogger({ logLevel, name, spinner }) {
133
172
  }
134
173
  };
135
174
  const logger = {
136
- name,
137
- logLevel,
138
175
  log,
139
176
  error,
140
177
  warn,
@@ -144,6 +181,75 @@ function createLogger({ logLevel, name, spinner }) {
144
181
  };
145
182
  return logger;
146
183
  }
184
+
185
+ // src/utils/nameSorter.ts
186
+ function nameSorter(a, b) {
187
+ if (a.name < b.name) {
188
+ return -1;
189
+ }
190
+ if (a.name > b.name) {
191
+ return 1;
192
+ }
193
+ return 0;
194
+ }
195
+ var Queue = class {
196
+ #queue = [];
197
+ #workerCount = 0;
198
+ #maxParallel;
199
+ #debug = false;
200
+ constructor(maxParallel, debug = false) {
201
+ this.#maxParallel = maxParallel;
202
+ this.#debug = debug;
203
+ }
204
+ run(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
205
+ return new Promise((resolve, reject) => {
206
+ const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
207
+ options.controller?.signal.addEventListener("abort", () => {
208
+ this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
209
+ reject("Aborted");
210
+ });
211
+ this.#queue.push(item);
212
+ this.#work();
213
+ });
214
+ }
215
+ runSync(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
216
+ new Promise((resolve, reject) => {
217
+ const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
218
+ options.controller?.signal.addEventListener("abort", () => {
219
+ this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
220
+ });
221
+ this.#queue.push(item);
222
+ this.#work();
223
+ });
224
+ }
225
+ get hasJobs() {
226
+ return this.#workerCount > 0 || this.#queue.length > 0;
227
+ }
228
+ get count() {
229
+ return this.#workerCount;
230
+ }
231
+ #work() {
232
+ if (this.#workerCount >= this.#maxParallel) {
233
+ return;
234
+ }
235
+ this.#workerCount++;
236
+ let entry;
237
+ while (entry = this.#queue.shift()) {
238
+ const { reject, resolve, job, name, description } = entry;
239
+ if (this.#debug) {
240
+ perf_hooks.performance.mark(name + "_start");
241
+ }
242
+ job().then((result) => {
243
+ resolve(result);
244
+ if (this.#debug) {
245
+ perf_hooks.performance.mark(name + "_stop");
246
+ perf_hooks.performance.measure(description, name + "_start", name + "_stop");
247
+ }
248
+ }).catch((err) => reject(err));
249
+ }
250
+ this.#workerCount--;
251
+ }
252
+ };
147
253
  var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
148
254
  function randomColour(text, colours = defaultColours) {
149
255
  if (!text) {
@@ -170,22 +276,46 @@ function randomPicoColour(text, colors = defaultColours) {
170
276
  }
171
277
  return formatter(text);
172
278
  }
279
+ function slash(path3, platform = "linux") {
280
+ const isWindowsPath = /^\\\\\?\\/.test(path3);
281
+ if (["linux", "mac"].includes(platform) && !isWindowsPath) {
282
+ return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
283
+ }
284
+ return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
285
+ }
286
+ function getRelativePath(rootDir, filePath, platform = "linux") {
287
+ if (!rootDir || !filePath) {
288
+ throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
289
+ }
290
+ const relativePath = path2__default.default.relative(rootDir, filePath);
291
+ const path3 = slash(relativePath, platform);
292
+ if (path3.startsWith("../")) {
293
+ return path3.replace(path2__default.default.basename(path3), path2__default.default.basename(path3, path2__default.default.extname(filePath)));
294
+ }
295
+ return `./${path3.replace(path2__default.default.basename(path3), path2__default.default.basename(path3, path2__default.default.extname(filePath)))}`;
296
+ }
297
+ function getPathMode(path3) {
298
+ if (!path3) {
299
+ return "directory";
300
+ }
301
+ return path2__default.default.extname(path3) ? "file" : "directory";
302
+ }
173
303
  var reader = jsRuntime.switcher(
174
304
  {
175
- node: async (path5) => {
176
- return fs2__default.default.readFile(path5, { encoding: "utf8" });
305
+ node: async (path3) => {
306
+ return fs2__default.default.readFile(path3, { encoding: "utf8" });
177
307
  },
178
- bun: async (path5) => {
179
- const file = Bun.file(path5);
308
+ bun: async (path3) => {
309
+ const file = Bun.file(path3);
180
310
  return file.text();
181
311
  }
182
312
  },
183
313
  "node"
184
314
  );
185
- jsRuntime.switcher(
315
+ var syncReader = jsRuntime.switcher(
186
316
  {
187
- node: (path5) => {
188
- return fs2__default.default.readFileSync(path5, { encoding: "utf8" });
317
+ node: (path3) => {
318
+ return fs2__default.default.readFileSync(path3, { encoding: "utf8" });
189
319
  },
190
320
  bun: () => {
191
321
  throw new Error("Bun cannot read sync");
@@ -193,115 +323,79 @@ jsRuntime.switcher(
193
323
  },
194
324
  "node"
195
325
  );
196
- async function read(path5) {
197
- return reader(path5);
326
+ async function read(path3) {
327
+ return reader(path3);
198
328
  }
199
- var URLPath = class {
200
- constructor(path5) {
201
- this.path = path5;
202
- return this;
203
- }
204
- /**
205
- * Convert Swagger path to URLPath(syntax of Express)
206
- * @example /pet/{petId} => /pet/:petId
207
- */
208
- get URL() {
209
- return this.toURLPath();
210
- }
211
- get isURL() {
212
- try {
213
- const url = new URL(this.path);
214
- if (url?.href) {
215
- return true;
216
- }
217
- } catch (error) {
218
- return false;
219
- }
220
- return false;
221
- }
222
- /**
223
- * Convert Swagger path to template literals/ template strings(camelcase)
224
- * @example /pet/{petId} => `/pet/${petId}`
225
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
226
- * @example /account/userID => `/account/${userId}`
227
- */
228
- get template() {
229
- return this.toTemplateString();
230
- }
231
- get object() {
232
- return this.toObject();
233
- }
234
- get params() {
235
- return this.getParams();
236
- }
237
- toObject({ type = "path", replacer, stringify } = {}) {
238
- const object = {
239
- url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
240
- params: this.getParams()
241
- };
242
- if (stringify) {
243
- if (type !== "template") {
244
- throw new Error("Type should be `template` when using stringiyf");
245
- }
246
- return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
247
- }
248
- return object;
249
- }
250
- /**
251
- * Convert Swagger path to template literals/ template strings(camelcase)
252
- * @example /pet/{petId} => `/pet/${petId}`
253
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
254
- * @example /account/userID => `/account/${userId}`
255
- */
256
- toTemplateString(replacer) {
257
- const regex = /{(\w|-)*}/g;
258
- const found = this.path.match(regex);
259
- let newPath = this.path.replaceAll("{", "${");
260
- if (found) {
261
- newPath = found.reduce((prev, curr) => {
262
- const pathParam = replacer ? replacer(changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
263
- const replacement = `\${${pathParam}}`;
264
- return prev.replace(curr, replacement);
265
- }, this.path);
329
+ function readSync(path3) {
330
+ return syncReader(path3);
331
+ }
332
+
333
+ // src/utils/renderTemplate.ts
334
+ function renderTemplate(template, data = void 0) {
335
+ if (!data || !Object.keys(data).length) {
336
+ return template.replace(/{{(.*?)}}/g, "");
337
+ }
338
+ const matches = template.match(/{{(.*?)}}/g);
339
+ return matches?.reduce((prev, curr) => {
340
+ const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
341
+ if (index === void 0) {
342
+ return prev;
266
343
  }
267
- return `\`${newPath}\``;
268
- }
269
- getParams(replacer) {
270
- const regex = /{(\w|-)*}/g;
271
- const found = this.path.match(regex);
272
- if (!found) {
273
- return void 0;
344
+ const value = data[index];
345
+ if (value === void 0) {
346
+ return prev;
274
347
  }
275
- const params = {};
276
- found.forEach((item) => {
277
- item = item.replaceAll("{", "").replaceAll("}", "");
278
- const pathParam = replacer ? replacer(changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
279
- params[pathParam] = pathParam;
280
- }, this.path);
281
- return params;
282
- }
283
- /**
284
- * Convert Swagger path to URLPath(syntax of Express)
285
- * @example /pet/{petId} => /pet/:petId
286
- */
287
- toURLPath() {
288
- return this.path.replaceAll("{", ":").replaceAll("}", "");
348
+ return prev.replace(curr, () => {
349
+ if (typeof value === "boolean") {
350
+ return `${value.toString()}` || "false";
351
+ }
352
+ return value || "";
353
+ }).trim();
354
+ }, template) || "";
355
+ }
356
+
357
+ // src/utils/SummaryError.ts
358
+ var SummaryError = class extends Error {
359
+ summary;
360
+ constructor(message, options) {
361
+ super(message, { cause: options.cause });
362
+ this.name = "SummaryError";
363
+ this.summary = options.summary || [];
289
364
  }
290
365
  };
291
366
 
292
- // src/config.ts
293
- function defineConfig(options) {
294
- return options;
295
- }
296
- function isInputPath(result) {
297
- return !!result && "path" in result;
298
- }
367
+ // src/utils/throttle.ts
368
+ var throttle = (fn, delay) => {
369
+ let wait = false;
370
+ let timeout2;
371
+ let cancelled = false;
372
+ return [
373
+ (...args) => {
374
+ if (cancelled) {
375
+ return void 0;
376
+ }
377
+ if (wait) {
378
+ return void 0;
379
+ }
380
+ const val = fn(...args);
381
+ wait = true;
382
+ timeout2 = setTimeout(() => {
383
+ wait = false;
384
+ }, delay);
385
+ return val;
386
+ },
387
+ () => {
388
+ cancelled = true;
389
+ clearTimeout(timeout2);
390
+ }
391
+ ];
392
+ };
299
393
 
300
394
  // src/utils/timeout.ts
301
395
  async function timeout(ms) {
302
- return new Promise((resolve2) => {
396
+ return new Promise((resolve) => {
303
397
  setTimeout(() => {
304
- resolve2(true);
398
+ resolve(true);
305
399
  }, ms);
306
400
  });
307
401
  }
@@ -311,17 +405,6 @@ function combineCodes(codes) {
311
405
  return codes.join("\n");
312
406
  }
313
407
 
314
- // src/utils/transformers/createJSDocBlockText.ts
315
- function createJSDocBlockText({ comments }) {
316
- const filteredComments = comments.filter(Boolean);
317
- if (!filteredComments.length) {
318
- return "";
319
- }
320
- return `/**
321
- * ${filteredComments.join("\n * ")}
322
- */`;
323
- }
324
-
325
408
  // src/utils/transformers/escape.ts
326
409
  function escape(text) {
327
410
  return text ? text.replaceAll("`", "\\`") : "";
@@ -347,39 +430,6 @@ function jsStringEscape(input) {
347
430
  });
348
431
  }
349
432
 
350
- // src/utils/transformers/indent.ts
351
- function createIndent(size) {
352
- return Array.from({ length: size + 1 }).join(" ");
353
- }
354
-
355
- // src/utils/transformers/nameSorter.ts
356
- function nameSorter(a, b) {
357
- if (a.name < b.name) {
358
- return -1;
359
- }
360
- if (a.name > b.name) {
361
- return 1;
362
- }
363
- return 0;
364
- }
365
-
366
- // src/utils/transformers/searchAndReplace.ts
367
- function searchAndReplace(options) {
368
- const { text, replaceBy, prefix = "", key } = options;
369
- const searchValues = options.searchValues?.(prefix, key) || [
370
- `${prefix}["${key}"]`,
371
- `${prefix}['${key}']`,
372
- `${prefix}[\`${key}\`]`,
373
- `${prefix}"${key}"`,
374
- `${prefix}'${key}'`,
375
- `${prefix}\`${key}\``,
376
- new RegExp(`${prefix}${key}`, "g")
377
- ];
378
- return searchValues.reduce((prev, searchValue) => {
379
- return prev.toString().replaceAll(searchValue, replaceBy);
380
- }, text);
381
- }
382
-
383
433
  // src/utils/transformers/transformReservedWord.ts
384
434
  var reservedWords = [
385
435
  "abstract",
@@ -472,83 +522,11 @@ function transformReservedWord(word) {
472
522
  }
473
523
  return word;
474
524
  }
475
-
476
- // src/utils/transformers/index.ts
477
- var transformers = {
478
- combineCodes,
479
- escape,
480
- jsStringEscape,
481
- createIndent,
482
- transformReservedWord,
483
- nameSorter,
484
- searchAndReplace,
485
- JSDoc: {
486
- createJSDocBlockText
487
- }
488
- };
489
- async function saveCreateDirectory(path5) {
490
- const passedPath = path4.dirname(path4.resolve(path5));
491
- await fs2__default.default.mkdir(passedPath, { recursive: true });
492
- }
493
- var writer = jsRuntime.switcher(
494
- {
495
- node: async (path5, data) => {
496
- try {
497
- await fs2__default.default.stat(path4.resolve(path5));
498
- const oldContent = await fs2__default.default.readFile(path4.resolve(path5), { encoding: "utf-8" });
499
- if (oldContent?.toString() === data?.toString()) {
500
- return;
501
- }
502
- } catch (_err) {
503
- }
504
- await saveCreateDirectory(path5);
505
- await fs2__default.default.writeFile(path4.resolve(path5), data, { encoding: "utf-8" });
506
- const savedData = await fs2__default.default.readFile(path4.resolve(path5), { encoding: "utf-8" });
507
- if (savedData?.toString() !== data?.toString()) {
508
- throw new Error(`Sanity check failed for ${path5}
509
-
510
- Data[${data.length}]:
511
- ${data}
512
-
513
- Saved[${savedData.length}]:
514
- ${savedData}
515
- `);
516
- }
517
- return savedData;
518
- },
519
- bun: async (path5, data) => {
520
- try {
521
- await saveCreateDirectory(path5);
522
- await Bun.write(path4.resolve(path5), data);
523
- const file = Bun.file(path4.resolve(path5));
524
- const savedData = await file.text();
525
- if (savedData?.toString() !== data?.toString()) {
526
- throw new Error(`Sanity check failed for ${path5}
527
-
528
- Data[${data.length}]:
529
- ${data}
530
-
531
- Saved[${savedData.length}]:
532
- ${savedData}
533
- `);
534
- }
535
- return savedData;
536
- } catch (e) {
537
- console.log(e, path4.resolve(path5));
538
- }
539
- }
540
- },
541
- "node"
542
- );
543
- async function write(data, path5) {
544
- if (data.trim() === "") {
545
- return void 0;
546
- }
547
- return writer(path5, data.trim());
548
- }
549
525
  var TreeNode = class _TreeNode {
526
+ data;
527
+ parent;
528
+ children = [];
550
529
  constructor(data, parent) {
551
- this.children = [];
552
530
  this.data = data;
553
531
  this.parent = parent;
554
532
  return this;
@@ -608,16 +586,16 @@ var TreeNode = class _TreeNode {
608
586
  }
609
587
  return this;
610
588
  }
611
- static build(path5, options = {}) {
589
+ static build(path3, options = {}) {
612
590
  try {
613
591
  const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
614
- const filteredTree = dirTree__default.default(path5, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
592
+ const filteredTree = dirTree__default.default(path3, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
615
593
  if (!filteredTree) {
616
594
  return null;
617
595
  }
618
- const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || FileManager.getMode(filteredTree.path) });
596
+ const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || getPathMode(filteredTree.path) });
619
597
  const recurse = (node, item) => {
620
- const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || FileManager.getMode(item.path) });
598
+ const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || getPathMode(item.path) });
621
599
  if (item.children?.length) {
622
600
  item.children?.forEach((child) => {
623
601
  recurse(subNode, child);
@@ -632,287 +610,227 @@ var TreeNode = class _TreeNode {
632
610
  }
633
611
  };
634
612
 
635
- // src/BarrelManager.ts
636
- var _options;
637
- var BarrelManager = class {
638
- constructor(options = {}) {
639
- __privateAdd(this, _options, {});
640
- __privateSet(this, _options, options);
613
+ // src/utils/uniqueIdFactory.ts
614
+ var uniqueIdFactory = (counter) => (str = "") => `${str}${++counter}`;
615
+ var URLPath = class {
616
+ path;
617
+ constructor(path3) {
618
+ this.path = path3;
641
619
  return this;
642
620
  }
643
- getIndexes(root, extName) {
644
- const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
645
- const extMapper = {
646
- ".ts": {
647
- extensions: /\.ts/,
648
- exclude: [/schemas/, /json/]
649
- },
650
- ".json": {
651
- extensions: /\.json/,
652
- exclude: []
621
+ /**
622
+ * Convert Swagger path to URLPath(syntax of Express)
623
+ * @example /pet/{petId} => /pet/:petId
624
+ */
625
+ get URL() {
626
+ return this.toURLPath();
627
+ }
628
+ get isURL() {
629
+ try {
630
+ const url = new URL(this.path);
631
+ if (url?.href) {
632
+ return true;
653
633
  }
654
- };
655
- const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
656
- if (!tree) {
657
- return null;
634
+ } catch (error) {
635
+ return false;
658
636
  }
659
- const fileReducer = (files2, currentTree) => {
660
- if (!currentTree.children) {
661
- return [];
662
- }
663
- if (currentTree.children?.length > 1) {
664
- const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
665
- const exports = currentTree.children.filter(Boolean).map((file) => {
666
- const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
667
- if (importPath.includes("index") && indexPath.includes("index")) {
668
- return void 0;
669
- }
670
- return {
671
- path: includeExt ? file.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
672
- isTypeOnly
673
- };
674
- }).filter(Boolean);
675
- files2.push({
676
- path: indexPath,
677
- baseName: "index.ts",
678
- source: "",
679
- exports: output ? exports?.filter((item) => {
680
- return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
681
- }) : exports
682
- });
683
- } else {
684
- currentTree.children?.forEach((child) => {
685
- const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
686
- const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
687
- const exports = [
688
- {
689
- path: includeExt ? child.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
690
- isTypeOnly
691
- }
692
- ];
693
- files2.push({
694
- path: indexPath,
695
- baseName: "index.ts",
696
- source: "",
697
- exports: output ? exports?.filter((item) => {
698
- return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
699
- }) : exports
700
- });
701
- });
702
- }
703
- currentTree.children.forEach((childItem) => {
704
- fileReducer(files2, childItem);
705
- });
706
- return files2;
707
- };
708
- const files = fileReducer([], tree).reverse();
709
- const filteredFiles = filter ? files.filter(filter) : files;
710
- return map ? filteredFiles.map(map) : filteredFiles;
637
+ return false;
711
638
  }
712
- };
713
- _options = new WeakMap();
714
-
715
- // src/FileManager.ts
716
- var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
717
- var _FileManager = class _FileManager {
718
- constructor(options) {
719
- __privateAdd(this, _validate);
720
- __privateAdd(this, _add);
721
- __privateAdd(this, _addOrAppend);
722
- __privateAdd(this, _cache, /* @__PURE__ */ new Map());
723
- __privateAdd(this, _task, void 0);
724
- __privateAdd(this, _isWriting, false);
725
- /**
726
- * Timeout between writes
727
- */
728
- __privateAdd(this, _timeout, 0);
729
- __privateAdd(this, _queue, void 0);
730
- if (options) {
731
- __privateSet(this, _task, options.task);
732
- __privateSet(this, _queue, options.queue);
733
- __privateSet(this, _timeout, options.timeout || 0);
734
- }
735
- return this;
639
+ /**
640
+ * Convert Swagger path to template literals/ template strings(camelcase)
641
+ * @example /pet/{petId} => `/pet/${petId}`
642
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
643
+ * @example /account/userID => `/account/${userId}`
644
+ */
645
+ get template() {
646
+ return this.toTemplateString();
736
647
  }
737
- get files() {
738
- const files = [];
739
- __privateGet(this, _cache).forEach((item) => {
740
- files.push(...item.flat(1));
741
- });
742
- return files;
648
+ get object() {
649
+ return this.toObject();
743
650
  }
744
- get isExecuting() {
745
- return __privateGet(this, _queue)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
651
+ get params() {
652
+ return this.getParams();
746
653
  }
747
- async add(...files) {
748
- const promises = files.map((file) => {
749
- __privateMethod(this, _validate, validate_fn).call(this, file);
750
- if (file.override) {
751
- return __privateMethod(this, _add, add_fn).call(this, file);
654
+ toObject({ type = "path", replacer, stringify } = {}) {
655
+ const object = {
656
+ url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
657
+ params: this.getParams()
658
+ };
659
+ if (stringify) {
660
+ if (type !== "template") {
661
+ throw new Error("Type should be `template` when using stringiyf");
752
662
  }
753
- return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
754
- });
755
- const resolvedFiles = await Promise.all(promises);
756
- if (files.length > 1) {
757
- return resolvedFiles;
663
+ return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
758
664
  }
759
- return resolvedFiles[0];
665
+ return object;
760
666
  }
761
- async addIndexes({ root, extName = ".ts", meta, options = {} }) {
762
- const barrelManager = new BarrelManager(options);
763
- const files = barrelManager.getIndexes(root, extName);
764
- if (!files) {
667
+ /**
668
+ * Convert Swagger path to template literals/ template strings(camelcase)
669
+ * @example /pet/{petId} => `/pet/${petId}`
670
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
671
+ * @example /account/userID => `/account/${userId}`
672
+ */
673
+ toTemplateString(replacer) {
674
+ const regex = /{(\w|-)*}/g;
675
+ const found = this.path.match(regex);
676
+ let newPath = this.path.replaceAll("{", "${");
677
+ if (found) {
678
+ newPath = found.reduce((prev, curr) => {
679
+ const pathParam = replacer ? replacer(changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
680
+ const replacement = `\${${pathParam}}`;
681
+ return prev.replace(curr, replacement);
682
+ }, this.path);
683
+ }
684
+ return `\`${newPath}\``;
685
+ }
686
+ getParams(replacer) {
687
+ const regex = /{(\w|-)*}/g;
688
+ const found = this.path.match(regex);
689
+ if (!found) {
765
690
  return void 0;
766
691
  }
767
- return await Promise.all(
768
- files.map((file) => {
769
- return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
770
- ...file,
771
- meta: meta ? meta : file.meta
772
- });
773
- })
774
- );
692
+ const params = {};
693
+ found.forEach((item) => {
694
+ item = item.replaceAll("{", "").replaceAll("}", "");
695
+ const pathParam = replacer ? replacer(changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
696
+ params[pathParam] = pathParam;
697
+ }, this.path);
698
+ return params;
775
699
  }
776
- getCacheByUUID(UUID) {
777
- let cache;
778
- __privateGet(this, _cache).forEach((files) => {
779
- cache = files.find((item) => item.id === UUID);
780
- });
781
- return cache;
700
+ /**
701
+ * Convert Swagger path to URLPath(syntax of Express)
702
+ * @example /pet/{petId} => /pet/:petId
703
+ */
704
+ toURLPath() {
705
+ return this.path.replaceAll("{", ":").replaceAll("}", "");
782
706
  }
783
- get(path5) {
784
- return __privateGet(this, _cache).get(path5);
707
+ };
708
+
709
+ // src/utils/Warning.ts
710
+ var Warning = class extends Error {
711
+ constructor(message, options) {
712
+ super(message, { cause: options?.cause });
713
+ this.name = "Warning";
785
714
  }
786
- remove(path5) {
787
- const cacheItem = this.get(path5);
788
- if (!cacheItem) {
789
- return;
715
+ };
716
+ async function saveCreateDirectory(path3) {
717
+ const passedPath = path2__default.default.dirname(path2__default.default.resolve(path3));
718
+ await fs2__default.default.mkdir(passedPath, { recursive: true });
719
+ }
720
+ var writer = jsRuntime.switcher(
721
+ {
722
+ node: async (path3, data) => {
723
+ try {
724
+ await fs2__default.default.stat(path3);
725
+ const oldContent = await fs2__default.default.readFile(path3, { encoding: "utf-8" });
726
+ if (oldContent?.toString() === data) {
727
+ return;
728
+ }
729
+ } catch (_err) {
730
+ }
731
+ await saveCreateDirectory(path3);
732
+ return fs2__default.default.writeFile(path2__default.default.resolve(path3), data, { encoding: "utf-8" });
733
+ },
734
+ bun: async (path3, data) => {
735
+ try {
736
+ await saveCreateDirectory(path3);
737
+ await Bun.write(path2__default.default.resolve(path3), data);
738
+ } catch (e) {
739
+ console.log(e, path2__default.default.resolve(path3));
740
+ }
790
741
  }
791
- __privateGet(this, _cache).delete(path5);
792
- }
793
- async write(...params) {
794
- if (!__privateGet(this, _isWriting)) {
795
- __privateSet(this, _isWriting, true);
796
- const text = await write(...params);
797
- __privateSet(this, _isWriting, false);
798
- return text;
742
+ },
743
+ "node"
744
+ );
745
+ async function write(data, path3) {
746
+ return writer(path3, data);
747
+ }
748
+ function getIndexes(root, extName, options = {}) {
749
+ const extMapper = {
750
+ ".ts": {
751
+ extensions: /\.ts/,
752
+ exclude: [/schemas/, /json/]
753
+ },
754
+ ".json": {
755
+ extensions: /\.json/,
756
+ exclude: []
799
757
  }
800
- await timeout(__privateGet(this, _timeout));
801
- return this.write(...params);
802
- }
803
- async read(...params) {
804
- return read(...params);
758
+ };
759
+ const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...options });
760
+ if (!tree) {
761
+ return null;
805
762
  }
806
- // statics
807
- static getSource(file) {
808
- if (!_FileManager.isExtensionAllowed(file.baseName)) {
809
- return file.source;
763
+ const fileReducer = (files2, currentTree) => {
764
+ if (!currentTree.children) {
765
+ return [];
810
766
  }
811
- const exports = file.exports ? combineExports(file.exports) : [];
812
- const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
813
- const importNodes = imports.map((item) => factory__namespace.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
814
- const exportNodes = exports.map(
815
- (item) => factory__namespace.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias })
816
- );
817
- return [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
818
- }
819
- static combineFiles(files) {
820
- return files.filter(Boolean).reduce((acc, file) => {
821
- const prevIndex = acc.findIndex((item) => item.path === file.path);
822
- if (prevIndex === -1) {
823
- return [...acc, file];
824
- }
767
+ if (currentTree.children?.length > 1) {
768
+ const path3 = path2__default.default.resolve(currentTree.data.path, "index.ts");
769
+ const exports = currentTree.children.map((file) => {
770
+ if (!file) {
771
+ return void 0;
772
+ }
773
+ const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
774
+ if (importPath.includes("index") && path3.includes("index")) {
775
+ return void 0;
776
+ }
777
+ return { path: importPath };
778
+ }).filter(Boolean);
779
+ files2.push({
780
+ path: path3,
781
+ baseName: "index.ts",
782
+ source: "",
783
+ exports
784
+ });
785
+ } else {
786
+ currentTree.children?.forEach((child) => {
787
+ const path3 = path2__default.default.resolve(currentTree.data.path, "index.ts");
788
+ const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
789
+ files2.push({
790
+ path: path3,
791
+ baseName: "index.ts",
792
+ source: "",
793
+ exports: [{ path: importPath }]
794
+ });
795
+ });
796
+ }
797
+ currentTree.children.forEach((childItem) => {
798
+ fileReducer(files2, childItem);
799
+ });
800
+ return files2;
801
+ };
802
+ const files = fileReducer([], tree);
803
+ return files;
804
+ }
805
+ function combineFiles(files) {
806
+ return files.filter(Boolean).reduce((acc, curr) => {
807
+ const prevIndex = acc.findIndex((item) => item.path === curr.path);
808
+ if (prevIndex !== -1) {
825
809
  const prev = acc[prevIndex];
826
- if (prev && file.override) {
827
- acc[prevIndex] = {
828
- imports: [],
829
- exports: [],
830
- ...file
831
- };
832
- return acc;
833
- }
834
810
  if (prev) {
835
811
  acc[prevIndex] = {
836
- ...file,
837
- source: prev.source && file.source ? `${prev.source}
838
- ${file.source}` : "",
839
- imports: [...prev.imports || [], ...file.imports || []],
840
- exports: [...prev.exports || [], ...file.exports || []],
841
- env: { ...prev.env || {}, ...file.env || {} }
812
+ ...curr,
813
+ source: prev.source && curr.source ? `${prev.source}
814
+ ${curr.source}` : "",
815
+ imports: [...prev.imports || [], ...curr.imports || []],
816
+ exports: [...prev.exports || [], ...curr.exports || []],
817
+ env: { ...prev.env || {}, ...curr.env || {} }
842
818
  };
843
819
  }
844
- return acc;
845
- }, []);
846
- }
847
- static getMode(path5) {
848
- if (!path5) {
849
- return "directory";
820
+ } else {
821
+ acc.push(curr);
850
822
  }
851
- return path4.extname(path5) ? "file" : "directory";
852
- }
853
- static get extensions() {
854
- return [".js", ".ts", ".tsx"];
855
- }
856
- static isExtensionAllowed(baseName) {
857
- return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
858
- }
859
- };
860
- _cache = new WeakMap();
861
- _task = new WeakMap();
862
- _isWriting = new WeakMap();
863
- _timeout = new WeakMap();
864
- _queue = new WeakMap();
865
- _validate = new WeakSet();
866
- validate_fn = function(file) {
867
- if (!file.validate) {
868
- return;
869
- }
870
- if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
871
- throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
872
- }
873
- };
874
- _add = new WeakSet();
875
- add_fn = async function(file) {
876
- const controller = new AbortController();
877
- const resolvedFile = { id: crypto2__default.default.randomUUID(), ...file };
878
- __privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
879
- if (__privateGet(this, _queue)) {
880
- await __privateGet(this, _queue).run(
881
- async () => {
882
- var _a;
883
- return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
884
- },
885
- { controller }
886
- );
887
- }
888
- return resolvedFile;
889
- };
890
- _addOrAppend = new WeakSet();
891
- addOrAppend_fn = async function(file) {
892
- const previousCaches = __privateGet(this, _cache).get(file.path);
893
- const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
894
- if (previousCache) {
895
- __privateGet(this, _cache).delete(previousCache.path);
896
- return __privateMethod(this, _add, add_fn).call(this, {
897
- ...file,
898
- source: previousCache.source && file.source ? `${previousCache.source}
899
- ${file.source}` : "",
900
- imports: [...previousCache.imports || [], ...file.imports || []],
901
- exports: [...previousCache.exports || [], ...file.exports || []],
902
- env: { ...previousCache.env || {}, ...file.env || {} }
903
- });
904
- }
905
- return __privateMethod(this, _add, add_fn).call(this, file);
906
- };
907
- var FileManager = _FileManager;
823
+ return acc;
824
+ }, []);
825
+ }
826
+ var extensions = [".js", ".ts", ".tsx"];
827
+ function isExtensionAllowed(baseName) {
828
+ return extensions.some((extension) => baseName.endsWith(extension));
829
+ }
908
830
  function combineExports(exports) {
909
- const combinedExports = naturalOrderby.orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
831
+ return exports.reduce((prev, curr) => {
910
832
  const name = curr.name;
911
833
  const prevByPath = prev.findLast((imp) => imp.path === curr.path);
912
- const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
913
- if (prevByPathAndIsTypeOnly) {
914
- return prev;
915
- }
916
834
  const uniquePrev = prev.findLast(
917
835
  (imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
918
836
  );
@@ -934,16 +852,12 @@ function combineExports(exports) {
934
852
  }
935
853
  return [...prev, curr];
936
854
  }, []);
937
- return naturalOrderby.orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
938
855
  }
939
856
  function combineImports(imports, exports, source) {
940
- const combinedImports = naturalOrderby.orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
857
+ return imports.reduce((prev, curr) => {
941
858
  let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
942
859
  const hasImportInSource = (importName) => {
943
- if (!source) {
944
- return true;
945
- }
946
- const checker = (name2) => name2 && !!source.includes(name2);
860
+ const checker = (name2) => name2 && !!source.includes(`${name2}`);
947
861
  return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
948
862
  };
949
863
  if (Array.isArray(name)) {
@@ -951,10 +865,6 @@ function combineImports(imports, exports, source) {
951
865
  }
952
866
  const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
953
867
  const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
954
- const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
955
- if (prevByPathNameAndIsTypeOnly) {
956
- return prev;
957
- }
958
868
  if (uniquePrev || Array.isArray(name) && !name.length) {
959
869
  return prev;
960
870
  }
@@ -976,7 +886,43 @@ function combineImports(imports, exports, source) {
976
886
  }
977
887
  return [...prev, curr];
978
888
  }, []);
979
- return naturalOrderby.orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
889
+ }
890
+ function createFileSource(file) {
891
+ let { source } = file;
892
+ if (!isExtensionAllowed(file.baseName)) {
893
+ return file.source;
894
+ }
895
+ const exports = file.exports ? combineExports(file.exports) : [];
896
+ const imports = file.imports ? combineImports(file.imports, exports, source) : [];
897
+ const importNodes = imports.map((item) => parser.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
898
+ const importSource = parser.print(importNodes);
899
+ const exportNodes = exports.map((item) => parser.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias }));
900
+ const exportSource = parser.print(exportNodes);
901
+ source = getEnvSource(file.source, file.env);
902
+ if (importSource) {
903
+ source = `${importSource}
904
+ ${source}`;
905
+ }
906
+ if (exportSource) {
907
+ source = `${exportSource}
908
+ ${source}`;
909
+ }
910
+ return source;
911
+ }
912
+ function searchAndReplace(options) {
913
+ const { text, replaceBy, prefix = "", key } = options;
914
+ const searchValues = options.searchValues?.(prefix, key) || [
915
+ `${prefix}["${key}"]`,
916
+ `${prefix}['${key}']`,
917
+ `${prefix}[\`${key}\`]`,
918
+ `${prefix}"${key}"`,
919
+ `${prefix}'${key}'`,
920
+ `${prefix}\`${key}\``,
921
+ new RegExp(`${prefix}${key}`, "g")
922
+ ];
923
+ return searchValues.reduce((prev, searchValue) => {
924
+ return prev.toString().replaceAll(searchValue, replaceBy);
925
+ }, text);
980
926
  }
981
927
  function getEnvSource(source, env) {
982
928
  if (!env) {
@@ -993,128 +939,132 @@ function getEnvSource(source, env) {
993
939
  throw new TypeError(`Environment should be in upperCase for ${key}`);
994
940
  }
995
941
  if (typeof replaceBy === "string") {
996
- prev = transformers.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
997
- prev = transformers.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
942
+ prev = searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
943
+ prev = searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
998
944
  `, "ig"), ""), replaceBy, key });
999
945
  }
1000
946
  return prev;
1001
947
  }, source);
1002
948
  }
1003
- var _emitter;
1004
- var EventEmitter = class {
1005
- constructor() {
1006
- __privateAdd(this, _emitter, new events.EventEmitter());
1007
- __privateGet(this, _emitter).setMaxListeners(100);
1008
- }
1009
- emit(eventName, ...eventArg) {
1010
- __privateGet(this, _emitter).emit(eventName, ...eventArg);
949
+
950
+ // src/managers/fileManager/FileManager.ts
951
+ var FileManager = class {
952
+ #cache = /* @__PURE__ */ new Map();
953
+ #task;
954
+ #queue;
955
+ constructor(options) {
956
+ if (options) {
957
+ this.#task = options.task;
958
+ this.#queue = options.queue;
959
+ }
960
+ return this;
1011
961
  }
1012
- on(eventName, handler) {
1013
- __privateGet(this, _emitter).on(eventName, handler);
962
+ get extensions() {
963
+ return extensions;
1014
964
  }
1015
- off(eventName, handler) {
1016
- __privateGet(this, _emitter).off(eventName, handler);
965
+ get files() {
966
+ const files = [];
967
+ this.#cache.forEach((item) => {
968
+ files.push(...item.flat(1));
969
+ });
970
+ return files;
1017
971
  }
1018
- removeAll() {
1019
- __privateGet(this, _emitter).removeAllListeners();
972
+ get isExecuting() {
973
+ return this.#queue?.hasJobs ?? false;
1020
974
  }
1021
- };
1022
- _emitter = new WeakMap();
1023
- var _queue2, _workerCount, _maxParallel, _debug, _work, work_fn;
1024
- var Queue = class {
1025
- constructor(maxParallel, debug = false) {
1026
- __privateAdd(this, _work);
1027
- __privateAdd(this, _queue2, []);
1028
- this.eventEmitter = new EventEmitter();
1029
- __privateAdd(this, _workerCount, 0);
1030
- __privateAdd(this, _maxParallel, void 0);
1031
- __privateAdd(this, _debug, false);
1032
- __privateSet(this, _maxParallel, maxParallel);
1033
- __privateSet(this, _debug, debug);
1034
- }
1035
- run(job, options = { controller: new AbortController(), name: crypto2__default.default.randomUUID(), description: "" }) {
1036
- return new Promise((resolve2, reject) => {
1037
- const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
1038
- options.controller?.signal.addEventListener("abort", () => {
1039
- __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
1040
- reject("Aborted");
1041
- });
1042
- __privateGet(this, _queue2).push(item);
1043
- __privateMethod(this, _work, work_fn).call(this);
1044
- });
975
+ async add(file) {
976
+ const controller = new AbortController();
977
+ const resolvedFile = { id: crypto__default.default.randomUUID(), ...file };
978
+ this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
979
+ if (this.#queue) {
980
+ try {
981
+ await this.#queue.run(
982
+ async () => {
983
+ return this.#task?.(resolvedFile);
984
+ },
985
+ { controller }
986
+ );
987
+ } catch {
988
+ return resolvedFile;
989
+ }
990
+ }
991
+ return resolvedFile;
1045
992
  }
1046
- runSync(job, options = { controller: new AbortController(), name: crypto2__default.default.randomUUID(), description: "" }) {
1047
- new Promise((resolve2, reject) => {
1048
- const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
1049
- options.controller?.signal.addEventListener("abort", () => {
1050
- __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
993
+ async addOrAppend(file) {
994
+ const previousCaches = this.#cache.get(file.path);
995
+ const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
996
+ if (previousCache) {
997
+ this.#cache.delete(previousCache.path);
998
+ return this.add({
999
+ ...file,
1000
+ source: previousCache.source && file.source ? `${previousCache.source}
1001
+ ${file.source}` : "",
1002
+ imports: [...previousCache.imports || [], ...file.imports || []],
1003
+ exports: [...previousCache.exports || [], ...file.exports || []],
1004
+ env: { ...previousCache.env || {}, ...file.env || {} }
1051
1005
  });
1052
- __privateGet(this, _queue2).push(item);
1053
- __privateMethod(this, _work, work_fn).call(this);
1054
- });
1055
- }
1056
- get hasJobs() {
1057
- return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue2).length > 0;
1006
+ }
1007
+ return this.add(file);
1058
1008
  }
1059
- get count() {
1060
- return __privateGet(this, _workerCount);
1009
+ async addIndexes(root, extName = ".ts", options = {}) {
1010
+ const files = await getIndexes(root, extName, options);
1011
+ if (!files) {
1012
+ return void 0;
1013
+ }
1014
+ return Promise.all(
1015
+ files.map((file) => {
1016
+ if (file.override) {
1017
+ return this.add(file);
1018
+ }
1019
+ return this.addOrAppend(file);
1020
+ })
1021
+ );
1061
1022
  }
1062
- };
1063
- _queue2 = new WeakMap();
1064
- _workerCount = new WeakMap();
1065
- _maxParallel = new WeakMap();
1066
- _debug = new WeakMap();
1067
- _work = new WeakSet();
1068
- work_fn = function() {
1069
- if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
1070
- return;
1023
+ #append(path3, file) {
1024
+ const previousFiles = this.#cache.get(path3) || [];
1025
+ this.#cache.set(path3, [...previousFiles, file]);
1071
1026
  }
1072
- __privateWrapper(this, _workerCount)._++;
1073
- let entry;
1074
- while (entry = __privateGet(this, _queue2).shift()) {
1075
- const { reject, resolve: resolve2, job, name, description } = entry;
1076
- if (__privateGet(this, _debug)) {
1077
- perf_hooks.performance.mark(name + "_start");
1078
- }
1079
- job().then((result) => {
1080
- this.eventEmitter.emit("jobDone", result);
1081
- resolve2(result);
1082
- if (__privateGet(this, _debug)) {
1083
- perf_hooks.performance.mark(name + "_stop");
1084
- perf_hooks.performance.measure(description, name + "_start", name + "_stop");
1085
- }
1086
- }).catch((err) => {
1087
- this.eventEmitter.emit("jobFailed", err);
1088
- reject(err);
1027
+ getCacheByUUID(UUID) {
1028
+ let cache;
1029
+ this.#cache.forEach((files) => {
1030
+ cache = files.find((item) => item.id === UUID);
1089
1031
  });
1032
+ return cache;
1090
1033
  }
1091
- __privateWrapper(this, _workerCount)._--;
1092
- };
1093
-
1094
- // src/utils/uniqueName.ts
1095
- function setUniqueName(originalName, data) {
1096
- let used = data[originalName] || 0;
1097
- if (used) {
1098
- data[originalName] = ++used;
1099
- return originalName;
1034
+ get(path3) {
1035
+ return this.#cache.get(path3);
1100
1036
  }
1101
- data[originalName] = 1;
1102
- return originalName;
1103
- }
1104
-
1105
- // src/errors.ts
1106
- var PluginError = class extends Error {
1107
- constructor(message, options) {
1108
- super(message, { cause: options.cause });
1109
- this.name = "PluginError";
1110
- this.cause = options.cause;
1111
- this.pluginManager = options.pluginManager;
1037
+ remove(path3) {
1038
+ const cacheItem = this.get(path3);
1039
+ if (!cacheItem) {
1040
+ return;
1041
+ }
1042
+ this.#cache.delete(path3);
1043
+ }
1044
+ async write(...params) {
1045
+ if (this.#queue) {
1046
+ return this.#queue.run(async () => {
1047
+ return write(...params);
1048
+ });
1049
+ }
1050
+ return write(...params);
1051
+ }
1052
+ async read(...params) {
1053
+ if (this.#queue) {
1054
+ return this.#queue.run(async () => {
1055
+ return read(...params);
1056
+ });
1057
+ }
1058
+ return read(...params);
1112
1059
  }
1113
1060
  };
1061
+
1062
+ // src/managers/pluginManager/ParallelPluginError.ts
1114
1063
  var ParallelPluginError = class extends Error {
1064
+ errors = [];
1065
+ pluginManager;
1115
1066
  constructor(message, options) {
1116
1067
  super(message, { cause: options.cause });
1117
- this.errors = [];
1118
1068
  this.name = "ParallelPluginError";
1119
1069
  this.errors = options.errors;
1120
1070
  this.pluginManager = options.pluginManager;
@@ -1134,54 +1084,30 @@ var ParallelPluginError = class extends Error {
1134
1084
  })?.cause;
1135
1085
  }
1136
1086
  };
1137
- var SummaryError = class extends Error {
1087
+
1088
+ // src/managers/pluginManager/PluginError.ts
1089
+ var PluginError = class extends Error {
1090
+ pluginManager;
1091
+ cause;
1138
1092
  constructor(message, options) {
1139
1093
  super(message, { cause: options.cause });
1140
- this.name = "SummaryError";
1141
- this.summary = options.summary || [];
1142
- }
1143
- };
1144
- var Warning = class extends Error {
1145
- constructor(message, options) {
1146
- super(message, { cause: options?.cause });
1147
- this.name = "Warning";
1094
+ this.name = "PluginError";
1095
+ this.cause = options.cause;
1096
+ this.pluginManager = options.pluginManager;
1148
1097
  }
1149
1098
  };
1150
- var ValidationPluginError = class extends Error {
1151
- };
1152
-
1153
- // src/utils/cache.ts
1154
- function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
1155
- return {
1156
- set(id, value) {
1157
- Store[id] = [0, value];
1158
- },
1159
- get(id) {
1160
- const item = Store[id];
1161
- if (!item) {
1162
- return null;
1163
- }
1164
- item[0] = 0;
1165
- return item[1];
1166
- },
1167
- has(id) {
1168
- const item = Store[id];
1169
- if (!item) {
1170
- return false;
1171
- }
1172
- item[0] = 0;
1173
- return true;
1174
- },
1175
- delete(id) {
1176
- return delete Store[id];
1177
- }
1178
- };
1179
- }
1180
-
1181
- // src/plugin.ts
1182
- function createPlugin(factory2) {
1099
+ function createPlugin(factory) {
1183
1100
  return (options) => {
1184
- return factory2(options);
1101
+ const plugin = factory(options);
1102
+ if (Array.isArray(plugin)) {
1103
+ throw new Error("Not implemented");
1104
+ }
1105
+ if (!plugin.transform) {
1106
+ plugin.transform = function transform(code) {
1107
+ return code;
1108
+ };
1109
+ }
1110
+ return plugin;
1185
1111
  };
1186
1112
  }
1187
1113
  var pluginName = "core";
@@ -1190,8 +1116,6 @@ var definePlugin = createPlugin((options) => {
1190
1116
  return {
1191
1117
  name: pluginName,
1192
1118
  options,
1193
- key: ["controller", "core"],
1194
- kind: "controller",
1195
1119
  api() {
1196
1120
  return {
1197
1121
  get config() {
@@ -1200,18 +1124,18 @@ var definePlugin = createPlugin((options) => {
1200
1124
  get plugins() {
1201
1125
  return options.getPlugins();
1202
1126
  },
1203
- get plugin() {
1204
- return options.plugin;
1205
- },
1206
1127
  logger,
1207
1128
  fileManager,
1208
1129
  pluginManager,
1209
1130
  async addFile(...files) {
1210
- const resolvedFiles = await fileManager.add(...files);
1211
- if (!Array.isArray(resolvedFiles)) {
1212
- return [resolvedFiles];
1213
- }
1214
- return resolvedFiles;
1131
+ return Promise.all(
1132
+ files.map((file) => {
1133
+ if (file.override) {
1134
+ return fileManager.add(file);
1135
+ }
1136
+ return fileManager.addOrAppend(file);
1137
+ })
1138
+ );
1215
1139
  },
1216
1140
  resolvePath,
1217
1141
  resolveName,
@@ -1219,133 +1143,75 @@ var definePlugin = createPlugin((options) => {
1219
1143
  };
1220
1144
  },
1221
1145
  resolvePath(baseName) {
1222
- const root = path4__default.default.resolve(this.config.root, this.config.output.path);
1223
- return path4__default.default.resolve(root, baseName);
1146
+ const root = path2__default.default.resolve(this.config.root, this.config.output.path);
1147
+ return path2__default.default.resolve(root, baseName);
1224
1148
  },
1225
1149
  resolveName(name) {
1226
1150
  return name;
1227
1151
  }
1228
1152
  };
1229
1153
  });
1230
-
1231
- // src/utils/executeStrategies.ts
1232
- function hookSeq(promises) {
1233
- return promises.reduce(
1234
- (promise, func) => {
1235
- if (!func || typeof func !== "function") {
1236
- throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
1237
- }
1238
- return promise.then((result) => {
1239
- const calledFunc = func();
1240
- if (calledFunc) {
1241
- return calledFunc.then(Array.prototype.concat.bind(result));
1242
- }
1243
- });
1244
- },
1245
- Promise.resolve([])
1246
- );
1247
- }
1248
-
1249
- // src/PromiseManager.ts
1250
- var _options2;
1251
- var PromiseManager = class {
1252
- constructor(options = {}) {
1253
- __privateAdd(this, _options2, {});
1254
- __privateSet(this, _options2, options);
1255
- return this;
1154
+ var EventEmitter = class {
1155
+ constructor() {
1156
+ this.#emitter.setMaxListeners(100);
1256
1157
  }
1257
- run(strategy, promises) {
1258
- if (strategy === "seq") {
1259
- return hookSeq(promises);
1260
- }
1261
- throw new Error(`${strategy} not implemented`);
1158
+ #emitter = new events.EventEmitter();
1159
+ emit(eventName, ...eventArg) {
1160
+ this.#emitter.emit(eventName, ...eventArg);
1161
+ }
1162
+ on(eventName, handler) {
1163
+ this.#emitter.on(eventName, handler);
1164
+ }
1165
+ off(eventName, handler) {
1166
+ this.#emitter.off(eventName, handler);
1167
+ }
1168
+ removeAll() {
1169
+ this.#emitter.removeAllListeners();
1262
1170
  }
1263
1171
  };
1264
- _options2 = new WeakMap();
1265
- function isPromise(result) {
1266
- return !!result && typeof result?.then === "function";
1267
- }
1268
- function isPromiseRejectedResult(result) {
1269
- return result.status === "rejected";
1172
+
1173
+ // src/managers/pluginManager/pluginParser.ts
1174
+ var usedPluginNames = {};
1175
+ function pluginParser(plugin, context) {
1176
+ const key = [plugin.kind, plugin.name, getUniqueName(plugin.name, usedPluginNames).split(plugin.name).at(1)];
1177
+ if (plugin.api && typeof plugin.api === "function") {
1178
+ const api = plugin.api.call(context);
1179
+ return {
1180
+ ...plugin,
1181
+ key,
1182
+ api
1183
+ };
1184
+ }
1185
+ return {
1186
+ ...plugin,
1187
+ key
1188
+ };
1270
1189
  }
1271
1190
 
1272
- // src/PluginManager.ts
1273
- var _core, _usedPluginNames, _promiseManager, _getSortedPlugins, getSortedPlugins_fn, _addExecutedToCallStack, addExecutedToCallStack_fn, _execute, execute_fn, _executeSync, executeSync_fn, _catcher, catcher_fn, _parse, parse_fn;
1191
+ // src/managers/pluginManager/PluginManager.ts
1192
+ var hookNames = {
1193
+ validate: 1,
1194
+ buildStart: 1,
1195
+ resolvePath: 1,
1196
+ resolveName: 1,
1197
+ load: 1,
1198
+ transform: 1,
1199
+ writeFile: 1,
1200
+ buildEnd: 1
1201
+ };
1202
+ var hooks = Object.keys(hookNames);
1274
1203
  var PluginManager = class {
1204
+ plugins;
1205
+ fileManager;
1206
+ eventEmitter = new EventEmitter();
1207
+ queue;
1208
+ executed = [];
1209
+ logger;
1210
+ #core;
1275
1211
  constructor(config, options) {
1276
- __privateAdd(this, _getSortedPlugins);
1277
- __privateAdd(this, _addExecutedToCallStack);
1278
- /**
1279
- * Run an async plugin hook and return the result.
1280
- * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
1281
- * @param args Arguments passed to the plugin hook.
1282
- * @param plugin The actual pluginObject to run.
1283
- */
1284
- // Implementation signature
1285
- __privateAdd(this, _execute);
1286
- /**
1287
- * Run a sync plugin hook and return the result.
1288
- * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
1289
- * @param args Arguments passed to the plugin hook.
1290
- * @param plugin The acutal plugin
1291
- * @param replaceContext When passed, the plugin context can be overridden.
1292
- */
1293
- __privateAdd(this, _executeSync);
1294
- __privateAdd(this, _catcher);
1295
- __privateAdd(this, _parse);
1296
- this.eventEmitter = new EventEmitter();
1297
- this.executed = [];
1298
- __privateAdd(this, _core, void 0);
1299
- __privateAdd(this, _usedPluginNames, {});
1300
- __privateAdd(this, _promiseManager, void 0);
1301
- this.resolvePath = (params) => {
1302
- if (params.pluginKey) {
1303
- const paths = this.hookForPluginSync({
1304
- pluginKey: params.pluginKey,
1305
- hookName: "resolvePath",
1306
- parameters: [params.baseName, params.directory, params.options]
1307
- });
1308
- if (paths && paths?.length > 1) {
1309
- throw new Error(
1310
- `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1311
-
1312
- Paths: ${JSON.stringify(paths, void 0, 2)}`
1313
- );
1314
- }
1315
- return paths?.at(0);
1316
- }
1317
- return this.hookFirstSync({
1318
- hookName: "resolvePath",
1319
- parameters: [params.baseName, params.directory, params.options]
1320
- }).result;
1321
- };
1322
- this.resolveName = (params) => {
1323
- if (params.pluginKey) {
1324
- const names = this.hookForPluginSync({
1325
- pluginKey: params.pluginKey,
1326
- hookName: "resolveName",
1327
- parameters: [params.name, params.type]
1328
- });
1329
- if (names && names?.length > 1) {
1330
- throw new Error(
1331
- `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1332
-
1333
- Names: ${JSON.stringify(names, void 0, 2)}`
1334
- );
1335
- }
1336
- return transformReservedWord(names?.at(0) || params.name);
1337
- }
1338
- const name = this.hookFirstSync({
1339
- hookName: "resolveName",
1340
- parameters: [params.name, params.type]
1341
- }).result;
1342
- return transformReservedWord(name);
1343
- };
1344
1212
  this.logger = options.logger;
1345
- this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
1346
- this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
1347
- __privateSet(this, _promiseManager, new PromiseManager());
1348
- const plugins = config.plugins || [];
1213
+ this.queue = new Queue(100, options.debug);
1214
+ this.fileManager = new FileManager({ task: options.task, queue: this.queue });
1349
1215
  const core = definePlugin({
1350
1216
  config,
1351
1217
  logger: this.logger,
@@ -1353,14 +1219,44 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1353
1219
  fileManager: this.fileManager,
1354
1220
  resolvePath: this.resolvePath.bind(this),
1355
1221
  resolveName: this.resolveName.bind(this),
1356
- getPlugins: __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).bind(this)
1357
- });
1358
- __privateSet(this, _core, __privateMethod(this, _parse, parse_fn).call(this, core, this, core.api.call(null)));
1359
- this.plugins = [__privateGet(this, _core), ...plugins].map((plugin) => {
1360
- return __privateMethod(this, _parse, parse_fn).call(this, plugin, this, __privateGet(this, _core).api);
1222
+ getPlugins: this.#getSortedPlugins.bind(this),
1223
+ plugin: void 0
1361
1224
  });
1225
+ this.#core = pluginParser(core, core.api.call(null));
1226
+ this.plugins = [this.#core, ...config.plugins || []].reduce((prev, plugin) => {
1227
+ const convertedApi = pluginParser(plugin, this.#core?.api);
1228
+ return [...prev, convertedApi];
1229
+ }, []);
1362
1230
  return this;
1363
1231
  }
1232
+ resolvePath = (params) => {
1233
+ if (params.pluginName) {
1234
+ return this.hookForPluginSync({
1235
+ pluginName: params.pluginName,
1236
+ hookName: "resolvePath",
1237
+ parameters: [params.baseName, params.directory, params.options]
1238
+ });
1239
+ }
1240
+ return this.hookFirstSync({
1241
+ hookName: "resolvePath",
1242
+ parameters: [params.baseName, params.directory, params.options]
1243
+ }).result;
1244
+ };
1245
+ resolveName = (params) => {
1246
+ if (params.pluginName) {
1247
+ const name2 = this.hookForPluginSync({
1248
+ pluginName: params.pluginName,
1249
+ hookName: "resolveName",
1250
+ parameters: [params.name, params.type]
1251
+ });
1252
+ return transformReservedWord(name2 || params.name);
1253
+ }
1254
+ const name = this.hookFirstSync({
1255
+ hookName: "resolveName",
1256
+ parameters: [params.name, params.type]
1257
+ }).result;
1258
+ return transformReservedWord(name);
1259
+ };
1364
1260
  on(eventName, handler) {
1365
1261
  this.eventEmitter.on(eventName, handler);
1366
1262
  }
@@ -1368,35 +1264,30 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1368
1264
  * Run only hook for a specific plugin name
1369
1265
  */
1370
1266
  hookForPlugin({
1371
- pluginKey,
1267
+ pluginName: pluginName2,
1372
1268
  hookName,
1373
1269
  parameters
1374
1270
  }) {
1375
- const plugins = this.getPluginsByKey(hookName, pluginKey);
1376
- const promises = plugins.map((plugin) => {
1377
- return __privateMethod(this, _execute, execute_fn).call(this, {
1378
- strategy: "hookFirst",
1379
- hookName,
1380
- parameters,
1381
- plugin
1382
- });
1383
- }).filter(Boolean);
1384
- return Promise.all(promises);
1271
+ const plugin = this.getPlugin(hookName, pluginName2);
1272
+ return this.#execute({
1273
+ strategy: "hookFirst",
1274
+ hookName,
1275
+ parameters,
1276
+ plugin
1277
+ });
1385
1278
  }
1386
1279
  hookForPluginSync({
1387
- pluginKey,
1280
+ pluginName: pluginName2,
1388
1281
  hookName,
1389
1282
  parameters
1390
1283
  }) {
1391
- const plugins = this.getPluginsByKey(hookName, pluginKey);
1392
- return plugins.map((plugin) => {
1393
- return __privateMethod(this, _executeSync, executeSync_fn).call(this, {
1394
- strategy: "hookFirst",
1395
- hookName,
1396
- parameters,
1397
- plugin
1398
- });
1399
- }).filter(Boolean);
1284
+ const plugin = this.getPlugin(hookName, pluginName2);
1285
+ return this.#executeSync({
1286
+ strategy: "hookFirst",
1287
+ hookName,
1288
+ parameters,
1289
+ plugin
1290
+ });
1400
1291
  }
1401
1292
  /**
1402
1293
  * Chains, first non-null result stops and returns
@@ -1407,7 +1298,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1407
1298
  skipped
1408
1299
  }) {
1409
1300
  let promise = Promise.resolve(null);
1410
- for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1301
+ for (const plugin of this.#getSortedPlugins()) {
1411
1302
  if (skipped && skipped.has(plugin)) {
1412
1303
  continue;
1413
1304
  }
@@ -1415,7 +1306,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1415
1306
  if (parseResult?.result != null) {
1416
1307
  return parseResult;
1417
1308
  }
1418
- const value = await __privateMethod(this, _execute, execute_fn).call(this, {
1309
+ const value = await this.#execute({
1419
1310
  strategy: "hookFirst",
1420
1311
  hookName,
1421
1312
  parameters,
@@ -1440,12 +1331,12 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1440
1331
  skipped
1441
1332
  }) {
1442
1333
  let parseResult = null;
1443
- for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1334
+ for (const plugin of this.#getSortedPlugins()) {
1444
1335
  if (skipped && skipped.has(plugin)) {
1445
1336
  continue;
1446
1337
  }
1447
1338
  parseResult = {
1448
- result: __privateMethod(this, _executeSync, executeSync_fn).call(this, {
1339
+ result: this.#executeSync({
1449
1340
  strategy: "hookFirst",
1450
1341
  hookName,
1451
1342
  parameters,
@@ -1467,8 +1358,8 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1467
1358
  parameters
1468
1359
  }) {
1469
1360
  const parallelPromises = [];
1470
- for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1471
- const promise = __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
1361
+ for (const plugin of this.#getSortedPlugins()) {
1362
+ const promise = this.#execute({ strategy: "hookParallel", hookName, parameters, plugin });
1472
1363
  if (promise) {
1473
1364
  parallelPromises.push(promise);
1474
1365
  }
@@ -1495,16 +1386,16 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1495
1386
  }) {
1496
1387
  const [argument0, ...rest] = parameters;
1497
1388
  let promise = Promise.resolve(argument0);
1498
- for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1389
+ for (const plugin of this.#getSortedPlugins()) {
1499
1390
  promise = promise.then((arg0) => {
1500
- const value = __privateMethod(this, _execute, execute_fn).call(this, {
1391
+ const value = this.#execute({
1501
1392
  strategy: "hookReduceArg0",
1502
1393
  hookName,
1503
1394
  parameters: [arg0, ...rest],
1504
1395
  plugin
1505
1396
  });
1506
1397
  return value;
1507
- }).then((result) => reduce.call(__privateGet(this, _core).api, argument0, result, plugin));
1398
+ }).then((result) => reduce.call(this.#core.api, argument0, result, plugin));
1508
1399
  }
1509
1400
  return promise;
1510
1401
  }
@@ -1512,192 +1403,160 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1512
1403
  * Chains plugins
1513
1404
  */
1514
1405
  hookSeq({ hookName, parameters }) {
1515
- const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
1516
- return () => __privateMethod(this, _execute, execute_fn).call(this, {
1517
- strategy: "hookSeq",
1518
- hookName,
1519
- parameters,
1520
- plugin
1406
+ let promise = Promise.resolve();
1407
+ for (const plugin of this.#getSortedPlugins()) {
1408
+ promise = promise.then(() => {
1409
+ this.#execute({
1410
+ strategy: "hookSeq",
1411
+ hookName,
1412
+ parameters,
1413
+ plugin
1414
+ });
1521
1415
  });
1522
- });
1523
- return __privateGet(this, _promiseManager).run("seq", promises);
1416
+ }
1417
+ return promise.then(noReturn);
1524
1418
  }
1525
- getPluginsByKey(hookName, pluginKey) {
1419
+ #getSortedPlugins(hookName) {
1420
+ const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
1421
+ if (hookName) {
1422
+ return plugins.filter((item) => item[hookName]);
1423
+ }
1424
+ return plugins;
1425
+ }
1426
+ getPlugin(hookName, pluginName2) {
1526
1427
  const plugins = [...this.plugins];
1527
- const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
1528
- const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
1529
- const [kind, name, identifier] = item.key;
1530
- const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
1531
- const kindCheck = kind === searchKind;
1532
- const nameCheck = name === searchPluginName;
1533
- if (searchIdentifier) {
1534
- return identifierCheck && kindCheck && nameCheck;
1535
- }
1536
- return kindCheck && nameCheck;
1537
- });
1538
- if (!pluginByPluginName?.length) {
1539
- const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
1540
- if (this.logger.logLevel === "info") {
1541
- if (corePlugin) {
1542
- this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
1543
- } else {
1544
- this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
1545
- }
1546
- }
1547
- return corePlugin ? [corePlugin] : [];
1428
+ const pluginByPluginName = plugins.find((item) => item.name === pluginName2 && item[hookName]);
1429
+ if (!pluginByPluginName) {
1430
+ return this.#core;
1548
1431
  }
1549
1432
  return pluginByPluginName;
1550
1433
  }
1551
- static getDependedPlugins(plugins, dependedPluginNames) {
1552
- let pluginNames = [];
1553
- if (typeof dependedPluginNames === "string") {
1554
- pluginNames = [dependedPluginNames];
1555
- } else {
1556
- pluginNames = dependedPluginNames;
1434
+ #addExecutedToCallStack(executer) {
1435
+ if (executer) {
1436
+ this.eventEmitter.emit("execute", executer);
1437
+ this.executed.push(executer);
1557
1438
  }
1558
- return pluginNames.map((pluginName2) => {
1559
- const plugin = plugins.find((plugin2) => plugin2.name === pluginName2);
1560
- if (!plugin) {
1561
- throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
1562
- }
1563
- return plugin;
1564
- });
1565
1439
  }
1566
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1567
- static get hooks() {
1568
- return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
1569
- }
1570
- };
1571
- _core = new WeakMap();
1572
- _usedPluginNames = new WeakMap();
1573
- _promiseManager = new WeakMap();
1574
- _getSortedPlugins = new WeakSet();
1575
- getSortedPlugins_fn = function(hookName) {
1576
- const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
1577
- if (hookName) {
1578
- if (this.logger.logLevel === "info") {
1579
- const containsHookName = plugins.some((item) => item[hookName]);
1580
- if (!containsHookName) {
1581
- this.logger.warn(`No hook ${hookName} found`);
1582
- }
1440
+ /**
1441
+ * Run an async plugin hook and return the result.
1442
+ * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
1443
+ * @param args Arguments passed to the plugin hook.
1444
+ * @param plugin The actual pluginObject to run.
1445
+ */
1446
+ // Implementation signature
1447
+ #execute({
1448
+ strategy,
1449
+ hookName,
1450
+ parameters,
1451
+ plugin
1452
+ }) {
1453
+ const hook = plugin[hookName];
1454
+ let output;
1455
+ if (!hook) {
1456
+ return null;
1583
1457
  }
1584
- return plugins.filter((item) => item[hookName]);
1585
- }
1586
- return plugins;
1587
- };
1588
- _addExecutedToCallStack = new WeakSet();
1589
- addExecutedToCallStack_fn = function(executer) {
1590
- if (executer) {
1591
- this.eventEmitter.emit("executed", executer);
1592
- this.executed.push(executer);
1593
- }
1594
- };
1595
- _execute = new WeakSet();
1596
- execute_fn = function({
1597
- strategy,
1598
- hookName,
1599
- parameters,
1600
- plugin
1601
- }) {
1602
- const hook = plugin[hookName];
1603
- let output;
1604
- if (!hook) {
1605
- return null;
1606
- }
1607
- this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1608
- const task = Promise.resolve().then(() => {
1609
- if (typeof hook === "function") {
1610
- const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
1611
- if (isPromise(possiblePromiseResult)) {
1612
- return Promise.resolve(possiblePromiseResult);
1458
+ this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1459
+ const task = Promise.resolve().then(() => {
1460
+ if (typeof hook === "function") {
1461
+ const possiblePromiseResult = hook.apply({ ...this.#core.api, plugin }, parameters);
1462
+ if (isPromise(possiblePromiseResult)) {
1463
+ return Promise.resolve(possiblePromiseResult);
1464
+ }
1465
+ return possiblePromiseResult;
1613
1466
  }
1614
- return possiblePromiseResult;
1615
- }
1616
- return hook;
1617
- }).then((result) => {
1618
- output = result;
1619
- return result;
1620
- }).catch((e) => {
1621
- __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1622
- return null;
1623
- }).finally(() => {
1624
- __privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
1625
- parameters,
1626
- output,
1627
- strategy,
1628
- hookName,
1629
- plugin
1467
+ return hook;
1468
+ }).then((result) => {
1469
+ output = result;
1470
+ return result;
1471
+ }).catch((e) => {
1472
+ this.#catcher(e, plugin, hookName);
1473
+ return null;
1474
+ }).finally(() => {
1475
+ this.#addExecutedToCallStack({
1476
+ parameters,
1477
+ output,
1478
+ strategy,
1479
+ hookName,
1480
+ plugin
1481
+ });
1630
1482
  });
1631
- });
1632
- return task;
1633
- };
1634
- _executeSync = new WeakSet();
1635
- executeSync_fn = function({
1636
- strategy,
1637
- hookName,
1638
- parameters,
1639
- plugin
1640
- }) {
1641
- const hook = plugin[hookName];
1642
- let output;
1643
- if (!hook) {
1644
- return null;
1483
+ return task;
1645
1484
  }
1646
- this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1647
- try {
1648
- if (typeof hook === "function") {
1649
- const fn = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
1650
- output = fn;
1651
- return fn;
1485
+ /**
1486
+ * Run a sync plugin hook and return the result.
1487
+ * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
1488
+ * @param args Arguments passed to the plugin hook.
1489
+ * @param plugin The acutal plugin
1490
+ * @param replaceContext When passed, the plugin context can be overridden.
1491
+ */
1492
+ #executeSync({
1493
+ strategy,
1494
+ hookName,
1495
+ parameters,
1496
+ plugin
1497
+ }) {
1498
+ const hook = plugin[hookName];
1499
+ let output;
1500
+ if (!hook) {
1501
+ return null;
1502
+ }
1503
+ this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1504
+ try {
1505
+ if (typeof hook === "function") {
1506
+ const fn = hook.apply(this.#core.api, parameters);
1507
+ output = fn;
1508
+ return fn;
1509
+ }
1510
+ output = hook;
1511
+ return hook;
1512
+ } catch (e) {
1513
+ this.#catcher(e, plugin, hookName);
1514
+ return null;
1515
+ } finally {
1516
+ this.#addExecutedToCallStack({
1517
+ parameters,
1518
+ output,
1519
+ strategy,
1520
+ hookName,
1521
+ plugin
1522
+ });
1652
1523
  }
1653
- output = hook;
1654
- return hook;
1655
- } catch (e) {
1656
- __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1657
- return null;
1658
- } finally {
1659
- __privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
1660
- parameters,
1661
- output,
1662
- strategy,
1663
- hookName,
1664
- plugin
1665
- });
1666
1524
  }
1667
- };
1668
- _catcher = new WeakSet();
1669
- catcher_fn = function(e, plugin, hookName) {
1670
- const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
1525
+ #catcher(e, plugin, hookName) {
1526
+ const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
1671
1527
  `;
1672
- const pluginError = new PluginError(text, { cause: e, pluginManager: this });
1673
- this.eventEmitter.emit("error", pluginError);
1674
- throw pluginError;
1675
- };
1676
- _parse = new WeakSet();
1677
- parse_fn = function(plugin, pluginManager, context) {
1678
- const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
1679
- setUniqueName(plugin.name, usedPluginNames);
1680
- const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
1681
- if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
1682
- pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
1683
- }
1684
- if (!plugin.transform) {
1685
- plugin.transform = function transform(code) {
1686
- return code;
1687
- };
1688
- }
1689
- if (plugin.api && typeof plugin.api === "function") {
1690
- const api = plugin.api.call(context);
1691
- return {
1692
- ...plugin,
1693
- key,
1694
- api
1695
- };
1528
+ const pluginError = new PluginError(text, { cause: e, pluginManager: this });
1529
+ this.eventEmitter.emit("error", pluginError);
1530
+ throw pluginError;
1696
1531
  }
1697
- return {
1698
- ...plugin,
1699
- key
1700
- };
1532
+ };
1533
+ function noReturn() {
1534
+ }
1535
+
1536
+ // src/managers/pluginManager/validate.ts
1537
+ var ValidationPluginError = class extends Error {
1538
+ };
1539
+ function getDependedPlugins(plugins, dependedPluginNames) {
1540
+ let pluginNames = [];
1541
+ if (typeof dependedPluginNames === "string") {
1542
+ pluginNames = [dependedPluginNames];
1543
+ } else {
1544
+ pluginNames = dependedPluginNames;
1545
+ }
1546
+ return pluginNames.map((pluginName2) => {
1547
+ const plugin = plugins.find((plugin2) => plugin2.name === pluginName2);
1548
+ if (!plugin) {
1549
+ throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
1550
+ }
1551
+ return plugin;
1552
+ });
1553
+ }
1554
+
1555
+ // src/types.ts
1556
+ var LogLevel = {
1557
+ silent: "silent",
1558
+ info: "info",
1559
+ debug: "debug"
1701
1560
  };
1702
1561
 
1703
1562
  // src/build.ts
@@ -1705,13 +1564,13 @@ async function transformReducer(_previousCode, result, _plugin) {
1705
1564
  return result;
1706
1565
  }
1707
1566
  async function build(options) {
1708
- const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
1567
+ const { config, logLevel, logger = createLogger() } = options;
1709
1568
  try {
1710
- if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
1569
+ if ("path" in config.input && !new URLPath(config.input.path).isURL) {
1711
1570
  await read(config.input.path);
1712
1571
  }
1713
1572
  } catch (e) {
1714
- if (isInputPath(config)) {
1573
+ if ("path" in config.input) {
1715
1574
  throw new Error(
1716
1575
  "Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config " + pc3__default.default.dim(config.input.path),
1717
1576
  {
@@ -1724,11 +1583,11 @@ async function build(options) {
1724
1583
  await clean(config.output.path);
1725
1584
  }
1726
1585
  const queueTask = async (file) => {
1727
- const { path: path5 } = file;
1728
- let code = FileManager.getSource(file);
1586
+ const { path: path3 } = file;
1587
+ let code = createFileSource(file);
1729
1588
  const { result: loadedResult } = await pluginManager.hookFirst({
1730
1589
  hookName: "load",
1731
- parameters: [path5]
1590
+ parameters: [path3]
1732
1591
  });
1733
1592
  if (loadedResult && isPromise(loadedResult)) {
1734
1593
  code = await loadedResult;
@@ -1739,53 +1598,28 @@ async function build(options) {
1739
1598
  if (code) {
1740
1599
  const transformedCode = await pluginManager.hookReduceArg0({
1741
1600
  hookName: "transform",
1742
- parameters: [code, path5],
1601
+ parameters: [code, path3],
1743
1602
  reduce: transformReducer
1744
1603
  });
1745
1604
  if (config.output.write || config.output.write === void 0) {
1746
- if (file.meta?.pluginKey) {
1747
- return pluginManager.hookForPlugin({
1748
- pluginKey: file.meta?.pluginKey,
1749
- hookName: "writeFile",
1750
- parameters: [transformedCode, path5]
1751
- });
1752
- }
1753
- return pluginManager.hookFirst({
1605
+ await pluginManager.hookParallel({
1754
1606
  hookName: "writeFile",
1755
- parameters: [transformedCode, path5]
1607
+ parameters: [transformedCode, path3]
1756
1608
  });
1757
1609
  }
1758
1610
  }
1759
1611
  };
1760
- const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
1612
+ const pluginManager = new PluginManager(config, { debug: logLevel === LogLevel.debug, logger, task: queueTask });
1761
1613
  const { plugins, fileManager } = pluginManager;
1762
1614
  pluginManager.on("execute", (executer) => {
1763
- const { hookName, parameters, plugin } = executer;
1764
- if (hookName === "writeFile" && logger.spinner) {
1765
- const [code] = parameters;
1766
- if (logger.logLevel === LogLevel.info) {
1767
- logger.spinner.start(`\u{1F4BE} Writing`);
1768
- }
1769
- if (logger.logLevel === "debug") {
1770
- logger.info(`PluginKey ${pc3__default.default.dim(JSON.stringify(plugin.key))}
1771
- with source
1772
-
1773
- ${code}`);
1774
- }
1775
- }
1776
- });
1777
- pluginManager.on("executed", (executer) => {
1778
1615
  const { hookName, plugin, output, parameters } = executer;
1779
1616
  const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
1780
- if (logger.logLevel === LogLevel.info && logger.spinner) {
1781
- if (hookName === "writeFile") {
1782
- const [_code, path5] = parameters;
1783
- logger.spinner.suffixText = pc3__default.default.dim(path5);
1784
- } else {
1617
+ if (logLevel === LogLevel.info) {
1618
+ if (logger.spinner) {
1785
1619
  logger.spinner.suffixText = messsage;
1786
1620
  }
1787
1621
  }
1788
- if (logger.logLevel === LogLevel.debug) {
1622
+ if (logLevel === LogLevel.debug) {
1789
1623
  logger.info(messsage);
1790
1624
  const logs = [
1791
1625
  parameters && `${pc3__default.default.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
@@ -1805,95 +1639,93 @@ ${code}`);
1805
1639
  parameters: [config]
1806
1640
  });
1807
1641
  await pluginManager.hookParallel({ hookName: "buildEnd" });
1808
- if (!fileManager.isExecuting && logger.spinner) {
1809
- logger.spinner.suffixText = "";
1810
- logger.spinner.succeed(`\u{1F4BE} Writing completed`);
1811
- }
1812
- return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
1642
+ return { files: fileManager.files.map((file) => ({ ...file, source: createFileSource(file) })), pluginManager };
1643
+ }
1644
+
1645
+ // src/config.ts
1646
+ function defineConfig(options) {
1647
+ return options;
1813
1648
  }
1814
1649
 
1815
- // src/Generator.ts
1816
- var _options3, _context;
1650
+ // src/generators/Generator.ts
1817
1651
  var Generator = class {
1652
+ #options = {};
1653
+ #context = {};
1818
1654
  constructor(options, context) {
1819
- __privateAdd(this, _options3, {});
1820
- __privateAdd(this, _context, {});
1821
1655
  if (context) {
1822
- __privateSet(this, _context, context);
1656
+ this.#context = context;
1823
1657
  }
1824
1658
  if (options) {
1825
- __privateSet(this, _options3, options);
1659
+ this.#options = options;
1826
1660
  }
1827
1661
  return this;
1828
1662
  }
1829
1663
  get options() {
1830
- return __privateGet(this, _options3);
1664
+ return this.#options;
1831
1665
  }
1832
1666
  get context() {
1833
- return __privateGet(this, _context);
1667
+ return this.#context;
1834
1668
  }
1835
1669
  set options(options) {
1836
- __privateSet(this, _options3, { ...__privateGet(this, _options3), ...options });
1670
+ this.#options = { ...this.#options, ...options };
1837
1671
  }
1838
1672
  };
1839
- _options3 = new WeakMap();
1840
- _context = new WeakMap();
1673
+
1674
+ // src/generators/SchemaGenerator.ts
1675
+ var SchemaGenerator = class extends Generator {
1676
+ };
1841
1677
 
1842
1678
  // ../../node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
1843
1679
  var Node = class {
1680
+ value;
1681
+ next;
1844
1682
  constructor(value) {
1845
- __publicField(this, "value");
1846
- __publicField(this, "next");
1847
1683
  this.value = value;
1848
1684
  }
1849
1685
  };
1850
- var _head, _tail, _size;
1851
1686
  var Queue2 = class {
1687
+ #head;
1688
+ #tail;
1689
+ #size;
1852
1690
  constructor() {
1853
- __privateAdd(this, _head, void 0);
1854
- __privateAdd(this, _tail, void 0);
1855
- __privateAdd(this, _size, void 0);
1856
1691
  this.clear();
1857
1692
  }
1858
1693
  enqueue(value) {
1859
1694
  const node = new Node(value);
1860
- if (__privateGet(this, _head)) {
1861
- __privateGet(this, _tail).next = node;
1862
- __privateSet(this, _tail, node);
1695
+ if (this.#head) {
1696
+ this.#tail.next = node;
1697
+ this.#tail = node;
1863
1698
  } else {
1864
- __privateSet(this, _head, node);
1865
- __privateSet(this, _tail, node);
1699
+ this.#head = node;
1700
+ this.#tail = node;
1866
1701
  }
1867
- __privateWrapper(this, _size)._++;
1702
+ this.#size++;
1868
1703
  }
1869
1704
  dequeue() {
1870
- const current = __privateGet(this, _head);
1705
+ const current = this.#head;
1871
1706
  if (!current) {
1872
1707
  return;
1873
1708
  }
1874
- __privateSet(this, _head, __privateGet(this, _head).next);
1875
- __privateWrapper(this, _size)._--;
1709
+ this.#head = this.#head.next;
1710
+ this.#size--;
1876
1711
  return current.value;
1877
1712
  }
1878
1713
  clear() {
1879
- __privateSet(this, _head, void 0);
1880
- __privateSet(this, _tail, void 0);
1881
- __privateSet(this, _size, 0);
1714
+ this.#head = void 0;
1715
+ this.#tail = void 0;
1716
+ this.#size = 0;
1882
1717
  }
1883
1718
  get size() {
1884
- return __privateGet(this, _size);
1719
+ return this.#size;
1885
1720
  }
1886
1721
  *[Symbol.iterator]() {
1887
- let current = __privateGet(this, _head);
1722
+ let current = this.#head;
1888
1723
  while (current) {
1889
1724
  yield current.value;
1890
1725
  current = current.next;
1891
1726
  }
1892
1727
  }
1893
1728
  };
1894
- _head = new WeakMap();
1895
- _tail = new WeakMap();
1896
- _size = new WeakMap();
1897
1729
 
1898
1730
  // ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
1899
1731
  function pLimit(concurrency) {
@@ -1908,18 +1740,18 @@ function pLimit(concurrency) {
1908
1740
  queue.dequeue()();
1909
1741
  }
1910
1742
  };
1911
- const run = async (fn, resolve2, args) => {
1743
+ const run = async (fn, resolve, args) => {
1912
1744
  activeCount++;
1913
1745
  const result = (async () => fn(...args))();
1914
- resolve2(result);
1746
+ resolve(result);
1915
1747
  try {
1916
1748
  await result;
1917
1749
  } catch {
1918
1750
  }
1919
1751
  next();
1920
1752
  };
1921
- const enqueue = (fn, resolve2, args) => {
1922
- queue.enqueue(run.bind(void 0, fn, resolve2, args));
1753
+ const enqueue = (fn, resolve, args) => {
1754
+ queue.enqueue(run.bind(void 0, fn, resolve, args));
1923
1755
  (async () => {
1924
1756
  await Promise.resolve();
1925
1757
  if (activeCount < concurrency && queue.size > 0) {
@@ -1927,8 +1759,8 @@ function pLimit(concurrency) {
1927
1759
  }
1928
1760
  })();
1929
1761
  };
1930
- const generator = (fn, ...args) => new Promise((resolve2) => {
1931
- enqueue(fn, resolve2, args);
1762
+ const generator = (fn, ...args) => new Promise((resolve) => {
1763
+ enqueue(fn, resolve, args);
1932
1764
  });
1933
1765
  Object.defineProperties(generator, {
1934
1766
  activeCount: {
@@ -2003,7 +1835,7 @@ async function locatePath(paths, {
2003
1835
  const statFunction = allowSymlinks ? fs3.promises.stat : fs3.promises.lstat;
2004
1836
  return pLocate(paths, async (path_) => {
2005
1837
  try {
2006
- const stat = await statFunction(path4__default.default.resolve(cwd, path_));
1838
+ const stat = await statFunction(path2__default.default.resolve(cwd, path_));
2007
1839
  return matchType(type, stat);
2008
1840
  } catch {
2009
1841
  return false;
@@ -2020,7 +1852,7 @@ function locatePathSync(paths, {
2020
1852
  const statFunction = allowSymlinks ? fs3__default.default.statSync : fs3__default.default.lstatSync;
2021
1853
  for (const path_ of paths) {
2022
1854
  try {
2023
- const stat = statFunction(path4__default.default.resolve(cwd, path_), {
1855
+ const stat = statFunction(path2__default.default.resolve(cwd, path_), {
2024
1856
  throwIfNoEntry: false
2025
1857
  });
2026
1858
  if (!stat) {
@@ -2038,9 +1870,9 @@ function locatePathSync(paths, {
2038
1870
  var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? url.fileURLToPath(urlOrPath) : urlOrPath;
2039
1871
  var findUpStop = Symbol("findUpStop");
2040
1872
  async function findUpMultiple(name, options = {}) {
2041
- let directory = path4__default.default.resolve(toPath2(options.cwd) || "");
2042
- const { root } = path4__default.default.parse(directory);
2043
- const stopAt = path4__default.default.resolve(directory, options.stopAt || root);
1873
+ let directory = path2__default.default.resolve(toPath2(options.cwd) || "");
1874
+ const { root } = path2__default.default.parse(directory);
1875
+ const stopAt = path2__default.default.resolve(directory, options.stopAt || root);
2044
1876
  const limit = options.limit || Number.POSITIVE_INFINITY;
2045
1877
  const paths = [name].flat();
2046
1878
  const runMatcher = async (locateOptions) => {
@@ -2060,18 +1892,18 @@ async function findUpMultiple(name, options = {}) {
2060
1892
  break;
2061
1893
  }
2062
1894
  if (foundPath) {
2063
- matches.push(path4__default.default.resolve(directory, foundPath));
1895
+ matches.push(path2__default.default.resolve(directory, foundPath));
2064
1896
  }
2065
1897
  if (directory === stopAt || matches.length >= limit) {
2066
1898
  break;
2067
1899
  }
2068
- directory = path4__default.default.dirname(directory);
1900
+ directory = path2__default.default.dirname(directory);
2069
1901
  }
2070
1902
  return matches;
2071
1903
  }
2072
1904
  function findUpMultipleSync(name, options = {}) {
2073
- let directory = path4__default.default.resolve(toPath2(options.cwd) || "");
2074
- const { root } = path4__default.default.parse(directory);
1905
+ let directory = path2__default.default.resolve(toPath2(options.cwd) || "");
1906
+ const { root } = path2__default.default.parse(directory);
2075
1907
  const stopAt = options.stopAt || root;
2076
1908
  const limit = options.limit || Number.POSITIVE_INFINITY;
2077
1909
  const paths = [name].flat();
@@ -2092,12 +1924,12 @@ function findUpMultipleSync(name, options = {}) {
2092
1924
  break;
2093
1925
  }
2094
1926
  if (foundPath) {
2095
- matches.push(path4__default.default.resolve(directory, foundPath));
1927
+ matches.push(path2__default.default.resolve(directory, foundPath));
2096
1928
  }
2097
1929
  if (directory === stopAt || matches.length >= limit) {
2098
1930
  break;
2099
1931
  }
2100
- directory = path4__default.default.dirname(directory);
1932
+ directory = path2__default.default.dirname(directory);
2101
1933
  }
2102
1934
  return matches;
2103
1935
  }
@@ -2109,39 +1941,39 @@ function findUpSync(name, options = {}) {
2109
1941
  const matches = findUpMultipleSync(name, { ...options, limit: 1 });
2110
1942
  return matches[0];
2111
1943
  }
2112
- var _cache2, _cwd, _SLASHES;
2113
- var _PackageManager = class _PackageManager {
1944
+ var PackageManager = class _PackageManager {
1945
+ static #cache = {};
1946
+ #cwd;
1947
+ #SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
2114
1948
  constructor(workspace) {
2115
- __privateAdd(this, _cwd, void 0);
2116
- __privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
2117
1949
  if (workspace) {
2118
- __privateSet(this, _cwd, workspace);
1950
+ this.#cwd = workspace;
2119
1951
  }
2120
1952
  return this;
2121
1953
  }
2122
1954
  set workspace(workspace) {
2123
- __privateSet(this, _cwd, workspace);
1955
+ this.#cwd = workspace;
2124
1956
  }
2125
1957
  get workspace() {
2126
- return __privateGet(this, _cwd);
1958
+ return this.#cwd;
2127
1959
  }
2128
1960
  normalizeDirectory(directory) {
2129
- if (!__privateGet(this, _SLASHES).has(directory[directory.length - 1])) {
1961
+ if (!this.#SLASHES.has(directory[directory.length - 1])) {
2130
1962
  return `${directory}/`;
2131
1963
  }
2132
1964
  return directory;
2133
1965
  }
2134
- getLocation(path5) {
2135
- let location = path5;
2136
- if (__privateGet(this, _cwd)) {
2137
- const require2 = mod__default.default.createRequire(this.normalizeDirectory(__privateGet(this, _cwd)));
2138
- location = require2.resolve(path5);
1966
+ getLocation(path3) {
1967
+ let location = path3;
1968
+ if (this.#cwd) {
1969
+ const require2 = mod__default.default.createRequire(this.normalizeDirectory(this.#cwd));
1970
+ location = require2.resolve(path3);
2139
1971
  }
2140
1972
  return location;
2141
1973
  }
2142
- async import(path5) {
1974
+ async import(path3) {
2143
1975
  try {
2144
- let location = this.getLocation(path5);
1976
+ let location = this.getLocation(path3);
2145
1977
  if (os__default.default.platform() == "win32") {
2146
1978
  location = url.pathToFileURL(location).href;
2147
1979
  }
@@ -2154,7 +1986,7 @@ var _PackageManager = class _PackageManager {
2154
1986
  }
2155
1987
  async getPackageJSON() {
2156
1988
  const pkgPath = await findUp(["package.json"], {
2157
- cwd: __privateGet(this, _cwd)
1989
+ cwd: this.#cwd
2158
1990
  });
2159
1991
  if (!pkgPath) {
2160
1992
  return void 0;
@@ -2163,7 +1995,7 @@ var _PackageManager = class _PackageManager {
2163
1995
  }
2164
1996
  getPackageJSONSync() {
2165
1997
  const pkgPath = findUpSync(["package.json"], {
2166
- cwd: __privateGet(this, _cwd)
1998
+ cwd: this.#cwd
2167
1999
  });
2168
2000
  if (!pkgPath) {
2169
2001
  return void 0;
@@ -2171,11 +2003,11 @@ var _PackageManager = class _PackageManager {
2171
2003
  return __require(pkgPath);
2172
2004
  }
2173
2005
  static setVersion(dependency, version) {
2174
- __privateGet(_PackageManager, _cache2)[dependency] = version;
2006
+ _PackageManager.#cache[dependency] = version;
2175
2007
  }
2176
2008
  async getVersion(dependency) {
2177
- if (__privateGet(_PackageManager, _cache2)[dependency]) {
2178
- return __privateGet(_PackageManager, _cache2)[dependency];
2009
+ if (_PackageManager.#cache[dependency]) {
2010
+ return _PackageManager.#cache[dependency];
2179
2011
  }
2180
2012
  const packageJSON = await this.getPackageJSON();
2181
2013
  if (!packageJSON) {
@@ -2184,8 +2016,8 @@ var _PackageManager = class _PackageManager {
2184
2016
  return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
2185
2017
  }
2186
2018
  getVersionSync(dependency) {
2187
- if (__privateGet(_PackageManager, _cache2)[dependency]) {
2188
- return __privateGet(_PackageManager, _cache2)[dependency];
2019
+ if (_PackageManager.#cache[dependency]) {
2020
+ return _PackageManager.#cache[dependency];
2189
2021
  }
2190
2022
  const packageJSON = this.getPackageJSONSync();
2191
2023
  if (!packageJSON) {
@@ -2216,38 +2048,68 @@ var _PackageManager = class _PackageManager {
2216
2048
  return semver.satisfies(semVer, version);
2217
2049
  }
2218
2050
  };
2219
- _cache2 = new WeakMap();
2220
- _cwd = new WeakMap();
2221
- _SLASHES = new WeakMap();
2222
- __privateAdd(_PackageManager, _cache2, {});
2223
- var PackageManager = _PackageManager;
2224
-
2225
- // src/SchemaGenerator.ts
2226
- var SchemaGenerator = class extends Generator {
2227
- };
2228
2051
 
2229
2052
  // src/index.ts
2230
2053
  var src_default = build;
2231
2054
 
2055
+ Object.defineProperty(exports, 'pc', {
2056
+ enumerable: true,
2057
+ get: function () { return pc3__default.default; }
2058
+ });
2232
2059
  exports.FileManager = FileManager;
2060
+ exports.FunctionParams = FunctionParams;
2233
2061
  exports.Generator = Generator;
2062
+ exports.LogLevel = LogLevel;
2234
2063
  exports.PackageManager = PackageManager;
2235
2064
  exports.ParallelPluginError = ParallelPluginError;
2236
2065
  exports.PluginError = PluginError;
2237
2066
  exports.PluginManager = PluginManager;
2238
- exports.PromiseManager = PromiseManager;
2067
+ exports.Queue = Queue;
2239
2068
  exports.SchemaGenerator = SchemaGenerator;
2240
2069
  exports.SummaryError = SummaryError;
2070
+ exports.TreeNode = TreeNode;
2071
+ exports.URLPath = URLPath;
2241
2072
  exports.ValidationPluginError = ValidationPluginError;
2242
2073
  exports.Warning = Warning;
2243
2074
  exports.build = build;
2075
+ exports.clean = clean;
2076
+ exports.combineCodes = combineCodes;
2244
2077
  exports.combineExports = combineExports;
2078
+ exports.combineFiles = combineFiles;
2245
2079
  exports.combineImports = combineImports;
2080
+ exports.createFileSource = createFileSource;
2081
+ exports.createJSDocBlockText = createJSDocBlockText;
2082
+ exports.createLogger = createLogger;
2246
2083
  exports.createPlugin = createPlugin;
2084
+ exports.createPluginCache = createPluginCache;
2247
2085
  exports.default = src_default;
2086
+ exports.defaultColours = defaultColours;
2248
2087
  exports.defineConfig = defineConfig;
2249
- exports.isInputPath = isInputPath;
2088
+ exports.escape = escape;
2089
+ exports.extensions = extensions;
2090
+ exports.getDependedPlugins = getDependedPlugins;
2091
+ exports.getIndexes = getIndexes;
2092
+ exports.getPathMode = getPathMode;
2093
+ exports.getRelativePath = getRelativePath;
2094
+ exports.getUniqueName = getUniqueName;
2095
+ exports.hooks = hooks;
2096
+ exports.isExtensionAllowed = isExtensionAllowed;
2097
+ exports.isPromise = isPromise;
2098
+ exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
2099
+ exports.isPromiseRejectedResult = isPromiseRejectedResult;
2100
+ exports.jsStringEscape = jsStringEscape;
2250
2101
  exports.name = pluginName;
2102
+ exports.nameSorter = nameSorter;
2251
2103
  exports.pluginName = pluginName;
2104
+ exports.randomColour = randomColour;
2105
+ exports.randomPicoColour = randomPicoColour;
2106
+ exports.read = read;
2107
+ exports.readSync = readSync;
2108
+ exports.renderTemplate = renderTemplate;
2109
+ exports.throttle = throttle;
2110
+ exports.timeout = timeout;
2111
+ exports.transformReservedWord = transformReservedWord;
2112
+ exports.uniqueIdFactory = uniqueIdFactory;
2113
+ exports.write = write;
2252
2114
  //# sourceMappingURL=out.js.map
2253
2115
  //# sourceMappingURL=index.cjs.map