@kubb/core 2.0.0-beta.1 → 2.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/index.cjs +292 -240
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +61 -61
  4. package/dist/index.d.ts +61 -61
  5. package/dist/index.js +289 -236
  6. package/dist/index.js.map +1 -1
  7. package/dist/transformers.cjs +222 -0
  8. package/dist/transformers.cjs.map +1 -0
  9. package/dist/transformers.d.cts +55 -0
  10. package/dist/transformers.d.ts +55 -0
  11. package/dist/transformers.js +207 -0
  12. package/dist/transformers.js.map +1 -0
  13. package/dist/utils.cjs +302 -274
  14. package/dist/utils.cjs.map +1 -1
  15. package/dist/utils.d.cts +515 -67
  16. package/dist/utils.d.ts +515 -67
  17. package/dist/utils.js +303 -274
  18. package/dist/utils.js.map +1 -1
  19. package/package.json +14 -9
  20. package/src/BarrelManager.ts +55 -65
  21. package/src/FileManager.ts +93 -24
  22. package/src/PluginManager.ts +35 -17
  23. package/src/build.ts +1 -11
  24. package/src/index.ts +0 -1
  25. package/src/plugin.ts +4 -4
  26. package/src/transformers/casing.ts +9 -0
  27. package/src/transformers/createJSDocBlockText.ts +9 -0
  28. package/src/transformers/index.ts +36 -0
  29. package/src/transformers/trim.ts +7 -0
  30. package/src/types.ts +22 -41
  31. package/src/utils/FunctionParams.ts +3 -2
  32. package/src/utils/TreeNode.ts +6 -3
  33. package/src/utils/URLPath.ts +5 -5
  34. package/src/utils/index.ts +0 -1
  35. package/src/SchemaGenerator.ts +0 -8
  36. package/src/utils/transformers/createJSDocBlockText.ts +0 -15
  37. package/src/utils/transformers/index.ts +0 -22
  38. package/src/utils/transformers/trim.ts +0 -3
  39. /package/src/{utils/transformers → transformers}/combineCodes.ts +0 -0
  40. /package/src/{utils/transformers → transformers}/escape.ts +0 -0
  41. /package/src/{utils/transformers → transformers}/indent.ts +0 -0
  42. /package/src/{utils/transformers → transformers}/nameSorter.ts +0 -0
  43. /package/src/{utils/transformers → transformers}/searchAndReplace.ts +0 -0
  44. /package/src/{utils/transformers → transformers}/transformReservedWord.ts +0 -0
package/dist/index.js CHANGED
@@ -2,10 +2,10 @@ import mod, { createRequire } from 'module';
2
2
  import pc3 from 'picocolors';
3
3
  import fs2, { remove } from 'fs-extra';
4
4
  import seedrandom from 'seedrandom';
5
+ import path, { resolve, dirname, extname, relative, basename } from 'path';
5
6
  import { switcher } from 'js-runtime';
6
- import { camelCase, camelCaseTransformMerge } from 'change-case';
7
+ import { camelCase as camelCase$1, camelCaseTransformMerge, pascalCase as pascalCase$1, pascalCaseTransformMerge } from 'change-case';
7
8
  import crypto2 from 'crypto';
8
- import path, { resolve, dirname, extname } from 'path';
9
9
  import { print } from '@kubb/parser';
10
10
  import * as factory from '@kubb/parser/factory';
11
11
  import isEqual from 'lodash.isequal';
@@ -128,6 +128,24 @@ function randomPicoColour(text, colors = defaultColours) {
128
128
  }
129
129
  return formatter(text);
130
130
  }
