@kubb/core 5.0.0-beta.87 → 5.0.0-beta.89
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/{Diagnostics-aWJg-H2d.d.ts → Diagnostics-CM0-Ae30.d.ts} +110 -49
- package/dist/index.cjs +109 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +30 -6
- package/dist/index.js +109 -27
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import { $ as Include, A as KubbHookStartContext, At as
|
|
2
|
+
import { $ as Include, A as KubbHookStartContext, At as Reporter, B as Kubb, C as KubbFilesProcessingEndContext, Ct as ResolverPathParams, D as KubbGenerationStartContext, Dt as Storage, E as KubbGenerationEndContext, Et as createRenderer, F as KubbSuccessContext, Ft as logLevel, G as KubbDriver, H as Generator, I as KubbWarnContext, It as Adapter, J as Parser, K as FileManagerHooks, L as PossibleConfig, Lt as AdapterFactoryOptions, M as KubbInfoContext, Mt as ReporterName, N as KubbLifecycleStartContext, Nt as UserReporter, O as KubbHookEndContext, Ot as createStorage, P as KubbPluginsEndContext, Pt as createReporter, Q as Group, R as UserConfig, Rt as AdapterSource, S as KubbFileProcessingUpdate, St as ResolverPatch, T as KubbFilesProcessingUpdateContext, Tt as RendererFactory, U as GeneratorContext, V as createKubb, W as defineGenerator, X as Exclude, Y as defineParser, Z as Filter, _ as InputPath, _t as Resolver, a as DiagnosticLocation, at as OutputMode, b as KubbDiagnosticContext, bt as ResolverFileParams, c as PerformanceDiagnostic, ct as Plugin, d as SerializedDiagnostic, dt as BannerMeta, et as KubbPluginEndContext, f as UpdateDiagnostic, ft as ResolveBannerContext, g as InputData, gt as ResolvePathOptions, h as Config, ht as ResolveOptionsContext, i as DiagnosticKind, it as Output, j as KubbHooks, jt as ReporterContext, k as KubbHookLineContext, kt as GenerationResult, l as ProblemCode, lt as PluginFactoryOptions, m as CLIOptions, mt as ResolveFileOptions, n as DiagnosticByCode, nt as KubbPluginStartContext, o as DiagnosticSeverity, ot as OutputOptions, p as BuildOutput, pt as ResolveBannerFile, q as Hookable, r as DiagnosticDoc, rt as NormalizedPlugin, s as Diagnostics, st as Override, t as Diagnostic, tt as KubbPluginSetupContext, u as ProblemDiagnostic, ut as definePlugin, v as KubbBuildEndContext, vt as ResolverDefault, w as KubbFilesProcessingStartContext, wt as Renderer, x as KubbErrorContext, xt as ResolverFilePathParams, y as KubbBuildStartContext, yt as ResolverFile, z as CreateKubbOptions, zt as createAdapter } from "./Diagnostics-CM0-Ae30.js";
|
|
3
3
|
|
|
4
4
|
//#region src/reporters/cliReporter.d.ts
|
|
5
5
|
/**
|
|
@@ -40,7 +40,7 @@ declare const jsonReporter: Reporter;
|
|
|
40
40
|
type ResolverOptions<T extends PluginFactoryOptions> = Omit<T['resolver'], keyof Resolver> & {
|
|
41
41
|
pluginName: T['name'];
|
|
42
42
|
name?: T['resolver']['name'];
|
|
43
|
-
file?:
|
|
43
|
+
file?: ResolverFile;
|
|
44
44
|
} & ThisType<T['resolver']>;
|
|
45
45
|
/**
|
|
46
46
|
* Defines a plugin resolver, the object that decides what every generated symbol and file
|
|
@@ -49,15 +49,39 @@ type ResolverOptions<T extends PluginFactoryOptions> = Omit<T['resolver'], keyof
|
|
|
49
49
|
* (`query`, `schema`, …). Every method reaches sibling helpers and the built-in machinery
|
|
50
50
|
* through `this.name`, `this.file`, and `this.default`.
|
|
51
51
|
*
|
|
52
|
-
* @example Custom identifier
|
|
52
|
+
* @example Custom identifier casing
|
|
53
53
|
* ```ts
|
|
54
54
|
* export const resolverTs = createResolver<PluginTs>({
|
|
55
55
|
* pluginName: 'plugin-ts',
|
|
56
56
|
* name(name) {
|
|
57
57
|
* return ensureValidVarName(pascalCase(name))
|
|
58
58
|
* },
|
|
59
|
-
*
|
|
60
|
-
*
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example Rename generated files with `file.baseName`
|
|
63
|
+
* ```ts
|
|
64
|
+
* export const resolverFaker = createResolver<PluginFaker>({
|
|
65
|
+
* pluginName: 'plugin-faker',
|
|
66
|
+
* name(name) {
|
|
67
|
+
* return camelCase(name, { prefix: 'create' })
|
|
68
|
+
* },
|
|
69
|
+
* file: {
|
|
70
|
+
* baseName({ name, extname }) {
|
|
71
|
+
* return `${camelCase(name, { prefix: 'create' })}${extname}`
|
|
72
|
+
* },
|
|
73
|
+
* },
|
|
74
|
+
* })
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example Own the full path with `file.path`
|
|
78
|
+
* ```ts
|
|
79
|
+
* export const resolverFaker = createResolver<PluginFaker>({
|
|
80
|
+
* pluginName: 'plugin-faker',
|
|
81
|
+
* file: {
|
|
82
|
+
* path({ baseName, output }) {
|
|
83
|
+
* return `${output.path}/mocks/${baseName}`
|
|
84
|
+
* },
|
|
61
85
|
* },
|
|
62
86
|
* })
|
|
63
87
|
* ```
|
|
@@ -116,5 +140,5 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Storag
|
|
|
116
140
|
*/
|
|
117
141
|
declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
|
|
118
142
|
//#endregion
|
|
119
|
-
export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticByCode, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type FileManagerHooks, type Filter, type GenerationResult, type Generator, type GeneratorContext, type Group, Hookable, type Include, InputData, InputPath, type Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbDiagnosticContext, KubbDriver, KubbErrorContext, KubbFileProcessingUpdate, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbFilesProcessingUpdateContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type PerformanceDiagnostic, type Plugin, type PluginFactoryOptions, PossibleConfig, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ResolveBannerContext, type ResolveBannerFile, type ResolveOptionsContext, Resolver, type
|
|
143
|
+
export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticByCode, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type FileManagerHooks, type Filter, type GenerationResult, type Generator, type GeneratorContext, type Group, Hookable, type Include, InputData, InputPath, type Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbDiagnosticContext, KubbDriver, KubbErrorContext, KubbFileProcessingUpdate, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbFilesProcessingUpdateContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type PerformanceDiagnostic, type Plugin, type PluginFactoryOptions, PossibleConfig, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveOptionsContext, type ResolvePathOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type SerializedDiagnostic, type Storage, type UpdateDiagnostic, UserConfig, type UserReporter, cliReporter, createAdapter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, jsonReporter, logLevel, memoryStorage };
|
|
120
144
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -170,7 +170,7 @@ function memoize(store, factory) {
|
|
|
170
170
|
}
|
|
171
171
|
//#endregion
|
|
172
172
|
//#region package.json
|
|
173
|
-
var version = "5.0.0-beta.
|
|
173
|
+
var version = "5.0.0-beta.89";
|
|
174
174
|
//#endregion
|
|
175
175
|
//#region src/constants.ts
|
|
176
176
|
/**
|
|
@@ -745,6 +745,19 @@ function isNamespace(value) {
|
|
|
745
745
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
746
746
|
}
|
|
747
747
|
/**
|
|
748
|
+
* Shared brand for reaching a resolver's build options. `Resolver.merge` reads this instead of
|
|
749
|
+
* relying on `instanceof`, which fails when a CommonJS config and the ESM CLI each load their own
|
|
750
|
+
* copy of `@kubb/core`. `Symbol.for` resolves to one key across those copies, so the options stay
|
|
751
|
+
* reachable and a `file` override is never dropped.
|
|
752
|
+
*/
|
|
753
|
+
const resolverOptions = Symbol.for("@kubb/core/resolver/options");
|
|
754
|
+
/**
|
|
755
|
+
* Built-in `file.baseName`: casts the identifier with `toFilePath` and appends the extension.
|
|
756
|
+
*/
|
|
757
|
+
function toBaseName({ name, extname }) {
|
|
758
|
+
return `${toFilePath(name)}${extname}`;
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
748
761
|
* Base constraint for all plugin resolver objects.
|
|
749
762
|
*
|
|
750
763
|
* The built-in machinery lives under `default`. Generators call the top-level `name` and
|
|
@@ -773,11 +786,19 @@ var Resolver = class Resolver {
|
|
|
773
786
|
static #optionsCache = /* @__PURE__ */ new WeakMap();
|
|
774
787
|
pluginName;
|
|
775
788
|
#options;
|
|
789
|
+
#baseName;
|
|
790
|
+
#filePath;
|
|
776
791
|
constructor(options) {
|
|
777
792
|
this.pluginName = options.pluginName;
|
|
778
793
|
this.#options = options;
|
|
794
|
+
this.#baseName = options.file?.baseName ? options.file.baseName.bind(this) : toBaseName;
|
|
795
|
+
this.#filePath = options.file?.path ? options.file.path.bind(this) : void 0;
|
|
779
796
|
this.#apply(options);
|
|
780
797
|
}
|
|
798
|
+
/** Exposes the raw build options so `Resolver.merge` can read them across `@kubb/core` copies. */
|
|
799
|
+
get [resolverOptions]() {
|
|
800
|
+
return this.#options;
|
|
801
|
+
}
|
|
781
802
|
/**
|
|
782
803
|
* The built-in resolution machinery. Always reaches the untouched defaults, even when a
|
|
783
804
|
* plugin overrides the top-level `name` or `file`.
|
|
@@ -795,19 +816,28 @@ var Resolver = class Resolver {
|
|
|
795
816
|
name(name) {
|
|
796
817
|
return this.default.name(name);
|
|
797
818
|
}
|
|
798
|
-
file(
|
|
799
|
-
return this
|
|
819
|
+
file(options) {
|
|
820
|
+
return this.#resolveFile(options);
|
|
800
821
|
}
|
|
801
822
|
/**
|
|
802
|
-
* Merges `override` over `base` and returns a new resolver with helpers re-bound.
|
|
803
|
-
*
|
|
823
|
+
* Merges `override` over `base` and returns a new resolver with helpers re-bound. Top-level
|
|
824
|
+
* keys replace, and a namespace (or `file`) merges per method, so overriding `query.name`
|
|
825
|
+
* keeps the base `query.keyName`. Used when applying `setResolver` partial overrides. Reads a
|
|
826
|
+
* resolver's options through the shared brand rather than `instanceof`, so a `file` override
|
|
827
|
+
* survives even when `base` and `override` come from different `@kubb/core` copies.
|
|
804
828
|
*/
|
|
805
829
|
static merge(base, override) {
|
|
806
|
-
const patch =
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
830
|
+
const patch = resolverOptions in override ? override[resolverOptions] : override;
|
|
831
|
+
const merged = { ...base[resolverOptions] };
|
|
832
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
833
|
+
if (value === void 0) continue;
|
|
834
|
+
const current = merged[key];
|
|
835
|
+
merged[key] = isNamespace(value) && isNamespace(current) ? {
|
|
836
|
+
...current,
|
|
837
|
+
...value
|
|
838
|
+
} : value;
|
|
839
|
+
}
|
|
840
|
+
return new Resolver(merged);
|
|
811
841
|
}
|
|
812
842
|
/**
|
|
813
843
|
* Binds each entry of `options` onto the resolver, so `this.name`, `this.default`, and
|
|
@@ -818,7 +848,7 @@ var Resolver = class Resolver {
|
|
|
818
848
|
const root = this;
|
|
819
849
|
const bind = (value) => typeof value === "function" ? value.bind(root) : value;
|
|
820
850
|
for (const [key, value] of Object.entries(options)) {
|
|
821
|
-
if (key === "pluginName" || key === "default" || value === void 0) continue;
|
|
851
|
+
if (key === "pluginName" || key === "default" || key === "file" || value === void 0) continue;
|
|
822
852
|
root[key] = isNamespace(value) ? Object.fromEntries(Object.entries(value).map(([method, member]) => [method, bind(member)])) : bind(value);
|
|
823
853
|
}
|
|
824
854
|
}
|
|
@@ -903,7 +933,7 @@ var Resolver = class Resolver {
|
|
|
903
933
|
* to `output.path/{baseName}`, or into a subdirectory when `group` and a `tag`/`path` value
|
|
904
934
|
* are provided.
|
|
905
935
|
*/
|
|
906
|
-
#resolvePath({ baseName, tag, path: groupPath
|
|
936
|
+
#resolvePath({ baseName, tag, path: groupPath, root, output, group }) {
|
|
907
937
|
if (output.mode === "file") return path.resolve(root, output.path);
|
|
908
938
|
const outputDir = path.resolve(root, output.path);
|
|
909
939
|
const result = group && (groupPath || tag) ? path.resolve(outputDir, Resolver.#resolveGroupDir(group, group.type === "path" ? groupPath : tag), baseName) : path.resolve(outputDir, baseName);
|
|
@@ -918,17 +948,45 @@ var Resolver = class Resolver {
|
|
|
918
948
|
return result;
|
|
919
949
|
}
|
|
920
950
|
/**
|
|
921
|
-
*
|
|
922
|
-
*
|
|
923
|
-
*
|
|
951
|
+
* Resolves a resolver-supplied full path (`file.path`) against `root`, bypassing `output.path`
|
|
952
|
+
* and `group`. The path may not escape `root`, which keeps a `file.path` that interpolates
|
|
953
|
+
* spec-derived values from writing outside the project.
|
|
954
|
+
*/
|
|
955
|
+
#resolveOverridePath(filePath, root) {
|
|
956
|
+
const resolved = path.resolve(root, filePath);
|
|
957
|
+
const rootWithSep = root.endsWith(path.sep) ? root : `${root}${path.sep}`;
|
|
958
|
+
if (resolved !== root && !resolved.startsWith(rootWithSep)) throw new Diagnostics.Error({
|
|
959
|
+
code: Diagnostics.code.pathTraversal,
|
|
960
|
+
severity: "error",
|
|
961
|
+
message: `Resolved path "${resolved}" is outside the project root "${root}".`,
|
|
962
|
+
help: "A resolver `file.path` must return a path inside the project root.",
|
|
963
|
+
location: { kind: "config" }
|
|
964
|
+
});
|
|
965
|
+
return resolved;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Builds a `FileNode`. When `#filePath` (the resolver's `file.path`) is set it owns the whole
|
|
969
|
+
* path; otherwise the base name (from `#baseName`, the resolver's `file.baseName` or the
|
|
970
|
+
* built-in `toBaseName`) is placed by the `output.path`/`group` layout. The resolved file starts
|
|
971
|
+
* with empty `sources`, `imports`, and `exports`, which consumers populate separately.
|
|
924
972
|
*/
|
|
925
|
-
#resolveFile(
|
|
926
|
-
const
|
|
927
|
-
const
|
|
928
|
-
|
|
973
|
+
#resolveFile(options) {
|
|
974
|
+
const { name, extname, tag, path: groupPath, root, output, group } = options;
|
|
975
|
+
const baseName = this.#baseName({
|
|
976
|
+
name,
|
|
977
|
+
extname
|
|
978
|
+
});
|
|
979
|
+
const filePath = this.#filePath ? this.#resolveOverridePath(this.#filePath({
|
|
980
|
+
baseName,
|
|
981
|
+
output
|
|
982
|
+
}), root) : this.#resolvePath({
|
|
983
|
+
baseName,
|
|
929
984
|
tag,
|
|
930
|
-
path: groupPath
|
|
931
|
-
|
|
985
|
+
path: groupPath,
|
|
986
|
+
root,
|
|
987
|
+
output,
|
|
988
|
+
group
|
|
989
|
+
});
|
|
932
990
|
return ast.factory.createFile({
|
|
933
991
|
path: filePath,
|
|
934
992
|
baseName: path.basename(filePath),
|
|
@@ -1005,15 +1063,39 @@ var Resolver = class Resolver {
|
|
|
1005
1063
|
* (`query`, `schema`, …). Every method reaches sibling helpers and the built-in machinery
|
|
1006
1064
|
* through `this.name`, `this.file`, and `this.default`.
|
|
1007
1065
|
*
|
|
1008
|
-
* @example Custom identifier
|
|
1066
|
+
* @example Custom identifier casing
|
|
1009
1067
|
* ```ts
|
|
1010
1068
|
* export const resolverTs = createResolver<PluginTs>({
|
|
1011
1069
|
* pluginName: 'plugin-ts',
|
|
1012
1070
|
* name(name) {
|
|
1013
1071
|
* return ensureValidVarName(pascalCase(name))
|
|
1014
1072
|
* },
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
1073
|
+
* })
|
|
1074
|
+
* ```
|
|
1075
|
+
*
|
|
1076
|
+
* @example Rename generated files with `file.baseName`
|
|
1077
|
+
* ```ts
|
|
1078
|
+
* export const resolverFaker = createResolver<PluginFaker>({
|
|
1079
|
+
* pluginName: 'plugin-faker',
|
|
1080
|
+
* name(name) {
|
|
1081
|
+
* return camelCase(name, { prefix: 'create' })
|
|
1082
|
+
* },
|
|
1083
|
+
* file: {
|
|
1084
|
+
* baseName({ name, extname }) {
|
|
1085
|
+
* return `${camelCase(name, { prefix: 'create' })}${extname}`
|
|
1086
|
+
* },
|
|
1087
|
+
* },
|
|
1088
|
+
* })
|
|
1089
|
+
* ```
|
|
1090
|
+
*
|
|
1091
|
+
* @example Own the full path with `file.path`
|
|
1092
|
+
* ```ts
|
|
1093
|
+
* export const resolverFaker = createResolver<PluginFaker>({
|
|
1094
|
+
* pluginName: 'plugin-faker',
|
|
1095
|
+
* file: {
|
|
1096
|
+
* path({ baseName, output }) {
|
|
1097
|
+
* return `${output.path}/mocks/${baseName}`
|
|
1098
|
+
* },
|
|
1017
1099
|
* },
|
|
1018
1100
|
* })
|
|
1019
1101
|
* ```
|
|
@@ -1324,7 +1406,7 @@ var KubbDriver = class {
|
|
|
1324
1406
|
* the failure as a {@link Diagnostic} instead of propagating. Each plugin also
|
|
1325
1407
|
* contributes a `timing` diagnostic for the run summary.
|
|
1326
1408
|
*/
|
|
1327
|
-
async run(
|
|
1409
|
+
async run() {
|
|
1328
1410
|
const { hooks, config, fileManager } = this;
|
|
1329
1411
|
const diagnostics = [];
|
|
1330
1412
|
const parsersMap = /* @__PURE__ */ new Map();
|
|
@@ -1406,7 +1488,7 @@ var KubbDriver = class {
|
|
|
1406
1488
|
diagnostics.push(...await this.#runGenerators(generatorPlugins));
|
|
1407
1489
|
await hooks.callHook("kubb:plugins:end", Object.assign({ config }, this.#filesPayload()));
|
|
1408
1490
|
await fileManager.write(fileManager.files, {
|
|
1409
|
-
storage,
|
|
1491
|
+
storage: config.storage,
|
|
1410
1492
|
parsers: parsersMap,
|
|
1411
1493
|
extension: config.output.extension
|
|
1412
1494
|
});
|
|
@@ -1974,7 +2056,7 @@ var Kubb = class {
|
|
|
1974
2056
|
const self = _usingCtx$1.u(this);
|
|
1975
2057
|
const driver = self.driver;
|
|
1976
2058
|
const storage = self.storage;
|
|
1977
|
-
const { diagnostics } = await driver.run(
|
|
2059
|
+
const { diagnostics } = await driver.run();
|
|
1978
2060
|
return {
|
|
1979
2061
|
diagnostics,
|
|
1980
2062
|
files: driver.fileManager.files,
|