@kubb/core 3.0.0-alpha.5 → 3.0.0-alpha.6
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-tzl0YsYE.d.ts → FileManager-Ceski1W9.d.ts} +46 -33
- package/dist/{FileManager-jZpqETKU.d.cts → FileManager-wyXRkgIk.d.cts} +46 -33
- package/dist/chunk-2EU7DMPM.js +97 -0
- package/dist/chunk-2EU7DMPM.js.map +1 -0
- package/dist/chunk-5HN4LW3R.cjs +102 -0
- package/dist/chunk-5HN4LW3R.cjs.map +1 -0
- package/dist/{chunk-Z5CHJQJB.js → chunk-76UEJFFE.js} +1 -4
- package/dist/chunk-76UEJFFE.js.map +1 -0
- package/dist/{chunk-5JZNFPUP.js → chunk-AWAZR3D5.js} +61 -10
- package/dist/chunk-AWAZR3D5.js.map +1 -0
- package/dist/{chunk-FWU62YO5.cjs → chunk-DCZQYCCO.cjs} +216 -326
- package/dist/chunk-DCZQYCCO.cjs.map +1 -0
- package/dist/{chunk-YTSNYMHW.cjs → chunk-L3JJLZ5Q.cjs} +62 -11
- package/dist/chunk-L3JJLZ5Q.cjs.map +1 -0
- package/dist/{chunk-RBP2ASUX.cjs → chunk-LOLEBOMW.cjs} +1 -4
- package/dist/chunk-LOLEBOMW.cjs.map +1 -0
- package/dist/chunk-RIEGCND2.js +525 -0
- package/dist/chunk-RIEGCND2.js.map +1 -0
- package/dist/index.cjs +80 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -6
- package/dist/index.d.ts +4 -6
- package/dist/index.js +67 -58
- package/dist/index.js.map +1 -1
- package/dist/{logger-BnWJh6Yq.d.cts → logger-BWFeedRk.d.cts} +15 -5
- package/dist/{logger-BnWJh6Yq.d.ts → logger-BWFeedRk.d.ts} +15 -5
- package/dist/logger.cjs +2 -2
- package/dist/logger.d.cts +1 -2
- package/dist/logger.d.ts +1 -2
- package/dist/logger.js +1 -1
- package/dist/mocks.cjs +4 -6
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +3 -5
- package/dist/mocks.d.ts +3 -5
- package/dist/mocks.js +3 -5
- package/dist/mocks.js.map +1 -1
- package/dist/transformers.cjs +189 -33
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.d.cts +1 -3
- package/dist/transformers.d.ts +1 -3
- package/dist/transformers.js +156 -14
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +6 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +30 -3
- package/dist/utils.d.ts +30 -3
- package/dist/utils.js +7 -3
- package/package.json +9 -8
- package/src/BarrelManager.ts +24 -99
- package/src/FileManager.ts +156 -281
- package/src/PackageManager.ts +1 -1
- package/src/PluginManager.ts +89 -57
- package/src/build.ts +6 -19
- package/src/logger.ts +6 -8
- package/src/transformers/index.ts +2 -3
- package/src/transformers/trim.ts +0 -4
- package/src/types.ts +1 -1
- package/src/utils/TreeNode.ts +91 -26
- package/src/utils/executeStrategies.ts +1 -1
- package/src/utils/index.ts +2 -1
- package/src/utils/parser.ts +96 -0
- package/dist/chunk-5JZNFPUP.js.map +0 -1
- package/dist/chunk-CEWT73XF.js +0 -637
- package/dist/chunk-CEWT73XF.js.map +0 -1
- package/dist/chunk-FWU62YO5.cjs.map +0 -1
- package/dist/chunk-JKZG2IJR.js +0 -283
- package/dist/chunk-JKZG2IJR.js.map +0 -1
- package/dist/chunk-PZT4CTBV.cjs +0 -299
- package/dist/chunk-PZT4CTBV.cjs.map +0 -1
- package/dist/chunk-RBP2ASUX.cjs.map +0 -1
- package/dist/chunk-YTSNYMHW.cjs.map +0 -1
- package/dist/chunk-Z5CHJQJB.js.map +0 -1
- package/src/utils/getParser.ts +0 -17
package/dist/chunk-CEWT73XF.js
DELETED
|
@@ -1,637 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
searchAndReplace,
|
|
3
|
-
transformers_default,
|
|
4
|
-
trimExtName
|
|
5
|
-
} from "./chunk-JKZG2IJR.js";
|
|
6
|
-
import {
|
|
7
|
-
getParser
|
|
8
|
-
} from "./chunk-5JZNFPUP.js";
|
|
9
|
-
import {
|
|
10
|
-
orderBy
|
|
11
|
-
} from "./chunk-4X5FFJPJ.js";
|
|
12
|
-
import {
|
|
13
|
-
__privateAdd,
|
|
14
|
-
__privateGet,
|
|
15
|
-
__privateMethod,
|
|
16
|
-
__privateSet
|
|
17
|
-
} from "./chunk-HMLY7DHA.js";
|
|
18
|
-
|
|
19
|
-
// src/FileManager.ts
|
|
20
|
-
import crypto from "crypto";
|
|
21
|
-
import path2, { extname, resolve } from "path";
|
|
22
|
-
import { isDeepEqual } from "remeda";
|
|
23
|
-
import { getRelativePath, read, write } from "@kubb/fs";
|
|
24
|
-
|
|
25
|
-
// src/BarrelManager.ts
|
|
26
|
-
import { getExports } from "@kubb/parser-ts";
|
|
27
|
-
import path from "path";
|
|
28
|
-
|
|
29
|
-
// src/utils/TreeNode.ts
|
|
30
|
-
import dirTree from "directory-tree";
|
|
31
|
-
var TreeNode = class _TreeNode {
|
|
32
|
-
constructor(data, parent) {
|
|
33
|
-
this.children = [];
|
|
34
|
-
this.data = data;
|
|
35
|
-
this.parent = parent;
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
addChild(data) {
|
|
39
|
-
const child = new _TreeNode(data, this);
|
|
40
|
-
if (!this.children) {
|
|
41
|
-
this.children = [];
|
|
42
|
-
}
|
|
43
|
-
this.children.push(child);
|
|
44
|
-
return child;
|
|
45
|
-
}
|
|
46
|
-
find(data) {
|
|
47
|
-
if (!data) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
if (data === this.data) {
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
if (this.children?.length) {
|
|
54
|
-
for (let i = 0, { length } = this.children, target = null; i < length; i++) {
|
|
55
|
-
target = this.children[i].find(data);
|
|
56
|
-
if (target) {
|
|
57
|
-
return target;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
get leaves() {
|
|
64
|
-
if (!this.children || this.children.length === 0) {
|
|
65
|
-
return [this];
|
|
66
|
-
}
|
|
67
|
-
const leaves = [];
|
|
68
|
-
if (this.children) {
|
|
69
|
-
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
70
|
-
leaves.push.apply(leaves, this.children[i].leaves);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return leaves;
|
|
74
|
-
}
|
|
75
|
-
get root() {
|
|
76
|
-
if (!this.parent) {
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
return this.parent.root;
|
|
80
|
-
}
|
|
81
|
-
forEach(callback) {
|
|
82
|
-
if (typeof callback !== "function") {
|
|
83
|
-
throw new TypeError("forEach() callback must be a function");
|
|
84
|
-
}
|
|
85
|
-
callback(this);
|
|
86
|
-
if (this.children) {
|
|
87
|
-
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
88
|
-
this.children[i]?.forEach(callback);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
static build(path3, options = {}) {
|
|
94
|
-
try {
|
|
95
|
-
const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
|
|
96
|
-
const filteredTree = dirTree(path3, {
|
|
97
|
-
extensions: options.extensions,
|
|
98
|
-
exclude: [/node_modules/, ...exclude]
|
|
99
|
-
});
|
|
100
|
-
if (!filteredTree) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
const treeNode = new _TreeNode({
|
|
104
|
-
name: filteredTree.name,
|
|
105
|
-
path: filteredTree.path,
|
|
106
|
-
type: FileManager.getMode(filteredTree.path)
|
|
107
|
-
});
|
|
108
|
-
const recurse = (node, item) => {
|
|
109
|
-
const subNode = node.addChild({
|
|
110
|
-
name: item.name,
|
|
111
|
-
path: item.path,
|
|
112
|
-
type: FileManager.getMode(item.path)
|
|
113
|
-
});
|
|
114
|
-
if (item.children?.length) {
|
|
115
|
-
item.children?.forEach((child) => {
|
|
116
|
-
recurse(subNode, child);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
filteredTree.children?.forEach((child) => recurse(treeNode, child));
|
|
121
|
-
return treeNode;
|
|
122
|
-
} catch (e) {
|
|
123
|
-
throw new Error("Something went wrong with creating index files with the TreehNode class", { cause: e });
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
// src/BarrelManager.ts
|
|
129
|
-
var _options;
|
|
130
|
-
var BarrelManager = class {
|
|
131
|
-
constructor(options = {}) {
|
|
132
|
-
__privateAdd(this, _options);
|
|
133
|
-
__privateSet(this, _options, options);
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Loop through the file and find all exports(with the help of the ts printer)
|
|
138
|
-
* Important: a real file is needed(cannot work from memory/FileManager)
|
|
139
|
-
*/
|
|
140
|
-
getNamedExport(root, item) {
|
|
141
|
-
const exportedNames = getExports(path.resolve(root, item.path));
|
|
142
|
-
if (!exportedNames) {
|
|
143
|
-
return [item];
|
|
144
|
-
}
|
|
145
|
-
const exports = exportedNames.reduce(
|
|
146
|
-
(prev, curr) => {
|
|
147
|
-
if (!prev[0]?.name || !prev[1]?.name) {
|
|
148
|
-
return prev;
|
|
149
|
-
}
|
|
150
|
-
if (curr.isTypeOnly) {
|
|
151
|
-
prev[1] = { ...prev[1], name: [...prev[1].name, curr.name] };
|
|
152
|
-
} else {
|
|
153
|
-
prev[0] = { ...prev[0], name: [...prev[0].name, curr.name] };
|
|
154
|
-
}
|
|
155
|
-
return prev;
|
|
156
|
-
},
|
|
157
|
-
[
|
|
158
|
-
{
|
|
159
|
-
...item,
|
|
160
|
-
name: [],
|
|
161
|
-
isTypeOnly: false
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
...item,
|
|
165
|
-
name: [],
|
|
166
|
-
isTypeOnly: true
|
|
167
|
-
}
|
|
168
|
-
]
|
|
169
|
-
);
|
|
170
|
-
return exports;
|
|
171
|
-
}
|
|
172
|
-
getNamedExports(root, exports) {
|
|
173
|
-
return exports?.flatMap((item) => {
|
|
174
|
-
return this.getNamedExport(root, item);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
getIndexes(root) {
|
|
178
|
-
const { treeNode = {}, isTypeOnly, extName } = __privateGet(this, _options);
|
|
179
|
-
const tree = TreeNode.build(root, treeNode);
|
|
180
|
-
if (!tree) {
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
const fileReducer = (files, treeNode2) => {
|
|
184
|
-
if (!treeNode2.children) {
|
|
185
|
-
return [];
|
|
186
|
-
}
|
|
187
|
-
if (treeNode2.children.length > 1) {
|
|
188
|
-
const indexPath = path.resolve(treeNode2.data.path, "index.ts");
|
|
189
|
-
const exports = treeNode2.children.filter(Boolean).map((file) => {
|
|
190
|
-
const importPath = file.data.type === "split" ? `./${file.data.name}/index` : `./${trimExtName(file.data.name)}`;
|
|
191
|
-
if (importPath.endsWith("index") && file.data.type === "single") {
|
|
192
|
-
return void 0;
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
path: extName ? `${importPath}${extName}` : importPath,
|
|
196
|
-
isTypeOnly
|
|
197
|
-
};
|
|
198
|
-
}).filter(Boolean);
|
|
199
|
-
files.push({
|
|
200
|
-
path: indexPath,
|
|
201
|
-
baseName: "index.ts",
|
|
202
|
-
source: "",
|
|
203
|
-
exports,
|
|
204
|
-
exportable: true
|
|
205
|
-
});
|
|
206
|
-
} else if (treeNode2.children.length === 1) {
|
|
207
|
-
const [treeNodeChild] = treeNode2.children;
|
|
208
|
-
const indexPath = path.resolve(treeNode2.data.path, "index.ts");
|
|
209
|
-
const importPath = treeNodeChild.data.type === "split" ? `./${treeNodeChild.data.name}/index` : `./${trimExtName(treeNodeChild.data.name)}`;
|
|
210
|
-
const exports = [
|
|
211
|
-
{
|
|
212
|
-
path: extName ? `${importPath}${extName}` : importPath,
|
|
213
|
-
isTypeOnly
|
|
214
|
-
}
|
|
215
|
-
];
|
|
216
|
-
files.push({
|
|
217
|
-
path: indexPath,
|
|
218
|
-
baseName: "index.ts",
|
|
219
|
-
source: "",
|
|
220
|
-
exports,
|
|
221
|
-
exportable: true
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
treeNode2.children.forEach((childItem) => {
|
|
225
|
-
fileReducer(files, childItem);
|
|
226
|
-
});
|
|
227
|
-
return files;
|
|
228
|
-
};
|
|
229
|
-
return fileReducer([], tree).reverse();
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
_options = new WeakMap();
|
|
233
|
-
|
|
234
|
-
// src/FileManager.ts
|
|
235
|
-
import PQueue from "p-queue";
|
|
236
|
-
var _cache, _FileManager_instances, add_fn, addOrAppend_fn;
|
|
237
|
-
var _FileManager = class _FileManager {
|
|
238
|
-
constructor() {
|
|
239
|
-
__privateAdd(this, _FileManager_instances);
|
|
240
|
-
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
241
|
-
return this;
|
|
242
|
-
}
|
|
243
|
-
get files() {
|
|
244
|
-
const files = [];
|
|
245
|
-
__privateGet(this, _cache).forEach((item) => {
|
|
246
|
-
files.push(...item.flat(1));
|
|
247
|
-
});
|
|
248
|
-
return files;
|
|
249
|
-
}
|
|
250
|
-
async add(...files) {
|
|
251
|
-
const promises = combineFiles(files).map((file) => {
|
|
252
|
-
if (file.override) {
|
|
253
|
-
return __privateMethod(this, _FileManager_instances, add_fn).call(this, file);
|
|
254
|
-
}
|
|
255
|
-
return __privateMethod(this, _FileManager_instances, addOrAppend_fn).call(this, file);
|
|
256
|
-
});
|
|
257
|
-
const resolvedFiles = await Promise.all(promises);
|
|
258
|
-
if (files.length > 1) {
|
|
259
|
-
return resolvedFiles;
|
|
260
|
-
}
|
|
261
|
-
return resolvedFiles[0];
|
|
262
|
-
}
|
|
263
|
-
async getIndexFiles({ plugin, root, output, logger, options = {} }) {
|
|
264
|
-
const { exportType = "barrel" } = output;
|
|
265
|
-
if (exportType === false) {
|
|
266
|
-
return [];
|
|
267
|
-
}
|
|
268
|
-
const pathToBuildFrom = resolve(root, output.path);
|
|
269
|
-
if (transformers_default.trimExtName(pathToBuildFrom).endsWith("index")) {
|
|
270
|
-
logger.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
|
|
271
|
-
return [];
|
|
272
|
-
}
|
|
273
|
-
const exportPath = output.path.startsWith("./") ? trimExtName(output.path) : `./${trimExtName(output.path)}`;
|
|
274
|
-
const mode = _FileManager.getMode(output.path);
|
|
275
|
-
const barrelManager = new BarrelManager({
|
|
276
|
-
extName: output.extName,
|
|
277
|
-
...options
|
|
278
|
-
});
|
|
279
|
-
let files = barrelManager.getIndexes(pathToBuildFrom);
|
|
280
|
-
if (!files) {
|
|
281
|
-
return [];
|
|
282
|
-
}
|
|
283
|
-
const rootPath = mode === "split" ? `${exportPath}/index${output.extName || ""}` : `${exportPath}${output.extName || ""}`;
|
|
284
|
-
const rootFile = {
|
|
285
|
-
path: resolve(root, "index.ts"),
|
|
286
|
-
baseName: "index.ts",
|
|
287
|
-
source: "",
|
|
288
|
-
exports: [
|
|
289
|
-
output.exportAs ? {
|
|
290
|
-
name: output.exportAs,
|
|
291
|
-
asAlias: true,
|
|
292
|
-
path: rootPath,
|
|
293
|
-
isTypeOnly: options.isTypeOnly
|
|
294
|
-
} : {
|
|
295
|
-
path: rootPath,
|
|
296
|
-
isTypeOnly: options.isTypeOnly
|
|
297
|
-
}
|
|
298
|
-
],
|
|
299
|
-
exportable: true
|
|
300
|
-
};
|
|
301
|
-
if (exportType === "barrelNamed") {
|
|
302
|
-
files = files.map((file) => {
|
|
303
|
-
if (file.exports) {
|
|
304
|
-
return {
|
|
305
|
-
...file,
|
|
306
|
-
exports: barrelManager.getNamedExports(pathToBuildFrom, file.exports)
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
return file;
|
|
310
|
-
});
|
|
311
|
-
const barrelExportRoot = rootFile.exports?.[0];
|
|
312
|
-
if (!output.exportAs && barrelExportRoot) {
|
|
313
|
-
const exportFile = files.find((file) => {
|
|
314
|
-
return trimExtName(file.path) === path2.resolve(root, barrelExportRoot.path);
|
|
315
|
-
});
|
|
316
|
-
if (exportFile?.exports) {
|
|
317
|
-
rootFile.exports = exportFile.exports.map((exportItem) => {
|
|
318
|
-
return {
|
|
319
|
-
...exportItem,
|
|
320
|
-
path: getRelativePath(rootFile.path, exportFile.path)
|
|
321
|
-
};
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return [
|
|
327
|
-
...await Promise.all(
|
|
328
|
-
files.map((file) => {
|
|
329
|
-
return __privateMethod(this, _FileManager_instances, addOrAppend_fn).call(this, {
|
|
330
|
-
...file,
|
|
331
|
-
meta: {
|
|
332
|
-
pluginKey: plugin.key
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
})
|
|
336
|
-
),
|
|
337
|
-
await __privateMethod(this, _FileManager_instances, addOrAppend_fn).call(this, {
|
|
338
|
-
...rootFile,
|
|
339
|
-
meta: {
|
|
340
|
-
pluginKey: plugin.key
|
|
341
|
-
}
|
|
342
|
-
})
|
|
343
|
-
];
|
|
344
|
-
}
|
|
345
|
-
getCacheByUUID(UUID) {
|
|
346
|
-
let cache;
|
|
347
|
-
__privateGet(this, _cache).forEach((files) => {
|
|
348
|
-
cache = files.find((item) => item.id === UUID);
|
|
349
|
-
});
|
|
350
|
-
return cache;
|
|
351
|
-
}
|
|
352
|
-
get(path3) {
|
|
353
|
-
return __privateGet(this, _cache).get(path3);
|
|
354
|
-
}
|
|
355
|
-
remove(path3) {
|
|
356
|
-
const cacheItem = this.get(path3);
|
|
357
|
-
if (!cacheItem) {
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
__privateGet(this, _cache).delete(path3);
|
|
361
|
-
}
|
|
362
|
-
async write(...params) {
|
|
363
|
-
return write(...params);
|
|
364
|
-
}
|
|
365
|
-
async read(...params) {
|
|
366
|
-
return read(...params);
|
|
367
|
-
}
|
|
368
|
-
async processFiles(...params) {
|
|
369
|
-
return processFiles(...params);
|
|
370
|
-
}
|
|
371
|
-
// statics
|
|
372
|
-
static combineFiles(files) {
|
|
373
|
-
return combineFiles(files);
|
|
374
|
-
}
|
|
375
|
-
static getMode(path3) {
|
|
376
|
-
if (!path3) {
|
|
377
|
-
return "split";
|
|
378
|
-
}
|
|
379
|
-
return extname(path3) ? "single" : "split";
|
|
380
|
-
}
|
|
381
|
-
static get extensions() {
|
|
382
|
-
return [".js", ".ts", ".tsx"];
|
|
383
|
-
}
|
|
384
|
-
static isJavascript(baseName) {
|
|
385
|
-
return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
_cache = new WeakMap();
|
|
389
|
-
_FileManager_instances = new WeakSet();
|
|
390
|
-
add_fn = async function(file) {
|
|
391
|
-
const controller = new AbortController();
|
|
392
|
-
const resolvedFile = {
|
|
393
|
-
id: crypto.randomUUID(),
|
|
394
|
-
name: trimExtName(file.baseName),
|
|
395
|
-
...file
|
|
396
|
-
};
|
|
397
|
-
if (resolvedFile.exports?.length) {
|
|
398
|
-
const folder = resolvedFile.path.replace(resolvedFile.baseName, "");
|
|
399
|
-
resolvedFile.exports = resolvedFile.exports.filter((exportItem) => {
|
|
400
|
-
const exportedFile = this.files.find((file2) => file2.path.includes(resolve(folder, exportItem.path)));
|
|
401
|
-
if (exportedFile) {
|
|
402
|
-
return exportedFile.exportable;
|
|
403
|
-
}
|
|
404
|
-
return true;
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
408
|
-
return resolvedFile;
|
|
409
|
-
};
|
|
410
|
-
addOrAppend_fn = async function(file) {
|
|
411
|
-
const previousCaches = __privateGet(this, _cache).get(file.path);
|
|
412
|
-
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
413
|
-
if (previousCache) {
|
|
414
|
-
__privateGet(this, _cache).delete(previousCache.path);
|
|
415
|
-
return __privateMethod(this, _FileManager_instances, add_fn).call(this, {
|
|
416
|
-
...file,
|
|
417
|
-
source: previousCache.source && file.source ? `${previousCache.source}
|
|
418
|
-
${file.source}` : "",
|
|
419
|
-
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
420
|
-
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
421
|
-
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
return __privateMethod(this, _FileManager_instances, add_fn).call(this, file);
|
|
425
|
-
};
|
|
426
|
-
var FileManager = _FileManager;
|
|
427
|
-
function combineFiles(files) {
|
|
428
|
-
return files.filter(Boolean).reduce(
|
|
429
|
-
(acc, file) => {
|
|
430
|
-
const prevIndex = acc.findIndex((item) => item.path === file.path);
|
|
431
|
-
if (prevIndex === -1) {
|
|
432
|
-
return [...acc, file];
|
|
433
|
-
}
|
|
434
|
-
const prev = acc[prevIndex];
|
|
435
|
-
if (prev && file.override) {
|
|
436
|
-
acc[prevIndex] = {
|
|
437
|
-
imports: [],
|
|
438
|
-
exports: [],
|
|
439
|
-
...file
|
|
440
|
-
};
|
|
441
|
-
return acc;
|
|
442
|
-
}
|
|
443
|
-
if (prev) {
|
|
444
|
-
acc[prevIndex] = {
|
|
445
|
-
...file,
|
|
446
|
-
source: prev.source && file.source ? `${prev.source}
|
|
447
|
-
${file.source}` : "",
|
|
448
|
-
imports: [...prev.imports || [], ...file.imports || []],
|
|
449
|
-
exports: [...prev.exports || [], ...file.exports || []],
|
|
450
|
-
env: { ...prev.env || {}, ...file.env || {} }
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
return acc;
|
|
454
|
-
},
|
|
455
|
-
[]
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
|
-
async function getSource(file) {
|
|
459
|
-
if (file.language ? !["typescript", "javascript"].includes(file.language) : !FileManager.isJavascript(file.baseName)) {
|
|
460
|
-
return file.source;
|
|
461
|
-
}
|
|
462
|
-
const parser = await getParser(file.language);
|
|
463
|
-
const exports = file.exports ? combineExports(file.exports) : [];
|
|
464
|
-
const imports = file.imports && file.source ? combineImports(file.imports, exports, file.source) : [];
|
|
465
|
-
const importNodes = imports.filter((item) => {
|
|
466
|
-
const path3 = item.root ? getRelativePath(item.root, item.path) : item.path;
|
|
467
|
-
return path3 !== trimExtName(file.path);
|
|
468
|
-
}).map((item) => {
|
|
469
|
-
const path3 = item.root ? getRelativePath(item.root, item.path) : item.path;
|
|
470
|
-
return parser.factory.createImportDeclaration({
|
|
471
|
-
name: item.name,
|
|
472
|
-
path: item.extName ? `${path3}${item.extName}` : path3,
|
|
473
|
-
isTypeOnly: item.isTypeOnly
|
|
474
|
-
});
|
|
475
|
-
});
|
|
476
|
-
const exportNodes = exports.map(
|
|
477
|
-
(item) => parser.factory.createExportDeclaration({
|
|
478
|
-
name: item.name,
|
|
479
|
-
path: item.extName ? `${item.path}${item.extName}` : item.path,
|
|
480
|
-
isTypeOnly: item.isTypeOnly,
|
|
481
|
-
asAlias: item.asAlias
|
|
482
|
-
})
|
|
483
|
-
);
|
|
484
|
-
const source = [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
485
|
-
return parser.print([], { source, noEmitHelpers: false });
|
|
486
|
-
}
|
|
487
|
-
function combineExports(exports) {
|
|
488
|
-
const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce(
|
|
489
|
-
(prev, curr) => {
|
|
490
|
-
const name = curr.name;
|
|
491
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
492
|
-
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly);
|
|
493
|
-
if (prevByPathAndIsTypeOnly) {
|
|
494
|
-
return prev;
|
|
495
|
-
}
|
|
496
|
-
const uniquePrev = prev.findLast(
|
|
497
|
-
(imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
498
|
-
);
|
|
499
|
-
if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
|
|
500
|
-
return prev;
|
|
501
|
-
}
|
|
502
|
-
if (!prevByPath) {
|
|
503
|
-
return [
|
|
504
|
-
...prev,
|
|
505
|
-
{
|
|
506
|
-
...curr,
|
|
507
|
-
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
508
|
-
}
|
|
509
|
-
];
|
|
510
|
-
}
|
|
511
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
512
|
-
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
|
|
513
|
-
return prev;
|
|
514
|
-
}
|
|
515
|
-
return [...prev, curr];
|
|
516
|
-
},
|
|
517
|
-
[]
|
|
518
|
-
);
|
|
519
|
-
return orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
520
|
-
}
|
|
521
|
-
function combineImports(imports, exports, source) {
|
|
522
|
-
const combinedImports = orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce(
|
|
523
|
-
(prev, curr) => {
|
|
524
|
-
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
525
|
-
const hasImportInSource = (importName) => {
|
|
526
|
-
if (!source) {
|
|
527
|
-
return true;
|
|
528
|
-
}
|
|
529
|
-
const checker = (name2) => name2 && !!source.includes(name2);
|
|
530
|
-
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
531
|
-
};
|
|
532
|
-
if (curr.path === curr.root) {
|
|
533
|
-
return prev;
|
|
534
|
-
}
|
|
535
|
-
if (Array.isArray(name)) {
|
|
536
|
-
name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
|
|
537
|
-
}
|
|
538
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
539
|
-
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
540
|
-
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly);
|
|
541
|
-
if (prevByPathNameAndIsTypeOnly) {
|
|
542
|
-
return prev;
|
|
543
|
-
}
|
|
544
|
-
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
545
|
-
return prev;
|
|
546
|
-
}
|
|
547
|
-
if (!prevByPath) {
|
|
548
|
-
return [
|
|
549
|
-
...prev,
|
|
550
|
-
{
|
|
551
|
-
...curr,
|
|
552
|
-
name
|
|
553
|
-
}
|
|
554
|
-
];
|
|
555
|
-
}
|
|
556
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
557
|
-
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
|
|
558
|
-
return prev;
|
|
559
|
-
}
|
|
560
|
-
if (!Array.isArray(name) && name && !hasImportInSource(name)) {
|
|
561
|
-
return prev;
|
|
562
|
-
}
|
|
563
|
-
return [...prev, curr];
|
|
564
|
-
},
|
|
565
|
-
[]
|
|
566
|
-
);
|
|
567
|
-
return orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
568
|
-
}
|
|
569
|
-
function getEnvSource(source, env) {
|
|
570
|
-
if (!env) {
|
|
571
|
-
return source;
|
|
572
|
-
}
|
|
573
|
-
const keys = Object.keys(env);
|
|
574
|
-
if (!keys.length) {
|
|
575
|
-
return source;
|
|
576
|
-
}
|
|
577
|
-
return keys.reduce((prev, key) => {
|
|
578
|
-
const environmentValue = env[key];
|
|
579
|
-
const replaceBy = environmentValue ? `'${environmentValue.replaceAll('"', "")?.replaceAll("'", "")}'` : "undefined";
|
|
580
|
-
if (key.toUpperCase() !== key) {
|
|
581
|
-
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
582
|
-
}
|
|
583
|
-
if (typeof replaceBy === "string") {
|
|
584
|
-
prev = searchAndReplace({
|
|
585
|
-
text: prev.replaceAll(`process.env.${key}`, replaceBy),
|
|
586
|
-
replaceBy,
|
|
587
|
-
prefix: "process.env",
|
|
588
|
-
key
|
|
589
|
-
});
|
|
590
|
-
prev = searchAndReplace({
|
|
591
|
-
text: prev.replaceAll(/(declare const).*\n/gi, ""),
|
|
592
|
-
replaceBy,
|
|
593
|
-
key
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
return prev;
|
|
597
|
-
}, source);
|
|
598
|
-
}
|
|
599
|
-
var queue = new PQueue({ concurrency: 10 });
|
|
600
|
-
async function processFiles({ dryRun, logger, files }) {
|
|
601
|
-
const mergedFiles = await Promise.all(
|
|
602
|
-
files.map(async (file) => ({
|
|
603
|
-
...file,
|
|
604
|
-
source: await getSource(file)
|
|
605
|
-
}))
|
|
606
|
-
);
|
|
607
|
-
const orderedFiles = orderBy(mergedFiles, [(v) => !v.meta?.pluginKey, (v) => v.path.length, (v) => trimExtName(v.path).endsWith("index")], ["desc", "desc"]);
|
|
608
|
-
logger.emit(
|
|
609
|
-
"debug",
|
|
610
|
-
orderedFiles.map((item) => `[${item.meta?.pluginKey || "unknown"}]${item.path}:
|
|
611
|
-
${item.source}`)
|
|
612
|
-
);
|
|
613
|
-
if (!dryRun) {
|
|
614
|
-
logger.consola?.pauseLogs();
|
|
615
|
-
const size = orderedFiles.length;
|
|
616
|
-
const promises = orderedFiles.map(async (file, index) => {
|
|
617
|
-
await queue.add(async () => {
|
|
618
|
-
logger.emit("progress", { count: index, size, file });
|
|
619
|
-
await write(file.path, file.source, { sanity: false });
|
|
620
|
-
await new Promise((resolve2) => {
|
|
621
|
-
setTimeout(resolve2, 0);
|
|
622
|
-
});
|
|
623
|
-
logger.emit("progress", { count: index + 1, size, file });
|
|
624
|
-
});
|
|
625
|
-
});
|
|
626
|
-
await Promise.all(promises);
|
|
627
|
-
logger.consola?.resumeLogs();
|
|
628
|
-
}
|
|
629
|
-
return mergedFiles;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
export {
|
|
633
|
-
FileManager,
|
|
634
|
-
getSource,
|
|
635
|
-
processFiles
|
|
636
|
-
};
|
|
637
|
-
//# sourceMappingURL=chunk-CEWT73XF.js.map
|