@kubb/core 2.0.0-beta.13 → 2.0.0-beta.14

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 (77) hide show
  1. package/dist/chunk-35FDNG5F.cjs +71 -0
  2. package/dist/chunk-35FDNG5F.cjs.map +1 -0
  3. package/dist/chunk-7CNPSL5M.js +85 -0
  4. package/dist/chunk-7CNPSL5M.js.map +1 -0
  5. package/dist/{chunk-SX2AYX5F.js → chunk-DKYWBKNH.js} +2 -2
  6. package/dist/chunk-EZSRGYAY.js +128 -0
  7. package/dist/chunk-EZSRGYAY.js.map +1 -0
  8. package/dist/{chunk-77QZQ377.cjs → chunk-GBX7KRCX.cjs} +12 -5
  9. package/dist/chunk-GBX7KRCX.cjs.map +1 -0
  10. package/dist/{chunk-FOQFLMOC.js → chunk-ICRPOCV4.cjs} +400 -446
  11. package/dist/chunk-ICRPOCV4.cjs.map +1 -0
  12. package/dist/chunk-LAS7UYTK.cjs +129 -0
  13. package/dist/chunk-LAS7UYTK.cjs.map +1 -0
  14. package/dist/chunk-LJHT3DNH.js +67 -0
  15. package/dist/chunk-LJHT3DNH.js.map +1 -0
  16. package/dist/{chunk-I7UUR5MZ.cjs → chunk-MM42A6GN.cjs} +3 -3
  17. package/dist/{chunk-I7UUR5MZ.cjs.map → chunk-MM42A6GN.cjs.map} +1 -1
  18. package/dist/{chunk-L6F5QUH2.js → chunk-SRGTC4FJ.js} +2 -2
  19. package/dist/{chunk-PY7I7OEN.cjs → chunk-ST7GHHSU.cjs} +34 -22
  20. package/dist/chunk-ST7GHHSU.cjs.map +1 -0
  21. package/dist/{chunk-ABFPJZJL.cjs → chunk-U4C2WTCI.cjs} +5 -5
  22. package/dist/{chunk-WFDR7OMY.js → chunk-UIQUKFF4.js} +9 -2
  23. package/dist/chunk-UIQUKFF4.js.map +1 -0
  24. package/dist/{chunk-6N4JBFFS.js → chunk-WTSDXEWD.js} +4 -12
  25. package/dist/chunk-WTSDXEWD.js.map +1 -0
  26. package/dist/fs.cjs +9 -8
  27. package/dist/fs.cjs.map +1 -1
  28. package/dist/fs.d.cts +1 -1
  29. package/dist/fs.d.ts +1 -1
  30. package/dist/fs.js +3 -2
  31. package/dist/fs.js.map +1 -1
  32. package/dist/index.cjs +955 -244
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +17 -15
  35. package/dist/index.d.ts +17 -15
  36. package/dist/index.js +135 -83
  37. package/dist/index.js.map +1 -1
  38. package/dist/logger.cjs +7 -6
  39. package/dist/logger.d.cts +1 -0
  40. package/dist/logger.d.ts +1 -0
  41. package/dist/logger.js +3 -2
  42. package/dist/transformers.cjs +21 -21
  43. package/dist/transformers.js +5 -5
  44. package/dist/utils.cjs +22 -19
  45. package/dist/utils.cjs.map +1 -1
  46. package/dist/utils.d.cts +0 -1
  47. package/dist/utils.d.ts +0 -1
  48. package/dist/utils.js +14 -4
  49. package/dist/utils.js.map +1 -1
  50. package/dist/{write-46ytbnu9.d.cts → write-A6VgHkYA.d.cts} +4 -1
  51. package/dist/{write-46ytbnu9.d.ts → write-A6VgHkYA.d.ts} +4 -1
  52. package/package.json +9 -8
  53. package/src/FileManager.ts +60 -57
  54. package/src/PluginManager.ts +11 -18
  55. package/src/build.ts +57 -32
  56. package/src/fs/clean.ts +2 -2
  57. package/src/fs/read.ts +1 -0
  58. package/src/fs/write.ts +40 -24
  59. package/src/logger.ts +10 -0
  60. package/src/utils/index.ts +0 -2
  61. package/dist/Queue-2-6pMcCx.d.cts +0 -32
  62. package/dist/Queue-2-6pMcCx.d.ts +0 -32
  63. package/dist/chunk-56YH3VX6.js +0 -239
  64. package/dist/chunk-56YH3VX6.js.map +0 -1
  65. package/dist/chunk-6N4JBFFS.js.map +0 -1
  66. package/dist/chunk-72O327DC.cjs +0 -247
  67. package/dist/chunk-72O327DC.cjs.map +0 -1
  68. package/dist/chunk-77QZQ377.cjs.map +0 -1
  69. package/dist/chunk-FOQFLMOC.js.map +0 -1
  70. package/dist/chunk-PY7I7OEN.cjs.map +0 -1
  71. package/dist/chunk-WFDR7OMY.js.map +0 -1
  72. package/dist/chunk-Z7XZQBAK.cjs +0 -2339
  73. package/dist/chunk-Z7XZQBAK.cjs.map +0 -1
  74. package/src/utils/Queue.ts +0 -110
  75. /package/dist/{chunk-SX2AYX5F.js.map → chunk-DKYWBKNH.js.map} +0 -0
  76. /package/dist/{chunk-L6F5QUH2.js.map → chunk-SRGTC4FJ.js.map} +0 -0
  77. /package/dist/{chunk-ABFPJZJL.cjs.map → chunk-U4C2WTCI.cjs.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { w as write, r as read } from './write-46ytbnu9.cjs';
1
+ import PQueue from 'p-queue';
2
+ import { w as write, r as read } from './write-A6VgHkYA.cjs';
2
3
  import { PossiblePromise, GreaterThan, TupleToUnion, ObjValueTuple } from '@kubb/types';
3
4
  import { DirectoryTreeOptions } from 'directory-tree';
4
- import { E as EventEmitter, Q as Queue, a as QueueJob } from './Queue-2-6pMcCx.cjs';
5
5
  import { Logger, LogLevel } from './logger.cjs';
6
6
  import 'ora';
7
7
 
@@ -14,6 +14,15 @@ type BarrelManagerOptions = {
14
14
  extName?: KubbFile.Extname;
15
15
  };
16
16
 
17
+ declare class EventEmitter<TEvents extends Record<string, any>> {
18
+ #private;
19
+ constructor();
20
+ emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
21
+ on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
22
+ off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
23
+ removeAll(): void;
24
+ }
25
+
17
26
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
18
27
  /**
19
28
  * Get the type of the first argument in a function.
@@ -38,11 +47,7 @@ type Options$2 = {
38
47
  /**
39
48
  * Task for the FileManager
40
49
  */
41
- task: QueueJob<KubbFile.ResolvedFile>;
42
- /**
43
- * Timeout between writes in the FileManager
44
- */
45
- writeTimeout?: number;
50
+ task: (file: KubbFile.ResolvedFile) => Promise<KubbFile.ResolvedFile>;
46
51
  };
