@kubb/core 5.14.6 → 5.15.0
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/{Hookable-CyMsl7Bl.js → Hookable-BYr6s0lB.js} +82 -70
- package/dist/Hookable-BYr6s0lB.js.map +1 -0
- package/dist/{createAdapter-BD4waEKc.d.ts → createAdapter-CCe-Oddm.d.ts} +35 -49
- package/dist/html/ui.iife.js +3 -3
- package/dist/index.cjs +124 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +70 -85
- package/dist/index.d.ts +38 -39
- package/dist/index.js +45 -56
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.ts +1 -3
- package/dist/mocks.js +8 -4
- package/dist/mocks.js.map +1 -1
- package/package.json +2 -2
- package/dist/Hookable-CyMsl7Bl.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -20,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
24
23
|
let verkit = require("verkit");
|
|
25
24
|
let node_async_hooks = require("node:async_hooks");
|
|
26
25
|
let node_process = require("node:process");
|
|
@@ -41,10 +40,9 @@ let node_crypto = require("node:crypto");
|
|
|
41
40
|
let node_readline = require("node:readline");
|
|
42
41
|
let node_url = require("node:url");
|
|
43
42
|
let node_module = require("node:module");
|
|
44
|
-
|
|
45
|
-
var version = "5.
|
|
46
|
-
|
|
47
|
-
//#region ../../internals/utils/src/casing.ts
|
|
43
|
+
// package.json
|
|
44
|
+
var version = "5.15.0";
|
|
45
|
+
// ../../internals/utils/src/casing.ts
|
|
48
46
|
/**
|
|
49
47
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
50
48
|
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
@@ -59,7 +57,7 @@ function convert(text, pascal) {
|
|
|
59
57
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
60
58
|
}
|
|
61
59
|
const cache = /* @__PURE__ */ new Map();
|
|
62
|
-
const cacheLimit =
|
|
60
|
+
const cacheLimit = 1e5;
|
|
63
61
|
function toCamelOrPascal(text, pascal) {
|
|
64
62
|
const key = `${pascal ? "P" : "c"}${text}`;
|
|
65
63
|
const cached = cache.get(key);
|
|
@@ -81,8 +79,19 @@ function toCamelOrPascal(text, pascal) {
|
|
|
81
79
|
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
82
80
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
83
81
|
}
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Converts `text` to PascalCase.
|
|
84
|
+
*
|
|
85
|
+
* @example Word boundaries
|
|
86
|
+
* `pascalCase('hello-world') // 'HelloWorld'`
|
|
87
|
+
*
|
|
88
|
+
* @example With a suffix
|
|
89
|
+
* `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
|
|
90
|
+
*/
|
|
91
|
+
function pascalCase(text, { prefix = "", suffix = "" } = {}) {
|
|
92
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
93
|
+
}
|
|
94
|
+
// ../../internals/utils/src/errors.ts
|
|
86
95
|
/**
|
|
87
96
|
* Coerces an unknown thrown value to an `Error` instance.
|
|
88
97
|
* Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
|
|
@@ -124,8 +133,7 @@ function getErrorChain(error) {
|
|
|
124
133
|
for (let current = error; current instanceof Error && !chain.includes(current); current = current.cause) chain.push(current);
|
|
125
134
|
return chain;
|
|
126
135
|
}
|
|
127
|
-
|
|
128
|
-
//#region ../../internals/utils/src/isCIEnvironment.ts
|
|
136
|
+
// ../../internals/utils/src/isCIEnvironment.ts
|
|
129
137
|
/**
|
|
130
138
|
* Returns `true` when a known CI provider has set its environment variable.
|
|
131
139
|
* `CI=false` and `CI=0` count as not CI, so a user can opt out locally.
|
|
@@ -134,8 +142,7 @@ function isCIEnvironment() {
|
|
|
134
142
|
const ci = node_process.default.env.CI;
|
|
135
143
|
return !!(ci && ci !== "false" && ci !== "0" || node_process.default.env.GITHUB_ACTIONS || node_process.default.env.GITLAB_CI || node_process.default.env.BITBUCKET_BUILD_NUMBER || node_process.default.env.JENKINS_URL || node_process.default.env.CIRCLECI || node_process.default.env.TRAVIS || node_process.default.env.TEAMCITY_VERSION || node_process.default.env.BUILDKITE || node_process.default.env.TF_BUILD);
|
|
136
144
|
}
|
|
137
|
-
|
|
138
|
-
//#region ../../internals/utils/src/openInBrowser.ts
|
|
145
|
+
// ../../internals/utils/src/openInBrowser.ts
|
|
139
146
|
const ignore = () => {};
|
|
140
147
|
/**
|
|
141
148
|
* Opens a URL or local file in the default browser, unless running in CI.
|
|
@@ -153,8 +160,7 @@ function openInBrowser(target) {
|
|
|
153
160
|
}
|
|
154
161
|
(0, tinyexec.x)(node_process.default.platform === "darwin" ? "open" : "xdg-open", [target]).then(ignore, ignore);
|
|
155
162
|
}
|
|
156
|
-
|
|
157
|
-
//#region ../../internals/utils/src/runtime.ts
|
|
163
|
+
// ../../internals/utils/src/runtime.ts
|
|
158
164
|
const isBun = typeof Bun !== "undefined";
|
|
159
165
|
const isDeno = "Deno" in globalThis;
|
|
160
166
|
/**
|
|
@@ -183,8 +189,7 @@ function detect() {
|
|
|
183
189
|
version: process.versions?.node ?? ""
|
|
184
190
|
};
|
|
185
191
|
}
|
|
186
|
-
|
|
187
|
-
//#region ../../internals/utils/src/fs.ts
|
|
192
|
+
// ../../internals/utils/src/fs.ts
|
|
188
193
|
/**
|
|
189
194
|
* Resolves to `true` when the file or directory at `path` exists.
|
|
190
195
|
* Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.
|
|
@@ -350,8 +355,7 @@ function isPathInside(path, parent) {
|
|
|
350
355
|
const rel = (0, node_path.relative)(resolvedParent, resolvedPath);
|
|
351
356
|
return rel !== "" && !rel.startsWith("..") && !(0, node_path.isAbsolute)(rel);
|
|
352
357
|
}
|
|
353
|
-
|
|
354
|
-
//#region ../../internals/utils/src/promise.ts
|
|
358
|
+
// ../../internals/utils/src/promise.ts
|
|
355
359
|
/**
|
|
356
360
|
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
357
361
|
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
@@ -368,8 +372,7 @@ async function inParallel({ items, limit, run }) {
|
|
|
368
372
|
};
|
|
369
373
|
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
370
374
|
}
|
|
371
|
-
|
|
372
|
-
//#region ../../internals/utils/src/tools.ts
|
|
375
|
+
// ../../internals/utils/src/tools.ts
|
|
373
376
|
/**
|
|
374
377
|
* CLI command descriptors for each supported code formatter.
|
|
375
378
|
*/
|
|
@@ -477,8 +480,7 @@ async function detectTool(candidates, cwd) {
|
|
|
477
480
|
function tokenize(command) {
|
|
478
481
|
return (command.match(/[^\s"']+|"([^"]*)"|'([^']*)'/g) ?? []).map((token) => token.replace(/^["']|["']$/g, ""));
|
|
479
482
|
}
|
|
480
|
-
|
|
481
|
-
//#region ../../internals/utils/src/time.ts
|
|
483
|
+
// ../../internals/utils/src/time.ts
|
|
482
484
|
/**
|
|
483
485
|
* Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
|
|
484
486
|
* Rounds to 2 decimal places for sub-millisecond precision without noise.
|
|
@@ -510,8 +512,7 @@ function formatMs(ms) {
|
|
|
510
512
|
if (ms >= 1e3) return `${(ms / 1e3).toFixed(2)}s`;
|
|
511
513
|
return `${Math.round(ms)}ms`;
|
|
512
514
|
}
|
|
513
|
-
|
|
514
|
-
//#region src/diagnosticCatalog.ts
|
|
515
|
+
// src/diagnosticCatalog.ts
|
|
515
516
|
/**
|
|
516
517
|
* Every diagnostic code with its docs entry: a short title, what triggers it, and how to resolve
|
|
517
518
|
* it. The source of truth for {@link diagnosticCode}, and the kubb.dev `/reference/diagnostics`
|
|
@@ -740,8 +741,7 @@ const diagnosticCatalog = {
|
|
|
740
741
|
* these instead of inlining the string at a throw site.
|
|
741
742
|
*/
|
|
742
743
|
const diagnosticCode = Object.fromEntries(Object.entries(diagnosticCatalog).map(([key, { code }]) => [key, code]));
|
|
743
|
-
|
|
744
|
-
//#region src/formatDiagnostic.ts
|
|
744
|
+
// src/formatDiagnostic.ts
|
|
745
745
|
/** A problem's `help`, or the catalog fix. `info` gets none: its catalog fix says no action is needed. */
|
|
746
746
|
function getHelp(problem) {
|
|
747
747
|
if (problem.help || problem.severity === "info") return problem.help;
|
|
@@ -858,8 +858,7 @@ function format(diagnostic, { audience = "agent", verbose = false, width = 0, po
|
|
|
858
858
|
if (code !== diagnosticCode.unknown) details.push(` ${paint("dim", "↳ Learn more")} ${paint("cyan", Diagnostics.docsUrl(code).replace(/^https:\/\//, ""))}`);
|
|
859
859
|
return [...headline, ...details];
|
|
860
860
|
}
|
|
861
|
-
|
|
862
|
-
//#region src/Diagnostics.ts
|
|
861
|
+
// src/Diagnostics.ts
|
|
863
862
|
/**
|
|
864
863
|
* Docs major version, derived from the package version so the link tracks the published major.
|
|
865
864
|
*/
|
|
@@ -1152,8 +1151,7 @@ var Diagnostics = class Diagnostics {
|
|
|
1152
1151
|
*/
|
|
1153
1152
|
static format = format;
|
|
1154
1153
|
};
|
|
1155
|
-
|
|
1156
|
-
//#region src/defineExtension.ts
|
|
1154
|
+
// src/defineExtension.ts
|
|
1157
1155
|
/**
|
|
1158
1156
|
* Returns `meta`, or `{ name }` for an extension that only sets the deprecated `name`. Throws `KUBB_INVALID_PLUGIN_OPTIONS` when it has neither.
|
|
1159
1157
|
*/
|
|
@@ -1287,8 +1285,7 @@ function defineExtension(definition) {
|
|
|
1287
1285
|
}
|
|
1288
1286
|
}
|
|
1289
1287
|
}
|
|
1290
|
-
|
|
1291
|
-
//#region src/createAdapter.ts
|
|
1288
|
+
// src/createAdapter.ts
|
|
1292
1289
|
/**
|
|
1293
1290
|
* Defines a custom adapter that translates a spec format into Kubb's universal
|
|
1294
1291
|
* AST, for example GraphQL, gRPC, or AsyncAPI. The built-in `@kubb/adapter-oas`
|
|
@@ -1305,8 +1302,7 @@ function createAdapter(definition) {
|
|
|
1305
1302
|
...definition
|
|
1306
1303
|
});
|
|
1307
1304
|
}
|
|
1308
|
-
|
|
1309
|
-
//#region src/composables.ts
|
|
1305
|
+
// src/composables.ts
|
|
1310
1306
|
const kubbContextKey = Symbol.for("kubb.context");
|
|
1311
1307
|
const host = globalThis;
|
|
1312
1308
|
/**
|
|
@@ -1373,6 +1369,10 @@ function injectFile(file) {
|
|
|
1373
1369
|
requireContext("injectFile").injectFile(file);
|
|
1374
1370
|
}
|
|
1375
1371
|
/**
|
|
1372
|
+
* Returns a value computed once per build and shared by every plugin, like `ctx.memo`.
|
|
1373
|
+
*/
|
|
1374
|
+
const memo = (key, compute) => requireContext("memo").memo(key, compute);
|
|
1375
|
+
/**
|
|
1376
1376
|
* Returns the options the user passed to the plugin being set up, like `ctx.options`.
|
|
1377
1377
|
*/
|
|
1378
1378
|
function useOptions() {
|
|
@@ -1396,8 +1396,7 @@ function useConfig() {
|
|
|
1396
1396
|
function requirePlugin(name) {
|
|
1397
1397
|
return requireContext("requirePlugin").requirePlugin(name);
|
|
1398
1398
|
}
|
|
1399
|
-
|
|
1400
|
-
//#region src/definePlugin.ts
|
|
1399
|
+
// src/definePlugin.ts
|
|
1401
1400
|
/**
|
|
1402
1401
|
* Merges the `output.mode` default into the output config and validates the combination.
|
|
1403
1402
|
* Throws `KUBB_INVALID_PLUGIN_OPTIONS` when `mode: 'file'` is paired with a `group` option,
|
|
@@ -1447,8 +1446,14 @@ function definePlugin(definition) {
|
|
|
1447
1446
|
...definition
|
|
1448
1447
|
});
|
|
1449
1448
|
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1449
|
+
// src/memo.ts
|
|
1450
|
+
function memoize(store, key, compute) {
|
|
1451
|
+
if (store.has(key)) return store.get(key);
|
|
1452
|
+
const value = compute();
|
|
1453
|
+
store.set(key, value);
|
|
1454
|
+
return value;
|
|
1455
|
+
}
|
|
1456
|
+
// src/publicAddress.ts
|
|
1452
1457
|
function createBlockList() {
|
|
1453
1458
|
const list = new node_net.default.BlockList();
|
|
1454
1459
|
for (const [address, prefix] of [
|
|
@@ -1483,8 +1488,7 @@ function isPublicAddress(address, blocked = privateAddresses) {
|
|
|
1483
1488
|
const family = node_net.default.isIP(address);
|
|
1484
1489
|
return family !== 0 && !blocked.check(address, family === 4 ? "ipv4" : "ipv6");
|
|
1485
1490
|
}
|
|
1486
|
-
|
|
1487
|
-
//#region src/gitInput.ts
|
|
1491
|
+
// src/gitInput.ts
|
|
1488
1492
|
/** Matches a git `input`: the `git+` prefix npm uses for git dependencies. */
|
|
1489
1493
|
const gitInputRegExp = /^git\+/i;
|
|
1490
1494
|
function gitError(message, cause) {
|
|
@@ -1656,8 +1660,7 @@ async function checkoutGitInput(input, signal, { publicOnly = false, authorizati
|
|
|
1656
1660
|
dispose
|
|
1657
1661
|
};
|
|
1658
1662
|
}
|
|
1659
|
-
|
|
1660
|
-
//#region src/input.ts
|
|
1663
|
+
// src/input.ts
|
|
1661
1664
|
/**
|
|
1662
1665
|
* Classifies an `input` value so callers branch on it once instead of repeating the checks.
|
|
1663
1666
|
*
|
|
@@ -1735,8 +1738,7 @@ function inputToAdapterSource(config) {
|
|
|
1735
1738
|
path: (0, node_path.resolve)(config.root, input)
|
|
1736
1739
|
};
|
|
1737
1740
|
}
|
|
1738
|
-
|
|
1739
|
-
//#region src/resolveOptions.ts
|
|
1741
|
+
// src/resolveOptions.ts
|
|
1740
1742
|
const patternCache = /* @__PURE__ */ new Map();
|
|
1741
1743
|
const optionsCache = /* @__PURE__ */ new WeakMap();
|
|
1742
1744
|
function testPattern(value, pattern) {
|
|
@@ -1804,8 +1806,7 @@ function resolveOptions(node, context) {
|
|
|
1804
1806
|
byOptions.set(node, { value: result });
|
|
1805
1807
|
return result;
|
|
1806
1808
|
}
|
|
1807
|
-
|
|
1808
|
-
//#region src/Resolver.ts
|
|
1809
|
+
// src/Resolver.ts
|
|
1809
1810
|
function isNamespace(value) {
|
|
1810
1811
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1811
1812
|
}
|
|
@@ -1879,8 +1880,8 @@ var Resolver = class Resolver {
|
|
|
1879
1880
|
/** The built-in machinery, untouched by `name`/`file` overrides and built once since the driver reads it per node. */
|
|
1880
1881
|
default;
|
|
1881
1882
|
#options;
|
|
1883
|
+
#memo = /* @__PURE__ */ new Map();
|
|
1882
1884
|
#usedNames = /* @__PURE__ */ new Set();
|
|
1883
|
-
#resolvedNames = /* @__PURE__ */ new Map();
|
|
1884
1885
|
#baseName;
|
|
1885
1886
|
#filePath;
|
|
1886
1887
|
constructor(options) {
|
|
@@ -1906,6 +1907,12 @@ var Resolver = class Resolver {
|
|
|
1906
1907
|
return this.default.name(name);
|
|
1907
1908
|
}
|
|
1908
1909
|
/**
|
|
1910
|
+
* Returns what `compute` produced the first time this build asked for `key`. A resolver lives for one build.
|
|
1911
|
+
*/
|
|
1912
|
+
memo(key, compute) {
|
|
1913
|
+
return memoize(this.#memo, key, compute);
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1909
1916
|
* Reserves emitted identifiers before allocating other declarations. The driver reserves component
|
|
1910
1917
|
* names. Reserve extra identifiers, such as enum type aliases, before calling `resolveName`.
|
|
1911
1918
|
*
|
|
@@ -1936,18 +1943,16 @@ var Resolver = class Resolver {
|
|
|
1936
1943
|
* ```
|
|
1937
1944
|
*/
|
|
1938
1945
|
resolveName({ key, name, normalize = (name) => name }) {
|
|
1939
|
-
const cacheKey =
|
|
1940
|
-
const
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
const names =
|
|
1944
|
-
|
|
1946
|
+
const cacheKey = typeof key === "string" ? `s:${key}` : `a:${key.map((segment) => segment === void 0 ? "u" : `${segment.length}:${segment}`).join("")}`;
|
|
1947
|
+
const allocate = (suffix) => {
|
|
1948
|
+
const candidate = suffix === 1 ? name : `${name}${suffix}`;
|
|
1949
|
+
const normalized = normalize(candidate);
|
|
1950
|
+
const names = typeof normalized === "string" ? [normalized] : normalized;
|
|
1951
|
+
if (names.some((emittedName) => this.#usedNames.has(emittedName))) return allocate(suffix + 1);
|
|
1952
|
+
this.reserveNames(names);
|
|
1953
|
+
return candidate;
|
|
1945
1954
|
};
|
|
1946
|
-
|
|
1947
|
-
for (let suffix = 2; emitted(result).some((emittedName) => this.#usedNames.has(emittedName)); suffix++) result = `${name}${suffix}`;
|
|
1948
|
-
this.reserveNames(emitted(result));
|
|
1949
|
-
this.#resolvedNames.set(cacheKey, result);
|
|
1950
|
-
return result;
|
|
1955
|
+
return this.memo(`resolveName:${cacheKey}`, () => allocate(1));
|
|
1951
1956
|
}
|
|
1952
1957
|
file(options) {
|
|
1953
1958
|
return this.#resolveFile(options);
|
|
@@ -2156,8 +2161,7 @@ var Resolver = class Resolver {
|
|
|
2156
2161
|
return Resolver.#resolveUserText(output?.footer, meta, file) ?? null;
|
|
2157
2162
|
}
|
|
2158
2163
|
};
|
|
2159
|
-
|
|
2160
|
-
//#region src/createResolver.ts
|
|
2164
|
+
// src/createResolver.ts
|
|
2161
2165
|
/**
|
|
2162
2166
|
* Defines a plugin resolver, the object that decides what every generated symbol and file
|
|
2163
2167
|
* path is called. Override the top-level `name` and `file` to set the plugin's conventions,
|
|
@@ -2170,7 +2174,7 @@ var Resolver = class Resolver {
|
|
|
2170
2174
|
* export const resolverTs = createResolver<PluginTs>({
|
|
2171
2175
|
* pluginName: 'plugin-ts',
|
|
2172
2176
|
* name(name) {
|
|
2173
|
-
* return ensureValidVarName(pascalCase(name))
|
|
2177
|
+
* return this.memo(`name:${name}`, () => ensureValidVarName(pascalCase(name)))
|
|
2174
2178
|
* },
|
|
2175
2179
|
* })
|
|
2176
2180
|
* ```
|
|
@@ -2205,8 +2209,7 @@ var Resolver = class Resolver {
|
|
|
2205
2209
|
function createResolver(options) {
|
|
2206
2210
|
return new Resolver(options);
|
|
2207
2211
|
}
|
|
2208
|
-
|
|
2209
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/usingCtx.js
|
|
2212
|
+
// \0@oxc-project+runtime@0.155.0/helpers/esm/usingCtx.js
|
|
2210
2213
|
function _usingCtx() {
|
|
2211
2214
|
var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
|
|
2212
2215
|
var n = Error();
|
|
@@ -2321,9 +2324,9 @@ function compareFiles(a, b) {
|
|
|
2321
2324
|
* manifest, as what the output passes make of it. Checking here rather than in a driver gives a
|
|
2322
2325
|
* storage writing to S3 or a database the same guarantee `fsStorage` has. `false` when skipped.
|
|
2323
2326
|
*/
|
|
2324
|
-
async function writeChanged({ storage, manifest, file, source, signal }) {
|
|
2327
|
+
async function writeChanged({ storage, manifest, file, source, signal, cleaned }) {
|
|
2325
2328
|
signal?.throwIfAborted();
|
|
2326
|
-
const stored = await storage.readItem(file.path);
|
|
2329
|
+
const stored = cleaned && isPathInside(file.path, cleaned) ? null : await storage.readItem(file.path);
|
|
2327
2330
|
if (stored !== null && (matchesStored({
|
|
2328
2331
|
stored,
|
|
2329
2332
|
source
|
|
@@ -2503,7 +2506,7 @@ var FileManager = class {
|
|
|
2503
2506
|
* writes nothing and leaves every mtime where it was. `kubb:files:processing:end` lists the
|
|
2504
2507
|
* skipped paths as `unchanged`.
|
|
2505
2508
|
*/
|
|
2506
|
-
async write(files, { storage, parsers, manifest, signal, hooks, config }) {
|
|
2509
|
+
async write(files, { storage, parsers, manifest, signal, hooks, config, cleaned }) {
|
|
2507
2510
|
if (files.length === 0) return;
|
|
2508
2511
|
await hooks?.callHook("kubb:files:processing:start", { files });
|
|
2509
2512
|
const unchanged = [];
|
|
@@ -2519,7 +2522,8 @@ var FileManager = class {
|
|
|
2519
2522
|
manifest,
|
|
2520
2523
|
file,
|
|
2521
2524
|
source,
|
|
2522
|
-
signal
|
|
2525
|
+
signal,
|
|
2526
|
+
cleaned
|
|
2523
2527
|
})) unchanged.push(file.path);
|
|
2524
2528
|
await progress?.(index);
|
|
2525
2529
|
}
|
|
@@ -2530,8 +2534,7 @@ var FileManager = class {
|
|
|
2530
2534
|
});
|
|
2531
2535
|
}
|
|
2532
2536
|
};
|
|
2533
|
-
|
|
2534
|
-
//#region src/nodeCache.ts
|
|
2537
|
+
// src/nodeCache.ts
|
|
2535
2538
|
/**
|
|
2536
2539
|
* Builds an empty {@link NodeCache} backed by a plain `Map`. Called once per node in the generate
|
|
2537
2540
|
* walk.
|
|
@@ -2554,8 +2557,7 @@ function createNodeCache() {
|
|
|
2554
2557
|
}
|
|
2555
2558
|
};
|
|
2556
2559
|
}
|
|
2557
|
-
|
|
2558
|
-
//#region src/KubbDriver.ts
|
|
2560
|
+
// src/KubbDriver.ts
|
|
2559
2561
|
const ENFORCE_ORDER = {
|
|
2560
2562
|
pre: -1,
|
|
2561
2563
|
post: 1
|
|
@@ -2663,6 +2665,7 @@ var KubbDriver = class {
|
|
|
2663
2665
|
*/
|
|
2664
2666
|
fileManager = new FileManager();
|
|
2665
2667
|
plugins = /* @__PURE__ */ new Map();
|
|
2668
|
+
#memo = /* @__PURE__ */ new Map();
|
|
2666
2669
|
/**
|
|
2667
2670
|
* Removers for every listener the driver added (plugin, generator) so `dispose()` can detach
|
|
2668
2671
|
* them in one pass. External `hooks.hook(...)` listeners are not tracked.
|
|
@@ -2824,7 +2827,8 @@ var KubbDriver = class {
|
|
|
2824
2827
|
injectFile: (userFileNode) => {
|
|
2825
2828
|
this.fileManager.add(_kubb_ast.ast.factory.createFile(userFileNode));
|
|
2826
2829
|
},
|
|
2827
|
-
requirePlugin: ((name) => this.requirePlugin(name, { requiredBy: plugin.name }))
|
|
2830
|
+
requirePlugin: ((name) => this.requirePlugin(name, { requiredBy: plugin.name })),
|
|
2831
|
+
memo: this.memo.bind(this)
|
|
2828
2832
|
};
|
|
2829
2833
|
try {
|
|
2830
2834
|
await kubbContext.run(ctx, async () => {
|
|
@@ -2926,6 +2930,7 @@ var KubbDriver = class {
|
|
|
2926
2930
|
parsers: parsersMap,
|
|
2927
2931
|
manifest: this.options.manifest,
|
|
2928
2932
|
signal: this.options.signal,
|
|
2933
|
+
cleaned: this.options.cleanPath,
|
|
2929
2934
|
hooks,
|
|
2930
2935
|
config
|
|
2931
2936
|
});
|
|
@@ -3214,6 +3219,7 @@ var KubbDriver = class {
|
|
|
3214
3219
|
this.fileManager.dispose();
|
|
3215
3220
|
this.inputNode = null;
|
|
3216
3221
|
this.#adapterSource = null;
|
|
3222
|
+
this.#memo.clear();
|
|
3217
3223
|
}
|
|
3218
3224
|
[Symbol.dispose]() {
|
|
3219
3225
|
this.dispose();
|
|
@@ -3221,6 +3227,9 @@ var KubbDriver = class {
|
|
|
3221
3227
|
getResolver(pluginName) {
|
|
3222
3228
|
return this.plugins.get(pluginName)?.resolver ?? createResolver({ pluginName });
|
|
3223
3229
|
}
|
|
3230
|
+
memo(key, compute) {
|
|
3231
|
+
return memoize(this.#memo, key, compute);
|
|
3232
|
+
}
|
|
3224
3233
|
getContext(plugin) {
|
|
3225
3234
|
const driver = this;
|
|
3226
3235
|
const report = (diagnostic) => {
|
|
@@ -3240,6 +3249,7 @@ var KubbDriver = class {
|
|
|
3240
3249
|
getPlugin: driver.getPlugin.bind(driver),
|
|
3241
3250
|
requirePlugin: ((name) => driver.requirePlugin(name, { requiredBy: plugin.name })),
|
|
3242
3251
|
getResolver: driver.getResolver.bind(driver),
|
|
3252
|
+
memo: driver.memo.bind(driver),
|
|
3243
3253
|
driver,
|
|
3244
3254
|
addFile: async (...files) => {
|
|
3245
3255
|
driver.fileManager.add(...files);
|
|
@@ -3319,8 +3329,7 @@ function pluginNotFoundError({ pluginName, requiredBy }) {
|
|
|
3319
3329
|
...requiredBy ? { plugin: requiredBy } : {}
|
|
3320
3330
|
});
|
|
3321
3331
|
}
|
|
3322
|
-
|
|
3323
|
-
//#region src/outputManifest.ts
|
|
3332
|
+
// src/outputManifest.ts
|
|
3324
3333
|
/**
|
|
3325
3334
|
* Bumped when the stored shape changes, so an older cache is discarded instead of misread.
|
|
3326
3335
|
*/
|
|
@@ -3382,8 +3391,7 @@ async function createOutputManifest({ storage, cache }) {
|
|
|
3382
3391
|
}
|
|
3383
3392
|
};
|
|
3384
3393
|
}
|
|
3385
|
-
|
|
3386
|
-
//#region src/createStorage.ts
|
|
3394
|
+
// src/createStorage.ts
|
|
3387
3395
|
/**
|
|
3388
3396
|
* Defines a custom storage backend. The builder receives user options and
|
|
3389
3397
|
* returns a `Storage` implementation. Kubb ships with filesystem and in-memory
|
|
@@ -3420,8 +3428,7 @@ async function createOutputManifest({ storage, cache }) {
|
|
|
3420
3428
|
* ```
|
|
3421
3429
|
*/
|
|
3422
3430
|
const createStorage = (build) => (options) => build(options ?? {});
|
|
3423
|
-
|
|
3424
|
-
//#region src/storages/fsStorage.ts
|
|
3431
|
+
// src/storages/fsStorage.ts
|
|
3425
3432
|
/**
|
|
3426
3433
|
* Built-in filesystem storage driver.
|
|
3427
3434
|
*
|
|
@@ -3435,6 +3442,7 @@ const createStorage = (build) => (options) => build(options ?? {});
|
|
|
3435
3442
|
* a formatter left behind
|
|
3436
3443
|
* - missing parent directories are created automatically
|
|
3437
3444
|
* - `FileManager.write` bounds in-flight writes, so this driver does not pace itself
|
|
3445
|
+
* - `empty` moves the directory aside and deletes it in the background
|
|
3438
3446
|
*
|
|
3439
3447
|
* @example
|
|
3440
3448
|
* ```ts
|
|
@@ -3476,14 +3484,26 @@ const fsStorage = createStorage(() => ({
|
|
|
3476
3484
|
},
|
|
3477
3485
|
async empty(base) {
|
|
3478
3486
|
if (!base) return;
|
|
3479
|
-
|
|
3487
|
+
const dir = (0, node_path.resolve)(base);
|
|
3488
|
+
const parent = (0, node_path.dirname)(dir);
|
|
3489
|
+
const prefix = `.${(0, node_path.basename)(dir)}.kubb-old-`;
|
|
3490
|
+
try {
|
|
3491
|
+
await (0, node_fs_promises.rename)(dir, (0, node_path.join)(parent, `${prefix}${process.pid}-${Date.now()}`));
|
|
3492
|
+
} catch (_error) {
|
|
3493
|
+
await (0, node_fs_promises.rm)(dir, {
|
|
3494
|
+
recursive: true,
|
|
3495
|
+
force: true
|
|
3496
|
+
});
|
|
3497
|
+
return;
|
|
3498
|
+
}
|
|
3499
|
+
const trash = (await (0, node_fs_promises.readdir)(parent)).filter((name) => name.startsWith(prefix));
|
|
3500
|
+
Promise.all(trash.map((name) => (0, node_fs_promises.rm)((0, node_path.join)(parent, name), {
|
|
3480
3501
|
recursive: true,
|
|
3481
3502
|
force: true
|
|
3482
|
-
});
|
|
3503
|
+
}))).catch(() => {});
|
|
3483
3504
|
}
|
|
3484
3505
|
}));
|
|
3485
|
-
|
|
3486
|
-
//#region src/storages/cacheStorage.ts
|
|
3506
|
+
// src/storages/cacheStorage.ts
|
|
3487
3507
|
/**
|
|
3488
3508
|
* Directory Kubb keeps build caches in. A project with a `node_modules` gets
|
|
3489
3509
|
* `node_modules/.cache/kubb`, the convention babel and eslint already use, so the cache stays out
|
|
@@ -3524,8 +3544,7 @@ const cacheStorage = createStorage(({ root = process.cwd() }) => {
|
|
|
3524
3544
|
empty: async (base) => base ? fs.empty(toPath(base)) : void 0
|
|
3525
3545
|
};
|
|
3526
3546
|
});
|
|
3527
|
-
|
|
3528
|
-
//#region src/Hookable.ts
|
|
3547
|
+
// src/Hookable.ts
|
|
3529
3548
|
/**
|
|
3530
3549
|
* Typed hook emitter that awaits all async listeners before resolving.
|
|
3531
3550
|
*
|
|
@@ -3631,8 +3650,7 @@ var Hookable = class {
|
|
|
3631
3650
|
this.#listeners.clear();
|
|
3632
3651
|
}
|
|
3633
3652
|
};
|
|
3634
|
-
|
|
3635
|
-
//#region src/output/runHook.ts
|
|
3653
|
+
// src/output/runHook.ts
|
|
3636
3654
|
const KILL_GRACE_MS = 2e3;
|
|
3637
3655
|
async function settle(proc, hooks, id, commandWithArgs) {
|
|
3638
3656
|
let childError = null;
|
|
@@ -3711,8 +3729,7 @@ async function runHook({ hooks, command, args = [], name, cwd = node_process.def
|
|
|
3711
3729
|
});
|
|
3712
3730
|
return result;
|
|
3713
3731
|
}
|
|
3714
|
-
|
|
3715
|
-
//#region src/output/runOutputPasses.ts
|
|
3732
|
+
// src/output/runOutputPasses.ts
|
|
3716
3733
|
/**
|
|
3717
3734
|
* Format and lint are one pass over the output directory that differs only in these values.
|
|
3718
3735
|
* `label` and `verb` are spelled out: deriving them from `kind` gives "lintter" and "lintting".
|
|
@@ -3824,8 +3841,7 @@ async function runOutputPasses({ config, outputPath, hooks, signal }) {
|
|
|
3824
3841
|
await hooks.callHook("kubb:hooks:end");
|
|
3825
3842
|
return diagnostics;
|
|
3826
3843
|
}
|
|
3827
|
-
|
|
3828
|
-
//#region src/createKubb.ts
|
|
3844
|
+
// src/createKubb.ts
|
|
3829
3845
|
function resolveConfig(userConfig) {
|
|
3830
3846
|
return {
|
|
3831
3847
|
...userConfig,
|
|
@@ -4066,8 +4082,7 @@ var Kubb = class {
|
|
|
4066
4082
|
function createKubb(userConfig, options = {}) {
|
|
4067
4083
|
return new Kubb(userConfig, options);
|
|
4068
4084
|
}
|
|
4069
|
-
|
|
4070
|
-
//#region src/createReporter.ts
|
|
4085
|
+
// src/createReporter.ts
|
|
4071
4086
|
/**
|
|
4072
4087
|
* Numeric log-level thresholds used internally to compare verbosity.
|
|
4073
4088
|
*
|
|
@@ -4122,8 +4137,7 @@ function createReporter(reporter) {
|
|
|
4122
4137
|
}
|
|
4123
4138
|
};
|
|
4124
4139
|
}
|
|
4125
|
-
|
|
4126
|
-
//#region src/reporters/report.ts
|
|
4140
|
+
// src/reporters/report.ts
|
|
4127
4141
|
/**
|
|
4128
4142
|
* Builds the normalized {@link Report} for one config from its {@link GenerationResult}. Splits the
|
|
4129
4143
|
* diagnostics into problems and per-plugin timings (slowest first) and derives the plugin and issue
|
|
@@ -4158,8 +4172,7 @@ function buildReport(result) {
|
|
|
4158
4172
|
diagnostics: problems.map((diagnostic) => Diagnostics.serialize(diagnostic))
|
|
4159
4173
|
};
|
|
4160
4174
|
}
|
|
4161
|
-
|
|
4162
|
-
//#region src/reporters/summary.ts
|
|
4175
|
+
// src/reporters/summary.ts
|
|
4163
4176
|
/**
|
|
4164
4177
|
* Puts the outcome first, followed by file counts, labeled plugin results, and the output path.
|
|
4165
4178
|
* Hosts that collect file changes get a compact diff section. Verbose output adds plugin timings.
|
|
@@ -4206,8 +4219,7 @@ function formatSummary(report, { showTimings }) {
|
|
|
4206
4219
|
}
|
|
4207
4220
|
return lines;
|
|
4208
4221
|
}
|
|
4209
|
-
|
|
4210
|
-
//#region src/reporters/cliReporter.ts
|
|
4222
|
+
// src/reporters/cliReporter.ts
|
|
4211
4223
|
/**
|
|
4212
4224
|
* Renders the summary as plain `console.log` lines so it works in every CLI (no clack/TTY
|
|
4213
4225
|
* dependency): a blank line, the config name colored by status, then the summary rows.
|
|
@@ -4247,8 +4259,7 @@ function createCliReporter({ render = consoleRenderer } = {}) {
|
|
|
4247
4259
|
* logger view.
|
|
4248
4260
|
*/
|
|
4249
4261
|
const cliReporter = createCliReporter();
|
|
4250
|
-
|
|
4251
|
-
//#region src/storages/kubbStorage.ts
|
|
4262
|
+
// src/storages/kubbStorage.ts
|
|
4252
4263
|
function ensurePrivateDir(dir) {
|
|
4253
4264
|
(0, node_fs.mkdirSync)(dir, {
|
|
4254
4265
|
recursive: true,
|
|
@@ -4309,8 +4320,7 @@ function kubbStorage({ base } = {}) {
|
|
|
4309
4320
|
}
|
|
4310
4321
|
};
|
|
4311
4322
|
}
|
|
4312
|
-
|
|
4313
|
-
//#region src/reporters/fileReporter.ts
|
|
4323
|
+
// src/reporters/fileReporter.ts
|
|
4314
4324
|
/**
|
|
4315
4325
|
* Builds the `## Problems` section: each problem rendered in the miette block format, blocks
|
|
4316
4326
|
* separated by a blank line. Returns an empty array when there are no problems, so the caller
|
|
@@ -4358,8 +4368,7 @@ const fileReporter = createReporter({
|
|
|
4358
4368
|
console.error(`Debug log written to ${(0, node_path.relative)(node_process.default.cwd(), (0, node_path.join)(dir, baseName))}`);
|
|
4359
4369
|
}
|
|
4360
4370
|
});
|
|
4361
|
-
|
|
4362
|
-
//#region src/reporters/jsonReporter.ts
|
|
4371
|
+
// src/reporters/jsonReporter.ts
|
|
4363
4372
|
/**
|
|
4364
4373
|
* The `json` reporter. `report` returns one config's {@link Report}, which {@link createReporter}
|
|
4365
4374
|
* buffers, and `drain` writes them as a single pretty-printed JSON array on `kubb:lifecycle:end`.
|
|
@@ -4376,8 +4385,7 @@ const jsonReporter = createReporter({
|
|
|
4376
4385
|
node_process.default.stdout.write(`${JSON.stringify(reports, null, 2)}\n`);
|
|
4377
4386
|
}
|
|
4378
4387
|
});
|
|
4379
|
-
|
|
4380
|
-
//#region src/reporters/htmlReporter.ts
|
|
4388
|
+
// src/reporters/htmlReporter.ts
|
|
4381
4389
|
function serializeReport(result) {
|
|
4382
4390
|
return `globalThis.__KUBB_REPORT__ = ${JSON.stringify({
|
|
4383
4391
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -4411,8 +4419,7 @@ const htmlReporter = createReporter({
|
|
|
4411
4419
|
openInBrowser(reportPath);
|
|
4412
4420
|
}
|
|
4413
4421
|
});
|
|
4414
|
-
|
|
4415
|
-
//#region src/createRenderer.ts
|
|
4422
|
+
// src/createRenderer.ts
|
|
4416
4423
|
/**
|
|
4417
4424
|
* Defines a renderer factory. Renderers turn the generator's return value
|
|
4418
4425
|
* (JSX, a template string, a tree of any shape) into `FileNode`s that get
|
|
@@ -4445,8 +4452,7 @@ const htmlReporter = createReporter({
|
|
|
4445
4452
|
function createRenderer(factory) {
|
|
4446
4453
|
return factory;
|
|
4447
4454
|
}
|
|
4448
|
-
|
|
4449
|
-
//#region src/defineGenerator.ts
|
|
4455
|
+
// src/defineGenerator.ts
|
|
4450
4456
|
/**
|
|
4451
4457
|
* Defines a generator: a unit of work that runs during the plugin's AST walk
|
|
4452
4458
|
* and produces files. Plugins register generators via `ctx.addGenerator()`
|
|
@@ -4478,8 +4484,7 @@ function createRenderer(factory) {
|
|
|
4478
4484
|
function defineGenerator(generator) {
|
|
4479
4485
|
return generator;
|
|
4480
4486
|
}
|
|
4481
|
-
|
|
4482
|
-
//#region src/defineParser.ts
|
|
4487
|
+
// src/defineParser.ts
|
|
4483
4488
|
/**
|
|
4484
4489
|
* Defines a parser from one object and returns a factory that takes the user's options.
|
|
4485
4490
|
* Register the result in the `parsers` array on `defineConfig`.
|
|
@@ -4492,8 +4497,7 @@ function defineParser(definition) {
|
|
|
4492
4497
|
...definition
|
|
4493
4498
|
});
|
|
4494
4499
|
}
|
|
4495
|
-
|
|
4496
|
-
//#region src/storages/memoryStorage.ts
|
|
4500
|
+
// src/storages/memoryStorage.ts
|
|
4497
4501
|
/**
|
|
4498
4502
|
* In-memory storage driver. Useful for testing and dry-run scenarios where
|
|
4499
4503
|
* generated output should be captured without touching the filesystem.
|
|
@@ -4539,8 +4543,7 @@ const memoryStorage = createStorage(() => {
|
|
|
4539
4543
|
}
|
|
4540
4544
|
};
|
|
4541
4545
|
});
|
|
4542
|
-
|
|
4543
|
-
//#region src/manifest.ts
|
|
4546
|
+
// src/manifest.ts
|
|
4544
4547
|
const EXTENSION_KINDS = /* @__PURE__ */ new Set([
|
|
4545
4548
|
"plugin",
|
|
4546
4549
|
"adapter",
|
|
@@ -4627,8 +4630,7 @@ function isRegistryEntry(value) {
|
|
|
4627
4630
|
const { id, kind, type, artifact, manifest } = value;
|
|
4628
4631
|
return typeof id === "string" && REGISTRY_ID.test(id) && EXTENSION_KINDS.has(kind) && (type === "official" || type === "community") && isRegistryArtifact(artifact) && isExtensionManifest(manifest) && manifest.kind === kind;
|
|
4629
4632
|
}
|
|
4630
|
-
|
|
4631
|
-
//#region src/installedPackages.ts
|
|
4633
|
+
// src/installedPackages.ts
|
|
4632
4634
|
/** Reads and parses a JSON file. Throws when it is missing or not JSON. */
|
|
4633
4635
|
const readJSON = async (file) => JSON.parse(await (0, node_fs_promises.readFile)(file, "utf8"));
|
|
4634
4636
|
/**
|
|
@@ -4664,7 +4666,6 @@ async function readInstalledPackages({ root, packages = [], resolveFrom = [] })
|
|
|
4664
4666
|
}
|
|
4665
4667
|
}));
|
|
4666
4668
|
}
|
|
4667
|
-
//#endregion
|
|
4668
4669
|
exports.Diagnostics = Diagnostics;
|
|
4669
4670
|
exports.Hookable = Hookable;
|
|
4670
4671
|
exports.KubbDriver = KubbDriver;
|
|
@@ -4673,6 +4674,7 @@ exports.addGenerator = addGenerator;
|
|
|
4673
4674
|
exports.addMacro = addMacro;
|
|
4674
4675
|
exports.assertPluginOption = assertPluginOption;
|
|
4675
4676
|
exports.cacheStorage = cacheStorage;
|
|
4677
|
+
exports.camelCase = camelCase;
|
|
4676
4678
|
exports.checkCompatibility = checkCompatibility;
|
|
4677
4679
|
exports.checkoutGitInput = checkoutGitInput;
|
|
4678
4680
|
exports.cliReporter = cliReporter;
|
|
@@ -4702,7 +4704,9 @@ exports.kubbContext = kubbContext;
|
|
|
4702
4704
|
exports.kubbStorage = kubbStorage;
|
|
4703
4705
|
exports.logLevel = logLevel;
|
|
4704
4706
|
exports.manifestProblems = manifestProblems;
|
|
4707
|
+
exports.memo = memo;
|
|
4705
4708
|
exports.memoryStorage = memoryStorage;
|
|
4709
|
+
exports.pascalCase = pascalCase;
|
|
4706
4710
|
exports.readInstalledPackages = readInstalledPackages;
|
|
4707
4711
|
exports.requirePlugin = requirePlugin;
|
|
4708
4712
|
exports.resolveCacheDir = resolveCacheDir;
|