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

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/utils.cjs CHANGED
@@ -1,48 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var fs2 = require('fs-extra');
4
3
  var naturalOrderby = require('natural-orderby');
5
4
  var changeCase = require('change-case');
6
- var pc2 = require('picocolors');
7
5
  var crypto = require('crypto');
8
6
  var perf_hooks = require('perf_hooks');
9
7
  var events = require('events');
10
- var seedrandom = require('seedrandom');
11
- var path = require('path');
12
- var jsRuntime = require('js-runtime');
13
- var dirTree = require('directory-tree');
14
- var parser = require('@kubb/parser');
15
- var factory = require('@kubb/parser/factory');
16
- var isEqual = require('lodash.isequal');
17
8
 
18
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
19
10
 
20
- function _interopNamespace(e) {
21
- if (e && e.__esModule) return e;
22
- var n = Object.create(null);
23
- if (e) {
24
- Object.keys(e).forEach(function (k) {
25
- if (k !== 'default') {
26
- var d = Object.getOwnPropertyDescriptor(e, k);
27
- Object.defineProperty(n, k, d.get ? d : {
28
- enumerable: true,
29
- get: function () { return e[k]; }
30
- });
31
- }
32
- });
33
- }
34
- n.default = e;
35
- return Object.freeze(n);
36
- }
37
-
38
- var fs2__default = /*#__PURE__*/_interopDefault(fs2);
39
- var pc2__default = /*#__PURE__*/_interopDefault(pc2);
40
11
  var crypto__default = /*#__PURE__*/_interopDefault(crypto);
41
- var seedrandom__default = /*#__PURE__*/_interopDefault(seedrandom);
42
- var path__default = /*#__PURE__*/_interopDefault(path);
43
- var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
44
- var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
45
- var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
46
12
 
47
13
  var __accessCheck = (obj, member, msg) => {
48
14
  if (!member.has(obj))
@@ -74,37 +40,6 @@ var __privateMethod = (obj, member, method) => {
74
40
  __accessCheck(obj, member, "access private method");
75
41
  return method;
76
42
  };
77
-
78
- // src/utils/cache.ts
79
- function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
80
- return {
81
- set(id, value) {
82
- Store[id] = [0, value];
83
- },
84
- get(id) {
85
- const item = Store[id];
86
- if (!item) {
87
- return null;
88
- }
89
- item[0] = 0;
90
- return item[1];
91
- },
92
- has(id) {
93
- const item = Store[id];
94
- if (!item) {
95
- return false;
96
- }
97
- item[0] = 0;
98
- return true;
99
- },
100
- delete(id) {
101
- return delete Store[id];
102
- }
103
- };
104
- }
105
- async function clean(path2) {
106
- return fs2.remove(path2);
107
- }
108
43
  function camelCase(text) {
109
44
  return changeCase.camelCase(text, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: changeCase.camelCaseTransformMerge });
110
45
  }
@@ -344,48 +279,6 @@ var FunctionParams = class {
344
279
  }, []).join(", ");
345
280
  }
346
281
  };
347
- var LogLevel = {
348
- silent: "silent",
349
- info: "info",
350
- debug: "debug"
351
- };
352
- function createLogger({ logLevel, name, spinner }) {
353
- const logs = [];
354
- const log = (message) => {
355
- if (message && spinner) {
356
- spinner.text = message;
357
- logs.push(message);
358
- }
359
- };
360
- const error = (message) => {
361
- if (message) {
362
- throw new Error(message || "Something went wrong");
363
- }
364
- };
365
- const warn = (message) => {
366
- if (message && spinner) {
367
- spinner.warn(pc2__default.default.yellow(message));
368
- logs.push(message);
369
- }
370
- };
371
- const info = (message) => {
372
- if (message && spinner && logLevel !== LogLevel.silent) {
373
- spinner.info(message);
374
- logs.push(message);
375
- }
376
- };
377
- const logger = {
378
- name,
379
- logLevel,
380
- log,
381
- error,
382
- warn,
383
- info,
384
- spinner,
385
- logs
386
- };
387
- return logger;
388
- }
389
282
 
390
283
  // src/utils/promise.ts
