@kubb/core 1.2.4 → 1.3.1

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
@@ -176,13 +176,30 @@ var Queue = class {
176
176
  this.maxParallel = maxParallel;
177
177
  this.debug = debug;
178
178
  }
179
- run(task, options = { name: crypto__default.default.randomUUID(), description: "" }) {
179
+ run(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
180
180
  return new Promise((resolve, reject) => {
181
- const item = { reject, resolve, task, name: options.name, description: options.description || options.name };
181
+ const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
182
+ options.controller?.signal.addEventListener("abort", () => {
183
+ this.queue = this.queue.filter((queueItem) => queueItem.name === item.name);
184
+ reject("Aborted");
185
+ });
186
+ this.queue.push(item);
187
+ this.work();
188
+ });
189
+ }
190
+ runSync(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
191
+ new Promise((resolve, reject) => {
192
+ const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
193
+ options.controller?.signal.addEventListener("abort", () => {
194
+ this.queue = this.queue.filter((queueItem) => queueItem.name === item.name);
195
+ });
182
196
  this.queue.push(item);
183
197
  this.work();
184
198
  });
185
199
  }
200
+ get hasJobs() {
201
+ return this.workerCount > 0 || this.queue.length > 0;
202
+ }
186
203
  work() {
187
204
  if (this.workerCount >= this.maxParallel) {
188
205
  return;
@@ -190,11 +207,11 @@ var Queue = class {
190
207
  this.workerCount++;
191
208
  let entry;
192
209
  while (entry = this.queue.shift()) {
193
- const { reject, resolve, task, name, description } = entry;
210
+ const { reject, resolve, job, name, description } = entry;
194
211
  if (this.debug) {
195
212
  perf_hooks.performance.mark(name + "_start");
196
213
  }
197
- task().then((result) => {
214
+ job().then((result) => {
198
215
  resolve(result);
199
216
  if (this.debug) {
200
217
  perf_hooks.performance.mark(name + "_stop");
@@ -628,7 +645,7 @@ var URLPath = class {
628
645
  return false;
629
646
  }
630
647
  };
631
- function writeIndexes(root, options = {}) {
648
+ function getIndexes(root, options = {}) {
632
649
  const tree = TreeNode.build(root, { extensions: /\.ts/, ...options });
633
650
  if (!tree) {
634
651
  return null;
@@ -814,13 +831,24 @@ var FileManager = class {
814
831
  });
815
832
  return files;
816
833
  }
834
+ get isExecuting() {
835
+ return this.queue?.hasJobs ?? false;
836
+ }
817
837
  async add(file) {
838
+ const controller = new AbortController();
818
839
  const resolvedFile = { id: crypto__default.default.randomUUID(), ...file };
819
- this.cache.set(resolvedFile.path, [resolvedFile]);
840
+ this.cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
820
841
  if (this.queue) {
821
- await this.queue.run(async () => {
822
- await this.task?.(resolvedFile);
823
- });
842
+ try {
843
+ await this.queue.run(
844
+ async () => {
845
+ return this.task?.(resolvedFile);
846
+ },
847
+ { controller }
848
+ );
849
+ } catch {
850
+ return resolvedFile;
851
+ }
824
852
  }
825
853
  return resolvedFile;
826
854
  }
@@ -832,6 +860,7 @@ var FileManager = class {
832
860
  if (sourceAlreadyExists) {
833
861
  return Promise.resolve(previousCache);
834
862
  }
863
+ previousCache.cancel?.();
835
864
  this.cache.delete(previousCache.path);
836
865
  return this.add({
837
866
  ...file,
@@ -1039,7 +1068,7 @@ var PluginManager = class {
1039
1068
  eventEmitter = new EventEmitter();
1040
1069
  constructor(config, options) {
1041
1070
  this.logger = options.logger;
1042
- this.queue = new Queue(100, options.debug);
1071
+ this.queue = new Queue(50, options.debug);
1043
1072
  this.fileManager = new FileManager({ task: options.task, queue: this.queue });
1044
1073
  const core = definePlugin({
1045
1074
  config,
@@ -1528,6 +1557,7 @@ exports.defineConfig = defineConfig;
1528
1557
  exports.extensions = extensions;
1529
1558
  exports.getEncodedText = getEncodedText;
1530
1559
  exports.getFileSource = getFileSource;
1560
+ exports.getIndexes = getIndexes;
1531
1561
  exports.getLocation = getLocation;
1532
1562
  exports.getPathMode = getPathMode;
1533
1563
  exports.getRelativePath = getRelativePath;
@@ -1553,6 +1583,5 @@ exports.transformReservedWord = transformReservedWord;
1553
1583
  exports.uniqueId = uniqueId;
1554
1584
  exports.validatePlugins = validatePlugins;
1555
1585
  exports.write = write;
1556
- exports.writeIndexes = writeIndexes;
1557
1586
  //# sourceMappingURL=out.js.map
1558
1587
  //# sourceMappingURL=index.cjs.map