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