@kubb/core 1.15.0-canary.20231023T140655 → 1.15.0-canary.20231024T104207

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
@@ -4,17 +4,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var pc3 = require('picocolors');
6
6
  var crypto = require('crypto');
7
+ var path4 = require('path');
7
8
  var fs2 = require('fs-extra');
8
9
  var changeCase = require('change-case');
9
10
  var naturalOrderby = require('natural-orderby');
10
11
  var perf_hooks = require('perf_hooks');
12
+ var events = require('events');
11
13
  var seedrandom = require('seedrandom');
12
- var path2 = require('path');
13
14
  var jsRuntime = require('js-runtime');
14
15
  var dirTree = require('directory-tree');
15
16
  var parser = require('@kubb/parser');
16
17
  var isEqual = require('lodash.isequal');
17
- var events = require('events');
18
18
  var mod = require('module');
19
19
  var os = require('os');
20
20
  var url = require('url');
@@ -26,9 +26,9 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
26
26
 
27
27
  var pc3__default = /*#__PURE__*/_interopDefault(pc3);
28
28
  var crypto__default = /*#__PURE__*/_interopDefault(crypto);
29
+ var path4__default = /*#__PURE__*/_interopDefault(path4);
29
30
  var fs2__default = /*#__PURE__*/_interopDefault(fs2);
30
31
  var seedrandom__default = /*#__PURE__*/_interopDefault(seedrandom);
31
- var path2__default = /*#__PURE__*/_interopDefault(path2);
32
32
  var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
33
33
  var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
34
34
  var mod__default = /*#__PURE__*/_interopDefault(mod);
@@ -71,8 +71,8 @@ function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
71
71
  }
72
72
  };
73
73
  }
74
- async function clean(path3) {
75
- return fs2.remove(path3);
74
+ async function clean(path5) {
75
+ return fs2.remove(path5);
76
76
  }
77
77
  var FunctionParams = class {
78
78
  type;
@@ -114,20 +114,9 @@ var FunctionParams = class {
114
114
  }
115
115
  };
116
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;
126
- }
127
-
128
117
  // src/utils/isPromise.ts
129
118
  function isPromise(result) {
130
- return typeof result?.then === "function";
119
+ return !!result && typeof result?.then === "function";
131
120
  }
