@kubb/core 5.8.0 → 5.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{KubbDriver-BrltQ0nL.js → KubbDriver-DBm4hRKA.js} +143 -154
- package/dist/KubbDriver-DBm4hRKA.js.map +1 -0
- package/dist/{KubbDriver-DXDTb9_c.cjs → KubbDriver-DxWuvJWV.cjs} +153 -152
- package/dist/KubbDriver-DxWuvJWV.cjs.map +1 -0
- package/dist/{types-anBcq2U0.d.ts → createAdapter-BpJYvJTw.d.ts} +1679 -1706
- package/dist/index.cjs +159 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +144 -5
- package/dist/index.js +154 -67
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.d.ts +2 -2
- package/dist/mocks.js +2 -2
- package/dist/{rolldown-runtime-C0LytTxp.js → rolldown-runtime-CRm0XQPb.js} +1 -0
- package/package.json +3 -2
- package/schemas/kubb-extension.json +168 -0
- package/dist/KubbDriver-BrltQ0nL.js.map +0 -1
- package/dist/KubbDriver-DXDTb9_c.cjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as __name } from "./rolldown-runtime-
|
|
2
|
-
import { $ as
|
|
1
|
+
import { t as __name } from "./rolldown-runtime-CRm0XQPb.js";
|
|
2
|
+
import { $ as defineGenerator, $t as ProblemDiagnostic, A as PluginFactory, At as HookResult, B as ResolveFileOptions, Bt as ReporterName, C as NormalizedPlugin, Ct as KubbMessageContext, D as Override, Dt as PossibleConfig, E as OutputOptions, Et as KubbWarnContext, F as assertPluginOption, Ft as Storage, G as ResolverDefault, Gt as Diagnostic, H as ResolveOptionsContext, Ht as UserReporter, I as definePlugin, It as createStorage, J as ResolverFilePathParams, Jt as DiagnosticLocation, K as ResolverFile, Kt as DiagnosticDoc, L as BannerMeta, Lt as GenerationResult, M as PluginName, Mt as runHook, N as PluginType, Nt as KubbDriver, O as Plugin, Ot as PostGenerateCommand, P as ResolvePluginOptions, Pt as FileManagerHooks, Q as GeneratorContext, Qt as ProblemCode, R as ResolveBannerContext, Rt as Reporter, S as KubbPluginStartContext, St as KubbLifecycleStartContext, T as OutputMode, Tt as KubbSuccessContext, U as ResolvePathOptions, Ut as createReporter, V as ResolveImportsOptions, Vt as ReporterPluginFiles, W as Resolver, Wt as logLevel, X as ResolverPathParams, Xt as Diagnostics, Y as ResolverPatch, Yt as DiagnosticSeverity, Z as Generator, Zt as PerformanceDiagnostic, _ as Filter, _t as KubbHookEndContext, a as AdapterSource, an as createRenderer, at as Input, b as KubbPluginEndContext, bt as KubbHooks, c as ExtensionDependency, cn as ParserFactory, ct as KubbDiagnosticContext, d as ExtensionKind, dt as KubbFilesProcessingEndContext, en as SerializedDiagnostic, et as NodeCache, f as ExtensionMeta, ft as KubbFilesProcessingStartContext, g as Exclude, gt as KubbGenerationSummaryContext, h as resolveMeta, ht as KubbGenerationStartContext, i as AdapterFactoryOptions, in as RendererFactory, it as FilesContext, j as PluginFactoryOptions, jt as RunHookOptions, k as PluginDefinition, kt as UserConfig, l as ExtensionDependencyRecord, ln as defineParser, lt as KubbErrorContext, m as defineExtension, mt as KubbGenerationEndContext, n as AdapterDefinition, nn as Hookable, nt as CLIOptions, o as createAdapter, on as Parser, ot as KubbBuildEndContext, p as checkCompatibility, pt as KubbFilesProcessingUpdateContext, q as ResolverFileParams, qt as DiagnosticKind, r as AdapterFactory, rn as Renderer, rt as Config, s as ExtensionDependencies, sn as ParserDefinition, st as KubbBuildStartContext, t as Adapter, tn as UpdateDiagnostic, tt as BuildOutput, u as ExtensionFactory, ut as KubbFileProcessingUpdate, v as Group, vt as KubbHookLineContext, w as Output, wt as KubbPluginsEndContext, x as KubbPluginSetupContext, xt as KubbInfoContext, y as Include, yt as KubbHookStartContext, z as ResolveBannerFile, zt as ReporterContext } from "./createAdapter-BpJYvJTw.js";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
4
|
import { FileNode, Macro, UserFileNode } from "@kubb/ast";
|
|
5
5
|
//#region src/applyConfigDefaults.d.ts
|
|
@@ -68,9 +68,9 @@ export declare function setMacros(macros: ReadonlyArray<Macro>): void;
|
|
|
68
68
|
*/
|
|
69
69
|
export declare function injectFile(file: UserFileNode): void;
|
|
70
70
|
/**
|
|
71
|
-
* Returns the options
|
|
71
|
+
* Returns the options the user passed to the plugin being set up, like `ctx.options`.
|
|
72
72
|
*/
|
|
73
|
-
export declare function useOptions<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(): TFactory['
|
|
73
|
+
export declare function useOptions<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(): TFactory['options'];
|
|
74
74
|
/**
|
|
75
75
|
* Sets the resolved options of the plugin being set up, like `ctx.setOptions`.
|
|
76
76
|
*/
|
|
@@ -474,5 +474,144 @@ export declare function kubbStorage({ base }?: KubbStorageOptions): import("unst
|
|
|
474
474
|
*/
|
|
475
475
|
export declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
|
|
476
476
|
//#endregion
|
|
477
|
-
|
|
477
|
+
//#region src/manifest.d.ts
|
|
478
|
+
/** A value that survives `JSON.stringify` and `JSON.parse` unchanged. */
|
|
479
|
+
type JSONValue = string | number | boolean | null | Array<JSONValue> | {
|
|
480
|
+
[key: string]: JSONValue;
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* One form field Studio renders for an extension. It edits the value at `path` in the options
|
|
484
|
+
* object the user passes to the factory.
|
|
485
|
+
*/
|
|
486
|
+
type ExtensionManifestOption = {
|
|
487
|
+
/** Stable UI key, unique within the manifest. */
|
|
488
|
+
key: string;
|
|
489
|
+
/** Where the value lives, such as `['output', 'path']`. */
|
|
490
|
+
path: Array<string>;
|
|
491
|
+
label: string;
|
|
492
|
+
description?: string;
|
|
493
|
+
type: 'select' | 'boolean' | 'text' | 'number' | 'list';
|
|
494
|
+
/** The extension's runtime default, shown when the option is unset. */
|
|
495
|
+
default?: JSONValue;
|
|
496
|
+
/** For `select`. A choice with value `null` leaves the option unset. */
|
|
497
|
+
choices?: Array<{
|
|
498
|
+
label?: string;
|
|
499
|
+
value: JSONValue;
|
|
500
|
+
}>;
|
|
501
|
+
/** For `boolean`: the value written for `true`, `true` when unset. */
|
|
502
|
+
trueValue?: JSONValue;
|
|
503
|
+
/** For `boolean`: the value written for `false`, `false` when unset. */
|
|
504
|
+
falseValue?: JSONValue;
|
|
505
|
+
/** For `list`: template for each entry, where every `"$item"` string is replaced by the entry. */
|
|
506
|
+
item?: JSONValue;
|
|
507
|
+
/** For `list`: upper-case each entry before writing it. */
|
|
508
|
+
itemCase?: 'upper';
|
|
509
|
+
};
|
|
510
|
+
/**
|
|
511
|
+
* The `kubb-extension.json` file an extension package ships at its root. Studio, the kubb.dev
|
|
512
|
+
* registry, and `kubb add` read it.
|
|
513
|
+
*/
|
|
514
|
+
type ExtensionManifest = {
|
|
515
|
+
$schema?: string;
|
|
516
|
+
kind: ExtensionKind;
|
|
517
|
+
/** Equals the extension's `meta.name`. */
|
|
518
|
+
name: string;
|
|
519
|
+
/** The factory export users call in `kubb.config.ts`, such as `pluginZod`. */
|
|
520
|
+
export: string;
|
|
521
|
+
displayName: string;
|
|
522
|
+
description: string;
|
|
523
|
+
category?: string;
|
|
524
|
+
icon?: {
|
|
525
|
+
light: string;
|
|
526
|
+
dark?: string;
|
|
527
|
+
};
|
|
528
|
+
/** HTTPS image or video URLs. */
|
|
529
|
+
media?: Array<string>;
|
|
530
|
+
tags?: Array<string>;
|
|
531
|
+
docs?: string;
|
|
532
|
+
compatibility?: {
|
|
533
|
+
kubb?: string;
|
|
534
|
+
node?: string;
|
|
535
|
+
};
|
|
536
|
+
/** Plugins only: `client` ships the HTTP client runtime, `consumer` calls one but ships none. */
|
|
537
|
+
role?: 'client' | 'consumer';
|
|
538
|
+
options?: Array<ExtensionManifestOption>;
|
|
539
|
+
};
|
|
540
|
+
/** One extension in a registry's `index.json`. */
|
|
541
|
+
type RegistryEntry = {
|
|
542
|
+
/** `<owner>/<slug>`, such as `kubb-labs/plugin-zod`. */
|
|
543
|
+
id: string;
|
|
544
|
+
kind: ExtensionKind;
|
|
545
|
+
type: 'official' | 'community';
|
|
546
|
+
/** The reviewed npm version to install. */
|
|
547
|
+
artifact: {
|
|
548
|
+
kind: 'npm';
|
|
549
|
+
package: string;
|
|
550
|
+
version: string;
|
|
551
|
+
};
|
|
552
|
+
repository?: {
|
|
553
|
+
url: string;
|
|
554
|
+
};
|
|
555
|
+
manifest: ExtensionManifest;
|
|
556
|
+
stats?: {
|
|
557
|
+
downloads?: number;
|
|
558
|
+
weekly?: number;
|
|
559
|
+
stars?: number;
|
|
560
|
+
};
|
|
561
|
+
submittedAt: string;
|
|
562
|
+
publishedAt: string;
|
|
563
|
+
reviewedAt: string;
|
|
564
|
+
};
|
|
565
|
+
/** The registry's `index.json`. */
|
|
566
|
+
type RegistryIndex = {
|
|
567
|
+
version: 1;
|
|
568
|
+
generatedAt: string;
|
|
569
|
+
extensions: Array<RegistryEntry>;
|
|
570
|
+
};
|
|
571
|
+
/** The registry's `<owner>/<slug>.json`: an entry plus its `OVERVIEW.md`. */
|
|
572
|
+
type RegistryDetail = RegistryEntry & {
|
|
573
|
+
overview: string | null;
|
|
574
|
+
};
|
|
575
|
+
/**
|
|
576
|
+
* Whether `name` is a valid npm package name, such as `@kubb/plugin-ts`. Rejects paths, URLs,
|
|
577
|
+
* `node:` specifiers, and names that start with `-`, so the result is safe to pass to `import()` or
|
|
578
|
+
* a package manager.
|
|
579
|
+
*/
|
|
580
|
+
export declare function isPackageName(name: unknown): name is string;
|
|
581
|
+
/**
|
|
582
|
+
* What is wrong with the options of a well-formed manifest, beyond their shape: keys are unique, a
|
|
583
|
+
* select has choices, and a select's default is one of its choice values. Empty when they pass.
|
|
584
|
+
*/
|
|
585
|
+
export declare function manifestProblems({ options }: ExtensionManifest): Array<string>;
|
|
586
|
+
/**
|
|
587
|
+
* Checks a parsed `kubb-extension.json` or a registry response before Kubb or Studio uses it: the
|
|
588
|
+
* fields Kubb reads, every option's shape (including option paths that cannot reach a prototype),
|
|
589
|
+
* and `manifestProblems`. A malformed manifest is skipped instead of trusted.
|
|
590
|
+
*/
|
|
591
|
+
export declare function isExtensionManifest(value: unknown): value is ExtensionManifest;
|
|
592
|
+
/**
|
|
593
|
+
* Checks one entry of a registry's `index.json` or `<owner>/<slug>.json`: a full `<owner>/<slug>` id,
|
|
594
|
+
* an npm artifact pinned to a valid version, and a valid manifest of the entry's kind.
|
|
595
|
+
*/
|
|
596
|
+
export declare function isRegistryEntry(value: unknown): value is RegistryEntry;
|
|
597
|
+
//#endregion
|
|
598
|
+
//#region src/installedPackages.d.ts
|
|
599
|
+
type InstalledPackage = {
|
|
600
|
+
package: string;
|
|
601
|
+
version?: string;
|
|
602
|
+
manifest?: ExtensionManifest;
|
|
603
|
+
};
|
|
604
|
+
/**
|
|
605
|
+
* The `dependencies` and `devDependencies` of the project at `root`, plus `packages`, with the
|
|
606
|
+
* installed version and the valid `kubb-extension.json` each one ships, when it does. A package
|
|
607
|
+
* also counts as installed when it resolves from one of the `resolveFrom` packages, such as `kubb`
|
|
608
|
+
* for the extensions it ships with.
|
|
609
|
+
*/
|
|
610
|
+
export declare function readInstalledPackages({ root, packages, resolveFrom }: {
|
|
611
|
+
root: string;
|
|
612
|
+
packages?: Iterable<string>;
|
|
613
|
+
resolveFrom?: Array<string>;
|
|
614
|
+
}): Promise<Array<InstalledPackage>>;
|
|
615
|
+
//#endregion
|
|
616
|
+
export { type Adapter, type AdapterDefinition, type AdapterFactory, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type ExtensionDependencies, type ExtensionDependency, type ExtensionDependencyRecord, type ExtensionFactory, type ExtensionKind, type ExtensionManifest, type ExtensionManifestOption, type ExtensionMeta, type FileManagerHooks, FilesContext, type Filter, type GenerateOptions, type GenerateResult, type GenerationResult, type Generator, type GeneratorContext, type Group, type HookResult, Hookable, type Include, Input, type InputKind, type InstalledPackage, type JSONValue, type Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbDiagnosticContext, KubbDriver, KubbErrorContext, KubbFileProcessingUpdate, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbFilesProcessingUpdateContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbGenerationSummaryContext, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, KubbMessageContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NodeCache, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type ParserDefinition, type ParserFactory, type PerformanceDiagnostic, type Plugin, type PluginDefinition, type PluginFactory, type PluginFactoryOptions, type PluginName, type PluginType, PossibleConfig, PostGenerateCommand, type ProblemCode, type ProblemDiagnostic, type RegistryDetail, type RegistryEntry, type RegistryIndex, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ReporterPluginFiles, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveImportsOptions, type ResolveOptionsContext, type ResolvePathOptions, type ResolvePluginOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type RunHookOptions, type RunOutputPassesOptions, type SerializedDiagnostic, type Storage, type SummaryRenderer, type UpdateDiagnostic, UserConfig, type UserReporter, assertPluginOption, checkCompatibility, createAdapter, createRenderer, createReporter, createStorage, defineExtension, defineGenerator, defineParser, definePlugin, logLevel, resolveMeta, runHook };
|
|
478
617
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import "./rolldown-runtime-
|
|
2
|
-
import { A as
|
|
1
|
+
import "./rolldown-runtime-CRm0XQPb.js";
|
|
2
|
+
import { A as getElapsedMs, C as useOptions, D as resolveMeta, E as defineExtension, F as read, I as toPosixPath, L as write, M as clean, N as exists, O as Diagnostics, P as isPathInside, R as toError, S as useKubb, T as createExtensionFactory, _ as setMacros, a as _usingCtx, b as tryUseKubb, c as Resolver, d as definePlugin, f as addGenerator, g as requirePlugin, h as kubbContext, j as inParallel, k as formatMs, l as getInputKind, m as injectFile, o as Hookable, p as addMacro, s as createResolver, t as KubbDriver, u as assertPluginOption, v as setOptions, w as checkCompatibility, x as useConfig, y as setResolver } from "./KubbDriver-DBm4hRKA.js";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { isValid } from "verkit";
|
|
3
5
|
import { stripVTControlCharacters, styleText } from "node:util";
|
|
4
6
|
import process$1 from "node:process";
|
|
5
7
|
import { x } from "tinyexec";
|
|
6
8
|
import { glob, readFile, rm } from "node:fs/promises";
|
|
7
|
-
import { join, relative, resolve } from "node:path";
|
|
9
|
+
import path, { join, relative, resolve } from "node:path";
|
|
8
10
|
import { hash, randomUUID } from "node:crypto";
|
|
9
11
|
import { chmodSync, existsSync, mkdirSync } from "node:fs";
|
|
10
12
|
import { homedir, tmpdir } from "node:os";
|
|
@@ -12,60 +14,6 @@ import { createInterface } from "node:readline";
|
|
|
12
14
|
import { createStorage as createStorage$1 } from "unstorage";
|
|
13
15
|
import fsDriver from "unstorage/drivers/fs";
|
|
14
16
|
import { fileURLToPath } from "node:url";
|
|
15
|
-
//#region src/createAdapter.ts
|
|
16
|
-
/**
|
|
17
|
-
* Defines a custom adapter that translates a spec format into Kubb's universal
|
|
18
|
-
* AST, for example GraphQL, gRPC, or AsyncAPI. The built-in `@kubb/adapter-oas`
|
|
19
|
-
* handles OpenAPI/Swagger documents.
|
|
20
|
-
*
|
|
21
|
-
* Adapters must return an `InputNode` from `parse`. That node is what every
|
|
22
|
-
* plugin in the build consumes.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* import { createAdapter, type AdapterFactoryOptions } from '@kubb/core'
|
|
27
|
-
* import { ast } from '@kubb/ast'
|
|
28
|
-
*
|
|
29
|
-
* type MyAdapter = AdapterFactoryOptions<'my-adapter', { validate?: boolean }>
|
|
30
|
-
*
|
|
31
|
-
* export const myAdapter = createAdapter<MyAdapter>((options) => ({
|
|
32
|
-
* name: 'my-adapter',
|
|
33
|
-
* options,
|
|
34
|
-
* document: null,
|
|
35
|
-
* async parse(_source) {
|
|
36
|
-
* // Convert the source (path or inline data) into an InputNode.
|
|
37
|
-
* return ast.factory.createInput()
|
|
38
|
-
* },
|
|
39
|
-
* async validate() {
|
|
40
|
-
* // Throw here when the spec is invalid.
|
|
41
|
-
* },
|
|
42
|
-
* }))
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
function createAdapter(build) {
|
|
46
|
-
return (options) => build(options ?? {});
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/applyConfigDefaults.ts
|
|
50
|
-
/**
|
|
51
|
-
* Fills in the config defaults shared by `defineConfig` and the unplugin factory: the fallback
|
|
52
|
-
* adapter, `defaultOutput`'s fields, and appending the barrel plugin when it's not already
|
|
53
|
-
* registered. Both entry points construct their own adapter, barrel plugin, and output defaults
|
|
54
|
-
* (`barrel` is a `@kubb/plugin-barrel` extension field core doesn't know about) and pass them in,
|
|
55
|
-
* so `@kubb/core` doesn't need to depend on `@kubb/adapter-oas` or `@kubb/plugin-barrel`.
|
|
56
|
-
*/
|
|
57
|
-
function applyConfigDefaults(config, { defaultAdapter, barrelPlugin, barrelPluginName, defaultOutput }) {
|
|
58
|
-
const plugins = config.plugins?.some((plugin) => plugin.name === barrelPluginName) ? config.plugins ?? [] : [...config.plugins ?? [], barrelPlugin];
|
|
59
|
-
return {
|
|
60
|
-
adapter: config.adapter ?? defaultAdapter,
|
|
61
|
-
plugins,
|
|
62
|
-
output: {
|
|
63
|
-
...defaultOutput,
|
|
64
|
-
...config.output
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
//#endregion
|
|
69
17
|
//#region ../../internals/utils/src/isCIEnvironment.ts
|
|
70
18
|
/**
|
|
71
19
|
* Returns `true` when a known CI provider has set its environment variable.
|
|
@@ -204,6 +152,38 @@ function tokenize(command) {
|
|
|
204
152
|
return (command.match(/[^\s"']+|"([^"]*)"|'([^']*)'/g) ?? []).map((token) => token.replace(/^["']|["']$/g, ""));
|
|
205
153
|
}
|
|
206
154
|
//#endregion
|
|
155
|
+
//#region src/createAdapter.ts
|
|
156
|
+
function createAdapter(input) {
|
|
157
|
+
if (typeof input === "function") return createExtensionFactory({
|
|
158
|
+
kind: "adapter",
|
|
159
|
+
build: (options) => input(options)
|
|
160
|
+
});
|
|
161
|
+
return defineExtension({
|
|
162
|
+
kind: "adapter",
|
|
163
|
+
...input
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/applyConfigDefaults.ts
|
|
168
|
+
/**
|
|
169
|
+
* Fills in the config defaults shared by `defineConfig` and the unplugin factory: the fallback
|
|
170
|
+
* adapter, `defaultOutput`'s fields, and appending the barrel plugin when it's not already
|
|
171
|
+
* registered. Both entry points construct their own adapter, barrel plugin, and output defaults
|
|
172
|
+
* (`barrel` is a `@kubb/plugin-barrel` extension field core doesn't know about) and pass them in,
|
|
173
|
+
* so `@kubb/core` doesn't need to depend on `@kubb/adapter-oas` or `@kubb/plugin-barrel`.
|
|
174
|
+
*/
|
|
175
|
+
function applyConfigDefaults(config, { defaultAdapter, barrelPlugin, barrelPluginName, defaultOutput }) {
|
|
176
|
+
const plugins = config.plugins?.some((plugin) => plugin.name === barrelPluginName) ? config.plugins ?? [] : [...config.plugins ?? [], barrelPlugin];
|
|
177
|
+
return {
|
|
178
|
+
adapter: config.adapter ?? defaultAdapter,
|
|
179
|
+
plugins,
|
|
180
|
+
output: {
|
|
181
|
+
...defaultOutput,
|
|
182
|
+
...config.output
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
207
187
|
//#region src/outputManifest.ts
|
|
208
188
|
/**
|
|
209
189
|
* Bumped when the stored shape changes, so an older cache is discarded instead of misread.
|
|
@@ -1296,9 +1276,9 @@ function defineGenerator(generator) {
|
|
|
1296
1276
|
//#endregion
|
|
1297
1277
|
//#region src/defineParser.ts
|
|
1298
1278
|
function defineParser(input) {
|
|
1299
|
-
if (typeof input === "function") return
|
|
1279
|
+
if (typeof input === "function") return createExtensionFactory({
|
|
1300
1280
|
kind: "parser",
|
|
1301
|
-
build: (
|
|
1281
|
+
build: (options) => {
|
|
1302
1282
|
const parser = input(options);
|
|
1303
1283
|
return {
|
|
1304
1284
|
...parser,
|
|
@@ -1306,15 +1286,10 @@ function defineParser(input) {
|
|
|
1306
1286
|
};
|
|
1307
1287
|
}
|
|
1308
1288
|
});
|
|
1309
|
-
const { meta, setup } = input;
|
|
1310
1289
|
return defineExtension({
|
|
1311
1290
|
kind: "parser",
|
|
1312
|
-
meta,
|
|
1313
|
-
build:
|
|
1314
|
-
...setup(options),
|
|
1315
|
-
name: meta.name,
|
|
1316
|
-
meta
|
|
1317
|
-
})
|
|
1291
|
+
meta: input.meta,
|
|
1292
|
+
build: "build" in input ? input.build : input.setup
|
|
1318
1293
|
});
|
|
1319
1294
|
}
|
|
1320
1295
|
//#endregion
|
|
@@ -1368,6 +1343,118 @@ const memoryStorage = createStorage(() => {
|
|
|
1368
1343
|
};
|
|
1369
1344
|
});
|
|
1370
1345
|
//#endregion
|
|
1371
|
-
|
|
1346
|
+
//#region src/manifest.ts
|
|
1347
|
+
const EXTENSION_KINDS = /* @__PURE__ */ new Set([
|
|
1348
|
+
"plugin",
|
|
1349
|
+
"adapter",
|
|
1350
|
+
"parser"
|
|
1351
|
+
]);
|
|
1352
|
+
const OPTION_TYPES = /* @__PURE__ */ new Set([
|
|
1353
|
+
"select",
|
|
1354
|
+
"boolean",
|
|
1355
|
+
"text",
|
|
1356
|
+
"number",
|
|
1357
|
+
"list"
|
|
1358
|
+
]);
|
|
1359
|
+
const PACKAGE_NAME = /^(?:@[a-z0-9~][a-z0-9._~-]*\/)?[a-z0-9~][a-z0-9._~-]*$/;
|
|
1360
|
+
const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
1361
|
+
const REGISTRY_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*\/[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
1362
|
+
/** Option path segments that would reach an object's prototype when Studio writes the value by path. */
|
|
1363
|
+
const UNSAFE_KEYS = /* @__PURE__ */ new Set([
|
|
1364
|
+
"__proto__",
|
|
1365
|
+
"constructor",
|
|
1366
|
+
"prototype"
|
|
1367
|
+
]);
|
|
1368
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1369
|
+
const isOptionalString = (value) => value === void 0 || typeof value === "string";
|
|
1370
|
+
const isFilledString = (value) => typeof value === "string" && value !== "";
|
|
1371
|
+
/** Serializes with sorted object keys, so equal JSON values give equal strings whatever their key order. */
|
|
1372
|
+
const canonicalJSON = (value) => JSON.stringify(value, (_key, item) => isObject(item) ? Object.fromEntries(Object.keys(item).sort().map((key) => [key, item[key]])) : item);
|
|
1373
|
+
/**
|
|
1374
|
+
* Whether `name` is a valid npm package name, such as `@kubb/plugin-ts`. Rejects paths, URLs,
|
|
1375
|
+
* `node:` specifiers, and names that start with `-`, so the result is safe to pass to `import()` or
|
|
1376
|
+
* a package manager.
|
|
1377
|
+
*/
|
|
1378
|
+
function isPackageName(name) {
|
|
1379
|
+
return typeof name === "string" && name.length <= 214 && PACKAGE_NAME.test(name);
|
|
1380
|
+
}
|
|
1381
|
+
/** Checks the shape of one manifest option, including that its path cannot reach a prototype. */
|
|
1382
|
+
function isOption(value) {
|
|
1383
|
+
if (!isObject(value)) return false;
|
|
1384
|
+
const { key, path, label, description, type, choices, itemCase } = value;
|
|
1385
|
+
return isFilledString(key) && Array.isArray(path) && path.length > 0 && path.every((segment) => isFilledString(segment) && !UNSAFE_KEYS.has(segment)) && isFilledString(label) && isOptionalString(description) && OPTION_TYPES.has(type) && (choices === void 0 || Array.isArray(choices) && choices.every((choice) => isObject(choice) && "value" in choice && isOptionalString(choice.label))) && (itemCase === void 0 || itemCase === "upper");
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* What is wrong with the options of a well-formed manifest, beyond their shape: keys are unique, a
|
|
1389
|
+
* select has choices, and a select's default is one of its choice values. Empty when they pass.
|
|
1390
|
+
*/
|
|
1391
|
+
function manifestProblems({ options = [] }) {
|
|
1392
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1393
|
+
return options.flatMap((option) => {
|
|
1394
|
+
const problems = seen.has(option.key) ? [`option "${option.key}" is declared more than once`] : [];
|
|
1395
|
+
seen.add(option.key);
|
|
1396
|
+
if (option.type !== "select") return problems;
|
|
1397
|
+
if (!option.choices?.length) return [...problems, `option "${option.key}" is a select without choices`];
|
|
1398
|
+
return !("default" in option) || option.choices.some((choice) => canonicalJSON(choice.value) === canonicalJSON(option.default)) ? problems : [...problems, `option "${option.key}" has a default that is not one of its choices`];
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Checks a parsed `kubb-extension.json` or a registry response before Kubb or Studio uses it: the
|
|
1403
|
+
* fields Kubb reads, every option's shape (including option paths that cannot reach a prototype),
|
|
1404
|
+
* and `manifestProblems`. A malformed manifest is skipped instead of trusted.
|
|
1405
|
+
*/
|
|
1406
|
+
function isExtensionManifest(value) {
|
|
1407
|
+
if (!isObject(value)) return false;
|
|
1408
|
+
const { kind, name, export: exportName, displayName, description, compatibility, options } = value;
|
|
1409
|
+
return EXTENSION_KINDS.has(kind) && isPackageName(name) && typeof exportName === "string" && IDENTIFIER.test(exportName) && typeof displayName === "string" && typeof description === "string" && (compatibility === void 0 || isObject(compatibility) && Object.entries(compatibility).every(([key, range]) => (key === "kubb" || key === "node") && typeof range === "string")) && (options === void 0 || Array.isArray(options) && options.every(isOption)) && manifestProblems(value).length === 0;
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Checks one entry of a registry's `index.json` or `<owner>/<slug>.json`: a full `<owner>/<slug>` id,
|
|
1413
|
+
* an npm artifact pinned to a valid version, and a valid manifest of the entry's kind.
|
|
1414
|
+
*/
|
|
1415
|
+
function isRegistryEntry(value) {
|
|
1416
|
+
if (!isObject(value)) return false;
|
|
1417
|
+
const { id, kind, type, artifact, manifest } = value;
|
|
1418
|
+
return typeof id === "string" && REGISTRY_ID.test(id) && EXTENSION_KINDS.has(kind) && (type === "official" || type === "community") && isObject(artifact) && artifact.kind === "npm" && isPackageName(artifact.package) && typeof artifact.version === "string" && isValid(artifact.version) && isExtensionManifest(manifest) && manifest.kind === kind;
|
|
1419
|
+
}
|
|
1420
|
+
//#endregion
|
|
1421
|
+
//#region src/installedPackages.ts
|
|
1422
|
+
/** Reads and parses a JSON file. Throws when it is missing or not JSON. */
|
|
1423
|
+
const readJSON = async (file) => JSON.parse(await readFile(file, "utf8"));
|
|
1424
|
+
/**
|
|
1425
|
+
* The `dependencies` and `devDependencies` of the project at `root`, plus `packages`, with the
|
|
1426
|
+
* installed version and the valid `kubb-extension.json` each one ships, when it does. A package
|
|
1427
|
+
* also counts as installed when it resolves from one of the `resolveFrom` packages, such as `kubb`
|
|
1428
|
+
* for the extensions it ships with.
|
|
1429
|
+
*/
|
|
1430
|
+
async function readInstalledPackages({ root, packages = [], resolveFrom = [] }) {
|
|
1431
|
+
const project = createRequire(path.join(root, "package.json"));
|
|
1432
|
+
const requires = [project, ...resolveFrom.flatMap((name) => {
|
|
1433
|
+
try {
|
|
1434
|
+
return [createRequire(project.resolve(`${name}/package.json`))];
|
|
1435
|
+
} catch {
|
|
1436
|
+
return [];
|
|
1437
|
+
}
|
|
1438
|
+
})];
|
|
1439
|
+
const packageJSON = await readJSON(path.join(root, "package.json")).catch(() => null);
|
|
1440
|
+
const dependencies = [packageJSON?.dependencies, packageJSON?.devDependencies].flatMap((record) => typeof record === "object" && record !== null ? Object.keys(record) : []);
|
|
1441
|
+
return Promise.all([.../* @__PURE__ */ new Set([...dependencies, ...packages])].filter(isPackageName).map(async (name) => {
|
|
1442
|
+
const dir = requires.flatMap((require) => require.resolve.paths(name) ?? []).map((dir) => path.join(dir, name)).find((dir) => existsSync(path.join(dir, "package.json")));
|
|
1443
|
+
if (!dir) return { package: name };
|
|
1444
|
+
try {
|
|
1445
|
+
const { version } = await readJSON(path.join(dir, "package.json"));
|
|
1446
|
+
const manifest = await readJSON(path.join(dir, "kubb-extension.json")).catch(() => void 0);
|
|
1447
|
+
return {
|
|
1448
|
+
package: name,
|
|
1449
|
+
version: typeof version === "string" ? version : void 0,
|
|
1450
|
+
manifest: isExtensionManifest(manifest) ? manifest : void 0
|
|
1451
|
+
};
|
|
1452
|
+
} catch {
|
|
1453
|
+
return { package: name };
|
|
1454
|
+
}
|
|
1455
|
+
}));
|
|
1456
|
+
}
|
|
1457
|
+
//#endregion
|
|
1458
|
+
export { Diagnostics, Hookable, KubbDriver, Resolver, addGenerator, addMacro, applyConfigDefaults, assertPluginOption, cacheStorage, checkCompatibility, cliReporter, createAdapter, createCliReporter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineExtension, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, getInputKind, htmlReporter, injectFile, isExtensionManifest, isPackageName, isRegistryEntry, jsonReporter, kubbContext, kubbStorage, logLevel, manifestProblems, memoryStorage, readInstalledPackages, requirePlugin, resolveCacheDir, resolveKubbDir, resolveMeta, runHook, runOutputPasses, setMacros, setOptions, setResolver, tryUseKubb, useConfig, useKubb, useOptions };
|
|
1372
1459
|
|
|
1373
1460
|
//# sourceMappingURL=index.js.map
|