@kubb/core 5.0.0-beta.7 → 5.0.0-beta.8
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/{PluginDriver-Cadu4ORh.cjs → PluginDriver-Cu1Kj9S-.cjs} +90 -52
- package/dist/PluginDriver-Cu1Kj9S-.cjs.map +1 -0
- package/dist/{PluginDriver-BkTRD2H2.js → PluginDriver-D8Z0Htid.js} +85 -53
- package/dist/PluginDriver-D8Z0Htid.js.map +1 -0
- package/dist/{types-ChyWgIgi.d.ts → createKubb-Cagd4PIe.d.ts} +1428 -1505
- package/dist/index.cjs +56 -103
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -162
- package/dist/index.js +55 -102
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.js +1 -1
- package/dist/mocks.js.map +1 -1
- package/package.json +4 -4
- package/src/PluginDriver.ts +38 -7
- package/src/createAdapter.ts +77 -1
- package/src/createKubb.ts +750 -55
- package/src/defineGenerator.ts +92 -4
- package/src/defineLogger.ts +23 -1
- package/src/defineMiddleware.ts +1 -1
- package/src/definePlugin.ts +304 -8
- package/src/defineResolver.ts +182 -49
- package/src/devtools.ts +8 -1
- package/src/index.ts +1 -1
- package/src/mocks.ts +1 -2
- package/src/storages/fsStorage.ts +6 -30
- package/src/types.ts +37 -1301
- package/dist/PluginDriver-BkTRD2H2.js.map +0 -1
- package/dist/PluginDriver-Cadu4ORh.cjs.map +0 -1
- package/src/Kubb.ts +0 -300
- package/src/renderNode.ts +0 -35
- package/src/utils/diagnostics.ts +0 -18
- package/src/utils/isInputPath.ts +0 -10
- package/src/utils/packageJSON.ts +0 -99
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as ResolverPathParams, A as isInputPath, B as KubbPluginSetupContext, C as KubbPluginsEndContext, D as PossibleConfig, E as KubbWarnContext, F as FileManager, G as Plugin, H as NormalizedPlugin, I as Exclude, J as ResolveBannerContext, K as PluginFactoryOptions, L as Group, M as GeneratorContext, N as defineGenerator, O as UserConfig, P as PluginDriver, Q as ResolverFileParams, R as Include, S as KubbLifecycleStartContext, T as KubbVersionNewContext, U as Output, V as KubbPluginStartContext, W as Override, X as Resolver, Y as ResolveOptionsContext, Z as ResolverContext, _ as KubbGenerationSummaryContext, _t as AdapterFactoryOptions, a as InputPath, at as Logger, b as KubbHooks, bt as logLevel, c as KubbBuildStartContext, ct as UserLogger, d as KubbErrorContext, dt as Storage, et as defineResolver, f as KubbFileProcessingUpdateContext, ft as createStorage, g as KubbGenerationStartContext, gt as Adapter, h as KubbGenerationEndContext, ht as createRenderer, i as InputData, it as defineMiddleware, j as Generator, k as createKubb, l as KubbConfigEndContext, lt as defineLogger, m as KubbFilesProcessingStartContext, mt as RendererFactory, n as CLIOptions, nt as defineParser, o as Kubb, ot as LoggerContext, p as KubbFilesProcessingEndContext, pt as Renderer, q as definePlugin, r as Config, rt as Middleware, s as KubbBuildEndContext, st as LoggerOptions, t as BuildOutput, tt as Parser, u as KubbDebugContext, ut as DevtoolsOptions, v as KubbHookEndContext, vt as AdapterSource, w as KubbSuccessContext, x as KubbInfoContext, xt as AsyncEventEmitter, y as KubbHookStartContext, yt as createAdapter, z as KubbPluginEndContext } from "./createKubb-Cagd4PIe.js";
|
|
3
3
|
import * as ast from "@kubb/ast";
|
|
4
|
-
import { FileNode
|
|
4
|
+
import { FileNode } from "@kubb/ast";
|
|
5
5
|
|
|
6
6
|
//#region ../../internals/utils/src/urlPath.d.ts
|
|
7
7
|
type URLObject = {
|
|
@@ -139,154 +139,6 @@ declare class URLPath {
|
|
|
139
139
|
toURLPath(): string;
|
|
140
140
|
}
|
|
141
141
|
//#endregion
|
|
142
|
-
//#region src/createAdapter.d.ts
|
|
143
|
-
type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>;
|
|
144
|
-
/**
|
|
145
|
-
* Factory for implementing custom adapters that translate non-OpenAPI specs into Kubb's AST.
|
|
146
|
-
*
|
|
147
|
-
* Use this to support GraphQL schemas, gRPC definitions, AsyncAPI, or custom domain-specific languages.
|
|
148
|
-
* Built-in adapters include `@kubb/adapter-oas` for OpenAPI and Swagger documents.
|
|
149
|
-
*
|
|
150
|
-
* @note Adapters must parse their input format to Kubb's `InputNode` structure.
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```ts
|
|
154
|
-
* export const myAdapter = createAdapter<MyAdapter>((options) => {
|
|
155
|
-
* return {
|
|
156
|
-
* name: 'my-adapter',
|
|
157
|
-
* options,
|
|
158
|
-
* async parse(source) {
|
|
159
|
-
* // Transform source format to InputNode
|
|
160
|
-
* return { ... }
|
|
161
|
-
* },
|
|
162
|
-
* }
|
|
163
|
-
* })
|
|
164
|
-
*
|
|
165
|
-
* // Instantiate:
|
|
166
|
-
* const adapter = myAdapter({ validate: true })
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
declare function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T>;
|
|
170
|
-
//#endregion
|
|
171
|
-
//#region src/defineLogger.d.ts
|
|
172
|
-
/**
|
|
173
|
-
* Wraps a logger definition into a typed {@link Logger}.
|
|
174
|
-
*
|
|
175
|
-
* The optional second type parameter `TInstallReturn` allows loggers to return
|
|
176
|
-
* a value from `install` — for example, a sink factory that the caller can
|
|
177
|
-
* forward to hook execution.
|
|
178
|
-
*
|
|
179
|
-
* @example Basic logger
|
|
180
|
-
* ```ts
|
|
181
|
-
* export const myLogger = defineLogger({
|
|
182
|
-
* name: 'my-logger',
|
|
183
|
-
* install(context, options) {
|
|
184
|
-
* context.on('kubb:info', (message) => console.log('ℹ', message))
|
|
185
|
-
* context.on('kubb:error', (error) => console.error('✗', error.message))
|
|
186
|
-
* },
|
|
187
|
-
* })
|
|
188
|
-
* ```
|
|
189
|
-
*
|
|
190
|
-
* @example Logger that returns a hook sink factory
|
|
191
|
-
* ```ts
|
|
192
|
-
* export const myLogger = defineLogger<LoggerOptions, HookSinkFactory>({
|
|
193
|
-
* name: 'my-logger',
|
|
194
|
-
* install(context, options) {
|
|
195
|
-
* // … register event handlers …
|
|
196
|
-
* return (commandWithArgs) => ({ onStdout: console.log })
|
|
197
|
-
* },
|
|
198
|
-
* })
|
|
199
|
-
* ```
|
|
200
|
-
*/
|
|
201
|
-
declare function defineLogger<Options extends LoggerOptions = LoggerOptions, TInstallReturn = void>(logger: UserLogger<Options, TInstallReturn>): Logger<Options, TInstallReturn>;
|
|
202
|
-
//#endregion
|
|
203
|
-
//#region src/defineResolver.d.ts
|
|
204
|
-
/**
|
|
205
|
-
* Builder type for the plugin-specific resolver fields.
|
|
206
|
-
*
|
|
207
|
-
* `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
|
|
208
|
-
* are optional — built-in fallbacks are injected when omitted.
|
|
209
|
-
*
|
|
210
|
-
* The builder receives `ctx` — a reference to the fully assembled resolver — so methods can
|
|
211
|
-
* call sibling resolver methods without using `this`. Because `ctx` is captured by the closure
|
|
212
|
-
* and the resolver is populated after the builder runs, `ctx` correctly reflects any overrides
|
|
213
|
-
* that were applied by the builder itself.
|
|
214
|
-
*/
|
|
215
|
-
type ResolverBuilder<T extends PluginFactoryOptions> = (ctx: T['resolver']) => Omit<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'> & Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {
|
|
216
|
-
name: string;
|
|
217
|
-
pluginName: T['name'];
|
|
218
|
-
};
|
|
219
|
-
/**
|
|
220
|
-
* Default option resolver — applies include/exclude filters and merges matching override options.
|
|
221
|
-
*
|
|
222
|
-
* Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.
|
|
223
|
-
*
|
|
224
|
-
* @example Include/exclude filtering
|
|
225
|
-
* ```ts
|
|
226
|
-
* const options = defaultResolveOptions(operationNode, {
|
|
227
|
-
* options: { output: 'types' },
|
|
228
|
-
* exclude: [{ type: 'tag', pattern: 'internal' }],
|
|
229
|
-
* })
|
|
230
|
-
* // → null when node has tag 'internal'
|
|
231
|
-
* ```
|
|
232
|
-
*
|
|
233
|
-
* @example Override merging
|
|
234
|
-
* ```ts
|
|
235
|
-
* const options = defaultResolveOptions(operationNode, {
|
|
236
|
-
* options: { enumType: 'asConst' },
|
|
237
|
-
* override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],
|
|
238
|
-
* })
|
|
239
|
-
* // → { enumType: 'enum' } when operationId matches
|
|
240
|
-
* ```
|
|
241
|
-
*/
|
|
242
|
-
/**
|
|
243
|
-
* Defines a resolver for a plugin, injecting built-in defaults for name casing,
|
|
244
|
-
* include/exclude/override filtering, path resolution, and file construction.
|
|
245
|
-
*
|
|
246
|
-
* All four defaults can be overridden by providing them in the builder function:
|
|
247
|
-
* - `default` — name casing strategy (camelCase / PascalCase)
|
|
248
|
-
* - `resolveOptions` — include/exclude/override filtering
|
|
249
|
-
* - `resolvePath` — output path computation
|
|
250
|
-
* - `resolveFile` — full `FileNode` construction
|
|
251
|
-
*
|
|
252
|
-
* The builder receives `ctx` — a reference to the assembled resolver — so methods can
|
|
253
|
-
* call sibling resolver methods using `ctx` instead of `this`.
|
|
254
|
-
*
|
|
255
|
-
* @example Basic resolver with naming helpers
|
|
256
|
-
* ```ts
|
|
257
|
-
* export const resolver = defineResolver<PluginTs>((ctx) => ({
|
|
258
|
-
* name: 'default',
|
|
259
|
-
* resolveName(node) {
|
|
260
|
-
* return ctx.default(node.name, 'function')
|
|
261
|
-
* },
|
|
262
|
-
* resolveTypedName(node) {
|
|
263
|
-
* return ctx.default(node.name, 'type')
|
|
264
|
-
* },
|
|
265
|
-
* }))
|
|
266
|
-
* ```
|
|
267
|
-
*
|
|
268
|
-
* @example Override resolvePath for a custom output structure
|
|
269
|
-
* ```ts
|
|
270
|
-
* export const resolver = defineResolver<PluginTs>((_ctx) => ({
|
|
271
|
-
* name: 'custom',
|
|
272
|
-
* resolvePath({ baseName }, { root, output }) {
|
|
273
|
-
* return path.resolve(root, output.path, 'generated', baseName)
|
|
274
|
-
* },
|
|
275
|
-
* }))
|
|
276
|
-
* ```
|
|
277
|
-
*
|
|
278
|
-
* @example Use ctx.default inside a helper
|
|
279
|
-
* ```ts
|
|
280
|
-
* export const resolver = defineResolver<PluginTs>((ctx) => ({
|
|
281
|
-
* name: 'default',
|
|
282
|
-
* resolveParamName(node, param) {
|
|
283
|
-
* return ctx.default(`${node.operationId} ${param.in} ${param.name}`, 'type')
|
|
284
|
-
* },
|
|
285
|
-
* }))
|
|
286
|
-
* ```
|
|
287
|
-
*/
|
|
288
|
-
declare function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'];
|
|
289
|
-
//#endregion
|
|
290
142
|
//#region src/FileProcessor.d.ts
|
|
291
143
|
type ParseOptions = {
|
|
292
144
|
parsers?: Map<FileNode['extname'], Parser>;
|
|
@@ -379,16 +231,5 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Storag
|
|
|
379
231
|
*/
|
|
380
232
|
declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
|
|
381
233
|
//#endregion
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Type guard to check if a given config has an `input.path`.
|
|
385
|
-
*/
|
|
386
|
-
declare function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath> & {
|
|
387
|
-
input: InputPath;
|
|
388
|
-
};
|
|
389
|
-
declare function isInputPath(config: Config | undefined): config is Config<InputPath> & {
|
|
390
|
-
input: InputPath;
|
|
391
|
-
};
|
|
392
|
-
//#endregion
|
|
393
|
-
export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BuildOutput, CLIOptions, Config, DevtoolsOptions, Exclude, FileManager, FileProcessor, Generator, GeneratorContext, Group, Include, InputData, InputPath, Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbConfigEndContext, KubbDebugContext, KubbErrorContext, KubbFileProcessingUpdateContext, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbGenerationSummaryContext, KubbHookEndContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbVersionNewContext, KubbWarnContext, Logger, LoggerContext, LoggerOptions, Middleware, NormalizedPlugin, Output, Override, Parser, Plugin, PluginDriver, PluginFactoryOptions, PossibleConfig, Renderer, RendererFactory, ResolveBannerContext, ResolveNameParams, ResolveOptionsContext, Resolver, ResolverContext, ResolverFileParams, ResolverPathParams, Storage, URLPath, UserConfig, UserLogger, ast, createAdapter, createKubb, createRenderer, createStorage, defineGenerator, defineLogger, defineMiddleware, defineParser, definePlugin, defineResolver, fsStorage, isInputPath, logLevel, memoryStorage };
|
|
234
|
+
export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BuildOutput, CLIOptions, Config, DevtoolsOptions, Exclude, FileManager, FileProcessor, Generator, GeneratorContext, Group, Include, InputData, InputPath, Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbConfigEndContext, KubbDebugContext, KubbErrorContext, KubbFileProcessingUpdateContext, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbGenerationSummaryContext, KubbHookEndContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbVersionNewContext, KubbWarnContext, Logger, LoggerContext, LoggerOptions, Middleware, NormalizedPlugin, Output, Override, Parser, Plugin, PluginDriver, PluginFactoryOptions, PossibleConfig, Renderer, RendererFactory, ResolveBannerContext, ResolveOptionsContext, Resolver, ResolverContext, ResolverFileParams, ResolverPathParams, Storage, URLPath, UserConfig, UserLogger, ast, createAdapter, createKubb, createRenderer, createStorage, defineGenerator, defineLogger, defineMiddleware, defineParser, definePlugin, defineResolver, fsStorage, isInputPath, logLevel, memoryStorage };
|
|
394
235
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as definePlugin, c as DEFAULT_STUDIO_URL, i as defineResolver, l as logLevel, n as applyHookResult, o as DEFAULT_BANNER, r as FileManager, s as DEFAULT_EXTENSION, t as PluginDriver, u as camelCase } from "./PluginDriver-D8Z0Htid.js";
|
|
3
3
|
import { EventEmitter } from "node:events";
|
|
4
4
|
import { access, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -524,6 +524,9 @@ function createAdapter(build) {
|
|
|
524
524
|
return (options) => build(options ?? {});
|
|
525
525
|
}
|
|
526
526
|
//#endregion
|
|
527
|
+
//#region package.json
|
|
528
|
+
var version$1 = "5.0.0-beta.8";
|
|
529
|
+
//#endregion
|
|
527
530
|
//#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
|
|
528
531
|
var Node$1 = class {
|
|
529
532
|
static {
|
|
@@ -738,12 +741,6 @@ function createStorage(build) {
|
|
|
738
741
|
//#endregion
|
|
739
742
|
//#region src/storages/fsStorage.ts
|
|
740
743
|
/**
|
|
741
|
-
* Detects the filesystem error used to indicate that a path does not exist.
|
|
742
|
-
*/
|
|
743
|
-
function isMissingPathError(error) {
|
|
744
|
-
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
745
|
-
}
|
|
746
|
-
/**
|
|
747
744
|
* Built-in filesystem storage driver.
|
|
748
745
|
*
|
|
749
746
|
* This is the default storage when no `storage` option is configured in the root config.
|
|
@@ -774,17 +771,15 @@ const fsStorage = createStorage(() => ({
|
|
|
774
771
|
try {
|
|
775
772
|
await access(resolve(key));
|
|
776
773
|
return true;
|
|
777
|
-
} catch (
|
|
778
|
-
|
|
779
|
-
throw new Error(`Failed to access storage item "${key}"`, { cause: error });
|
|
774
|
+
} catch (_error) {
|
|
775
|
+
return false;
|
|
780
776
|
}
|
|
781
777
|
},
|
|
782
778
|
async getItem(key) {
|
|
783
779
|
try {
|
|
784
780
|
return await readFile(resolve(key), "utf8");
|
|
785
|
-
} catch (
|
|
786
|
-
|
|
787
|
-
throw new Error(`Failed to read storage item "${key}"`, { cause: error });
|
|
781
|
+
} catch (_error) {
|
|
782
|
+
return null;
|
|
788
783
|
}
|
|
789
784
|
},
|
|
790
785
|
async setItem(key, value) {
|
|
@@ -800,9 +795,8 @@ const fsStorage = createStorage(() => ({
|
|
|
800
795
|
let entries;
|
|
801
796
|
try {
|
|
802
797
|
entries = await readdir(dir, { withFileTypes: true });
|
|
803
|
-
} catch (
|
|
804
|
-
|
|
805
|
-
throw new Error(`Failed to list storage keys under "${resolvedBase}"`, { cause: error });
|
|
798
|
+
} catch (_error) {
|
|
799
|
+
return;
|
|
806
800
|
}
|
|
807
801
|
for (const entry of entries) {
|
|
808
802
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
@@ -819,37 +813,31 @@ const fsStorage = createStorage(() => ({
|
|
|
819
813
|
}
|
|
820
814
|
}));
|
|
821
815
|
//#endregion
|
|
822
|
-
//#region package.json
|
|
823
|
-
var version$1 = "5.0.0-beta.7";
|
|
824
|
-
//#endregion
|
|
825
|
-
//#region src/utils/diagnostics.ts
|
|
826
|
-
/**
|
|
827
|
-
* Returns a snapshot of the current runtime environment.
|
|
828
|
-
*
|
|
829
|
-
* Useful for attaching context to debug logs and error reports so that
|
|
830
|
-
* issues can be reproduced without manual information gathering.
|
|
831
|
-
*/
|
|
832
|
-
function getDiagnosticInfo() {
|
|
833
|
-
return {
|
|
834
|
-
nodeVersion: version,
|
|
835
|
-
KubbVersion: version$1,
|
|
836
|
-
platform: process.platform,
|
|
837
|
-
arch: process.arch,
|
|
838
|
-
cwd: process.cwd()
|
|
839
|
-
};
|
|
840
|
-
}
|
|
841
|
-
//#endregion
|
|
842
|
-
//#region src/utils/isInputPath.ts
|
|
843
|
-
function isInputPath(config) {
|
|
844
|
-
return typeof config?.input === "object" && config.input !== null && "path" in config.input;
|
|
845
|
-
}
|
|
846
|
-
//#endregion
|
|
847
816
|
//#region src/createKubb.ts
|
|
848
817
|
async function setup(userConfig, options = {}) {
|
|
849
818
|
const hooks = options.hooks ?? new AsyncEventEmitter();
|
|
819
|
+
const config = {
|
|
820
|
+
...userConfig,
|
|
821
|
+
root: userConfig.root || process.cwd(),
|
|
822
|
+
parsers: userConfig.parsers ?? [],
|
|
823
|
+
adapter: userConfig.adapter,
|
|
824
|
+
output: {
|
|
825
|
+
format: false,
|
|
826
|
+
lint: false,
|
|
827
|
+
extension: DEFAULT_EXTENSION,
|
|
828
|
+
defaultBanner: DEFAULT_BANNER,
|
|
829
|
+
...userConfig.output
|
|
830
|
+
},
|
|
831
|
+
storage: userConfig.storage ?? fsStorage(),
|
|
832
|
+
devtools: userConfig.devtools ? {
|
|
833
|
+
studioUrl: DEFAULT_STUDIO_URL,
|
|
834
|
+
...typeof userConfig.devtools === "boolean" ? {} : userConfig.devtools
|
|
835
|
+
} : void 0,
|
|
836
|
+
plugins: userConfig.plugins ?? []
|
|
837
|
+
};
|
|
838
|
+
const driver = new PluginDriver(config, { hooks });
|
|
850
839
|
const sources = /* @__PURE__ */ new Map();
|
|
851
840
|
const diagnosticInfo = getDiagnosticInfo();
|
|
852
|
-
if (Array.isArray(userConfig.input)) await hooks.emit("kubb:warn", { message: "This feature is still under development — use with caution" });
|
|
853
841
|
await hooks.emit("kubb:debug", {
|
|
854
842
|
date: /* @__PURE__ */ new Date(),
|
|
855
843
|
logs: [
|
|
@@ -859,7 +847,7 @@ async function setup(userConfig, options = {}) {
|
|
|
859
847
|
` • Output: ${userConfig.output?.path || "not specified"}`,
|
|
860
848
|
` • Plugins: ${userConfig.plugins?.length || 0}`,
|
|
861
849
|
"Output Settings:",
|
|
862
|
-
` • Storage: ${
|
|
850
|
+
` • Storage: ${config.storage.name}`,
|
|
863
851
|
` • Formatter: ${userConfig.output?.format || "none"}`,
|
|
864
852
|
` • Linter: ${userConfig.output?.lint || "none"}`,
|
|
865
853
|
"Environment:",
|
|
@@ -880,34 +868,13 @@ async function setup(userConfig, options = {}) {
|
|
|
880
868
|
throw new Error(`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`, { cause: error });
|
|
881
869
|
}
|
|
882
870
|
}
|
|
883
|
-
const config = {
|
|
884
|
-
...userConfig,
|
|
885
|
-
root: userConfig.root || process.cwd(),
|
|
886
|
-
parsers: userConfig.parsers ?? [],
|
|
887
|
-
adapter: userConfig.adapter,
|
|
888
|
-
output: {
|
|
889
|
-
format: false,
|
|
890
|
-
lint: false,
|
|
891
|
-
write: true,
|
|
892
|
-
extension: DEFAULT_EXTENSION,
|
|
893
|
-
defaultBanner: DEFAULT_BANNER,
|
|
894
|
-
...userConfig.output
|
|
895
|
-
},
|
|
896
|
-
devtools: userConfig.devtools ? {
|
|
897
|
-
studioUrl: DEFAULT_STUDIO_URL,
|
|
898
|
-
...typeof userConfig.devtools === "boolean" ? {} : userConfig.devtools
|
|
899
|
-
} : void 0,
|
|
900
|
-
plugins: userConfig.plugins ?? []
|
|
901
|
-
};
|
|
902
|
-
const storage = config.output.write === false ? null : config.storage ?? fsStorage();
|
|
903
871
|
if (config.output.clean) {
|
|
904
872
|
await hooks.emit("kubb:debug", {
|
|
905
873
|
date: /* @__PURE__ */ new Date(),
|
|
906
874
|
logs: ["Cleaning output directories", ` • Output: ${config.output.path}`]
|
|
907
875
|
});
|
|
908
|
-
await storage
|
|
876
|
+
await config.storage.clear(resolve(config.root, config.output.path));
|
|
909
877
|
}
|
|
910
|
-
const driver = new PluginDriver(config, { hooks });
|
|
911
878
|
function registerMiddlewareHook(event, middlewareHooks) {
|
|
912
879
|
const handler = middlewareHooks[event];
|
|
913
880
|
if (handler) hooks.on(event, handler);
|
|
@@ -934,8 +901,7 @@ async function setup(userConfig, options = {}) {
|
|
|
934
901
|
config,
|
|
935
902
|
hooks,
|
|
936
903
|
driver,
|
|
937
|
-
sources
|
|
938
|
-
storage
|
|
904
|
+
sources
|
|
939
905
|
};
|
|
940
906
|
}
|
|
941
907
|
/**
|
|
@@ -951,7 +917,7 @@ async function setup(userConfig, options = {}) {
|
|
|
951
917
|
async function runPluginAstHooks(plugin, context) {
|
|
952
918
|
const { adapter, inputNode, resolver, driver } = context;
|
|
953
919
|
const { exclude, include, override } = plugin.options;
|
|
954
|
-
if (!adapter || !inputNode) throw new Error(`[${plugin.name}] No adapter found. Add an OAS adapter (e.g.
|
|
920
|
+
if (!adapter || !inputNode) throw new Error(`[${plugin.name}] No adapter found. Add an OAS adapter (e.g. adapterOas()) before this plugin in your Kubb config.`);
|
|
955
921
|
function resolveRenderer(gen) {
|
|
956
922
|
return gen.renderer === null ? void 0 : gen.renderer ?? plugin.renderer ?? context.config.renderer;
|
|
957
923
|
}
|
|
@@ -1034,7 +1000,7 @@ async function runPluginAstHooks(plugin, context) {
|
|
|
1034
1000
|
}
|
|
1035
1001
|
}
|
|
1036
1002
|
async function safeBuild(setupResult) {
|
|
1037
|
-
const { driver, hooks, sources
|
|
1003
|
+
const { driver, hooks, sources } = setupResult;
|
|
1038
1004
|
const failedPlugins = /* @__PURE__ */ new Set();
|
|
1039
1005
|
const pluginTimings = /* @__PURE__ */ new Map();
|
|
1040
1006
|
const config = driver.config;
|
|
@@ -1125,6 +1091,7 @@ async function safeBuild(setupResult) {
|
|
|
1125
1091
|
});
|
|
1126
1092
|
await fileProcessor.run(files, {
|
|
1127
1093
|
parsers: parsersMap,
|
|
1094
|
+
mode: "parallel",
|
|
1128
1095
|
extension: config.output.extension,
|
|
1129
1096
|
onStart: async (processingFiles) => {
|
|
1130
1097
|
await hooks.emit("kubb:files:processing:start", { files: processingFiles });
|
|
@@ -1139,7 +1106,7 @@ async function safeBuild(setupResult) {
|
|
|
1139
1106
|
config
|
|
1140
1107
|
});
|
|
1141
1108
|
if (source) {
|
|
1142
|
-
await storage
|
|
1109
|
+
await config.storage.setItem(file.path, source);
|
|
1143
1110
|
sources.set(file.path, source);
|
|
1144
1111
|
}
|
|
1145
1112
|
},
|
|
@@ -1192,13 +1159,27 @@ async function build(setupResult) {
|
|
|
1192
1159
|
sources
|
|
1193
1160
|
};
|
|
1194
1161
|
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Returns a snapshot of the current runtime environment.
|
|
1164
|
+
*
|
|
1165
|
+
* Useful for attaching context to debug logs and error reports so that
|
|
1166
|
+
* issues can be reproduced without manual information gathering.
|
|
1167
|
+
*/
|
|
1168
|
+
function getDiagnosticInfo() {
|
|
1169
|
+
return {
|
|
1170
|
+
nodeVersion: version,
|
|
1171
|
+
KubbVersion: version$1,
|
|
1172
|
+
platform: process.platform,
|
|
1173
|
+
arch: process.arch,
|
|
1174
|
+
cwd: process.cwd()
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
function isInputPath(config) {
|
|
1178
|
+
return typeof config?.input === "object" && config.input !== null && "path" in config.input;
|
|
1179
|
+
}
|
|
1195
1180
|
function inputToAdapterSource(config) {
|
|
1196
1181
|
const input = config.input;
|
|
1197
1182
|
if (!input) throw new Error("[kubb] input is required when using an adapter. Provide input.path or input.data in your config.");
|
|
1198
|
-
if (Array.isArray(input)) return {
|
|
1199
|
-
type: "paths",
|
|
1200
|
-
paths: input.map((i) => new URLPath(i.path).isURL ? i.path : resolve(config.root, i.path))
|
|
1201
|
-
};
|
|
1202
1183
|
if ("data" in input) return {
|
|
1203
1184
|
type: "data",
|
|
1204
1185
|
data: input.data
|
|
@@ -1404,34 +1385,6 @@ function defineParser(parser) {
|
|
|
1404
1385
|
return parser;
|
|
1405
1386
|
}
|
|
1406
1387
|
//#endregion
|
|
1407
|
-
//#region src/definePlugin.ts
|
|
1408
|
-
/**
|
|
1409
|
-
* Wraps a factory function and returns a typed `Plugin` with lifecycle handlers grouped under `hooks`.
|
|
1410
|
-
*
|
|
1411
|
-
* Handlers live in a single `hooks` object (inspired by Astro integrations).
|
|
1412
|
-
* All lifecycle events from `KubbHooks` are available for subscription.
|
|
1413
|
-
*
|
|
1414
|
-
* @note For real plugins, use a `PluginFactoryOptions` type parameter to get type-safe context in `kubb:plugin:setup`.
|
|
1415
|
-
* Plugin names should follow the convention `plugin-<feature>` (e.g., `plugin-react-query`, `plugin-zod`).
|
|
1416
|
-
*
|
|
1417
|
-
* @example
|
|
1418
|
-
* ```ts
|
|
1419
|
-
* import { definePlugin } from '@kubb/core'
|
|
1420
|
-
*
|
|
1421
|
-
* export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({
|
|
1422
|
-
* name: 'plugin-ts',
|
|
1423
|
-
* hooks: {
|
|
1424
|
-
* 'kubb:plugin:setup'(ctx) {
|
|
1425
|
-
* ctx.setResolver(resolverTs)
|
|
1426
|
-
* },
|
|
1427
|
-
* },
|
|
1428
|
-
* }))
|
|
1429
|
-
* ```
|
|
1430
|
-
*/
|
|
1431
|
-
function definePlugin(factory) {
|
|
1432
|
-
return (options) => factory(options ?? {});
|
|
1433
|
-
}
|
|
1434
|
-
//#endregion
|
|
1435
1388
|
//#region src/storages/memoryStorage.ts
|
|
1436
1389
|
/**
|
|
1437
1390
|
* In-memory storage driver. Useful for testing and dry-run scenarios where
|