132
121
  function isPromiseFulfilledResult(result) {
133
122
  return result.status === "fulfilled";
@@ -146,7 +135,7 @@ function createJSDocBlockText({ comments }) {
146
135
  * ${filteredComments.join("\n * ")}
147
136
  */`;
148
137
  }
149
- function createLogger(spinner) {
138
+ function createLogger({ logLevel, name, spinner }) {
150
139
  const logs = [];
151
140
  const log = (message) => {
152
141
  if (message && spinner) {
@@ -172,6 +161,8 @@ function createLogger(spinner) {
172
161
  }
173
162
  };
174
163
  const logger = {
164
+ name,
165
+ logLevel,
175
166
  log,
176
167
  error,
177
168
  warn,
@@ -192,8 +183,29 @@ function nameSorter(a, b) {
192
183
  }
193
184
  return 0;
194
185
  }
186
+ var EventEmitter = class {
187
+ constructor() {
188
+ this.#emitter.setMaxListeners(100);
189
+ }
190
+ #emitter = new events.EventEmitter();
191
+ emit(eventName, ...eventArg) {
192
+ this.#emitter.emit(eventName, ...eventArg);
193
+ }
194
+ on(eventName, handler) {
195
+ this.#emitter.on(eventName, handler);
196
+ }
197
+ off(eventName, handler) {
198
+ this.#emitter.off(eventName, handler);
199
+ }
200
+ removeAll() {
201
+ this.#emitter.removeAllListeners();
202
+ }
203
+ };
204
+
205
+ // src/utils/Queue.ts
195
206
  var Queue = class {
196
207
  #queue = [];
208
+ eventEmitter = new EventEmitter();
197
209
  #workerCount = 0;
198
210
  #maxParallel;
199
211
  #debug = false;
@@ -202,8 +214,8 @@ var Queue = class {
202
214
  this.#debug = debug;
203
215
  }
204
216
  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 };
217
+ return new Promise((resolve2, reject) => {
218
+ const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
207
219
  options.controller?.signal.addEventListener("abort", () => {
208
220
  this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
209
221
  reject("Aborted");
@@ -213,8 +225,8 @@ var Queue = class {
213
225
  });
214
226
  }
215
227
  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 };
228
+ new Promise((resolve2, reject) => {
229
+ const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
218
230
  options.controller?.signal.addEventListener("abort", () => {
219
231
  this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
220
232
  });
@@ -235,17 +247,21 @@ var Queue = class {
235
247
  this.#workerCount++;
236
248
  let entry;
237
249
  while (entry = this.#queue.shift()) {
238
- const { reject, resolve, job, name, description } = entry;
250
+ const { reject, resolve: resolve2, job, name, description } = entry;
239
251
  if (this.#debug) {
240
252
  perf_hooks.performance.mark(name + "_start");
241
253
  }
242
254
  job().then((result) => {
243
- resolve(result);
255
+ this.eventEmitter.emit("jobDone", result);
256
+ resolve2(result);
244
257
  if (this.#debug) {
245
258
  perf_hooks.performance.mark(name + "_stop");
246
259
  perf_hooks.performance.measure(description, name + "_start", name + "_stop");
247
260
  }
248
- }).catch((err) => reject(err));
261
+ }).catch((err) => {
262
+ this.eventEmitter.emit("jobFailed", err);
263
+ reject(err);
264
+ });
249
265
  }
250
266
  this.#workerCount--;
251
267
  }
@@ -276,37 +292,31 @@ function randomPicoColour(text, colors = defaultColours) {
276
292
  }
277
293
  return formatter(text);
278
294
  }
279
- function slash(path3, platform = "linux") {
280
- const isWindowsPath = /^\\\\\?\\/.test(path3);
295
+ function slash(path5, platform = "linux") {
296
+ const isWindowsPath = /^\\\\\?\\/.test(path5);
281
297
  if (["linux", "mac"].includes(platform) && !isWindowsPath) {
282
- return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
298
+ return path5.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
283
299
  }
284
- return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
300
+ return path5.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
285
301
  }
286
302
  function getRelativePath(rootDir, filePath, platform = "linux") {
287
303
  if (!rootDir || !filePath) {
288
304
  throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
289
305
  }
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";
306
+ const relativePath = path4.relative(rootDir, filePath);
307
+ const slashedPath = slash(relativePath, platform);
308
+ if (slashedPath.startsWith("../")) {
309
+ return slashedPath.replace(path4.basename(slashedPath), path4.basename(slashedPath, path4.extname(filePath)));
300
310
  }
301
- return path2__default.default.extname(path3) ? "file" : "directory";
311
+ return `./${slashedPath.replace(path4.basename(slashedPath), path4.basename(slashedPath, path4.extname(filePath)))}`;
302
312
  }
303
313
  var reader = jsRuntime.switcher(
304
314
  {
305
- node: async (path3) => {
306
- return fs2__default.default.readFile(path3, { encoding: "utf8" });
315
+ node: async (path5) => {
316
+ return fs2__default.default.readFile(path5, { encoding: "utf8" });
307
317
  },
308
- bun: async (path3) => {
309
- const file = Bun.file(path3);
318
+ bun: async (path5) => {
319
+ const file = Bun.file(path5);
310
320
  return file.text();
311
321
  }
312
322
  },
@@ -314,8 +324,8 @@ var reader = jsRuntime.switcher(
314
324
  );
315
325
  var syncReader = jsRuntime.switcher(
316
326
  {
317
- node: (path3) => {
318
- return fs2__default.default.readFileSync(path3, { encoding: "utf8" });
327
+ node: (path5) => {
328
+ return fs2__default.default.readFileSync(path5, { encoding: "utf8" });
319
329
  },
320
330
  bun: () => {
321
331
  throw new Error("Bun cannot read sync");
@@ -323,11 +333,11 @@ var syncReader = jsRuntime.switcher(
323
333
  },
324
334
  "node"
325
335
  );
326
- async function read(path3) {
327
- return reader(path3);
336
+ async function read(path5) {
337
+ return reader(path5);
328
338
  }
329
- function readSync(path3) {
330
- return syncReader(path3);
339
+ function readSync(path5) {
340
+ return syncReader(path5);
331
341
  }
332
342
 
333
343
  // src/utils/renderTemplate.ts
@@ -393,9 +403,9 @@ var throttle = (fn, delay) => {
393
403
 
394
404
  // src/utils/timeout.ts
395
405
  async function timeout(ms) {
396
- return new Promise((resolve) => {
406
+ return new Promise((resolve2) => {
397
407
  setTimeout(() => {
398
- resolve(true);
408
+ resolve2(true);
399
409
  }, ms);
400
410
  });
401
411
  }
@@ -430,6 +440,11 @@ function jsStringEscape(input) {
430
440
  });
431
441
  }
432
442
 
443
+ // src/utils/transformers/indent.ts
444
+ function createIndent(size) {
445
+ return Array.from({ length: size + 1 }).join(" ");
446
+ }
447
+
433
448
  // src/utils/transformers/transformReservedWord.ts
434
449
  var reservedWords = [
435
450
  "abstract",
@@ -522,6 +537,15 @@ function transformReservedWord(word) {
522
537
  }
523
538
  return word;
524
539
  }
540
+
541
+ // src/utils/transformers/index.ts
542
+ var transformers = {
543
+ combineCodes,
544
+ escape,
545
+ jsStringEscape,
546
+ createIndent,
547
+ transformReservedWord
548
+ };
525
549
  var TreeNode = class _TreeNode {
526
550
  data;
527
551
  parent;
@@ -586,16 +610,16 @@ var TreeNode = class _TreeNode {
586
610
  }
587
611
  return this;
588
612
  }
589
- static build(path3, options = {}) {
613
+ static build(path5, options = {}) {
590
614
  try {
591
615
  const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
592
- const filteredTree = dirTree__default.default(path3, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
616
+ const filteredTree = dirTree__default.default(path5, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
593
617
  if (!filteredTree) {
594
618
  return null;
595
619
  }
596
- const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || getPathMode(filteredTree.path) });
620
+ const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || FileManager.getMode(filteredTree.path) });
597
621
  const recurse = (node, item) => {
598
- const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || getPathMode(item.path) });
622
+ const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || FileManager.getMode(item.path) });
599
623
  if (item.children?.length) {
600
624
  item.children?.forEach((child) => {
601
625
  recurse(subNode, child);
@@ -612,10 +636,30 @@ var TreeNode = class _TreeNode {
612
636
 
613
637
  // src/utils/uniqueIdFactory.ts
614
638
  var uniqueIdFactory = (counter) => (str = "") => `${str}${++counter}`;
639
+
640
+ // src/utils/uniqueName.ts
641
+ function getUniqueName(originalName, data) {
642
+ let used = data[originalName] || 0;
643
+ if (used) {
644
+ data[originalName] = ++used;
645
+ originalName += used;
646
+ }
647
+ data[originalName] = 1;
648
+ return originalName;
649
+ }
650
+ function setUniqueName(originalName, data) {
651
+ let used = data[originalName] || 0;
652
+ if (used) {
653
+ data[originalName] = ++used;
654
+ return originalName;
655
+ }
656
+ data[originalName] = 1;
657
+ return originalName;
658
+ }
615
659
  var URLPath = class {
616
660
  path;
617
- constructor(path3) {
618
- this.path = path3;
661
+ constructor(path5) {
662
+ this.path = path5;
619
663
  return this;
620
664
  }
621
665
  /**
@@ -713,39 +757,67 @@ var Warning = class extends Error {
713
757
  this.name = "Warning";
714
758
  }
715
759
  };
716
- async function saveCreateDirectory(path3) {
717
- const passedPath = path2__default.default.dirname(path2__default.default.resolve(path3));
760
+ async function saveCreateDirectory(path5) {
761
+ const passedPath = path4.dirname(path4.resolve(path5));
718
762
  await fs2__default.default.mkdir(passedPath, { recursive: true });
719
763
  }
720
764
  var writer = jsRuntime.switcher(
721
765
  {
722
- node: async (path3, data) => {
766
+ node: async (path5, data) => {
723
767
  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) {
768
+ await fs2__default.default.stat(path4.resolve(path5));
769
+ const oldContent = await fs2__default.default.readFile(path4.resolve(path5), { encoding: "utf-8" });
770
+ if (oldContent?.toString() === data?.toString()) {
727
771
  return;
728
772
  }
729
773
  } catch (_err) {
730
774
  }
731
- await saveCreateDirectory(path3);
732
- return fs2__default.default.writeFile(path2__default.default.resolve(path3), data, { encoding: "utf-8" });
775
+ await saveCreateDirectory(path5);
776
+ await fs2__default.default.writeFile(path4.resolve(path5), data, { encoding: "utf-8" });
777
+ const savedData = await fs2__default.default.readFile(path4.resolve(path5), { encoding: "utf-8" });
778
+ if (savedData?.toString() !== data?.toString()) {
779
+ throw new Error(`Sanity check failed for ${path5}
780
+
781
+ Data[${data.length}]:
782
+ ${data}
783
+
784
+ Saved[${savedData.length}]:
785
+ ${savedData}
786
+ `);
787
+ }
788
+ return savedData;
733
789
  },
734
- bun: async (path3, data) => {
790
+ bun: async (path5, data) => {
735
791
  try {
736
- await saveCreateDirectory(path3);
737
- await Bun.write(path2__default.default.resolve(path3), data);
792
+ await saveCreateDirectory(path5);
793
+ await Bun.write(path4.resolve(path5), data);
794
+ const file = Bun.file(path4.resolve(path5));
795
+ const savedData = await file.text();
796
+ if (savedData?.toString() !== data?.toString()) {
797
+ throw new Error(`Sanity check failed for ${path5}
798
+
799
+ Data[${data.length}]:
800
+ ${data}
801
+
802
+ Saved[${savedData.length}]:
803
+ ${savedData}
804
+ `);
805
+ }
806
+ return savedData;
738
807
  } catch (e) {
739
- console.log(e, path2__default.default.resolve(path3));
808
+ console.log(e, path4.resolve(path5));
740
809
  }
741
810
  }
742
811
  },
743
812
  "node"
744
813
  );
745
- async function write(data, path3) {
746
- return writer(path3, data);
814
+ async function write(data, path5) {
815
+ if (data.trim() === "") {
816
+ return void 0;
817
+ }
818
+ return writer(path5, data.trim());
747
819
  }
748
- function getIndexes(root, extName, options = {}) {
820
+ function getIndexes(root, extName, { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = {}) {
749
821
  const extMapper = {
750
822
  ".ts": {
751
823
  extensions: /\.ts/,
@@ -756,7 +828,7 @@ function getIndexes(root, extName, options = {}) {
756
828
  exclude: []
757
829
  }
758
830
  };
759
- const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...options });
831
+ const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
760
832
  if (!tree) {
761
833
  return null;
762
834
  }
@@ -765,32 +837,42 @@ function getIndexes(root, extName, options = {}) {
765
837
  return [];
766
838
  }
767
839
  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
- }
840
+ const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
841
+ const exports = currentTree.children.filter(Boolean).map((file) => {
773
842
  const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
774
- if (importPath.includes("index") && path3.includes("index")) {
843
+ if (importPath.includes("index") && indexPath.includes("index")) {
775
844
  return void 0;
776
845
  }
777
- return { path: importPath };
846
+ return {
847
+ path: includeExt ? file.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
848
+ isTypeOnly
849
+ };
778
850
  }).filter(Boolean);
779
851
  files2.push({
780
- path: path3,
852
+ path: indexPath,
781
853
  baseName: "index.ts",
782
854
  source: "",
783
- exports
855
+ exports: output ? exports?.filter((item) => {
856
+ return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
857
+ }) : exports
784
858
  });
785
859
  } else {
786
860
  currentTree.children?.forEach((child) => {
787
- const path3 = path2__default.default.resolve(currentTree.data.path, "index.ts");
861
+ const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
788
862
  const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
863
+ const exports = [
864
+ {
865
+ path: includeExt ? child.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
866
+ isTypeOnly
867
+ }
868
+ ];
789
869
  files2.push({
790
- path: path3,
870
+ path: indexPath,
791
871
  baseName: "index.ts",
792
872
  source: "",
793
- exports: [{ path: importPath }]
873
+ exports: output ? exports?.filter((item) => {
874
+ return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
875
+ }) : exports
794
876
  });
795
877
  });
796
878
  }
@@ -799,8 +881,9 @@ function getIndexes(root, extName, options = {}) {
799
881
  });
800
882
  return files2;
801
883
  };
802
- const files = fileReducer([], tree);
803
- return files;
884
+ const files = fileReducer([], tree).reverse();
885
+ const filteredFiles = filter ? files.filter(filter) : files;
886
+ return map ? filteredFiles.map(map) : filteredFiles;
804
887
  }
805
888
  function combineFiles(files) {
806
889
  return files.filter(Boolean).reduce((acc, curr) => {
@@ -828,9 +911,13 @@ function isExtensionAllowed(baseName) {
828
911
  return extensions.some((extension) => baseName.endsWith(extension));
829
912
  }
830
913
  function combineExports(exports) {
831
- return exports.reduce((prev, curr) => {
914
+ const combinedExports = naturalOrderby.orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
832
915
  const name = curr.name;
833
916
  const prevByPath = prev.findLast((imp) => imp.path === curr.path);
917
+ const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
918
+ if (prevByPathAndIsTypeOnly) {
919
+ return prev;
920
+ }
834
921
  const uniquePrev = prev.findLast(
835
922
  (imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
836
923
  );
@@ -852,12 +939,16 @@ function combineExports(exports) {
852
939
  }
853
940
  return [...prev, curr];
854
941
  }, []);
942
+ return naturalOrderby.orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
855
943
  }
856
944
  function combineImports(imports, exports, source) {
857
- return imports.reduce((prev, curr) => {
945
+ const combinedImports = naturalOrderby.orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
858
946
  let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
859
947
  const hasImportInSource = (importName) => {
860
- const checker = (name2) => name2 && !!source.includes(`${name2}`);
948
+ if (!source) {
949
+ return true;
950
+ }
951
+ const checker = (name2) => name2 && !!source.includes(name2);
861
952
  return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
862
953
  };
863
954
  if (Array.isArray(name)) {
@@ -865,6 +956,10 @@ function combineImports(imports, exports, source) {
865
956
  }
866
957
  const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
867
958
  const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
959
+ const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
960
+ if (prevByPathNameAndIsTypeOnly) {
961
+ return prev;
962
+ }
868
963
  if (uniquePrev || Array.isArray(name) && !name.length) {
869
964
  return prev;
870
965
  }
@@ -886,28 +981,17 @@ function combineImports(imports, exports, source) {
886
981
  }
887
982
  return [...prev, curr];
888
983
  }, []);
984
+ return naturalOrderby.orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
889
985
  }
890
986
  function createFileSource(file) {
891
- let { source } = file;
892
987
  if (!isExtensionAllowed(file.baseName)) {
893
988
  return file.source;
894
989
  }
895
990
  const exports = file.exports ? combineExports(file.exports) : [];
896
- const imports = file.imports ? combineImports(file.imports, exports, source) : [];
991
+ const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
897
992
  const importNodes = imports.map((item) => parser.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
898
- const importSource = parser.print(importNodes);
899
993
  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;
994
+ return [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
911
995
  }
912
996
  function searchAndReplace(options) {
913
997
  const { text, replaceBy, prefix = "", key } = options;
@@ -951,11 +1035,17 @@ function getEnvSource(source, env) {
951
1035
  var FileManager = class {
952
1036
  #cache = /* @__PURE__ */ new Map();
953
1037
  #task;
1038
+ #isWriting = false;
1039
+ /**
1040
+ * Timeout between writes
1041
+ */
1042
+ #timeout = 0;
954
1043
  #queue;
955
1044
  constructor(options) {
956
1045
  if (options) {
957
1046
  this.#task = options.task;
958
1047
  this.#queue = options.queue;
1048
+ this.#timeout = options.timeout || 0;
959
1049
  }
960
1050
  return this;
961
1051
  }
@@ -970,23 +1060,19 @@ var FileManager = class {
970
1060
  return files;
971
1061
  }
972
1062
  get isExecuting() {
973
- return this.#queue?.hasJobs ?? false;
1063
+ return this.#queue?.hasJobs ?? this.#isWriting ?? false;
974
1064
  }
975
1065
  async add(file) {
976
1066
  const controller = new AbortController();
977
1067
  const resolvedFile = { id: crypto__default.default.randomUUID(), ...file };
978
1068
  this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
979
1069
  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
- }
1070
+ await this.#queue.run(
1071
+ async () => {
1072
+ return this.#task?.(resolvedFile);
1073
+ },
1074
+ { controller }
1075
+ );
990
1076
  }
991
1077
  return resolvedFile;
992
1078
  }
@@ -1006,24 +1092,20 @@ ${file.source}` : "",
1006
1092
  }
1007
1093
  return this.add(file);
1008
1094
  }