131
+ function slash(path3, platform = "linux") {
132
+ const isWindowsPath = /^\\\\\?\\/.test(path3);
133
+ if (["linux", "mac"].includes(platform) && !isWindowsPath) {
134
+ return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
135
+ }
136
+ return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
137
+ }
138
+ function getRelativePath(rootDir, filePath, platform = "linux") {
139
+ if (!rootDir || !filePath) {
140
+ throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
141
+ }
142
+ const relativePath = relative(rootDir, filePath);
143
+ const slashedPath = slash(relativePath, platform);
144
+ if (slashedPath.startsWith("../")) {
145
+ return slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)));
146
+ }
147
+ return `./${slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)))}`;
148
+ }
131
149
  var reader = switcher(
132
150
  {
133
151
  node: async (path3) => {
@@ -154,141 +172,30 @@ switcher(
154
172
  async function read(path3) {
155
173
  return reader(path3);
156
174
  }
157
- var URLPath = class {
158
- constructor(path3) {
159
- this.path = path3;
160
- return this;
161
- }
162
- /**
163
- * Convert Swagger path to URLPath(syntax of Express)
164
- * @example /pet/{petId} => /pet/:petId
165
- */
166
- get URL() {
167
- return this.toURLPath();
168
- }
169
- get isURL() {
170
- try {
171
- const url = new URL(this.path);
172
- if (url?.href) {
173
- return true;
174
- }
175
- } catch (error) {
176
- return false;
177
- }
178
- return false;
179
- }
180
- /**
181
- * Convert Swagger path to template literals/ template strings(camelcase)
182
- * @example /pet/{petId} => `/pet/${petId}`
183
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
184
- * @example /account/userID => `/account/${userId}`
185
- */
186
- get template() {
187
- return this.toTemplateString();
188
- }
189
- get object() {
190
- return this.toObject();
191
- }
192
- get params() {
193
- return this.getParams();
194
- }
195
- toObject({ type = "path", replacer, stringify } = {}) {
196
- const object = {
197
- url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
198
- params: this.getParams()
199
- };
200
- if (stringify) {
201
- if (type === "template") {
202
- return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
203
- }
204
- if (object.params) {
205
- return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
206
- }
207
- return `{ url: '${object.url}' }`;
208
- }
209
- return object;
210
- }
211
- /**
212
- * Convert Swagger path to template literals/ template strings(camelcase)
213
- * @example /pet/{petId} => `/pet/${petId}`
214
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
215
- * @example /account/userID => `/account/${userId}`
216
- */
217
- toTemplateString(replacer) {
218
- const regex = /{(\w|-)*}/g;
219
- const found = this.path.match(regex);
220
- let newPath = this.path.replaceAll("{", "${");
221
- if (found) {
222
- newPath = found.reduce((prev, curr) => {
223
- const pathParam = replacer ? replacer(camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge })) : camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge });
224
- const replacement = `\${${pathParam}}`;
225
- return prev.replace(curr, replacement);
226
- }, this.path);
227
- }
228
- return `\`${newPath}\``;
229
- }
230
- getParams(replacer) {
231
- const regex = /{(\w|-)*}/g;
232
- const found = this.path.match(regex);
233
- if (!found) {
234
- return void 0;
235
- }
236
- const params = {};
237
- found.forEach((item) => {
238
- item = item.replaceAll("{", "").replaceAll("}", "");
239
- const pathParam = replacer ? replacer(camelCase(item, { delimiter: "", transform: camelCaseTransformMerge })) : camelCase(item, { delimiter: "", transform: camelCaseTransformMerge });
240
- params[pathParam] = pathParam;
241
- }, this.path);
242
- return params;
243
- }
244
- /**
245
- * Convert Swagger path to URLPath(syntax of Express)
246
- * @example /pet/{petId} => /pet/:petId
247
- */
248
- toURLPath() {
249
- return this.path.replaceAll("{", ":").replaceAll("}", "");
250
- }
251
- };
252
-
253
- // src/config.ts
254
- function defineConfig(options) {
255
- return options;
256
- }
257
- function isInputPath(result) {
258
- return !!result && "path" in result;
175
+ function camelCase(text) {
176
+ return camelCase$1(text, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: camelCaseTransformMerge });
259
177
  }
260
-
261
- // src/utils/timeout.ts
262
- async function timeout(ms) {
263
- return new Promise((resolve2) => {
264
- setTimeout(() => {
265
- resolve2(true);
266
- }, ms);
267
- });
178
+ function pascalCase(text) {
179
+ return pascalCase$1(text, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge });
268
180
  }
269
181
 
270
- // src/utils/transformers/combineCodes.ts
182
+ // src/transformers/combineCodes.ts
271
183
  function combineCodes(codes) {
272
184
  return codes.join("\n");
273
185
  }
274
186
 
