@kubb/core 5.8.3 → 5.9.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/index.d.ts CHANGED
@@ -544,18 +544,30 @@ type ExtensionManifest = {
544
544
  role?: 'client' | 'consumer';
545
545
  options?: Array<ExtensionManifestOption>;
546
546
  };
547
+ /** What `kubb add` installs: a reviewed npm version, or a GitHub release tag and the commit it points to. */
548
+ type RegistryArtifact = {
549
+ kind: 'npm';
550
+ package: string;
551
+ version: string;
552
+ } | {
553
+ kind: 'github';
554
+ /** The `name` in the root `package.json`, so the package installs under this name. */
555
+ package: string;
556
+ /** The release version, equal to `tag` without a leading `v`. */
557
+ version: string;
558
+ owner: string;
559
+ repo: string;
560
+ tag: string;
561
+ /** The full commit SHA the tag points to. */
562
+ commit: string;
563
+ };
547
564
  /** One extension in a registry's `index.json`. */
548
565
  type RegistryEntry = {
549
566
  /** `<owner>/<slug>`, such as `kubb-labs/plugin-zod`. */
550
567
  id: string;
551
568
  kind: ExtensionKind;
552
569
  type: 'official' | 'community';
553
- /** The reviewed npm version to install. */
554
- artifact: {
555
- kind: 'npm';
556
- package: string;
557
- version: string;
558
- };
570
+ artifact: RegistryArtifact;
559
571
  repository?: {
560
572
  url: string;
561
573
  };
@@ -607,7 +619,7 @@ export declare function manifestProblems({ options }: ExtensionManifest): Array<
607
619
  export declare function isExtensionManifest(value: unknown): value is ExtensionManifest;
608
620
  /**
609
621
  * Checks one entry of a registry's `index.json` or `<owner>/<slug>.json`: a full `<owner>/<slug>` id,
610
- * an npm artifact pinned to a valid version, and a valid manifest of the entry's kind.
622
+ * an npm or GitHub artifact pinned to a valid version, and a valid manifest of the entry's kind.
611
623
  */
612
624
  export declare function isRegistryEntry(value: unknown): value is RegistryEntry;
613
625
  //#endregion
@@ -629,5 +641,5 @@ export declare function readInstalledPackages({ root, packages, resolveFrom }: {
629
641
  resolveFrom?: Array<string>;
630
642
  }): Promise<Array<InstalledPackage>>;
631
643
  //#endregion
632
- 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 RegistryGuide, 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 };
644
+ 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 RegistryArtifact, type RegistryDetail, type RegistryEntry, type RegistryGuide, 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 };
633
645
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
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-BX8mbluL.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-B13hgYVE.js";
3
3
  import { createRequire } from "node:module";
4
4
  import { isValid } from "verkit";
5
5
  import { stripVTControlCharacters, styleText } from "node:util";
@@ -1359,6 +1359,9 @@ const OPTION_TYPES = /* @__PURE__ */ new Set([
1359
1359
  const PACKAGE_NAME = /^(?:@[a-z0-9~][a-z0-9._~-]*\/)?[a-z0-9~][a-z0-9._~-]*$/;
1360
1360
  const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
1361
1361
  const REGISTRY_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*\/[a-z0-9]+(?:-[a-z0-9]+)*$/;
1362
+ const GITHUB_OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/;
1363
+ const GITHUB_REPO = /^(?!\.\.?$)[A-Za-z0-9._-]{1,100}$/;
1364
+ const COMMIT = /^[0-9a-f]{40}$/;
1362
1365
  /** Option path segments that would reach an object's prototype when Studio writes the value by path. */
1363
1366
  const UNSAFE_KEYS = /* @__PURE__ */ new Set([
1364
1367
  "__proto__",
@@ -1368,6 +1371,7 @@ const UNSAFE_KEYS = /* @__PURE__ */ new Set([
1368
1371
  const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1369
1372
  const isOptionalString = (value) => value === void 0 || typeof value === "string";
1370
1373
  const isFilledString = (value) => typeof value === "string" && value !== "";
1374
+ const matches = (pattern, value) => typeof value === "string" && pattern.test(value);
1371
1375
  /** Serializes with sorted object keys, so equal JSON values give equal strings whatever their key order. */
1372
1376
  const canonicalJSON = (value) => JSON.stringify(value, (_key, item) => isObject(item) ? Object.fromEntries(Object.keys(item).sort().map((key) => [key, item[key]])) : item);
1373
1377
  /**
@@ -1411,14 +1415,20 @@ function isExtensionManifest(value) {
1411
1415
  const { kind, name, export: exportName, displayName, description, maintainers, dependencies, compatibility, options } = value;
1412
1416
  return EXTENSION_KINDS.has(kind) && isPackageName(name) && typeof exportName === "string" && IDENTIFIER.test(exportName) && typeof displayName === "string" && typeof description === "string" && (maintainers === void 0 || Array.isArray(maintainers) && maintainers.every(isMaintainer)) && (dependencies === void 0 || Array.isArray(dependencies) && dependencies.every(isPackageName)) && (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;
1413
1417
  }
1418
+ /** Checks that no artifact field can reach a package manager as a flag or path, and that a GitHub tag names the version. */
1419
+ function isRegistryArtifact(value) {
1420
+ if (!isObject(value) || !isPackageName(value.package) || typeof value.version !== "string" || !isValid(value.version)) return false;
1421
+ if (value.kind === "npm") return true;
1422
+ return value.kind === "github" && matches(GITHUB_OWNER, value.owner) && matches(GITHUB_REPO, value.repo) && (value.tag === value.version || value.tag === `v${value.version}`) && matches(COMMIT, value.commit);
1423
+ }
1414
1424
  /**
1415
1425
  * Checks one entry of a registry's `index.json` or `<owner>/<slug>.json`: a full `<owner>/<slug>` id,
1416
- * an npm artifact pinned to a valid version, and a valid manifest of the entry's kind.
1426
+ * an npm or GitHub artifact pinned to a valid version, and a valid manifest of the entry's kind.
1417
1427
  */
1418
1428
  function isRegistryEntry(value) {
1419
1429
  if (!isObject(value)) return false;
1420
1430
  const { id, kind, type, artifact, manifest } = value;
1421
- 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;
1431
+ return typeof id === "string" && REGISTRY_ID.test(id) && EXTENSION_KINDS.has(kind) && (type === "official" || type === "community") && isRegistryArtifact(artifact) && isExtensionManifest(manifest) && manifest.kind === kind;
1422
1432
  }
1423
1433
  //#endregion
1424
1434
  //#region src/installedPackages.ts