1009
- async addIndexes(root, extName = ".ts", options = {}) {
1010
- const files = await getIndexes(root, extName, options);
1095
+ async addIndexes({ root, extName = ".ts", meta, options = {} }) {
1096
+ const files = getIndexes(root, extName, options);
1011
1097
  if (!files) {
1012
1098
  return void 0;
1013
1099
  }
1014
- return Promise.all(
1100
+ return await Promise.all(
1015
1101
  files.map((file) => {
1016
- if (file.override) {
1017
- return this.add(file);
1018
- }
1019
- return this.addOrAppend(file);
1102
+ return this.addOrAppend({
1103
+ ...file,
1104
+ meta: meta ? meta : file.meta
1105
+ });
1020
1106
  })
1021
1107
  );
1022
1108
  }
1023
- #append(path3, file) {
1024
- const previousFiles = this.#cache.get(path3) || [];
1025
- this.#cache.set(path3, [...previousFiles, file]);
1026
- }
1027
1109
  getCacheByUUID(UUID) {
1028
1110
  let cache;
1029
1111
  this.#cache.forEach((files) => {
@@ -1031,32 +1113,63 @@ ${file.source}` : "",
1031
1113
  });
1032
1114
  return cache;
1033
1115
  }
1034
- get(path3) {
1035
- return this.#cache.get(path3);
1116
+ get(path5) {
1117
+ return this.#cache.get(path5);
1036
1118
  }
1037
- remove(path3) {
1038
- const cacheItem = this.get(path3);
1119
+ remove(path5) {
1120
+ const cacheItem = this.get(path5);
1039
1121
  if (!cacheItem) {
1040
1122
  return;
1041
1123
  }
1042
- this.#cache.delete(path3);
1124
+ this.#cache.delete(path5);
1043
1125
  }
1044
1126
  async write(...params) {
1045
- if (this.#queue) {
1046
- return this.#queue.run(async () => {
1047
- return write(...params);
1048
- });
1127
+ if (!this.#isWriting) {
1128
+ this.#isWriting = true;
1129
+ const text = await write(...params);
1130
+ this.#isWriting = false;
1131
+ return text;
1049
1132
  }
1050
- return write(...params);
1133
+ await timeout(this.#timeout);
1134
+ return this.write(...params);
1051
1135
  }
1052
1136
  async read(...params) {
1053
- if (this.#queue) {
1054
- return this.#queue.run(async () => {
1055
- return read(...params);
1056
- });
1057
- }
1058
1137
  return read(...params);
1059
1138
  }
1139
+ // statics
1140
+ static getSource(file) {
1141
+ return createFileSource(file);
1142
+ }
1143
+ static combineFiles(files) {
1144
+ return combineFiles(files);
1145
+ }
1146
+ static getMode(path5) {
1147
+ if (!path5) {
1148
+ return "directory";
1149
+ }
1150
+ return path4.extname(path5) ? "file" : "directory";
1151
+ }
1152
+ };
1153
+
1154
+ // src/managers/pluginManager/executeStrategies.ts
1155
+ function hookSeq(promises) {
1156
+ return promises.reduce(
1157
+ (promise, func) => {
1158
+ if (!func || typeof func !== "function") {
1159
+ throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
1160
+ }
1161
+ return promise.then((result) => {
1162
+ const calledFunc = func();
1163
+ if (calledFunc) {
1164
+ return calledFunc.then(Array.prototype.concat.bind(result));
1165
+ }
1166
+ });
1167
+ },
1168
+ Promise.resolve([])
1169
+ );
1170
+ }
1171
+ var executeStrategies = {
1172
+ hookSeq
1060
1173
  };
1061
1174
 
1062
1175
  // src/managers/pluginManager/ParallelPluginError.ts
@@ -1098,16 +1211,7 @@ var PluginError = class extends Error {
1098
1211
  };
1099
1212
  function createPlugin(factory) {
1100
1213
  return (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;
1214
+ return factory(options);
1111
1215
  };
1112
1216
  }
1113
1217
  var pluginName = "core";
@@ -1116,6 +1220,8 @@ var definePlugin = createPlugin((options) => {
1116
1220
  return {
1117
1221
  name: pluginName,
1118
1222
  options,
1223
+ key: ["controller", "core"],
1224
+ kind: "controller",
1119
1225
  api() {
1120
1226
  return {
1121
1227
  get config() {
@@ -1124,6 +1230,9 @@ var definePlugin = createPlugin((options) => {
1124
1230
  get plugins() {
1125
1231
  return options.getPlugins();
1126
1232
  },
1233
+ get plugin() {
1234
+ return options.plugin;
1235
+ },
1127
1236
  logger,
1128
1237
  fileManager,
1129
1238
  pluginManager,
@@ -1143,37 +1252,35 @@ var definePlugin = createPlugin((options) => {
1143
1252
  };
1144
1253
  },
1145
1254
  resolvePath(baseName) {
1146
- const root = path2__default.default.resolve(this.config.root, this.config.output.path);
1147
- return path2__default.default.resolve(root, baseName);
1255
+ const root = path4__default.default.resolve(this.config.root, this.config.output.path);
1256
+ return path4__default.default.resolve(root, baseName);
1148
1257
  },
1149
1258
  resolveName(name) {
1150
1259
  return name;
1151
1260
  }
1152
1261
  };
1153
1262
  });
1154
- var EventEmitter = class {
1155
- constructor() {
1156
- this.#emitter.setMaxListeners(100);
1157
- }
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();
1170
- }
1263
+
1264
+ // src/types.ts
1265
+ var LogLevel = {
1266
+ silent: "silent",
1267
+ info: "info",
1268
+ debug: "debug"
1171
1269
  };
1172
1270
 
1173
1271
  // 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)];
1272
+ function pluginParser(plugin, pluginManager, context) {
1273
+ const usedPluginNames = pluginManager.usedPluginNames;
1274
+ setUniqueName(plugin.name, usedPluginNames);
1275
+ const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
1276
+ if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
1277
+ pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
1278
+ }
1279
+ if (!plugin.transform) {
1280
+ plugin.transform = function transform(code) {
1281
+ return code;
1282
+ };
1283
+ }
1177
1284
  if (plugin.api && typeof plugin.api === "function") {
1178
1285
  const api = plugin.api.call(context);
1179
1286
  return {
@@ -1208,10 +1315,12 @@ var PluginManager = class {
1208
1315
  executed = [];
1209
1316
  logger;
1210
1317
  #core;
1318
+ usedPluginNames = {};
1211
1319
  constructor(config, options) {
1212
1320
  this.logger = options.logger;
1213
- this.queue = new Queue(100, options.debug);
1214
- this.fileManager = new FileManager({ task: options.task, queue: this.queue });
1321
+ this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
1322
+ this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
1323
+ const plugins = config.plugins || [];
1215
1324
  const core = definePlugin({
1216
1325
  config,
1217
1326
  logger: this.logger,
@@ -1219,23 +1328,29 @@ var PluginManager = class {
1219
1328
  fileManager: this.fileManager,
1220
1329
  resolvePath: this.resolvePath.bind(this),
1221
1330
  resolveName: this.resolveName.bind(this),
1222
- getPlugins: this.#getSortedPlugins.bind(this),
1223
- plugin: void 0
1331
+ getPlugins: this.#getSortedPlugins.bind(this)
1332
+ });
1333
+ this.#core = pluginParser(core, this, core.api.call(null));
1334
+ this.plugins = [this.#core, ...plugins].map((plugin) => {
1335
+ return pluginParser(plugin, this, this.#core.api);
1224
1336
  });
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
- }, []);
1230
1337
  return this;
1231
1338
  }
1232
1339
  resolvePath = (params) => {
1233
- if (params.pluginName) {
1234
- return this.hookForPluginSync({
1235
- pluginName: params.pluginName,
1340
+ if (params.pluginKey) {
1341
+ const paths = this.hookForPluginSync({
1342
+ pluginKey: params.pluginKey,
1236
1343
  hookName: "resolvePath",
1237
1344
  parameters: [params.baseName, params.directory, params.options]
1238
1345
  });
1346
+ if (paths && paths?.length > 1) {
1347
+ throw new Error(
1348
+ `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1349
+
1350
+ Paths: ${JSON.stringify(paths, void 0, 2)}`
1351
+ );
1352
+ }
1353
+ return paths?.at(0);
1239
1354
  }
1240
1355
  return this.hookFirstSync({
1241
1356
  hookName: "resolvePath",
@@ -1243,13 +1358,20 @@ var PluginManager = class {
1243
1358
  }).result;
1244
1359
  };
1245
1360
  resolveName = (params) => {
1246
- if (params.pluginName) {
1247
- const name2 = this.hookForPluginSync({
1248
- pluginName: params.pluginName,
1361
+ if (params.pluginKey) {
1362
+ const names = this.hookForPluginSync({
1363
+ pluginKey: params.pluginKey,
1249
1364
  hookName: "resolveName",
1250
1365
  parameters: [params.name, params.type]
1251
1366
  });
1252
- return transformReservedWord(name2 || params.name);
1367
+ if (names && names?.length > 1) {
1368
+ throw new Error(
1369
+ `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1370
+
1371
+ Names: ${JSON.stringify(names, void 0, 2)}`
1372
+ );
1373
+ }
1374
+ return transformReservedWord(names?.at(0) || params.name);
1253
1375
  }
1254
1376
  const name = this.hookFirstSync({
1255
1377
  hookName: "resolveName",
@@ -1264,30 +1386,35 @@ var PluginManager = class {
1264
1386
  * Run only hook for a specific plugin name
1265
1387
  */
1266
1388
  hookForPlugin({
1267
- pluginName: pluginName2,
1389
+ pluginKey,
1268
1390
  hookName,
1269
1391
  parameters
1270
1392
  }) {
1271
- const plugin = this.getPlugin(hookName, pluginName2);
1272
- return this.#execute({
1273
- strategy: "hookFirst",
1274
- hookName,
1275
- parameters,
1276
- plugin
1277
- });
1393
+ const plugins = this.getPluginsByKey(hookName, pluginKey);
1394
+ const promises = plugins.map((plugin) => {
1395
+ return this.#execute({
1396
+ strategy: "hookFirst",
1397
+ hookName,
1398
+ parameters,
1399
+ plugin
1400
+ });
1401
+ }).filter(Boolean);
1402
+ return Promise.all(promises);
1278
1403
  }
1279
1404
  hookForPluginSync({
1280
- pluginName: pluginName2,
1405
+ pluginKey,
1281
1406
  hookName,
1282
1407
  parameters
1283
1408
  }) {
1284
- const plugin = this.getPlugin(hookName, pluginName2);
1285
- return this.#executeSync({
1286
- strategy: "hookFirst",
1287
- hookName,
1288
- parameters,
1289
- plugin
1290
- });
1409
+ const plugins = this.getPluginsByKey(hookName, pluginKey);
1410
+ return plugins.map((plugin) => {
1411
+ return this.#executeSync({
1412
+ strategy: "hookFirst",
1413
+ hookName,
1414
+ parameters,
1415
+ plugin
1416
+ });
1417
+ }).filter(Boolean);
1291
1418
  }
1292
1419
  /**
1293
1420
  * Chains, first non-null result stops and returns
@@ -1403,37 +1530,58 @@ var PluginManager = class {
1403
1530
  * Chains plugins
1404
1531
  */
1405
1532
  hookSeq({ hookName, parameters }) {
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
- });
1533
+ const promises = this.#getSortedPlugins().map((plugin) => {
1534
+ return () => this.#execute({
1535
+ strategy: "hookSeq",
1536
+ hookName,
1537
+ parameters,
1538
+ plugin
1415
1539
  });
1416
- }
1417
- return promise.then(noReturn);
1540
+ });
1541
+ return executeStrategies.hookSeq(promises);
1418
1542
  }
1419
1543
  #getSortedPlugins(hookName) {
1420
1544
  const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
1421
1545
  if (hookName) {
1546
+ if (this.logger.logLevel === "info") {
1547
+ const containsHookName = plugins.some((item) => item[hookName]);
1548
+ if (!containsHookName) {
1549
+ this.logger.warn(`No hook ${hookName} found`);
1550
+ }
1551
+ }
1422
1552
  return plugins.filter((item) => item[hookName]);
1423
1553
  }
1424
1554
  return plugins;
1425
1555
  }
1426
- getPlugin(hookName, pluginName2) {
1556
+ getPluginsByKey(hookName, pluginKey) {
1427
1557
  const plugins = [...this.plugins];
1428
- const pluginByPluginName = plugins.find((item) => item.name === pluginName2 && item[hookName]);
1429
- if (!pluginByPluginName) {
1430
- return this.#core;
1558
+ const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
1559
+ const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
1560
+ const [kind, name, identifier] = item.key;
1561
+ const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
1562
+ const kindCheck = kind === searchKind;
1563
+ const nameCheck = name === searchPluginName;
1564
+ if (searchIdentifier) {
1565
+ return identifierCheck && kindCheck && nameCheck;
1566
+ }
1567
+ return kindCheck && nameCheck;
1568
+ });
1569
+ if (!pluginByPluginName?.length) {
1570
+ const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
1571
+ if (this.logger.logLevel === "info") {
1572
+ if (corePlugin) {
1573
+ this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
1574
+ } else {
1575
+ this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
1576
+ }
1577
+ }
1578
+ return corePlugin ? [corePlugin] : [];
1431
1579
  }
1432
1580
  return pluginByPluginName;
1433
1581
  }
1434
1582
  #addExecutedToCallStack(executer) {
1435
1583
  if (executer) {
1436
- this.eventEmitter.emit("execute", executer);
1584
+ this.eventEmitter.emit("executed", executer);
1437
1585
  this.executed.push(executer);
1438
1586
  }
1439
1587
  }
@@ -1503,7 +1651,7 @@ var PluginManager = class {
1503
1651
  this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1504
1652
  try {
1505
1653
  if (typeof hook === "function") {
1506
- const fn = hook.apply(this.#core.api, parameters);
1654
+ const fn = hook.apply({ ...this.#core.api, plugin }, parameters);
1507
1655
  output = fn;
1508
1656
  return fn;
1509
1657
  }
@@ -1530,8 +1678,6 @@ var PluginManager = class {
1530
1678
  throw pluginError;
1531
1679
  }
1532
1680
  };
1533
- function noReturn() {
1534
- }
1535
1681
 
1536
1682
  // src/managers/pluginManager/validate.ts
1537
1683
  var ValidationPluginError = class extends Error {
@@ -1552,25 +1698,26 @@ function getDependedPlugins(plugins, dependedPluginNames) {
1552
1698
  });
1553
1699
  }
1554
1700
 
1555
- // src/types.ts
1556
- var LogLevel = {
1557
- silent: "silent",
1558
- info: "info",
1559
- debug: "debug"
1560
- };
1701
+ // src/config.ts
1702
+ function defineConfig(options) {
1703
+ return options;
1704
+ }
1705
+ function isInputPath(result) {
1706
+ return !!result && "path" in result;
1707
+ }
1561
1708
 
1562
1709
  // src/build.ts
1563
1710
  async function transformReducer(_previousCode, result, _plugin) {
1564
1711
  return result;
1565
1712
  }
1566
1713
  async function build(options) {
1567
- const { config, logLevel, logger = createLogger() } = options;
1714
+ const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
1568
1715
  try {
1569
- if ("path" in config.input && !new URLPath(config.input.path).isURL) {
1716
+ if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
1570
1717
  await read(config.input.path);
1571
1718
  }
1572
1719
  } catch (e) {
1573
- if ("path" in config.input) {
1720
+ if (isInputPath(config)) {
1574
1721
  throw new Error(
1575
1722
  "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),
1576
1723
  {
@@ -1583,11 +1730,11 @@ async function build(options) {
1583
1730
  await clean(config.output.path);
1584
1731
  }
1585
1732
  const queueTask = async (file) => {
1586
- const { path: path3 } = file;
1587
- let code = createFileSource(file);
1733
+ const { path: path5 } = file;
1734
+ let code = FileManager.getSource(file);
1588
1735
  const { result: loadedResult } = await pluginManager.hookFirst({
1589
1736
  hookName: "load",
1590
- parameters: [path3]
1737
+ parameters: [path5]
1591
1738
  });
1592
1739
  if (loadedResult && isPromise(loadedResult)) {
1593
1740
  code = await loadedResult;
@@ -1598,28 +1745,53 @@ async function build(options) {
1598
1745
  if (code) {
1599
1746
  const transformedCode = await pluginManager.hookReduceArg0({
1600
1747
  hookName: "transform",
1601
- parameters: [code, path3],
1748
+ parameters: [code, path5],
1602
1749
  reduce: transformReducer
1603
1750
  });
1604
1751
  if (config.output.write || config.output.write === void 0) {
1605
- await pluginManager.hookParallel({
1752
+ if (file.meta?.pluginKey) {
1753
+ return pluginManager.hookForPlugin({
1754
+ pluginKey: file.meta?.pluginKey,
1755
+ hookName: "writeFile",
1756
+ parameters: [transformedCode, path5]
1757
+ });
1758
+ }
1759
+ return pluginManager.hookFirst({
1606
1760
  hookName: "writeFile",
1607
- parameters: [transformedCode, path3]
1761
+ parameters: [transformedCode, path5]
1608
1762
  });
1609
1763
  }
1610
1764
  }
1611
1765
  };
1612
- const pluginManager = new PluginManager(config, { debug: logLevel === LogLevel.debug, logger, task: queueTask });
1766
+ const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
1613
1767
  const { plugins, fileManager } = pluginManager;
1614
1768
  pluginManager.on("execute", (executer) => {
1769
+ const { hookName, parameters, plugin } = executer;
1770
+ if (hookName === "writeFile" && logger.spinner) {
1771
+ const [code] = parameters;
1772
+ if (logger.logLevel === LogLevel.info) {
1773
+ logger.spinner.start(`\u{1F4BE} Writing`);
1774
+ }
1775
+ if (logger.logLevel === "debug") {
1776
+ logger.info(`PluginKey ${pc3__default.default.dim(JSON.stringify(plugin.key))}
1777
+ with source
1778
+
1779
+ ${code}`);
1780
+ }
1781
+ }
1782
+ });
1783
+ pluginManager.on("executed", (executer) => {
1615
1784
  const { hookName, plugin, output, parameters } = executer;
1616
1785
  const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
1617
- if (logLevel === LogLevel.info) {
1618
- if (logger.spinner) {
1786
+ if (logger.logLevel === LogLevel.info && logger.spinner) {
1787
+ if (hookName === "writeFile") {
1788
+ const [_code, path5] = parameters;
1789
+ logger.spinner.suffixText = pc3__default.default.dim(path5);
1790
+ } else {
1619
1791
  logger.spinner.suffixText = messsage;
1620
1792
  }
1621
1793
  }
1622
- if (logLevel === LogLevel.debug) {
1794
+ if (logger.logLevel === LogLevel.debug) {
1623
1795
  logger.info(messsage);
1624
1796
  const logs = [
1625
1797
  parameters && `${pc3__default.default.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
@@ -1639,12 +1811,11 @@ async function build(options) {
1639
1811
  parameters: [config]
1640
1812
  });
1641
1813
  await pluginManager.hookParallel({ hookName: "buildEnd" });
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;
1814
+ if (!fileManager.isExecuting && logger.spinner) {
1815
+ logger.spinner.suffixText = "";
1816
+ logger.spinner.succeed(`\u{1F4BE} Writing completed`);
1817
+ }
1818
+ return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
1648
1819
  }
1649
1820
 
1650
1821
  // src/generators/Generator.ts
@@ -1740,18 +1911,18 @@ function pLimit(concurrency) {
1740
1911
  queue.dequeue()();
1741
1912
  }
1742
1913
  };
