Skip to content
Commands

kubb add

The add command installs a plugin, adapter, or parser from the Kubb extension registry at its reviewed version and adds a plugin to kubb.config.ts.

kubb add installs an extension at the version the registry pins. It adds a plugin or parser to your kubb.config.ts. For an adapter, it prints the code you add by hand.

Ids, versions, and project files work as in Extension commands.

Terminal
kubb add                             # search the registry
kubb add plugin-zod                  # an official plugin by slug
kubb add acme/plugin-graphql --yes   # a community plugin, no prompt
kubb add plugin-zod --no-install     # edit the config only
noyesResolve idRead manifestSupported?Exit 1Preview and confirmInstall package andrequired pluginsEdit kubb.config.ts

Arguments

ArgumentWhat it does
[id]The registry id. Without it, you pick an extension.

Without an id, kubb add lists the registry. Type to filter on the id, display name, and description. You cannot pick an installed extension.

Preview and summary

Before it asks, the CLI shows the required plugins, the packages it installs, and the config lines it adds:

Output
◇  Plugin plugin-faker v5.3.2 · Generates a Faker.js mock-data factory for every schema in your…
│  Needs     plugin-ts ✓ installed
│  Installs  @kubb/[email protected]
│  Config    kubb.config.ts
│    + import { pluginFaker } from '@kubb/plugin-faker'
│    + plugins: [pluginTs(), pluginFaker()],
◆  Add it?

After the install, the summary title gives the outcome. If it says Plugin needs configuration, add the printed snippet to the config by hand. See Command output.

Required plugins

When the manifest lists dependencies that kubb.config.ts lacks, the CLI asks whether to add them too:

AnswerResult
Yes, add both or Yes, add allInstalls them and adds them next to the extension.
Only <name>Adds the extension alone. kubb generate fails until you add the rest.

--yes adds them.

Config changes

ExtensionChange
PluginAdds its import and a call at the end of the plugins array.
ParserAdds its import and a call at the end of the parsers array. Without parsers, it also writes the defaults parserTs(), parserTsx(), and parserMd().
AdapterChanges nothing. The CLI prints the import and the adapter line to add by hand.
When the CLI cannot edit the config, such as when plugins is not an array literal, it prints Could not edit <file>: <reason> and the snippet to add by hand, then exits with code 1. See Config edits.

Options

FlagAliasDefaultWhat it does
--config <path>-cPath to the Kubb config to edit.
--yes-yfalseSkip the confirmation and add the required plugins. Needs an id.
--no-installEdit the config only. A plugin or parser is still added.
--dry-runfalseShow what the command would install or write, then stop.
Pass --yes in scripts and CI, where no one can answer the prompt.

Exit codes

CodeWhen
0The extension is added, or you canceled a prompt.
1The id is invalid, unknown, or missing with --yes.
1The registry cannot be read, or the extension does not support your Kubb or Node.js version.
1No config is found for a plugin or parser, the install fails, or the config edit fails.

Less common cases

Command output

After the install, the summary lists the packages, the added calls, the next step (kubb generate), and the extension's options page. Its title gives the outcome.

Summary titleWhen
Plugin readyInstalled and added to the config.
Plugin configuredAdded to the config with --no-install.
Plugin already configuredThe plugin was already in the config.
Plugin needs configurationInstalled, but the config needs a manual change. The CLI prints the snippet.
Plugin configured; dependencies missingAdded without the required plugins you declined.

Adapters and parsers say Adapter and Parser instead, except in Plugin configured; dependencies missing, which every kind uses.

Without an id, kubb add lists the registry. An installed extension shows installed and cannot be picked.

Config edits

When kubb add cannot write the extension into the config, it prints a snippet. Add its import and call to the config, then run kubb generate.

  • An extension already in its array is left alone.
  • The CLI cannot edit the config when plugins is not an array literal, or the export name is already imported from another module. The CLI then prints Could not edit <file>: <reason> and the snippet, and exits with code 1.
  • An adapter is never written, so its manual snippet does not set exit code 1.