@kubb/core 1.15.0-canary.20231023T125852 → 1.15.0-canary.20231024T104207
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +447 -285
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +238 -168
- package/dist/index.d.ts +238 -168
- package/dist/index.js +427 -256
- package/dist/index.js.map +1 -1
- package/globals.d.ts +33 -16
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -2,17 +2,17 @@ import mod, { createRequire } from 'module';
|
|
|
2
2
|
import pc3 from 'picocolors';
|
|
3
3
|
export { default as pc } from 'picocolors';
|
|
4
4
|
import crypto from 'crypto';
|
|
5
|
+
import path, { resolve, relative, basename, extname, dirname } from 'path';
|
|
5
6
|
import fs2, { remove } from 'fs-extra';
|
|
6
7
|
import { camelCase, camelCaseTransformMerge } from 'change-case';
|
|
7
8
|
import { orderBy } from 'natural-orderby';
|
|
8
9
|
import { performance } from 'perf_hooks';
|
|
10
|
+
import { EventEmitter as EventEmitter$1 } from 'events';
|
|
9
11
|
import seedrandom from 'seedrandom';
|
|
10
|
-
import pathParser from 'path';
|
|
11
12
|
import { switcher } from 'js-runtime';
|
|
12
13
|
import dirTree from 'directory-tree';
|
|
13
|
-
import { createImportDeclaration,
|
|
14
|
+
import { createImportDeclaration, createExportDeclaration, print } from '@kubb/parser';
|
|
14
15
|
import isEqual from 'lodash.isequal';
|
|
15
|
-
import { EventEmitter as EventEmitter$1 } from 'events';
|
|
16
16
|
import os from 'os';
|
|
17
17
|
import { pathToFileURL } from 'url';
|
|
18
18
|
import { findUp, findUpSync } from 'find-up';
|
|
@@ -55,8 +55,8 @@ function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
async function clean(
|
|
59
|
-
return remove(
|
|
58
|
+
async function clean(path3) {
|
|
59
|
+
return remove(path3);
|
|
60
60
|
}
|
|
61
61
|
var FunctionParams = class {
|
|
62
62
|
type;
|
|
@@ -98,20 +98,9 @@ var FunctionParams = class {
|
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
// src/utils/getUniqueName.ts
|
|
102
|
-
function getUniqueName(originalName, data) {
|
|
103
|
-
let used = data[originalName] || 0;
|
|
104
|
-
if (used) {
|
|
105
|
-
data[originalName] = ++used;
|
|
106
|
-
originalName += used;
|
|
107
|
-
}
|
|
108
|
-
data[originalName] = 1;
|
|
109
|
-
return originalName;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
101
|
// src/utils/isPromise.ts
|
|
113
102
|
function isPromise(result) {
|
|
114
|
-
return typeof result?.then === "function";
|
|
103
|
+
return !!result && typeof result?.then === "function";
|
|
115
104
|
}
|
|
116
105
|
function isPromiseFulfilledResult(result) {
|
|
117
106
|
return result.status === "fulfilled";
|
|
@@ -130,7 +119,7 @@ function createJSDocBlockText({ comments }) {
|
|
|
130
119
|
* ${filteredComments.join("\n * ")}
|
|
131
120
|
*/`;
|
|
132
121
|
}
|
|
133
|
-
function createLogger(spinner) {
|
|
122
|
+
function createLogger({ logLevel, name, spinner }) {
|
|
134
123
|
const logs = [];
|
|
135
124
|
const log = (message) => {
|
|
136
125
|
if (message && spinner) {
|
|
@@ -156,6 +145,8 @@ function createLogger(spinner) {
|
|
|
156
145
|
}
|
|
157
146
|
};
|
|
158
147
|
const logger = {
|
|
148
|
+
name,
|
|
149
|
+
logLevel,
|
|
159
150
|
log,
|
|
160
151
|
error,
|
|
161
152
|
warn,
|
|
@@ -176,8 +167,29 @@ function nameSorter(a, b) {
|
|
|
176
167
|
}
|
|
177
168
|
return 0;
|
|
178
169
|
}
|
|
170
|
+
var EventEmitter = class {
|
|
171
|
+
constructor() {
|
|
172
|
+
this.#emitter.setMaxListeners(100);
|
|
173
|
+
}
|
|
174
|
+
#emitter = new EventEmitter$1();
|
|
175
|
+
emit(eventName, ...eventArg) {
|
|
176
|
+
this.#emitter.emit(eventName, ...eventArg);
|
|
177
|
+
}
|
|
178
|
+
on(eventName, handler) {
|
|
179
|
+
this.#emitter.on(eventName, handler);
|
|
180
|
+
}
|
|
181
|
+
off(eventName, handler) {
|
|
182
|
+
this.#emitter.off(eventName, handler);
|
|
183
|
+
}
|
|
184
|
+
removeAll() {
|
|
185
|
+
this.#emitter.removeAllListeners();
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// src/utils/Queue.ts
|
|
179
190
|
var Queue = class {
|
|
180
191
|
#queue = [];
|
|
192
|
+
eventEmitter = new EventEmitter();
|
|
181
193
|
#workerCount = 0;
|
|
182
194
|
#maxParallel;
|
|
183
195
|
#debug = false;
|
|
@@ -186,8 +198,8 @@ var Queue = class {
|
|
|
186
198
|
this.#debug = debug;
|
|
187
199
|
}
|
|
188
200
|
run(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
189
|
-
return new Promise((
|
|
190
|
-
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
201
|
+
return new Promise((resolve2, reject) => {
|
|
202
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
191
203
|
options.controller?.signal.addEventListener("abort", () => {
|
|
192
204
|
this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
|
|
193
205
|
reject("Aborted");
|
|
@@ -197,8 +209,8 @@ var Queue = class {
|
|
|
197
209
|
});
|
|
198
210
|
}
|
|
199
211
|
runSync(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
200
|
-
new Promise((
|
|
201
|
-
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
212
|
+
new Promise((resolve2, reject) => {
|
|
213
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
202
214
|
options.controller?.signal.addEventListener("abort", () => {
|
|
203
215
|
this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
|
|
204
216
|
});
|
|
@@ -219,17 +231,21 @@ var Queue = class {
|
|
|
219
231
|
this.#workerCount++;
|
|
220
232
|
let entry;
|
|
221
233
|
while (entry = this.#queue.shift()) {
|
|
222
|
-
const { reject, resolve, job, name, description } = entry;
|
|
234
|
+
const { reject, resolve: resolve2, job, name, description } = entry;
|
|
223
235
|
if (this.#debug) {
|
|
224
236
|
performance.mark(name + "_start");
|
|
225
237
|
}
|
|
226
238
|
job().then((result) => {
|
|
227
|
-
|
|
239
|
+
this.eventEmitter.emit("jobDone", result);
|
|
240
|
+
resolve2(result);
|
|
228
241
|
if (this.#debug) {
|
|
229
242
|
performance.mark(name + "_stop");
|
|
230
243
|
performance.measure(description, name + "_start", name + "_stop");
|
|
231
244
|
}
|
|
232
|
-
}).catch((err) =>
|
|
245
|
+
}).catch((err) => {
|
|
246
|
+
this.eventEmitter.emit("jobFailed", err);
|
|
247
|
+
reject(err);
|
|
248
|
+
});
|
|
233
249
|
}
|
|
234
250
|
this.#workerCount--;
|
|
235
251
|
}
|
|
@@ -260,37 +276,31 @@ function randomPicoColour(text, colors = defaultColours) {
|
|
|
260
276
|
}
|
|
261
277
|
return formatter(text);
|
|
262
278
|
}
|
|
263
|
-
function slash(
|
|
264
|
-
const isWindowsPath = /^\\\\\?\\/.test(
|
|
279
|
+
function slash(path3, platform = "linux") {
|
|
280
|
+
const isWindowsPath = /^\\\\\?\\/.test(path3);
|
|
265
281
|
if (["linux", "mac"].includes(platform) && !isWindowsPath) {
|
|
266
|
-
return
|
|
282
|
+
return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
267
283
|
}
|
|
268
|
-
return
|
|
284
|
+
return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
269
285
|
}
|
|
270
286
|
function getRelativePath(rootDir, filePath, platform = "linux") {
|
|
271
287
|
if (!rootDir || !filePath) {
|
|
272
288
|
throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
|
|
273
289
|
}
|
|
274
|
-
const relativePath =
|
|
275
|
-
const
|
|
276
|
-
if (
|
|
277
|
-
return
|
|
278
|
-
}
|
|
279
|
-
return `./${path.replace(pathParser.basename(path), pathParser.basename(path, pathParser.extname(filePath)))}`;
|
|
280
|
-
}
|
|
281
|
-
function getPathMode(path) {
|
|
282
|
-
if (!path) {
|
|
283
|
-
return "directory";
|
|
290
|
+
const relativePath = relative(rootDir, filePath);
|
|
291
|
+
const slashedPath = slash(relativePath, platform);
|
|
292
|
+
if (slashedPath.startsWith("../")) {
|
|
293
|
+
return slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)));
|
|
284
294
|
}
|
|
285
|
-
return
|
|
295
|
+
return `./${slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)))}`;
|
|
286
296
|
}
|
|
287
297
|
var reader = switcher(
|
|
288
298
|
{
|
|
289
|
-
node: async (
|
|
290
|
-
return fs2.readFile(
|
|
299
|
+
node: async (path3) => {
|
|
300
|
+
return fs2.readFile(path3, { encoding: "utf8" });
|
|
291
301
|
},
|
|
292
|
-
bun: async (
|
|
293
|
-
const file = Bun.file(
|
|
302
|
+
bun: async (path3) => {
|
|
303
|
+
const file = Bun.file(path3);
|
|
294
304
|
return file.text();
|
|
295
305
|
}
|
|
296
306
|
},
|
|
@@ -298,8 +308,8 @@ var reader = switcher(
|
|
|
298
308
|
);
|
|
299
309
|
var syncReader = switcher(
|
|
300
310
|
{
|
|
301
|
-
node: (
|
|
302
|
-
return fs2.readFileSync(
|
|
311
|
+
node: (path3) => {
|
|
312
|
+
return fs2.readFileSync(path3, { encoding: "utf8" });
|
|
303
313
|
},
|
|
304
314
|
bun: () => {
|
|
305
315
|
throw new Error("Bun cannot read sync");
|
|
@@ -307,11 +317,11 @@ var syncReader = switcher(
|
|
|
307
317
|
},
|
|
308
318
|
"node"
|
|
309
319
|
);
|
|
310
|
-
async function read(
|
|
311
|
-
return reader(
|
|
320
|
+
async function read(path3) {
|
|
321
|
+
return reader(path3);
|
|
312
322
|
}
|
|
313
|
-
function readSync(
|
|
314
|
-
return syncReader(
|
|
323
|
+
function readSync(path3) {
|
|
324
|
+
return syncReader(path3);
|
|
315
325
|
}
|
|
316
326
|
|
|
317
327
|
// src/utils/renderTemplate.ts
|
|
@@ -377,9 +387,9 @@ var throttle = (fn, delay) => {
|
|
|
377
387
|
|
|
378
388
|
// src/utils/timeout.ts
|
|
379
389
|
async function timeout(ms) {
|
|
380
|
-
return new Promise((
|
|
390
|
+
return new Promise((resolve2) => {
|
|
381
391
|
setTimeout(() => {
|
|
382
|
-
|
|
392
|
+
resolve2(true);
|
|
383
393
|
}, ms);
|
|
384
394
|
});
|
|
385
395
|
}
|
|
@@ -414,6 +424,11 @@ function jsStringEscape(input) {
|
|
|
414
424
|
});
|
|
415
425
|
}
|
|
416
426
|
|
|
427
|
+
// src/utils/transformers/indent.ts
|
|
428
|
+
function createIndent(size) {
|
|
429
|
+
return Array.from({ length: size + 1 }).join(" ");
|
|
430
|
+
}
|
|
431
|
+
|
|
417
432
|
// src/utils/transformers/transformReservedWord.ts
|
|
418
433
|
var reservedWords = [
|
|
419
434
|
"abstract",
|
|
@@ -506,6 +521,15 @@ function transformReservedWord(word) {
|
|
|
506
521
|
}
|
|
507
522
|
return word;
|
|
508
523
|
}
|
|
524
|
+
|
|
525
|
+
// src/utils/transformers/index.ts
|
|
526
|
+
var transformers = {
|
|
527
|
+
combineCodes,
|
|
528
|
+
escape,
|
|
529
|
+
jsStringEscape,
|
|
530
|
+
createIndent,
|
|
531
|
+
transformReservedWord
|
|
532
|
+
};
|
|
509
533
|
var TreeNode = class _TreeNode {
|
|
510
534
|
data;
|
|
511
535
|
parent;
|
|
@@ -570,16 +594,16 @@ var TreeNode = class _TreeNode {
|
|
|
570
594
|
}
|
|
571
595
|
return this;
|
|
572
596
|
}
|
|
573
|
-
static build(
|
|
597
|
+
static build(path3, options = {}) {
|
|
574
598
|
try {
|
|
575
599
|
const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
|
|
576
|
-
const filteredTree = dirTree(
|
|
600
|
+
const filteredTree = dirTree(path3, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
|
|
577
601
|
if (!filteredTree) {
|
|
578
602
|
return null;
|
|
579
603
|
}
|
|
580
|
-
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type ||
|
|
604
|
+
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || FileManager.getMode(filteredTree.path) });
|
|
581
605
|
const recurse = (node, item) => {
|
|
582
|
-
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type ||
|
|
606
|
+
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || FileManager.getMode(item.path) });
|
|
583
607
|
if (item.children?.length) {
|
|
584
608
|
item.children?.forEach((child) => {
|
|
585
609
|
recurse(subNode, child);
|
|
@@ -596,10 +620,30 @@ var TreeNode = class _TreeNode {
|
|
|
596
620
|
|
|
597
621
|
// src/utils/uniqueIdFactory.ts
|
|
598
622
|
var uniqueIdFactory = (counter) => (str = "") => `${str}${++counter}`;
|
|
623
|
+
|
|
624
|
+
// src/utils/uniqueName.ts
|
|
625
|
+
function getUniqueName(originalName, data) {
|
|
626
|
+
let used = data[originalName] || 0;
|
|
627
|
+
if (used) {
|
|
628
|
+
data[originalName] = ++used;
|
|
629
|
+
originalName += used;
|
|
630
|
+
}
|
|
631
|
+
data[originalName] = 1;
|
|
632
|
+
return originalName;
|
|
633
|
+
}
|
|
634
|
+
function setUniqueName(originalName, data) {
|
|
635
|
+
let used = data[originalName] || 0;
|
|
636
|
+
if (used) {
|
|
637
|
+
data[originalName] = ++used;
|
|
638
|
+
return originalName;
|
|
639
|
+
}
|
|
640
|
+
data[originalName] = 1;
|
|
641
|
+
return originalName;
|
|
642
|
+
}
|
|
599
643
|
var URLPath = class {
|
|
600
644
|
path;
|
|
601
|
-
constructor(
|
|
602
|
-
this.path =
|
|
645
|
+
constructor(path3) {
|
|
646
|
+
this.path = path3;
|
|
603
647
|
return this;
|
|
604
648
|
}
|
|
605
649
|
/**
|
|
@@ -697,39 +741,67 @@ var Warning = class extends Error {
|
|
|
697
741
|
this.name = "Warning";
|
|
698
742
|
}
|
|
699
743
|
};
|
|
700
|
-
async function saveCreateDirectory(
|
|
701
|
-
const passedPath =
|
|
744
|
+
async function saveCreateDirectory(path3) {
|
|
745
|
+
const passedPath = dirname(resolve(path3));
|
|
702
746
|
await fs2.mkdir(passedPath, { recursive: true });
|
|
703
747
|
}
|
|
704
748
|
var writer = switcher(
|
|
705
749
|
{
|
|
706
|
-
node: async (
|
|
750
|
+
node: async (path3, data) => {
|
|
707
751
|
try {
|
|
708
|
-
await fs2.stat(
|
|
709
|
-
const oldContent = await fs2.readFile(
|
|
710
|
-
if (oldContent?.toString() === data) {
|
|
752
|
+
await fs2.stat(resolve(path3));
|
|
753
|
+
const oldContent = await fs2.readFile(resolve(path3), { encoding: "utf-8" });
|
|
754
|
+
if (oldContent?.toString() === data?.toString()) {
|
|
711
755
|
return;
|
|
712
756
|
}
|
|
713
757
|
} catch (_err) {
|
|
714
758
|
}
|
|
715
|
-
await saveCreateDirectory(
|
|
716
|
-
|
|
759
|
+
await saveCreateDirectory(path3);
|
|
760
|
+
await fs2.writeFile(resolve(path3), data, { encoding: "utf-8" });
|
|
761
|
+
const savedData = await fs2.readFile(resolve(path3), { encoding: "utf-8" });
|
|
762
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
763
|
+
throw new Error(`Sanity check failed for ${path3}
|
|
764
|
+
|
|
765
|
+
Data[${data.length}]:
|
|
766
|
+
${data}
|
|
767
|
+
|
|
768
|
+
Saved[${savedData.length}]:
|
|
769
|
+
${savedData}
|
|
770
|
+
`);
|
|
771
|
+
}
|
|
772
|
+
return savedData;
|
|
717
773
|
},
|
|
718
|
-
bun: async (
|
|
774
|
+
bun: async (path3, data) => {
|
|
719
775
|
try {
|
|
720
|
-
await saveCreateDirectory(
|
|
721
|
-
await Bun.write(
|
|
776
|
+
await saveCreateDirectory(path3);
|
|
777
|
+
await Bun.write(resolve(path3), data);
|
|
778
|
+
const file = Bun.file(resolve(path3));
|
|
779
|
+
const savedData = await file.text();
|
|
780
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
781
|
+
throw new Error(`Sanity check failed for ${path3}
|
|
782
|
+
|
|
783
|
+
Data[${data.length}]:
|
|
784
|
+
${data}
|
|
785
|
+
|
|
786
|
+
Saved[${savedData.length}]:
|
|
787
|
+
${savedData}
|
|
788
|
+
`);
|
|
789
|
+
}
|
|
790
|
+
return savedData;
|
|
722
791
|
} catch (e) {
|
|
723
|
-
console.log(e,
|
|
792
|
+
console.log(e, resolve(path3));
|
|
724
793
|
}
|
|
725
794
|
}
|
|
726
795
|
},
|
|
727
796
|
"node"
|
|
728
797
|
);
|
|
729
|
-
async function write(data,
|
|
730
|
-
|
|
798
|
+
async function write(data, path3) {
|
|
799
|
+
if (data.trim() === "") {
|
|
800
|
+
return void 0;
|
|
801
|
+
}
|
|
802
|
+
return writer(path3, data.trim());
|
|
731
803
|
}
|
|
732
|
-
function getIndexes(root, extName,
|
|
804
|
+
function getIndexes(root, extName, { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = {}) {
|
|
733
805
|
const extMapper = {
|
|
734
806
|
".ts": {
|
|
735
807
|
extensions: /\.ts/,
|
|
@@ -740,7 +812,7 @@ function getIndexes(root, extName, options = {}) {
|
|
|
740
812
|
exclude: []
|
|
741
813
|
}
|
|
742
814
|
};
|
|
743
|
-
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...
|
|
815
|
+
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
|
|
744
816
|
if (!tree) {
|
|
745
817
|
return null;
|
|
746
818
|
}
|
|
@@ -749,32 +821,42 @@ function getIndexes(root, extName, options = {}) {
|
|
|
749
821
|
return [];
|
|
750
822
|
}
|
|
751
823
|
if (currentTree.children?.length > 1) {
|
|
752
|
-
const
|
|
753
|
-
const exports = currentTree.children.map((file) => {
|
|
754
|
-
if (!file) {
|
|
755
|
-
return void 0;
|
|
756
|
-
}
|
|
824
|
+
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
825
|
+
const exports = currentTree.children.filter(Boolean).map((file) => {
|
|
757
826
|
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
758
|
-
if (importPath.includes("index") &&
|
|
827
|
+
if (importPath.includes("index") && indexPath.includes("index")) {
|
|
759
828
|
return void 0;
|
|
760
829
|
}
|
|
761
|
-
return {
|
|
830
|
+
return {
|
|
831
|
+
path: includeExt ? file.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
832
|
+
isTypeOnly
|
|
833
|
+
};
|
|
762
834
|
}).filter(Boolean);
|
|
763
835
|
files2.push({
|
|
764
|
-
path,
|
|
836
|
+
path: indexPath,
|
|
765
837
|
baseName: "index.ts",
|
|
766
838
|
source: "",
|
|
767
|
-
exports
|
|
839
|
+
exports: output ? exports?.filter((item) => {
|
|
840
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
841
|
+
}) : exports
|
|
768
842
|
});
|
|
769
843
|
} else {
|
|
770
844
|
currentTree.children?.forEach((child) => {
|
|
771
|
-
const
|
|
845
|
+
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
772
846
|
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
847
|
+
const exports = [
|
|
848
|
+
{
|
|
849
|
+
path: includeExt ? child.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
850
|
+
isTypeOnly
|
|
851
|
+
}
|
|
852
|
+
];
|
|
773
853
|
files2.push({
|
|
774
|
-
path,
|
|
854
|
+
path: indexPath,
|
|
775
855
|
baseName: "index.ts",
|
|
776
856
|
source: "",
|
|
777
|
-
exports:
|
|
857
|
+
exports: output ? exports?.filter((item) => {
|
|
858
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
859
|
+
}) : exports
|
|
778
860
|
});
|
|
779
861
|
});
|
|
780
862
|
}
|
|
@@ -783,8 +865,9 @@ function getIndexes(root, extName, options = {}) {
|
|
|
783
865
|
});
|
|
784
866
|
return files2;
|
|
785
867
|
};
|
|
786
|
-
const files = fileReducer([], tree);
|
|
787
|
-
|
|
868
|
+
const files = fileReducer([], tree).reverse();
|
|
869
|
+
const filteredFiles = filter ? files.filter(filter) : files;
|
|
870
|
+
return map ? filteredFiles.map(map) : filteredFiles;
|
|
788
871
|
}
|
|
789
872
|
function combineFiles(files) {
|
|
790
873
|
return files.filter(Boolean).reduce((acc, curr) => {
|
|
@@ -812,9 +895,13 @@ function isExtensionAllowed(baseName) {
|
|
|
812
895
|
return extensions.some((extension) => baseName.endsWith(extension));
|
|
813
896
|
}
|
|
814
897
|
function combineExports(exports) {
|
|
815
|
-
|
|
898
|
+
const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
816
899
|
const name = curr.name;
|
|
817
900
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
901
|
+
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly);
|
|
902
|
+
if (prevByPathAndIsTypeOnly) {
|
|
903
|
+
return prev;
|
|
904
|
+
}
|
|
818
905
|
const uniquePrev = prev.findLast(
|
|
819
906
|
(imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
820
907
|
);
|
|
@@ -836,12 +923,16 @@ function combineExports(exports) {
|
|
|
836
923
|
}
|
|
837
924
|
return [...prev, curr];
|
|
838
925
|
}, []);
|
|
926
|
+
return orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
839
927
|
}
|
|
840
928
|
function combineImports(imports, exports, source) {
|
|
841
|
-
|
|
929
|
+
const combinedImports = orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
842
930
|
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
843
931
|
const hasImportInSource = (importName) => {
|
|
844
|
-
|
|
932
|
+
if (!source) {
|
|
933
|
+
return true;
|
|
934
|
+
}
|
|
935
|
+
const checker = (name2) => name2 && !!source.includes(name2);
|
|
845
936
|
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
846
937
|
};
|
|
847
938
|
if (Array.isArray(name)) {
|
|
@@ -849,6 +940,10 @@ function combineImports(imports, exports, source) {
|
|
|
849
940
|
}
|
|
850
941
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
851
942
|
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
943
|
+
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly);
|
|
944
|
+
if (prevByPathNameAndIsTypeOnly) {
|
|
945
|
+
return prev;
|
|
946
|
+
}
|
|
852
947
|
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
853
948
|
return prev;
|
|
854
949
|
}
|
|
@@ -870,28 +965,17 @@ function combineImports(imports, exports, source) {
|
|
|
870
965
|
}
|
|
871
966
|
return [...prev, curr];
|
|
872
967
|
}, []);
|
|
968
|
+
return orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
873
969
|
}
|
|
874
970
|
function createFileSource(file) {
|
|
875
|
-
let { source } = file;
|
|
876
971
|
if (!isExtensionAllowed(file.baseName)) {
|
|
877
972
|
return file.source;
|
|
878
973
|
}
|
|
879
974
|
const exports = file.exports ? combineExports(file.exports) : [];
|
|
880
|
-
const imports = file.imports ? combineImports(file.imports, exports, source) : [];
|
|
975
|
+
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
881
976
|
const importNodes = imports.map((item) => createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
882
|
-
const importSource = print(importNodes);
|
|
883
977
|
const exportNodes = exports.map((item) => createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias }));
|
|
884
|
-
|
|
885
|
-
source = getEnvSource(file.source, file.env);
|
|
886
|
-
if (importSource) {
|
|
887
|
-
source = `${importSource}
|
|
888
|
-
${source}`;
|
|
889
|
-
}
|
|
890
|
-
if (exportSource) {
|
|
891
|
-
source = `${exportSource}
|
|
892
|
-
${source}`;
|
|
893
|
-
}
|
|
894
|
-
return source;
|
|
978
|
+
return [print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
895
979
|
}
|
|
896
980
|
function searchAndReplace(options) {
|
|
897
981
|
const { text, replaceBy, prefix = "", key } = options;
|
|
@@ -935,11 +1019,17 @@ function getEnvSource(source, env) {
|
|
|
935
1019
|
var FileManager = class {
|
|
936
1020
|
#cache = /* @__PURE__ */ new Map();
|
|
937
1021
|
#task;
|
|
1022
|
+
#isWriting = false;
|
|
1023
|
+
/**
|
|
1024
|
+
* Timeout between writes
|
|
1025
|
+
*/
|
|
1026
|
+
#timeout = 0;
|
|
938
1027
|
#queue;
|
|
939
1028
|
constructor(options) {
|
|
940
1029
|
if (options) {
|
|
941
1030
|
this.#task = options.task;
|
|
942
1031
|
this.#queue = options.queue;
|
|
1032
|
+
this.#timeout = options.timeout || 0;
|
|
943
1033
|
}
|
|
944
1034
|
return this;
|
|
945
1035
|
}
|
|
@@ -954,23 +1044,19 @@ var FileManager = class {
|
|
|
954
1044
|
return files;
|
|
955
1045
|
}
|
|
956
1046
|
get isExecuting() {
|
|
957
|
-
return this.#queue?.hasJobs ?? false;
|
|
1047
|
+
return this.#queue?.hasJobs ?? this.#isWriting ?? false;
|
|
958
1048
|
}
|
|
959
1049
|
async add(file) {
|
|
960
1050
|
const controller = new AbortController();
|
|
961
1051
|
const resolvedFile = { id: crypto.randomUUID(), ...file };
|
|
962
1052
|
this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
963
1053
|
if (this.#queue) {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
);
|
|
971
|
-
} catch {
|
|
972
|
-
return resolvedFile;
|
|
973
|
-
}
|
|
1054
|
+
await this.#queue.run(
|
|
1055
|
+
async () => {
|
|
1056
|
+
return this.#task?.(resolvedFile);
|
|
1057
|
+
},
|
|
1058
|
+
{ controller }
|
|
1059
|
+
);
|
|
974
1060
|
}
|
|
975
1061
|
return resolvedFile;
|
|
976
1062
|
}
|
|
@@ -990,24 +1076,20 @@ ${file.source}` : "",
|
|
|
990
1076
|
}
|
|
991
1077
|
return this.add(file);
|
|
992
1078
|
}
|
|
993
|
-
async addIndexes(root, extName = ".ts", options = {}) {
|
|
994
|
-
const files =
|
|
1079
|
+
async addIndexes({ root, extName = ".ts", meta, options = {} }) {
|
|
1080
|
+
const files = getIndexes(root, extName, options);
|
|
995
1081
|
if (!files) {
|
|
996
1082
|
return void 0;
|
|
997
1083
|
}
|
|
998
|
-
return Promise.all(
|
|
1084
|
+
return await Promise.all(
|
|
999
1085
|
files.map((file) => {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1086
|
+
return this.addOrAppend({
|
|
1087
|
+
...file,
|
|
1088
|
+
meta: meta ? meta : file.meta
|
|
1089
|
+
});
|
|
1004
1090
|
})
|
|
1005
1091
|
);
|
|
1006
1092
|
}
|
|
1007
|
-
#append(path, file) {
|
|
1008
|
-
const previousFiles = this.#cache.get(path) || [];
|
|
1009
|
-
this.#cache.set(path, [...previousFiles, file]);
|
|
1010
|
-
}
|
|
1011
1093
|
getCacheByUUID(UUID) {
|
|
1012
1094
|
let cache;
|
|
1013
1095
|
this.#cache.forEach((files) => {
|
|
@@ -1015,32 +1097,63 @@ ${file.source}` : "",
|
|
|
1015
1097
|
});
|
|
1016
1098
|
return cache;
|
|
1017
1099
|
}
|
|
1018
|
-
get(
|
|
1019
|
-
return this.#cache.get(
|
|
1100
|
+
get(path3) {
|
|
1101
|
+
return this.#cache.get(path3);
|
|
1020
1102
|
}
|
|
1021
|
-
remove(
|
|
1022
|
-
const cacheItem = this.get(
|
|
1103
|
+
remove(path3) {
|
|
1104
|
+
const cacheItem = this.get(path3);
|
|
1023
1105
|
if (!cacheItem) {
|
|
1024
1106
|
return;
|
|
1025
1107
|
}
|
|
1026
|
-
this.#cache.delete(
|
|
1108
|
+
this.#cache.delete(path3);
|
|
1027
1109
|
}
|
|
1028
1110
|
async write(...params) {
|
|
1029
|
-
if (this.#
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1111
|
+
if (!this.#isWriting) {
|
|
1112
|
+
this.#isWriting = true;
|
|
1113
|
+
const text = await write(...params);
|
|
1114
|
+
this.#isWriting = false;
|
|
1115
|
+
return text;
|
|
1033
1116
|
}
|
|
1034
|
-
|
|
1117
|
+
await timeout(this.#timeout);
|
|
1118
|
+
return this.write(...params);
|
|
1035
1119
|
}
|
|
1036
1120
|
async read(...params) {
|
|
1037
|
-
if (this.#queue) {
|
|
1038
|
-
return this.#queue.run(async () => {
|
|
1039
|
-
return read(...params);
|
|
1040
|
-
});
|
|
1041
|
-
}
|
|
1042
1121
|
return read(...params);
|
|
1043
1122
|
}
|
|
1123
|
+
// statics
|
|
1124
|
+
static getSource(file) {
|
|
1125
|
+
return createFileSource(file);
|
|
1126
|
+
}
|
|
1127
|
+
static combineFiles(files) {
|
|
1128
|
+
return combineFiles(files);
|
|
1129
|
+
}
|
|
1130
|
+
static getMode(path3) {
|
|
1131
|
+
if (!path3) {
|
|
1132
|
+
return "directory";
|
|
1133
|
+
}
|
|
1134
|
+
return extname(path3) ? "file" : "directory";
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
// src/managers/pluginManager/executeStrategies.ts
|
|
1139
|
+
function hookSeq(promises) {
|
|
1140
|
+
return promises.reduce(
|
|
1141
|
+
(promise, func) => {
|
|
1142
|
+
if (!func || typeof func !== "function") {
|
|
1143
|
+
throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
1144
|
+
}
|
|
1145
|
+
return promise.then((result) => {
|
|
1146
|
+
const calledFunc = func();
|
|
1147
|
+
if (calledFunc) {
|
|
1148
|
+
return calledFunc.then(Array.prototype.concat.bind(result));
|
|
1149
|
+
}
|
|
1150
|
+
});
|
|
1151
|
+
},
|
|
1152
|
+
Promise.resolve([])
|
|
1153
|
+
);
|
|
1154
|
+
}
|
|
1155
|
+
var executeStrategies = {
|
|
1156
|
+
hookSeq
|
|
1044
1157
|
};
|
|
1045
1158
|
|
|
1046
1159
|
// src/managers/pluginManager/ParallelPluginError.ts
|
|
@@ -1082,16 +1195,7 @@ var PluginError = class extends Error {
|
|
|
1082
1195
|
};
|
|
1083
1196
|
function createPlugin(factory) {
|
|
1084
1197
|
return (options) => {
|
|
1085
|
-
|
|
1086
|
-
if (Array.isArray(plugin)) {
|
|
1087
|
-
throw new Error("Not implemented");
|
|
1088
|
-
}
|
|
1089
|
-
if (!plugin.transform) {
|
|
1090
|
-
plugin.transform = function transform(code) {
|
|
1091
|
-
return code;
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
return plugin;
|
|
1198
|
+
return factory(options);
|
|
1095
1199
|
};
|
|
1096
1200
|
}
|
|
1097
1201
|
var pluginName = "core";
|
|
@@ -1100,6 +1204,8 @@ var definePlugin = createPlugin((options) => {
|
|
|
1100
1204
|
return {
|
|
1101
1205
|
name: pluginName,
|
|
1102
1206
|
options,
|
|
1207
|
+
key: ["controller", "core"],
|
|
1208
|
+
kind: "controller",
|
|
1103
1209
|
api() {
|
|
1104
1210
|
return {
|
|
1105
1211
|
get config() {
|
|
@@ -1108,6 +1214,9 @@ var definePlugin = createPlugin((options) => {
|
|
|
1108
1214
|
get plugins() {
|
|
1109
1215
|
return options.getPlugins();
|
|
1110
1216
|
},
|
|
1217
|
+
get plugin() {
|
|
1218
|
+
return options.plugin;
|
|
1219
|
+
},
|
|
1111
1220
|
logger,
|
|
1112
1221
|
fileManager,
|
|
1113
1222
|
pluginManager,
|
|
@@ -1127,37 +1236,35 @@ var definePlugin = createPlugin((options) => {
|
|
|
1127
1236
|
};
|
|
1128
1237
|
},
|
|
1129
1238
|
resolvePath(baseName) {
|
|
1130
|
-
const root =
|
|
1131
|
-
return
|
|
1239
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
1240
|
+
return path.resolve(root, baseName);
|
|
1132
1241
|
},
|
|
1133
1242
|
resolveName(name) {
|
|
1134
1243
|
return name;
|
|
1135
1244
|
}
|
|
1136
1245
|
};
|
|
1137
1246
|
});
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
this.#emitter.emit(eventName, ...eventArg);
|
|
1145
|
-
}
|
|
1146
|
-
on(eventName, handler) {
|
|
1147
|
-
this.#emitter.on(eventName, handler);
|
|
1148
|
-
}
|
|
1149
|
-
off(eventName, handler) {
|
|
1150
|
-
this.#emitter.off(eventName, handler);
|
|
1151
|
-
}
|
|
1152
|
-
removeAll() {
|
|
1153
|
-
this.#emitter.removeAllListeners();
|
|
1154
|
-
}
|
|
1247
|
+
|
|
1248
|
+
// src/types.ts
|
|
1249
|
+
var LogLevel = {
|
|
1250
|
+
silent: "silent",
|
|
1251
|
+
info: "info",
|
|
1252
|
+
debug: "debug"
|
|
1155
1253
|
};
|
|
1156
1254
|
|
|
1157
1255
|
// src/managers/pluginManager/pluginParser.ts
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1256
|
+
function pluginParser(plugin, pluginManager, context) {
|
|
1257
|
+
const usedPluginNames = pluginManager.usedPluginNames;
|
|
1258
|
+
setUniqueName(plugin.name, usedPluginNames);
|
|
1259
|
+
const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
1260
|
+
if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
|
|
1261
|
+
pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
|
|
1262
|
+
}
|
|
1263
|
+
if (!plugin.transform) {
|
|
1264
|
+
plugin.transform = function transform(code) {
|
|
1265
|
+
return code;
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1161
1268
|
if (plugin.api && typeof plugin.api === "function") {
|
|
1162
1269
|
const api = plugin.api.call(context);
|
|
1163
1270
|
return {
|
|
@@ -1192,10 +1299,12 @@ var PluginManager = class {
|
|
|
1192
1299
|
executed = [];
|
|
1193
1300
|
logger;
|
|
1194
1301
|
#core;
|
|
1302
|
+
usedPluginNames = {};
|
|
1195
1303
|
constructor(config, options) {
|
|
1196
1304
|
this.logger = options.logger;
|
|
1197
|
-
this.queue = new Queue(100,
|
|
1198
|
-
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
1305
|
+
this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
|
|
1306
|
+
this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
|
|
1307
|
+
const plugins = config.plugins || [];
|
|
1199
1308
|
const core = definePlugin({
|
|
1200
1309
|
config,
|
|
1201
1310
|
logger: this.logger,
|
|
@@ -1203,23 +1312,29 @@ var PluginManager = class {
|
|
|
1203
1312
|
fileManager: this.fileManager,
|
|
1204
1313
|
resolvePath: this.resolvePath.bind(this),
|
|
1205
1314
|
resolveName: this.resolveName.bind(this),
|
|
1206
|
-
getPlugins: this.#getSortedPlugins.bind(this)
|
|
1207
|
-
|
|
1315
|
+
getPlugins: this.#getSortedPlugins.bind(this)
|
|
1316
|
+
});
|
|
1317
|
+
this.#core = pluginParser(core, this, core.api.call(null));
|
|
1318
|
+
this.plugins = [this.#core, ...plugins].map((plugin) => {
|
|
1319
|
+
return pluginParser(plugin, this, this.#core.api);
|
|
1208
1320
|
});
|
|
1209
|
-
this.#core = pluginParser(core, core.api.call(null));
|
|
1210
|
-
this.plugins = [this.#core, ...config.plugins || []].reduce((prev, plugin) => {
|
|
1211
|
-
const convertedApi = pluginParser(plugin, this.#core?.api);
|
|
1212
|
-
return [...prev, convertedApi];
|
|
1213
|
-
}, []);
|
|
1214
1321
|
return this;
|
|
1215
1322
|
}
|
|
1216
1323
|
resolvePath = (params) => {
|
|
1217
|
-
if (params.
|
|
1218
|
-
|
|
1219
|
-
|
|
1324
|
+
if (params.pluginKey) {
|
|
1325
|
+
const paths = this.hookForPluginSync({
|
|
1326
|
+
pluginKey: params.pluginKey,
|
|
1220
1327
|
hookName: "resolvePath",
|
|
1221
1328
|
parameters: [params.baseName, params.directory, params.options]
|
|
1222
1329
|
});
|
|
1330
|
+
if (paths && paths?.length > 1) {
|
|
1331
|
+
throw new Error(
|
|
1332
|
+
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1333
|
+
|
|
1334
|
+
Paths: ${JSON.stringify(paths, void 0, 2)}`
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
return paths?.at(0);
|
|
1223
1338
|
}
|
|
1224
1339
|
return this.hookFirstSync({
|
|
1225
1340
|
hookName: "resolvePath",
|
|
@@ -1227,13 +1342,20 @@ var PluginManager = class {
|
|
|
1227
1342
|
}).result;
|
|
1228
1343
|
};
|
|
1229
1344
|
resolveName = (params) => {
|
|
1230
|
-
if (params.
|
|
1231
|
-
const
|
|
1232
|
-
|
|
1345
|
+
if (params.pluginKey) {
|
|
1346
|
+
const names = this.hookForPluginSync({
|
|
1347
|
+
pluginKey: params.pluginKey,
|
|
1233
1348
|
hookName: "resolveName",
|
|
1234
1349
|
parameters: [params.name, params.type]
|
|
1235
1350
|
});
|
|
1236
|
-
|
|
1351
|
+
if (names && names?.length > 1) {
|
|
1352
|
+
throw new Error(
|
|
1353
|
+
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1354
|
+
|
|
1355
|
+
Names: ${JSON.stringify(names, void 0, 2)}`
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1358
|
+
return transformReservedWord(names?.at(0) || params.name);
|
|
1237
1359
|
}
|
|
1238
1360
|
const name = this.hookFirstSync({
|
|
1239
1361
|
hookName: "resolveName",
|
|
@@ -1248,30 +1370,35 @@ var PluginManager = class {
|
|
|
1248
1370
|
* Run only hook for a specific plugin name
|
|
1249
1371
|
*/
|
|
1250
1372
|
hookForPlugin({
|
|
1251
|
-
|
|
1373
|
+
pluginKey,
|
|
1252
1374
|
hookName,
|
|
1253
1375
|
parameters
|
|
1254
1376
|
}) {
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1377
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1378
|
+
const promises = plugins.map((plugin) => {
|
|
1379
|
+
return this.#execute({
|
|
1380
|
+
strategy: "hookFirst",
|
|
1381
|
+
hookName,
|
|
1382
|
+
parameters,
|
|
1383
|
+
plugin
|
|
1384
|
+
});
|
|
1385
|
+
}).filter(Boolean);
|
|
1386
|
+
return Promise.all(promises);
|
|
1262
1387
|
}
|
|
1263
1388
|
hookForPluginSync({
|
|
1264
|
-
|
|
1389
|
+
pluginKey,
|
|
1265
1390
|
hookName,
|
|
1266
1391
|
parameters
|
|
1267
1392
|
}) {
|
|
1268
|
-
const
|
|
1269
|
-
return
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1393
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1394
|
+
return plugins.map((plugin) => {
|
|
1395
|
+
return this.#executeSync({
|
|
1396
|
+
strategy: "hookFirst",
|
|
1397
|
+
hookName,
|
|
1398
|
+
parameters,
|
|
1399
|
+
plugin
|
|
1400
|
+
});
|
|
1401
|
+
}).filter(Boolean);
|
|
1275
1402
|
}
|
|
1276
1403
|
/**
|
|
1277
1404
|
* Chains, first non-null result stops and returns
|
|
@@ -1387,37 +1514,58 @@ var PluginManager = class {
|
|
|
1387
1514
|
* Chains plugins
|
|
1388
1515
|
*/
|
|
1389
1516
|
hookSeq({ hookName, parameters }) {
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
parameters,
|
|
1397
|
-
plugin
|
|
1398
|
-
});
|
|
1517
|
+
const promises = this.#getSortedPlugins().map((plugin) => {
|
|
1518
|
+
return () => this.#execute({
|
|
1519
|
+
strategy: "hookSeq",
|
|
1520
|
+
hookName,
|
|
1521
|
+
parameters,
|
|
1522
|
+
plugin
|
|
1399
1523
|
});
|
|
1400
|
-
}
|
|
1401
|
-
return
|
|
1524
|
+
});
|
|
1525
|
+
return executeStrategies.hookSeq(promises);
|
|
1402
1526
|
}
|
|
1403
1527
|
#getSortedPlugins(hookName) {
|
|
1404
1528
|
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1405
1529
|
if (hookName) {
|
|
1530
|
+
if (this.logger.logLevel === "info") {
|
|
1531
|
+
const containsHookName = plugins.some((item) => item[hookName]);
|
|
1532
|
+
if (!containsHookName) {
|
|
1533
|
+
this.logger.warn(`No hook ${hookName} found`);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1406
1536
|
return plugins.filter((item) => item[hookName]);
|
|
1407
1537
|
}
|
|
1408
1538
|
return plugins;
|
|
1409
1539
|
}
|
|
1410
|
-
|
|
1540
|
+
getPluginsByKey(hookName, pluginKey) {
|
|
1411
1541
|
const plugins = [...this.plugins];
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
|
|
1542
|
+
const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
|
|
1543
|
+
const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
|
|
1544
|
+
const [kind, name, identifier] = item.key;
|
|
1545
|
+
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1546
|
+
const kindCheck = kind === searchKind;
|
|
1547
|
+
const nameCheck = name === searchPluginName;
|
|
1548
|
+
if (searchIdentifier) {
|
|
1549
|
+
return identifierCheck && kindCheck && nameCheck;
|
|
1550
|
+
}
|
|
1551
|
+
return kindCheck && nameCheck;
|
|
1552
|
+
});
|
|
1553
|
+
if (!pluginByPluginName?.length) {
|
|
1554
|
+
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
1555
|
+
if (this.logger.logLevel === "info") {
|
|
1556
|
+
if (corePlugin) {
|
|
1557
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
|
|
1558
|
+
} else {
|
|
1559
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
return corePlugin ? [corePlugin] : [];
|
|
1415
1563
|
}
|
|
1416
1564
|
return pluginByPluginName;
|
|
1417
1565
|
}
|
|
1418
1566
|
#addExecutedToCallStack(executer) {
|
|
1419
1567
|
if (executer) {
|
|
1420
|
-
this.eventEmitter.emit("
|
|
1568
|
+
this.eventEmitter.emit("executed", executer);
|
|
1421
1569
|
this.executed.push(executer);
|
|
1422
1570
|
}
|
|
1423
1571
|
}
|
|
@@ -1487,7 +1635,7 @@ var PluginManager = class {
|
|
|
1487
1635
|
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1488
1636
|
try {
|
|
1489
1637
|
if (typeof hook === "function") {
|
|
1490
|
-
const fn = hook.apply(this.#core.api, parameters);
|
|
1638
|
+
const fn = hook.apply({ ...this.#core.api, plugin }, parameters);
|
|
1491
1639
|
output = fn;
|
|
1492
1640
|
return fn;
|
|
1493
1641
|
}
|
|
@@ -1514,8 +1662,6 @@ var PluginManager = class {
|
|
|
1514
1662
|
throw pluginError;
|
|
1515
1663
|
}
|
|
1516
1664
|
};
|
|
1517
|
-
function noReturn() {
|
|
1518
|
-
}
|
|
1519
1665
|
|
|
1520
1666
|
// src/managers/pluginManager/validate.ts
|
|
1521
1667
|
var ValidationPluginError = class extends Error {
|
|
@@ -1536,25 +1682,26 @@ function getDependedPlugins(plugins, dependedPluginNames) {
|
|
|
1536
1682
|
});
|
|
1537
1683
|
}
|
|
1538
1684
|
|
|
1539
|
-
// src/
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1685
|
+
// src/config.ts
|
|
1686
|
+
function defineConfig(options) {
|
|
1687
|
+
return options;
|
|
1688
|
+
}
|
|
1689
|
+
function isInputPath(result) {
|
|
1690
|
+
return !!result && "path" in result;
|
|
1691
|
+
}
|
|
1545
1692
|
|
|
1546
1693
|
// src/build.ts
|
|
1547
1694
|
async function transformReducer(_previousCode, result, _plugin) {
|
|
1548
1695
|
return result;
|
|
1549
1696
|
}
|
|
1550
1697
|
async function build(options) {
|
|
1551
|
-
const { config,
|
|
1698
|
+
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1552
1699
|
try {
|
|
1553
|
-
if (
|
|
1700
|
+
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
1554
1701
|
await read(config.input.path);
|
|
1555
1702
|
}
|
|
1556
1703
|
} catch (e) {
|
|
1557
|
-
if (
|
|
1704
|
+
if (isInputPath(config)) {
|
|
1558
1705
|
throw new Error(
|
|
1559
1706
|
"Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config " + pc3.dim(config.input.path),
|
|
1560
1707
|
{
|
|
@@ -1567,11 +1714,11 @@ async function build(options) {
|
|
|
1567
1714
|
await clean(config.output.path);
|
|
1568
1715
|
}
|
|
1569
1716
|
const queueTask = async (file) => {
|
|
1570
|
-
const { path } = file;
|
|
1571
|
-
let code =
|
|
1717
|
+
const { path: path3 } = file;
|
|
1718
|
+
let code = FileManager.getSource(file);
|
|
1572
1719
|
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1573
1720
|
hookName: "load",
|
|
1574
|
-
parameters: [
|
|
1721
|
+
parameters: [path3]
|
|
1575
1722
|
});
|
|
1576
1723
|
if (loadedResult && isPromise(loadedResult)) {
|
|
1577
1724
|
code = await loadedResult;
|
|
@@ -1582,28 +1729,53 @@ async function build(options) {
|
|
|
1582
1729
|
if (code) {
|
|
1583
1730
|
const transformedCode = await pluginManager.hookReduceArg0({
|
|
1584
1731
|
hookName: "transform",
|
|
1585
|
-
parameters: [code,
|
|
1732
|
+
parameters: [code, path3],
|
|
1586
1733
|
reduce: transformReducer
|
|
1587
1734
|
});
|
|
1588
1735
|
if (config.output.write || config.output.write === void 0) {
|
|
1589
|
-
|
|
1736
|
+
if (file.meta?.pluginKey) {
|
|
1737
|
+
return pluginManager.hookForPlugin({
|
|
1738
|
+
pluginKey: file.meta?.pluginKey,
|
|
1739
|
+
hookName: "writeFile",
|
|
1740
|
+
parameters: [transformedCode, path3]
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
return pluginManager.hookFirst({
|
|
1590
1744
|
hookName: "writeFile",
|
|
1591
|
-
parameters: [transformedCode,
|
|
1745
|
+
parameters: [transformedCode, path3]
|
|
1592
1746
|
});
|
|
1593
1747
|
}
|
|
1594
1748
|
}
|
|
1595
1749
|
};
|
|
1596
|
-
const pluginManager = new PluginManager(config, {
|
|
1750
|
+
const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
|
|
1597
1751
|
const { plugins, fileManager } = pluginManager;
|
|
1598
1752
|
pluginManager.on("execute", (executer) => {
|
|
1753
|
+
const { hookName, parameters, plugin } = executer;
|
|
1754
|
+
if (hookName === "writeFile" && logger.spinner) {
|
|
1755
|
+
const [code] = parameters;
|
|
1756
|
+
if (logger.logLevel === LogLevel.info) {
|
|
1757
|
+
logger.spinner.start(`\u{1F4BE} Writing`);
|
|
1758
|
+
}
|
|
1759
|
+
if (logger.logLevel === "debug") {
|
|
1760
|
+
logger.info(`PluginKey ${pc3.dim(JSON.stringify(plugin.key))}
|
|
1761
|
+
with source
|
|
1762
|
+
|
|
1763
|
+
${code}`);
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
});
|
|
1767
|
+
pluginManager.on("executed", (executer) => {
|
|
1599
1768
|
const { hookName, plugin, output, parameters } = executer;
|
|
1600
1769
|
const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
|
|
1601
|
-
if (logLevel === LogLevel.info) {
|
|
1602
|
-
if (
|
|
1770
|
+
if (logger.logLevel === LogLevel.info && logger.spinner) {
|
|
1771
|
+
if (hookName === "writeFile") {
|
|
1772
|
+
const [_code, path3] = parameters;
|
|
1773
|
+
logger.spinner.suffixText = pc3.dim(path3);
|
|
1774
|
+
} else {
|
|
1603
1775
|
logger.spinner.suffixText = messsage;
|
|
1604
1776
|
}
|
|
1605
1777
|
}
|
|
1606
|
-
if (logLevel === LogLevel.debug) {
|
|
1778
|
+
if (logger.logLevel === LogLevel.debug) {
|
|
1607
1779
|
logger.info(messsage);
|
|
1608
1780
|
const logs = [
|
|
1609
1781
|
parameters && `${pc3.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
@@ -1623,12 +1795,11 @@ async function build(options) {
|
|
|
1623
1795
|
parameters: [config]
|
|
1624
1796
|
});
|
|
1625
1797
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
return options;
|
|
1798
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1799
|
+
logger.spinner.suffixText = "";
|
|
1800
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1801
|
+
}
|
|
1802
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1632
1803
|
}
|
|
1633
1804
|
|
|
1634
1805
|
// src/generators/Generator.ts
|
|
@@ -1679,17 +1850,17 @@ var PackageManager = class {
|
|
|
1679
1850
|
}
|
|
1680
1851
|
return directory;
|
|
1681
1852
|
}
|
|
1682
|
-
getLocation(
|
|
1683
|
-
let location =
|
|
1853
|
+
getLocation(path3) {
|
|
1854
|
+
let location = path3;
|
|
1684
1855
|
if (this.#cwd) {
|
|
1685
1856
|
const require2 = mod.createRequire(this.normalizeDirectory(this.#cwd));
|
|
1686
|
-
location = require2.resolve(
|
|
1857
|
+
location = require2.resolve(path3);
|
|
1687
1858
|
}
|
|
1688
1859
|
return location;
|
|
1689
1860
|
}
|
|
1690
|
-
async import(
|
|
1861
|
+
async import(path3) {
|
|
1691
1862
|
try {
|
|
1692
|
-
let location = this.getLocation(
|
|
1863
|
+
let location = this.getLocation(path3);
|
|
1693
1864
|
if (os.platform() == "win32") {
|
|
1694
1865
|
location = pathToFileURL(location).href;
|
|
1695
1866
|
}
|
|
@@ -1759,6 +1930,6 @@ var PackageManager = class {
|
|
|
1759
1930
|
// src/index.ts
|
|
1760
1931
|
var src_default = build;
|
|
1761
1932
|
|
|
1762
|
-
export { FileManager, FunctionParams, Generator, LogLevel, PackageManager, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, SummaryError, TreeNode, URLPath, ValidationPluginError, Warning, build, clean,
|
|
1933
|
+
export { FileManager, FunctionParams, Generator, LogLevel, PackageManager, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, SummaryError, TreeNode, URLPath, ValidationPluginError, Warning, build, clean, createJSDocBlockText, createLogger, createPlugin, createPluginCache, src_default as default, defineConfig, executeStrategies, getDependedPlugins, getRelativePath, getUniqueName, hooks, isInputPath, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, pluginName as name, nameSorter, pluginName, randomColour, randomPicoColour, read, readSync, renderTemplate, setUniqueName, throttle, timeout, transformers, uniqueIdFactory, write };
|
|
1763
1934
|
//# sourceMappingURL=out.js.map
|
|
1764
1935
|
//# sourceMappingURL=index.js.map
|