@kubb/core 2.0.0-alpha.9 → 2.0.0-beta.10
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/README.md +1 -1
- package/dist/index.cjs +302 -248
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -69
- package/dist/index.d.ts +72 -69
- package/dist/index.js +299 -244
- package/dist/index.js.map +1 -1
- package/dist/transformers.cjs +222 -0
- package/dist/transformers.cjs.map +1 -0
- package/dist/transformers.d.cts +55 -0
- package/dist/transformers.d.ts +55 -0
- package/dist/transformers.js +207 -0
- package/dist/transformers.js.map +1 -0
- package/dist/utils.cjs +302 -274
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +515 -67
- package/dist/utils.d.ts +515 -67
- package/dist/utils.js +303 -274
- package/dist/utils.js.map +1 -1
- package/package.json +19 -15
- package/src/BarrelManager.ts +55 -65
- package/src/FileManager.ts +100 -31
- package/src/PluginManager.ts +41 -39
- package/src/PromiseManager.ts +5 -1
- package/src/build.ts +1 -11
- package/src/index.ts +0 -1
- package/src/plugin.ts +4 -4
- package/src/transformers/casing.ts +9 -0
- package/src/transformers/createJSDocBlockText.ts +9 -0
- package/src/transformers/index.ts +36 -0
- package/src/transformers/trim.ts +7 -0
- package/src/types.ts +22 -39
- package/src/utils/FunctionParams.ts +3 -2
- package/src/utils/TreeNode.ts +6 -3
- package/src/utils/URLPath.ts +5 -5
- package/src/utils/executeStrategies.ts +14 -2
- package/src/utils/index.ts +0 -1
- package/src/SchemaGenerator.ts +0 -8
- package/src/utils/transformers/createJSDocBlockText.ts +0 -15
- package/src/utils/transformers/index.ts +0 -22
- package/src/utils/transformers/trim.ts +0 -3
- /package/src/{utils/transformers → transformers}/combineCodes.ts +0 -0
- /package/src/{utils/transformers → transformers}/escape.ts +0 -0
- /package/src/{utils/transformers → transformers}/indent.ts +0 -0
- /package/src/{utils/transformers → transformers}/nameSorter.ts +0 -0
- /package/src/{utils/transformers → transformers}/searchAndReplace.ts +0 -0
- /package/src/{utils/transformers → transformers}/transformReservedWord.ts +0 -0
package/dist/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import fs2, { remove } from 'fs-extra';
|
|
3
|
-
import { camelCase, camelCaseTransformMerge } from 'change-case';
|
|
4
3
|
import { orderBy } from 'natural-orderby';
|
|
4
|
+
import { camelCase as camelCase$1, camelCaseTransformMerge, pascalCase as pascalCase$1, pascalCaseTransformMerge } from 'change-case';
|
|
5
5
|
import pc2 from 'picocolors';
|
|
6
6
|
export { default as pc } from 'picocolors';
|
|
7
7
|
import crypto from 'crypto';
|
|
@@ -78,6 +78,207 @@ function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
|
78
78
|
async function clean(path2) {
|
|
79
79
|
return remove(path2);
|
|
80
80
|
}
|
|
81
|
+
function camelCase(text) {
|
|
82
|
+
return camelCase$1(text, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: camelCaseTransformMerge });
|
|
83
|
+
}
|
|
84
|
+
function pascalCase(text) {
|
|
85
|
+
return pascalCase$1(text, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/transformers/combineCodes.ts
|
|
89
|
+
function combineCodes(codes) {
|
|
90
|
+
return codes.join("\n");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/transformers/createJSDocBlockText.ts
|
|
94
|
+
function createJSDocBlockText({ comments }) {
|
|
95
|
+
const filteredComments = comments.filter(Boolean);
|
|
96
|
+
if (!filteredComments.length) {
|
|
97
|
+
return "";
|
|
98
|
+
}
|
|
99
|
+
return `/**
|
|
100
|
+
* ${filteredComments.join("\n * ")}
|
|
101
|
+
*/`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/transformers/escape.ts
|
|
105
|
+
function escape(text) {
|
|
106
|
+
return text ? text.replaceAll("`", "\\`") : "";
|
|
107
|
+
}
|
|
108
|
+
function jsStringEscape(input) {
|
|
109
|
+
return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
|
|
110
|
+
switch (character) {
|
|
111
|
+
case '"':
|
|
112
|
+
case "'":
|
|
113
|
+
case "\\":
|
|
114
|
+
return "\\" + character;
|
|
115
|
+
case "\n":
|
|
116
|
+
return "\\n";
|
|
117
|
+
case "\r":
|
|
118
|
+
return "\\r";
|
|
119
|
+
case "\u2028":
|
|
120
|
+
return "\\u2028";
|
|
121
|
+
case "\u2029":
|
|
122
|
+
return "\\u2029";
|
|
123
|
+
default:
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/transformers/indent.ts
|
|
130
|
+
function createIndent(size) {
|
|
131
|
+
return Array.from({ length: size + 1 }).join(" ");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/transformers/nameSorter.ts
|
|
135
|
+
function nameSorter(a, b) {
|
|
136
|
+
if (a.name < b.name) {
|
|
137
|
+
return -1;
|
|
138
|
+
}
|
|
139
|
+
if (a.name > b.name) {
|
|
140
|
+
return 1;
|
|
141
|
+
}
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/transformers/searchAndReplace.ts
|
|
146
|
+
function searchAndReplace(options) {
|
|
147
|
+
const { text, replaceBy, prefix = "", key } = options;
|
|
148
|
+
const searchValues = options.searchValues?.(prefix, key) || [
|
|
149
|
+
`${prefix}["${key}"]`,
|
|
150
|
+
`${prefix}['${key}']`,
|
|
151
|
+
`${prefix}[\`${key}\`]`,
|
|
152
|
+
`${prefix}"${key}"`,
|
|
153
|
+
`${prefix}'${key}'`,
|
|
154
|
+
`${prefix}\`${key}\``,
|
|
155
|
+
new RegExp(`${prefix}${key}`, "g")
|
|
156
|
+
];
|
|
157
|
+
return searchValues.reduce((prev, searchValue) => {
|
|
158
|
+
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
159
|
+
}, text);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/transformers/transformReservedWord.ts
|
|
163
|
+
var reservedWords = [
|
|
164
|
+
"abstract",
|
|
165
|
+
"arguments",
|
|
166
|
+
"boolean",
|
|
167
|
+
"break",
|
|
168
|
+
"byte",
|
|
169
|
+
"case",
|
|
170
|
+
"catch",
|
|
171
|
+
"char",
|
|
172
|
+
"class",
|
|
173
|
+
"const",
|
|
174
|
+
"continue",
|
|
175
|
+
"debugger",
|
|
176
|
+
"default",
|
|
177
|
+
"delete",
|
|
178
|
+
"do",
|
|
179
|
+
"double",
|
|
180
|
+
"else",
|
|
181
|
+
"enum",
|
|
182
|
+
"eval",
|
|
183
|
+
"export",
|
|
184
|
+
"extends",
|
|
185
|
+
"false",
|
|
186
|
+
"final",
|
|
187
|
+
"finally",
|
|
188
|
+
"float",
|
|
189
|
+
"for",
|
|
190
|
+
"function",
|
|
191
|
+
"goto",
|
|
192
|
+
"if",
|
|
193
|
+
"implements",
|
|
194
|
+
"import",
|
|
195
|
+
"in",
|
|
196
|
+
"instanceof",
|
|
197
|
+
"int",
|
|
198
|
+
"interface",
|
|
199
|
+
"let",
|
|
200
|
+
"long",
|
|
201
|
+
"native",
|
|
202
|
+
"new",
|
|
203
|
+
"null",
|
|
204
|
+
"package",
|
|
205
|
+
"private",
|
|
206
|
+
"protected",
|
|
207
|
+
"public",
|
|
208
|
+
"return",
|
|
209
|
+
"short",
|
|
210
|
+
"static",
|
|
211
|
+
"super",
|
|
212
|
+
"switch",
|
|
213
|
+
"synchronized",
|
|
214
|
+
"this",
|
|
215
|
+
"throw",
|
|
216
|
+
"throws",
|
|
217
|
+
"transient",
|
|
218
|
+
"true",
|
|
219
|
+
"try",
|
|
220
|
+
"typeof",
|
|
221
|
+
"var",
|
|
222
|
+
"void",
|
|
223
|
+
"volatile",
|
|
224
|
+
"while",
|
|
225
|
+
"with",
|
|
226
|
+
"yield",
|
|
227
|
+
"Array",
|
|
228
|
+
"Date",
|
|
229
|
+
"eval",
|
|
230
|
+
"function",
|
|
231
|
+
"hasOwnProperty",
|
|
232
|
+
"Infinity",
|
|
233
|
+
"isFinite",
|
|
234
|
+
"isNaN",
|
|
235
|
+
"isPrototypeOf",
|
|
236
|
+
"length",
|
|
237
|
+
"Math",
|
|
238
|
+
"name",
|
|
239
|
+
"NaN",
|
|
240
|
+
"Number",
|
|
241
|
+
"Object",
|
|
242
|
+
"prototype",
|
|
243
|
+
"String",
|
|
244
|
+
"toString",
|
|
245
|
+
"undefined",
|
|
246
|
+
"valueOf"
|
|
247
|
+
];
|
|
248
|
+
function transformReservedWord(word) {
|
|
249
|
+
if (word && reservedWords.includes(word) || word?.match(/^\d/)) {
|
|
250
|
+
return `_${word}`;
|
|
251
|
+
}
|
|
252
|
+
return word;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/transformers/trim.ts
|
|
256
|
+
function trim(text) {
|
|
257
|
+
return text.replaceAll(/\n/g, "").trim();
|
|
258
|
+
}
|
|
259
|
+
function trimExtName(text) {
|
|
260
|
+
return text.replace(/\.[^/.]+$/, "");
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// src/transformers/index.ts
|
|
264
|
+
var transformers_default = {
|
|
265
|
+
combineCodes,
|
|
266
|
+
escape,
|
|
267
|
+
jsStringEscape,
|
|
268
|
+
createIndent,
|
|
269
|
+
transformReservedWord,
|
|
270
|
+
nameSorter,
|
|
271
|
+
searchAndReplace,
|
|
272
|
+
trim,
|
|
273
|
+
trimExtName,
|
|
274
|
+
JSDoc: {
|
|
275
|
+
createJSDocBlockText
|
|
276
|
+
},
|
|
277
|
+
camelCase,
|
|
278
|
+
pascalCase
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// src/utils/FunctionParams.ts
|
|
81
282
|
var FunctionParams = class {
|
|
82
283
|
constructor(type) {
|
|
83
284
|
this.items = [];
|
|
@@ -102,7 +303,7 @@ var FunctionParams = class {
|
|
|
102
303
|
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
103
304
|
return acc;
|
|
104
305
|
}
|
|
105
|
-
const parameterName = name.startsWith("{") ? name : camelCase(name
|
|
306
|
+
const parameterName = name.startsWith("{") ? name : transformers_default.camelCase(name);
|
|
106
307
|
if (type) {
|
|
107
308
|
if (required) {
|
|
108
309
|
acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
@@ -204,8 +405,8 @@ var Queue = class {
|
|
|
204
405
|
__privateSet(this, _debug, debug);
|
|
205
406
|
}
|
|
206
407
|
run(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
207
|
-
return new Promise((
|
|
208
|
-
const item = { reject, resolve:
|
|
408
|
+
return new Promise((resolve3, reject) => {
|
|
409
|
+
const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
|
|
209
410
|
options.controller?.signal.addEventListener("abort", () => {
|
|
210
411
|
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
211
412
|
reject("Aborted");
|
|
@@ -215,8 +416,8 @@ var Queue = class {
|
|
|
215
416
|
});
|
|
216
417
|
}
|
|
217
418
|
runSync(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
218
|
-
new Promise((
|
|
219
|
-
const item = { reject, resolve:
|
|
419
|
+
new Promise((resolve3, reject) => {
|
|
420
|
+
const item = { reject, resolve: resolve3, job, name: options.name, description: options.description || options.name };
|
|
220
421
|
options.controller?.signal.addEventListener("abort", () => {
|
|
221
422
|
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
222
423
|
});
|
|
@@ -243,13 +444,13 @@ work_fn = function() {
|
|
|
243
444
|
__privateWrapper(this, _workerCount)._++;
|
|
244
445
|
let entry;
|
|
245
446
|
while (entry = __privateGet(this, _queue).shift()) {
|
|
246
|
-
const { reject, resolve:
|
|
447
|
+
const { reject, resolve: resolve3, job, name, description } = entry;
|
|
247
448
|
if (__privateGet(this, _debug)) {
|
|
248
449
|
performance.mark(name + "_start");
|
|
249
450
|
}
|
|
250
451
|
job().then((result) => {
|
|
251
452
|
this.eventEmitter.emit("jobDone", result);
|
|
252
|
-
|
|
453
|
+
resolve3(result);
|
|
253
454
|
if (__privateGet(this, _debug)) {
|
|
254
455
|
performance.mark(name + "_stop");
|
|
255
456
|
performance.measure(description, name + "_start", name + "_stop");
|
|
@@ -388,204 +589,12 @@ var throttle = (fn, delay) => {
|
|
|
388
589
|
|
|
389
590
|
// src/utils/timeout.ts
|
|
390
591
|
async function timeout(ms) {
|
|
391
|
-
return new Promise((
|
|
592
|
+
return new Promise((resolve3) => {
|
|
392
593
|
setTimeout(() => {
|
|
393
|
-
|
|
594
|
+
resolve3(true);
|
|
394
595
|
}, ms);
|
|
395
596
|
});
|
|
396
597
|
}
|
|
397
|
-
|
|
398
|
-
// src/utils/transformers/combineCodes.ts
|
|
399
|
-
function combineCodes(codes) {
|
|
400
|
-
return codes.join("\n");
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// src/utils/transformers/createJSDocBlockText.ts
|
|
404
|
-
function createJSDocBlockText({ comments, newLine }) {
|
|
405
|
-
const filteredComments = comments.filter(Boolean);
|
|
406
|
-
if (!filteredComments.length) {
|
|
407
|
-
return "";
|
|
408
|
-
}
|
|
409
|
-
const source = `/**
|
|
410
|
-
* ${filteredComments.join("\n * ")}
|
|
411
|
-
*/`;
|
|
412
|
-
if (newLine) {
|
|
413
|
-
return `${source}
|
|
414
|
-
`;
|
|
415
|
-
}
|
|
416
|
-
return source;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// src/utils/transformers/escape.ts
|
|
420
|
-
function escape(text) {
|
|
421
|
-
return text ? text.replaceAll("`", "\\`") : "";
|
|
422
|
-
}
|
|
423
|
-
function jsStringEscape(input) {
|
|
424
|
-
return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
|
|
425
|
-
switch (character) {
|
|
426
|
-
case '"':
|
|
427
|
-
case "'":
|
|
428
|
-
case "\\":
|
|
429
|
-
return "\\" + character;
|
|
430
|
-
case "\n":
|
|
431
|
-
return "\\n";
|
|
432
|
-
case "\r":
|
|
433
|
-
return "\\r";
|
|
434
|
-
case "\u2028":
|
|
435
|
-
return "\\u2028";
|
|
436
|
-
case "\u2029":
|
|
437
|
-
return "\\u2029";
|
|
438
|
-
default:
|
|
439
|
-
return "";
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
// src/utils/transformers/indent.ts
|
|
445
|
-
function createIndent(size) {
|
|
446
|
-
return Array.from({ length: size + 1 }).join(" ");
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// src/utils/transformers/nameSorter.ts
|
|
450
|
-
function nameSorter(a, b) {
|
|
451
|
-
if (a.name < b.name) {
|
|
452
|
-
return -1;
|
|
453
|
-
}
|
|
454
|
-
if (a.name > b.name) {
|
|
455
|
-
return 1;
|
|
456
|
-
}
|
|
457
|
-
return 0;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
// src/utils/transformers/searchAndReplace.ts
|
|
461
|
-
function searchAndReplace(options) {
|
|
462
|
-
const { text, replaceBy, prefix = "", key } = options;
|
|
463
|
-
const searchValues = options.searchValues?.(prefix, key) || [
|
|
464
|
-
`${prefix}["${key}"]`,
|
|
465
|
-
`${prefix}['${key}']`,
|
|
466
|
-
`${prefix}[\`${key}\`]`,
|
|
467
|
-
`${prefix}"${key}"`,
|
|
468
|
-
`${prefix}'${key}'`,
|
|
469
|
-
`${prefix}\`${key}\``,
|
|
470
|
-
new RegExp(`${prefix}${key}`, "g")
|
|
471
|
-
];
|
|
472
|
-
return searchValues.reduce((prev, searchValue) => {
|
|
473
|
-
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
474
|
-
}, text);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// src/utils/transformers/transformReservedWord.ts
|
|
478
|
-
var reservedWords = [
|
|
479
|
-
"abstract",
|
|
480
|
-
"arguments",
|
|
481
|
-
"boolean",
|
|
482
|
-
"break",
|
|
483
|
-
"byte",
|
|
484
|
-
"case",
|
|
485
|
-
"catch",
|
|
486
|
-
"char",
|
|
487
|
-
"class",
|
|
488
|
-
"const",
|
|
489
|
-
"continue",
|
|
490
|
-
"debugger",
|
|
491
|
-
"default",
|
|
492
|
-
"delete",
|
|
493
|
-
"do",
|
|
494
|
-
"double",
|
|
495
|
-
"else",
|
|
496
|
-
"enum",
|
|
497
|
-
"eval",
|
|
498
|
-
"export",
|
|
499
|
-
"extends",
|
|
500
|
-
"false",
|
|
501
|
-
"final",
|
|
502
|
-
"finally",
|
|
503
|
-
"float",
|
|
504
|
-
"for",
|
|
505
|
-
"function",
|
|
506
|
-
"goto",
|
|
507
|
-
"if",
|
|
508
|
-
"implements",
|
|
509
|
-
"import",
|
|
510
|
-
"in",
|
|
511
|
-
"instanceof",
|
|
512
|
-
"int",
|
|
513
|
-
"interface",
|
|
514
|
-
"let",
|
|
515
|
-
"long",
|
|
516
|
-
"native",
|
|
517
|
-
"new",
|
|
518
|
-
"null",
|
|
519
|
-
"package",
|
|
520
|
-
"private",
|
|
521
|
-
"protected",
|
|
522
|
-
"public",
|
|
523
|
-
"return",
|
|
524
|
-
"short",
|
|
525
|
-
"static",
|
|
526
|
-
"super",
|
|
527
|
-
"switch",
|
|
528
|
-
"synchronized",
|
|
529
|
-
"this",
|
|
530
|
-
"throw",
|
|
531
|
-
"throws",
|
|
532
|
-
"transient",
|
|
533
|
-
"true",
|
|
534
|
-
"try",
|
|
535
|
-
"typeof",
|
|
536
|
-
"var",
|
|
537
|
-
"void",
|
|
538
|
-
"volatile",
|
|
539
|
-
"while",
|
|
540
|
-
"with",
|
|
541
|
-
"yield",
|
|
542
|
-
"Array",
|
|
543
|
-
"Date",
|
|
544
|
-
"eval",
|
|
545
|
-
"function",
|
|
546
|
-
"hasOwnProperty",
|
|
547
|
-
"Infinity",
|
|
548
|
-
"isFinite",
|
|
549
|
-
"isNaN",
|
|
550
|
-
"isPrototypeOf",
|
|
551
|
-
"length",
|
|
552
|
-
"Math",
|
|
553
|
-
"name",
|
|
554
|
-
"NaN",
|
|
555
|
-
"Number",
|
|
556
|
-
"Object",
|
|
557
|
-
"prototype",
|
|
558
|
-
"String",
|
|
559
|
-
"toString",
|
|
560
|
-
"undefined",
|
|
561
|
-
"valueOf"
|
|
562
|
-
];
|
|
563
|
-
function transformReservedWord(word) {
|
|
564
|
-
if (word && reservedWords.includes(word) || word?.match(/^\d/)) {
|
|
565
|
-
return `_${word}`;
|
|
566
|
-
}
|
|
567
|
-
return word;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// src/utils/transformers/trim.ts
|
|
571
|
-
function trim(text) {
|
|
572
|
-
return text.replaceAll(/\n/g, "").trim();
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
// src/utils/transformers/index.ts
|
|
576
|
-
var transformers = {
|
|
577
|
-
combineCodes,
|
|
578
|
-
escape,
|
|
579
|
-
jsStringEscape,
|
|
580
|
-
createIndent,
|
|
581
|
-
transformReservedWord,
|
|
582
|
-
nameSorter,
|
|
583
|
-
searchAndReplace,
|
|
584
|
-
trim,
|
|
585
|
-
JSDoc: {
|
|
586
|
-
createJSDocBlockText
|
|
587
|
-
}
|
|
588
|
-
};
|
|
589
598
|
async function saveCreateDirectory(path2) {
|
|
590
599
|
const passedPath = dirname(resolve(path2));
|
|
591
600
|
await fs2.mkdir(passedPath, { recursive: true });
|
|
@@ -649,82 +658,71 @@ async function write(data, path2) {
|
|
|
649
658
|
var _options;
|
|
650
659
|
var BarrelManager = class {
|
|
651
660
|
constructor(options = {}) {
|
|
652
|
-
__privateAdd(this, _options,
|
|
661
|
+
__privateAdd(this, _options, void 0);
|
|
653
662
|
__privateSet(this, _options, options);
|
|
654
663
|
return this;
|
|
655
664
|
}
|
|
656
|
-
getIndexes(
|
|
657
|
-
const { treeNode = {}, isTypeOnly,
|
|
658
|
-
const
|
|
659
|
-
".ts": {
|
|
660
|
-
extensions: /\.ts/,
|
|
661
|
-
exclude: [/schemas/, /json/]
|
|
662
|
-
},
|
|
663
|
-
".json": {
|
|
664
|
-
extensions: /\.json/,
|
|
665
|
-
exclude: []
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
|
|
665
|
+
getIndexes(pathToBuild) {
|
|
666
|
+
const { treeNode = {}, isTypeOnly, extName } = __privateGet(this, _options);
|
|
667
|
+
const tree = TreeNode.build(pathToBuild, treeNode);
|
|
669
668
|
if (!tree) {
|
|
670
669
|
return null;
|
|
671
670
|
}
|
|
672
|
-
const fileReducer = (
|
|
673
|
-
if (!
|
|
671
|
+
const fileReducer = (files, treeNode2) => {
|
|
672
|
+
if (!treeNode2.children) {
|
|
674
673
|
return [];
|
|
675
674
|
}
|
|
676
|
-
if (
|
|
677
|
-
const indexPath = path.resolve(
|
|
678
|
-
const exports =
|
|
679
|
-
const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name
|
|
680
|
-
if (importPath.
|
|
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") {
|
|
681
680
|
return void 0;
|
|
682
681
|
}
|
|
683
682
|
return {
|
|
684
|
-
path:
|
|
683
|
+
path: extName ? `${importPath}${extName}` : importPath,
|
|
685
684
|
isTypeOnly
|
|
686
685
|
};
|
|
687
686
|
}).filter(Boolean);
|
|
688
|
-
|
|
687
|
+
files.push({
|
|
689
688
|
path: indexPath,
|
|
690
689
|
baseName: "index.ts",
|
|
691
690
|
source: "",
|
|
692
|
-
exports
|
|
693
|
-
|
|
694
|
-
|
|
691
|
+
exports,
|
|
692
|
+
meta: {
|
|
693
|
+
treeNode: treeNode2
|
|
694
|
+
}
|
|
695
695
|
});
|
|
696
|
-
} else {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
}
|
|
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
714
|
});
|
|
715
715
|
}
|
|
716
|
-
|
|
717
|
-
fileReducer(
|
|
716
|
+
treeNode2.children.forEach((childItem) => {
|
|
717
|
+
fileReducer(files, childItem);
|
|
718
718
|
});
|
|
719
|
-
return
|
|
719
|
+
return files;
|
|
720
720
|
};
|
|
721
|
-
|
|
722
|
-
const filteredFiles = filter ? files.filter(filter) : files;
|
|
723
|
-
return map ? filteredFiles.map(map) : filteredFiles;
|
|
721
|
+
return fileReducer([], tree).reverse();
|
|
724
722
|
}
|
|
725
723
|
};
|
|
726
724
|
_options = new WeakMap();
|
|
727
|
-
var _cache, _task, _isWriting, _timeout, _queue2, _validate,
|
|
725
|
+
var _cache, _task, _isWriting, _timeout, _queue2, _validate, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
728
726
|
var _FileManager = class _FileManager {
|
|
729
727
|
constructor(options) {
|
|
730
728
|
__privateAdd(this, _validate);
|
|
@@ -757,7 +755,6 @@ var _FileManager = class _FileManager {
|
|
|
757
755
|
}
|
|
758
756
|
async add(...files) {
|
|
759
757
|
const promises = files.map((file) => {
|
|
760
|
-
__privateMethod(this, _validate, validate_fn).call(this, file);
|
|
761
758
|
if (file.override) {
|
|
762
759
|
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
763
760
|
}
|
|
@@ -769,12 +766,37 @@ var _FileManager = class _FileManager {
|
|
|
769
766
|
}
|
|
770
767
|
return resolvedFiles[0];
|
|
771
768
|
}
|
|
772
|
-
async addIndexes({ root,
|
|
773
|
-
const
|
|
774
|
-
|
|
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));
|
|
775
777
|
if (!files) {
|
|
776
778
|
return void 0;
|
|
777
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
|
+
});
|
|
778
800
|
return await Promise.all(
|
|
779
801
|
files.map((file) => {
|
|
780
802
|
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
@@ -821,9 +843,22 @@ var _FileManager = class _FileManager {
|
|
|
821
843
|
}
|
|
822
844
|
const exports = file.exports ? combineExports(file.exports) : [];
|
|
823
845
|
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
824
|
-
const importNodes = imports.
|
|
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
|
+
});
|
|
825
855
|
const exportNodes = exports.map(
|
|
826
|
-
(item) => factory.createExportDeclaration({
|
|
856
|
+
(item) => factory.createExportDeclaration({
|
|
857
|
+
name: item.name,
|
|
858
|
+
path: item.path,
|
|
859
|
+
isTypeOnly: item.isTypeOnly,
|
|
860
|
+
asAlias: item.asAlias
|
|
861
|
+
})
|
|
827
862
|
);
|
|
828
863
|
return [print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
829
864
|
}
|
|
@@ -874,18 +909,10 @@ _isWriting = new WeakMap();
|
|
|
874
909
|
_timeout = new WeakMap();
|
|
875
910
|
_queue2 = new WeakMap();
|
|
876
911
|
_validate = new WeakSet();
|
|
877
|
-
validate_fn = function(file) {
|
|
878
|
-
if (!file.validate) {
|
|
879
|
-
return;
|
|
880
|
-
}
|
|
881
|
-
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
882
|
-
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
883
|
-
}
|
|
884
|
-
};
|
|
885
912
|
_add = new WeakSet();
|
|
886
913
|
add_fn = async function(file) {
|
|
887
914
|
const controller = new AbortController();
|
|
888
|
-
const resolvedFile = { id: crypto.randomUUID(), ...file };
|
|
915
|
+
const resolvedFile = { id: crypto.randomUUID(), name: transformers_default.trimExtName(file.baseName), ...file };
|
|
889
916
|
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
890
917
|
if (__privateGet(this, _queue2)) {
|
|
891
918
|
await __privateGet(this, _queue2).run(
|
|
@@ -958,7 +985,7 @@ function combineImports(imports, exports, source) {
|
|
|
958
985
|
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
959
986
|
};
|
|
960
987
|
if (Array.isArray(name)) {
|
|
961
|
-
name = name.filter((item) => hasImportInSource(item));
|
|
988
|
+
name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
|
|
962
989
|
}
|
|
963
990
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
964
991
|
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
@@ -1004,8 +1031,8 @@ function getEnvSource(source, env) {
|
|
|
1004
1031
|
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
1005
1032
|
}
|
|
1006
1033
|
if (typeof replaceBy === "string") {
|
|
1007
|
-
prev =
|
|
1008
|
-
prev =
|
|
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).*
|
|
1009
1036
|
`, "ig"), ""), replaceBy, key });
|
|
1010
1037
|
}
|
|
1011
1038
|
return prev;
|
|
@@ -1118,6 +1145,8 @@ function setUniqueName(originalName, data) {
|
|
|
1118
1145
|
data[originalName] = 1;
|
|
1119
1146
|
return originalName;
|
|
1120
1147
|
}
|
|
1148
|
+
|
|
1149
|
+
// src/utils/URLPath.ts
|
|
1121
1150
|
var URLPath = class {
|
|
1122
1151
|
constructor(path2) {
|
|
1123
1152
|
this.path = path2;
|
|
@@ -1184,7 +1213,7 @@ var URLPath = class {
|
|
|
1184
1213
|
let newPath = this.path.replaceAll("{", "${");
|
|
1185
1214
|
if (found) {
|
|
1186
1215
|
newPath = found.reduce((prev, curr) => {
|
|
1187
|
-
const pathParam = replacer ? replacer(camelCase(curr
|
|
1216
|
+
const pathParam = replacer ? replacer(transformers_default.camelCase(curr)) : transformers_default.camelCase(curr);
|
|
1188
1217
|
const replacement = `\${${pathParam}}`;
|
|
1189
1218
|
return prev.replace(curr, replacement);
|
|
1190
1219
|
}, this.path);
|
|
@@ -1200,7 +1229,7 @@ var URLPath = class {
|
|
|
1200
1229
|
const params = {};
|
|
1201
1230
|
found.forEach((item) => {
|
|
1202
1231
|
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
1203
|
-
const pathParam = replacer ? replacer(camelCase(item
|
|
1232
|
+
const pathParam = replacer ? replacer(transformers_default.camelCase(item)) : transformers_default.camelCase(item);
|
|
1204
1233
|
params[pathParam] = pathParam;
|
|
1205
1234
|
}, this.path);
|
|
1206
1235
|
return params;
|
|
@@ -1214,6 +1243,6 @@ var URLPath = class {
|
|
|
1214
1243
|
}
|
|
1215
1244
|
};
|
|
1216
1245
|
|
|
1217
|
-
export { FunctionParams, LogLevel, Queue, TreeNode, URLPath, clean, createLogger, createPluginCache, getRelativePath, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, randomColour, randomPicoColour, read, readSync, renderTemplate, setUniqueName, throttle, timeout,
|
|
1246
|
+
export { FunctionParams, LogLevel, Queue, TreeNode, URLPath, clean, createLogger, createPluginCache, getRelativePath, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, randomColour, randomPicoColour, read, readSync, renderTemplate, setUniqueName, throttle, timeout, write };
|
|
1218
1247
|
//# sourceMappingURL=out.js.map
|
|
1219
1248
|
//# sourceMappingURL=utils.js.map
|