@kubb/core 3.16.2 → 3.16.3
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/FileManager-Dk759iZ3.js +918 -0
- package/dist/FileManager-Dk759iZ3.js.map +1 -0
- package/dist/FileManager-DsRjYJa_.cjs +1031 -0
- package/dist/FileManager-DsRjYJa_.cjs.map +1 -0
- package/dist/PluginManager-1jPxuyQK.d.ts +511 -0
- package/dist/PluginManager-Cvj5AlsU.d.cts +511 -0
- package/dist/chunk-DWy1uDak.cjs +39 -0
- package/dist/chunk-DbvY3SJr.js +33 -0
- package/dist/fs-BacxV1CO.js +87 -0
- package/dist/fs-BacxV1CO.js.map +1 -0
- package/dist/fs-BazSaf2y.cjs +129 -0
- package/dist/fs-BazSaf2y.cjs.map +1 -0
- package/dist/fs.cjs +15 -39
- package/dist/fs.d.cts +2 -19
- package/dist/fs.d.ts +2 -19
- package/dist/fs.js +4 -3
- package/dist/index-BKHQGQVq.d.ts +140 -0
- package/dist/index-BfD6z1P5.d.cts +141 -0
- package/dist/index-Cb4pChs8.d.ts +180 -0
- package/dist/index-D2ptHzfn.d.cts +180 -0
- package/dist/index.cjs +997 -1077
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +107 -89
- package/dist/index.d.ts +107 -89
- package/dist/index.js +1020 -864
- package/dist/index.js.map +1 -1
- package/dist/logger-BxvJpQMX.cjs +1115 -0
- package/dist/logger-BxvJpQMX.cjs.map +1 -0
- package/dist/logger-Cs45J4yy.js +1085 -0
- package/dist/logger-Cs45J4yy.js.map +1 -0
- package/dist/logger-OWS6fqk0.d.cts +69 -0
- package/dist/logger-xcdTETKy.d.ts +69 -0
- package/dist/logger.cjs +6 -24
- package/dist/logger.d.cts +2 -3
- package/dist/logger.d.ts +2 -3
- package/dist/logger.js +4 -4
- package/dist/mocks.cjs +49 -65
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +6 -6
- package/dist/mocks.d.ts +6 -6
- package/dist/mocks.js +48 -59
- package/dist/mocks.js.map +1 -1
- package/dist/prompt-DwEAzq0q.js +853 -0
- package/dist/prompt-DwEAzq0q.js.map +1 -0
- package/dist/prompt-qiwl6Be9.cjs +855 -0
- package/dist/prompt-qiwl6Be9.cjs.map +1 -0
- package/dist/transformers-B3CHtwuB.cjs +948 -0
- package/dist/transformers-B3CHtwuB.cjs.map +1 -0
- package/dist/transformers-CJqBQFIl.js +829 -0
- package/dist/transformers-CJqBQFIl.js.map +1 -0
- package/dist/transformers.cjs +33 -88
- package/dist/transformers.d.cts +75 -54
- package/dist/transformers.d.ts +75 -54
- package/dist/transformers.js +4 -3
- package/dist/utils.cjs +20 -73
- package/dist/utils.d.cts +5 -126
- package/dist/utils.d.ts +5 -126
- package/dist/utils.js +6 -5
- package/dist/write-CLTPlucv.js +42 -0
- package/dist/write-CLTPlucv.js.map +1 -0
- package/dist/write-l_NzIqyy.cjs +48 -0
- package/dist/write-l_NzIqyy.cjs.map +1 -0
- package/package.json +25 -32
- package/src/BarrelManager.ts +1 -0
- package/src/PromiseManager.ts +1 -7
- package/src/build.ts +9 -11
- package/src/index.ts +5 -5
- package/src/logger.ts +10 -10
- package/src/utils/FunctionParams.ts +3 -1
- package/src/utils/TreeNode.ts +3 -1
- package/dist/PluginManager-E3SghPP9.d.cts +0 -458
- package/dist/PluginManager-PDmRCu9k.d.ts +0 -458
- package/dist/chunk-4V7HK7PT.js +0 -1199
- package/dist/chunk-4V7HK7PT.js.map +0 -1
- package/dist/chunk-BHSTNFNQ.cjs +0 -701
- package/dist/chunk-BHSTNFNQ.cjs.map +0 -1
- package/dist/chunk-CAZ37TGB.js +0 -918
- package/dist/chunk-CAZ37TGB.js.map +0 -1
- package/dist/chunk-E4XLCCPK.cjs +0 -170
- package/dist/chunk-E4XLCCPK.cjs.map +0 -1
- package/dist/chunk-GBYHPDPK.js +0 -595
- package/dist/chunk-GBYHPDPK.js.map +0 -1
- package/dist/chunk-L3A3DTAX.cjs +0 -1074
- package/dist/chunk-L3A3DTAX.cjs.map +0 -1
- package/dist/chunk-MCNA6SYG.cjs +0 -1231
- package/dist/chunk-MCNA6SYG.cjs.map +0 -1
- package/dist/chunk-YRPOID7E.js +0 -157
- package/dist/chunk-YRPOID7E.js.map +0 -1
- package/dist/fs.cjs.map +0 -1
- package/dist/fs.js.map +0 -1
- package/dist/logger-BWq-oJU_.d.cts +0 -63
- package/dist/logger-BWq-oJU_.d.ts +0 -63
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.js.map +0 -1
- package/dist/parser-C1vOjVEd.d.ts +0 -41
- package/dist/parser-D6vU1kA9.d.cts +0 -41
- package/dist/prompt-ELTHGQK6.js +0 -753
- package/dist/prompt-ELTHGQK6.js.map +0 -1
- package/dist/prompt-U7M5G25C.cjs +0 -761
- package/dist/prompt-U7M5G25C.cjs.map +0 -1
- package/dist/transformers.cjs.map +0 -1
- package/dist/transformers.js.map +0 -1
- package/dist/types-CA8nQKwM.d.cts +0 -132
- package/dist/types-CA8nQKwM.d.ts +0 -132
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.js.map +0 -1
package/dist/chunk-CAZ37TGB.js
DELETED
|
@@ -1,918 +0,0 @@
|
|
|
1
|
-
import { orderBy, camelCase, isValidVarName } from './chunk-GBYHPDPK.js';
|
|
2
|
-
import { trimExtName, write, getRelativePath } from './chunk-YRPOID7E.js';
|
|
3
|
-
import path, { relative, join, extname } from 'path';
|
|
4
|
-
import hash from 'object-hash';
|
|
5
|
-
import { isDeepEqual, uniqueBy } from 'remeda';
|
|
6
|
-
import pLimit from 'p-limit';
|
|
7
|
-
|
|
8
|
-
// src/utils/FunctionParams.ts
|
|
9
|
-
var FunctionParams = class _FunctionParams {
|
|
10
|
-
#items = [];
|
|
11
|
-
constructor() {
|
|
12
|
-
return this;
|
|
13
|
-
}
|
|
14
|
-
get items() {
|
|
15
|
-
return this.#items.flat();
|
|
16
|
-
}
|
|
17
|
-
add(item) {
|
|
18
|
-
if (!item) {
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
if (Array.isArray(item)) {
|
|
22
|
-
item.filter(Boolean).forEach((it) => this.#items.push(it));
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
this.#items.push(item);
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
static #orderItems(items) {
|
|
29
|
-
return orderBy(
|
|
30
|
-
items.filter(Boolean),
|
|
31
|
-
[
|
|
32
|
-
(v) => {
|
|
33
|
-
if (Array.isArray(v)) {
|
|
34
|
-
return void 0;
|
|
35
|
-
}
|
|
36
|
-
return !v.default;
|
|
37
|
-
},
|
|
38
|
-
(v) => {
|
|
39
|
-
if (Array.isArray(v)) {
|
|
40
|
-
return void 0;
|
|
41
|
-
}
|
|
42
|
-
return v.required ?? true;
|
|
43
|
-
}
|
|
44
|
-
],
|
|
45
|
-
["desc", "desc"]
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
static #addParams(acc, item) {
|
|
49
|
-
const { enabled = true, name, type, required = true, ...rest } = item;
|
|
50
|
-
if (!enabled) {
|
|
51
|
-
return acc;
|
|
52
|
-
}
|
|
53
|
-
if (!name) {
|
|
54
|
-
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
55
|
-
return acc;
|
|
56
|
-
}
|
|
57
|
-
const parameterName = name.startsWith("{") ? name : camelCase(name);
|
|
58
|
-
if (type) {
|
|
59
|
-
if (required) {
|
|
60
|
-
acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
61
|
-
} else {
|
|
62
|
-
acc.push(`${parameterName}?: ${type}`);
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
acc.push(`${parameterName}`);
|
|
66
|
-
}
|
|
67
|
-
return acc;
|
|
68
|
-
}
|
|
69
|
-
static toObject(items) {
|
|
70
|
-
let type = [];
|
|
71
|
-
let name = [];
|
|
72
|
-
const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true;
|
|
73
|
-
const required = items.every((item) => item.required) ?? true;
|
|
74
|
-
items.forEach((item) => {
|
|
75
|
-
name = _FunctionParams.#addParams(name, { ...item, type: void 0 });
|
|
76
|
-
if (items.some((item2) => item2.type)) {
|
|
77
|
-
type = _FunctionParams.#addParams(type, item);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return {
|
|
81
|
-
name: `{ ${name.join(", ")} }`,
|
|
82
|
-
type: type.length ? `{ ${type.join("; ")} }` : void 0,
|
|
83
|
-
enabled,
|
|
84
|
-
required
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
static toString(items) {
|
|
88
|
-
const sortedData = _FunctionParams.#orderItems(items);
|
|
89
|
-
return sortedData.reduce((acc, item) => {
|
|
90
|
-
if (Array.isArray(item)) {
|
|
91
|
-
if (item.length <= 0) {
|
|
92
|
-
return acc;
|
|
93
|
-
}
|
|
94
|
-
const subItems = _FunctionParams.#orderItems(item);
|
|
95
|
-
const objectItem = _FunctionParams.toObject(subItems);
|
|
96
|
-
return _FunctionParams.#addParams(acc, objectItem);
|
|
97
|
-
}
|
|
98
|
-
return _FunctionParams.#addParams(acc, item);
|
|
99
|
-
}, []).join(", ");
|
|
100
|
-
}
|
|
101
|
-
toObject() {
|
|
102
|
-
const items = _FunctionParams.#orderItems(this.#items).flat();
|
|
103
|
-
return _FunctionParams.toObject(items);
|
|
104
|
-
}
|
|
105
|
-
toString() {
|
|
106
|
-
const items = _FunctionParams.#orderItems(this.#items);
|
|
107
|
-
return _FunctionParams.toString(items);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// src/utils/promise.ts
|
|
112
|
-
function isPromise(result) {
|
|
113
|
-
return !!result && typeof result?.then === "function";
|
|
114
|
-
}
|
|
115
|
-
function isPromiseFulfilledResult(result) {
|
|
116
|
-
return result.status === "fulfilled";
|
|
117
|
-
}
|
|
118
|
-
function isPromiseRejectedResult(result) {
|
|
119
|
-
return result.status === "rejected";
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// src/utils/renderTemplate.ts
|
|
123
|
-
function renderTemplate(template, data = void 0) {
|
|
124
|
-
if (!data || !Object.keys(data).length) {
|
|
125
|
-
return template.replace(/{{(.*?)}}/g, "");
|
|
126
|
-
}
|
|
127
|
-
const matches = template.match(/{{(.*?)}}/g);
|
|
128
|
-
return matches?.reduce((prev, curr) => {
|
|
129
|
-
const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
|
|
130
|
-
if (index === void 0) {
|
|
131
|
-
return prev;
|
|
132
|
-
}
|
|
133
|
-
const value = data[index];
|
|
134
|
-
if (value === void 0) {
|
|
135
|
-
return prev;
|
|
136
|
-
}
|
|
137
|
-
return prev.replace(curr, () => {
|
|
138
|
-
if (typeof value === "boolean") {
|
|
139
|
-
return `${value.toString()}` || "false";
|
|
140
|
-
}
|
|
141
|
-
return value || "";
|
|
142
|
-
}).trim();
|
|
143
|
-
}, template) || "";
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// src/utils/timeout.ts
|
|
147
|
-
async function timeout(ms) {
|
|
148
|
-
return new Promise((resolve) => {
|
|
149
|
-
setTimeout(() => {
|
|
150
|
-
resolve(true);
|
|
151
|
-
}, ms);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// src/utils/uniqueName.ts
|
|
156
|
-
function getUniqueName(originalName, data) {
|
|
157
|
-
let used = data[originalName] || 0;
|
|
158
|
-
if (used) {
|
|
159
|
-
data[originalName] = ++used;
|
|
160
|
-
originalName += used;
|
|
161
|
-
}
|
|
162
|
-
data[originalName] = 1;
|
|
163
|
-
return originalName;
|
|
164
|
-
}
|
|
165
|
-
function setUniqueName(originalName, data) {
|
|
166
|
-
let used = data[originalName] || 0;
|
|
167
|
-
if (used) {
|
|
168
|
-
data[originalName] = ++used;
|
|
169
|
-
return originalName;
|
|
170
|
-
}
|
|
171
|
-
data[originalName] = 1;
|
|
172
|
-
return originalName;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// src/utils/URLPath.ts
|
|
176
|
-
var URLPath = class {
|
|
177
|
-
path;
|
|
178
|
-
#options;
|
|
179
|
-
constructor(path2, options = {}) {
|
|
180
|
-
this.path = path2;
|
|
181
|
-
this.#options = options;
|
|
182
|
-
return this;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
186
|
-
* @example /pet/{petId} => /pet/:petId
|
|
187
|
-
*/
|
|
188
|
-
get URL() {
|
|
189
|
-
return this.toURLPath();
|
|
190
|
-
}
|
|
191
|
-
get isURL() {
|
|
192
|
-
try {
|
|
193
|
-
const url = new URL(this.path);
|
|
194
|
-
if (url?.href) {
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
} catch (_error) {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
204
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
205
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
206
|
-
* @example /account/userID => `/account/${userId}`
|
|
207
|
-
*/
|
|
208
|
-
get template() {
|
|
209
|
-
return this.toTemplateString();
|
|
210
|
-
}
|
|
211
|
-
get object() {
|
|
212
|
-
return this.toObject();
|
|
213
|
-
}
|
|
214
|
-
get params() {
|
|
215
|
-
return this.getParams();
|
|
216
|
-
}
|
|
217
|
-
toObject({ type = "path", replacer, stringify } = {}) {
|
|
218
|
-
const object = {
|
|
219
|
-
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
220
|
-
params: this.getParams()
|
|
221
|
-
};
|
|
222
|
-
if (stringify) {
|
|
223
|
-
if (type === "template") {
|
|
224
|
-
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
225
|
-
}
|
|
226
|
-
if (object.params) {
|
|
227
|
-
return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
228
|
-
}
|
|
229
|
-
return `{ url: '${object.url}' }`;
|
|
230
|
-
}
|
|
231
|
-
return object;
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
235
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
236
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
237
|
-
* @example /account/userID => `/account/${userId}`
|
|
238
|
-
*/
|
|
239
|
-
toTemplateString({ prefix = "", replacer } = {}) {
|
|
240
|
-
const regex = /{(\w|-)*}/g;
|
|
241
|
-
const found = this.path.match(regex);
|
|
242
|
-
let newPath = this.path.replaceAll("{", "${");
|
|
243
|
-
if (found) {
|
|
244
|
-
newPath = found.reduce((prev, path2) => {
|
|
245
|
-
const pathWithoutBrackets = path2.replaceAll("{", "").replaceAll("}", "");
|
|
246
|
-
let param = isValidVarName(pathWithoutBrackets) ? pathWithoutBrackets : camelCase(pathWithoutBrackets);
|
|
247
|
-
if (this.#options.casing === "camelcase") {
|
|
248
|
-
param = camelCase(param);
|
|
249
|
-
}
|
|
250
|
-
return prev.replace(path2, `\${${replacer ? replacer(param) : param}}`);
|
|
251
|
-
}, this.path);
|
|
252
|
-
}
|
|
253
|
-
return `\`${prefix}${newPath}\``;
|
|
254
|
-
}
|
|
255
|
-
getParams(replacer) {
|
|
256
|
-
const regex = /{(\w|-)*}/g;
|
|
257
|
-
const found = this.path.match(regex);
|
|
258
|
-
if (!found) {
|
|
259
|
-
return void 0;
|
|
260
|
-
}
|
|
261
|
-
const params = {};
|
|
262
|
-
found.forEach((item) => {
|
|
263
|
-
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
264
|
-
let param = isValidVarName(item) ? item : camelCase(item);
|
|
265
|
-
if (this.#options.casing === "camelcase") {
|
|
266
|
-
param = camelCase(param);
|
|
267
|
-
}
|
|
268
|
-
const key = replacer ? replacer(param) : param;
|
|
269
|
-
params[key] = key;
|
|
270
|
-
}, this.path);
|
|
271
|
-
return params;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
275
|
-
* @example /pet/{petId} => /pet/:petId
|
|
276
|
-
*/
|
|
277
|
-
toURLPath() {
|
|
278
|
-
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
// src/utils/TreeNode.ts
|
|
283
|
-
var TreeNode = class _TreeNode {
|
|
284
|
-
data;
|
|
285
|
-
parent;
|
|
286
|
-
children = [];
|
|
287
|
-
#cachedLeaves = void 0;
|
|
288
|
-
constructor(data, parent) {
|
|
289
|
-
this.data = data;
|
|
290
|
-
this.parent = parent;
|
|
291
|
-
return this;
|
|
292
|
-
}
|
|
293
|
-
addChild(data) {
|
|
294
|
-
const child = new _TreeNode(data, this);
|
|
295
|
-
if (!this.children) {
|
|
296
|
-
this.children = [];
|
|
297
|
-
}
|
|
298
|
-
this.children.push(child);
|
|
299
|
-
return child;
|
|
300
|
-
}
|
|
301
|
-
get root() {
|
|
302
|
-
if (!this.parent) {
|
|
303
|
-
return this;
|
|
304
|
-
}
|
|
305
|
-
return this.parent.root;
|
|
306
|
-
}
|
|
307
|
-
get leaves() {
|
|
308
|
-
if (!this.children || this.children.length === 0) {
|
|
309
|
-
return [this];
|
|
310
|
-
}
|
|
311
|
-
if (this.#cachedLeaves) {
|
|
312
|
-
return this.#cachedLeaves;
|
|
313
|
-
}
|
|
314
|
-
const leaves = [];
|
|
315
|
-
if (this.children) {
|
|
316
|
-
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
317
|
-
leaves.push.apply(leaves, this.children[i].leaves);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
this.#cachedLeaves = leaves;
|
|
321
|
-
return leaves;
|
|
322
|
-
}
|
|
323
|
-
forEach(callback) {
|
|
324
|
-
if (typeof callback !== "function") {
|
|
325
|
-
throw new TypeError("forEach() callback must be a function");
|
|
326
|
-
}
|
|
327
|
-
callback(this);
|
|
328
|
-
if (this.children) {
|
|
329
|
-
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
330
|
-
this.children[i]?.forEach(callback);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
return this;
|
|
334
|
-
}
|
|
335
|
-
findDeep(predicate) {
|
|
336
|
-
if (typeof predicate !== "function") {
|
|
337
|
-
throw new TypeError("find() predicate must be a function");
|
|
338
|
-
}
|
|
339
|
-
return this.leaves.find(predicate);
|
|
340
|
-
}
|
|
341
|
-
forEachDeep(callback) {
|
|
342
|
-
if (typeof callback !== "function") {
|
|
343
|
-
throw new TypeError("forEach() callback must be a function");
|
|
344
|
-
}
|
|
345
|
-
this.leaves.forEach(callback);
|
|
346
|
-
}
|
|
347
|
-
filterDeep(callback) {
|
|
348
|
-
if (typeof callback !== "function") {
|
|
349
|
-
throw new TypeError("filter() callback must be a function");
|
|
350
|
-
}
|
|
351
|
-
return this.leaves.filter(callback);
|
|
352
|
-
}
|
|
353
|
-
mapDeep(callback) {
|
|
354
|
-
if (typeof callback !== "function") {
|
|
355
|
-
throw new TypeError("map() callback must be a function");
|
|
356
|
-
}
|
|
357
|
-
return this.leaves.map(callback);
|
|
358
|
-
}
|
|
359
|
-
static build(files, root) {
|
|
360
|
-
try {
|
|
361
|
-
const filteredTree = buildDirectoryTree(files, root);
|
|
362
|
-
if (!filteredTree) {
|
|
363
|
-
return null;
|
|
364
|
-
}
|
|
365
|
-
const treeNode = new _TreeNode({
|
|
366
|
-
name: filteredTree.name,
|
|
367
|
-
path: filteredTree.path,
|
|
368
|
-
file: filteredTree.file,
|
|
369
|
-
type: FileManager.getMode(filteredTree.path)
|
|
370
|
-
});
|
|
371
|
-
const recurse = (node, item) => {
|
|
372
|
-
const subNode = node.addChild({
|
|
373
|
-
name: item.name,
|
|
374
|
-
path: item.path,
|
|
375
|
-
file: item.file,
|
|
376
|
-
type: FileManager.getMode(item.path)
|
|
377
|
-
});
|
|
378
|
-
if (item.children?.length) {
|
|
379
|
-
item.children?.forEach((child) => {
|
|
380
|
-
recurse(subNode, child);
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
filteredTree.children?.forEach((child) => recurse(treeNode, child));
|
|
385
|
-
return treeNode;
|
|
386
|
-
} catch (e) {
|
|
387
|
-
throw new Error("Something went wrong with creating barrel files with the TreeNode class", { cause: e });
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
var normalizePath = (p) => p.replace(/\\/g, "/");
|
|
392
|
-
function buildDirectoryTree(files, rootFolder = "") {
|
|
393
|
-
const normalizedRootFolder = normalizePath(rootFolder);
|
|
394
|
-
const rootPrefix = normalizedRootFolder.endsWith("/") ? normalizedRootFolder : `${normalizedRootFolder}/`;
|
|
395
|
-
const filteredFiles = files.filter((file) => {
|
|
396
|
-
const normalizedFilePath = normalizePath(file.path);
|
|
397
|
-
return rootFolder ? normalizedFilePath.startsWith(rootPrefix) && !normalizedFilePath.endsWith(".json") : !normalizedFilePath.endsWith(".json");
|
|
398
|
-
});
|
|
399
|
-
if (filteredFiles.length === 0) {
|
|
400
|
-
return null;
|
|
401
|
-
}
|
|
402
|
-
const root = {
|
|
403
|
-
name: rootFolder || "",
|
|
404
|
-
path: rootFolder || "",
|
|
405
|
-
children: []
|
|
406
|
-
};
|
|
407
|
-
filteredFiles.forEach((file) => {
|
|
408
|
-
const path2 = file.path.slice(rootFolder.length);
|
|
409
|
-
const parts = path2.split("/");
|
|
410
|
-
let currentLevel = root.children;
|
|
411
|
-
let currentPath = rootFolder;
|
|
412
|
-
parts.forEach((part, index) => {
|
|
413
|
-
if (index !== 0) {
|
|
414
|
-
currentPath += `/${part}`;
|
|
415
|
-
} else {
|
|
416
|
-
currentPath += `${part}`;
|
|
417
|
-
}
|
|
418
|
-
let existingNode = currentLevel.find((node) => node.name === part);
|
|
419
|
-
if (!existingNode) {
|
|
420
|
-
if (index === parts.length - 1) {
|
|
421
|
-
existingNode = {
|
|
422
|
-
name: part,
|
|
423
|
-
file,
|
|
424
|
-
path: currentPath
|
|
425
|
-
};
|
|
426
|
-
} else {
|
|
427
|
-
existingNode = {
|
|
428
|
-
name: part,
|
|
429
|
-
path: currentPath,
|
|
430
|
-
children: []
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
currentLevel.push(existingNode);
|
|
434
|
-
}
|
|
435
|
-
if (!existingNode.file) {
|
|
436
|
-
currentLevel = existingNode.children;
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
});
|
|
440
|
-
return root;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
// src/BarrelManager.ts
|
|
444
|
-
var BarrelManager = class {
|
|
445
|
-
#options;
|
|
446
|
-
constructor(options = {}) {
|
|
447
|
-
this.#options = options;
|
|
448
|
-
return this;
|
|
449
|
-
}
|
|
450
|
-
getFiles({ files: generatedFiles, root }) {
|
|
451
|
-
const { logger } = this.#options;
|
|
452
|
-
const cachedFiles = /* @__PURE__ */ new Map();
|
|
453
|
-
TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
|
|
454
|
-
if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) {
|
|
455
|
-
return void 0;
|
|
456
|
-
}
|
|
457
|
-
const barrelFile = {
|
|
458
|
-
path: join(treeNode.parent?.data.path, "index.ts"),
|
|
459
|
-
baseName: "index.ts",
|
|
460
|
-
exports: [],
|
|
461
|
-
sources: []
|
|
462
|
-
};
|
|
463
|
-
const previousBarrelFile = cachedFiles.get(barrelFile.path);
|
|
464
|
-
const leaves = treeNode.leaves;
|
|
465
|
-
leaves.forEach((item) => {
|
|
466
|
-
if (!item.data.name) {
|
|
467
|
-
return void 0;
|
|
468
|
-
}
|
|
469
|
-
const sources = item.data.file?.sources || [];
|
|
470
|
-
if (!sources.some((source) => source.isIndexable)) {
|
|
471
|
-
logger?.emit(
|
|
472
|
-
"warning",
|
|
473
|
-
`No isIndexable source found(source should have a name and isIndexable):
|
|
474
|
-
File: ${JSON.stringify(item.data.file, void 0, 2)}`
|
|
475
|
-
);
|
|
476
|
-
}
|
|
477
|
-
sources.forEach((source) => {
|
|
478
|
-
if (!item.data.file?.path || !source.isIndexable || !source.name) {
|
|
479
|
-
return void 0;
|
|
480
|
-
}
|
|
481
|
-
const alreadyContainInPreviousBarrelFile = previousBarrelFile?.sources.some(
|
|
482
|
-
(item2) => item2.name === source.name && item2.isTypeOnly === source.isTypeOnly
|
|
483
|
-
);
|
|
484
|
-
if (alreadyContainInPreviousBarrelFile) {
|
|
485
|
-
return void 0;
|
|
486
|
-
}
|
|
487
|
-
if (!barrelFile.exports) {
|
|
488
|
-
barrelFile.exports = [];
|
|
489
|
-
}
|
|
490
|
-
const isSubExport = !!treeNode.parent?.data.path?.split?.("/")?.length;
|
|
491
|
-
if (isSubExport) {
|
|
492
|
-
barrelFile.exports.push({
|
|
493
|
-
name: [source.name],
|
|
494
|
-
path: getRelativePath(treeNode.parent?.data.path, item.data.path),
|
|
495
|
-
isTypeOnly: source.isTypeOnly
|
|
496
|
-
});
|
|
497
|
-
} else {
|
|
498
|
-
barrelFile.exports.push({
|
|
499
|
-
name: [source.name],
|
|
500
|
-
path: `./${item.data.file.baseName}`,
|
|
501
|
-
isTypeOnly: source.isTypeOnly
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
barrelFile.sources.push({
|
|
505
|
-
name: source.name,
|
|
506
|
-
isTypeOnly: source.isTypeOnly,
|
|
507
|
-
//TODO use parser to generate import
|
|
508
|
-
value: "",
|
|
509
|
-
isExportable: false,
|
|
510
|
-
isIndexable: false
|
|
511
|
-
});
|
|
512
|
-
});
|
|
513
|
-
});
|
|
514
|
-
if (previousBarrelFile) {
|
|
515
|
-
previousBarrelFile.sources.push(...barrelFile.sources);
|
|
516
|
-
previousBarrelFile.exports?.push(...barrelFile.exports || []);
|
|
517
|
-
} else {
|
|
518
|
-
cachedFiles.set(barrelFile.path, barrelFile);
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
return [...cachedFiles.values()];
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
|
|
525
|
-
// src/utils/Cache.ts
|
|
526
|
-
var Cache = class {
|
|
527
|
-
#buffer = /* @__PURE__ */ new Map();
|
|
528
|
-
async get(key) {
|
|
529
|
-
return this.#buffer.get(key) ?? null;
|
|
530
|
-
}
|
|
531
|
-
async set(key, value) {
|
|
532
|
-
this.#buffer.set(key, value);
|
|
533
|
-
}
|
|
534
|
-
async delete(key) {
|
|
535
|
-
this.#buffer.delete(key);
|
|
536
|
-
}
|
|
537
|
-
async clear() {
|
|
538
|
-
this.#buffer.clear();
|
|
539
|
-
}
|
|
540
|
-
async keys() {
|
|
541
|
-
return [...this.#buffer.keys()];
|
|
542
|
-
}
|
|
543
|
-
async values() {
|
|
544
|
-
return [...this.#buffer.values()];
|
|
545
|
-
}
|
|
546
|
-
async flush() {
|
|
547
|
-
}
|
|
548
|
-
};
|
|
549
|
-
|
|
550
|
-
// src/FileManager.ts
|
|
551
|
-
var FileManager = class {
|
|
552
|
-
#cache = new Cache();
|
|
553
|
-
#limit = pLimit(100);
|
|
554
|
-
constructor() {
|
|
555
|
-
return this;
|
|
556
|
-
}
|
|
557
|
-
async add(...files) {
|
|
558
|
-
const resolvedFiles = [];
|
|
559
|
-
const mergedFiles = /* @__PURE__ */ new Map();
|
|
560
|
-
files.forEach((file) => {
|
|
561
|
-
const existing = mergedFiles.get(file.path);
|
|
562
|
-
if (existing) {
|
|
563
|
-
mergedFiles.set(file.path, mergeFile(existing, file));
|
|
564
|
-
} else {
|
|
565
|
-
mergedFiles.set(file.path, file);
|
|
566
|
-
}
|
|
567
|
-
});
|
|
568
|
-
for (const file of mergedFiles.values()) {
|
|
569
|
-
const existing = await this.#cache.get(file.path);
|
|
570
|
-
const merged = existing ? mergeFile(existing, file) : file;
|
|
571
|
-
const resolvedFile = createFile(merged);
|
|
572
|
-
await this.#cache.set(resolvedFile.path, resolvedFile);
|
|
573
|
-
await this.#cache.flush();
|
|
574
|
-
resolvedFiles.push(resolvedFile);
|
|
575
|
-
}
|
|
576
|
-
if (files.length > 1) {
|
|
577
|
-
return resolvedFiles;
|
|
578
|
-
}
|
|
579
|
-
return resolvedFiles[0];
|
|
580
|
-
}
|
|
581
|
-
async getByPath(path2) {
|
|
582
|
-
return this.#cache.get(path2);
|
|
583
|
-
}
|
|
584
|
-
async deleteByPath(path2) {
|
|
585
|
-
await this.#cache.delete(path2);
|
|
586
|
-
}
|
|
587
|
-
async clear() {
|
|
588
|
-
await this.#cache.clear();
|
|
589
|
-
}
|
|
590
|
-
async getFiles() {
|
|
591
|
-
const cachedKeys = await this.#cache.keys();
|
|
592
|
-
const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith("index")]);
|
|
593
|
-
const filesTasks = keys.map(
|
|
594
|
-
(key) => this.#limit(async () => {
|
|
595
|
-
const file = await this.#cache.get(key);
|
|
596
|
-
return file;
|
|
597
|
-
})
|
|
598
|
-
);
|
|
599
|
-
const files = await Promise.all(filesTasks);
|
|
600
|
-
return files.filter(Boolean);
|
|
601
|
-
}
|
|
602
|
-
async processFiles({ dryRun, root, extension, logger }) {
|
|
603
|
-
const files = await this.getFiles();
|
|
604
|
-
logger?.emit("progress_start", { id: "files", size: files.length, message: "Writing files ..." });
|
|
605
|
-
const promises = files.map((file) => {
|
|
606
|
-
return this.#limit(async () => {
|
|
607
|
-
const message = file ? `Writing ${relative(root, file.path)}` : "";
|
|
608
|
-
const extname2 = extension?.[file.extname] || void 0;
|
|
609
|
-
if (!dryRun) {
|
|
610
|
-
const source = await getSource(file, { logger, extname: extname2 });
|
|
611
|
-
await write(file.path, source, { sanity: false });
|
|
612
|
-
}
|
|
613
|
-
logger?.emit("progressed", { id: "files", message });
|
|
614
|
-
});
|
|
615
|
-
});
|
|
616
|
-
await Promise.all(promises);
|
|
617
|
-
logger?.emit("progress_stop", { id: "files" });
|
|
618
|
-
return files;
|
|
619
|
-
}
|
|
620
|
-
async getBarrelFiles({ type, meta = {}, root, output, logger }) {
|
|
621
|
-
if (!type || type === "propagate") {
|
|
622
|
-
return [];
|
|
623
|
-
}
|
|
624
|
-
const barrelManager = new BarrelManager({ logger });
|
|
625
|
-
const files = await this.getFiles();
|
|
626
|
-
const pathToBuildFrom = join(root, output.path);
|
|
627
|
-
if (trimExtName(pathToBuildFrom).endsWith("index")) {
|
|
628
|
-
logger?.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
|
|
629
|
-
return [];
|
|
630
|
-
}
|
|
631
|
-
const barrelFiles = barrelManager.getFiles({ files, root: pathToBuildFrom, meta });
|
|
632
|
-
if (type === "all") {
|
|
633
|
-
return barrelFiles.map((file) => {
|
|
634
|
-
return {
|
|
635
|
-
...file,
|
|
636
|
-
exports: file.exports?.map((exportItem) => {
|
|
637
|
-
return {
|
|
638
|
-
...exportItem,
|
|
639
|
-
name: void 0
|
|
640
|
-
};
|
|
641
|
-
})
|
|
642
|
-
};
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
return barrelFiles.map((indexFile) => {
|
|
646
|
-
return {
|
|
647
|
-
...indexFile,
|
|
648
|
-
meta
|
|
649
|
-
};
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
// statics
|
|
653
|
-
static getMode(path2) {
|
|
654
|
-
if (!path2) {
|
|
655
|
-
return "split";
|
|
656
|
-
}
|
|
657
|
-
return extname(path2) ? "single" : "split";
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
async function getSource(file, { logger, extname: extname2 } = {}) {
|
|
661
|
-
const parser = await getFileParser(file.extname);
|
|
662
|
-
const source = await parser.print(file, { logger, extname: extname2 });
|
|
663
|
-
return parser.format(source).catch((err) => {
|
|
664
|
-
console.warn(err);
|
|
665
|
-
return source;
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
function mergeFile(a, b) {
|
|
669
|
-
return {
|
|
670
|
-
...a,
|
|
671
|
-
sources: [...a.sources || [], ...b.sources || []],
|
|
672
|
-
imports: [...a.imports || [], ...b.imports || []],
|
|
673
|
-
exports: [...a.exports || [], ...b.exports || []]
|
|
674
|
-
};
|
|
675
|
-
}
|
|
676
|
-
function combineSources(sources) {
|
|
677
|
-
return uniqueBy(sources, (obj) => [obj.name, obj.isExportable, obj.isTypeOnly]);
|
|
678
|
-
}
|
|
679
|
-
function combineExports(exports) {
|
|
680
|
-
return orderBy(exports, [
|
|
681
|
-
(v) => !!Array.isArray(v.name),
|
|
682
|
-
(v) => !v.isTypeOnly,
|
|
683
|
-
(v) => v.path,
|
|
684
|
-
(v) => !!v.name,
|
|
685
|
-
(v) => Array.isArray(v.name) ? orderBy(v.name) : v.name
|
|
686
|
-
]).reduce(
|
|
687
|
-
(prev, curr) => {
|
|
688
|
-
const name = curr.name;
|
|
689
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
690
|
-
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly);
|
|
691
|
-
if (prevByPathAndIsTypeOnly) {
|
|
692
|
-
return prev;
|
|
693
|
-
}
|
|
694
|
-
const uniquePrev = prev.findLast(
|
|
695
|
-
(imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
696
|
-
);
|
|
697
|
-
if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
|
|
698
|
-
return prev;
|
|
699
|
-
}
|
|
700
|
-
if (!prevByPath) {
|
|
701
|
-
return [
|
|
702
|
-
...prev,
|
|
703
|
-
{
|
|
704
|
-
...curr,
|
|
705
|
-
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
706
|
-
}
|
|
707
|
-
];
|
|
708
|
-
}
|
|
709
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
710
|
-
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
|
|
711
|
-
return prev;
|
|
712
|
-
}
|
|
713
|
-
return [...prev, curr];
|
|
714
|
-
},
|
|
715
|
-
[]
|
|
716
|
-
);
|
|
717
|
-
}
|
|
718
|
-
function combineImports(imports, exports, source) {
|
|
719
|
-
return orderBy(imports, [
|
|
720
|
-
(v) => !!Array.isArray(v.name),
|
|
721
|
-
(v) => !v.isTypeOnly,
|
|
722
|
-
(v) => v.path,
|
|
723
|
-
(v) => !!v.name,
|
|
724
|
-
(v) => Array.isArray(v.name) ? orderBy(v.name) : v.name
|
|
725
|
-
]).reduce(
|
|
726
|
-
(prev, curr) => {
|
|
727
|
-
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
728
|
-
const hasImportInSource = (importName) => {
|
|
729
|
-
if (!source) {
|
|
730
|
-
return true;
|
|
731
|
-
}
|
|
732
|
-
const checker = (name2) => {
|
|
733
|
-
return name2 && source.includes(name2);
|
|
734
|
-
};
|
|
735
|
-
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
736
|
-
};
|
|
737
|
-
if (curr.path === curr.root) {
|
|
738
|
-
return prev;
|
|
739
|
-
}
|
|
740
|
-
if (Array.isArray(name)) {
|
|
741
|
-
name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
|
|
742
|
-
}
|
|
743
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
744
|
-
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
745
|
-
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly);
|
|
746
|
-
if (prevByPathNameAndIsTypeOnly) {
|
|
747
|
-
return prev;
|
|
748
|
-
}
|
|
749
|
-
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
750
|
-
return prev;
|
|
751
|
-
}
|
|
752
|
-
if (!prevByPath) {
|
|
753
|
-
return [
|
|
754
|
-
...prev,
|
|
755
|
-
{
|
|
756
|
-
...curr,
|
|
757
|
-
name
|
|
758
|
-
}
|
|
759
|
-
];
|
|
760
|
-
}
|
|
761
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
762
|
-
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
|
|
763
|
-
return prev;
|
|
764
|
-
}
|
|
765
|
-
if (!Array.isArray(name) && name && !hasImportInSource(name)) {
|
|
766
|
-
return prev;
|
|
767
|
-
}
|
|
768
|
-
return [...prev, curr];
|
|
769
|
-
},
|
|
770
|
-
[]
|
|
771
|
-
);
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
// src/utils/parser.ts
|
|
775
|
-
function getDefaultBanner({ title, description, version, config }) {
|
|
776
|
-
try {
|
|
777
|
-
let source = "";
|
|
778
|
-
if ("path" in config.input) {
|
|
779
|
-
source = path.basename(config.input.path);
|
|
780
|
-
} else if ("data" in config.input) {
|
|
781
|
-
source = "text content";
|
|
782
|
-
}
|
|
783
|
-
let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
|
|
784
|
-
if (config.output.defaultBanner === "simple") {
|
|
785
|
-
banner += "*/\n";
|
|
786
|
-
return banner;
|
|
787
|
-
}
|
|
788
|
-
if (source) {
|
|
789
|
-
banner += `* Source: ${source}
|
|
790
|
-
`;
|
|
791
|
-
}
|
|
792
|
-
if (title) {
|
|
793
|
-
banner += `* Title: ${title}
|
|
794
|
-
`;
|
|
795
|
-
}
|
|
796
|
-
if (description) {
|
|
797
|
-
const formattedDescription = description.replace(/\n/gm, "\n* ");
|
|
798
|
-
banner += `* Description: ${formattedDescription}
|
|
799
|
-
`;
|
|
800
|
-
}
|
|
801
|
-
if (version) {
|
|
802
|
-
banner += `* OpenAPI spec version: ${version}
|
|
803
|
-
`;
|
|
804
|
-
}
|
|
805
|
-
banner += "*/\n";
|
|
806
|
-
return banner;
|
|
807
|
-
} catch (_error) {
|
|
808
|
-
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
function createFile(file) {
|
|
812
|
-
const extname2 = path.extname(file.baseName);
|
|
813
|
-
if (!extname2) {
|
|
814
|
-
throw new Error(`No extname found for ${file.baseName}`);
|
|
815
|
-
}
|
|
816
|
-
const source = file.sources.map((item) => item.value).join("\n\n");
|
|
817
|
-
const exports = file.exports?.length ? combineExports(file.exports) : [];
|
|
818
|
-
const imports = file.imports?.length && source ? combineImports(file.imports, exports, source) : [];
|
|
819
|
-
const sources = file.sources?.length ? combineSources(file.sources) : [];
|
|
820
|
-
return {
|
|
821
|
-
...file,
|
|
822
|
-
id: hash({ path: file.path }),
|
|
823
|
-
name: trimExtName2(file.baseName),
|
|
824
|
-
extname: extname2,
|
|
825
|
-
imports: imports.map(createFileImport),
|
|
826
|
-
exports: exports.map(createFileExport),
|
|
827
|
-
sources: sources.map(createFileSource),
|
|
828
|
-
meta: file.meta || {}
|
|
829
|
-
};
|
|
830
|
-
}
|
|
831
|
-
function createFileSource(source) {
|
|
832
|
-
return source;
|
|
833
|
-
}
|
|
834
|
-
function createFileImport(imp) {
|
|
835
|
-
return {
|
|
836
|
-
...imp
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
function createFileExport(exp) {
|
|
840
|
-
return {
|
|
841
|
-
...exp
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
function createFileParser(parser) {
|
|
845
|
-
return parser;
|
|
846
|
-
}
|
|
847
|
-
var typeScriptParser = createFileParser({
|
|
848
|
-
async format(source) {
|
|
849
|
-
const module = await import('@kubb/parser-ts');
|
|
850
|
-
return module.format(source);
|
|
851
|
-
},
|
|
852
|
-
async print(file, options = { extname: ".ts" }) {
|
|
853
|
-
const module = await import('@kubb/parser-ts');
|
|
854
|
-
const source = file.sources.map((item) => item.value).join("\n\n");
|
|
855
|
-
const importNodes = file.imports.map((item) => {
|
|
856
|
-
const importPath = item.root ? getRelativePath(item.root, item.path) : item.path;
|
|
857
|
-
const hasExtname = !!path.extname(importPath);
|
|
858
|
-
return module.factory.createImportDeclaration({
|
|
859
|
-
name: item.name,
|
|
860
|
-
path: options.extname && hasExtname ? `${trimExtName2(importPath)}${options.extname}` : item.root ? trimExtName2(importPath) : importPath,
|
|
861
|
-
isTypeOnly: item.isTypeOnly
|
|
862
|
-
});
|
|
863
|
-
}).filter(Boolean);
|
|
864
|
-
const exportNodes = file.exports.map((item) => {
|
|
865
|
-
const exportPath = item.path;
|
|
866
|
-
const hasExtname = !!path.extname(exportPath);
|
|
867
|
-
return module.factory.createExportDeclaration({
|
|
868
|
-
name: item.name,
|
|
869
|
-
path: options.extname && hasExtname ? `${trimExtName2(item.path)}${options.extname}` : trimExtName2(item.path),
|
|
870
|
-
isTypeOnly: item.isTypeOnly,
|
|
871
|
-
asAlias: item.asAlias
|
|
872
|
-
});
|
|
873
|
-
}).filter(Boolean);
|
|
874
|
-
return [file.banner, module.print([...importNodes, ...exportNodes]), source, file.footer].join("\n");
|
|
875
|
-
}
|
|
876
|
-
});
|
|
877
|
-
var tsxParser = createFileParser({
|
|
878
|
-
async format(source) {
|
|
879
|
-
const module = await import('@kubb/parser-ts');
|
|
880
|
-
return module.format(source);
|
|
881
|
-
},
|
|
882
|
-
async print(file, options = { extname: ".tsx" }) {
|
|
883
|
-
return typeScriptParser.print(file, options);
|
|
884
|
-
}
|
|
885
|
-
});
|
|
886
|
-
var defaultParser = createFileParser({
|
|
887
|
-
async format(source) {
|
|
888
|
-
return source;
|
|
889
|
-
},
|
|
890
|
-
async print(file) {
|
|
891
|
-
return file.sources.map((item) => item.value).join("\n\n");
|
|
892
|
-
}
|
|
893
|
-
});
|
|
894
|
-
var parsers = {
|
|
895
|
-
".ts": typeScriptParser,
|
|
896
|
-
".js": typeScriptParser,
|
|
897
|
-
".jsx": tsxParser,
|
|
898
|
-
".tsx": tsxParser,
|
|
899
|
-
".json": defaultParser
|
|
900
|
-
};
|
|
901
|
-
async function getFileParser(extname2) {
|
|
902
|
-
if (!extname2) {
|
|
903
|
-
return defaultParser;
|
|
904
|
-
}
|
|
905
|
-
const parser = parsers[extname2];
|
|
906
|
-
if (!parser) {
|
|
907
|
-
console.warn(`[parser] No parser found for ${extname2}, default parser will be used`);
|
|
908
|
-
}
|
|
909
|
-
return parser || defaultParser;
|
|
910
|
-
}
|
|
911
|
-
function trimExtName2(text) {
|
|
912
|
-
const extname2 = text.split(".").pop();
|
|
913
|
-
return text.replace(`.${extname2}`, "");
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
export { Cache, FileManager, FunctionParams, URLPath, createFile, createFileExport, createFileImport, createFileParser, getDefaultBanner, getFileParser, getSource, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout };
|
|
917
|
-
//# sourceMappingURL=chunk-CAZ37TGB.js.map
|
|
918
|
-
//# sourceMappingURL=chunk-CAZ37TGB.js.map
|