@kubb/core 2.18.4 → 2.18.5
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/chunk-7TB4GNKF.cjs +1268 -0
- package/dist/chunk-7TB4GNKF.cjs.map +1 -0
- package/dist/{chunk-TIYJPVUG.js → chunk-7UMWFPXG.js} +1 -9
- package/dist/chunk-7UMWFPXG.js.map +1 -0
- package/dist/{chunk-GRBLCGB5.cjs → chunk-BE4KSMB4.cjs} +5 -5
- package/dist/chunk-EPAC7V2R.js +597 -0
- package/dist/chunk-EPAC7V2R.js.map +1 -0
- package/dist/{chunk-YTLMG2AN.cjs → chunk-FWUA552W.cjs} +29 -29
- package/dist/{chunk-NP7GXHZS.cjs → chunk-JI763CHT.cjs} +18 -18
- package/dist/{chunk-GG3XRJX3.cjs → chunk-M6VNU2SJ.cjs} +12 -20
- package/dist/chunk-M6VNU2SJ.cjs.map +1 -0
- package/dist/{chunk-XUCU53HT.cjs → chunk-TCFN5BZ6.cjs} +3 -11
- package/dist/chunk-TCFN5BZ6.cjs.map +1 -0
- package/dist/index.cjs +1297 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -148
- package/dist/index.d.ts +26 -148
- package/dist/index.js +991 -22
- package/dist/index.js.map +1 -1
- package/dist/logger.cjs +3 -4
- package/dist/logger.js +1 -2
- package/dist/mocks.cjs +15 -14
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +4 -2
- package/dist/mocks.d.ts +4 -2
- package/dist/mocks.js +7 -6
- package/dist/mocks.js.map +1 -1
- package/dist/transformers.cjs +4 -4
- package/dist/utils.cjs +4 -4
- package/package.json +8 -18
- package/src/BarrelManager.ts +1 -1
- package/src/FileManager.ts +36 -167
- package/src/PackageManager.ts +1 -1
- package/src/PluginManager.ts +5 -5
- package/src/build.ts +6 -8
- package/src/index.ts +2 -3
- package/src/logger.ts +0 -7
- package/src/types.ts +3 -2
- package/src/utils/TreeNode.ts +1 -1
- package/dist/chunk-2F7E62RD.js +0 -85
- package/dist/chunk-2F7E62RD.js.map +0 -1
- package/dist/chunk-6NMPKKGV.js +0 -1597
- package/dist/chunk-6NMPKKGV.js.map +0 -1
- package/dist/chunk-7PBKI3OR.cjs +0 -2584
- package/dist/chunk-7PBKI3OR.cjs.map +0 -1
- package/dist/chunk-AQJCCWPW.cjs +0 -75
- package/dist/chunk-AQJCCWPW.cjs.map +0 -1
- package/dist/chunk-GG3XRJX3.cjs.map +0 -1
- package/dist/chunk-MDO6MCFJ.js +0 -65
- package/dist/chunk-MDO6MCFJ.js.map +0 -1
- package/dist/chunk-TIYJPVUG.js.map +0 -1
- package/dist/chunk-X5IJHUXJ.cjs +0 -2332
- package/dist/chunk-X5IJHUXJ.cjs.map +0 -1
- package/dist/chunk-XUCU53HT.cjs.map +0 -1
- package/dist/fs.cjs +0 -23
- package/dist/fs.cjs.map +0 -1
- package/dist/fs.d.cts +0 -5
- package/dist/fs.d.ts +0 -5
- package/dist/fs.js +0 -18
- package/dist/fs.js.map +0 -1
- package/dist/write-CN8f7bYv.d.cts +0 -10
- package/dist/write-CN8f7bYv.d.ts +0 -10
- package/src/fs/clean.ts +0 -5
- package/src/fs/index.ts +0 -3
- package/src/fs/read.ts +0 -68
- package/src/fs/write.ts +0 -83
- /package/dist/{chunk-GRBLCGB5.cjs.map → chunk-BE4KSMB4.cjs.map} +0 -0
- /package/dist/{chunk-YTLMG2AN.cjs.map → chunk-FWUA552W.cjs.map} +0 -0
- /package/dist/{chunk-NP7GXHZS.cjs.map → chunk-JI763CHT.cjs.map} +0 -0
package/dist/chunk-6NMPKKGV.js
DELETED
|
@@ -1,1597 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
searchAndReplace,
|
|
3
|
-
transformReservedWord,
|
|
4
|
-
transformers_default,
|
|
5
|
-
trimExtName
|
|
6
|
-
} from "./chunk-UCKFXEKM.js";
|
|
7
|
-
import {
|
|
8
|
-
URLPath,
|
|
9
|
-
getParser,
|
|
10
|
-
setUniqueName
|
|
11
|
-
} from "./chunk-FRT5NM5I.js";
|
|
12
|
-
import {
|
|
13
|
-
orderBy
|
|
14
|
-
} from "./chunk-4X5FFJPJ.js";
|
|
15
|
-
import {
|
|
16
|
-
EventEmitter,
|
|
17
|
-
LogLevel,
|
|
18
|
-
createLogger,
|
|
19
|
-
p,
|
|
20
|
-
randomCliColour
|
|
21
|
-
} from "./chunk-TIYJPVUG.js";
|
|
22
|
-
import {
|
|
23
|
-
clean,
|
|
24
|
-
getRelativePath,
|
|
25
|
-
read,
|
|
26
|
-
readSync
|
|
27
|
-
} from "./chunk-MDO6MCFJ.js";
|
|
28
|
-
import {
|
|
29
|
-
write
|
|
30
|
-
} from "./chunk-2F7E62RD.js";
|
|
31
|
-
import {
|
|
32
|
-
__privateAdd,
|
|
33
|
-
__privateGet,
|
|
34
|
-
__privateMethod,
|
|
35
|
-
__privateSet
|
|
36
|
-
} from "./chunk-Z4BLTVTB.js";
|
|
37
|
-
|
|
38
|
-
// src/FileManager.ts
|
|
39
|
-
import crypto from "crypto";
|
|
40
|
-
import { extname, resolve } from "path";
|
|
41
|
-
import PQueue from "p-queue";
|
|
42
|
-
import { isDeepEqual } from "remeda";
|
|
43
|
-
|
|
44
|
-
// src/BarrelManager.ts
|
|
45
|
-
import { getExports } from "@kubb/parser-ts";
|
|
46
|
-
import path from "path";
|
|
47
|
-
|
|
48
|
-
// src/utils/TreeNode.ts
|
|
49
|
-
import dirTree from "directory-tree";
|
|
50
|
-
var TreeNode = class _TreeNode {
|
|
51
|
-
constructor(data, parent) {
|
|
52
|
-
this.children = [];
|
|
53
|
-
this.data = data;
|
|
54
|
-
this.parent = parent;
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
addChild(data) {
|
|
58
|
-
const child = new _TreeNode(data, this);
|
|
59
|
-
if (!this.children) {
|
|
60
|
-
this.children = [];
|
|
61
|
-
}
|
|
62
|
-
this.children.push(child);
|
|
63
|
-
return child;
|
|
64
|
-
}
|
|
65
|
-
find(data) {
|
|
66
|
-
if (!data) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
if (data === this.data) {
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
if (this.children?.length) {
|
|
73
|
-
for (let i = 0, { length } = this.children, target = null; i < length; i++) {
|
|
74
|
-
target = this.children[i].find(data);
|
|
75
|
-
if (target) {
|
|
76
|
-
return target;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
get leaves() {
|
|
83
|
-
if (!this.children || this.children.length === 0) {
|
|
84
|
-
return [this];
|
|
85
|
-
}
|
|
86
|
-
const leaves = [];
|
|
87
|
-
if (this.children) {
|
|
88
|
-
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
89
|
-
leaves.push.apply(leaves, this.children[i].leaves);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return leaves;
|
|
93
|
-
}
|
|
94
|
-
get root() {
|
|
95
|
-
if (!this.parent) {
|
|
96
|
-
return this;
|
|
97
|
-
}
|
|
98
|
-
return this.parent.root;
|
|
99
|
-
}
|
|
100
|
-
forEach(callback) {
|
|
101
|
-
if (typeof callback !== "function") {
|
|
102
|
-
throw new TypeError("forEach() callback must be a function");
|
|
103
|
-
}
|
|
104
|
-
callback(this);
|
|
105
|
-
if (this.children) {
|
|
106
|
-
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
107
|
-
this.children[i]?.forEach(callback);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return this;
|
|
111
|
-
}
|
|
112
|
-
static build(path3, options = {}) {
|
|
113
|
-
try {
|
|
114
|
-
const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
|
|
115
|
-
const filteredTree = dirTree(path3, {
|
|
116
|
-
extensions: options.extensions,
|
|
117
|
-
exclude: [/node_modules/, ...exclude]
|
|
118
|
-
});
|
|
119
|
-
if (!filteredTree) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
const treeNode = new _TreeNode({
|
|
123
|
-
name: filteredTree.name,
|
|
124
|
-
path: filteredTree.path,
|
|
125
|
-
type: FileManager.getMode(filteredTree.path)
|
|
126
|
-
});
|
|
127
|
-
const recurse = (node, item) => {
|
|
128
|
-
const subNode = node.addChild({
|
|
129
|
-
name: item.name,
|
|
130
|
-
path: item.path,
|
|
131
|
-
type: FileManager.getMode(item.path)
|
|
132
|
-
});
|
|
133
|
-
if (item.children?.length) {
|
|
134
|
-
item.children?.forEach((child) => {
|
|
135
|
-
recurse(subNode, child);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
filteredTree.children?.forEach((child) => recurse(treeNode, child));
|
|
140
|
-
return treeNode;
|
|
141
|
-
} catch (e) {
|
|
142
|
-
throw new Error("Something went wrong with creating index files with the TreehNode class", { cause: e });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
// src/BarrelManager.ts
|
|
148
|
-
var _options;
|
|
149
|
-
var BarrelManager = class {
|
|
150
|
-
constructor(options = {}) {
|
|
151
|
-
__privateAdd(this, _options, void 0);
|
|
152
|
-
__privateSet(this, _options, options);
|
|
153
|
-
return this;
|
|
154
|
-
}
|
|
155
|
-
getNamedExport(root, item) {
|
|
156
|
-
const exportedNames = getExports(path.resolve(root, item.path));
|
|
157
|
-
if (!exportedNames) {
|
|
158
|
-
return [item];
|
|
159
|
-
}
|
|
160
|
-
return exportedNames.reduce(
|
|
161
|
-
(prev, curr) => {
|
|
162
|
-
if (!prev[0]?.name || !prev[1]?.name) {
|
|
163
|
-
return prev;
|
|
164
|
-
}
|
|
165
|
-
if (curr.isTypeOnly) {
|
|
166
|
-
prev[1] = { ...prev[1], name: [...prev[1].name, curr.name] };
|
|
167
|
-
} else {
|
|
168
|
-
prev[0] = { ...prev[0], name: [...prev[0].name, curr.name] };
|
|
169
|
-
}
|
|
170
|
-
return prev;
|
|
171
|
-
},
|
|
172
|
-
[
|
|
173
|
-
{
|
|
174
|
-
...item,
|
|
175
|
-
name: [],
|
|
176
|
-
isTypeOnly: false
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
...item,
|
|
180
|
-
name: [],
|
|
181
|
-
isTypeOnly: true
|
|
182
|
-
}
|
|
183
|
-
]
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
getNamedExports(root, exports) {
|
|
187
|
-
return exports?.flatMap((item) => {
|
|
188
|
-
return this.getNamedExport(root, item);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
getIndexes(root) {
|
|
192
|
-
const { treeNode = {}, isTypeOnly, extName } = __privateGet(this, _options);
|
|
193
|
-
const tree = TreeNode.build(root, treeNode);
|
|
194
|
-
if (!tree) {
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
const fileReducer = (files, treeNode2) => {
|
|
198
|
-
if (!treeNode2.children) {
|
|
199
|
-
return [];
|
|
200
|
-
}
|
|
201
|
-
if (treeNode2.children.length > 1) {
|
|
202
|
-
const indexPath = path.resolve(treeNode2.data.path, "index.ts");
|
|
203
|
-
const exports = treeNode2.children.filter(Boolean).map((file) => {
|
|
204
|
-
const importPath = file.data.type === "split" ? `./${file.data.name}/index` : `./${trimExtName(file.data.name)}`;
|
|
205
|
-
if (importPath.endsWith("index") && file.data.type === "single") {
|
|
206
|
-
return void 0;
|
|
207
|
-
}
|
|
208
|
-
return {
|
|
209
|
-
path: extName ? `${importPath}${extName}` : importPath,
|
|
210
|
-
isTypeOnly
|
|
211
|
-
};
|
|
212
|
-
}).filter(Boolean);
|
|
213
|
-
files.push({
|
|
214
|
-
path: indexPath,
|
|
215
|
-
baseName: "index.ts",
|
|
216
|
-
source: "",
|
|
217
|
-
exports,
|
|
218
|
-
exportable: true
|
|
219
|
-
});
|
|
220
|
-
} else if (treeNode2.children.length === 1) {
|
|
221
|
-
const [treeNodeChild] = treeNode2.children;
|
|
222
|
-
const indexPath = path.resolve(treeNode2.data.path, "index.ts");
|
|
223
|
-
const importPath = treeNodeChild.data.type === "split" ? `./${treeNodeChild.data.name}/index` : `./${trimExtName(treeNodeChild.data.name)}`;
|
|
224
|
-
const exports = [
|
|
225
|
-
{
|
|
226
|
-
path: extName ? `${importPath}${extName}` : importPath,
|
|
227
|
-
isTypeOnly
|
|
228
|
-
}
|
|
229
|
-
];
|
|
230
|
-
files.push({
|
|
231
|
-
path: indexPath,
|
|
232
|
-
baseName: "index.ts",
|
|
233
|
-
source: "",
|
|
234
|
-
exports,
|
|
235
|
-
exportable: true
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
treeNode2.children.forEach((childItem) => {
|
|
239
|
-
fileReducer(files, childItem);
|
|
240
|
-
});
|
|
241
|
-
return files;
|
|
242
|
-
};
|
|
243
|
-
return fileReducer([], tree).reverse();
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
_options = new WeakMap();
|
|
247
|
-
|
|
248
|
-
// src/FileManager.ts
|
|
249
|
-
var KubbFile;
|
|
250
|
-
((KubbFile2) => {
|
|
251
|
-
})(KubbFile || (KubbFile = {}));
|
|
252
|
-
var _cache, _task, _queue, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
253
|
-
var _FileManager = class _FileManager {
|
|
254
|
-
constructor({ task = async (file) => file, queue = new PQueue() } = {}) {
|
|
255
|
-
__privateAdd(this, _add);
|
|
256
|
-
__privateAdd(this, _addOrAppend);
|
|
257
|
-
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
258
|
-
__privateAdd(this, _task, void 0);
|
|
259
|
-
__privateAdd(this, _queue, void 0);
|
|
260
|
-
__privateSet(this, _task, task);
|
|
261
|
-
__privateSet(this, _queue, queue);
|
|
262
|
-
return this;
|
|
263
|
-
}
|
|
264
|
-
get files() {
|
|
265
|
-
const files = [];
|
|
266
|
-
__privateGet(this, _cache).forEach((item) => {
|
|
267
|
-
files.push(...item.flat(1));
|
|
268
|
-
});
|
|
269
|
-
return files;
|
|
270
|
-
}
|
|
271
|
-
get isExecuting() {
|
|
272
|
-
return __privateGet(this, _queue).size !== 0 && __privateGet(this, _queue).pending !== 0;
|
|
273
|
-
}
|
|
274
|
-
async add(...files) {
|
|
275
|
-
const promises = combineFiles(files).map((file) => {
|
|
276
|
-
if (file.override) {
|
|
277
|
-
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
278
|
-
}
|
|
279
|
-
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
|
|
280
|
-
});
|
|
281
|
-
const resolvedFiles = await Promise.all(promises);
|
|
282
|
-
if (files.length > 1) {
|
|
283
|
-
return resolvedFiles;
|
|
284
|
-
}
|
|
285
|
-
return resolvedFiles[0];
|
|
286
|
-
}
|
|
287
|
-
async addIndexes({ root, output, meta, logger, options = {} }) {
|
|
288
|
-
const { exportType = "barrel" } = output;
|
|
289
|
-
if (exportType === false) {
|
|
290
|
-
return void 0;
|
|
291
|
-
}
|
|
292
|
-
const pathToBuildFrom = resolve(root, output.path);
|
|
293
|
-
if (transformers_default.trimExtName(pathToBuildFrom).endsWith("index")) {
|
|
294
|
-
logger.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
const exportPath = output.path.startsWith("./") ? trimExtName(output.path) : `./${trimExtName(output.path)}`;
|
|
298
|
-
const mode = _FileManager.getMode(output.path);
|
|
299
|
-
const barrelManager = new BarrelManager({
|
|
300
|
-
extName: output.extName,
|
|
301
|
-
...options
|
|
302
|
-
});
|
|
303
|
-
let files = barrelManager.getIndexes(pathToBuildFrom);
|
|
304
|
-
if (!files) {
|
|
305
|
-
return void 0;
|
|
306
|
-
}
|
|
307
|
-
if (exportType === "barrelNamed") {
|
|
308
|
-
files = files.map((file) => {
|
|
309
|
-
if (file.exports) {
|
|
310
|
-
return {
|
|
311
|
-
...file,
|
|
312
|
-
exports: barrelManager.getNamedExports(pathToBuildFrom, file.exports)
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
return file;
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
await Promise.all(
|
|
319
|
-
files.map((file) => {
|
|
320
|
-
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
321
|
-
...file,
|
|
322
|
-
meta: meta ? meta : file.meta
|
|
323
|
-
});
|
|
324
|
-
})
|
|
325
|
-
);
|
|
326
|
-
const rootPath = mode === "split" ? `${exportPath}/index${output.extName || ""}` : `${exportPath}${output.extName || ""}`;
|
|
327
|
-
const rootFile = {
|
|
328
|
-
path: resolve(root, "index.ts"),
|
|
329
|
-
baseName: "index.ts",
|
|
330
|
-
source: "",
|
|
331
|
-
exports: [
|
|
332
|
-
output.exportAs ? {
|
|
333
|
-
name: output.exportAs,
|
|
334
|
-
asAlias: true,
|
|
335
|
-
path: rootPath,
|
|
336
|
-
isTypeOnly: options.isTypeOnly
|
|
337
|
-
} : {
|
|
338
|
-
path: rootPath,
|
|
339
|
-
isTypeOnly: options.isTypeOnly
|
|
340
|
-
}
|
|
341
|
-
],
|
|
342
|
-
exportable: true
|
|
343
|
-
};
|
|
344
|
-
if (exportType === "barrelNamed" && !output.exportAs && rootFile.exports?.[0]) {
|
|
345
|
-
rootFile.exports = barrelManager.getNamedExport(root, rootFile.exports[0]);
|
|
346
|
-
}
|
|
347
|
-
await __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
348
|
-
...rootFile,
|
|
349
|
-
meta: meta ? meta : rootFile.meta
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
getCacheByUUID(UUID) {
|
|
353
|
-
let cache;
|
|
354
|
-
__privateGet(this, _cache).forEach((files) => {
|
|
355
|
-
cache = files.find((item) => item.id === UUID);
|
|
356
|
-
});
|
|
357
|
-
return cache;
|
|
358
|
-
}
|
|
359
|
-
get(path3) {
|
|
360
|
-
return __privateGet(this, _cache).get(path3);
|
|
361
|
-
}
|
|
362
|
-
remove(path3) {
|
|
363
|
-
const cacheItem = this.get(path3);
|
|
364
|
-
if (!cacheItem) {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
__privateGet(this, _cache).delete(path3);
|
|
368
|
-
}
|
|
369
|
-
async write(...params) {
|
|
370
|
-
return write(...params);
|
|
371
|
-
}
|
|
372
|
-
async read(...params) {
|
|
373
|
-
return read(...params);
|
|
374
|
-
}
|
|
375
|
-
// statics
|
|
376
|
-
static async getSource(file) {
|
|
377
|
-
return getSource(file);
|
|
378
|
-
}
|
|
379
|
-
static combineFiles(files) {
|
|
380
|
-
return combineFiles(files);
|
|
381
|
-
}
|
|
382
|
-
static getMode(path3) {
|
|
383
|
-
if (!path3) {
|
|
384
|
-
return "split";
|
|
385
|
-
}
|
|
386
|
-
return extname(path3) ? "single" : "split";
|
|
387
|
-
}
|
|
388
|
-
static get extensions() {
|
|
389
|
-
return [".js", ".ts", ".tsx"];
|
|
390
|
-
}
|
|
391
|
-
static isJavascript(baseName) {
|
|
392
|
-
return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
_cache = new WeakMap();
|
|
396
|
-
_task = new WeakMap();
|
|
397
|
-
_queue = new WeakMap();
|
|
398
|
-
_add = new WeakSet();
|
|
399
|
-
add_fn = async function(file) {
|
|
400
|
-
const controller = new AbortController();
|
|
401
|
-
const resolvedFile = {
|
|
402
|
-
id: crypto.randomUUID(),
|
|
403
|
-
name: trimExtName(file.baseName),
|
|
404
|
-
...file
|
|
405
|
-
};
|
|
406
|
-
if (resolvedFile.exports?.length) {
|
|
407
|
-
const folder = resolvedFile.path.replace(resolvedFile.baseName, "");
|
|
408
|
-
resolvedFile.exports = resolvedFile.exports.filter((exportItem) => {
|
|
409
|
-
const exportedFile = this.files.find((file2) => file2.path.includes(resolve(folder, exportItem.path)));
|
|
410
|
-
if (exportedFile) {
|
|
411
|
-
return exportedFile.exportable;
|
|
412
|
-
}
|
|
413
|
-
return true;
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
417
|
-
return __privateGet(this, _queue).add(
|
|
418
|
-
async () => {
|
|
419
|
-
var _a;
|
|
420
|
-
return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
|
|
421
|
-
},
|
|
422
|
-
{ signal: controller.signal }
|
|
423
|
-
);
|
|
424
|
-
};
|
|
425
|
-
_addOrAppend = new WeakSet();
|
|
426
|
-
addOrAppend_fn = async function(file) {
|
|
427
|
-
const previousCaches = __privateGet(this, _cache).get(file.path);
|
|
428
|
-
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
429
|
-
if (previousCache) {
|
|
430
|
-
__privateGet(this, _cache).delete(previousCache.path);
|
|
431
|
-
return __privateMethod(this, _add, add_fn).call(this, {
|
|
432
|
-
...file,
|
|
433
|
-
source: previousCache.source && file.source ? `${previousCache.source}
|
|
434
|
-
${file.source}` : "",
|
|
435
|
-
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
436
|
-
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
437
|
-
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
441
|
-
};
|
|
442
|
-
var FileManager = _FileManager;
|
|
443
|
-
function combineFiles(files) {
|
|
444
|
-
return files.filter(Boolean).reduce(
|
|
445
|
-
(acc, file) => {
|
|
446
|
-
const prevIndex = acc.findIndex((item) => item.path === file.path);
|
|
447
|
-
if (prevIndex === -1) {
|
|
448
|
-
return [...acc, file];
|
|
449
|
-
}
|
|
450
|
-
const prev = acc[prevIndex];
|
|
451
|
-
if (prev && file.override) {
|
|
452
|
-
acc[prevIndex] = {
|
|
453
|
-
imports: [],
|
|
454
|
-
exports: [],
|
|
455
|
-
...file
|
|
456
|
-
};
|
|
457
|
-
return acc;
|
|
458
|
-
}
|
|
459
|
-
if (prev) {
|
|
460
|
-
acc[prevIndex] = {
|
|
461
|
-
...file,
|
|
462
|
-
source: prev.source && file.source ? `${prev.source}
|
|
463
|
-
${file.source}` : "",
|
|
464
|
-
imports: [...prev.imports || [], ...file.imports || []],
|
|
465
|
-
exports: [...prev.exports || [], ...file.exports || []],
|
|
466
|
-
env: { ...prev.env || {}, ...file.env || {} }
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
return acc;
|
|
470
|
-
},
|
|
471
|
-
[]
|
|
472
|
-
);
|
|
473
|
-
}
|
|
474
|
-
async function getSource(file) {
|
|
475
|
-
if (file.language ? !["typescript", "javascript"].includes(file.language) : !FileManager.isJavascript(file.baseName)) {
|
|
476
|
-
return file.source;
|
|
477
|
-
}
|
|
478
|
-
const parser = await getParser(file.language);
|
|
479
|
-
const exports = file.exports ? combineExports(file.exports) : [];
|
|
480
|
-
const imports = file.imports && file.source ? combineImports(file.imports, exports, file.source) : [];
|
|
481
|
-
const importNodes = imports.filter((item) => {
|
|
482
|
-
const path3 = item.root ? getRelativePath(item.root, item.path) : item.path;
|
|
483
|
-
return path3 !== trimExtName(file.path);
|
|
484
|
-
}).map((item) => {
|
|
485
|
-
return parser.factory.createImportDeclaration({
|
|
486
|
-
name: item.name,
|
|
487
|
-
path: item.root ? getRelativePath(item.root, item.path) : item.path,
|
|
488
|
-
isTypeOnly: item.isTypeOnly
|
|
489
|
-
});
|
|
490
|
-
});
|
|
491
|
-
const exportNodes = exports.map(
|
|
492
|
-
(item) => parser.factory.createExportDeclaration({
|
|
493
|
-
name: item.name,
|
|
494
|
-
path: item.path,
|
|
495
|
-
isTypeOnly: item.isTypeOnly,
|
|
496
|
-
asAlias: item.asAlias
|
|
497
|
-
})
|
|
498
|
-
);
|
|
499
|
-
const source = [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
500
|
-
return parser.print([], { source, noEmitHelpers: false });
|
|
501
|
-
}
|
|
502
|
-
function combineExports(exports) {
|
|
503
|
-
const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce(
|
|
504
|
-
(prev, curr) => {
|
|
505
|
-
const name = curr.name;
|
|
506
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
507
|
-
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly);
|
|
508
|
-
if (prevByPathAndIsTypeOnly) {
|
|
509
|
-
return prev;
|
|
510
|
-
}
|
|
511
|
-
const uniquePrev = prev.findLast(
|
|
512
|
-
(imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
513
|
-
);
|
|
514
|
-
if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
|
|
515
|
-
return prev;
|
|
516
|
-
}
|
|
517
|
-
if (!prevByPath) {
|
|
518
|
-
return [
|
|
519
|
-
...prev,
|
|
520
|
-
{
|
|
521
|
-
...curr,
|
|
522
|
-
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
523
|
-
}
|
|
524
|
-
];
|
|
525
|
-
}
|
|
526
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
527
|
-
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
|
|
528
|
-
return prev;
|
|
529
|
-
}
|
|
530
|
-
return [...prev, curr];
|
|
531
|
-
},
|
|
532
|
-
[]
|
|
533
|
-
);
|
|
534
|
-
return orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
535
|
-
}
|
|
536
|
-
function combineImports(imports, exports, source) {
|
|
537
|
-
const combinedImports = orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce(
|
|
538
|
-
(prev, curr) => {
|
|
539
|
-
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
540
|
-
const hasImportInSource = (importName) => {
|
|
541
|
-
if (!source) {
|
|
542
|
-
return true;
|
|
543
|
-
}
|
|
544
|
-
const checker = (name2) => name2 && !!source.includes(name2);
|
|
545
|
-
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
546
|
-
};
|
|
547
|
-
if (curr.path === curr.root) {
|
|
548
|
-
return prev;
|
|
549
|
-
}
|
|
550
|
-
if (Array.isArray(name)) {
|
|
551
|
-
name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
|
|
552
|
-
}
|
|
553
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
554
|
-
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
555
|
-
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly);
|
|
556
|
-
if (prevByPathNameAndIsTypeOnly) {
|
|
557
|
-
return prev;
|
|
558
|
-
}
|
|
559
|
-
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
560
|
-
return prev;
|
|
561
|
-
}
|
|
562
|
-
if (!prevByPath) {
|
|
563
|
-
return [
|
|
564
|
-
...prev,
|
|
565
|
-
{
|
|
566
|
-
...curr,
|
|
567
|
-
name
|
|
568
|
-
}
|
|
569
|
-
];
|
|
570
|
-
}
|
|
571
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
572
|
-
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
|
|
573
|
-
return prev;
|
|
574
|
-
}
|
|
575
|
-
if (!Array.isArray(name) && name && !hasImportInSource(name)) {
|
|
576
|
-
return prev;
|
|
577
|
-
}
|
|
578
|
-
return [...prev, curr];
|
|
579
|
-
},
|
|
580
|
-
[]
|
|
581
|
-
);
|
|
582
|
-
return orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
583
|
-
}
|
|
584
|
-
function getEnvSource(source, env) {
|
|
585
|
-
if (!env) {
|
|
586
|
-
return source;
|
|
587
|
-
}
|
|
588
|
-
const keys = Object.keys(env);
|
|
589
|
-
if (!keys.length) {
|
|
590
|
-
return source;
|
|
591
|
-
}
|
|
592
|
-
return keys.reduce((prev, key) => {
|
|
593
|
-
const environmentValue = env[key];
|
|
594
|
-
const replaceBy = environmentValue ? `'${environmentValue.replaceAll('"', "")?.replaceAll("'", "")}'` : "undefined";
|
|
595
|
-
if (key.toUpperCase() !== key) {
|
|
596
|
-
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
597
|
-
}
|
|
598
|
-
if (typeof replaceBy === "string") {
|
|
599
|
-
prev = searchAndReplace({
|
|
600
|
-
text: prev.replaceAll(`process.env.${key}`, replaceBy),
|
|
601
|
-
replaceBy,
|
|
602
|
-
prefix: "process.env",
|
|
603
|
-
key
|
|
604
|
-
});
|
|
605
|
-
prev = searchAndReplace({
|
|
606
|
-
text: prev.replaceAll(/(declare const).*\n/gi, ""),
|
|
607
|
-
replaceBy,
|
|
608
|
-
key
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
return prev;
|
|
612
|
-
}, source);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
// src/PluginManager.ts
|
|
616
|
-
import PQueue2 from "p-queue";
|
|
617
|
-
|
|
618
|
-
// src/utils/executeStrategies.ts
|
|
619
|
-
function hookSeq(promises) {
|
|
620
|
-
return promises.filter(Boolean).reduce(
|
|
621
|
-
(promise, func) => {
|
|
622
|
-
if (typeof func !== "function") {
|
|
623
|
-
throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
624
|
-
}
|
|
625
|
-
return promise.then((state) => {
|
|
626
|
-
const calledFunc = func(state);
|
|
627
|
-
if (calledFunc) {
|
|
628
|
-
return calledFunc.then(Array.prototype.concat.bind(state));
|
|
629
|
-
}
|
|
630
|
-
});
|
|
631
|
-
},
|
|
632
|
-
Promise.resolve([])
|
|
633
|
-
);
|
|
634
|
-
}
|
|
635
|
-
function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
636
|
-
let promise = Promise.resolve(null);
|
|
637
|
-
for (const func of promises.filter(Boolean)) {
|
|
638
|
-
promise = promise.then((state) => {
|
|
639
|
-
if (nullCheck(state)) {
|
|
640
|
-
return state;
|
|
641
|
-
}
|
|
642
|
-
const calledFunc = func(state);
|
|
643
|
-
return calledFunc;
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
return promise;
|
|
647
|
-
}
|
|
648
|
-
function hookParallel(promises) {
|
|
649
|
-
return Promise.allSettled(promises.filter(Boolean).map((promise) => promise()));
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// src/PromiseManager.ts
|
|
653
|
-
var _options2;
|
|
654
|
-
var PromiseManager = class {
|
|
655
|
-
constructor(options = {}) {
|
|
656
|
-
__privateAdd(this, _options2, {});
|
|
657
|
-
__privateSet(this, _options2, options);
|
|
658
|
-
return this;
|
|
659
|
-
}
|
|
660
|
-
run(strategy, promises) {
|
|
661
|
-
if (strategy === "seq") {
|
|
662
|
-
return hookSeq(promises);
|
|
663
|
-
}
|
|
664
|
-
if (strategy === "first") {
|
|
665
|
-
return hookFirst(promises, __privateGet(this, _options2).nullCheck);
|
|
666
|
-
}
|
|
667
|
-
if (strategy === "parallel") {
|
|
668
|
-
return hookParallel(promises);
|
|
669
|
-
}
|
|
670
|
-
throw new Error(`${strategy} not implemented`);
|
|
671
|
-
}
|
|
672
|
-
};
|
|
673
|
-
_options2 = new WeakMap();
|
|
674
|
-
function isPromise(result) {
|
|
675
|
-
return !!result && typeof result?.then === "function";
|
|
676
|
-
}
|
|
677
|
-
function isPromiseRejectedResult(result) {
|
|
678
|
-
return result.status === "rejected";
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
// src/errors.ts
|
|
682
|
-
var Warning = class extends Error {
|
|
683
|
-
constructor(message, options) {
|
|
684
|
-
super(message, { cause: options?.cause });
|
|
685
|
-
this.name = "Warning";
|
|
686
|
-
}
|
|
687
|
-
};
|
|
688
|
-
var ValidationPluginError = class extends Error {
|
|
689
|
-
};
|
|
690
|
-
|
|
691
|
-
// src/plugin.ts
|
|
692
|
-
import path2 from "path";
|
|
693
|
-
|
|
694
|
-
// src/utils/cache.ts
|
|
695
|
-
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
696
|
-
return {
|
|
697
|
-
set(id, value) {
|
|
698
|
-
Store[id] = [0, value];
|
|
699
|
-
},
|
|
700
|
-
get(id) {
|
|
701
|
-
const item = Store[id];
|
|
702
|
-
if (!item) {
|
|
703
|
-
return null;
|
|
704
|
-
}
|
|
705
|
-
item[0] = 0;
|
|
706
|
-
return item[1];
|
|
707
|
-
},
|
|
708
|
-
has(id) {
|
|
709
|
-
const item = Store[id];
|
|
710
|
-
if (!item) {
|
|
711
|
-
return false;
|
|
712
|
-
}
|
|
713
|
-
item[0] = 0;
|
|
714
|
-
return true;
|
|
715
|
-
},
|
|
716
|
-
delete(id) {
|
|
717
|
-
return delete Store[id];
|
|
718
|
-
}
|
|
719
|
-
};
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
// src/plugin.ts
|
|
723
|
-
function createPlugin(factory) {
|
|
724
|
-
return (options = {}) => {
|
|
725
|
-
return factory(options);
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
var pluginCore = createPlugin((options) => {
|
|
729
|
-
const { fileManager, pluginManager, resolvePath, resolveName, logger } = options;
|
|
730
|
-
return {
|
|
731
|
-
name: "core",
|
|
732
|
-
options,
|
|
733
|
-
key: ["core"],
|
|
734
|
-
api() {
|
|
735
|
-
return {
|
|
736
|
-
get config() {
|
|
737
|
-
return options.config;
|
|
738
|
-
},
|
|
739
|
-
get plugins() {
|
|
740
|
-
return options.getPlugins();
|
|
741
|
-
},
|
|
742
|
-
get plugin() {
|
|
743
|
-
return options.plugin;
|
|
744
|
-
},
|
|
745
|
-
logger,
|
|
746
|
-
fileManager,
|
|
747
|
-
pluginManager,
|
|
748
|
-
async addFile(...files) {
|
|
749
|
-
const resolvedFiles = await fileManager.add(...files);
|
|
750
|
-
if (!Array.isArray(resolvedFiles)) {
|
|
751
|
-
return [resolvedFiles];
|
|
752
|
-
}
|
|
753
|
-
return resolvedFiles;
|
|
754
|
-
},
|
|
755
|
-
resolvePath,
|
|
756
|
-
resolveName,
|
|
757
|
-
cache: createPluginCache()
|
|
758
|
-
};
|
|
759
|
-
},
|
|
760
|
-
resolvePath(baseName) {
|
|
761
|
-
const root = path2.resolve(this.config.root, this.config.output.path);
|
|
762
|
-
return path2.resolve(root, baseName);
|
|
763
|
-
},
|
|
764
|
-
resolveName(name) {
|
|
765
|
-
return name;
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
});
|
|
769
|
-
|
|
770
|
-
// src/PluginManager.ts
|
|
771
|
-
var _core, _usedPluginNames, _promiseManager, _getSortedPlugins, getSortedPlugins_fn, _addExecutedToCallStack, addExecutedToCallStack_fn, _execute, execute_fn, _executeSync, executeSync_fn, _catcher, catcher_fn, _parse, parse_fn;
|
|
772
|
-
var PluginManager = class {
|
|
773
|
-
constructor(config, options) {
|
|
774
|
-
__privateAdd(this, _getSortedPlugins);
|
|
775
|
-
__privateAdd(this, _addExecutedToCallStack);
|
|
776
|
-
/**
|
|
777
|
-
* Run an async plugin hook and return the result.
|
|
778
|
-
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
779
|
-
* @param args Arguments passed to the plugin hook.
|
|
780
|
-
* @param plugin The actual pluginObject to run.
|
|
781
|
-
*/
|
|
782
|
-
// Implementation signature
|
|
783
|
-
__privateAdd(this, _execute);
|
|
784
|
-
/**
|
|
785
|
-
* Run a sync plugin hook and return the result.
|
|
786
|
-
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
787
|
-
* @param args Arguments passed to the plugin hook.
|
|
788
|
-
* @param plugin The acutal plugin
|
|
789
|
-
* @param replaceContext When passed, the plugin context can be overridden.
|
|
790
|
-
*/
|
|
791
|
-
__privateAdd(this, _executeSync);
|
|
792
|
-
__privateAdd(this, _catcher);
|
|
793
|
-
__privateAdd(this, _parse);
|
|
794
|
-
this.events = new EventEmitter();
|
|
795
|
-
this.executed = [];
|
|
796
|
-
__privateAdd(this, _core, void 0);
|
|
797
|
-
__privateAdd(this, _usedPluginNames, {});
|
|
798
|
-
__privateAdd(this, _promiseManager, void 0);
|
|
799
|
-
this.resolvePath = (params) => {
|
|
800
|
-
if (params.pluginKey) {
|
|
801
|
-
const paths = this.hookForPluginSync({
|
|
802
|
-
pluginKey: params.pluginKey,
|
|
803
|
-
hookName: "resolvePath",
|
|
804
|
-
parameters: [params.baseName, params.mode, params.options]
|
|
805
|
-
});
|
|
806
|
-
if (paths && paths?.length > 1) {
|
|
807
|
-
this.logger.emit("debug", [
|
|
808
|
-
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
809
|
-
|
|
810
|
-
Paths: ${JSON.stringify(paths, void 0, 2)}
|
|
811
|
-
|
|
812
|
-
Falling back on the first item.
|
|
813
|
-
`
|
|
814
|
-
]);
|
|
815
|
-
}
|
|
816
|
-
return paths?.at(0);
|
|
817
|
-
}
|
|
818
|
-
return this.hookFirstSync({
|
|
819
|
-
hookName: "resolvePath",
|
|
820
|
-
parameters: [params.baseName, params.mode, params.options]
|
|
821
|
-
}).result;
|
|
822
|
-
};
|
|
823
|
-
this.resolveName = (params) => {
|
|
824
|
-
if (params.pluginKey) {
|
|
825
|
-
const names = this.hookForPluginSync({
|
|
826
|
-
pluginKey: params.pluginKey,
|
|
827
|
-
hookName: "resolveName",
|
|
828
|
-
parameters: [params.name, params.type]
|
|
829
|
-
});
|
|
830
|
-
if (names && names?.length > 1) {
|
|
831
|
-
this.logger.emit("debug", [
|
|
832
|
-
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
833
|
-
|
|
834
|
-
Names: ${JSON.stringify(names, void 0, 2)}
|
|
835
|
-
|
|
836
|
-
Falling back on the first item.
|
|
837
|
-
`
|
|
838
|
-
]);
|
|
839
|
-
}
|
|
840
|
-
return transformReservedWord(names?.at(0) || params.name);
|
|
841
|
-
}
|
|
842
|
-
const name = this.hookFirstSync({
|
|
843
|
-
hookName: "resolveName",
|
|
844
|
-
parameters: [params.name, params.type]
|
|
845
|
-
}).result;
|
|
846
|
-
return transformReservedWord(name);
|
|
847
|
-
};
|
|
848
|
-
this.config = config;
|
|
849
|
-
this.logger = options.logger;
|
|
850
|
-
this.queue = new PQueue2({ concurrency: 1 });
|
|
851
|
-
this.fileManager = new FileManager({
|
|
852
|
-
task: options.task,
|
|
853
|
-
queue: this.queue
|
|
854
|
-
});
|
|
855
|
-
__privateSet(this, _promiseManager, new PromiseManager({
|
|
856
|
-
nullCheck: (state) => !!state?.result
|
|
857
|
-
}));
|
|
858
|
-
const plugins = config.plugins || [];
|
|
859
|
-
const core = pluginCore({
|
|
860
|
-
config,
|
|
861
|
-
logger: this.logger,
|
|
862
|
-
pluginManager: this,
|
|
863
|
-
fileManager: this.fileManager,
|
|
864
|
-
resolvePath: this.resolvePath.bind(this),
|
|
865
|
-
resolveName: this.resolveName.bind(this),
|
|
866
|
-
getPlugins: __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).bind(this)
|
|
867
|
-
});
|
|
868
|
-
__privateSet(this, _core, __privateMethod(this, _parse, parse_fn).call(this, core, this, core.api.call(null)));
|
|
869
|
-
this.plugins = [__privateGet(this, _core), ...plugins].map((plugin) => {
|
|
870
|
-
return __privateMethod(this, _parse, parse_fn).call(this, plugin, this, __privateGet(this, _core).api);
|
|
871
|
-
});
|
|
872
|
-
return this;
|
|
873
|
-
}
|
|
874
|
-
getFile({ name, mode, extName, pluginKey, options }) {
|
|
875
|
-
let source = "";
|
|
876
|
-
const baseName = `${name}${extName}`;
|
|
877
|
-
const path3 = this.resolvePath({ baseName, mode, pluginKey, options });
|
|
878
|
-
if (!path3) {
|
|
879
|
-
throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`);
|
|
880
|
-
}
|
|
881
|
-
try {
|
|
882
|
-
source = readSync(path3);
|
|
883
|
-
} catch (_e) {
|
|
884
|
-
}
|
|
885
|
-
return {
|
|
886
|
-
path: path3,
|
|
887
|
-
baseName,
|
|
888
|
-
meta: {
|
|
889
|
-
pluginKey
|
|
890
|
-
},
|
|
891
|
-
source
|
|
892
|
-
};
|
|
893
|
-
}
|
|
894
|
-
/**
|
|
895
|
-
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
896
|
-
*/
|
|
897
|
-
on(eventName, handler) {
|
|
898
|
-
this.events.on(eventName, handler);
|
|
899
|
-
}
|
|
900
|
-
/**
|
|
901
|
-
* Run a specific hookName for plugin x.
|
|
902
|
-
*/
|
|
903
|
-
hookForPlugin({
|
|
904
|
-
pluginKey,
|
|
905
|
-
hookName,
|
|
906
|
-
parameters
|
|
907
|
-
}) {
|
|
908
|
-
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
909
|
-
const promises = plugins.map((plugin) => {
|
|
910
|
-
return __privateMethod(this, _execute, execute_fn).call(this, {
|
|
911
|
-
strategy: "hookFirst",
|
|
912
|
-
hookName,
|
|
913
|
-
parameters,
|
|
914
|
-
plugin
|
|
915
|
-
});
|
|
916
|
-
}).filter(Boolean);
|
|
917
|
-
return Promise.all(promises);
|
|
918
|
-
}
|
|
919
|
-
/**
|
|
920
|
-
* Run a specific hookName for plugin x.
|
|
921
|
-
*/
|
|
922
|
-
hookForPluginSync({
|
|
923
|
-
pluginKey,
|
|
924
|
-
hookName,
|
|
925
|
-
parameters
|
|
926
|
-
}) {
|
|
927
|
-
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
928
|
-
return plugins.map((plugin) => {
|
|
929
|
-
return __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
930
|
-
strategy: "hookFirst",
|
|
931
|
-
hookName,
|
|
932
|
-
parameters,
|
|
933
|
-
plugin
|
|
934
|
-
});
|
|
935
|
-
}).filter(Boolean);
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
* First non-null result stops and will return it's value.
|
|
939
|
-
*/
|
|
940
|
-
async hookFirst({
|
|
941
|
-
hookName,
|
|
942
|
-
parameters,
|
|
943
|
-
skipped
|
|
944
|
-
}) {
|
|
945
|
-
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).filter((plugin) => {
|
|
946
|
-
return skipped ? skipped.has(plugin) : true;
|
|
947
|
-
}).map((plugin) => {
|
|
948
|
-
return async () => {
|
|
949
|
-
const value = await __privateMethod(this, _execute, execute_fn).call(this, {
|
|
950
|
-
strategy: "hookFirst",
|
|
951
|
-
hookName,
|
|
952
|
-
parameters,
|
|
953
|
-
plugin
|
|
954
|
-
});
|
|
955
|
-
return Promise.resolve({
|
|
956
|
-
plugin,
|
|
957
|
-
result: value
|
|
958
|
-
});
|
|
959
|
-
};
|
|
960
|
-
});
|
|
961
|
-
return __privateGet(this, _promiseManager).run("first", promises);
|
|
962
|
-
}
|
|
963
|
-
/**
|
|
964
|
-
* First non-null result stops and will return it's value.
|
|
965
|
-
*/
|
|
966
|
-
hookFirstSync({
|
|
967
|
-
hookName,
|
|
968
|
-
parameters,
|
|
969
|
-
skipped
|
|
970
|
-
}) {
|
|
971
|
-
let parseResult = null;
|
|
972
|
-
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
973
|
-
if (skipped?.has(plugin)) {
|
|
974
|
-
continue;
|
|
975
|
-
}
|
|
976
|
-
parseResult = {
|
|
977
|
-
result: __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
978
|
-
strategy: "hookFirst",
|
|
979
|
-
hookName,
|
|
980
|
-
parameters,
|
|
981
|
-
plugin
|
|
982
|
-
}),
|
|
983
|
-
plugin
|
|
984
|
-
};
|
|
985
|
-
if (parseResult?.result != null) {
|
|
986
|
-
break;
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
return parseResult;
|
|
990
|
-
}
|
|
991
|
-
/**
|
|
992
|
-
* Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
|
|
993
|
-
*/
|
|
994
|
-
async hookParallel({
|
|
995
|
-
hookName,
|
|
996
|
-
parameters
|
|
997
|
-
}) {
|
|
998
|
-
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
999
|
-
return () => __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1000
|
-
strategy: "hookParallel",
|
|
1001
|
-
hookName,
|
|
1002
|
-
parameters,
|
|
1003
|
-
plugin
|
|
1004
|
-
});
|
|
1005
|
-
});
|
|
1006
|
-
const results = await __privateGet(this, _promiseManager).run("parallel", promises);
|
|
1007
|
-
results.forEach((result, index) => {
|
|
1008
|
-
if (isPromiseRejectedResult(result)) {
|
|
1009
|
-
const plugin = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)[index];
|
|
1010
|
-
__privateMethod(this, _catcher, catcher_fn).call(this, result.reason, plugin, hookName);
|
|
1011
|
-
}
|
|
1012
|
-
});
|
|
1013
|
-
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
1014
|
-
}
|
|
1015
|
-
/**
|
|
1016
|
-
* Chain all plugins, `reduce` can be passed through to handle every returned value. The return value of the first plugin will be used as the first parameter for the plugin after that.
|
|
1017
|
-
*/
|
|
1018
|
-
hookReduceArg0({
|
|
1019
|
-
hookName,
|
|
1020
|
-
parameters,
|
|
1021
|
-
reduce
|
|
1022
|
-
}) {
|
|
1023
|
-
const [argument0, ...rest] = parameters;
|
|
1024
|
-
let promise = Promise.resolve(argument0);
|
|
1025
|
-
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1026
|
-
promise = promise.then((arg0) => {
|
|
1027
|
-
const value = __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1028
|
-
strategy: "hookReduceArg0",
|
|
1029
|
-
hookName,
|
|
1030
|
-
parameters: [arg0, ...rest],
|
|
1031
|
-
plugin
|
|
1032
|
-
});
|
|
1033
|
-
return value;
|
|
1034
|
-
}).then((result) => reduce.call(__privateGet(this, _core).api, argument0, result, plugin));
|
|
1035
|
-
}
|
|
1036
|
-
return promise;
|
|
1037
|
-
}
|
|
1038
|
-
/**
|
|
1039
|
-
* Chains plugins
|
|
1040
|
-
*/
|
|
1041
|
-
async hookSeq({ hookName, parameters }) {
|
|
1042
|
-
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1043
|
-
return () => __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1044
|
-
strategy: "hookSeq",
|
|
1045
|
-
hookName,
|
|
1046
|
-
parameters,
|
|
1047
|
-
plugin
|
|
1048
|
-
});
|
|
1049
|
-
});
|
|
1050
|
-
return __privateGet(this, _promiseManager).run("seq", promises);
|
|
1051
|
-
}
|
|
1052
|
-
getPluginsByKey(hookName, pluginKey) {
|
|
1053
|
-
const plugins = [...this.plugins];
|
|
1054
|
-
const [searchPluginName, searchIdentifier] = pluginKey;
|
|
1055
|
-
const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
|
|
1056
|
-
const [name, identifier] = item.key;
|
|
1057
|
-
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1058
|
-
const nameCheck = name === searchPluginName;
|
|
1059
|
-
if (searchIdentifier) {
|
|
1060
|
-
return identifierCheck && nameCheck;
|
|
1061
|
-
}
|
|
1062
|
-
return nameCheck;
|
|
1063
|
-
});
|
|
1064
|
-
if (!pluginByPluginName?.length) {
|
|
1065
|
-
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
1066
|
-
if (corePlugin) {
|
|
1067
|
-
this.logger.emit("debug", [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`]);
|
|
1068
|
-
} else {
|
|
1069
|
-
this.logger.emit("debug", [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`]);
|
|
1070
|
-
}
|
|
1071
|
-
return corePlugin ? [corePlugin] : [];
|
|
1072
|
-
}
|
|
1073
|
-
return pluginByPluginName;
|
|
1074
|
-
}
|
|
1075
|
-
static getDependedPlugins(plugins, dependedPluginNames) {
|
|
1076
|
-
let pluginNames = [];
|
|
1077
|
-
if (typeof dependedPluginNames === "string") {
|
|
1078
|
-
pluginNames = [dependedPluginNames];
|
|
1079
|
-
} else {
|
|
1080
|
-
pluginNames = dependedPluginNames;
|
|
1081
|
-
}
|
|
1082
|
-
return pluginNames.map((pluginName) => {
|
|
1083
|
-
const plugin = plugins.find((plugin2) => plugin2.name === pluginName);
|
|
1084
|
-
if (!plugin) {
|
|
1085
|
-
throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`);
|
|
1086
|
-
}
|
|
1087
|
-
return plugin;
|
|
1088
|
-
});
|
|
1089
|
-
}
|
|
1090
|
-
static get hooks() {
|
|
1091
|
-
return ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
1092
|
-
}
|
|
1093
|
-
};
|
|
1094
|
-
_core = new WeakMap();
|
|
1095
|
-
_usedPluginNames = new WeakMap();
|
|
1096
|
-
_promiseManager = new WeakMap();
|
|
1097
|
-
_getSortedPlugins = new WeakSet();
|
|
1098
|
-
getSortedPlugins_fn = function(hookName) {
|
|
1099
|
-
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1100
|
-
if (hookName) {
|
|
1101
|
-
if (this.logger.logLevel === LogLevel.info) {
|
|
1102
|
-
const containsHookName = plugins.some((item) => item[hookName]);
|
|
1103
|
-
if (!containsHookName) {
|
|
1104
|
-
this.logger.emit("warning", `No hook ${hookName} found`);
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
return plugins.filter((item) => item[hookName]);
|
|
1108
|
-
}
|
|
1109
|
-
return plugins.map((plugin) => {
|
|
1110
|
-
if (plugin.pre) {
|
|
1111
|
-
const isValid = plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName));
|
|
1112
|
-
if (!isValid) {
|
|
1113
|
-
throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
return plugin;
|
|
1117
|
-
}).sort((a, b) => {
|
|
1118
|
-
if (b.pre?.includes(a.name)) {
|
|
1119
|
-
return 1;
|
|
1120
|
-
}
|
|
1121
|
-
if (b.post?.includes(a.name)) {
|
|
1122
|
-
return -1;
|
|
1123
|
-
}
|
|
1124
|
-
return 0;
|
|
1125
|
-
});
|
|
1126
|
-
};
|
|
1127
|
-
_addExecutedToCallStack = new WeakSet();
|
|
1128
|
-
addExecutedToCallStack_fn = function(executer) {
|
|
1129
|
-
if (executer) {
|
|
1130
|
-
this.events.emit("executed", executer);
|
|
1131
|
-
this.executed.push(executer);
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
1134
|
-
_execute = new WeakSet();
|
|
1135
|
-
execute_fn = function({
|
|
1136
|
-
strategy,
|
|
1137
|
-
hookName,
|
|
1138
|
-
parameters,
|
|
1139
|
-
plugin
|
|
1140
|
-
}) {
|
|
1141
|
-
const hook = plugin[hookName];
|
|
1142
|
-
let output;
|
|
1143
|
-
if (!hook) {
|
|
1144
|
-
return null;
|
|
1145
|
-
}
|
|
1146
|
-
this.events.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1147
|
-
const task = Promise.resolve().then(() => {
|
|
1148
|
-
if (typeof hook === "function") {
|
|
1149
|
-
const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1150
|
-
if (isPromise(possiblePromiseResult)) {
|
|
1151
|
-
return Promise.resolve(possiblePromiseResult);
|
|
1152
|
-
}
|
|
1153
|
-
return possiblePromiseResult;
|
|
1154
|
-
}
|
|
1155
|
-
return hook;
|
|
1156
|
-
}).then((result) => {
|
|
1157
|
-
output = result;
|
|
1158
|
-
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1159
|
-
parameters,
|
|
1160
|
-
output,
|
|
1161
|
-
strategy,
|
|
1162
|
-
hookName,
|
|
1163
|
-
plugin
|
|
1164
|
-
});
|
|
1165
|
-
return result;
|
|
1166
|
-
}).catch((e) => {
|
|
1167
|
-
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1168
|
-
return null;
|
|
1169
|
-
});
|
|
1170
|
-
return task;
|
|
1171
|
-
};
|
|
1172
|
-
_executeSync = new WeakSet();
|
|
1173
|
-
executeSync_fn = function({
|
|
1174
|
-
strategy,
|
|
1175
|
-
hookName,
|
|
1176
|
-
parameters,
|
|
1177
|
-
plugin
|
|
1178
|
-
}) {
|
|
1179
|
-
const hook = plugin[hookName];
|
|
1180
|
-
let output;
|
|
1181
|
-
if (!hook) {
|
|
1182
|
-
return null;
|
|
1183
|
-
}
|
|
1184
|
-
this.events.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1185
|
-
try {
|
|
1186
|
-
if (typeof hook === "function") {
|
|
1187
|
-
const fn = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1188
|
-
output = fn;
|
|
1189
|
-
return fn;
|
|
1190
|
-
}
|
|
1191
|
-
output = hook;
|
|
1192
|
-
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1193
|
-
parameters,
|
|
1194
|
-
output,
|
|
1195
|
-
strategy,
|
|
1196
|
-
hookName,
|
|
1197
|
-
plugin
|
|
1198
|
-
});
|
|
1199
|
-
return hook;
|
|
1200
|
-
} catch (e) {
|
|
1201
|
-
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1202
|
-
return null;
|
|
1203
|
-
}
|
|
1204
|
-
};
|
|
1205
|
-
_catcher = new WeakSet();
|
|
1206
|
-
catcher_fn = function(cause, plugin, hookName) {
|
|
1207
|
-
const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
|
|
1208
|
-
this.logger.emit("error", text, cause);
|
|
1209
|
-
this.events.emit("error", cause);
|
|
1210
|
-
};
|
|
1211
|
-
_parse = new WeakSet();
|
|
1212
|
-
parse_fn = function(plugin, pluginManager, context) {
|
|
1213
|
-
const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
|
|
1214
|
-
setUniqueName(plugin.name, usedPluginNames);
|
|
1215
|
-
const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
1216
|
-
if (!plugin.transform) {
|
|
1217
|
-
plugin.transform = function transform(code) {
|
|
1218
|
-
return code;
|
|
1219
|
-
};
|
|
1220
|
-
}
|
|
1221
|
-
if (plugin.api && typeof plugin.api === "function") {
|
|
1222
|
-
const api = plugin.api.call(context);
|
|
1223
|
-
return {
|
|
1224
|
-
...plugin,
|
|
1225
|
-
key,
|
|
1226
|
-
api
|
|
1227
|
-
};
|
|
1228
|
-
}
|
|
1229
|
-
return {
|
|
1230
|
-
...plugin,
|
|
1231
|
-
key
|
|
1232
|
-
};
|
|
1233
|
-
};
|
|
1234
|
-
|
|
1235
|
-
// src/config.ts
|
|
1236
|
-
function defineConfig(options) {
|
|
1237
|
-
return options;
|
|
1238
|
-
}
|
|
1239
|
-
function isInputPath(result) {
|
|
1240
|
-
return !!result && "path" in result;
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
// src/build.ts
|
|
1244
|
-
async function transformReducer(_previousCode, result, _plugin) {
|
|
1245
|
-
return result;
|
|
1246
|
-
}
|
|
1247
|
-
async function setup(options) {
|
|
1248
|
-
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1249
|
-
let count = 0;
|
|
1250
|
-
try {
|
|
1251
|
-
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
1252
|
-
await read(config.input.path);
|
|
1253
|
-
}
|
|
1254
|
-
} catch (e) {
|
|
1255
|
-
if (isInputPath(config)) {
|
|
1256
|
-
throw new Error(
|
|
1257
|
-
`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${p.dim(config.input.path)}`,
|
|
1258
|
-
{
|
|
1259
|
-
cause: e
|
|
1260
|
-
}
|
|
1261
|
-
);
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
if (config.output.clean) {
|
|
1265
|
-
await clean(config.output.path);
|
|
1266
|
-
}
|
|
1267
|
-
const task = async (file) => {
|
|
1268
|
-
const { path: path3 } = file;
|
|
1269
|
-
let source = await FileManager.getSource(file);
|
|
1270
|
-
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1271
|
-
hookName: "load",
|
|
1272
|
-
parameters: [path3]
|
|
1273
|
-
});
|
|
1274
|
-
if (loadedResult && isPromise(loadedResult)) {
|
|
1275
|
-
source = await loadedResult;
|
|
1276
|
-
}
|
|
1277
|
-
if (loadedResult && !isPromise(loadedResult)) {
|
|
1278
|
-
source = loadedResult;
|
|
1279
|
-
}
|
|
1280
|
-
if (source) {
|
|
1281
|
-
source = await pluginManager.hookReduceArg0({
|
|
1282
|
-
hookName: "transform",
|
|
1283
|
-
parameters: [source, path3],
|
|
1284
|
-
reduce: transformReducer
|
|
1285
|
-
});
|
|
1286
|
-
if (config.output.write || config.output.write === void 0) {
|
|
1287
|
-
if (file.meta?.pluginKey) {
|
|
1288
|
-
await pluginManager.hookForPlugin({
|
|
1289
|
-
pluginKey: file.meta?.pluginKey,
|
|
1290
|
-
hookName: "writeFile",
|
|
1291
|
-
parameters: [source, path3]
|
|
1292
|
-
});
|
|
1293
|
-
}
|
|
1294
|
-
await pluginManager.hookFirst({
|
|
1295
|
-
hookName: "writeFile",
|
|
1296
|
-
parameters: [source, path3]
|
|
1297
|
-
});
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
return {
|
|
1301
|
-
...file,
|
|
1302
|
-
source: source || ""
|
|
1303
|
-
};
|
|
1304
|
-
};
|
|
1305
|
-
const pluginManager = new PluginManager(config, { logger, task });
|
|
1306
|
-
pluginManager.on("execute", (executer) => {
|
|
1307
|
-
const { hookName, parameters, plugin } = executer;
|
|
1308
|
-
if (hookName === "writeFile") {
|
|
1309
|
-
const [code] = parameters;
|
|
1310
|
-
logger.emit("debug", [`PluginKey ${p.dim(JSON.stringify(plugin.key))}
|
|
1311
|
-
with source
|
|
1312
|
-
|
|
1313
|
-
${code}`]);
|
|
1314
|
-
}
|
|
1315
|
-
});
|
|
1316
|
-
pluginManager.queue.on("add", () => {
|
|
1317
|
-
if (logger.logLevel !== LogLevel.info) {
|
|
1318
|
-
return;
|
|
1319
|
-
}
|
|
1320
|
-
if (count === 0) {
|
|
1321
|
-
logger.emit("start", "\u{1F4BE} Writing");
|
|
1322
|
-
}
|
|
1323
|
-
});
|
|
1324
|
-
pluginManager.queue.on("active", () => {
|
|
1325
|
-
if (logger.logLevel !== LogLevel.info) {
|
|
1326
|
-
return;
|
|
1327
|
-
}
|
|
1328
|
-
if (logger.spinner && pluginManager.queue.size > 0) {
|
|
1329
|
-
const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`;
|
|
1330
|
-
logger.spinner.suffixText = p.dim(text);
|
|
1331
|
-
}
|
|
1332
|
-
++count;
|
|
1333
|
-
});
|
|
1334
|
-
pluginManager.queue.on("completed", () => {
|
|
1335
|
-
if (logger.logLevel !== LogLevel.info) {
|
|
1336
|
-
return;
|
|
1337
|
-
}
|
|
1338
|
-
if (logger.spinner) {
|
|
1339
|
-
const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`;
|
|
1340
|
-
logger.spinner.suffixText = p.dim(text);
|
|
1341
|
-
}
|
|
1342
|
-
});
|
|
1343
|
-
pluginManager.on("executed", (executer) => {
|
|
1344
|
-
const { hookName, plugin, output, parameters } = executer;
|
|
1345
|
-
const logs = [
|
|
1346
|
-
`${randomCliColour(plugin.name)} Executing ${hookName}`,
|
|
1347
|
-
parameters && `${p.bgWhite("Parameters")} ${randomCliColour(plugin.name)} ${hookName}`,
|
|
1348
|
-
JSON.stringify(parameters, void 0, 2),
|
|
1349
|
-
output && `${p.bgWhite("Output")} ${randomCliColour(plugin.name)} ${hookName}`,
|
|
1350
|
-
output
|
|
1351
|
-
].filter(Boolean);
|
|
1352
|
-
logger.emit("debug", logs);
|
|
1353
|
-
});
|
|
1354
|
-
return pluginManager;
|
|
1355
|
-
}
|
|
1356
|
-
async function build(options) {
|
|
1357
|
-
const pluginManager = await setup(options);
|
|
1358
|
-
const { fileManager, logger } = pluginManager;
|
|
1359
|
-
await pluginManager.hookParallel({
|
|
1360
|
-
hookName: "buildStart",
|
|
1361
|
-
parameters: [options.config]
|
|
1362
|
-
});
|
|
1363
|
-
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1364
|
-
if (logger.logLevel === LogLevel.info) {
|
|
1365
|
-
logger.emit("end", "\u{1F4BE} Writing completed");
|
|
1366
|
-
}
|
|
1367
|
-
const files = await Promise.all(
|
|
1368
|
-
fileManager.files.map(async (file) => ({
|
|
1369
|
-
...file,
|
|
1370
|
-
source: await FileManager.getSource(file)
|
|
1371
|
-
}))
|
|
1372
|
-
);
|
|
1373
|
-
return {
|
|
1374
|
-
files,
|
|
1375
|
-
pluginManager
|
|
1376
|
-
};
|
|
1377
|
-
}
|
|
1378
|
-
async function safeBuild(options) {
|
|
1379
|
-
const pluginManager = await setup(options);
|
|
1380
|
-
const { fileManager, logger } = pluginManager;
|
|
1381
|
-
try {
|
|
1382
|
-
await pluginManager.hookParallel({
|
|
1383
|
-
hookName: "buildStart",
|
|
1384
|
-
parameters: [options.config]
|
|
1385
|
-
});
|
|
1386
|
-
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1387
|
-
if (logger.logLevel === LogLevel.info) {
|
|
1388
|
-
logger.emit("end", "\u{1F4BE} Writing completed");
|
|
1389
|
-
}
|
|
1390
|
-
} catch (e) {
|
|
1391
|
-
const files2 = await Promise.all(
|
|
1392
|
-
fileManager.files.map(async (file) => ({
|
|
1393
|
-
...file,
|
|
1394
|
-
source: await FileManager.getSource(file)
|
|
1395
|
-
}))
|
|
1396
|
-
);
|
|
1397
|
-
return {
|
|
1398
|
-
files: files2,
|
|
1399
|
-
pluginManager,
|
|
1400
|
-
error: e
|
|
1401
|
-
};
|
|
1402
|
-
}
|
|
1403
|
-
const files = await Promise.all(
|
|
1404
|
-
fileManager.files.map(async (file) => ({
|
|
1405
|
-
...file,
|
|
1406
|
-
source: await FileManager.getSource(file)
|
|
1407
|
-
}))
|
|
1408
|
-
);
|
|
1409
|
-
return {
|
|
1410
|
-
files,
|
|
1411
|
-
pluginManager
|
|
1412
|
-
};
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
// src/Generator.ts
|
|
1416
|
-
var _options3, _context;
|
|
1417
|
-
var Generator = class {
|
|
1418
|
-
constructor(options, context) {
|
|
1419
|
-
__privateAdd(this, _options3, {});
|
|
1420
|
-
__privateAdd(this, _context, {});
|
|
1421
|
-
if (context) {
|
|
1422
|
-
__privateSet(this, _context, context);
|
|
1423
|
-
}
|
|
1424
|
-
if (options) {
|
|
1425
|
-
__privateSet(this, _options3, options);
|
|
1426
|
-
}
|
|
1427
|
-
return this;
|
|
1428
|
-
}
|
|
1429
|
-
get options() {
|
|
1430
|
-
return __privateGet(this, _options3);
|
|
1431
|
-
}
|
|
1432
|
-
get context() {
|
|
1433
|
-
return __privateGet(this, _context);
|
|
1434
|
-
}
|
|
1435
|
-
set options(options) {
|
|
1436
|
-
__privateSet(this, _options3, { ...__privateGet(this, _options3), ...options });
|
|
1437
|
-
}
|
|
1438
|
-
};
|
|
1439
|
-
_options3 = new WeakMap();
|
|
1440
|
-
_context = new WeakMap();
|
|
1441
|
-
|
|
1442
|
-
// src/PackageManager.ts
|
|
1443
|
-
import mod from "module";
|
|
1444
|
-
import os from "os";
|
|
1445
|
-
import { pathToFileURL } from "url";
|
|
1446
|
-
import { findUp, findUpSync } from "find-up";
|
|
1447
|
-
import { coerce, satisfies } from "semver";
|
|
1448
|
-
var _cache2, _cwd, _SLASHES, _match, match_fn;
|
|
1449
|
-
var _PackageManager = class _PackageManager {
|
|
1450
|
-
constructor(workspace) {
|
|
1451
|
-
__privateAdd(this, _match);
|
|
1452
|
-
__privateAdd(this, _cwd, void 0);
|
|
1453
|
-
__privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
|
|
1454
|
-
if (workspace) {
|
|
1455
|
-
__privateSet(this, _cwd, workspace);
|
|
1456
|
-
}
|
|
1457
|
-
return this;
|
|
1458
|
-
}
|
|
1459
|
-
set workspace(workspace) {
|
|
1460
|
-
__privateSet(this, _cwd, workspace);
|
|
1461
|
-
}
|
|
1462
|
-
get workspace() {
|
|
1463
|
-
return __privateGet(this, _cwd);
|
|
1464
|
-
}
|
|
1465
|
-
normalizeDirectory(directory) {
|
|
1466
|
-
if (!__privateGet(this, _SLASHES).has(directory[directory.length - 1])) {
|
|
1467
|
-
return `${directory}/`;
|
|
1468
|
-
}
|
|
1469
|
-
return directory;
|
|
1470
|
-
}
|
|
1471
|
-
getLocation(path3) {
|
|
1472
|
-
let location = path3;
|
|
1473
|
-
if (__privateGet(this, _cwd)) {
|
|
1474
|
-
const require2 = mod.createRequire(this.normalizeDirectory(__privateGet(this, _cwd)));
|
|
1475
|
-
location = require2.resolve(path3);
|
|
1476
|
-
}
|
|
1477
|
-
return location;
|
|
1478
|
-
}
|
|
1479
|
-
async import(path3) {
|
|
1480
|
-
try {
|
|
1481
|
-
let location = this.getLocation(path3);
|
|
1482
|
-
if (os.platform() === "win32") {
|
|
1483
|
-
location = pathToFileURL(location).href;
|
|
1484
|
-
}
|
|
1485
|
-
const module = await import(location);
|
|
1486
|
-
return module?.default ?? module;
|
|
1487
|
-
} catch (e) {
|
|
1488
|
-
console.log(e);
|
|
1489
|
-
return void 0;
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
async getPackageJSON() {
|
|
1493
|
-
const pkgPath = await findUp(["package.json"], {
|
|
1494
|
-
cwd: __privateGet(this, _cwd)
|
|
1495
|
-
});
|
|
1496
|
-
if (!pkgPath) {
|
|
1497
|
-
return void 0;
|
|
1498
|
-
}
|
|
1499
|
-
const json = await read(pkgPath);
|
|
1500
|
-
return JSON.parse(json);
|
|
1501
|
-
}
|
|
1502
|
-
getPackageJSONSync() {
|
|
1503
|
-
const pkgPath = findUpSync(["package.json"], {
|
|
1504
|
-
cwd: __privateGet(this, _cwd)
|
|
1505
|
-
});
|
|
1506
|
-
if (!pkgPath) {
|
|
1507
|
-
return void 0;
|
|
1508
|
-
}
|
|
1509
|
-
const json = readSync(pkgPath);
|
|
1510
|
-
return JSON.parse(json);
|
|
1511
|
-
}
|
|
1512
|
-
static setVersion(dependency, version) {
|
|
1513
|
-
__privateGet(_PackageManager, _cache2)[dependency] = version;
|
|
1514
|
-
}
|
|
1515
|
-
async getVersion(dependency) {
|
|
1516
|
-
if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
|
|
1517
|
-
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
1518
|
-
}
|
|
1519
|
-
const packageJSON = await this.getPackageJSON();
|
|
1520
|
-
if (!packageJSON) {
|
|
1521
|
-
return void 0;
|
|
1522
|
-
}
|
|
1523
|
-
return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
|
|
1524
|
-
}
|
|
1525
|
-
getVersionSync(dependency) {
|
|
1526
|
-
if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
|
|
1527
|
-
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
1528
|
-
}
|
|
1529
|
-
const packageJSON = this.getPackageJSONSync();
|
|
1530
|
-
if (!packageJSON) {
|
|
1531
|
-
return void 0;
|
|
1532
|
-
}
|
|
1533
|
-
return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
|
|
1534
|
-
}
|
|
1535
|
-
async isValid(dependency, version) {
|
|
1536
|
-
const packageVersion = await this.getVersion(dependency);
|
|
1537
|
-
if (!packageVersion) {
|
|
1538
|
-
return false;
|
|
1539
|
-
}
|
|
1540
|
-
if (packageVersion === version) {
|
|
1541
|
-
return true;
|
|
1542
|
-
}
|
|
1543
|
-
const semVer = coerce(packageVersion);
|
|
1544
|
-
if (!semVer) {
|
|
1545
|
-
throw new Error(`${packageVersion} is not valid`);
|
|
1546
|
-
}
|
|
1547
|
-
return satisfies(semVer, version);
|
|
1548
|
-
}
|
|
1549
|
-
isValidSync(dependency, version) {
|
|
1550
|
-
const packageVersion = this.getVersionSync(dependency);
|
|
1551
|
-
if (!packageVersion) {
|
|
1552
|
-
return false;
|
|
1553
|
-
}
|
|
1554
|
-
const semVer = coerce(packageVersion);
|
|
1555
|
-
if (!semVer) {
|
|
1556
|
-
throw new Error(`${packageVersion} is not valid`);
|
|
1557
|
-
}
|
|
1558
|
-
return satisfies(semVer, version);
|
|
1559
|
-
}
|
|
1560
|
-
};
|
|
1561
|
-
_cache2 = new WeakMap();
|
|
1562
|
-
_cwd = new WeakMap();
|
|
1563
|
-
_SLASHES = new WeakMap();
|
|
1564
|
-
_match = new WeakSet();
|
|
1565
|
-
match_fn = function(packageJSON, dependency) {
|
|
1566
|
-
const dependencies = {
|
|
1567
|
-
...packageJSON["dependencies"] || {},
|
|
1568
|
-
...packageJSON["devDependencies"] || {}
|
|
1569
|
-
};
|
|
1570
|
-
if (typeof dependency === "string" && dependencies[dependency]) {
|
|
1571
|
-
return dependencies[dependency];
|
|
1572
|
-
}
|
|
1573
|
-
const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
|
|
1574
|
-
return matchedDependency ? dependencies[matchedDependency] : void 0;
|
|
1575
|
-
};
|
|
1576
|
-
__privateAdd(_PackageManager, _cache2, {});
|
|
1577
|
-
var PackageManager = _PackageManager;
|
|
1578
|
-
|
|
1579
|
-
// src/kubb.ts
|
|
1580
|
-
var kubb_exports = {};
|
|
1581
|
-
|
|
1582
|
-
export {
|
|
1583
|
-
KubbFile,
|
|
1584
|
-
FileManager,
|
|
1585
|
-
PromiseManager,
|
|
1586
|
-
Warning,
|
|
1587
|
-
createPlugin,
|
|
1588
|
-
PluginManager,
|
|
1589
|
-
defineConfig,
|
|
1590
|
-
isInputPath,
|
|
1591
|
-
build,
|
|
1592
|
-
safeBuild,
|
|
1593
|
-
Generator,
|
|
1594
|
-
PackageManager,
|
|
1595
|
-
kubb_exports
|
|
1596
|
-
};
|
|
1597
|
-
//# sourceMappingURL=chunk-6NMPKKGV.js.map
|