275
- // src/utils/transformers/createJSDocBlockText.ts
276
- function createJSDocBlockText({ comments, newLine }) {
187
+ // src/transformers/createJSDocBlockText.ts
188
+ function createJSDocBlockText({ comments }) {
277
189
  const filteredComments = comments.filter(Boolean);
278
190
  if (!filteredComments.length) {
279
191
  return "";
280
192
  }
281
- const source = `/**
193
+ return `/**
282
194
  * ${filteredComments.join("\n * ")}
283
195
  */`;
284
- if (newLine) {
285
- return `${source}
286
- `;
287
- }
288
- return source;
289
196
  }
290
197
 
291
- // src/utils/transformers/escape.ts
198
+ // src/transformers/escape.ts
292
199
  function escape(text) {
293
200
  return text ? text.replaceAll("`", "\\`") : "";
294
201
  }
@@ -313,12 +220,12 @@ function jsStringEscape(input) {
313
220
  });
314
221
  }
315
222
 
316
- // src/utils/transformers/indent.ts
223
+ // src/transformers/indent.ts
317
224
  function createIndent(size) {
318
225
  return Array.from({ length: size + 1 }).join(" ");
319
226
  }
320
227
 
321
- // src/utils/transformers/nameSorter.ts
228
+ // src/transformers/nameSorter.ts
322
229
  function nameSorter(a, b) {
323
230
  if (a.name < b.name) {
324
231
  return -1;
@@ -329,7 +236,7 @@ function nameSorter(a, b) {
329
236
  return 0;
330
237
  }
331
238
 
332
- // src/utils/transformers/searchAndReplace.ts
239
+ // src/transformers/searchAndReplace.ts
333
240
  function searchAndReplace(options) {
334
241
  const { text, replaceBy, prefix = "", key } = options;
335
242
  const searchValues = options.searchValues?.(prefix, key) || [
@@ -346,7 +253,7 @@ function searchAndReplace(options) {
346
253
  }, text);
347
254
  }
348
255
 
349
- // src/utils/transformers/transformReservedWord.ts
256
+ // src/transformers/transformReservedWord.ts
350
257
  var reservedWords = [
351
258
  "abstract",
352
259
  "arguments",
@@ -439,13 +346,16 @@ function transformReservedWord(word) {
439
346
  return word;
440
347
  }
441
348
 
442
- // src/utils/transformers/trim.ts
349
+ // src/transformers/trim.ts
443
350
  function trim(text) {
444
351
  return text.replaceAll(/\n/g, "").trim();
445
352
  }
353
+ function trimExtName(text) {
354
+ return text.replace(/\.[^/.]+$/, "");
355
+ }
446
356
 
447
- // src/utils/transformers/index.ts
448
- var transformers = {
357
+ // src/transformers/index.ts
358
+ var transformers_default = {
449
359
  combineCodes,
450
360
  escape,
451
361
  jsStringEscape,
@@ -454,10 +364,127 @@ var transformers = {
454
364
  nameSorter,
455
365
  searchAndReplace,
456
366
  trim,
367
+ trimExtName,
457
368
  JSDoc: {
458
369
  createJSDocBlockText
370
+ },
371
+ camelCase,
372
+ pascalCase
373
+ };
374
+
375
+ // src/utils/URLPath.ts
376
+ var URLPath = class {
377
+ constructor(path3) {
378
+ this.path = path3;
379
+ return this;
380
+ }
381
+ /**
382
+ * Convert Swagger path to URLPath(syntax of Express)
383
+ * @example /pet/{petId} => /pet/:petId
384
+ */
385
+ get URL() {
386
+ return this.toURLPath();
387
+ }
388
+ get isURL() {
389
+ try {
390
+ const url = new URL(this.path);
391
+ if (url?.href) {
392
+ return true;
393
+ }
394
+ } catch (error) {
395
+ return false;
396
+ }
397
+ return false;
398
+ }
399
+ /**
400
+ * Convert Swagger path to template literals/ template strings(camelcase)
401
+ * @example /pet/{petId} => `/pet/${petId}`
402
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
403
+ * @example /account/userID => `/account/${userId}`
404
+ */
405
+ get template() {
406
+ return this.toTemplateString();
407
+ }
408
+ get object() {
409
+ return this.toObject();
410
+ }
411
+ get params() {
412
+ return this.getParams();
413
+ }
414
+ toObject({ type = "path", replacer, stringify } = {}) {
415
+ const object = {
416
+ url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
417
+ params: this.getParams()
418
+ };
419
+ if (stringify) {
420
+ if (type === "template") {
421
+ return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
422
+ }
423
+ if (object.params) {
424
+ return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
425
+ }
426
+ return `{ url: '${object.url}' }`;
427
+ }
428
+ return object;
429
+ }
430
+ /**
431
+ * Convert Swagger path to template literals/ template strings(camelcase)
432
+ * @example /pet/{petId} => `/pet/${petId}`
433
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
434
+ * @example /account/userID => `/account/${userId}`
435
+ */
436
+ toTemplateString(replacer) {
437
+ const regex = /{(\w|-)*}/g;
438
+ const found = this.path.match(regex);
439
+ let newPath = this.path.replaceAll("{", "${");
440
+ if (found) {
441
+ newPath = found.reduce((prev, curr) => {
442
+ const pathParam = replacer ? replacer(transformers_default.camelCase(curr)) : transformers_default.camelCase(curr);
443
+ const replacement = `\${${pathParam}}`;
444
+ return prev.replace(curr, replacement);
445
+ }, this.path);
446
+ }
447
+ return `\`${newPath}\``;
448
+ }
449
+ getParams(replacer) {
450
+ const regex = /{(\w|-)*}/g;
451
+ const found = this.path.match(regex);
452
+ if (!found) {
453
+ return void 0;
454
+ }
455
+ const params = {};
456
+ found.forEach((item) => {
457
+ item = item.replaceAll("{", "").replaceAll("}", "");
458
+ const pathParam = replacer ? replacer(transformers_default.camelCase(item)) : transformers_default.camelCase(item);
459
+ params[pathParam] = pathParam;
460
+ }, this.path);
461
+ return params;
462
+ }
463
+ /**
464
+ * Convert Swagger path to URLPath(syntax of Express)
465
+ * @example /pet/{petId} => /pet/:petId
466
+ */
467
+ toURLPath() {
468
+ return this.path.replaceAll("{", ":").replaceAll("}", "");
459
469
  }
460
470
  };
