@kubb/core 1.15.0-canary.20231024T104207 → 1.15.0-canary.20231025T103357

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