@kubb/core 4.5.0 → 4.5.2
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/EventEmitter-3-rxpjGN.cjs +32 -0
- package/dist/EventEmitter-3-rxpjGN.cjs.map +1 -0
- package/dist/EventEmitter-IlDflnd2.js +25 -0
- package/dist/EventEmitter-IlDflnd2.js.map +1 -0
- package/dist/getBarrelFiles-B9LswRVo.d.cts +37 -0
- package/dist/getBarrelFiles-CB-XIF32.d.ts +37 -0
- package/dist/getBarrelFiles-D7p4n7Ug.js +962 -0
- package/dist/getBarrelFiles-D7p4n7Ug.js.map +1 -0
- package/dist/getBarrelFiles-o9ETjpTV.cjs +1017 -0
- package/dist/getBarrelFiles-o9ETjpTV.cjs.map +1 -0
- package/dist/hooks.d.cts +1 -2
- package/dist/hooks.d.ts +2 -3
- package/dist/index.cjs +83 -953
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -62
- package/dist/index.d.ts +46 -63
- package/dist/index.js +51 -921
- package/dist/index.js.map +1 -1
- package/dist/{logger-Bxe022ug.js → logger-BGuor9Uu.js} +5 -26
- package/dist/logger-BGuor9Uu.js.map +1 -0
- package/dist/{logger-BIzTtBYJ.cjs → logger-CLbtdL9m.cjs} +4 -32
- package/dist/logger-CLbtdL9m.cjs.map +1 -0
- package/dist/{logger-BwhJWK-H.d.ts → logger-weazBKCW.d.ts} +1 -1
- package/dist/logger.cjs +2 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +2 -1
- package/dist/{prompt-D5DZPtWc.cjs → prompt-39QFDCh6.cjs} +1 -1
- package/dist/{prompt-D5DZPtWc.cjs.map → prompt-39QFDCh6.cjs.map} +1 -1
- package/dist/{prompt-xM0onfy8.js → prompt-CIYhgpSM.js} +1 -1
- package/dist/{prompt-xM0onfy8.js.map → prompt-CIYhgpSM.js.map} +1 -1
- package/dist/{transformers-CeNW0G32.js → transformers-BaV4FwQd.js} +1 -1
- package/dist/{transformers-CeNW0G32.js.map → transformers-BaV4FwQd.js.map} +1 -1
- package/dist/{transformers-DWLXDYKb.cjs → transformers-BpnIvSiH.cjs} +1 -1
- package/dist/{transformers-DWLXDYKb.cjs.map → transformers-BpnIvSiH.cjs.map} +1 -1
- package/dist/transformers.cjs +1 -1
- package/dist/transformers.js +1 -1
- package/dist/{types-CyDeSlGF.d.ts → types-CqYAL0CK.d.ts} +29 -38
- package/dist/{types-CVONMhN_.d.cts → types-DqHtLxpp.d.cts} +28 -37
- package/dist/utils.cjs +7 -5
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +4 -2
- package/dist/utils.d.ts +4 -2
- package/dist/utils.js +4 -3
- package/dist/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/BarrelManager.ts +1 -1
- package/src/PluginManager.ts +74 -76
- package/src/build.ts +24 -13
- package/src/config.ts +35 -29
- package/src/definePlugin.ts +12 -0
- package/src/index.ts +5 -5
- package/src/types.ts +19 -40
- package/src/utils/AsyncEventEmitter.ts +45 -0
- package/src/utils/TreeNode.ts +1 -1
- package/src/utils/__snapshots__/barrel.json +147 -0
- package/src/{FileManager.ts → utils/getBarrelFiles.ts} +4 -11
- package/src/utils/index.ts +1 -0
- package/dist/URLPath-DbWtfVa1.js +0 -116
- package/dist/URLPath-DbWtfVa1.js.map +0 -1
- package/dist/URLPath-Dir2mxRT.cjs +0 -133
- package/dist/URLPath-Dir2mxRT.cjs.map +0 -1
- package/dist/logger-BIzTtBYJ.cjs.map +0 -1
- package/dist/logger-Bxe022ug.js.map +0 -1
- package/dist/types-DCR_QgGt.d.ts +0 -5
- package/dist/types-DueAg3XP.d.cts +0 -5
- package/src/plugin.ts +0 -80
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
const require_getBarrelFiles = require('./getBarrelFiles-o9ETjpTV.cjs');
|
|
4
|
+
const require_logger = require('./logger-CLbtdL9m.cjs');
|
|
5
|
+
require('./EventEmitter-3-rxpjGN.cjs');
|
|
6
|
+
require('./transformers-BpnIvSiH.cjs');
|
|
6
7
|
let node_path = require("node:path");
|
|
7
8
|
node_path = require_chunk.__toESM(node_path);
|
|
8
9
|
let __kubb_react_fabric = require("@kubb/react-fabric");
|
|
@@ -62,748 +63,81 @@ var BaseGenerator = class {
|
|
|
62
63
|
//#endregion
|
|
63
64
|
//#region src/config.ts
|
|
64
65
|
/**
|
|
65
|
-
*
|
|
66
|
+
* Helper for defining a Kubb configuration.
|
|
67
|
+
*
|
|
68
|
+
* Accepts either:
|
|
69
|
+
* - A config object or array of configs
|
|
70
|
+
* - A function returning the config(s), optionally async,
|
|
71
|
+
* receiving the CLI options as argument
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* export default defineConfig(({ logLevel }) => ({
|
|
75
|
+
* root: 'src',
|
|
76
|
+
* plugins: [myPlugin()],
|
|
77
|
+
* }))
|
|
66
78
|
*/
|
|
67
|
-
function defineConfig(
|
|
68
|
-
return
|
|
79
|
+
function defineConfig(config) {
|
|
80
|
+
return config;
|
|
69
81
|
}
|
|
70
|
-
|
|
71
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Type guard to check if a given config has an `input.path`.
|
|
84
|
+
*/
|
|
85
|
+
function isInputPath(config) {
|
|
86
|
+
return typeof config?.input === "object" && config.input !== null && "path" in config.input;
|
|
72
87
|
}
|
|
73
88
|
|
|
74
89
|
//#endregion
|
|
75
90
|
//#region src/fs/clean.ts
|
|
76
|
-
async function clean(path$
|
|
77
|
-
return fs_extra.default.remove(path$
|
|
91
|
+
async function clean(path$2) {
|
|
92
|
+
return fs_extra.default.remove(path$2);
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
//#endregion
|
|
81
96
|
//#region src/fs/exists.ts
|
|
82
97
|
const reader$1 = (0, js_runtime.switcher)({
|
|
83
|
-
node: async (path$
|
|
84
|
-
return fs_extra.default.pathExists(path$
|
|
98
|
+
node: async (path$2) => {
|
|
99
|
+
return fs_extra.default.pathExists(path$2);
|
|
85
100
|
},
|
|
86
|
-
bun: async (path$
|
|
87
|
-
return Bun.file(path$
|
|
101
|
+
bun: async (path$2) => {
|
|
102
|
+
return Bun.file(path$2).exists();
|
|
88
103
|
}
|
|
89
104
|
}, "node");
|
|
90
105
|
const syncReader$1 = (0, js_runtime.switcher)({
|
|
91
|
-
node: (path$
|
|
92
|
-
return fs_extra.default.pathExistsSync(path$
|
|
106
|
+
node: (path$2) => {
|
|
107
|
+
return fs_extra.default.pathExistsSync(path$2);
|
|
93
108
|
},
|
|
94
109
|
bun: () => {
|
|
95
110
|
throw new Error("Bun cannot read sync");
|
|
96
111
|
}
|
|
97
112
|
}, "node");
|
|
98
|
-
async function exists(path$
|
|
99
|
-
return reader$1(path$
|
|
113
|
+
async function exists(path$2) {
|
|
114
|
+
return reader$1(path$2);
|
|
100
115
|
}
|
|
101
116
|
|
|
102
117
|
//#endregion
|
|
103
118
|
//#region src/fs/read.ts
|
|
104
119
|
const reader = (0, js_runtime.switcher)({
|
|
105
|
-
node: async (path$
|
|
106
|
-
return fs_extra.default.readFile(path$
|
|
120
|
+
node: async (path$2) => {
|
|
121
|
+
return fs_extra.default.readFile(path$2, { encoding: "utf8" });
|
|
107
122
|
},
|
|
108
|
-
bun: async (path$
|
|
109
|
-
return Bun.file(path$
|
|
123
|
+
bun: async (path$2) => {
|
|
124
|
+
return Bun.file(path$2).text();
|
|
110
125
|
}
|
|
111
126
|
}, "node");
|
|
112
127
|
const syncReader = (0, js_runtime.switcher)({
|
|
113
|
-
node: (path$
|
|
114
|
-
return fs_extra.default.readFileSync(path$
|
|
128
|
+
node: (path$2) => {
|
|
129
|
+
return fs_extra.default.readFileSync(path$2, { encoding: "utf8" });
|
|
115
130
|
},
|
|
116
131
|
bun: () => {
|
|
117
132
|
throw new Error("Bun cannot read sync");
|
|
118
133
|
}
|
|
119
134
|
}, "node");
|
|
120
|
-
async function read(path$
|
|
121
|
-
return reader(path$
|
|
122
|
-
}
|
|
123
|
-
function readSync(path$3) {
|
|
124
|
-
return syncReader(path$3);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
//#endregion
|
|
128
|
-
//#region src/fs/utils.ts
|
|
129
|
-
function slash(path$3, platform = "linux") {
|
|
130
|
-
const isWindowsPath = /^\\\\\?\\/.test(path$3);
|
|
131
|
-
const normalizedPath = (0, node_path.normalize)(path$3);
|
|
132
|
-
if (["linux", "mac"].includes(platform) && !isWindowsPath) return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
|
|
133
|
-
return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
|
|
134
|
-
}
|
|
135
|
-
function getRelativePath(rootDir, filePath, platform = "linux") {
|
|
136
|
-
if (!rootDir || !filePath) throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
|
|
137
|
-
const slashedPath = slash((0, node_path.relative)(rootDir, filePath), platform);
|
|
138
|
-
if (slashedPath.startsWith("../")) return slashedPath;
|
|
139
|
-
return `./${slashedPath}`;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
//#endregion
|
|
143
|
-
//#region src/errors.ts
|
|
144
|
-
var ValidationPluginError = class extends Error {};
|
|
145
|
-
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region ../../node_modules/.pnpm/yocto-queue@1.2.1/node_modules/yocto-queue/index.js
|
|
148
|
-
var Node = class {
|
|
149
|
-
value;
|
|
150
|
-
next;
|
|
151
|
-
constructor(value) {
|
|
152
|
-
this.value = value;
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
var Queue = class {
|
|
156
|
-
#head;
|
|
157
|
-
#tail;
|
|
158
|
-
#size;
|
|
159
|
-
constructor() {
|
|
160
|
-
this.clear();
|
|
161
|
-
}
|
|
162
|
-
enqueue(value) {
|
|
163
|
-
const node = new Node(value);
|
|
164
|
-
if (this.#head) {
|
|
165
|
-
this.#tail.next = node;
|
|
166
|
-
this.#tail = node;
|
|
167
|
-
} else {
|
|
168
|
-
this.#head = node;
|
|
169
|
-
this.#tail = node;
|
|
170
|
-
}
|
|
171
|
-
this.#size++;
|
|
172
|
-
}
|
|
173
|
-
dequeue() {
|
|
174
|
-
const current = this.#head;
|
|
175
|
-
if (!current) return;
|
|
176
|
-
this.#head = this.#head.next;
|
|
177
|
-
this.#size--;
|
|
178
|
-
return current.value;
|
|
179
|
-
}
|
|
180
|
-
peek() {
|
|
181
|
-
if (!this.#head) return;
|
|
182
|
-
return this.#head.value;
|
|
183
|
-
}
|
|
184
|
-
clear() {
|
|
185
|
-
this.#head = void 0;
|
|
186
|
-
this.#tail = void 0;
|
|
187
|
-
this.#size = 0;
|
|
188
|
-
}
|
|
189
|
-
get size() {
|
|
190
|
-
return this.#size;
|
|
191
|
-
}
|
|
192
|
-
*[Symbol.iterator]() {
|
|
193
|
-
let current = this.#head;
|
|
194
|
-
while (current) {
|
|
195
|
-
yield current.value;
|
|
196
|
-
current = current.next;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
*drain() {
|
|
200
|
-
while (this.#head) yield this.dequeue();
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
//#endregion
|
|
205
|
-
//#region ../../node_modules/.pnpm/p-limit@7.2.0/node_modules/p-limit/index.js
|
|
206
|
-
function pLimit$1(concurrency) {
|
|
207
|
-
validateConcurrency(concurrency);
|
|
208
|
-
const queue = new Queue();
|
|
209
|
-
let activeCount = 0;
|
|
210
|
-
const resumeNext = () => {
|
|
211
|
-
if (activeCount < concurrency && queue.size > 0) {
|
|
212
|
-
activeCount++;
|
|
213
|
-
queue.dequeue()();
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
const next = () => {
|
|
217
|
-
activeCount--;
|
|
218
|
-
resumeNext();
|
|
219
|
-
};
|
|
220
|
-
const run = async (function_, resolve$1, arguments_) => {
|
|
221
|
-
const result = (async () => function_(...arguments_))();
|
|
222
|
-
resolve$1(result);
|
|
223
|
-
try {
|
|
224
|
-
await result;
|
|
225
|
-
} catch {}
|
|
226
|
-
next();
|
|
227
|
-
};
|
|
228
|
-
const enqueue = (function_, resolve$1, arguments_) => {
|
|
229
|
-
new Promise((internalResolve) => {
|
|
230
|
-
queue.enqueue(internalResolve);
|
|
231
|
-
}).then(run.bind(void 0, function_, resolve$1, arguments_));
|
|
232
|
-
if (activeCount < concurrency) resumeNext();
|
|
233
|
-
};
|
|
234
|
-
const generator = (function_, ...arguments_) => new Promise((resolve$1) => {
|
|
235
|
-
enqueue(function_, resolve$1, arguments_);
|
|
236
|
-
});
|
|
237
|
-
Object.defineProperties(generator, {
|
|
238
|
-
activeCount: { get: () => activeCount },
|
|
239
|
-
pendingCount: { get: () => queue.size },
|
|
240
|
-
clearQueue: { value() {
|
|
241
|
-
queue.clear();
|
|
242
|
-
} },
|
|
243
|
-
concurrency: {
|
|
244
|
-
get: () => concurrency,
|
|
245
|
-
set(newConcurrency) {
|
|
246
|
-
validateConcurrency(newConcurrency);
|
|
247
|
-
concurrency = newConcurrency;
|
|
248
|
-
queueMicrotask(() => {
|
|
249
|
-
while (activeCount < concurrency && queue.size > 0) resumeNext();
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
map: { async value(iterable, function_) {
|
|
254
|
-
const promises = Array.from(iterable, (value, index) => this(function_, value, index));
|
|
255
|
-
return Promise.all(promises);
|
|
256
|
-
} }
|
|
257
|
-
});
|
|
258
|
-
return generator;
|
|
259
|
-
}
|
|
260
|
-
function validateConcurrency(concurrency) {
|
|
261
|
-
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/utils/executeStrategies.ts
|
|
266
|
-
/**
|
|
267
|
-
* Chains promises
|
|
268
|
-
*/
|
|
269
|
-
function hookSeq(promises) {
|
|
270
|
-
return promises.filter(Boolean).reduce((promise, func) => {
|
|
271
|
-
if (typeof func !== "function") throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
272
|
-
return promise.then((state) => {
|
|
273
|
-
const calledFunc = func(state);
|
|
274
|
-
if (calledFunc) return calledFunc.then(Array.prototype.concat.bind(state));
|
|
275
|
-
});
|
|
276
|
-
}, Promise.resolve([]));
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Chains promises, first non-null result stops and returns
|
|
280
|
-
*/
|
|
281
|
-
function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
282
|
-
let promise = Promise.resolve(null);
|
|
283
|
-
for (const func of promises.filter(Boolean)) promise = promise.then((state) => {
|
|
284
|
-
if (nullCheck(state)) return state;
|
|
285
|
-
return func(state);
|
|
286
|
-
});
|
|
287
|
-
return promise;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Runs an array of promise functions with optional concurrency limit.
|
|
291
|
-
*/
|
|
292
|
-
function hookParallel(promises, concurrency = Number.POSITIVE_INFINITY) {
|
|
293
|
-
const limit = pLimit$1(concurrency);
|
|
294
|
-
const tasks = promises.filter(Boolean).map((promise) => limit(() => promise()));
|
|
295
|
-
return Promise.allSettled(tasks);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
//#endregion
|
|
299
|
-
//#region src/PromiseManager.ts
|
|
300
|
-
var PromiseManager = class {
|
|
301
|
-
#options = {};
|
|
302
|
-
constructor(options = {}) {
|
|
303
|
-
this.#options = options;
|
|
304
|
-
return this;
|
|
305
|
-
}
|
|
306
|
-
run(strategy, promises, { concurrency = Number.POSITIVE_INFINITY } = {}) {
|
|
307
|
-
if (strategy === "seq") return hookSeq(promises);
|
|
308
|
-
if (strategy === "first") return hookFirst(promises, this.#options.nullCheck);
|
|
309
|
-
if (strategy === "parallel") return hookParallel(promises, concurrency);
|
|
310
|
-
throw new Error(`${strategy} not implemented`);
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
function isPromiseRejectedResult(result) {
|
|
314
|
-
return result.status === "rejected";
|
|
135
|
+
async function read(path$2) {
|
|
136
|
+
return reader(path$2);
|
|
315
137
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
//#region src/plugin.ts
|
|
319
|
-
function createPlugin(factory) {
|
|
320
|
-
return (options = {}) => {
|
|
321
|
-
return factory(options);
|
|
322
|
-
};
|
|
138
|
+
function readSync(path$2) {
|
|
139
|
+
return syncReader(path$2);
|
|
323
140
|
}
|
|
324
|
-
const pluginCore = createPlugin((options) => {
|
|
325
|
-
const { fabric, pluginManager, resolvePath, resolveName, logger } = options;
|
|
326
|
-
return {
|
|
327
|
-
name: "core",
|
|
328
|
-
options,
|
|
329
|
-
key: ["core"],
|
|
330
|
-
context() {
|
|
331
|
-
return {
|
|
332
|
-
get fabric() {
|
|
333
|
-
return fabric;
|
|
334
|
-
},
|
|
335
|
-
get config() {
|
|
336
|
-
return options.config;
|
|
337
|
-
},
|
|
338
|
-
get plugins() {
|
|
339
|
-
return options.getPlugins();
|
|
340
|
-
},
|
|
341
|
-
get plugin() {
|
|
342
|
-
return options.plugin;
|
|
343
|
-
},
|
|
344
|
-
logger,
|
|
345
|
-
get fileManager() {
|
|
346
|
-
return fabric.context.fileManager;
|
|
347
|
-
},
|
|
348
|
-
pluginManager,
|
|
349
|
-
async addFile(...files) {
|
|
350
|
-
const resolvedFiles = await fabric.context.fileManager.add(...files);
|
|
351
|
-
if (!Array.isArray(resolvedFiles)) return [resolvedFiles];
|
|
352
|
-
return resolvedFiles;
|
|
353
|
-
},
|
|
354
|
-
resolvePath,
|
|
355
|
-
resolveName
|
|
356
|
-
};
|
|
357
|
-
},
|
|
358
|
-
resolvePath(baseName) {
|
|
359
|
-
const root = node_path.default.resolve(options.config.root, options.config.output.path);
|
|
360
|
-
return node_path.default.resolve(root, baseName);
|
|
361
|
-
},
|
|
362
|
-
resolveName(name) {
|
|
363
|
-
return name;
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
//#endregion
|
|
369
|
-
//#region src/PluginManager.ts
|
|
370
|
-
var PluginManager = class {
|
|
371
|
-
plugins = /* @__PURE__ */ new Set();
|
|
372
|
-
events = new require_logger.EventEmitter();
|
|
373
|
-
config;
|
|
374
|
-
executed = [];
|
|
375
|
-
logger;
|
|
376
|
-
options;
|
|
377
|
-
#core;
|
|
378
|
-
#usedPluginNames = {};
|
|
379
|
-
#promiseManager;
|
|
380
|
-
constructor(config, options) {
|
|
381
|
-
this.config = config;
|
|
382
|
-
this.options = options;
|
|
383
|
-
this.logger = options.logger;
|
|
384
|
-
this.#promiseManager = new PromiseManager({ nullCheck: (state) => !!state?.result });
|
|
385
|
-
const core = pluginCore({
|
|
386
|
-
fabric: options.fabric,
|
|
387
|
-
config,
|
|
388
|
-
logger: this.logger,
|
|
389
|
-
pluginManager: this,
|
|
390
|
-
resolvePath: this.resolvePath.bind(this),
|
|
391
|
-
resolveName: this.resolveName.bind(this),
|
|
392
|
-
getPlugins: this.#getSortedPlugins.bind(this)
|
|
393
|
-
});
|
|
394
|
-
this.#core = this.#parse(core, this, core.context.call(null));
|
|
395
|
-
[this.#core, ...config.plugins || []].forEach((plugin) => {
|
|
396
|
-
const parsedPlugin = this.#parse(plugin, this, this.#core.context);
|
|
397
|
-
this.plugins.add(parsedPlugin);
|
|
398
|
-
});
|
|
399
|
-
return this;
|
|
400
|
-
}
|
|
401
|
-
getFile({ name, mode, extname: extname$1, pluginKey, options }) {
|
|
402
|
-
const baseName = `${name}${extname$1}`;
|
|
403
|
-
const path$3 = this.resolvePath({
|
|
404
|
-
baseName,
|
|
405
|
-
mode,
|
|
406
|
-
pluginKey,
|
|
407
|
-
options
|
|
408
|
-
});
|
|
409
|
-
if (!path$3) throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`);
|
|
410
|
-
return {
|
|
411
|
-
path: path$3,
|
|
412
|
-
baseName,
|
|
413
|
-
meta: { pluginKey },
|
|
414
|
-
sources: []
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
resolvePath = (params) => {
|
|
418
|
-
if (params.pluginKey) {
|
|
419
|
-
const paths = this.hookForPluginSync({
|
|
420
|
-
pluginKey: params.pluginKey,
|
|
421
|
-
hookName: "resolvePath",
|
|
422
|
-
parameters: [
|
|
423
|
-
params.baseName,
|
|
424
|
-
params.mode,
|
|
425
|
-
params.options
|
|
426
|
-
],
|
|
427
|
-
message: `Resolving path '${params.baseName}'`
|
|
428
|
-
});
|
|
429
|
-
if (paths && paths?.length > 1) this.logger.emit("debug", {
|
|
430
|
-
date: /* @__PURE__ */ new Date(),
|
|
431
|
-
logs: [`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : "\""} is not unique enough\n\nPaths: ${JSON.stringify(paths, void 0, 2)}\n\nFalling back on the first item.\n`]
|
|
432
|
-
});
|
|
433
|
-
return paths?.at(0);
|
|
434
|
-
}
|
|
435
|
-
return this.hookFirstSync({
|
|
436
|
-
hookName: "resolvePath",
|
|
437
|
-
parameters: [
|
|
438
|
-
params.baseName,
|
|
439
|
-
params.mode,
|
|
440
|
-
params.options
|
|
441
|
-
],
|
|
442
|
-
message: `Resolving path '${params.baseName}'`
|
|
443
|
-
}).result;
|
|
444
|
-
};
|
|
445
|
-
resolveName = (params) => {
|
|
446
|
-
if (params.pluginKey) {
|
|
447
|
-
const names = this.hookForPluginSync({
|
|
448
|
-
pluginKey: params.pluginKey,
|
|
449
|
-
hookName: "resolveName",
|
|
450
|
-
parameters: [require_transformers.trim(params.name), params.type],
|
|
451
|
-
message: `Resolving name '${params.name}' and type '${params.type}'`
|
|
452
|
-
});
|
|
453
|
-
if (names && names?.length > 1) this.logger.emit("debug", {
|
|
454
|
-
date: /* @__PURE__ */ new Date(),
|
|
455
|
-
logs: [`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : "\""} is not unique enough\n\nNames: ${JSON.stringify(names, void 0, 2)}\n\nFalling back on the first item.\n`]
|
|
456
|
-
});
|
|
457
|
-
return require_transformers.transformReservedWord(names?.at(0) || params.name);
|
|
458
|
-
}
|
|
459
|
-
const name = this.hookFirstSync({
|
|
460
|
-
hookName: "resolveName",
|
|
461
|
-
parameters: [require_transformers.trim(params.name), params.type],
|
|
462
|
-
message: `Resolving name '${params.name}' and type '${params.type}'`
|
|
463
|
-
}).result;
|
|
464
|
-
return require_transformers.transformReservedWord(name);
|
|
465
|
-
};
|
|
466
|
-
/**
|
|
467
|
-
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
468
|
-
*/
|
|
469
|
-
on(eventName, handler) {
|
|
470
|
-
this.events.on(eventName, handler);
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Run a specific hookName for plugin x.
|
|
474
|
-
*/
|
|
475
|
-
async hookForPlugin({ pluginKey, hookName, parameters, message }) {
|
|
476
|
-
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
477
|
-
this.logger.emit("progress_start", {
|
|
478
|
-
id: hookName,
|
|
479
|
-
size: plugins.length,
|
|
480
|
-
message: "Running plugins..."
|
|
481
|
-
});
|
|
482
|
-
const items = [];
|
|
483
|
-
for (const plugin of plugins) {
|
|
484
|
-
const result = await this.#execute({
|
|
485
|
-
strategy: "hookFirst",
|
|
486
|
-
hookName,
|
|
487
|
-
parameters,
|
|
488
|
-
plugin,
|
|
489
|
-
message
|
|
490
|
-
});
|
|
491
|
-
if (result !== void 0 && result !== null) items.push(result);
|
|
492
|
-
}
|
|
493
|
-
this.logger.emit("progress_stop", { id: hookName });
|
|
494
|
-
return items;
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* Run a specific hookName for plugin x.
|
|
498
|
-
*/
|
|
499
|
-
hookForPluginSync({ pluginKey, hookName, parameters, message }) {
|
|
500
|
-
return this.getPluginsByKey(hookName, pluginKey).map((plugin) => {
|
|
501
|
-
return this.#executeSync({
|
|
502
|
-
strategy: "hookFirst",
|
|
503
|
-
hookName,
|
|
504
|
-
parameters,
|
|
505
|
-
plugin,
|
|
506
|
-
message
|
|
507
|
-
});
|
|
508
|
-
}).filter(Boolean);
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* First non-null result stops and will return it's value.
|
|
512
|
-
*/
|
|
513
|
-
async hookFirst({ hookName, parameters, skipped, message }) {
|
|
514
|
-
const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
|
|
515
|
-
return skipped ? skipped.has(plugin) : true;
|
|
516
|
-
});
|
|
517
|
-
this.logger.emit("progress_start", {
|
|
518
|
-
id: hookName,
|
|
519
|
-
size: plugins.length
|
|
520
|
-
});
|
|
521
|
-
const promises = plugins.map((plugin) => {
|
|
522
|
-
return async () => {
|
|
523
|
-
const value = await this.#execute({
|
|
524
|
-
strategy: "hookFirst",
|
|
525
|
-
hookName,
|
|
526
|
-
parameters,
|
|
527
|
-
plugin,
|
|
528
|
-
message
|
|
529
|
-
});
|
|
530
|
-
return Promise.resolve({
|
|
531
|
-
plugin,
|
|
532
|
-
result: value
|
|
533
|
-
});
|
|
534
|
-
};
|
|
535
|
-
});
|
|
536
|
-
const result = await this.#promiseManager.run("first", promises);
|
|
537
|
-
this.logger.emit("progress_stop", { id: hookName });
|
|
538
|
-
return result;
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* First non-null result stops and will return it's value.
|
|
542
|
-
*/
|
|
543
|
-
hookFirstSync({ hookName, parameters, skipped, message }) {
|
|
544
|
-
let parseResult = null;
|
|
545
|
-
const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
|
|
546
|
-
return skipped ? skipped.has(plugin) : true;
|
|
547
|
-
});
|
|
548
|
-
for (const plugin of plugins) {
|
|
549
|
-
parseResult = {
|
|
550
|
-
result: this.#executeSync({
|
|
551
|
-
strategy: "hookFirst",
|
|
552
|
-
hookName,
|
|
553
|
-
parameters,
|
|
554
|
-
plugin,
|
|
555
|
-
message
|
|
556
|
-
}),
|
|
557
|
-
plugin
|
|
558
|
-
};
|
|
559
|
-
if (parseResult?.result != null) break;
|
|
560
|
-
}
|
|
561
|
-
return parseResult;
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
|
|
565
|
-
*/
|
|
566
|
-
async hookParallel({ hookName, parameters, message }) {
|
|
567
|
-
const plugins = this.#getSortedPlugins(hookName);
|
|
568
|
-
this.logger.emit("progress_start", {
|
|
569
|
-
id: hookName,
|
|
570
|
-
size: plugins.length
|
|
571
|
-
});
|
|
572
|
-
const promises = plugins.map((plugin) => {
|
|
573
|
-
return () => this.#execute({
|
|
574
|
-
strategy: "hookParallel",
|
|
575
|
-
hookName,
|
|
576
|
-
parameters,
|
|
577
|
-
plugin,
|
|
578
|
-
message
|
|
579
|
-
});
|
|
580
|
-
});
|
|
581
|
-
const results = await this.#promiseManager.run("parallel", promises, { concurrency: this.options.concurrency });
|
|
582
|
-
results.forEach((result, index) => {
|
|
583
|
-
if (isPromiseRejectedResult(result)) {
|
|
584
|
-
const plugin = this.#getSortedPlugins(hookName)[index];
|
|
585
|
-
this.#catcher(result.reason, plugin, hookName);
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
this.logger.emit("progress_stop", { id: hookName });
|
|
589
|
-
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* Chains plugins
|
|
593
|
-
*/
|
|
594
|
-
async hookSeq({ hookName, parameters, message }) {
|
|
595
|
-
const plugins = this.#getSortedPlugins(hookName);
|
|
596
|
-
this.logger.emit("progress_start", {
|
|
597
|
-
id: hookName,
|
|
598
|
-
size: plugins.length
|
|
599
|
-
});
|
|
600
|
-
const promises = plugins.map((plugin) => {
|
|
601
|
-
return () => this.#execute({
|
|
602
|
-
strategy: "hookSeq",
|
|
603
|
-
hookName,
|
|
604
|
-
parameters,
|
|
605
|
-
plugin,
|
|
606
|
-
message
|
|
607
|
-
});
|
|
608
|
-
});
|
|
609
|
-
await this.#promiseManager.run("seq", promises);
|
|
610
|
-
this.logger.emit("progress_stop", { id: hookName });
|
|
611
|
-
}
|
|
612
|
-
#getSortedPlugins(hookName) {
|
|
613
|
-
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
614
|
-
if (hookName) return plugins.filter((plugin) => hookName in plugin);
|
|
615
|
-
return plugins.map((plugin) => {
|
|
616
|
-
if (plugin.pre) {
|
|
617
|
-
if (!plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName))) throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
|
|
618
|
-
}
|
|
619
|
-
return plugin;
|
|
620
|
-
}).sort((a, b) => {
|
|
621
|
-
if (b.pre?.includes(a.name)) return 1;
|
|
622
|
-
if (b.post?.includes(a.name)) return -1;
|
|
623
|
-
return 0;
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
getPluginByKey(pluginKey) {
|
|
627
|
-
const plugins = [...this.plugins];
|
|
628
|
-
const [searchPluginName] = pluginKey;
|
|
629
|
-
return plugins.find((item) => {
|
|
630
|
-
const [name] = item.key;
|
|
631
|
-
return name === searchPluginName;
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
getPluginsByKey(hookName, pluginKey) {
|
|
635
|
-
const plugins = [...this.plugins];
|
|
636
|
-
const [searchPluginName, searchIdentifier] = pluginKey;
|
|
637
|
-
const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => {
|
|
638
|
-
const [name, identifier] = item.key;
|
|
639
|
-
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
640
|
-
const nameCheck = name === searchPluginName;
|
|
641
|
-
if (searchIdentifier) return identifierCheck && nameCheck;
|
|
642
|
-
return nameCheck;
|
|
643
|
-
});
|
|
644
|
-
if (!pluginByPluginName?.length) {
|
|
645
|
-
const corePlugin = plugins.find((plugin) => plugin.name === "core" && hookName in plugin);
|
|
646
|
-
if (corePlugin) this.logger.emit("debug", {
|
|
647
|
-
date: /* @__PURE__ */ new Date(),
|
|
648
|
-
logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`]
|
|
649
|
-
});
|
|
650
|
-
else this.logger.emit("debug", {
|
|
651
|
-
date: /* @__PURE__ */ new Date(),
|
|
652
|
-
logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`]
|
|
653
|
-
});
|
|
654
|
-
return corePlugin ? [corePlugin] : [];
|
|
655
|
-
}
|
|
656
|
-
return pluginByPluginName;
|
|
657
|
-
}
|
|
658
|
-
#addExecutedToCallStack(executer) {
|
|
659
|
-
if (executer) {
|
|
660
|
-
this.events.emit("executed", executer);
|
|
661
|
-
this.executed.push(executer);
|
|
662
|
-
this.logger.emit("progressed", {
|
|
663
|
-
id: executer.hookName,
|
|
664
|
-
message: `${executer.plugin.name}: ${executer.message}`
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
/**
|
|
669
|
-
* Run an async plugin hook and return the result.
|
|
670
|
-
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
671
|
-
* @param args Arguments passed to the plugin hook.
|
|
672
|
-
* @param plugin The actual pluginObject to run.
|
|
673
|
-
*/
|
|
674
|
-
#execute({ strategy, hookName, parameters, plugin, message }) {
|
|
675
|
-
const hook = plugin[hookName];
|
|
676
|
-
let output;
|
|
677
|
-
if (!hook) return null;
|
|
678
|
-
this.events.emit("executing", {
|
|
679
|
-
strategy,
|
|
680
|
-
hookName,
|
|
681
|
-
parameters,
|
|
682
|
-
plugin,
|
|
683
|
-
message
|
|
684
|
-
});
|
|
685
|
-
return (async () => {
|
|
686
|
-
try {
|
|
687
|
-
if (typeof hook === "function") {
|
|
688
|
-
const result = await Promise.resolve(hook.apply({
|
|
689
|
-
...this.#core.context,
|
|
690
|
-
plugin
|
|
691
|
-
}, parameters));
|
|
692
|
-
output = result;
|
|
693
|
-
this.#addExecutedToCallStack({
|
|
694
|
-
parameters,
|
|
695
|
-
output,
|
|
696
|
-
strategy,
|
|
697
|
-
hookName,
|
|
698
|
-
plugin,
|
|
699
|
-
message
|
|
700
|
-
});
|
|
701
|
-
return result;
|
|
702
|
-
}
|
|
703
|
-
output = hook;
|
|
704
|
-
this.#addExecutedToCallStack({
|
|
705
|
-
parameters,
|
|
706
|
-
output,
|
|
707
|
-
strategy,
|
|
708
|
-
hookName,
|
|
709
|
-
plugin,
|
|
710
|
-
message
|
|
711
|
-
});
|
|
712
|
-
return hook;
|
|
713
|
-
} catch (e) {
|
|
714
|
-
this.#catcher(e, plugin, hookName);
|
|
715
|
-
return null;
|
|
716
|
-
}
|
|
717
|
-
})();
|
|
718
|
-
}
|
|
719
|
-
/**
|
|
720
|
-
* Run a sync plugin hook and return the result.
|
|
721
|
-
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
722
|
-
* @param args Arguments passed to the plugin hook.
|
|
723
|
-
* @param plugin The acutal plugin
|
|
724
|
-
* @param replaceContext When passed, the plugin context can be overridden.
|
|
725
|
-
*/
|
|
726
|
-
#executeSync({ strategy, hookName, parameters, plugin, message }) {
|
|
727
|
-
const hook = plugin[hookName];
|
|
728
|
-
let output;
|
|
729
|
-
if (!hook) return null;
|
|
730
|
-
this.events.emit("executing", {
|
|
731
|
-
strategy,
|
|
732
|
-
hookName,
|
|
733
|
-
parameters,
|
|
734
|
-
plugin,
|
|
735
|
-
message
|
|
736
|
-
});
|
|
737
|
-
try {
|
|
738
|
-
if (typeof hook === "function") {
|
|
739
|
-
const fn = hook.apply({
|
|
740
|
-
...this.#core.context,
|
|
741
|
-
plugin
|
|
742
|
-
}, parameters);
|
|
743
|
-
output = fn;
|
|
744
|
-
this.#addExecutedToCallStack({
|
|
745
|
-
parameters,
|
|
746
|
-
output,
|
|
747
|
-
strategy,
|
|
748
|
-
hookName,
|
|
749
|
-
plugin,
|
|
750
|
-
message
|
|
751
|
-
});
|
|
752
|
-
return fn;
|
|
753
|
-
}
|
|
754
|
-
output = hook;
|
|
755
|
-
this.#addExecutedToCallStack({
|
|
756
|
-
parameters,
|
|
757
|
-
output,
|
|
758
|
-
strategy,
|
|
759
|
-
hookName,
|
|
760
|
-
plugin,
|
|
761
|
-
message
|
|
762
|
-
});
|
|
763
|
-
return hook;
|
|
764
|
-
} catch (e) {
|
|
765
|
-
this.#catcher(e, plugin, hookName);
|
|
766
|
-
return null;
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
#catcher(cause, plugin, hookName) {
|
|
770
|
-
const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
|
|
771
|
-
this.logger.emit("error", text, cause);
|
|
772
|
-
this.events.emit("error", cause);
|
|
773
|
-
}
|
|
774
|
-
#parse(plugin, pluginManager, context) {
|
|
775
|
-
const usedPluginNames = pluginManager.#usedPluginNames;
|
|
776
|
-
require_URLPath.setUniqueName(plugin.name, usedPluginNames);
|
|
777
|
-
const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
778
|
-
if (plugin.context && typeof plugin.context === "function") return {
|
|
779
|
-
...plugin,
|
|
780
|
-
key,
|
|
781
|
-
context: plugin.context.call(context)
|
|
782
|
-
};
|
|
783
|
-
return {
|
|
784
|
-
...plugin,
|
|
785
|
-
key
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
static getDependedPlugins(plugins, dependedPluginNames) {
|
|
789
|
-
let pluginNames = [];
|
|
790
|
-
if (typeof dependedPluginNames === "string") pluginNames = [dependedPluginNames];
|
|
791
|
-
else pluginNames = dependedPluginNames;
|
|
792
|
-
return pluginNames.map((pluginName) => {
|
|
793
|
-
const plugin = plugins.find((plugin$1) => plugin$1.name === pluginName);
|
|
794
|
-
if (!plugin) throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`);
|
|
795
|
-
return plugin;
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
static get hooks() {
|
|
799
|
-
return [
|
|
800
|
-
"buildStart",
|
|
801
|
-
"resolvePath",
|
|
802
|
-
"resolveName",
|
|
803
|
-
"buildEnd"
|
|
804
|
-
];
|
|
805
|
-
}
|
|
806
|
-
};
|
|
807
141
|
|
|
808
142
|
//#endregion
|
|
809
143
|
//#region src/build.ts
|
|
@@ -811,7 +145,7 @@ async function setup(options) {
|
|
|
811
145
|
const { config: userConfig, logger = require_logger.createLogger() } = options;
|
|
812
146
|
if (Array.isArray(userConfig.input)) console.warn(picocolors.default.yellow("This feature is still under development — use with caution"));
|
|
813
147
|
try {
|
|
814
|
-
if (isInputPath(userConfig) && !new
|
|
148
|
+
if (isInputPath(userConfig) && !new require_getBarrelFiles.URLPath(userConfig.input.path).isURL) await exists(userConfig.input.path);
|
|
815
149
|
} catch (e) {
|
|
816
150
|
if (isInputPath(userConfig)) throw new Error(`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`, { cause: e });
|
|
817
151
|
}
|
|
@@ -836,7 +170,7 @@ async function setup(options) {
|
|
|
836
170
|
fabric.use(__kubb_react_fabric_parsers.typescriptParser);
|
|
837
171
|
return {
|
|
838
172
|
fabric,
|
|
839
|
-
pluginManager: new PluginManager(definedConfig, {
|
|
173
|
+
pluginManager: new require_getBarrelFiles.PluginManager(definedConfig, {
|
|
840
174
|
fabric,
|
|
841
175
|
logger,
|
|
842
176
|
concurrency: 5
|
|
@@ -844,9 +178,10 @@ async function setup(options) {
|
|
|
844
178
|
};
|
|
845
179
|
}
|
|
846
180
|
async function build(options, overrides) {
|
|
847
|
-
const { fabric, files, pluginManager, error } = await safeBuild(options, overrides);
|
|
181
|
+
const { fabric, files, pluginManager, failedPlugins, error } = await safeBuild(options, overrides);
|
|
848
182
|
if (error) throw error;
|
|
849
183
|
return {
|
|
184
|
+
failedPlugins,
|
|
850
185
|
fabric,
|
|
851
186
|
files,
|
|
852
187
|
pluginManager,
|
|
@@ -855,13 +190,21 @@ async function build(options, overrides) {
|
|
|
855
190
|
}
|
|
856
191
|
async function safeBuild(options, overrides) {
|
|
857
192
|
const { fabric, pluginManager } = overrides ? overrides : await setup(options);
|
|
193
|
+
const failedPlugins = /* @__PURE__ */ new Set();
|
|
858
194
|
const config = pluginManager.config;
|
|
859
195
|
try {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
196
|
+
for (const plugin of pluginManager.plugins) {
|
|
197
|
+
const context = pluginManager.getContext(plugin);
|
|
198
|
+
const installer = plugin.install.bind(context);
|
|
199
|
+
try {
|
|
200
|
+
await installer(context);
|
|
201
|
+
} catch (e) {
|
|
202
|
+
failedPlugins.add({
|
|
203
|
+
plugin,
|
|
204
|
+
error: e
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
865
208
|
if (config.output.barrelType) {
|
|
866
209
|
const rootPath = (0, node_path.resolve)((0, node_path.resolve)(config.root), config.output.path, "index.ts");
|
|
867
210
|
const rootFile = {
|
|
@@ -880,7 +223,7 @@ async function safeBuild(options, overrides) {
|
|
|
880
223
|
if (!pluginOptions || pluginOptions?.output?.barrelType === false) return;
|
|
881
224
|
return {
|
|
882
225
|
name: config.output.barrelType === "all" ? void 0 : [source.name],
|
|
883
|
-
path: getRelativePath(rootPath, file.path),
|
|
226
|
+
path: require_getBarrelFiles.getRelativePath(rootPath, file.path),
|
|
884
227
|
isTypeOnly: config.output.barrelType === "all" ? containsOnlyTypes : source.isTypeOnly
|
|
885
228
|
};
|
|
886
229
|
}).filter(Boolean);
|
|
@@ -890,14 +233,14 @@ async function safeBuild(options, overrides) {
|
|
|
890
233
|
};
|
|
891
234
|
await fabric.addFile(rootFile);
|
|
892
235
|
}
|
|
893
|
-
fabric.context.
|
|
236
|
+
fabric.context.on("process:start", ({ files: files$1 }) => {
|
|
894
237
|
pluginManager.logger.emit("progress_start", {
|
|
895
238
|
id: "files",
|
|
896
239
|
size: files$1.length,
|
|
897
240
|
message: "Writing files ..."
|
|
898
241
|
});
|
|
899
242
|
});
|
|
900
|
-
fabric.context.
|
|
243
|
+
fabric.context.on("process:progress", async ({ file, source }) => {
|
|
901
244
|
const message = file ? `Writing ${(0, node_path.relative)(config.root, file.path)}` : "";
|
|
902
245
|
pluginManager.logger.emit("progressed", {
|
|
903
246
|
id: "files",
|
|
@@ -905,22 +248,20 @@ async function safeBuild(options, overrides) {
|
|
|
905
248
|
});
|
|
906
249
|
if (source) await require_logger.write(file.path, source, { sanity: false });
|
|
907
250
|
});
|
|
908
|
-
fabric.context.
|
|
251
|
+
fabric.context.on("process:end", () => {
|
|
909
252
|
pluginManager.logger.emit("progress_stop", { id: "files" });
|
|
910
253
|
});
|
|
911
254
|
const files = [...fabric.files];
|
|
912
255
|
await fabric.write({ extension: config.output.extension });
|
|
913
|
-
await pluginManager.hookParallel({
|
|
914
|
-
hookName: "buildEnd",
|
|
915
|
-
message: `Build stopped for ${config.name}`
|
|
916
|
-
});
|
|
917
256
|
return {
|
|
257
|
+
failedPlugins,
|
|
918
258
|
fabric,
|
|
919
259
|
files,
|
|
920
260
|
pluginManager
|
|
921
261
|
};
|
|
922
262
|
} catch (e) {
|
|
923
263
|
return {
|
|
264
|
+
failedPlugins,
|
|
924
265
|
fabric,
|
|
925
266
|
files: [],
|
|
926
267
|
pluginManager,
|
|
@@ -930,230 +271,19 @@ async function safeBuild(options, overrides) {
|
|
|
930
271
|
}
|
|
931
272
|
|
|
932
273
|
//#endregion
|
|
933
|
-
//#region src/
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
constructor(data, parent) {
|
|
940
|
-
this.data = data;
|
|
941
|
-
this.parent = parent;
|
|
942
|
-
return this;
|
|
943
|
-
}
|
|
944
|
-
addChild(data) {
|
|
945
|
-
const child = new TreeNode(data, this);
|
|
946
|
-
if (!this.children) this.children = [];
|
|
947
|
-
this.children.push(child);
|
|
948
|
-
return child;
|
|
949
|
-
}
|
|
950
|
-
get root() {
|
|
951
|
-
if (!this.parent) return this;
|
|
952
|
-
return this.parent.root;
|
|
953
|
-
}
|
|
954
|
-
get leaves() {
|
|
955
|
-
if (!this.children || this.children.length === 0) return [this];
|
|
956
|
-
if (this.#cachedLeaves) return this.#cachedLeaves;
|
|
957
|
-
const leaves = [];
|
|
958
|
-
if (this.children) for (let i = 0, { length } = this.children; i < length; i++) leaves.push.apply(leaves, this.children[i].leaves);
|
|
959
|
-
this.#cachedLeaves = leaves;
|
|
960
|
-
return leaves;
|
|
961
|
-
}
|
|
962
|
-
forEach(callback) {
|
|
963
|
-
if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
|
|
964
|
-
callback(this);
|
|
965
|
-
if (this.children) for (let i = 0, { length } = this.children; i < length; i++) this.children[i]?.forEach(callback);
|
|
966
|
-
return this;
|
|
967
|
-
}
|
|
968
|
-
findDeep(predicate) {
|
|
969
|
-
if (typeof predicate !== "function") throw new TypeError("find() predicate must be a function");
|
|
970
|
-
return this.leaves.find(predicate);
|
|
971
|
-
}
|
|
972
|
-
forEachDeep(callback) {
|
|
973
|
-
if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
|
|
974
|
-
this.leaves.forEach(callback);
|
|
975
|
-
}
|
|
976
|
-
filterDeep(callback) {
|
|
977
|
-
if (typeof callback !== "function") throw new TypeError("filter() callback must be a function");
|
|
978
|
-
return this.leaves.filter(callback);
|
|
979
|
-
}
|
|
980
|
-
mapDeep(callback) {
|
|
981
|
-
if (typeof callback !== "function") throw new TypeError("map() callback must be a function");
|
|
982
|
-
return this.leaves.map(callback);
|
|
983
|
-
}
|
|
984
|
-
static build(files, root) {
|
|
985
|
-
try {
|
|
986
|
-
const filteredTree = buildDirectoryTree(files, root);
|
|
987
|
-
if (!filteredTree) return null;
|
|
988
|
-
const treeNode = new TreeNode({
|
|
989
|
-
name: filteredTree.name,
|
|
990
|
-
path: filteredTree.path,
|
|
991
|
-
file: filteredTree.file,
|
|
992
|
-
type: getMode(filteredTree.path)
|
|
993
|
-
});
|
|
994
|
-
const recurse = (node, item) => {
|
|
995
|
-
const subNode = node.addChild({
|
|
996
|
-
name: item.name,
|
|
997
|
-
path: item.path,
|
|
998
|
-
file: item.file,
|
|
999
|
-
type: getMode(item.path)
|
|
1000
|
-
});
|
|
1001
|
-
if (item.children?.length) item.children?.forEach((child) => {
|
|
1002
|
-
recurse(subNode, child);
|
|
1003
|
-
});
|
|
1004
|
-
};
|
|
1005
|
-
filteredTree.children?.forEach((child) => {
|
|
1006
|
-
recurse(treeNode, child);
|
|
1007
|
-
});
|
|
1008
|
-
return treeNode;
|
|
1009
|
-
} catch (e) {
|
|
1010
|
-
throw new Error("Something went wrong with creating barrel files with the TreeNode class", { cause: e });
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
};
|
|
1014
|
-
const normalizePath = (p) => p.replace(/\\/g, "/");
|
|
1015
|
-
function buildDirectoryTree(files, rootFolder = "") {
|
|
1016
|
-
const normalizedRootFolder = normalizePath(rootFolder);
|
|
1017
|
-
const rootPrefix = normalizedRootFolder.endsWith("/") ? normalizedRootFolder : `${normalizedRootFolder}/`;
|
|
1018
|
-
const filteredFiles = files.filter((file) => {
|
|
1019
|
-
const normalizedFilePath = normalizePath(file.path);
|
|
1020
|
-
return rootFolder ? normalizedFilePath.startsWith(rootPrefix) && !normalizedFilePath.endsWith(".json") : !normalizedFilePath.endsWith(".json");
|
|
1021
|
-
});
|
|
1022
|
-
if (filteredFiles.length === 0) return null;
|
|
1023
|
-
const root = {
|
|
1024
|
-
name: rootFolder || "",
|
|
1025
|
-
path: rootFolder || "",
|
|
1026
|
-
children: []
|
|
1027
|
-
};
|
|
1028
|
-
filteredFiles.forEach((file) => {
|
|
1029
|
-
const parts = file.path.slice(rootFolder.length).split("/");
|
|
1030
|
-
let currentLevel = root.children;
|
|
1031
|
-
let currentPath = rootFolder;
|
|
1032
|
-
parts.forEach((part, index) => {
|
|
1033
|
-
if (index !== 0) currentPath += `/${part}`;
|
|
1034
|
-
else currentPath += `${part}`;
|
|
1035
|
-
let existingNode = currentLevel.find((node) => node.name === part);
|
|
1036
|
-
if (!existingNode) {
|
|
1037
|
-
if (index === parts.length - 1) existingNode = {
|
|
1038
|
-
name: part,
|
|
1039
|
-
file,
|
|
1040
|
-
path: currentPath
|
|
1041
|
-
};
|
|
1042
|
-
else existingNode = {
|
|
1043
|
-
name: part,
|
|
1044
|
-
path: currentPath,
|
|
1045
|
-
children: []
|
|
1046
|
-
};
|
|
1047
|
-
currentLevel.push(existingNode);
|
|
1048
|
-
}
|
|
1049
|
-
if (!existingNode.file) currentLevel = existingNode.children;
|
|
1050
|
-
});
|
|
1051
|
-
});
|
|
1052
|
-
return root;
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
//#endregion
|
|
1056
|
-
//#region src/BarrelManager.ts
|
|
1057
|
-
var BarrelManager = class {
|
|
1058
|
-
#options;
|
|
1059
|
-
constructor(options = {}) {
|
|
1060
|
-
this.#options = options;
|
|
1061
|
-
return this;
|
|
1062
|
-
}
|
|
1063
|
-
getFiles({ files: generatedFiles, root }) {
|
|
1064
|
-
const { logger } = this.#options;
|
|
1065
|
-
const cachedFiles = /* @__PURE__ */ new Map();
|
|
1066
|
-
TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
|
|
1067
|
-
if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) return;
|
|
1068
|
-
const barrelFile = {
|
|
1069
|
-
path: (0, node_path.join)(treeNode.parent?.data.path, "index.ts"),
|
|
1070
|
-
baseName: "index.ts",
|
|
1071
|
-
exports: [],
|
|
1072
|
-
sources: []
|
|
1073
|
-
};
|
|
1074
|
-
const previousBarrelFile = cachedFiles.get(barrelFile.path);
|
|
1075
|
-
treeNode.leaves.forEach((item) => {
|
|
1076
|
-
if (!item.data.name) return;
|
|
1077
|
-
const sources = item.data.file?.sources || [];
|
|
1078
|
-
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)}`);
|
|
1079
|
-
sources.forEach((source) => {
|
|
1080
|
-
if (!item.data.file?.path || !source.isIndexable || !source.name) return;
|
|
1081
|
-
if (previousBarrelFile?.sources.some((item$1) => item$1.name === source.name && item$1.isTypeOnly === source.isTypeOnly)) return;
|
|
1082
|
-
if (!barrelFile.exports) barrelFile.exports = [];
|
|
1083
|
-
if (!!treeNode.parent?.data.path?.split?.("/")?.length) barrelFile.exports.push({
|
|
1084
|
-
name: [source.name],
|
|
1085
|
-
path: getRelativePath(treeNode.parent?.data.path, item.data.path),
|
|
1086
|
-
isTypeOnly: source.isTypeOnly
|
|
1087
|
-
});
|
|
1088
|
-
else barrelFile.exports.push({
|
|
1089
|
-
name: [source.name],
|
|
1090
|
-
path: `./${item.data.file.baseName}`,
|
|
1091
|
-
isTypeOnly: source.isTypeOnly
|
|
1092
|
-
});
|
|
1093
|
-
barrelFile.sources.push({
|
|
1094
|
-
name: source.name,
|
|
1095
|
-
isTypeOnly: source.isTypeOnly,
|
|
1096
|
-
value: "",
|
|
1097
|
-
isExportable: false,
|
|
1098
|
-
isIndexable: false
|
|
1099
|
-
});
|
|
1100
|
-
});
|
|
1101
|
-
});
|
|
1102
|
-
if (previousBarrelFile) {
|
|
1103
|
-
previousBarrelFile.sources.push(...barrelFile.sources);
|
|
1104
|
-
previousBarrelFile.exports?.push(...barrelFile.exports || []);
|
|
1105
|
-
} else cachedFiles.set(barrelFile.path, barrelFile);
|
|
1106
|
-
});
|
|
1107
|
-
return [...cachedFiles.values()];
|
|
1108
|
-
}
|
|
1109
|
-
};
|
|
1110
|
-
|
|
1111
|
-
//#endregion
|
|
1112
|
-
//#region src/FileManager.ts
|
|
1113
|
-
function getMode(path$3) {
|
|
1114
|
-
if (!path$3) return "split";
|
|
1115
|
-
return (0, node_path.extname)(path$3) ? "single" : "split";
|
|
1116
|
-
}
|
|
1117
|
-
function trimExtName(text) {
|
|
1118
|
-
return text.replace(/\.[^/.]+$/, "");
|
|
1119
|
-
}
|
|
1120
|
-
async function getBarrelFiles(files, { type, meta = {}, root, output, logger }) {
|
|
1121
|
-
if (!type || type === "propagate") return [];
|
|
1122
|
-
const barrelManager = new BarrelManager({ logger });
|
|
1123
|
-
const pathToBuildFrom = (0, node_path.join)(root, output.path);
|
|
1124
|
-
if (trimExtName(pathToBuildFrom).endsWith("index")) {
|
|
1125
|
-
logger?.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
|
|
1126
|
-
return [];
|
|
1127
|
-
}
|
|
1128
|
-
const barrelFiles = barrelManager.getFiles({
|
|
1129
|
-
files,
|
|
1130
|
-
root: pathToBuildFrom,
|
|
1131
|
-
meta
|
|
1132
|
-
});
|
|
1133
|
-
if (type === "all") return barrelFiles.map((file) => {
|
|
1134
|
-
return {
|
|
1135
|
-
...file,
|
|
1136
|
-
exports: file.exports?.map((exportItem) => {
|
|
1137
|
-
return {
|
|
1138
|
-
...exportItem,
|
|
1139
|
-
name: void 0
|
|
1140
|
-
};
|
|
1141
|
-
})
|
|
1142
|
-
};
|
|
1143
|
-
});
|
|
1144
|
-
return barrelFiles.map((indexFile) => {
|
|
1145
|
-
return {
|
|
1146
|
-
...indexFile,
|
|
1147
|
-
meta
|
|
1148
|
-
};
|
|
1149
|
-
});
|
|
274
|
+
//#region src/definePlugin.ts
|
|
275
|
+
/**
|
|
276
|
+
* Wraps a plugin builder to make the options parameter optional.
|
|
277
|
+
*/
|
|
278
|
+
function definePlugin(build$1) {
|
|
279
|
+
return (options) => build$1(options ?? {});
|
|
1150
280
|
}
|
|
1151
281
|
|
|
1152
282
|
//#endregion
|
|
1153
283
|
//#region ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
|
|
1154
284
|
function pLimit(concurrency) {
|
|
1155
285
|
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
1156
|
-
const queue = new Queue();
|
|
286
|
+
const queue = new require_getBarrelFiles.Queue();
|
|
1157
287
|
let activeCount = 0;
|
|
1158
288
|
const next = () => {
|
|
1159
289
|
activeCount--;
|
|
@@ -1344,14 +474,14 @@ var PackageManager = class PackageManager {
|
|
|
1344
474
|
if (!this.#SLASHES.has(directory[directory.length - 1])) return `${directory}/`;
|
|
1345
475
|
return directory;
|
|
1346
476
|
}
|
|
1347
|
-
getLocation(path$
|
|
1348
|
-
let location = path$
|
|
1349
|
-
if (this.#cwd) location = node_module.default.createRequire(this.normalizeDirectory(this.#cwd)).resolve(path$
|
|
477
|
+
getLocation(path$2) {
|
|
478
|
+
let location = path$2;
|
|
479
|
+
if (this.#cwd) location = node_module.default.createRequire(this.normalizeDirectory(this.#cwd)).resolve(path$2);
|
|
1350
480
|
return location;
|
|
1351
481
|
}
|
|
1352
|
-
async import(path$
|
|
482
|
+
async import(path$2) {
|
|
1353
483
|
try {
|
|
1354
|
-
let location = this.getLocation(path$
|
|
484
|
+
let location = this.getLocation(path$2);
|
|
1355
485
|
if (node_os.default.platform() === "win32") location = (0, node_url.pathToFileURL)(location).href;
|
|
1356
486
|
const module$1 = await import(location);
|
|
1357
487
|
return module$1?.default ?? module$1;
|
|
@@ -1417,14 +547,14 @@ var PackageManager = class PackageManager {
|
|
|
1417
547
|
//#endregion
|
|
1418
548
|
exports.BaseGenerator = BaseGenerator;
|
|
1419
549
|
exports.PackageManager = PackageManager;
|
|
1420
|
-
exports.PluginManager = PluginManager;
|
|
1421
|
-
exports.PromiseManager = PromiseManager;
|
|
550
|
+
exports.PluginManager = require_getBarrelFiles.PluginManager;
|
|
551
|
+
exports.PromiseManager = require_getBarrelFiles.PromiseManager;
|
|
1422
552
|
exports.build = build;
|
|
1423
|
-
exports.createPlugin = createPlugin;
|
|
1424
553
|
exports.default = build;
|
|
1425
554
|
exports.defineConfig = defineConfig;
|
|
1426
|
-
exports.
|
|
1427
|
-
exports.
|
|
555
|
+
exports.definePlugin = definePlugin;
|
|
556
|
+
exports.getBarrelFiles = require_getBarrelFiles.getBarrelFiles;
|
|
557
|
+
exports.getMode = require_getBarrelFiles.getMode;
|
|
1428
558
|
exports.isInputPath = isInputPath;
|
|
1429
559
|
exports.safeBuild = safeBuild;
|
|
1430
560
|
exports.setup = setup;
|