471
+
472
+ // src/config.ts
473
+ function defineConfig(options) {
474
+ return options;
475
+ }
476
+ function isInputPath(result) {
477
+ return !!result && "path" in result;
478
+ }
479
+
480
+ // src/utils/timeout.ts
481
+ async function timeout(ms) {
482
+ return new Promise((resolve3) => {
483
+ setTimeout(() => {
484
+ resolve3(true);
485
+ }, ms);
486
+ });
487
+ }
461
488
  async function saveCreateDirectory(path3) {
462
489
  const passedPath = dirname(resolve(path3));
463
490
  await fs2.mkdir(passedPath, { recursive: true });
@@ -608,78 +635,67 @@ var TreeNode = class _TreeNode {
608
635
  var _options;
609
636
  var BarrelManager = class {
610
637
  constructor(options = {}) {
611
- __privateAdd(this, _options, {});
638
+ __privateAdd(this, _options, void 0);
612
639
  __privateSet(this, _options, options);
613
640
  return this;
614
641
  }
615
- getIndexes(root, extName) {
616
- const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
617
- const extMapper = {
618
- ".ts": {
619
- extensions: /\.ts/,
620
- exclude: [/schemas/, /json/]
621
- },
622
- ".json": {
623
- extensions: /\.json/,
624
- exclude: []
625
- }
626
- };
627
- const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
642
+ getIndexes(pathToBuild) {
643
+ const { treeNode = {}, isTypeOnly, extName } = __privateGet(this, _options);
644
+ const tree = TreeNode.build(pathToBuild, treeNode);
628
645
  if (!tree) {
629
646
  return null;
630
647
  }
631
- const fileReducer = (files2, currentTree) => {
632
- if (!currentTree.children) {
648
+ const fileReducer = (files, treeNode2) => {
649
+ if (!treeNode2.children) {
633
650
  return [];
634
651
  }
635
- if (currentTree.children?.length > 1) {
636
- const indexPath = path.resolve(currentTree.data.path, "index.ts");
637
- const exports = currentTree.children.filter(Boolean).map((file) => {
638
- const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
639
- if (importPath.includes("index") && file.data.type === "file") {
652
+ if (treeNode2.children.length > 1) {
653
+ const indexPath = path.resolve(treeNode2.data.path, "index.ts");
654
+ const exports = treeNode2.children.filter(Boolean).map((file) => {
655
+ const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${transformers_default.trimExtName(file.data.name)}`;
656
+ if (importPath.endsWith("index") && file.data.type === "file") {
640
657
  return void 0;
641
658
  }
642
659
  return {
643
- path: includeExt ? `${importPath}${extName}` : importPath,
660
+ path: extName ? `${importPath}${extName}` : importPath,
644
661
  isTypeOnly
645
662
  };
646
663
  }).filter(Boolean);
647
- files2.push({
664
+ files.push({
648
665
  path: indexPath,
649
666
  baseName: "index.ts",
650
667
  source: "",
651
- exports: output ? exports?.filter((item) => {
652
- return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
653
- }) : exports
668
+ exports,
669
+ meta: {
670
+ treeNode: treeNode2
671
+ }
654
672
  });
655
- } else {
656
- currentTree.children?.forEach((child) => {
657
- const indexPath = path.resolve(currentTree.data.path, "index.ts");
658
- const importPath = child.data.type === "directory" ? `./${child.data.name}/index` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
659
- const exports = [
660
- {
661
- path: includeExt ? `${importPath}${extName}` : importPath,
662
- isTypeOnly
663
- }
664
- ];
665
- files2.push({
666
- path: indexPath,
667
- baseName: "index.ts",
668
- source: "",
669
- exports: output ? exports?.filter((item) => {
670
- return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
671
- }) : exports
672
- });
673
+ } else if (treeNode2.children.length === 1) {
674
+ const [treeNodeChild] = treeNode2.children;
675
+ const indexPath = path.resolve(treeNode2.data.path, "index.ts");
676
+ const importPath = treeNodeChild.data.type === "directory" ? `./${treeNodeChild.data.name}/index` : `./${transformers_default.trimExtName(treeNodeChild.data.name)}`;
677
+ const exports = [
678
+ {
679
+ path: extName ? `${importPath}${extName}` : importPath,
680
+ isTypeOnly
681
+ }
682
+ ];
683
+ files.push({
684
+ path: indexPath,
685
+ baseName: "index.ts",
686
+ source: "",
687
+ exports,
688
+ meta: {
689
+ treeNode: treeNode2
690
+ }
673
691
  });
674
692
  }
675
- currentTree.children.forEach((childItem) => {
676
- fileReducer(files2, childItem);
693
+ treeNode2.children.forEach((childItem) => {
694
+ fileReducer(files, childItem);
677
695
  });
678
- return files2;
696
+ return files;
679
697
  };
680
- const files = fileReducer([], tree).reverse();
681
- const filteredFiles = filter ? files.filter(filter) : files;
682
- return map ? filteredFiles.map(map) : filteredFiles;
698
+ return fileReducer([], tree).reverse();
683
699
  }
684
700
  };
685
701
  _options = new WeakMap();
@@ -688,7 +704,7 @@ _options = new WeakMap();
688
704
  var KubbFile;
689
705
  ((KubbFile2) => {
690
706
  })(KubbFile || (KubbFile = {}));
691
- var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
707
+ var _cache, _task, _isWriting, _timeout, _queue, _validate, _add, add_fn, _addOrAppend, addOrAppend_fn;
692
708
  var _FileManager = class _FileManager {
693
709
  constructor(options) {
694
710
  __privateAdd(this, _validate);
@@ -721,7 +737,6 @@ var _FileManager = class _FileManager {
721
737
  }
722
738
  async add(...files) {
723
739
  const promises = files.map((file) => {
724
- __privateMethod(this, _validate, validate_fn).call(this, file);
725
740
  if (file.override) {
726
741
  return __privateMethod(this, _add, add_fn).call(this, file);
727
742
  }
@@ -733,12 +748,37 @@ var _FileManager = class _FileManager {
733
748
  }
734
749
  return resolvedFiles[0];
735
750
  }
736
- async addIndexes({ root, extName = ".ts", meta, options = {} }) {
737
- const barrelManager = new BarrelManager(options);
738
- const files = barrelManager.getIndexes(root, extName);
751
+ async addIndexes({ root, output, meta, options = {} }) {
752
+ const { exportType = "barrel" } = output;
753
+ if (!exportType) {
754
+ return void 0;
755
+ }
756
+ const exportPath = output.path.startsWith("./") ? output.path : `./${output.path}`;
757
+ const barrelManager = new BarrelManager({ extName: output.extName, ...options });
758
+ const files = barrelManager.getIndexes(resolve(root, output.path));
739
759
  if (!files) {
740
760
  return void 0;
741
761
  }
762
+ const rootFile = {
763
+ path: resolve(root, "index.ts"),
764
+ baseName: "index.ts",
765
+ source: "",
766
+ exports: [
767
+ output.exportAs ? {
768
+ name: output.exportAs,
769
+ asAlias: true,
770
+ path: exportPath,
771
+ isTypeOnly: options.isTypeOnly
772
+ } : {
773
+ path: exportPath,
774
+ isTypeOnly: options.isTypeOnly
775
+ }
776
+ ]
777
+ };
778
+ await __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
779
+ ...rootFile,
780
+ meta: meta ? meta : rootFile.meta
781
+ });
742
782
  return await Promise.all(
743
783
  files.map((file) => {
744
784
  return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
@@ -785,9 +825,22 @@ var _FileManager = class _FileManager {
785
825
  }
786
826
  const exports = file.exports ? combineExports(file.exports) : [];
787
827
  const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
788
- const importNodes = imports.map((item) => factory.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
828
+ const importNodes = imports.filter((item) => {
829
+ return item.path !== transformers_default.trimExtName(file.path);
830
+ }).map((item) => {
831
+ return factory.createImportDeclaration({
832
+ name: item.name,
833
+ path: item.root ? getRelativePath(item.root, item.path) : item.path,
834
+ isTypeOnly: item.isTypeOnly
835
+ });
836
+ });
789
837
  const exportNodes = exports.map(
790
- (item) => factory.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias })
838
+ (item) => factory.createExportDeclaration({
839
+ name: item.name,
840
+ path: item.path,
841
+ isTypeOnly: item.isTypeOnly,
842
+ asAlias: item.asAlias
843
+ })
791
844
  );
792
845
  return [print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
793
846
  }
@@ -838,18 +891,10 @@ _isWriting = new WeakMap();
838
891
  _timeout = new WeakMap();
839
892
  _queue = new WeakMap();
840
893
  _validate = new WeakSet();
841
- validate_fn = function(file) {
842
- if (!file.validate) {
843
- return;
844
- }
845
- if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
846
- throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
847
- }
848
- };
849
894
  _add = new WeakSet();
850
895
  add_fn = async function(file) {
851
896
  const controller = new AbortController();
852
- const resolvedFile = { id: crypto2.randomUUID(), ...file };
897
+ const resolvedFile = { id: crypto2.randomUUID(), name: transformers_default.trimExtName(file.baseName), ...file };
853
898
  __privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
854
899
  if (__privateGet(this, _queue)) {
855
900
  await __privateGet(this, _queue).run(
@@ -922,7 +967,7 @@ function combineImports(imports, exports, source) {
922
967
  return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
923
968
  };
924
969
  if (Array.isArray(name)) {
925
- name = name.filter((item) => hasImportInSource(item));
970
+ name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
926
971
  }
927
972
  const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
928
973
  const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
@@ -968,8 +1013,8 @@ function getEnvSource(source, env) {
968
1013
  throw new TypeError(`Environment should be in upperCase for ${key}`);
969
1014
  }
970
1015
  if (typeof replaceBy === "string") {
971
- prev = transformers.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
972
- prev = transformers.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
1016
+ prev = transformers_default.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
1017
+ prev = transformers_default.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
973
1018
  `, "ig"), ""), replaceBy, key });
974
1019
  }
975
1020
  return prev;
@@ -1008,8 +1053,8 @@ var Queue = class {
1008
1053
  __privateSet(this, _debug, debug);
1009
1054
  }
1010
1055
  run(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
1011
- return new Promise((resolve2, reject) => {
1012
- const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
1056
+ return new Promise((resolve3, reject) => {
1057
+ const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
1013
1058
  options.controller?.signal.addEventListener("abort", () => {
1014
1059
  __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
1015
1060
  reject("Aborted");
@@ -1019,8 +1064,8 @@ var Queue = class {
1019
1064
  });
1020
1065
  }
1021
1066
  runSync(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
1022
- new Promise((resolve2, reject) => {
1023
- const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
1067
+ new Promise((resolve3, reject) => {
1068
+ const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
1024
1069
  options.controller?.signal.addEventListener("abort", () => {
1025
1070
  __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
1026
1071
  });
@@ -1047,13 +1092,13 @@ work_fn = function() {
1047
1092
  __privateWrapper(this, _workerCount)._++;
1048
1093
  let entry;
1049
1094
  while (entry = __privateGet(this, _queue2).shift()) {
1050
- const { reject, resolve: resolve2, job, name, description } = entry;
1095
+ const { reject, resolve: resolve3, job, name, description } = entry;
1051
1096
  if (__privateGet(this, _debug)) {
1052
1097
  performance.mark(name + "_start");
1053
1098
  }
1054
1099
  job().then((result) => {
1055
1100
  this.eventEmitter.emit("jobDone", result);
1056
- resolve2(result);
1101
+ resolve3(result);
1057
1102
  if (__privateGet(this, _debug)) {
1058
1103
  performance.mark(name + "_stop");
1059
1104
  performance.measure(description, name + "_start", name + "_stop");
@@ -1127,8 +1172,7 @@ var definePlugin = createPlugin((options) => {
1127
1172
  return {
1128
1173
  name: pluginName,
1129
1174
  options,
1130
- key: ["controller", "core"],
1131
- kind: "controller",
1175
+ key: ["core"],
1132
1176
  api() {
1133
1177
  return {
1134
1178
  get config() {
@@ -1264,11 +1308,14 @@ var PluginManager = class {
1264
1308
  hookName: "resolvePath",
1265
1309
  parameters: [params.baseName, params.directory, params.options]
1266
1310
  });
1267
- if (paths && paths?.length > 1) {
1268
- throw new Error(
1311
+ if (paths && paths?.length > 1 && this.logger.logLevel === LogLevel.debug) {
1312
+ this.logger.warn(
1269
1313
  `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1270
1314
 
1271
- Paths: ${JSON.stringify(paths, void 0, 2)}`
1315
+ Paths: ${JSON.stringify(paths, void 0, 2)}
1316
+
1317
+ Falling back on the first item.
1318
+ `
1272
1319
  );
1273
1320
  }
1274
1321
  return paths?.at(0);
@@ -1285,11 +1332,14 @@ Paths: ${JSON.stringify(paths, void 0, 2)}`
1285
1332
  hookName: "resolveName",
1286
1333
  parameters: [params.name, params.type]
1287
1334
  });
1288
- if (names && names?.length > 1) {
1289
- throw new Error(
1335
+ if (names && names?.length > 1 && this.logger.logLevel === LogLevel.debug) {
1336
+ this.logger.warn(
1290
1337
  `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1291
1338
 
1292
- Names: ${JSON.stringify(names, void 0, 2)}`
1339
+ Names: ${JSON.stringify(names, void 0, 2)}
1340
+
1341
+ Falling back on the first item.
1342
+ `
1293
1343
  );
1294
1344
  }
1295
1345
  return transformReservedWord(names?.at(0) || params.name);
@@ -1472,20 +1522,19 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1472
1522
  }
1473
1523
  getPluginsByKey(hookName, pluginKey) {
1474
1524
  const plugins = [...this.plugins];
1475
- const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
1525
+ const [searchPluginName, searchIdentifier] = pluginKey;
1476
1526
  const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
1477
- const [kind, name, identifier] = item.key;
1527
+ const [name, identifier] = item.key;
1478
1528
  const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
1479
- const kindCheck = kind === searchKind;
1480
1529
  const nameCheck = name === searchPluginName;
1481
1530
  if (searchIdentifier) {
1482
- return identifierCheck && kindCheck && nameCheck;
1531
+ return identifierCheck && nameCheck;
1483
1532
  }
1484
- return kindCheck && nameCheck;
1533
+ return nameCheck;
1485
1534
  });
1486
1535
  if (!pluginByPluginName?.length) {
1487
1536
  const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
1488
- if (this.logger.logLevel === "info") {
1537
+ if (this.logger.logLevel === LogLevel.debug) {
1489
1538
  if (corePlugin) {
1490
1539
  this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
1491
1540
  } else {
@@ -1513,7 +1562,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1513
1562
  }
1514
1563
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1515
1564
  static get hooks() {
1516
- return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
1565
+ return ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
1517
1566
  }
1518
1567
  };
1519
1568
  _core = new WeakMap();
@@ -1523,7 +1572,7 @@ _getSortedPlugins = new WeakSet();
1523
1572
  getSortedPlugins_fn = function(hookName) {
1524
1573
  const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
1525
1574
  if (hookName) {
1526
- if (this.logger.logLevel === "info") {
1575
+ if (this.logger.logLevel === LogLevel.info) {
1527
1576
  const containsHookName = plugins.some((item) => item[hookName]);
1528
1577
  if (!containsHookName) {
1529
1578
  this.logger.warn(`No hook ${hookName} found`);
@@ -1531,7 +1580,23 @@ getSortedPlugins_fn = function(hookName) {
1531
1580
  }
1532
1581
  return plugins.filter((item) => item[hookName]);
1533
1582
  }
1534
- return plugins;
1583
+ return plugins.map((plugin) => {
1584
+ if (plugin.pre) {
1585
+ const isValid = plugin.pre.every((pluginName2) => plugins.find((pluginToFind) => pluginToFind.name === pluginName2));
1586
+ if (!isValid) {
1587
+ throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
1588
+ }
1589
+ }
1590
+ return plugin;
1591
+ }).sort((a, b) => {
1592
+ if (b.pre?.includes(a.name)) {
1593
+ return 1;
1594
+ }
1595
+ if (b.post?.includes(a.name)) {
1596
+ return -1;
1597
+ }
1598
+ return 0;
1599
+ });
1535
1600
  };
1536
1601
  _addExecutedToCallStack = new WeakSet();
1537
1602
  addExecutedToCallStack_fn = function(executer) {
@@ -1622,7 +1687,7 @@ _parse = new WeakSet();
1622
1687
  parse_fn = function(plugin, pluginManager, context) {
1623
1688
  const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
1624
1689
  setUniqueName(plugin.name, usedPluginNames);
1625
- const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
1690
+ const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
1626
1691
  if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
1627
1692
  pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
1628
1693
  }
@@ -1710,7 +1775,7 @@ async function setup(options) {
1710
1775
  if (logger.logLevel === LogLevel.info) {
1711
1776
  logger.spinner.start(`\u{1F4BE} Writing`);
1712
1777
  }
1713
- if (logger.logLevel === "debug") {
1778
+ if (logger.logLevel === LogLevel.debug) {
1714
1779
  logger.info(`PluginKey ${pc3.dim(JSON.stringify(plugin.key))}
1715
1780
  with source
1716
1781
 
@@ -1745,10 +1810,6 @@ ${code}`);
1745
1810
  async function build(options) {
1746
1811
  const pluginManager = await setup(options);
1747
1812
  const { fileManager, logger } = pluginManager;
1748
- await pluginManager.hookParallel({
1749
- hookName: "validate",
1750
- parameters: [pluginManager.plugins]
1751
- });
1752
1813
  await pluginManager.hookParallel({
1753
1814
  hookName: "buildStart",
1754
1815
  parameters: [options.config]
@@ -1764,10 +1825,6 @@ async function safeBuild(options) {
1764
1825
  const pluginManager = await setup(options);
1765
1826
  const { fileManager, logger } = pluginManager;
1766
1827
  try {
1767
- await pluginManager.hookParallel({
1768
- hookName: "validate",
1769
- parameters: [pluginManager.plugins]
1770
- });
1771
1828
  await pluginManager.hookParallel({
1772
1829
  hookName: "buildStart",
1773
1830
  parameters: [options.config]
@@ -1938,13 +1995,9 @@ match_fn = function(packageJSON, dependency) {
1938
1995
  __privateAdd(_PackageManager, _cache2, {});
1939
1996
  var PackageManager = _PackageManager;
1940
1997
 
1941
- // src/SchemaGenerator.ts
1942
- var SchemaGenerator = class extends Generator {
1943
- };
1944
-
1945
1998
  // src/index.ts
1946
1999
  var src_default = build;
1947
2000
 
1948
- export { FileManager, Generator, KubbFile, PackageManager, PluginManager, PromiseManager, SchemaGenerator, ValidationPluginError, Warning, build, combineExports, combineImports, createPlugin, src_default as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
2001
+ export { FileManager, Generator, KubbFile, PackageManager, PluginManager, PromiseManager, ValidationPluginError, Warning, build, combineExports, combineImports, createPlugin, src_default as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
1949
2002
  //# sourceMappingURL=out.js.map
1950
2003
  //# sourceMappingURL=index.js.map