1743
- const run = async (fn, resolve, args) => {
1914
+ const run = async (fn, resolve2, args) => {
1744
1915
  activeCount++;
1745
1916
  const result = (async () => fn(...args))();
1746
- resolve(result);
1917
+ resolve2(result);
1747
1918
  try {
1748
1919
  await result;
1749
1920
  } catch {
1750
1921
  }
1751
1922
  next();
1752
1923
  };
1753
- const enqueue = (fn, resolve, args) => {
1754
- queue.enqueue(run.bind(void 0, fn, resolve, args));
1924
+ const enqueue = (fn, resolve2, args) => {
1925
+ queue.enqueue(run.bind(void 0, fn, resolve2, args));
1755
1926
  (async () => {
1756
1927
  await Promise.resolve();
1757
1928
  if (activeCount < concurrency && queue.size > 0) {
@@ -1759,8 +1930,8 @@ function pLimit(concurrency) {
1759
1930
  }
1760
1931
  })();
1761
1932
  };
1762
- const generator = (fn, ...args) => new Promise((resolve) => {
1763
- enqueue(fn, resolve, args);
1933
+ const generator = (fn, ...args) => new Promise((resolve2) => {
1934
+ enqueue(fn, resolve2, args);
1764
1935
  });
1765
1936
  Object.defineProperties(generator, {
1766
1937
  activeCount: {
@@ -1835,7 +2006,7 @@ async function locatePath(paths, {
1835
2006
  const statFunction = allowSymlinks ? fs3.promises.stat : fs3.promises.lstat;
1836
2007
  return pLocate(paths, async (path_) => {
1837
2008
  try {
1838
- const stat = await statFunction(path2__default.default.resolve(cwd, path_));
2009
+ const stat = await statFunction(path4__default.default.resolve(cwd, path_));
1839
2010
  return matchType(type, stat);
1840
2011
  } catch {
1841
2012
  return false;
@@ -1852,7 +2023,7 @@ function locatePathSync(paths, {
1852
2023
  const statFunction = allowSymlinks ? fs3__default.default.statSync : fs3__default.default.lstatSync;
1853
2024
  for (const path_ of paths) {
1854
2025
  try {
1855
- const stat = statFunction(path2__default.default.resolve(cwd, path_), {
2026
+ const stat = statFunction(path4__default.default.resolve(cwd, path_), {
1856
2027
  throwIfNoEntry: false
1857
2028
  });
1858
2029
  if (!stat) {
@@ -1870,9 +2041,9 @@ function locatePathSync(paths, {
1870
2041
  var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? url.fileURLToPath(urlOrPath) : urlOrPath;
1871
2042
  var findUpStop = Symbol("findUpStop");
1872
2043
  async function findUpMultiple(name, options = {}) {
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
+ let directory = path4__default.default.resolve(toPath2(options.cwd) || "");
2045
+ const { root } = path4__default.default.parse(directory);
2046
+ const stopAt = path4__default.default.resolve(directory, options.stopAt || root);
1876
2047
  const limit = options.limit || Number.POSITIVE_INFINITY;
1877
2048
  const paths = [name].flat();
1878
2049
  const runMatcher = async (locateOptions) => {
@@ -1892,18 +2063,18 @@ async function findUpMultiple(name, options = {}) {
1892
2063
  break;
1893
2064
  }
1894
2065
  if (foundPath) {
1895
- matches.push(path2__default.default.resolve(directory, foundPath));
2066
+ matches.push(path4__default.default.resolve(directory, foundPath));
1896
2067
  }
1897
2068
  if (directory === stopAt || matches.length >= limit) {
1898
2069
  break;
1899
2070
  }
1900
- directory = path2__default.default.dirname(directory);
2071
+ directory = path4__default.default.dirname(directory);
1901
2072
  }
1902
2073
  return matches;
1903
2074
  }
1904
2075
  function findUpMultipleSync(name, options = {}) {
1905
- let directory = path2__default.default.resolve(toPath2(options.cwd) || "");
1906
- const { root } = path2__default.default.parse(directory);
2076
+ let directory = path4__default.default.resolve(toPath2(options.cwd) || "");
2077
+ const { root } = path4__default.default.parse(directory);
1907
2078
  const stopAt = options.stopAt || root;
1908
2079
  const limit = options.limit || Number.POSITIVE_INFINITY;
1909
2080
  const paths = [name].flat();
@@ -1924,12 +2095,12 @@ function findUpMultipleSync(name, options = {}) {
1924
2095
  break;
1925
2096
  }
1926
2097
  if (foundPath) {
1927
- matches.push(path2__default.default.resolve(directory, foundPath));
2098
+ matches.push(path4__default.default.resolve(directory, foundPath));
1928
2099
  }
1929
2100
  if (directory === stopAt || matches.length >= limit) {
1930
2101
  break;
1931
2102
  }
1932
- directory = path2__default.default.dirname(directory);
2103
+ directory = path4__default.default.dirname(directory);
1933
2104
  }
1934
2105
  return matches;
1935
2106
  }
@@ -1962,17 +2133,17 @@ var PackageManager = class {
1962
2133
  }
1963
2134
  return directory;
1964
2135
  }
1965
- getLocation(path3) {
1966
- let location = path3;
2136
+ getLocation(path5) {
2137
+ let location = path5;
1967
2138
  if (this.#cwd) {
1968
2139
  const require2 = mod__default.default.createRequire(this.normalizeDirectory(this.#cwd));
1969
- location = require2.resolve(path3);
2140
+ location = require2.resolve(path5);
1970
2141
  }
1971
2142
  return location;
1972
2143
  }
1973
- async import(path3) {
2144
+ async import(path5) {
1974
2145
  try {
1975
- let location = this.getLocation(path3);
2146
+ let location = this.getLocation(path5);
1976
2147
  if (os__default.default.platform() == "win32") {
1977
2148
  location = url.pathToFileURL(location).href;
1978
2149
  }
@@ -2063,31 +2234,21 @@ exports.ValidationPluginError = ValidationPluginError;
2063
2234
  exports.Warning = Warning;
2064
2235
  exports.build = build;
2065
2236
  exports.clean = clean;
2066
- exports.combineCodes = combineCodes;
2067
- exports.combineExports = combineExports;
2068
- exports.combineFiles = combineFiles;
2069
- exports.combineImports = combineImports;
2070
- exports.createFileSource = createFileSource;
2071
2237
  exports.createJSDocBlockText = createJSDocBlockText;
2072
2238
  exports.createLogger = createLogger;
2073
2239
  exports.createPlugin = createPlugin;
2074
2240
  exports.createPluginCache = createPluginCache;
2075
2241
  exports.default = src_default;
2076
- exports.defaultColours = defaultColours;
2077
2242
  exports.defineConfig = defineConfig;
2078
- exports.escape = escape;
2079
- exports.extensions = extensions;
2243
+ exports.executeStrategies = executeStrategies;
2080
2244
  exports.getDependedPlugins = getDependedPlugins;
2081
- exports.getIndexes = getIndexes;
2082
- exports.getPathMode = getPathMode;
2083
2245
  exports.getRelativePath = getRelativePath;
2084
2246
  exports.getUniqueName = getUniqueName;
2085
2247
  exports.hooks = hooks;
2086
- exports.isExtensionAllowed = isExtensionAllowed;
2248
+ exports.isInputPath = isInputPath;
2087
2249
  exports.isPromise = isPromise;
2088
2250
  exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
2089
2251
  exports.isPromiseRejectedResult = isPromiseRejectedResult;
2090
- exports.jsStringEscape = jsStringEscape;
2091
2252
  exports.name = pluginName;
2092
2253
  exports.nameSorter = nameSorter;
2093
2254
  exports.pluginName = pluginName;
@@ -2096,9 +2257,10 @@ exports.randomPicoColour = randomPicoColour;
2096
2257
  exports.read = read;
2097
2258
  exports.readSync = readSync;
2098
2259
  exports.renderTemplate = renderTemplate;
2260
+ exports.setUniqueName = setUniqueName;
2099
2261
  exports.throttle = throttle;
2100
2262
  exports.timeout = timeout;
2101
- exports.transformReservedWord = transformReservedWord;
2263
+ exports.transformers = transformers;
2102
2264
  exports.uniqueIdFactory = uniqueIdFactory;
2103
2265
  exports.write = write;
2104
2266
  //# sourceMappingURL=out.js.map