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