391
284
  function isPromise(result) {
@@ -432,8 +325,8 @@ var Queue = class {
432
325
  __privateSet(this, _debug, debug);
433
326
  }
434
327
  run(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
435
- return new Promise((resolve3, reject) => {
436
- const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
328
+ return new Promise((resolve, reject) => {
329
+ const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
437
330
  options.controller?.signal.addEventListener("abort", () => {
438
331
  __privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
439
332
  reject("Aborted");
@@ -443,8 +336,8 @@ var Queue = class {
443
336
  });
444
337
  }
445
338
  runSync(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
446
- new Promise((resolve3, reject) => {
447
- const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
339
+ new Promise((resolve, reject) => {
340
+ const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
448
341
  options.controller?.signal.addEventListener("abort", () => {
449
342
  __privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
450
343
  });
@@ -471,13 +364,13 @@ work_fn = function() {
471
364
  __privateWrapper(this, _workerCount)._++;
472
365
  let entry;
473
366
  while (entry = __privateGet(this, _queue).shift()) {
474
- const { reject, resolve: resolve3, job, name, description } = entry;
367
+ const { reject, resolve, job, name, description } = entry;
475
368
  if (__privateGet(this, _debug)) {
476
369
  perf_hooks.performance.mark(name + "_start");
477
370
  }
478
371
  job().then((result) => {
479
372
  this.eventEmitter.emit("jobDone", result);
480
- resolve3(result);
373
+ resolve(result);
481
374
  if (__privateGet(this, _debug)) {
482
375
  perf_hooks.performance.mark(name + "_stop");
483
376
  perf_hooks.performance.measure(description, name + "_start", name + "_stop");
@@ -489,79 +382,6 @@ work_fn = function() {
489
382
  }
490
383
  __privateWrapper(this, _workerCount)._--;
491
384
  };
492
- var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
493
- function randomColour(text, colours = defaultColours) {
494
- if (!text) {
495
- return "white";
496
- }
497
- const random = seedrandom__default.default(text);
498
- const colour = colours.at(Math.floor(random() * colours.length)) || "white";
499
- return colour;
500
- }
501
- function randomPicoColour(text, colors = defaultColours) {
502
- const colours = pc2__default.default.createColors(true);
503
- if (!text) {
504
- return colours.white(text);
505
- }
506
- const colour = randomColour(text, colors);
507
- const isDark = colour.includes("dark");
508
- const key = colour.replace("dark", "").toLowerCase();
509
- const formatter = colours[key];
510
- if (isDark) {
511
- return pc2__default.default.bold(formatter(text));
512
- }
513
- if (typeof formatter !== "function") {
514
- throw new Error("Formatter for picoColor is not of type function/Formatter");
515
- }
516
- return formatter(text);
517
- }
518
- function slash(path2, platform = "linux") {
519
- const isWindowsPath = /^\\\\\?\\/.test(path2);
520
- if (["linux", "mac"].includes(platform) && !isWindowsPath) {
521
- return path2.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
522
- }
523
- return path2.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
524
- }
525
- function getRelativePath(rootDir, filePath, platform = "linux") {
526
- if (!rootDir || !filePath) {
527
- throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
528
- }
529
- const relativePath = path.relative(rootDir, filePath);
530
- const slashedPath = slash(relativePath, platform);
531
- if (slashedPath.startsWith("../")) {
532
- return slashedPath.replace(path.basename(slashedPath), path.basename(slashedPath, path.extname(filePath)));
533
- }
534
- return `./${slashedPath.replace(path.basename(slashedPath), path.basename(slashedPath, path.extname(filePath)))}`;
535
- }
536
- var reader = jsRuntime.switcher(
537
- {
538
- node: async (path2) => {
539
- return fs2__default.default.readFile(path2, { encoding: "utf8" });
540
- },
541
- bun: async (path2) => {
542
- const file = Bun.file(path2);
543
- return file.text();
544
- }
545
- },
546
- "node"
547
- );
548
- var syncReader = jsRuntime.switcher(
549
- {
550
- node: (path2) => {
551
- return fs2__default.default.readFileSync(path2, { encoding: "utf8" });
552
- },
553
- bun: () => {
554
- throw new Error("Bun cannot read sync");
555
- }
556
- },
557
- "node"
558
- );
559
- async function read(path2) {
560
- return reader(path2);
561
- }
562
- function readSync(path2) {
563
- return syncReader(path2);
564
- }
565
385
 
566
386
  // src/utils/renderTemplate.ts
567
387
  function renderTemplate(template, data = void 0) {
@@ -587,571 +407,14 @@ function renderTemplate(template, data = void 0) {
587
407
  }, template) || "";
588
408
  }
589
409
 
590
- // src/utils/throttle.ts
591
- var throttle = (fn, delay) => {
592
- let wait = false;
593
- let timeout2;
594
- let cancelled = false;
595
- return [
596
- (...args) => {
597
- if (cancelled) {
598
- return void 0;
599
- }
600
- if (wait) {
601
- return void 0;
602
- }
603
- const val = fn(...args);
604
- wait = true;
605
- timeout2 = setTimeout(() => {
606
- wait = false;
607
- }, delay);
608
- return val;
609
- },
610
- () => {
611
- cancelled = true;
612
- clearTimeout(timeout2);
613
- }
614
- ];
615
- };
616
-
617
410
  // src/utils/timeout.ts
618
411
  async function timeout(ms) {
619
- return new Promise((resolve3) => {
412
+ return new Promise((resolve) => {
620
413
  setTimeout(() => {
621
- resolve3(true);
414
+ resolve(true);
622
415
  }, ms);
623
416
  });
624
417
  }
625
- async function saveCreateDirectory(path2) {
626
- const passedPath = path.dirname(path.resolve(path2));
627
- await fs2__default.default.mkdir(passedPath, { recursive: true });
628
- }
629
- var writer = jsRuntime.switcher(
630
- {
631
- node: async (path2, data) => {
632
- try {
633
- await fs2__default.default.stat(path.resolve(path2));
634
- const oldContent = await fs2__default.default.readFile(path.resolve(path2), { encoding: "utf-8" });
635
- if (oldContent?.toString() === data?.toString()) {
636
- return;
637
- }
638
- } catch (_err) {
639
- }
640
- await saveCreateDirectory(path2);
641
- await fs2__default.default.writeFile(path.resolve(path2), data, { encoding: "utf-8" });
642
- const savedData = await fs2__default.default.readFile(path.resolve(path2), { encoding: "utf-8" });
643
- if (savedData?.toString() !== data?.toString()) {
644
- throw new Error(`Sanity check failed for ${path2}
645
-
646
- Data[${data.length}]:
647
- ${data}
648
-
649
- Saved[${savedData.length}]:
650
- ${savedData}
651
- `);
652
- }
653
- return savedData;
654
- },
655
- bun: async (path2, data) => {
656
- try {
657
- await saveCreateDirectory(path2);
658
- await Bun.write(path.resolve(path2), data);
659
- const file = Bun.file(path.resolve(path2));
660
- const savedData = await file.text();
661
- if (savedData?.toString() !== data?.toString()) {
662
- throw new Error(`Sanity check failed for ${path2}
663
-
664
- Data[${data.length}]:
665
- ${data}
666
-
667
- Saved[${savedData.length}]:
668
- ${savedData}
669
- `);
670
- }
671
- return savedData;
672
- } catch (e) {
673
- console.log(e, path.resolve(path2));
674
- }
675
- }
676
- },
677
- "node"
678
- );
679
- async function write(data, path2) {
680
- if (data.trim() === "") {
681
- return void 0;
682
- }
683
- return writer(path2, data.trim());
684
- }
685
- var _options;
686
- var BarrelManager = class {
687
- constructor(options = {}) {
688
- __privateAdd(this, _options, void 0);
689
- __privateSet(this, _options, options);
690
- return this;
691
- }
692
- getIndexes(pathToBuild) {
693
- const { treeNode = {}, isTypeOnly, extName } = __privateGet(this, _options);
694
- const tree = TreeNode.build(pathToBuild, treeNode);
695
- if (!tree) {
696
- return null;
697
- }
698
- const fileReducer = (files, treeNode2) => {
699
- if (!treeNode2.children) {
700
- return [];
701
- }
702
- if (treeNode2.children.length > 1) {
703
- const indexPath = path__default.default.resolve(treeNode2.data.path, "index.ts");
704
- const exports = treeNode2.children.filter(Boolean).map((file) => {
705
- const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${transformers_default.trimExtName(file.data.name)}`;
706
- if (importPath.endsWith("index") && file.data.type === "file") {
707
- return void 0;
708
- }
709
- return {
710
- path: extName ? `${importPath}${extName}` : importPath,
711
- isTypeOnly
712
- };
713
- }).filter(Boolean);
714
- files.push({
715
- path: indexPath,
716
- baseName: "index.ts",
717
- source: "",
718
- exports,
719
- meta: {
720
- treeNode: treeNode2
721
- }
722
- });
723
- } else if (treeNode2.children.length === 1) {
724
- const [treeNodeChild] = treeNode2.children;
725
- const indexPath = path__default.default.resolve(treeNode2.data.path, "index.ts");
726
- const importPath = treeNodeChild.data.type === "directory" ? `./${treeNodeChild.data.name}/index` : `./${transformers_default.trimExtName(treeNodeChild.data.name)}`;
727
- const exports = [
728
- {
729
- path: extName ? `${importPath}${extName}` : importPath,
730
- isTypeOnly
731
- }
732
- ];
733
- files.push({
734
- path: indexPath,
735
- baseName: "index.ts",
736
- source: "",
737
- exports,
738
- meta: {
739
- treeNode: treeNode2
740
- }
741
- });
742
- }
743
- treeNode2.children.forEach((childItem) => {
744
- fileReducer(files, childItem);
745
- });
746
- return files;
747
- };
748
- return fileReducer([], tree).reverse();
749
- }
750
- };
751
- _options = new WeakMap();
752
- var _cache, _task, _isWriting, _timeout, _queue2, _validate, _add, add_fn, _addOrAppend, addOrAppend_fn;
753
- var _FileManager = class _FileManager {
754
- constructor(options) {
755
- __privateAdd(this, _validate);
756
- __privateAdd(this, _add);
757
- __privateAdd(this, _addOrAppend);
758
- __privateAdd(this, _cache, /* @__PURE__ */ new Map());
759
- __privateAdd(this, _task, void 0);
760
- __privateAdd(this, _isWriting, false);
761
- /**
762
- * Timeout between writes
763
- */
764
- __privateAdd(this, _timeout, 0);
765
- __privateAdd(this, _queue2, void 0);
766
- if (options) {
767
- __privateSet(this, _task, options.task);
768
- __privateSet(this, _queue2, options.queue);
769
- __privateSet(this, _timeout, options.timeout || 0);
770
- }
771
- return this;
772
- }
773
- get files() {
774
- const files = [];
775
- __privateGet(this, _cache).forEach((item) => {
776
- files.push(...item.flat(1));
777
- });
778
- return files;
779
- }
780
- get isExecuting() {
781
- return __privateGet(this, _queue2)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
782
- }
783
- async add(...files) {
784
- const promises = files.map((file) => {
785
- if (file.override) {
786
- return __privateMethod(this, _add, add_fn).call(this, file);
787
- }
788
- return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
789
- });
790
- const resolvedFiles = await Promise.all(promises);
791
- if (files.length > 1) {
792
- return resolvedFiles;
793
- }
794
- return resolvedFiles[0];
795
- }
796
- async addIndexes({ root, output, meta, options = {} }) {
797
- const { exportType = "barrel" } = output;
798
- if (!exportType) {
799
- return void 0;
800
- }
801
- const exportPath = output.path.startsWith("./") ? output.path : `./${output.path}`;
802
- const barrelManager = new BarrelManager({ extName: output.extName, ...options });
803
- const files = barrelManager.getIndexes(path.resolve(root, output.path));
804
- if (!files) {
805
- return void 0;
806
- }
807
- const rootFile = {
808
- path: path.resolve(root, "index.ts"),
809
- baseName: "index.ts",
810
- source: "",
811
- exports: [
812
- output.exportAs ? {
813
- name: output.exportAs,
814
- asAlias: true,
815
- path: exportPath,
816
- isTypeOnly: options.isTypeOnly
817
- } : {
818
- path: exportPath,
819
- isTypeOnly: options.isTypeOnly
820
- }
821
- ]
822
- };
823
- await __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
824
- ...rootFile,
825
- meta: meta ? meta : rootFile.meta
826
- });
827
- return await Promise.all(
828
- files.map((file) => {
829
- return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
830
- ...file,
831
- meta: meta ? meta : file.meta
832
- });
833
- })
834
- );
835
- }
836
- getCacheByUUID(UUID) {
837
- let cache;
838
- __privateGet(this, _cache).forEach((files) => {
839
- cache = files.find((item) => item.id === UUID);
840
- });
841
- return cache;
842
- }
843
- get(path2) {
844
- return __privateGet(this, _cache).get(path2);
845
- }
846
- remove(path2) {
847
- const cacheItem = this.get(path2);
848
- if (!cacheItem) {
849
- return;
850
- }
851
- __privateGet(this, _cache).delete(path2);
852
- }
853
- async write(...params) {
854
- if (!__privateGet(this, _isWriting)) {
855
- __privateSet(this, _isWriting, true);
856
- const text = await write(...params);
857
- __privateSet(this, _isWriting, false);
858
- return text;
859
- }
860
- await timeout(__privateGet(this, _timeout));
861
- return this.write(...params);
862
- }
863
- async read(...params) {
864
- return read(...params);
865
- }
866
- // statics
867
- static getSource(file) {
868
- if (!_FileManager.isExtensionAllowed(file.baseName)) {
869
- return file.source;
870
- }
871
- const exports = file.exports ? combineExports(file.exports) : [];
872
- const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
873
- const importNodes = imports.filter((item) => {
874
- return item.path !== transformers_default.trimExtName(file.path);
875
- }).map((item) => {
876
- return factory__namespace.createImportDeclaration({
877
- name: item.name,
878
- path: item.root ? getRelativePath(item.root, item.path) : item.path,
879
- isTypeOnly: item.isTypeOnly
880
- });
881
- });
882
- const exportNodes = exports.map(
883
- (item) => factory__namespace.createExportDeclaration({
884
- name: item.name,
885
- path: item.path,
886
- isTypeOnly: item.isTypeOnly,
887
- asAlias: item.asAlias
888
- })
889
- );
890
- return [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
891
- }
892
- static combineFiles(files) {
893
- return files.filter(Boolean).reduce((acc, file) => {
894
- const prevIndex = acc.findIndex((item) => item.path === file.path);
895
- if (prevIndex === -1) {
896
- return [...acc, file];
897
- }
898
- const prev = acc[prevIndex];
899
- if (prev && file.override) {
900
- acc[prevIndex] = {
901
- imports: [],
902
- exports: [],
903
- ...file
904
- };
905
- return acc;
906
- }
907
- if (prev) {
908
- acc[prevIndex] = {
909
- ...file,
910
- source: prev.source && file.source ? `${prev.source}
911
- ${file.source}` : "",
912
- imports: [...prev.imports || [], ...file.imports || []],
913
- exports: [...prev.exports || [], ...file.exports || []],
914
- env: { ...prev.env || {}, ...file.env || {} }
915
- };
916
- }
917
- return acc;
918
- }, []);
919
- }
920
- static getMode(path2) {
921
- if (!path2) {
922
- return "directory";
923
- }
924
- return path.extname(path2) ? "file" : "directory";
925
- }
926
- static get extensions() {
927
- return [".js", ".ts", ".tsx"];
928
- }
929
- static isExtensionAllowed(baseName) {
930
- return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
931
- }
932
- };
933
- _cache = new WeakMap();
934
- _task = new WeakMap();
935
- _isWriting = new WeakMap();
936
- _timeout = new WeakMap();
937
- _queue2 = new WeakMap();
938
- _validate = new WeakSet();
939
- _add = new WeakSet();
940
- add_fn = async function(file) {
941
- const controller = new AbortController();
942
- const resolvedFile = { id: crypto__default.default.randomUUID(), name: transformers_default.trimExtName(file.baseName), ...file };
943
- __privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
944
- if (__privateGet(this, _queue2)) {
945
- await __privateGet(this, _queue2).run(
946
- async () => {
947
- var _a;
948
- return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
949
- },
950
- { controller }
951
- );
952
- }
953
- return resolvedFile;
954
- };
955
- _addOrAppend = new WeakSet();
956
- addOrAppend_fn = async function(file) {
957
- const previousCaches = __privateGet(this, _cache).get(file.path);
958
- const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
959
- if (previousCache) {
960
- __privateGet(this, _cache).delete(previousCache.path);
961
- return __privateMethod(this, _add, add_fn).call(this, {
962
- ...file,
963
- source: previousCache.source && file.source ? `${previousCache.source}
964
- ${file.source}` : "",
965
- imports: [...previousCache.imports || [], ...file.imports || []],
966
- exports: [...previousCache.exports || [], ...file.exports || []],
967
- env: { ...previousCache.env || {}, ...file.env || {} }
968
- });
969
- }
970
- return __privateMethod(this, _add, add_fn).call(this, file);
971
- };
972
- var FileManager = _FileManager;
973
- function combineExports(exports) {
974
- const combinedExports = naturalOrderby.orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
975
- const name = curr.name;
976
- const prevByPath = prev.findLast((imp) => imp.path === curr.path);
977
- const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
978
- if (prevByPathAndIsTypeOnly) {
979
- return prev;
980
- }
981
- const uniquePrev = prev.findLast(
982
- (imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
983
- );
984
- if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
985
- return prev;
986
- }
987
- if (!prevByPath) {
988
- return [
989
- ...prev,
990
- {
991
- ...curr,
992
- name: Array.isArray(name) ? [...new Set(name)] : name
993
- }
994
- ];
995
- }
996
- if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
997
- prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
998
- return prev;
999
- }
1000
- return [...prev, curr];
1001
- }, []);
1002
- return naturalOrderby.orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
1003
- }
1004
- function combineImports(imports, exports, source) {
1005
- const combinedImports = naturalOrderby.orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
1006
- let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
1007
- const hasImportInSource = (importName) => {
1008
- if (!source) {
1009
- return true;
1010
- }
1011
- const checker = (name2) => name2 && !!source.includes(name2);
1012
- return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
1013
- };
1014
- if (Array.isArray(name)) {
1015
- name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
1016
- }
1017
- const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
1018
- const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
1019
- const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
1020
- if (prevByPathNameAndIsTypeOnly) {
1021
- return prev;
1022
- }
1023
- if (uniquePrev || Array.isArray(name) && !name.length) {
1024
- return prev;
1025
- }
1026
- if (!prevByPath) {
1027
- return [
1028
- ...prev,
1029
- {
1030
- ...curr,
1031
- name
1032
- }
1033
- ];
1034
- }
1035
- if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
1036
- prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
1037
- return prev;
1038
- }
1039
- if (!Array.isArray(name) && name && !hasImportInSource(name)) {
1040
- return prev;
1041
- }
1042
- return [...prev, curr];
1043
- }, []);
1044
- return naturalOrderby.orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
1045
- }
1046
- function getEnvSource(source, env) {
1047
- if (!env) {
1048
- return source;
1049
- }
1050
- const keys = Object.keys(env);
1051
- if (!keys.length) {
1052
- return source;
1053
- }
1054
- return keys.reduce((prev, key) => {
1055
- const environmentValue = env[key];
1056
- const replaceBy = environmentValue ? `'${environmentValue.replaceAll('"', "")?.replaceAll("'", "")}'` : "undefined";
1057
- if (key.toUpperCase() !== key) {
1058
- throw new TypeError(`Environment should be in upperCase for ${key}`);
1059
- }
1060
- if (typeof replaceBy === "string") {
1061
- prev = transformers_default.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
1062
- prev = transformers_default.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
1063
- `, "ig"), ""), replaceBy, key });
1064
- }
1065
- return prev;
1066
- }, source);
1067
- }
1068
-
1069
- // src/utils/TreeNode.ts
1070
- var TreeNode = class _TreeNode {
1071
- constructor(data, parent) {
1072
- this.children = [];
1073
- this.data = data;
1074
- this.parent = parent;
1075
- return this;
1076
- }
1077
- addChild(data) {
1078
- const child = new _TreeNode(data, this);
1079
- if (!this.children) {
1080
- this.children = [];
1081
- }
1082
- this.children.push(child);
1083
- return child;
1084
- }
1085
- find(data) {
1086
- if (!data) {
1087
- return null;
1088
- }
1089
- if (data === this.data) {
1090
- return this;
1091
- }
1092
- if (this.children?.length) {
1093
- for (let i = 0, { length } = this.children, target = null; i < length; i++) {
1094
- target = this.children[i].find(data);
1095
- if (target) {
1096
- return target;
1097
- }
1098
- }
1099
- }
1100
- return null;
1101
- }
1102
- get leaves() {
1103
- if (!this.children || this.children.length === 0) {
1104
- return [this];
1105
- }
1106
- const leaves = [];
1107
- if (this.children) {
1108
- for (let i = 0, { length } = this.children; i < length; i++) {
1109
- leaves.push.apply(leaves, this.children[i].leaves);
1110
- }
1111
- }
1112
- return leaves;
1113
- }
1114
- get root() {
1115
- if (!this.parent) {
1116
- return this;
1117
- }
1118
- return this.parent.root;
1119
- }
1120
- forEach(callback) {
1121
- if (typeof callback !== "function") {
1122
- throw new TypeError("forEach() callback must be a function");
1123
- }
1124
- callback(this);
1125
- if (this.children) {
1126
- for (let i = 0, { length } = this.children; i < length; i++) {
1127
- this.children[i].forEach(callback);
1128
- }
1129
- }
1130
- return this;
1131
- }
1132
- static build(path2, options = {}) {
1133
- try {
1134
- const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
1135
- const filteredTree = dirTree__default.default(path2, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
1136
- if (!filteredTree) {
1137
- return null;
1138
- }
1139
- const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || FileManager.getMode(filteredTree.path) });
1140
- const recurse = (node, item) => {
1141
- const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || FileManager.getMode(item.path) });
1142
- if (item.children?.length) {
1143
- item.children?.forEach((child) => {
1144
- recurse(subNode, child);
1145
- });
1146
- }
1147
- };
1148
- filteredTree.children?.forEach((child) => recurse(treeNode, child));
1149
- return treeNode;
1150
- } catch (e) {
1151
- throw new Error("Something went wrong with creating index files with the TreehNode class", { cause: e });
1152
- }
1153
- }
1154
- };
1155
418
 
1156
419
  // src/utils/uniqueName.ts
1157
420
  function getUniqueName(originalName, data) {
@@ -1175,8 +438,8 @@ function setUniqueName(originalName, data) {
1175
438
 
1176
439
  // src/utils/URLPath.ts
1177
440
  var URLPath = class {
1178
- constructor(path2) {
1179
- this.path = path2;
441
+ constructor(path) {
442
+ this.path = path;
1180
443
  return this;
1181
444
  }
1182
445
  /**
@@ -1270,31 +533,15 @@ var URLPath = class {
1270
533
  }
1271
534
  };
1272
535
 
1273
- Object.defineProperty(exports, 'pc', {
1274
- enumerable: true,
1275
- get: function () { return pc2__default.default; }
1276
- });
1277
536
  exports.FunctionParams = FunctionParams;
1278
- exports.LogLevel = LogLevel;
1279
537
  exports.Queue = Queue;
1280
- exports.TreeNode = TreeNode;
1281
538
  exports.URLPath = URLPath;
1282
- exports.clean = clean;
1283
- exports.createLogger = createLogger;
1284
- exports.createPluginCache = createPluginCache;
1285
- exports.getRelativePath = getRelativePath;
1286
539
  exports.getUniqueName = getUniqueName;
1287
540
  exports.isPromise = isPromise;
1288
541
  exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
1289
542
  exports.isPromiseRejectedResult = isPromiseRejectedResult;
1290
- exports.randomColour = randomColour;
1291
- exports.randomPicoColour = randomPicoColour;
1292
- exports.read = read;
1293
- exports.readSync = readSync;
1294
543
  exports.renderTemplate = renderTemplate;
1295
544
  exports.setUniqueName = setUniqueName;
1296
- exports.throttle = throttle;
1297
545
  exports.timeout = timeout;
1298
- exports.write = write;
1299
546
  //# sourceMappingURL=out.js.map
1300
547
  //# sourceMappingURL=utils.cjs.map