@kubb/core 4.32.4 → 4.33.1
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/hooks.d.ts +1 -1
- package/dist/index.cjs +1695 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +150 -20
- package/dist/index.js +1673 -65
- package/dist/index.js.map +1 -1
- package/dist/{types-f_no0d7G.d.ts → types-DfjjJb2r.d.ts} +70 -27
- package/package.json +3 -24
- package/src/BarrelManager.ts +10 -31
- package/src/PackageManager.ts +13 -21
- package/src/PluginManager.ts +65 -87
- package/src/PromiseManager.ts +3 -5
- package/src/build.ts +61 -47
- package/src/config.ts +1 -1
- package/src/constants.ts +60 -0
- package/src/errors.ts +1 -14
- package/src/index.ts +6 -3
- package/src/types.ts +5 -14
- package/src/utils/FunctionParams.ts +7 -8
- package/src/utils/TreeNode.ts +12 -23
- package/src/utils/executeStrategies.ts +5 -3
- package/src/utils/formatters.ts +3 -20
- package/src/utils/getBarrelFiles.ts +8 -2
- package/src/utils/getConfigs.ts +6 -15
- package/src/utils/getPlugins.ts +7 -7
- package/src/utils/linters.ts +3 -20
- package/dist/fs-D4eqq6bR.cjs +0 -103
- package/dist/fs-D4eqq6bR.cjs.map +0 -1
- package/dist/fs-TVBCPkE-.js +0 -67
- package/dist/fs-TVBCPkE-.js.map +0 -1
- package/dist/fs.cjs +0 -8
- package/dist/fs.d.ts +0 -23
- package/dist/fs.js +0 -2
- package/dist/packageManager-_7I0WFQU.d.ts +0 -82
- package/dist/packageManager-jzjuEj2U.cjs +0 -1103
- package/dist/packageManager-jzjuEj2U.cjs.map +0 -1
- package/dist/packageManager-wMCQlgd6.js +0 -1024
- package/dist/packageManager-wMCQlgd6.js.map +0 -1
- package/dist/transformers-BwSpAhvT.js +0 -267
- package/dist/transformers-BwSpAhvT.js.map +0 -1
- package/dist/transformers-BweFhqh-.cjs +0 -380
- package/dist/transformers-BweFhqh-.cjs.map +0 -1
- package/dist/transformers.cjs +0 -24
- package/dist/transformers.d.ts +0 -108
- package/dist/transformers.js +0 -2
- package/dist/utils.cjs +0 -430
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.ts +0 -290
- package/dist/utils.js +0 -402
- package/dist/utils.js.map +0 -1
- package/src/BaseGenerator.ts +0 -34
- package/src/fs/clean.ts +0 -5
- package/src/fs/exists.ts +0 -16
- package/src/fs/index.ts +0 -5
- package/src/fs/read.ts +0 -13
- package/src/fs/utils.ts +0 -32
- package/src/fs/write.ts +0 -46
- package/src/transformers/casing.ts +0 -62
- package/src/transformers/combineCodes.ts +0 -3
- package/src/transformers/createJSDocBlockText.ts +0 -9
- package/src/transformers/escape.ts +0 -31
- package/src/transformers/indent.ts +0 -3
- package/src/transformers/index.ts +0 -46
- package/src/transformers/nameSorter.ts +0 -9
- package/src/transformers/searchAndReplace.ts +0 -25
- package/src/transformers/stringify.ts +0 -25
- package/src/transformers/toRegExp.ts +0 -22
- package/src/transformers/transformReservedWord.ts +0 -106
- package/src/transformers/trim.ts +0 -18
- package/src/utils/AsyncEventEmitter.ts +0 -48
- package/src/utils/Cache.ts +0 -31
- package/src/utils/URLPath.ts +0 -146
- package/src/utils/buildJSDoc.ts +0 -34
- package/src/utils/checkOnlineStatus.ts +0 -40
- package/src/utils/formatHrtime.ts +0 -33
- package/src/utils/getNestedAccessor.ts +0 -25
- package/src/utils/index.ts +0 -26
- package/src/utils/packageManager.ts +0 -58
- package/src/utils/promise.ts +0 -13
- package/src/utils/renderTemplate.ts +0 -31
- package/src/utils/serializePluginOptions.ts +0 -29
- package/src/utils/timeout.ts +0 -11
- package/src/utils/tokenize.ts +0 -23
- package/src/utils/types.ts +0 -1
- package/src/utils/uniqueName.ts +0 -20
package/dist/index.js
CHANGED
|
@@ -1,40 +1,654 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { a as formatMs, c as PluginManager, f as PromiseManager, l as getMode, n as getBarrelFiles, o as getElapsedMs, p as BuildError, r as URLPath, s as AsyncEventEmitter, t as detectPackageManager } from "./packageManager-wMCQlgd6.js";
|
|
3
|
-
import { a as exists, i as readSync, n as getRelativePath, o as clean, r as read, t as write } from "./fs-TVBCPkE-.js";
|
|
4
2
|
import mod from "node:module";
|
|
5
|
-
import { resolve } from "node:path";
|
|
3
|
+
import path, { dirname, join, posix, resolve } from "node:path";
|
|
4
|
+
import { EventEmitter } from "node:events";
|
|
5
|
+
import { parseArgs, styleText } from "node:util";
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { access, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
6
8
|
import { createFabric } from "@kubb/react-fabric";
|
|
7
9
|
import { typescriptParser } from "@kubb/react-fabric/parsers";
|
|
8
10
|
import { fsPlugin } from "@kubb/react-fabric/plugins";
|
|
11
|
+
import { performance } from "node:perf_hooks";
|
|
9
12
|
import { version } from "node:process";
|
|
10
13
|
import os from "node:os";
|
|
11
14
|
import { pathToFileURL } from "node:url";
|
|
12
15
|
import * as pkg from "empathic/package";
|
|
13
16
|
import { coerce, satisfies } from "semver";
|
|
14
|
-
|
|
17
|
+
import { sortBy } from "remeda";
|
|
18
|
+
import { x } from "tinyexec";
|
|
19
|
+
//#region ../../internals/utils/dist/index.js
|
|
20
|
+
/** Thrown when a plugin's configuration or input fails validation. */
|
|
21
|
+
var ValidationPluginError = class extends Error {};
|
|
15
22
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
23
|
+
* Thrown when one or more errors occur during a Kubb build.
|
|
24
|
+
* Carries the full list of underlying errors on `errors`.
|
|
18
25
|
*/
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
var BuildError = class extends Error {
|
|
27
|
+
errors;
|
|
28
|
+
constructor(message, options) {
|
|
29
|
+
super(message, { cause: options.cause });
|
|
30
|
+
this.name = "BuildError";
|
|
31
|
+
this.errors = options.errors;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Coerces an unknown thrown value to an `Error` instance.
|
|
36
|
+
* When the value is already an `Error` it is returned as-is;
|
|
37
|
+
* otherwise a new `Error` is created whose message is `String(value)`.
|
|
38
|
+
*/
|
|
39
|
+
function toError(value) {
|
|
40
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A typed EventEmitter that awaits all async listeners before resolving.
|
|
44
|
+
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
45
|
+
*/
|
|
46
|
+
var AsyncEventEmitter = class {
|
|
47
|
+
/**
|
|
48
|
+
* `maxListener` controls the maximum number of listeners per event before Node emits a memory-leak warning.
|
|
49
|
+
* @default 10
|
|
50
|
+
*/
|
|
51
|
+
constructor(maxListener = 10) {
|
|
52
|
+
this.#emitter.setMaxListeners(maxListener);
|
|
26
53
|
}
|
|
27
|
-
|
|
28
|
-
|
|
54
|
+
#emitter = new EventEmitter();
|
|
55
|
+
/**
|
|
56
|
+
* Emits an event and awaits all registered listeners in parallel.
|
|
57
|
+
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
58
|
+
*/
|
|
59
|
+
async emit(eventName, ...eventArgs) {
|
|
60
|
+
const listeners = this.#emitter.listeners(eventName);
|
|
61
|
+
if (listeners.length === 0) return;
|
|
62
|
+
await Promise.all(listeners.map(async (listener) => {
|
|
63
|
+
try {
|
|
64
|
+
return await listener(...eventArgs);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
let serializedArgs;
|
|
67
|
+
try {
|
|
68
|
+
serializedArgs = JSON.stringify(eventArgs);
|
|
69
|
+
} catch {
|
|
70
|
+
serializedArgs = String(eventArgs);
|
|
71
|
+
}
|
|
72
|
+
throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
29
75
|
}
|
|
30
|
-
|
|
31
|
-
|
|
76
|
+
/** Registers a persistent listener for the given event. */
|
|
77
|
+
on(eventName, handler) {
|
|
78
|
+
this.#emitter.on(eventName, handler);
|
|
32
79
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
80
|
+
/** Registers a one-shot listener that removes itself after the first invocation. */
|
|
81
|
+
onOnce(eventName, handler) {
|
|
82
|
+
const wrapper = (...args) => {
|
|
83
|
+
this.off(eventName, wrapper);
|
|
84
|
+
return handler(...args);
|
|
37
85
|
};
|
|
86
|
+
this.on(eventName, wrapper);
|
|
87
|
+
}
|
|
88
|
+
/** Removes a previously registered listener. */
|
|
89
|
+
off(eventName, handler) {
|
|
90
|
+
this.#emitter.off(eventName, handler);
|
|
91
|
+
}
|
|
92
|
+
/** Removes all listeners from every event channel. */
|
|
93
|
+
removeAll() {
|
|
94
|
+
this.#emitter.removeAllListeners();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Shared implementation for camelCase and PascalCase conversion.
|
|
99
|
+
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
100
|
+
* and capitalizes each word according to `pascal`.
|
|
101
|
+
*
|
|
102
|
+
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
103
|
+
*/
|
|
104
|
+
function toCamelOrPascal(text, pascal) {
|
|
105
|
+
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
106
|
+
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
107
|
+
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
108
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
109
|
+
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
113
|
+
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
114
|
+
* Segments are joined with `/` to form a file path.
|
|
115
|
+
*/
|
|
116
|
+
function applyToFileParts(text, transformPart) {
|
|
117
|
+
const parts = text.split(".");
|
|
118
|
+
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Converts `text` to camelCase.
|
|
122
|
+
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* camelCase('hello-world') // 'helloWorld'
|
|
126
|
+
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
127
|
+
*/
|
|
128
|
+
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
129
|
+
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
130
|
+
prefix,
|
|
131
|
+
suffix
|
|
132
|
+
} : {}));
|
|
133
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
134
|
+
}
|
|
135
|
+
/** Returns a `CLIAdapter` with type inference. Pass a different adapter to `createCLI` to swap the CLI engine. */
|
|
136
|
+
function defineCLIAdapter(adapter) {
|
|
137
|
+
return adapter;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Serializes `CommandDefinition[]` to a plain, JSON-serializable structure.
|
|
141
|
+
* Use to expose CLI capabilities to AI agents or MCP tools.
|
|
142
|
+
*/
|
|
143
|
+
function getCommandSchema(defs) {
|
|
144
|
+
return defs.map(serializeCommand);
|
|
145
|
+
}
|
|
146
|
+
function serializeCommand(def) {
|
|
147
|
+
return {
|
|
148
|
+
name: def.name,
|
|
149
|
+
description: def.description,
|
|
150
|
+
arguments: def.arguments,
|
|
151
|
+
options: serializeOptions(def.options ?? {}),
|
|
152
|
+
subCommands: def.subCommands ? def.subCommands.map(serializeCommand) : []
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function serializeOptions(options) {
|
|
156
|
+
return Object.entries(options).map(([name, opt]) => {
|
|
157
|
+
return {
|
|
158
|
+
name,
|
|
159
|
+
flags: `${opt.short ? `-${opt.short}, ` : ""}--${name}${opt.type === "string" ? ` <${opt.hint ?? name}>` : ""}`,
|
|
160
|
+
type: opt.type,
|
|
161
|
+
description: opt.description,
|
|
162
|
+
...opt.default !== void 0 ? { default: opt.default } : {},
|
|
163
|
+
...opt.hint ? { hint: opt.hint } : {},
|
|
164
|
+
...opt.enum ? { enum: opt.enum } : {},
|
|
165
|
+
...opt.required ? { required: opt.required } : {}
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/** Prints formatted help output for a command using its `CommandDefinition`. */
|
|
170
|
+
function renderHelp(def, parentName) {
|
|
171
|
+
const schema = getCommandSchema([def])[0];
|
|
172
|
+
const programName = parentName ? `${parentName} ${schema.name}` : schema.name;
|
|
173
|
+
const argsPart = schema.arguments?.length ? ` ${schema.arguments.join(" ")}` : "";
|
|
174
|
+
const subCmdPart = schema.subCommands.length ? " <command>" : "";
|
|
175
|
+
console.log(`\n${styleText("bold", "Usage:")} ${programName}${argsPart}${subCmdPart} [options]\n`);
|
|
176
|
+
if (schema.description) console.log(` ${schema.description}\n`);
|
|
177
|
+
if (schema.subCommands.length) {
|
|
178
|
+
console.log(styleText("bold", "Commands:"));
|
|
179
|
+
for (const sub of schema.subCommands) console.log(` ${styleText("cyan", sub.name.padEnd(16))}${sub.description}`);
|
|
180
|
+
console.log();
|
|
181
|
+
}
|
|
182
|
+
const options = [...schema.options, {
|
|
183
|
+
name: "help",
|
|
184
|
+
flags: "-h, --help",
|
|
185
|
+
type: "boolean",
|
|
186
|
+
description: "Show help"
|
|
187
|
+
}];
|
|
188
|
+
console.log(styleText("bold", "Options:"));
|
|
189
|
+
for (const opt of options) {
|
|
190
|
+
const flags = styleText("cyan", opt.flags.padEnd(30));
|
|
191
|
+
const defaultPart = opt.default !== void 0 ? styleText("dim", ` (default: ${opt.default})`) : "";
|
|
192
|
+
console.log(` ${flags}${opt.description}${defaultPart}`);
|
|
193
|
+
}
|
|
194
|
+
console.log();
|
|
195
|
+
}
|
|
196
|
+
function buildParseOptions(def) {
|
|
197
|
+
const result = { help: {
|
|
198
|
+
type: "boolean",
|
|
199
|
+
short: "h"
|
|
200
|
+
} };
|
|
201
|
+
for (const [name, opt] of Object.entries(def.options ?? {})) result[name] = {
|
|
202
|
+
type: opt.type,
|
|
203
|
+
...opt.short ? { short: opt.short } : {},
|
|
204
|
+
...opt.default !== void 0 ? { default: opt.default } : {}
|
|
205
|
+
};
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
async function runCommand(def, argv, parentName) {
|
|
209
|
+
const parseOptions = buildParseOptions(def);
|
|
210
|
+
let parsed;
|
|
211
|
+
try {
|
|
212
|
+
const result = parseArgs({
|
|
213
|
+
args: argv,
|
|
214
|
+
options: parseOptions,
|
|
215
|
+
allowPositionals: true,
|
|
216
|
+
strict: false
|
|
217
|
+
});
|
|
218
|
+
parsed = {
|
|
219
|
+
values: result.values,
|
|
220
|
+
positionals: result.positionals
|
|
221
|
+
};
|
|
222
|
+
} catch {
|
|
223
|
+
renderHelp(def, parentName);
|
|
224
|
+
process.exit(1);
|
|
225
|
+
}
|
|
226
|
+
if (parsed.values["help"]) {
|
|
227
|
+
renderHelp(def, parentName);
|
|
228
|
+
process.exit(0);
|
|
229
|
+
}
|
|
230
|
+
for (const [name, opt] of Object.entries(def.options ?? {})) if (opt.required && parsed.values[name] === void 0) {
|
|
231
|
+
console.error(styleText("red", `Error: --${name} is required`));
|
|
232
|
+
renderHelp(def, parentName);
|
|
233
|
+
process.exit(1);
|
|
234
|
+
}
|
|
235
|
+
if (!def.run) {
|
|
236
|
+
renderHelp(def, parentName);
|
|
237
|
+
process.exit(0);
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
await def.run(parsed);
|
|
241
|
+
} catch (err) {
|
|
242
|
+
console.error(styleText("red", `Error: ${err instanceof Error ? err.message : String(err)}`));
|
|
243
|
+
renderHelp(def, parentName);
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function printRootHelp(programName, version, defs) {
|
|
248
|
+
console.log(`\n${styleText("bold", "Usage:")} ${programName} <command> [options]\n`);
|
|
249
|
+
console.log(` Kubb generation — v${version}\n`);
|
|
250
|
+
console.log(styleText("bold", "Commands:"));
|
|
251
|
+
for (const def of defs) console.log(` ${styleText("cyan", def.name.padEnd(16))}${def.description}`);
|
|
252
|
+
console.log();
|
|
253
|
+
console.log(styleText("bold", "Options:"));
|
|
254
|
+
console.log(` ${styleText("cyan", "-v, --version".padEnd(30))}Show version number`);
|
|
255
|
+
console.log(` ${styleText("cyan", "-h, --help".padEnd(30))}Show help`);
|
|
256
|
+
console.log();
|
|
257
|
+
console.log(`Run ${styleText("cyan", `${programName} <command> --help`)} for command-specific help.\n`);
|
|
258
|
+
}
|
|
259
|
+
defineCLIAdapter({
|
|
260
|
+
renderHelp(def, parentName) {
|
|
261
|
+
renderHelp(def, parentName);
|
|
262
|
+
},
|
|
263
|
+
async run(defs, argv, opts) {
|
|
264
|
+
const { programName, defaultCommandName, version } = opts;
|
|
265
|
+
const args = argv.length >= 2 && argv[0]?.includes("node") ? argv.slice(2) : argv;
|
|
266
|
+
if (args[0] === "--version" || args[0] === "-v") {
|
|
267
|
+
console.log(version);
|
|
268
|
+
process.exit(0);
|
|
269
|
+
}
|
|
270
|
+
if (args[0] === "--help" || args[0] === "-h") {
|
|
271
|
+
printRootHelp(programName, version, defs);
|
|
272
|
+
process.exit(0);
|
|
273
|
+
}
|
|
274
|
+
if (args.length === 0) {
|
|
275
|
+
const defaultDef = defs.find((d) => d.name === defaultCommandName);
|
|
276
|
+
if (defaultDef?.run) await runCommand(defaultDef, [], programName);
|
|
277
|
+
else printRootHelp(programName, version, defs);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const [first, ...rest] = args;
|
|
281
|
+
const isKnownSubcommand = defs.some((d) => d.name === first);
|
|
282
|
+
let def;
|
|
283
|
+
let commandArgv;
|
|
284
|
+
let parentName;
|
|
285
|
+
if (isKnownSubcommand) {
|
|
286
|
+
def = defs.find((d) => d.name === first);
|
|
287
|
+
commandArgv = rest;
|
|
288
|
+
parentName = programName;
|
|
289
|
+
} else {
|
|
290
|
+
def = defs.find((d) => d.name === defaultCommandName);
|
|
291
|
+
commandArgv = args;
|
|
292
|
+
parentName = programName;
|
|
293
|
+
}
|
|
294
|
+
if (!def) {
|
|
295
|
+
console.error(`Unknown command: ${first}`);
|
|
296
|
+
printRootHelp(programName, version, defs);
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
299
|
+
if (def.subCommands?.length) {
|
|
300
|
+
const [subName, ...subRest] = commandArgv;
|
|
301
|
+
const subDef = def.subCommands.find((s) => s.name === subName);
|
|
302
|
+
if (subName === "--help" || subName === "-h") {
|
|
303
|
+
renderHelp(def, parentName);
|
|
304
|
+
process.exit(0);
|
|
305
|
+
}
|
|
306
|
+
if (!subDef) {
|
|
307
|
+
renderHelp(def, parentName);
|
|
308
|
+
process.exit(subName ? 1 : 0);
|
|
309
|
+
}
|
|
310
|
+
await runCommand(subDef, subRest, `${parentName} ${def.name}`);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
await runCommand(def, commandArgv, parentName);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
/**
|
|
317
|
+
* Calculates elapsed time in milliseconds from a high-resolution start time.
|
|
318
|
+
* Rounds to 2 decimal places to provide sub-millisecond precision without noise.
|
|
319
|
+
*/
|
|
320
|
+
function getElapsedMs(hrStart) {
|
|
321
|
+
const [seconds, nanoseconds] = process.hrtime(hrStart);
|
|
322
|
+
const ms = seconds * 1e3 + nanoseconds / 1e6;
|
|
323
|
+
return Math.round(ms * 100) / 100;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Converts a millisecond duration into a human-readable string.
|
|
327
|
+
* Adjusts units (ms, s, m s) based on the magnitude of the duration.
|
|
328
|
+
*/
|
|
329
|
+
function formatMs(ms) {
|
|
330
|
+
if (ms >= 6e4) return `${Math.floor(ms / 6e4)}m ${(ms % 6e4 / 1e3).toFixed(1)}s`;
|
|
331
|
+
if (ms >= 1e3) return `${(ms / 1e3).toFixed(2)}s`;
|
|
332
|
+
return `${Math.round(ms)}ms`;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Parses a CSS hex color string (`#RGB`) into its RGB channels.
|
|
336
|
+
* Falls back to `255` for any channel that cannot be parsed.
|
|
337
|
+
*/
|
|
338
|
+
function parseHex(color) {
|
|
339
|
+
const int = Number.parseInt(color.replace("#", ""), 16);
|
|
340
|
+
return Number.isNaN(int) ? {
|
|
341
|
+
r: 255,
|
|
342
|
+
g: 255,
|
|
343
|
+
b: 255
|
|
344
|
+
} : {
|
|
345
|
+
r: int >> 16 & 255,
|
|
346
|
+
g: int >> 8 & 255,
|
|
347
|
+
b: int & 255
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Returns a function that wraps a string in a 24-bit ANSI true-color escape sequence
|
|
352
|
+
* for the given hex color.
|
|
353
|
+
*/
|
|
354
|
+
function hex(color) {
|
|
355
|
+
const { r, g, b } = parseHex(color);
|
|
356
|
+
return (text) => `\x1b[38;2;${r};${g};${b}m${text}\x1b[0m`;
|
|
357
|
+
}
|
|
358
|
+
hex("#F55A17"), hex("#F5A217"), hex("#F58517"), hex("#B45309"), hex("#FFFFFF"), hex("#adadc6"), hex("#FDA4AF");
|
|
359
|
+
/**
|
|
360
|
+
* Converts all backslashes to forward slashes.
|
|
361
|
+
* Extended-length Windows paths (`\\?\...`) are left unchanged.
|
|
362
|
+
*/
|
|
363
|
+
function toSlash(p) {
|
|
364
|
+
if (p.startsWith("\\\\?\\")) return p;
|
|
365
|
+
return p.replaceAll("\\", "/");
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Returns the relative path from `rootDir` to `filePath`, always using
|
|
369
|
+
* forward slashes and prefixed with `./` when not already traversing upward.
|
|
370
|
+
*/
|
|
371
|
+
function getRelativePath(rootDir, filePath) {
|
|
372
|
+
if (!rootDir || !filePath) throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
|
|
373
|
+
const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath));
|
|
374
|
+
return relativePath.startsWith("../") ? relativePath : `./${relativePath}`;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Resolves to `true` when the file or directory at `path` exists.
|
|
378
|
+
* Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.
|
|
379
|
+
*/
|
|
380
|
+
async function exists(path) {
|
|
381
|
+
if (typeof Bun !== "undefined") return Bun.file(path).exists();
|
|
382
|
+
return access(path).then(() => true, () => false);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Reads the file at `path` as a UTF-8 string.
|
|
386
|
+
* Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.
|
|
387
|
+
*/
|
|
388
|
+
async function read(path) {
|
|
389
|
+
if (typeof Bun !== "undefined") return Bun.file(path).text();
|
|
390
|
+
return readFile(path, { encoding: "utf8" });
|
|
391
|
+
}
|
|
392
|
+
/** Synchronous counterpart of `read`. */
|
|
393
|
+
function readSync(path) {
|
|
394
|
+
return readFileSync(path, { encoding: "utf8" });
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Writes `data` to `path`, trimming leading/trailing whitespace before saving.
|
|
398
|
+
* Skips the write and returns `undefined` when the trimmed content is empty or
|
|
399
|
+
* identical to what is already on disk.
|
|
400
|
+
* Creates any missing parent directories automatically.
|
|
401
|
+
* When `sanity` is `true`, re-reads the file after writing and throws if the
|
|
402
|
+
* content does not match — useful for catching write failures on unreliable file systems.
|
|
403
|
+
*/
|
|
404
|
+
async function write(path, data, options = {}) {
|
|
405
|
+
const trimmed = data.trim();
|
|
406
|
+
if (trimmed === "") return void 0;
|
|
407
|
+
const resolved = resolve(path);
|
|
408
|
+
if (typeof Bun !== "undefined") {
|
|
409
|
+
const file = Bun.file(resolved);
|
|
410
|
+
if ((await file.exists() ? await file.text() : null) === trimmed) return void 0;
|
|
411
|
+
await Bun.write(resolved, trimmed);
|
|
412
|
+
return trimmed;
|
|
413
|
+
}
|
|
414
|
+
try {
|
|
415
|
+
if (await readFile(resolved, { encoding: "utf-8" }) === trimmed) return void 0;
|
|
416
|
+
} catch {}
|
|
417
|
+
await mkdir(dirname(resolved), { recursive: true });
|
|
418
|
+
await writeFile(resolved, trimmed, { encoding: "utf-8" });
|
|
419
|
+
if (options.sanity) {
|
|
420
|
+
const savedData = await readFile(resolved, { encoding: "utf-8" });
|
|
421
|
+
if (savedData !== trimmed) throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
|
|
422
|
+
return savedData;
|
|
423
|
+
}
|
|
424
|
+
return trimmed;
|
|
425
|
+
}
|
|
426
|
+
/** Recursively removes `path`. Silently succeeds when `path` does not exist. */
|
|
427
|
+
async function clean(path) {
|
|
428
|
+
return rm(path, {
|
|
429
|
+
recursive: true,
|
|
430
|
+
force: true
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Registers `originalName` in `data` without altering the returned name.
|
|
435
|
+
* Use this when you need to track usage frequency but always emit the original identifier.
|
|
436
|
+
*/
|
|
437
|
+
function setUniqueName(originalName, data) {
|
|
438
|
+
let used = data[originalName] || 0;
|
|
439
|
+
if (used) {
|
|
440
|
+
data[originalName] = ++used;
|
|
441
|
+
return originalName;
|
|
442
|
+
}
|
|
443
|
+
data[originalName] = 1;
|
|
444
|
+
return originalName;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* JavaScript and Java reserved words.
|
|
448
|
+
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
449
|
+
*/
|
|
450
|
+
const reservedWords = [
|
|
451
|
+
"abstract",
|
|
452
|
+
"arguments",
|
|
453
|
+
"boolean",
|
|
454
|
+
"break",
|
|
455
|
+
"byte",
|
|
456
|
+
"case",
|
|
457
|
+
"catch",
|
|
458
|
+
"char",
|
|
459
|
+
"class",
|
|
460
|
+
"const",
|
|
461
|
+
"continue",
|
|
462
|
+
"debugger",
|
|
463
|
+
"default",
|
|
464
|
+
"delete",
|
|
465
|
+
"do",
|
|
466
|
+
"double",
|
|
467
|
+
"else",
|
|
468
|
+
"enum",
|
|
469
|
+
"eval",
|
|
470
|
+
"export",
|
|
471
|
+
"extends",
|
|
472
|
+
"false",
|
|
473
|
+
"final",
|
|
474
|
+
"finally",
|
|
475
|
+
"float",
|
|
476
|
+
"for",
|
|
477
|
+
"function",
|
|
478
|
+
"goto",
|
|
479
|
+
"if",
|
|
480
|
+
"implements",
|
|
481
|
+
"import",
|
|
482
|
+
"in",
|
|
483
|
+
"instanceof",
|
|
484
|
+
"int",
|
|
485
|
+
"interface",
|
|
486
|
+
"let",
|
|
487
|
+
"long",
|
|
488
|
+
"native",
|
|
489
|
+
"new",
|
|
490
|
+
"null",
|
|
491
|
+
"package",
|
|
492
|
+
"private",
|
|
493
|
+
"protected",
|
|
494
|
+
"public",
|
|
495
|
+
"return",
|
|
496
|
+
"short",
|
|
497
|
+
"static",
|
|
498
|
+
"super",
|
|
499
|
+
"switch",
|
|
500
|
+
"synchronized",
|
|
501
|
+
"this",
|
|
502
|
+
"throw",
|
|
503
|
+
"throws",
|
|
504
|
+
"transient",
|
|
505
|
+
"true",
|
|
506
|
+
"try",
|
|
507
|
+
"typeof",
|
|
508
|
+
"var",
|
|
509
|
+
"void",
|
|
510
|
+
"volatile",
|
|
511
|
+
"while",
|
|
512
|
+
"with",
|
|
513
|
+
"yield",
|
|
514
|
+
"Array",
|
|
515
|
+
"Date",
|
|
516
|
+
"hasOwnProperty",
|
|
517
|
+
"Infinity",
|
|
518
|
+
"isFinite",
|
|
519
|
+
"isNaN",
|
|
520
|
+
"isPrototypeOf",
|
|
521
|
+
"length",
|
|
522
|
+
"Math",
|
|
523
|
+
"name",
|
|
524
|
+
"NaN",
|
|
525
|
+
"Number",
|
|
526
|
+
"Object",
|
|
527
|
+
"prototype",
|
|
528
|
+
"String",
|
|
529
|
+
"toString",
|
|
530
|
+
"undefined",
|
|
531
|
+
"valueOf"
|
|
532
|
+
];
|
|
533
|
+
/**
|
|
534
|
+
* Prefixes a word with `_` when it is a reserved JavaScript/Java identifier
|
|
535
|
+
* or starts with a digit.
|
|
536
|
+
*/
|
|
537
|
+
function transformReservedWord(word) {
|
|
538
|
+
const firstChar = word.charCodeAt(0);
|
|
539
|
+
if (word && (reservedWords.includes(word) || firstChar >= 48 && firstChar <= 57)) return `_${word}`;
|
|
540
|
+
return word;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
544
|
+
*/
|
|
545
|
+
function isValidVarName(name) {
|
|
546
|
+
try {
|
|
547
|
+
new Function(`var ${name}`);
|
|
548
|
+
} catch {
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
return true;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Parses and transforms an OpenAPI/Swagger path string into various URL formats.
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* const p = new URLPath('/pet/{petId}')
|
|
558
|
+
* p.URL // '/pet/:petId'
|
|
559
|
+
* p.template // '`/pet/${petId}`'
|
|
560
|
+
*/
|
|
561
|
+
var URLPath = class {
|
|
562
|
+
/** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */
|
|
563
|
+
path;
|
|
564
|
+
#options;
|
|
565
|
+
constructor(path, options = {}) {
|
|
566
|
+
this.path = path;
|
|
567
|
+
this.#options = options;
|
|
568
|
+
}
|
|
569
|
+
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
|
|
570
|
+
get URL() {
|
|
571
|
+
return this.toURLPath();
|
|
572
|
+
}
|
|
573
|
+
/** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */
|
|
574
|
+
get isURL() {
|
|
575
|
+
try {
|
|
576
|
+
return !!new URL(this.path).href;
|
|
577
|
+
} catch {
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
|
|
586
|
+
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
587
|
+
*/
|
|
588
|
+
get template() {
|
|
589
|
+
return this.toTemplateString();
|
|
590
|
+
}
|
|
591
|
+
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */
|
|
592
|
+
get object() {
|
|
593
|
+
return this.toObject();
|
|
594
|
+
}
|
|
595
|
+
/** Returns a map of path parameter names, or `undefined` when the path has no parameters. */
|
|
596
|
+
get params() {
|
|
597
|
+
return this.getParams();
|
|
598
|
+
}
|
|
599
|
+
#transformParam(raw) {
|
|
600
|
+
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
601
|
+
return this.#options.casing === "camelcase" ? camelCase(param) : param;
|
|
602
|
+
}
|
|
603
|
+
/** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */
|
|
604
|
+
#eachParam(fn) {
|
|
605
|
+
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
606
|
+
const raw = match[1];
|
|
607
|
+
fn(raw, this.#transformParam(raw));
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
611
|
+
const object = {
|
|
612
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
613
|
+
params: this.getParams()
|
|
614
|
+
};
|
|
615
|
+
if (stringify) {
|
|
616
|
+
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
617
|
+
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
618
|
+
return `{ url: '${object.url}' }`;
|
|
619
|
+
}
|
|
620
|
+
return object;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
624
|
+
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
628
|
+
*/
|
|
629
|
+
toTemplateString({ prefix = "", replacer } = {}) {
|
|
630
|
+
return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
631
|
+
if (i % 2 === 0) return part;
|
|
632
|
+
const param = this.#transformParam(part);
|
|
633
|
+
return `\${${replacer ? replacer(param) : param}}`;
|
|
634
|
+
}).join("")}\``;
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
638
|
+
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
639
|
+
* Returns `undefined` when no path parameters are found.
|
|
640
|
+
*/
|
|
641
|
+
getParams(replacer) {
|
|
642
|
+
const params = {};
|
|
643
|
+
this.#eachParam((_raw, param) => {
|
|
644
|
+
const key = replacer ? replacer(param) : param;
|
|
645
|
+
params[key] = key;
|
|
646
|
+
});
|
|
647
|
+
return Object.keys(params).length > 0 ? params : void 0;
|
|
648
|
+
}
|
|
649
|
+
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
|
|
650
|
+
toURLPath() {
|
|
651
|
+
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
38
652
|
}
|
|
39
653
|
};
|
|
40
654
|
//#endregion
|
|
@@ -62,9 +676,638 @@ function defineConfig(config) {
|
|
|
62
676
|
function isInputPath(config) {
|
|
63
677
|
return typeof config?.input === "object" && config.input !== null && "path" in config.input;
|
|
64
678
|
}
|
|
679
|
+
const BARREL_FILENAME = "index.ts";
|
|
680
|
+
const DEFAULT_BANNER = "simple";
|
|
681
|
+
const DEFAULT_EXTENSION = { ".ts": ".ts" };
|
|
682
|
+
const PATH_SEPARATORS = ["/", "\\"];
|
|
683
|
+
const logLevel = {
|
|
684
|
+
silent: Number.NEGATIVE_INFINITY,
|
|
685
|
+
error: 0,
|
|
686
|
+
warn: 1,
|
|
687
|
+
info: 3,
|
|
688
|
+
verbose: 4,
|
|
689
|
+
debug: 5
|
|
690
|
+
};
|
|
691
|
+
const linters = {
|
|
692
|
+
eslint: {
|
|
693
|
+
command: "eslint",
|
|
694
|
+
args: (outputPath) => [outputPath, "--fix"],
|
|
695
|
+
errorMessage: "Eslint not found"
|
|
696
|
+
},
|
|
697
|
+
biome: {
|
|
698
|
+
command: "biome",
|
|
699
|
+
args: (outputPath) => [
|
|
700
|
+
"lint",
|
|
701
|
+
"--fix",
|
|
702
|
+
outputPath
|
|
703
|
+
],
|
|
704
|
+
errorMessage: "Biome not found"
|
|
705
|
+
},
|
|
706
|
+
oxlint: {
|
|
707
|
+
command: "oxlint",
|
|
708
|
+
args: (outputPath) => ["--fix", outputPath],
|
|
709
|
+
errorMessage: "Oxlint not found"
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
const formatters = {
|
|
713
|
+
prettier: {
|
|
714
|
+
command: "prettier",
|
|
715
|
+
args: (outputPath) => [
|
|
716
|
+
"--ignore-unknown",
|
|
717
|
+
"--write",
|
|
718
|
+
outputPath
|
|
719
|
+
],
|
|
720
|
+
errorMessage: "Prettier not found"
|
|
721
|
+
},
|
|
722
|
+
biome: {
|
|
723
|
+
command: "biome",
|
|
724
|
+
args: (outputPath) => [
|
|
725
|
+
"format",
|
|
726
|
+
"--write",
|
|
727
|
+
outputPath
|
|
728
|
+
],
|
|
729
|
+
errorMessage: "Biome not found"
|
|
730
|
+
},
|
|
731
|
+
oxfmt: {
|
|
732
|
+
command: "oxfmt",
|
|
733
|
+
args: (outputPath) => [outputPath],
|
|
734
|
+
errorMessage: "Oxfmt not found"
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
//#endregion
|
|
738
|
+
//#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
|
|
739
|
+
var Node = class {
|
|
740
|
+
value;
|
|
741
|
+
next;
|
|
742
|
+
constructor(value) {
|
|
743
|
+
this.value = value;
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
var Queue = class {
|
|
747
|
+
#head;
|
|
748
|
+
#tail;
|
|
749
|
+
#size;
|
|
750
|
+
constructor() {
|
|
751
|
+
this.clear();
|
|
752
|
+
}
|
|
753
|
+
enqueue(value) {
|
|
754
|
+
const node = new Node(value);
|
|
755
|
+
if (this.#head) {
|
|
756
|
+
this.#tail.next = node;
|
|
757
|
+
this.#tail = node;
|
|
758
|
+
} else {
|
|
759
|
+
this.#head = node;
|
|
760
|
+
this.#tail = node;
|
|
761
|
+
}
|
|
762
|
+
this.#size++;
|
|
763
|
+
}
|
|
764
|
+
dequeue() {
|
|
765
|
+
const current = this.#head;
|
|
766
|
+
if (!current) return;
|
|
767
|
+
this.#head = this.#head.next;
|
|
768
|
+
this.#size--;
|
|
769
|
+
if (!this.#head) this.#tail = void 0;
|
|
770
|
+
return current.value;
|
|
771
|
+
}
|
|
772
|
+
peek() {
|
|
773
|
+
if (!this.#head) return;
|
|
774
|
+
return this.#head.value;
|
|
775
|
+
}
|
|
776
|
+
clear() {
|
|
777
|
+
this.#head = void 0;
|
|
778
|
+
this.#tail = void 0;
|
|
779
|
+
this.#size = 0;
|
|
780
|
+
}
|
|
781
|
+
get size() {
|
|
782
|
+
return this.#size;
|
|
783
|
+
}
|
|
784
|
+
*[Symbol.iterator]() {
|
|
785
|
+
let current = this.#head;
|
|
786
|
+
while (current) {
|
|
787
|
+
yield current.value;
|
|
788
|
+
current = current.next;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
*drain() {
|
|
792
|
+
while (this.#head) yield this.dequeue();
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
//#endregion
|
|
796
|
+
//#region ../../node_modules/.pnpm/p-limit@7.3.0/node_modules/p-limit/index.js
|
|
797
|
+
function pLimit(concurrency) {
|
|
798
|
+
let rejectOnClear = false;
|
|
799
|
+
if (typeof concurrency === "object") ({concurrency, rejectOnClear = false} = concurrency);
|
|
800
|
+
validateConcurrency(concurrency);
|
|
801
|
+
if (typeof rejectOnClear !== "boolean") throw new TypeError("Expected `rejectOnClear` to be a boolean");
|
|
802
|
+
const queue = new Queue();
|
|
803
|
+
let activeCount = 0;
|
|
804
|
+
const resumeNext = () => {
|
|
805
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
806
|
+
activeCount++;
|
|
807
|
+
queue.dequeue().run();
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
const next = () => {
|
|
811
|
+
activeCount--;
|
|
812
|
+
resumeNext();
|
|
813
|
+
};
|
|
814
|
+
const run = async (function_, resolve, arguments_) => {
|
|
815
|
+
const result = (async () => function_(...arguments_))();
|
|
816
|
+
resolve(result);
|
|
817
|
+
try {
|
|
818
|
+
await result;
|
|
819
|
+
} catch {}
|
|
820
|
+
next();
|
|
821
|
+
};
|
|
822
|
+
const enqueue = (function_, resolve, reject, arguments_) => {
|
|
823
|
+
const queueItem = { reject };
|
|
824
|
+
new Promise((internalResolve) => {
|
|
825
|
+
queueItem.run = internalResolve;
|
|
826
|
+
queue.enqueue(queueItem);
|
|
827
|
+
}).then(run.bind(void 0, function_, resolve, arguments_));
|
|
828
|
+
if (activeCount < concurrency) resumeNext();
|
|
829
|
+
};
|
|
830
|
+
const generator = (function_, ...arguments_) => new Promise((resolve, reject) => {
|
|
831
|
+
enqueue(function_, resolve, reject, arguments_);
|
|
832
|
+
});
|
|
833
|
+
Object.defineProperties(generator, {
|
|
834
|
+
activeCount: { get: () => activeCount },
|
|
835
|
+
pendingCount: { get: () => queue.size },
|
|
836
|
+
clearQueue: { value() {
|
|
837
|
+
if (!rejectOnClear) {
|
|
838
|
+
queue.clear();
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
const abortError = AbortSignal.abort().reason;
|
|
842
|
+
while (queue.size > 0) queue.dequeue().reject(abortError);
|
|
843
|
+
} },
|
|
844
|
+
concurrency: {
|
|
845
|
+
get: () => concurrency,
|
|
846
|
+
set(newConcurrency) {
|
|
847
|
+
validateConcurrency(newConcurrency);
|
|
848
|
+
concurrency = newConcurrency;
|
|
849
|
+
queueMicrotask(() => {
|
|
850
|
+
while (activeCount < concurrency && queue.size > 0) resumeNext();
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
map: { async value(iterable, function_) {
|
|
855
|
+
const promises = Array.from(iterable, (value, index) => this(function_, value, index));
|
|
856
|
+
return Promise.all(promises);
|
|
857
|
+
} }
|
|
858
|
+
});
|
|
859
|
+
return generator;
|
|
860
|
+
}
|
|
861
|
+
function validateConcurrency(concurrency) {
|
|
862
|
+
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
863
|
+
}
|
|
864
|
+
//#endregion
|
|
865
|
+
//#region src/utils/executeStrategies.ts
|
|
866
|
+
/**
|
|
867
|
+
* Chains promises
|
|
868
|
+
*/
|
|
869
|
+
function hookSeq(promises) {
|
|
870
|
+
return promises.filter(Boolean).reduce((promise, func) => {
|
|
871
|
+
if (typeof func !== "function") throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
872
|
+
return promise.then((state) => {
|
|
873
|
+
const calledFunc = func(state);
|
|
874
|
+
if (calledFunc) return calledFunc.then(Array.prototype.concat.bind(state));
|
|
875
|
+
return state;
|
|
876
|
+
});
|
|
877
|
+
}, Promise.resolve([]));
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Chains promises, first non-null result stops and returns
|
|
881
|
+
*/
|
|
882
|
+
function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
883
|
+
let promise = Promise.resolve(null);
|
|
884
|
+
for (const func of promises.filter(Boolean)) promise = promise.then((state) => {
|
|
885
|
+
if (nullCheck(state)) return state;
|
|
886
|
+
return func(state);
|
|
887
|
+
});
|
|
888
|
+
return promise;
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Runs an array of promise functions with optional concurrency limit.
|
|
892
|
+
*/
|
|
893
|
+
function hookParallel(promises, concurrency = Number.POSITIVE_INFINITY) {
|
|
894
|
+
const limit = pLimit(concurrency);
|
|
895
|
+
const tasks = promises.filter(Boolean).map((promise) => limit(() => promise()));
|
|
896
|
+
return Promise.allSettled(tasks);
|
|
897
|
+
}
|
|
898
|
+
//#endregion
|
|
899
|
+
//#region src/PromiseManager.ts
|
|
900
|
+
var PromiseManager = class {
|
|
901
|
+
#options = {};
|
|
902
|
+
constructor(options = {}) {
|
|
903
|
+
this.#options = options;
|
|
904
|
+
}
|
|
905
|
+
run(strategy, promises, { concurrency = Number.POSITIVE_INFINITY } = {}) {
|
|
906
|
+
if (strategy === "seq") return hookSeq(promises);
|
|
907
|
+
if (strategy === "first") return hookFirst(promises, this.#options.nullCheck);
|
|
908
|
+
if (strategy === "parallel") return hookParallel(promises, concurrency);
|
|
909
|
+
throw new Error(`${strategy} not implemented`);
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
function isPromiseRejectedResult(result) {
|
|
913
|
+
return result.status === "rejected";
|
|
914
|
+
}
|
|
915
|
+
//#endregion
|
|
916
|
+
//#region src/PluginManager.ts
|
|
917
|
+
function getMode(fileOrFolder) {
|
|
918
|
+
if (!fileOrFolder) return "split";
|
|
919
|
+
return path.extname(fileOrFolder) ? "single" : "split";
|
|
920
|
+
}
|
|
921
|
+
var PluginManager = class {
|
|
922
|
+
config;
|
|
923
|
+
options;
|
|
924
|
+
#plugins = /* @__PURE__ */ new Set();
|
|
925
|
+
#usedPluginNames = {};
|
|
926
|
+
#promiseManager;
|
|
927
|
+
constructor(config, options) {
|
|
928
|
+
this.config = config;
|
|
929
|
+
this.options = options;
|
|
930
|
+
this.#promiseManager = new PromiseManager({ nullCheck: (state) => !!state?.result });
|
|
931
|
+
[...config.plugins || []].forEach((plugin) => {
|
|
932
|
+
const parsedPlugin = this.#parse(plugin);
|
|
933
|
+
this.#plugins.add(parsedPlugin);
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
get events() {
|
|
937
|
+
return this.options.events;
|
|
938
|
+
}
|
|
939
|
+
getContext(plugin) {
|
|
940
|
+
const plugins = [...this.#plugins];
|
|
941
|
+
const baseContext = {
|
|
942
|
+
fabric: this.options.fabric,
|
|
943
|
+
config: this.config,
|
|
944
|
+
plugin,
|
|
945
|
+
events: this.options.events,
|
|
946
|
+
pluginManager: this,
|
|
947
|
+
mode: getMode(path.resolve(this.config.root, this.config.output.path)),
|
|
948
|
+
addFile: async (...files) => {
|
|
949
|
+
await this.options.fabric.addFile(...files);
|
|
950
|
+
},
|
|
951
|
+
upsertFile: async (...files) => {
|
|
952
|
+
await this.options.fabric.upsertFile(...files);
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
const mergedExtras = {};
|
|
956
|
+
for (const p of plugins) if (typeof p.inject === "function") {
|
|
957
|
+
const result = p.inject.call(baseContext, baseContext);
|
|
958
|
+
if (result !== null && typeof result === "object") Object.assign(mergedExtras, result);
|
|
959
|
+
}
|
|
960
|
+
return {
|
|
961
|
+
...baseContext,
|
|
962
|
+
...mergedExtras
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
get plugins() {
|
|
966
|
+
return this.#getSortedPlugins();
|
|
967
|
+
}
|
|
968
|
+
getFile({ name, mode, extname, pluginKey, options }) {
|
|
969
|
+
const baseName = `${name}${extname}`;
|
|
970
|
+
const path = this.resolvePath({
|
|
971
|
+
baseName,
|
|
972
|
+
mode,
|
|
973
|
+
pluginKey,
|
|
974
|
+
options
|
|
975
|
+
});
|
|
976
|
+
if (!path) throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`);
|
|
977
|
+
return {
|
|
978
|
+
path,
|
|
979
|
+
baseName,
|
|
980
|
+
meta: { pluginKey },
|
|
981
|
+
sources: [],
|
|
982
|
+
imports: [],
|
|
983
|
+
exports: []
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
resolvePath = (params) => {
|
|
987
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
988
|
+
const defaultPath = path.resolve(root, params.baseName);
|
|
989
|
+
if (params.pluginKey) return this.hookForPluginSync({
|
|
990
|
+
pluginKey: params.pluginKey,
|
|
991
|
+
hookName: "resolvePath",
|
|
992
|
+
parameters: [
|
|
993
|
+
params.baseName,
|
|
994
|
+
params.mode,
|
|
995
|
+
params.options
|
|
996
|
+
]
|
|
997
|
+
})?.at(0) || defaultPath;
|
|
998
|
+
return this.hookFirstSync({
|
|
999
|
+
hookName: "resolvePath",
|
|
1000
|
+
parameters: [
|
|
1001
|
+
params.baseName,
|
|
1002
|
+
params.mode,
|
|
1003
|
+
params.options
|
|
1004
|
+
]
|
|
1005
|
+
})?.result || defaultPath;
|
|
1006
|
+
};
|
|
1007
|
+
resolveName = (params) => {
|
|
1008
|
+
if (params.pluginKey) {
|
|
1009
|
+
const names = this.hookForPluginSync({
|
|
1010
|
+
pluginKey: params.pluginKey,
|
|
1011
|
+
hookName: "resolveName",
|
|
1012
|
+
parameters: [params.name.trim(), params.type]
|
|
1013
|
+
});
|
|
1014
|
+
return transformReservedWord([...new Set(names)].at(0) || params.name);
|
|
1015
|
+
}
|
|
1016
|
+
const name = this.hookFirstSync({
|
|
1017
|
+
hookName: "resolveName",
|
|
1018
|
+
parameters: [params.name.trim(), params.type]
|
|
1019
|
+
})?.result;
|
|
1020
|
+
return transformReservedWord(name ?? params.name);
|
|
1021
|
+
};
|
|
1022
|
+
/**
|
|
1023
|
+
* Run a specific hookName for plugin x.
|
|
1024
|
+
*/
|
|
1025
|
+
async hookForPlugin({ pluginKey, hookName, parameters }) {
|
|
1026
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1027
|
+
this.events.emit("plugins:hook:progress:start", {
|
|
1028
|
+
hookName,
|
|
1029
|
+
plugins
|
|
1030
|
+
});
|
|
1031
|
+
const items = [];
|
|
1032
|
+
for (const plugin of plugins) {
|
|
1033
|
+
const result = await this.#execute({
|
|
1034
|
+
strategy: "hookFirst",
|
|
1035
|
+
hookName,
|
|
1036
|
+
parameters,
|
|
1037
|
+
plugin
|
|
1038
|
+
});
|
|
1039
|
+
if (result !== void 0 && result !== null) items.push(result);
|
|
1040
|
+
}
|
|
1041
|
+
this.events.emit("plugins:hook:progress:end", { hookName });
|
|
1042
|
+
return items;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Run a specific hookName for plugin x.
|
|
1046
|
+
*/
|
|
1047
|
+
hookForPluginSync({ pluginKey, hookName, parameters }) {
|
|
1048
|
+
return this.getPluginsByKey(hookName, pluginKey).map((plugin) => {
|
|
1049
|
+
return this.#executeSync({
|
|
1050
|
+
strategy: "hookFirst",
|
|
1051
|
+
hookName,
|
|
1052
|
+
parameters,
|
|
1053
|
+
plugin
|
|
1054
|
+
});
|
|
1055
|
+
}).filter((x) => x !== null);
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Returns the first non-null result.
|
|
1059
|
+
*/
|
|
1060
|
+
async hookFirst({ hookName, parameters, skipped }) {
|
|
1061
|
+
const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
|
|
1062
|
+
return skipped ? !skipped.has(plugin) : true;
|
|
1063
|
+
});
|
|
1064
|
+
this.events.emit("plugins:hook:progress:start", {
|
|
1065
|
+
hookName,
|
|
1066
|
+
plugins
|
|
1067
|
+
});
|
|
1068
|
+
const promises = plugins.map((plugin) => {
|
|
1069
|
+
return async () => {
|
|
1070
|
+
const value = await this.#execute({
|
|
1071
|
+
strategy: "hookFirst",
|
|
1072
|
+
hookName,
|
|
1073
|
+
parameters,
|
|
1074
|
+
plugin
|
|
1075
|
+
});
|
|
1076
|
+
return Promise.resolve({
|
|
1077
|
+
plugin,
|
|
1078
|
+
result: value
|
|
1079
|
+
});
|
|
1080
|
+
};
|
|
1081
|
+
});
|
|
1082
|
+
const result = await this.#promiseManager.run("first", promises);
|
|
1083
|
+
this.events.emit("plugins:hook:progress:end", { hookName });
|
|
1084
|
+
return result;
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Returns the first non-null result.
|
|
1088
|
+
*/
|
|
1089
|
+
hookFirstSync({ hookName, parameters, skipped }) {
|
|
1090
|
+
let parseResult = null;
|
|
1091
|
+
const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
|
|
1092
|
+
return skipped ? !skipped.has(plugin) : true;
|
|
1093
|
+
});
|
|
1094
|
+
for (const plugin of plugins) {
|
|
1095
|
+
parseResult = {
|
|
1096
|
+
result: this.#executeSync({
|
|
1097
|
+
strategy: "hookFirst",
|
|
1098
|
+
hookName,
|
|
1099
|
+
parameters,
|
|
1100
|
+
plugin
|
|
1101
|
+
}),
|
|
1102
|
+
plugin
|
|
1103
|
+
};
|
|
1104
|
+
if (parseResult?.result != null) break;
|
|
1105
|
+
}
|
|
1106
|
+
return parseResult;
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
|
|
1110
|
+
*/
|
|
1111
|
+
async hookParallel({ hookName, parameters }) {
|
|
1112
|
+
const plugins = this.#getSortedPlugins(hookName);
|
|
1113
|
+
this.events.emit("plugins:hook:progress:start", {
|
|
1114
|
+
hookName,
|
|
1115
|
+
plugins
|
|
1116
|
+
});
|
|
1117
|
+
const pluginStartTimes = /* @__PURE__ */ new Map();
|
|
1118
|
+
const promises = plugins.map((plugin) => {
|
|
1119
|
+
return () => {
|
|
1120
|
+
pluginStartTimes.set(plugin, performance.now());
|
|
1121
|
+
return this.#execute({
|
|
1122
|
+
strategy: "hookParallel",
|
|
1123
|
+
hookName,
|
|
1124
|
+
parameters,
|
|
1125
|
+
plugin
|
|
1126
|
+
});
|
|
1127
|
+
};
|
|
1128
|
+
});
|
|
1129
|
+
const results = await this.#promiseManager.run("parallel", promises, { concurrency: this.options.concurrency });
|
|
1130
|
+
results.forEach((result, index) => {
|
|
1131
|
+
if (isPromiseRejectedResult(result)) {
|
|
1132
|
+
const plugin = this.#getSortedPlugins(hookName)[index];
|
|
1133
|
+
if (plugin) {
|
|
1134
|
+
const startTime = pluginStartTimes.get(plugin) ?? performance.now();
|
|
1135
|
+
this.events.emit("error", result.reason, {
|
|
1136
|
+
plugin,
|
|
1137
|
+
hookName,
|
|
1138
|
+
strategy: "hookParallel",
|
|
1139
|
+
duration: Math.round(performance.now() - startTime),
|
|
1140
|
+
parameters
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
this.events.emit("plugins:hook:progress:end", { hookName });
|
|
1146
|
+
return results.reduce((acc, result) => {
|
|
1147
|
+
if (result.status === "fulfilled") acc.push(result.value);
|
|
1148
|
+
return acc;
|
|
1149
|
+
}, []);
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Chains plugins
|
|
1153
|
+
*/
|
|
1154
|
+
async hookSeq({ hookName, parameters }) {
|
|
1155
|
+
const plugins = this.#getSortedPlugins(hookName);
|
|
1156
|
+
this.events.emit("plugins:hook:progress:start", {
|
|
1157
|
+
hookName,
|
|
1158
|
+
plugins
|
|
1159
|
+
});
|
|
1160
|
+
const promises = plugins.map((plugin) => {
|
|
1161
|
+
return () => this.#execute({
|
|
1162
|
+
strategy: "hookSeq",
|
|
1163
|
+
hookName,
|
|
1164
|
+
parameters,
|
|
1165
|
+
plugin
|
|
1166
|
+
});
|
|
1167
|
+
});
|
|
1168
|
+
await this.#promiseManager.run("seq", promises);
|
|
1169
|
+
this.events.emit("plugins:hook:progress:end", { hookName });
|
|
1170
|
+
}
|
|
1171
|
+
#getSortedPlugins(hookName) {
|
|
1172
|
+
const plugins = [...this.#plugins];
|
|
1173
|
+
if (hookName) return plugins.filter((plugin) => hookName in plugin);
|
|
1174
|
+
return plugins.map((plugin) => {
|
|
1175
|
+
if (plugin.pre) {
|
|
1176
|
+
const missingPlugins = plugin.pre.filter((pluginName) => !plugins.find((pluginToFind) => pluginToFind.name === pluginName));
|
|
1177
|
+
if (missingPlugins.length > 0) throw new ValidationPluginError(`The plugin '${plugin.name}' has a pre set that references missing plugins for '${missingPlugins.join(", ")}'`);
|
|
1178
|
+
}
|
|
1179
|
+
return plugin;
|
|
1180
|
+
}).sort((a, b) => {
|
|
1181
|
+
if (b.pre?.includes(a.name)) return 1;
|
|
1182
|
+
if (b.post?.includes(a.name)) return -1;
|
|
1183
|
+
return 0;
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
getPluginByKey(pluginKey) {
|
|
1187
|
+
const plugins = [...this.#plugins];
|
|
1188
|
+
const [searchPluginName] = pluginKey;
|
|
1189
|
+
return plugins.find((item) => {
|
|
1190
|
+
const [name] = item.key;
|
|
1191
|
+
return name === searchPluginName;
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
getPluginsByKey(hookName, pluginKey) {
|
|
1195
|
+
const plugins = [...this.plugins];
|
|
1196
|
+
const [searchPluginName, searchIdentifier] = pluginKey;
|
|
1197
|
+
const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => {
|
|
1198
|
+
const [name, identifier] = item.key;
|
|
1199
|
+
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1200
|
+
const nameCheck = name === searchPluginName;
|
|
1201
|
+
if (searchIdentifier) return identifierCheck && nameCheck;
|
|
1202
|
+
return nameCheck;
|
|
1203
|
+
});
|
|
1204
|
+
if (!pluginByPluginName?.length) {
|
|
1205
|
+
const corePlugin = plugins.find((plugin) => plugin.name === "core" && hookName in plugin);
|
|
1206
|
+
return corePlugin ? [corePlugin] : [];
|
|
1207
|
+
}
|
|
1208
|
+
return pluginByPluginName;
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Run an async plugin hook and return the result.
|
|
1212
|
+
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
1213
|
+
* @param args Arguments passed to the plugin hook.
|
|
1214
|
+
* @param plugin The actual pluginObject to run.
|
|
1215
|
+
*/
|
|
1216
|
+
#emitProcessingEnd({ startTime, output, strategy, hookName, plugin, parameters }) {
|
|
1217
|
+
this.events.emit("plugins:hook:processing:end", {
|
|
1218
|
+
duration: Math.round(performance.now() - startTime),
|
|
1219
|
+
parameters,
|
|
1220
|
+
output,
|
|
1221
|
+
strategy,
|
|
1222
|
+
hookName,
|
|
1223
|
+
plugin
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
#execute({ strategy, hookName, parameters, plugin }) {
|
|
1227
|
+
const hook = plugin[hookName];
|
|
1228
|
+
if (!hook) return null;
|
|
1229
|
+
this.events.emit("plugins:hook:processing:start", {
|
|
1230
|
+
strategy,
|
|
1231
|
+
hookName,
|
|
1232
|
+
parameters,
|
|
1233
|
+
plugin
|
|
1234
|
+
});
|
|
1235
|
+
const startTime = performance.now();
|
|
1236
|
+
return (async () => {
|
|
1237
|
+
try {
|
|
1238
|
+
const output = typeof hook === "function" ? await Promise.resolve(hook.apply(this.getContext(plugin), parameters ?? [])) : hook;
|
|
1239
|
+
this.#emitProcessingEnd({
|
|
1240
|
+
startTime,
|
|
1241
|
+
output,
|
|
1242
|
+
strategy,
|
|
1243
|
+
hookName,
|
|
1244
|
+
plugin,
|
|
1245
|
+
parameters
|
|
1246
|
+
});
|
|
1247
|
+
return output;
|
|
1248
|
+
} catch (error) {
|
|
1249
|
+
this.events.emit("error", error, {
|
|
1250
|
+
plugin,
|
|
1251
|
+
hookName,
|
|
1252
|
+
strategy,
|
|
1253
|
+
duration: Math.round(performance.now() - startTime)
|
|
1254
|
+
});
|
|
1255
|
+
return null;
|
|
1256
|
+
}
|
|
1257
|
+
})();
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Run a sync plugin hook and return the result.
|
|
1261
|
+
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
1262
|
+
* @param args Arguments passed to the plugin hook.
|
|
1263
|
+
* @param plugin The actual plugin
|
|
1264
|
+
*/
|
|
1265
|
+
#executeSync({ strategy, hookName, parameters, plugin }) {
|
|
1266
|
+
const hook = plugin[hookName];
|
|
1267
|
+
if (!hook) return null;
|
|
1268
|
+
this.events.emit("plugins:hook:processing:start", {
|
|
1269
|
+
strategy,
|
|
1270
|
+
hookName,
|
|
1271
|
+
parameters,
|
|
1272
|
+
plugin
|
|
1273
|
+
});
|
|
1274
|
+
const startTime = performance.now();
|
|
1275
|
+
try {
|
|
1276
|
+
const output = typeof hook === "function" ? hook.apply(this.getContext(plugin), parameters) : hook;
|
|
1277
|
+
this.#emitProcessingEnd({
|
|
1278
|
+
startTime,
|
|
1279
|
+
output,
|
|
1280
|
+
strategy,
|
|
1281
|
+
hookName,
|
|
1282
|
+
plugin,
|
|
1283
|
+
parameters
|
|
1284
|
+
});
|
|
1285
|
+
return output;
|
|
1286
|
+
} catch (error) {
|
|
1287
|
+
this.events.emit("error", error, {
|
|
1288
|
+
plugin,
|
|
1289
|
+
hookName,
|
|
1290
|
+
strategy,
|
|
1291
|
+
duration: Math.round(performance.now() - startTime)
|
|
1292
|
+
});
|
|
1293
|
+
return null;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
#parse(plugin) {
|
|
1297
|
+
const usedPluginNames = this.#usedPluginNames;
|
|
1298
|
+
setUniqueName(plugin.name, usedPluginNames);
|
|
1299
|
+
const usageCount = usedPluginNames[plugin.name];
|
|
1300
|
+
if (usageCount && usageCount > 1) this.events.emit("warn", `Multiple instances of plugin "${plugin.name}" detected. This behavior is deprecated and will be removed in v5.`, `Plugin key: [${plugin.name}, ${usageCount}]`);
|
|
1301
|
+
return {
|
|
1302
|
+
install() {},
|
|
1303
|
+
...plugin,
|
|
1304
|
+
key: [plugin.name, usedPluginNames[plugin.name]].filter(Boolean)
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
65
1308
|
//#endregion
|
|
66
1309
|
//#region package.json
|
|
67
|
-
var version$1 = "4.
|
|
1310
|
+
var version$1 = "4.33.1";
|
|
68
1311
|
//#endregion
|
|
69
1312
|
//#region src/utils/diagnostics.ts
|
|
70
1313
|
/**
|
|
@@ -122,8 +1365,8 @@ async function setup(options) {
|
|
|
122
1365
|
output: {
|
|
123
1366
|
write: true,
|
|
124
1367
|
barrelType: "named",
|
|
125
|
-
extension:
|
|
126
|
-
defaultBanner:
|
|
1368
|
+
extension: DEFAULT_EXTENSION,
|
|
1369
|
+
defaultBanner: DEFAULT_BANNER,
|
|
127
1370
|
...userConfig.output
|
|
128
1371
|
},
|
|
129
1372
|
plugins: userConfig.plugins
|
|
@@ -254,7 +1497,8 @@ async function safeBuild(options, overrides) {
|
|
|
254
1497
|
}
|
|
255
1498
|
}
|
|
256
1499
|
if (config.output.barrelType) {
|
|
257
|
-
const rootPath = resolve(resolve(config.root), config.output.path,
|
|
1500
|
+
const rootPath = resolve(resolve(config.root), config.output.path, BARREL_FILENAME);
|
|
1501
|
+
const rootDir = dirname(rootPath);
|
|
258
1502
|
await events.emit("debug", {
|
|
259
1503
|
date: /* @__PURE__ */ new Date(),
|
|
260
1504
|
logs: [
|
|
@@ -270,25 +1514,17 @@ async function safeBuild(options, overrides) {
|
|
|
270
1514
|
date: /* @__PURE__ */ new Date(),
|
|
271
1515
|
logs: [`Found ${barrelFiles.length} indexable files for barrel export`]
|
|
272
1516
|
});
|
|
273
|
-
const
|
|
274
|
-
for (const plugin of pluginManager.plugins) pluginKeyMap.set(JSON.stringify(plugin.key), plugin);
|
|
1517
|
+
const existingBarrel = fabric.files.find((f) => f.path === rootPath);
|
|
275
1518
|
const rootFile = {
|
|
276
1519
|
path: rootPath,
|
|
277
|
-
baseName:
|
|
278
|
-
exports:
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
return {
|
|
286
|
-
name: config.output.barrelType === "all" ? void 0 : [source.name],
|
|
287
|
-
path: getRelativePath(rootPath, file.path),
|
|
288
|
-
isTypeOnly: config.output.barrelType === "all" ? containsOnlyTypes : source.isTypeOnly
|
|
289
|
-
};
|
|
290
|
-
}).filter(Boolean);
|
|
291
|
-
}).filter(Boolean),
|
|
1520
|
+
baseName: BARREL_FILENAME,
|
|
1521
|
+
exports: buildBarrelExports({
|
|
1522
|
+
barrelFiles,
|
|
1523
|
+
rootDir,
|
|
1524
|
+
existingExports: new Set(existingBarrel?.exports?.flatMap((e) => Array.isArray(e.name) ? e.name : [e.name]).filter((n) => Boolean(n)) ?? []),
|
|
1525
|
+
config,
|
|
1526
|
+
pluginManager
|
|
1527
|
+
}),
|
|
292
1528
|
sources: [],
|
|
293
1529
|
imports: [],
|
|
294
1530
|
meta: {}
|
|
@@ -321,6 +1557,26 @@ async function safeBuild(options, overrides) {
|
|
|
321
1557
|
};
|
|
322
1558
|
}
|
|
323
1559
|
}
|
|
1560
|
+
function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, pluginManager }) {
|
|
1561
|
+
const pluginKeyMap = /* @__PURE__ */ new Map();
|
|
1562
|
+
for (const plugin of pluginManager.plugins) pluginKeyMap.set(JSON.stringify(plugin.key), plugin);
|
|
1563
|
+
return barrelFiles.flatMap((file) => {
|
|
1564
|
+
const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly);
|
|
1565
|
+
return (file.sources ?? []).flatMap((source) => {
|
|
1566
|
+
if (!file.path || !source.isIndexable) return [];
|
|
1567
|
+
const meta = file.meta;
|
|
1568
|
+
const pluginOptions = (meta?.pluginKey ? pluginKeyMap.get(JSON.stringify(meta.pluginKey)) : void 0)?.options;
|
|
1569
|
+
if (!pluginOptions || pluginOptions.output?.barrelType === false) return [];
|
|
1570
|
+
const exportName = config.output.barrelType === "all" ? void 0 : source.name ? [source.name] : void 0;
|
|
1571
|
+
if (exportName?.some((n) => existingExports.has(n))) return [];
|
|
1572
|
+
return [{
|
|
1573
|
+
name: exportName,
|
|
1574
|
+
path: getRelativePath(rootDir, file.path),
|
|
1575
|
+
isTypeOnly: config.output.barrelType === "all" ? containsOnlyTypes : source.isTypeOnly
|
|
1576
|
+
}];
|
|
1577
|
+
});
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
324
1580
|
//#endregion
|
|
325
1581
|
//#region src/defineLogger.ts
|
|
326
1582
|
function defineLogger(logger) {
|
|
@@ -339,10 +1595,8 @@ function definePlugin(build) {
|
|
|
339
1595
|
var PackageManager = class PackageManager {
|
|
340
1596
|
static #cache = {};
|
|
341
1597
|
#cwd;
|
|
342
|
-
#SLASHES = new Set(["/", "\\"]);
|
|
343
1598
|
constructor(workspace) {
|
|
344
1599
|
if (workspace) this.#cwd = workspace;
|
|
345
|
-
return this;
|
|
346
1600
|
}
|
|
347
1601
|
set workspace(workspace) {
|
|
348
1602
|
this.#cwd = workspace;
|
|
@@ -352,7 +1606,7 @@ var PackageManager = class PackageManager {
|
|
|
352
1606
|
}
|
|
353
1607
|
normalizeDirectory(directory) {
|
|
354
1608
|
const lastChar = directory[directory.length - 1];
|
|
355
|
-
if (lastChar && !
|
|
1609
|
+
if (lastChar && !PATH_SEPARATORS.includes(lastChar)) return `${directory}/`;
|
|
356
1610
|
return directory;
|
|
357
1611
|
}
|
|
358
1612
|
getLocation(path) {
|
|
@@ -361,15 +1615,10 @@ var PackageManager = class PackageManager {
|
|
|
361
1615
|
return location;
|
|
362
1616
|
}
|
|
363
1617
|
async import(path) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return module?.default ?? module;
|
|
369
|
-
} catch (error) {
|
|
370
|
-
console.error(error);
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
1618
|
+
let location = this.getLocation(path);
|
|
1619
|
+
if (os.platform() === "win32") location = pathToFileURL(location).href;
|
|
1620
|
+
const module = await import(location);
|
|
1621
|
+
return module?.default ?? module;
|
|
373
1622
|
}
|
|
374
1623
|
async getPackageJSON() {
|
|
375
1624
|
const pkgPath = pkg.up({ cwd: this.#cwd });
|
|
@@ -388,8 +1637,8 @@ var PackageManager = class PackageManager {
|
|
|
388
1637
|
}
|
|
389
1638
|
#match(packageJSON, dependency) {
|
|
390
1639
|
const dependencies = {
|
|
391
|
-
...packageJSON
|
|
392
|
-
...packageJSON
|
|
1640
|
+
...packageJSON.dependencies || {},
|
|
1641
|
+
...packageJSON.devDependencies || {}
|
|
393
1642
|
};
|
|
394
1643
|
if (typeof dependency === "string" && dependencies[dependency]) return dependencies[dependency];
|
|
395
1644
|
const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
|
|
@@ -425,16 +1674,375 @@ var PackageManager = class PackageManager {
|
|
|
425
1674
|
}
|
|
426
1675
|
};
|
|
427
1676
|
//#endregion
|
|
428
|
-
//#region src/
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
1677
|
+
//#region src/utils/FunctionParams.ts
|
|
1678
|
+
/**
|
|
1679
|
+
* @deprecated
|
|
1680
|
+
*/
|
|
1681
|
+
var FunctionParams = class FunctionParams {
|
|
1682
|
+
#items = [];
|
|
1683
|
+
get items() {
|
|
1684
|
+
return this.#items.flat();
|
|
1685
|
+
}
|
|
1686
|
+
add(item) {
|
|
1687
|
+
if (!item) return this;
|
|
1688
|
+
if (Array.isArray(item)) {
|
|
1689
|
+
item.filter((x) => x !== void 0).forEach((it) => {
|
|
1690
|
+
this.#items.push(it);
|
|
1691
|
+
});
|
|
1692
|
+
return this;
|
|
1693
|
+
}
|
|
1694
|
+
this.#items.push(item);
|
|
1695
|
+
return this;
|
|
1696
|
+
}
|
|
1697
|
+
static #orderItems(items) {
|
|
1698
|
+
return sortBy(items.filter(Boolean), [(item) => Array.isArray(item), "desc"], [(item) => !Array.isArray(item) && item.default !== void 0, "asc"], [(item) => Array.isArray(item) || (item.required ?? true), "desc"]);
|
|
1699
|
+
}
|
|
1700
|
+
static #addParams(acc, item) {
|
|
1701
|
+
const { enabled = true, name, type, required = true, ...rest } = item;
|
|
1702
|
+
if (!enabled) return acc;
|
|
1703
|
+
if (!name) {
|
|
1704
|
+
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
1705
|
+
return acc;
|
|
1706
|
+
}
|
|
1707
|
+
const parameterName = name.startsWith("{") ? name : camelCase(name);
|
|
1708
|
+
if (type) if (required) acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
1709
|
+
else acc.push(`${parameterName}?: ${type}`);
|
|
1710
|
+
else acc.push(`${parameterName}`);
|
|
1711
|
+
return acc;
|
|
1712
|
+
}
|
|
1713
|
+
static toObject(items) {
|
|
1714
|
+
let type = [];
|
|
1715
|
+
let name = [];
|
|
1716
|
+
const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true;
|
|
1717
|
+
const required = items.every((item) => item.required) ?? true;
|
|
1718
|
+
items.forEach((item) => {
|
|
1719
|
+
name = FunctionParams.#addParams(name, {
|
|
1720
|
+
...item,
|
|
1721
|
+
type: void 0
|
|
1722
|
+
});
|
|
1723
|
+
if (items.some((item) => item.type)) type = FunctionParams.#addParams(type, item);
|
|
1724
|
+
});
|
|
1725
|
+
return {
|
|
1726
|
+
name: `{ ${name.join(", ")} }`,
|
|
1727
|
+
type: type.length ? `{ ${type.join("; ")} }` : void 0,
|
|
1728
|
+
enabled,
|
|
1729
|
+
required
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
toObject() {
|
|
1733
|
+
const items = FunctionParams.#orderItems(this.#items).flat();
|
|
1734
|
+
return FunctionParams.toObject(items);
|
|
1735
|
+
}
|
|
1736
|
+
static toString(items) {
|
|
1737
|
+
return FunctionParams.#orderItems(items).reduce((acc, item) => {
|
|
1738
|
+
if (Array.isArray(item)) {
|
|
1739
|
+
if (item.length <= 0) return acc;
|
|
1740
|
+
const subItems = FunctionParams.#orderItems(item);
|
|
1741
|
+
const objectItem = FunctionParams.toObject(subItems);
|
|
1742
|
+
return FunctionParams.#addParams(acc, objectItem);
|
|
1743
|
+
}
|
|
1744
|
+
return FunctionParams.#addParams(acc, item);
|
|
1745
|
+
}, []).join(", ");
|
|
1746
|
+
}
|
|
1747
|
+
toString() {
|
|
1748
|
+
const items = FunctionParams.#orderItems(this.#items);
|
|
1749
|
+
return FunctionParams.toString(items);
|
|
1750
|
+
}
|
|
436
1751
|
};
|
|
437
1752
|
//#endregion
|
|
438
|
-
|
|
1753
|
+
//#region src/utils/formatters.ts
|
|
1754
|
+
/**
|
|
1755
|
+
* Check if a formatter command is available in the system.
|
|
1756
|
+
*
|
|
1757
|
+
* @param formatter - The formatter to check ('biome', 'prettier', or 'oxfmt')
|
|
1758
|
+
* @returns Promise that resolves to true if the formatter is available, false otherwise
|
|
1759
|
+
*
|
|
1760
|
+
* @remarks
|
|
1761
|
+
* This function checks availability by running `<formatter> --version` command.
|
|
1762
|
+
* All supported formatters (biome, prettier, oxfmt) implement the --version flag.
|
|
1763
|
+
*/
|
|
1764
|
+
async function isFormatterAvailable(formatter) {
|
|
1765
|
+
try {
|
|
1766
|
+
await x(formatter, ["--version"], { nodeOptions: { stdio: "ignore" } });
|
|
1767
|
+
return true;
|
|
1768
|
+
} catch {
|
|
1769
|
+
return false;
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Detect which formatter is available in the system.
|
|
1774
|
+
*
|
|
1775
|
+
* @returns Promise that resolves to the first available formatter or undefined if none are found
|
|
1776
|
+
*
|
|
1777
|
+
* @remarks
|
|
1778
|
+
* Checks in order of preference: biome, oxfmt, prettier.
|
|
1779
|
+
* Uses the `--version` flag to detect if each formatter command is available.
|
|
1780
|
+
* This is a reliable method as all supported formatters implement this flag.
|
|
1781
|
+
*
|
|
1782
|
+
* @example
|
|
1783
|
+
* ```typescript
|
|
1784
|
+
* const formatter = await detectFormatter()
|
|
1785
|
+
* if (formatter) {
|
|
1786
|
+
* console.log(`Using ${formatter} for formatting`)
|
|
1787
|
+
* } else {
|
|
1788
|
+
* console.log('No formatter found')
|
|
1789
|
+
* }
|
|
1790
|
+
* ```
|
|
1791
|
+
*/
|
|
1792
|
+
async function detectFormatter() {
|
|
1793
|
+
for (const formatter of [
|
|
1794
|
+
"biome",
|
|
1795
|
+
"oxfmt",
|
|
1796
|
+
"prettier"
|
|
1797
|
+
]) if (await isFormatterAvailable(formatter)) return formatter;
|
|
1798
|
+
}
|
|
1799
|
+
//#endregion
|
|
1800
|
+
//#region src/utils/TreeNode.ts
|
|
1801
|
+
var TreeNode = class TreeNode {
|
|
1802
|
+
data;
|
|
1803
|
+
parent;
|
|
1804
|
+
children = [];
|
|
1805
|
+
#cachedLeaves = void 0;
|
|
1806
|
+
constructor(data, parent) {
|
|
1807
|
+
this.data = data;
|
|
1808
|
+
this.parent = parent;
|
|
1809
|
+
}
|
|
1810
|
+
addChild(data) {
|
|
1811
|
+
const child = new TreeNode(data, this);
|
|
1812
|
+
if (!this.children) this.children = [];
|
|
1813
|
+
this.children.push(child);
|
|
1814
|
+
return child;
|
|
1815
|
+
}
|
|
1816
|
+
get root() {
|
|
1817
|
+
if (!this.parent) return this;
|
|
1818
|
+
return this.parent.root;
|
|
1819
|
+
}
|
|
1820
|
+
get leaves() {
|
|
1821
|
+
if (!this.children || this.children.length === 0) return [this];
|
|
1822
|
+
if (this.#cachedLeaves) return this.#cachedLeaves;
|
|
1823
|
+
const leaves = [];
|
|
1824
|
+
for (const child of this.children) leaves.push(...child.leaves);
|
|
1825
|
+
this.#cachedLeaves = leaves;
|
|
1826
|
+
return leaves;
|
|
1827
|
+
}
|
|
1828
|
+
forEach(callback) {
|
|
1829
|
+
if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
|
|
1830
|
+
callback(this);
|
|
1831
|
+
for (const child of this.children) child.forEach(callback);
|
|
1832
|
+
return this;
|
|
1833
|
+
}
|
|
1834
|
+
findDeep(predicate) {
|
|
1835
|
+
if (typeof predicate !== "function") throw new TypeError("find() predicate must be a function");
|
|
1836
|
+
return this.leaves.find(predicate);
|
|
1837
|
+
}
|
|
1838
|
+
forEachDeep(callback) {
|
|
1839
|
+
if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
|
|
1840
|
+
this.leaves.forEach(callback);
|
|
1841
|
+
}
|
|
1842
|
+
filterDeep(callback) {
|
|
1843
|
+
if (typeof callback !== "function") throw new TypeError("filter() callback must be a function");
|
|
1844
|
+
return this.leaves.filter(callback);
|
|
1845
|
+
}
|
|
1846
|
+
mapDeep(callback) {
|
|
1847
|
+
if (typeof callback !== "function") throw new TypeError("map() callback must be a function");
|
|
1848
|
+
return this.leaves.map(callback);
|
|
1849
|
+
}
|
|
1850
|
+
static build(files, root) {
|
|
1851
|
+
try {
|
|
1852
|
+
const filteredTree = buildDirectoryTree(files, root);
|
|
1853
|
+
if (!filteredTree) return null;
|
|
1854
|
+
const treeNode = new TreeNode({
|
|
1855
|
+
name: filteredTree.name,
|
|
1856
|
+
path: filteredTree.path,
|
|
1857
|
+
file: filteredTree.file,
|
|
1858
|
+
type: getMode(filteredTree.path)
|
|
1859
|
+
});
|
|
1860
|
+
const recurse = (node, item) => {
|
|
1861
|
+
const subNode = node.addChild({
|
|
1862
|
+
name: item.name,
|
|
1863
|
+
path: item.path,
|
|
1864
|
+
file: item.file,
|
|
1865
|
+
type: getMode(item.path)
|
|
1866
|
+
});
|
|
1867
|
+
if (item.children?.length) item.children?.forEach((child) => {
|
|
1868
|
+
recurse(subNode, child);
|
|
1869
|
+
});
|
|
1870
|
+
};
|
|
1871
|
+
filteredTree.children?.forEach((child) => {
|
|
1872
|
+
recurse(treeNode, child);
|
|
1873
|
+
});
|
|
1874
|
+
return treeNode;
|
|
1875
|
+
} catch (error) {
|
|
1876
|
+
throw new Error("Something went wrong with creating barrel files with the TreeNode class", { cause: error });
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
const normalizePath = (p) => p.replaceAll("\\", "/");
|
|
1881
|
+
function buildDirectoryTree(files, rootFolder = "") {
|
|
1882
|
+
const normalizedRootFolder = normalizePath(rootFolder);
|
|
1883
|
+
const rootPrefix = normalizedRootFolder.endsWith("/") ? normalizedRootFolder : `${normalizedRootFolder}/`;
|
|
1884
|
+
const filteredFiles = files.filter((file) => {
|
|
1885
|
+
const normalizedFilePath = normalizePath(file.path);
|
|
1886
|
+
return rootFolder ? normalizedFilePath.startsWith(rootPrefix) && !normalizedFilePath.endsWith(".json") : !normalizedFilePath.endsWith(".json");
|
|
1887
|
+
});
|
|
1888
|
+
if (filteredFiles.length === 0) return null;
|
|
1889
|
+
const root = {
|
|
1890
|
+
name: rootFolder || "",
|
|
1891
|
+
path: rootFolder || "",
|
|
1892
|
+
children: []
|
|
1893
|
+
};
|
|
1894
|
+
filteredFiles.forEach((file) => {
|
|
1895
|
+
const parts = file.path.slice(rootFolder.length).split("/").filter(Boolean);
|
|
1896
|
+
let currentLevel = root.children;
|
|
1897
|
+
let currentPath = normalizePath(rootFolder);
|
|
1898
|
+
parts.forEach((part, index) => {
|
|
1899
|
+
currentPath = path.posix.join(currentPath, part);
|
|
1900
|
+
let existingNode = currentLevel.find((node) => node.name === part);
|
|
1901
|
+
if (!existingNode) {
|
|
1902
|
+
if (index === parts.length - 1) existingNode = {
|
|
1903
|
+
name: part,
|
|
1904
|
+
file,
|
|
1905
|
+
path: currentPath
|
|
1906
|
+
};
|
|
1907
|
+
else existingNode = {
|
|
1908
|
+
name: part,
|
|
1909
|
+
path: currentPath,
|
|
1910
|
+
children: []
|
|
1911
|
+
};
|
|
1912
|
+
currentLevel.push(existingNode);
|
|
1913
|
+
}
|
|
1914
|
+
if (!existingNode.file) currentLevel = existingNode.children;
|
|
1915
|
+
});
|
|
1916
|
+
});
|
|
1917
|
+
return root;
|
|
1918
|
+
}
|
|
1919
|
+
//#endregion
|
|
1920
|
+
//#region src/BarrelManager.ts
|
|
1921
|
+
/** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */
|
|
1922
|
+
var BarrelManager = class {
|
|
1923
|
+
getFiles({ files: generatedFiles, root }) {
|
|
1924
|
+
const cachedFiles = /* @__PURE__ */ new Map();
|
|
1925
|
+
TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
|
|
1926
|
+
if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) return;
|
|
1927
|
+
const barrelFile = {
|
|
1928
|
+
path: join(treeNode.parent?.data.path, "index.ts"),
|
|
1929
|
+
baseName: "index.ts",
|
|
1930
|
+
exports: [],
|
|
1931
|
+
imports: [],
|
|
1932
|
+
sources: []
|
|
1933
|
+
};
|
|
1934
|
+
const previousBarrelFile = cachedFiles.get(barrelFile.path);
|
|
1935
|
+
treeNode.leaves.forEach((item) => {
|
|
1936
|
+
if (!item.data.name) return;
|
|
1937
|
+
(item.data.file?.sources || []).forEach((source) => {
|
|
1938
|
+
if (!item.data.file?.path || !source.isIndexable || !source.name) return;
|
|
1939
|
+
if (previousBarrelFile?.sources.some((item) => item.name === source.name && item.isTypeOnly === source.isTypeOnly)) return;
|
|
1940
|
+
barrelFile.exports.push({
|
|
1941
|
+
name: [source.name],
|
|
1942
|
+
path: getRelativePath(treeNode.parent?.data.path, item.data.path),
|
|
1943
|
+
isTypeOnly: source.isTypeOnly
|
|
1944
|
+
});
|
|
1945
|
+
barrelFile.sources.push({
|
|
1946
|
+
name: source.name,
|
|
1947
|
+
isTypeOnly: source.isTypeOnly,
|
|
1948
|
+
value: "",
|
|
1949
|
+
isExportable: false,
|
|
1950
|
+
isIndexable: false
|
|
1951
|
+
});
|
|
1952
|
+
});
|
|
1953
|
+
});
|
|
1954
|
+
if (previousBarrelFile) {
|
|
1955
|
+
previousBarrelFile.sources.push(...barrelFile.sources);
|
|
1956
|
+
previousBarrelFile.exports?.push(...barrelFile.exports || []);
|
|
1957
|
+
} else cachedFiles.set(barrelFile.path, barrelFile);
|
|
1958
|
+
});
|
|
1959
|
+
return [...cachedFiles.values()];
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
//#endregion
|
|
1963
|
+
//#region src/utils/getBarrelFiles.ts
|
|
1964
|
+
function trimExtName(text) {
|
|
1965
|
+
const dotIndex = text.lastIndexOf(".");
|
|
1966
|
+
if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
|
|
1967
|
+
return text;
|
|
1968
|
+
}
|
|
1969
|
+
async function getBarrelFiles(files, { type, meta = {}, root, output }) {
|
|
1970
|
+
if (!type || type === "propagate") return [];
|
|
1971
|
+
const barrelManager = new BarrelManager();
|
|
1972
|
+
const pathToBuildFrom = join(root, output.path);
|
|
1973
|
+
if (trimExtName(pathToBuildFrom).endsWith("index")) return [];
|
|
1974
|
+
const barrelFiles = barrelManager.getFiles({
|
|
1975
|
+
files,
|
|
1976
|
+
root: pathToBuildFrom,
|
|
1977
|
+
meta
|
|
1978
|
+
});
|
|
1979
|
+
if (type === "all") return barrelFiles.map((file) => {
|
|
1980
|
+
return {
|
|
1981
|
+
...file,
|
|
1982
|
+
exports: file.exports?.map((exportItem) => {
|
|
1983
|
+
return {
|
|
1984
|
+
...exportItem,
|
|
1985
|
+
name: void 0
|
|
1986
|
+
};
|
|
1987
|
+
})
|
|
1988
|
+
};
|
|
1989
|
+
});
|
|
1990
|
+
return barrelFiles.map((indexFile) => {
|
|
1991
|
+
return {
|
|
1992
|
+
...indexFile,
|
|
1993
|
+
meta
|
|
1994
|
+
};
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
//#endregion
|
|
1998
|
+
//#region src/utils/getPlugins.ts
|
|
1999
|
+
function isJSONPlugins(plugins) {
|
|
2000
|
+
return Array.isArray(plugins) && plugins.some((plugin) => Array.isArray(plugin) && typeof plugin[0] === "string");
|
|
2001
|
+
}
|
|
2002
|
+
function isObjectPlugins(plugins) {
|
|
2003
|
+
return plugins instanceof Object && !Array.isArray(plugins);
|
|
2004
|
+
}
|
|
2005
|
+
function getPlugins(plugins) {
|
|
2006
|
+
if (isObjectPlugins(plugins)) throw new Error("Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
|
|
2007
|
+
if (isJSONPlugins(plugins)) throw new Error("JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
|
|
2008
|
+
return Promise.resolve(plugins);
|
|
2009
|
+
}
|
|
2010
|
+
//#endregion
|
|
2011
|
+
//#region src/utils/getConfigs.ts
|
|
2012
|
+
/**
|
|
2013
|
+
* Converting UserConfig to Config Array without a change in the object beside the JSON convert.
|
|
2014
|
+
*/
|
|
2015
|
+
async function getConfigs(config, args) {
|
|
2016
|
+
let userConfigs = await (typeof config === "function" ? Promise.resolve(config(args)) : Promise.resolve(config));
|
|
2017
|
+
if (!Array.isArray(userConfigs)) userConfigs = [userConfigs];
|
|
2018
|
+
const results = [];
|
|
2019
|
+
for (const item of userConfigs) {
|
|
2020
|
+
const plugins = item.plugins ? await getPlugins(item.plugins) : void 0;
|
|
2021
|
+
results.push({
|
|
2022
|
+
...item,
|
|
2023
|
+
plugins
|
|
2024
|
+
});
|
|
2025
|
+
}
|
|
2026
|
+
return results;
|
|
2027
|
+
}
|
|
2028
|
+
//#endregion
|
|
2029
|
+
//#region src/utils/linters.ts
|
|
2030
|
+
async function isLinterAvailable(linter) {
|
|
2031
|
+
try {
|
|
2032
|
+
await x(linter, ["--version"], { nodeOptions: { stdio: "ignore" } });
|
|
2033
|
+
return true;
|
|
2034
|
+
} catch {
|
|
2035
|
+
return false;
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
async function detectLinter() {
|
|
2039
|
+
for (const linter of [
|
|
2040
|
+
"biome",
|
|
2041
|
+
"oxlint",
|
|
2042
|
+
"eslint"
|
|
2043
|
+
]) if (await isLinterAvailable(linter)) return linter;
|
|
2044
|
+
}
|
|
2045
|
+
//#endregion
|
|
2046
|
+
export { FunctionParams, PackageManager, PluginManager, PromiseManager, build, build as default, defineConfig, defineLogger, definePlugin, detectFormatter, detectLinter, formatters, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, safeBuild, setup };
|
|
439
2047
|
|
|
440
2048
|
//# sourceMappingURL=index.js.map
|