47
52
  type Events = {
48
53
  execute: [executer: Executer];
@@ -54,10 +59,10 @@ declare class PluginManager {
54
59
  readonly plugins: KubbPluginWithLifeCycle[];
55
60
  readonly fileManager: FileManager;
56
61
  readonly events: EventEmitter<Events>;
57
- readonly queue: Queue;
58
62
  readonly config: KubbConfig;
59
63
  readonly executed: Array<Executer>;
60
64
  readonly logger: Logger;
65
+ readonly queue: PQueue;
61
66
  constructor(config: KubbConfig, options: Options$2);
62
67
  resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
63
68
  resolveName: (params: ResolveNameParams) => string;
@@ -558,16 +563,12 @@ type AddIndexesProps = {
558
563
  meta?: KubbFile.File['meta'];
559
564
  };
560
565
  type Options$1 = {
561
- queue?: Queue;
562
- task?: QueueJob<KubbFile.ResolvedFile>;
563
- /**
564
- * Timeout between writes
565
- */
566
- timeout?: number;
566
+ queue?: PQueue;
567
+ task?: (file: KubbFile.ResolvedFile) => Promise<KubbFile.ResolvedFile>;
567
568
  };
568
569
  declare class FileManager {
569
570
  #private;
570
- constructor(options?: Options$1);
571
+ constructor({ task, queue }?: Options$1);
571
572
  get files(): Array<KubbFile.File>;
572
573
  get isExecuting(): boolean;
573
574
  add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
@@ -578,6 +579,7 @@ declare class FileManager {
578
579
  write(...params: Parameters<typeof write>): Promise<string | undefined>;
579
580
  read(...params: Parameters<typeof read>): Promise<string>;
580
581
  static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
582
+ static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
581
583
  static getMode(path: string | undefined | null): KubbFile.Mode;
582
584
  static get extensions(): Array<KubbFile.Extname>;
583
585
  static isExtensionAllowed(baseName: string): boolean;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { w as write, r as read } from './write-46ytbnu9.js';
1
+ import PQueue from 'p-queue';
2
+ import { w as write, r as read } from './write-A6VgHkYA.js';
2
3
  import { PossiblePromise, GreaterThan, TupleToUnion, ObjValueTuple } from '@kubb/types';
3
4
  import { DirectoryTreeOptions } from 'directory-tree';
4
- import { E as EventEmitter, Q as Queue, a as QueueJob } from './Queue-2-6pMcCx.js';
5
5
  import { Logger, LogLevel } from './logger.js';
6
6
  import 'ora';
7
7
 
@@ -14,6 +14,15 @@ type BarrelManagerOptions = {
14
14
  extName?: KubbFile.Extname;
15
15
  };
16
16
 
17
+ declare class EventEmitter<TEvents extends Record<string, any>> {
18
+ #private;
19
+ constructor();
20
+ emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
21
+ on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
22
+ off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
23
+ removeAll(): void;
24
+ }
25
+
17
26
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
18
27
  /**
19
28
  * Get the type of the first argument in a function.
@@ -38,11 +47,7 @@ type Options$2 = {
38
47
  /**
39
48
  * Task for the FileManager
40
49
  */
41
- task: QueueJob<KubbFile.ResolvedFile>;
42
- /**
43
- * Timeout between writes in the FileManager
44
- */
45
- writeTimeout?: number;
50
+ task: (file: KubbFile.ResolvedFile) => Promise<KubbFile.ResolvedFile>;
46
51
  };
47
52
  type Events = {
48
53
  execute: [executer: Executer];
@@ -54,10 +59,10 @@ declare class PluginManager {
54
59
  readonly plugins: KubbPluginWithLifeCycle[];
55
60
  readonly fileManager: FileManager;
56
61
  readonly events: EventEmitter<Events>;
57
- readonly queue: Queue;
58
62
  readonly config: KubbConfig;
59
63
  readonly executed: Array<Executer>;
60
64
  readonly logger: Logger;
65
+ readonly queue: PQueue;
61
66
  constructor(config: KubbConfig, options: Options$2);
62
67
  resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
63
68
  resolveName: (params: ResolveNameParams) => string;
@@ -558,16 +563,12 @@ type AddIndexesProps = {
558
563
  meta?: KubbFile.File['meta'];
559
564
  };
560
565
  type Options$1 = {
561
- queue?: Queue;
562
- task?: QueueJob<KubbFile.ResolvedFile>;
563
- /**
564
- * Timeout between writes
565
- */
566
- timeout?: number;
566
+ queue?: PQueue;
567
+ task?: (file: KubbFile.ResolvedFile) => Promise<KubbFile.ResolvedFile>;
567
568
  };
568
569
  declare class FileManager {
569
570
  #private;
570
- constructor(options?: Options$1);
571
+ constructor({ task, queue }?: Options$1);
571
572
  get files(): Array<KubbFile.File>;
572
573
  get isExecuting(): boolean;
573
574
  add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
@@ -578,6 +579,7 @@ declare class FileManager {
578
579
  write(...params: Parameters<typeof write>): Promise<string | undefined>;
579
580
  read(...params: Parameters<typeof read>): Promise<string>;
580
581
  static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
582
+ static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
581
583
  static getMode(path: string | undefined | null): KubbFile.Mode;
582
584
  static get extensions(): Array<KubbFile.Extname>;
583
585
  static isExtensionAllowed(baseName: string): boolean;
package/dist/index.js CHANGED
@@ -1,16 +1,19 @@
1
1
  import mod, { createRequire } from 'module';
2
- import { transformReservedWord, trimExtName, searchAndReplace } from './chunk-L6F5QUH2.js';
3
- import { EventEmitter, Queue, setUniqueName, timeout, URLPath } from './chunk-56YH3VX6.js';
4
- import './chunk-SX2AYX5F.js';
5
- import { LogLevel, createLogger, p, randomCliColour } from './chunk-WFDR7OMY.js';
6
- import { write, read, getRelativePath, clean } from './chunk-FOQFLMOC.js';
7
- import { __commonJS, init_esm_shims, __toESM, __privateAdd, __privateSet, __privateGet, __privateMethod, __require } from './chunk-6N4JBFFS.js';
2
+ import { transformReservedWord, trimExtName, searchAndReplace } from './chunk-SRGTC4FJ.js';
3
+ import { setUniqueName, URLPath } from './chunk-EZSRGYAY.js';
4
+ import './chunk-DKYWBKNH.js';
5
+ import { LogLevel, createLogger, p, randomCliColour } from './chunk-UIQUKFF4.js';
6
+ import { read, getRelativePath, clean } from './chunk-LJHT3DNH.js';
7
+ import { write } from './chunk-7CNPSL5M.js';
8
+ import { __commonJS, init_esm_shims, __toESM, __privateAdd, __privateSet, __privateGet, __privateMethod, __require } from './chunk-WTSDXEWD.js';
8
9
  import crypto from 'crypto';
9
10
  import path, { resolve, extname } from 'path';
10
11
  import { print } from '@kubb/parser';
11
12
  import * as factory from '@kubb/parser/factory';
12
13
  import { orderBy } from 'natural-orderby';
14
+ import PQueue from 'p-queue';
13
15
  import dirTree from 'directory-tree';
16
+ import { EventEmitter as EventEmitter$1 } from 'events';
14
17
  import os from 'os';
15
18
  import { pathToFileURL } from 'url';
16
19
  import { findUp, findUpSync } from 'find-up';
@@ -903,25 +906,16 @@ _options = new WeakMap();
903
906
  var KubbFile;
904
907
  ((KubbFile2) => {
905
908
  })(KubbFile || (KubbFile = {}));
906
- var _cache, _task, _isWriting, _timeout, _queue, _validate, _add, add_fn, _addOrAppend, addOrAppend_fn;
909
+ var _cache, _task, _queue, _add, add_fn, _addOrAppend, addOrAppend_fn;
907
910
  var _FileManager = class _FileManager {
908
- constructor(options) {
909
- __privateAdd(this, _validate);
911
+ constructor({ task = async (file) => file, queue = new PQueue() } = {}) {
910
912
  __privateAdd(this, _add);
911
913
  __privateAdd(this, _addOrAppend);
912
914
  __privateAdd(this, _cache, /* @__PURE__ */ new Map());
913
915
  __privateAdd(this, _task, void 0);
914
- __privateAdd(this, _isWriting, false);
915
- /**
916
- * Timeout between writes
917
- */
918
- __privateAdd(this, _timeout, 0);
919
916
  __privateAdd(this, _queue, void 0);
920
- if (options) {
921
- __privateSet(this, _task, options.task);
922
- __privateSet(this, _queue, options.queue);
923
- __privateSet(this, _timeout, options.timeout || 0);
924
- }
917
+ __privateSet(this, _task, task);
918
+ __privateSet(this, _queue, queue);
925
919
  return this;
926
920
  }
927
921
  get files() {
@@ -932,10 +926,10 @@ var _FileManager = class _FileManager {
932
926
  return files;
933
927
  }
934
928
  get isExecuting() {
935
- return __privateGet(this, _queue)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
929
+ return __privateGet(this, _queue).size !== 0 && __privateGet(this, _queue).pending !== 0;
936
930
  }
937
931
  async add(...files) {
938
- const promises = files.map((file) => {
932
+ const promises = combineFiles(files).map((file) => {
939
933
  if (file.override) {
940
934
  return __privateMethod(this, _add, add_fn).call(this, file);
941
935
  }
@@ -952,7 +946,7 @@ var _FileManager = class _FileManager {
952
946
  if (!exportType) {
953
947
  return void 0;
954
948
  }
955
- const exportPath = output.path.startsWith("./") ? output.path : `./${output.path}`;
949
+ const exportPath = output.path.startsWith("./") ? trimExtName(output.path) : `./${trimExtName(output.path)}`;
956
950
  const barrelManager = new BarrelManager({ extName: output.extName, ...options });
957
951
  const files = barrelManager.getIndexes(resolve(root, output.path));
958
952
  if (!files) {
@@ -966,10 +960,10 @@ var _FileManager = class _FileManager {
966
960
  output.exportAs ? {
967
961
  name: output.exportAs,
968
962
  asAlias: true,
969
- path: exportPath,
963
+ path: output.extName ? `${exportPath}${output.extName}` : exportPath,
970
964
  isTypeOnly: options.isTypeOnly
971
965
  } : {
972
- path: exportPath,
966
+ path: output.extName ? `${exportPath}${output.extName}` : exportPath,
973
967
  isTypeOnly: options.isTypeOnly
974
968
  }
975
969
  ]
@@ -1005,14 +999,7 @@ var _FileManager = class _FileManager {
1005
999
  __privateGet(this, _cache).delete(path3);
1006
1000
  }
1007
1001
  async write(...params) {
1008
- if (!__privateGet(this, _isWriting)) {
1009
- __privateSet(this, _isWriting, true);
1010
- const text = await write(...params);
1011
- __privateSet(this, _isWriting, false);
1012
- return text;
1013
- }
1014
- await timeout(__privateGet(this, _timeout));
1015
- return this.write(...params);
1002
+ return write(...params);
1016
1003
  }
1017
1004
  async read(...params) {
1018
1005
  return read(...params);
@@ -1021,6 +1008,9 @@ var _FileManager = class _FileManager {
1021
1008
  static getSource(file) {
1022
1009
  return getSource(file);
1023
1010
  }
1011
+ static combineFiles(files) {
1012
+ return combineFiles(files);
1013
+ }
1024
1014
  static getMode(path3) {
1025
1015
  if (!path3) {
1026
1016
  return "directory";
@@ -1036,25 +1026,19 @@ var _FileManager = class _FileManager {
1036
1026
  };
1037
1027
  _cache = new WeakMap();
1038
1028
  _task = new WeakMap();
1039
- _isWriting = new WeakMap();
1040
- _timeout = new WeakMap();
1041
1029
  _queue = new WeakMap();
1042
- _validate = new WeakSet();
1043
1030
  _add = new WeakSet();
1044
1031
  add_fn = async function(file) {
1045
1032
  const controller = new AbortController();
1046
1033
  const resolvedFile = { id: crypto.randomUUID(), name: trimExtName(file.baseName), ...file };
1047
1034
  __privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
1048
- if (__privateGet(this, _queue)) {
1049
- await __privateGet(this, _queue).run(
1050
- async () => {
1051
- var _a;
1052
- return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
1053
- },
1054
- { controller }
1055
- );
1056
- }
1057
- return resolvedFile;
1035
+ return __privateGet(this, _queue).add(
1036
+ async () => {
1037
+ var _a;
1038
+ return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
1039
+ },
1040
+ { signal: controller.signal }
1041
+ );
1058
1042
  };
1059
1043
  _addOrAppend = new WeakSet();
1060
1044
  addOrAppend_fn = async function(file) {
@@ -1074,6 +1058,34 @@ ${file.source}` : "",
1074
1058
  return __privateMethod(this, _add, add_fn).call(this, file);
1075
1059
  };
1076
1060
  var FileManager = _FileManager;
1061
+ function combineFiles(files) {
1062
+ return files.filter(Boolean).reduce((acc, file) => {
1063
+ const prevIndex = acc.findIndex((item) => item.path === file.path);
1064
+ if (prevIndex === -1) {
1065
+ return [...acc, file];
1066
+ }
1067
+ const prev = acc[prevIndex];
1068
+ if (prev && file.override) {
1069
+ acc[prevIndex] = {
1070
+ imports: [],
1071
+ exports: [],
1072
+ ...file
1073
+ };
1074
+ return acc;
1075
+ }
1076
+ if (prev) {
1077
+ acc[prevIndex] = {
1078
+ ...file,
1079
+ source: prev.source && file.source ? `${prev.source}
1080
+ ${file.source}` : "",
1081
+ imports: [...prev.imports || [], ...file.imports || []],
1082
+ exports: [...prev.exports || [], ...file.exports || []],
1083
+ env: { ...prev.env || {}, ...file.env || {} }
1084
+ };
1085
+ }
1086
+ return acc;
1087
+ }, []);
1088
+ }
1077
1089
  function getSource(file) {
1078
1090
  if (!FileManager.isExtensionAllowed(file.baseName)) {
1079
1091
  return file.source;
@@ -1198,6 +1210,29 @@ function getEnvSource(source, env) {
1198
1210
  // src/PluginManager.ts
1199
1211
  init_esm_shims();
1200
1212
 
1213
+ // src/utils/EventEmitter.ts
1214
+ init_esm_shims();
1215
+ var _emitter;
1216
+ var EventEmitter = class {
1217
+ constructor() {
1218
+ __privateAdd(this, _emitter, new EventEmitter$1());
1219
+ __privateGet(this, _emitter).setMaxListeners(100);
1220
+ }
1221
+ emit(eventName, ...eventArg) {
1222
+ __privateGet(this, _emitter).emit(eventName, ...eventArg);
1223
+ }
1224
+ on(eventName, handler) {
1225
+ __privateGet(this, _emitter).on(eventName, handler);
1226
+ }
1227
+ off(eventName, handler) {
1228
+ __privateGet(this, _emitter).off(eventName, handler);
1229
+ }
1230
+ removeAll() {
1231
+ __privateGet(this, _emitter).removeAllListeners();
1232
+ }
1233
+ };
1234
+ _emitter = new WeakMap();
1235
+
1201
1236
  // src/errors.ts
1202
1237
  init_esm_shims();
1203
1238
  var Warning = class extends Error {
@@ -1394,7 +1429,7 @@ var PluginManager = class {
1394
1429
  parameters: [params.baseName, params.directory, params.options]
1395
1430
  });
1396
1431
  if (paths && paths?.length > 1 && this.logger.logLevel === LogLevel.debug) {
1397
- this.logger.warn(
1432
+ this.logger.debug(
1398
1433
  `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1399
1434
 
1400
1435
  Paths: ${JSON.stringify(paths, void 0, 2)}
@@ -1418,7 +1453,7 @@ Falling back on the first item.
1418
1453
  parameters: [params.name, params.type]
1419
1454
  });
1420
1455
  if (names && names?.length > 1 && this.logger.logLevel === LogLevel.debug) {
1421
- this.logger.warn(
1456
+ this.logger.debug(
1422
1457
  `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1423
1458
 
1424
1459
  Names: ${JSON.stringify(names, void 0, 2)}
@@ -1437,8 +1472,8 @@ Falling back on the first item.
1437
1472
  };
1438
1473
  this.config = config;
1439
1474
  this.logger = options.logger;
1440
- this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
1441
- this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
1475
+ this.queue = new PQueue({ concurrency: 1 });
1476
+ this.fileManager = new FileManager({ task: options.task, queue: this.queue });
1442
1477
  __privateSet(this, _promiseManager, new PromiseManager({ nullCheck: (state) => !!state?.result }));
1443
1478
  const plugins = config.plugins || [];
1444
1479
  const core = definePlugin({
@@ -1627,9 +1662,9 @@ Falling back on the first item.
1627
1662
  const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
1628
1663
  if (this.logger.logLevel === LogLevel.debug) {
1629
1664
  if (corePlugin) {
1630
- this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
1665
+ this.logger.debug(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
1631
1666
  } else {
1632
- this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
1667
+ this.logger.debug(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
1633
1668
  }
1634
1669
  }
1635
1670
  return corePlugin ? [corePlugin] : [];
@@ -1779,9 +1814,6 @@ parse_fn = function(plugin, pluginManager, context) {
1779
1814
  const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
1780
1815
  setUniqueName(plugin.name, usedPluginNames);
1781
1816
  const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
1782
- if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
1783
- pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
1784
- }
1785
1817
  if (!plugin.transform) {
1786
1818
  plugin.transform = function transform(code) {
1787
1819
  return code;
@@ -1807,6 +1839,7 @@ async function transformReducer(_previousCode, result, _plugin) {
1807
1839
  }
1808
1840
  async function setup(options) {
1809
1841
  const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
1842
+ let count = 0;
1810
1843
  try {
1811
1844
  if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
1812
1845
  await read(config.input.path);
@@ -1824,76 +1857,95 @@ async function setup(options) {
1824
1857
  if (config.output.clean) {
1825
1858
  await clean(config.output.path);
1826
1859
  }
1827
- const queueTask = async (file) => {
1860
+ const task = async (file) => {
1828
1861
  const { path: path3 } = file;
1829
- let code = FileManager.getSource(file);
1862
+ let source = FileManager.getSource(file);
1830
1863
  const { result: loadedResult } = await pluginManager.hookFirst({
1831
1864
  hookName: "load",
1832
1865
  parameters: [path3]
1833
1866
  });
1834
1867
  if (loadedResult && isPromise(loadedResult)) {
1835
- code = await loadedResult;
1868
+ source = await loadedResult;
1836
1869
  }
1837
1870
  if (loadedResult && !isPromise(loadedResult)) {
1838
- code = loadedResult;
1871
+ source = loadedResult;
1839
1872
  }
1840
- if (code) {
1841
- const transformedCode = await pluginManager.hookReduceArg0({
1873
+ if (source) {
1874
+ source = await pluginManager.hookReduceArg0({
1842
1875
  hookName: "transform",
1843
- parameters: [code, path3],
1876
+ parameters: [source, path3],
1844
1877
  reduce: transformReducer
1845
1878
  });
1846
1879
  if (config.output.write || config.output.write === void 0) {
1847
1880
  if (file.meta?.pluginKey) {
1848
- return pluginManager.hookForPlugin({
1881
+ await pluginManager.hookForPlugin({
1849
1882
  pluginKey: file.meta?.pluginKey,
1850
1883
  hookName: "writeFile",
1851
- parameters: [transformedCode, path3]
1884
+ parameters: [source, path3]
1852
1885
  });
1853
1886
  }
1854
- return pluginManager.hookFirst({
1887
+ await pluginManager.hookFirst({
1855
1888
  hookName: "writeFile",
1856
- parameters: [transformedCode, path3]
1889
+ parameters: [source, path3]
1857
1890
  });
1858
1891
  }
1859
1892
  }
1893
+ return {
1894
+ ...file,
1895
+ source: source || ""
1896
+ };
1860
1897
  };
1861
- const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
1898
+ const pluginManager = new PluginManager(config, { logger, task });
1862
1899
  pluginManager.on("execute", (executer) => {
1863
1900
  const { hookName, parameters, plugin } = executer;
1864
1901
  if (hookName === "writeFile" && logger.spinner) {
1865
1902
  const [code] = parameters;
1866
- if (logger.logLevel === LogLevel.info) {
1867
- logger.spinner.start(`\u{1F4BE} Writing`);
1868
- }
1869
1903
  if (logger.logLevel === LogLevel.debug) {
1870
- logger.info(`PluginKey ${p.dim(JSON.stringify(plugin.key))}
1904
+ logger.debug(`PluginKey ${p.dim(JSON.stringify(plugin.key))}
1871
1905
  with source
1872
1906
 
1873
1907
  ${code}`);
1874
1908
  }
1875
1909
  }
1876
1910
  });
1911
+ pluginManager.queue.on("add", () => {
1912
+ if (logger.logLevel !== LogLevel.info) {
1913
+ return;
1914
+ }
1915
+ if (logger.spinner && count === 0) {
1916
+ logger.spinner?.start(`\u{1F4BE} Writing`);
1917
+ }
1918
+ });
1919
+ pluginManager.queue.on("active", () => {
1920
+ if (logger.logLevel !== LogLevel.info) {
1921
+ return;
1922
+ }
1923
+ if (logger.spinner && pluginManager.queue.size > 0) {
1924
+ const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`;
1925
+ logger.spinner.suffixText = p.dim(text);
1926
+ }
1927
+ ++count;
1928
+ });
1929
+ pluginManager.queue.on("completed", () => {
1930
+ if (logger.logLevel !== LogLevel.info) {
1931
+ return;
1932
+ }
1933
+ if (logger.spinner) {
1934
+ const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`;
1935
+ logger.spinner.suffixText = p.dim(text);
1936
+ }
1937
+ });
1877
1938
  pluginManager.on("executed", (executer) => {
1878
1939
  const { hookName, plugin, output, parameters } = executer;
1879
- const messsage = `${randomCliColour(plugin.name)} Executing ${hookName}`;
1880
- if (logger.logLevel === LogLevel.info && logger.spinner) {
1881
- if (hookName === "writeFile") {
1882
- const [_code, path3] = parameters;
1883
- logger.spinner.suffixText = p.dim(path3);
1884
- } else {
1885
- logger.spinner.suffixText = messsage;
1886
- }
1887
- }
1888
1940
  if (logger.logLevel === LogLevel.debug) {
1889
- logger.info(messsage);
1890
1941
  const logs = [
1942
+ `${randomCliColour(plugin.name)} Executing ${hookName}`,
1891
1943
  parameters && `${p.bgWhite(`Parameters`)} ${randomCliColour(plugin.name)} ${hookName}`,
1892
1944
  JSON.stringify(parameters, void 0, 2),
1893
1945
  output && `${p.bgWhite("Output")} ${randomCliColour(plugin.name)} ${hookName}`,
1894
1946
  output
1895
1947
  ].filter(Boolean);
1896
- console.log(logs.join("\n"));
1948
+ logger.debug(logs.join("\n"));
1897
1949
  }
1898
1950
  });
1899
1951
  return pluginManager;
@@ -1906,7 +1958,7 @@ async function build(options) {
1906
1958
  parameters: [options.config]
1907
1959
  });
1908
1960
  await pluginManager.hookParallel({ hookName: "buildEnd" });
1909
- if (!fileManager.isExecuting && logger.spinner) {
1961
+ if (logger.logLevel === LogLevel.info && logger.spinner) {
1910
1962
  logger.spinner.suffixText = "";
1911
1963
  logger.spinner.succeed(`\u{1F4BE} Writing completed`);
1912
1964
  }
@@ -1921,7 +1973,7 @@ async function safeBuild(options) {
1921
1973
  parameters: [options.config]
1922
1974
  });
1923
1975
  await pluginManager.hookParallel({ hookName: "buildEnd" });
1924
- if (!fileManager.isExecuting && logger.spinner) {
1976
+ if (logger.logLevel === LogLevel.info && logger.spinner) {
1925
1977
  logger.spinner.suffixText = "";
1926
1978
  logger.spinner.succeed(`\u{1F4BE} Writing completed`);
1927
1979
  }