A plain-language guide for anyone new to this codebase. It explains what moved, why, and what (if anything) you need to change as a consumer. For the precise package reference, see
spec.md.This file lives under
docs/optimizer/(notdocs/*.md) so it is not copied to the AsyncAPI website. The website CLI docs are for people using the CLI; this guide is for maintainers and npm library consumers.
@asyncapi/optimizer used to live in its own repository (asyncapi/optimizer). Its source now lives inside the
AsyncAPI CLI repository under packages/optimizer/. The CLI became a small monorepo
so the library can be developed and released next to the CLI that uses it. The npm package name is unchanged
(@asyncapi/optimizer), and the asyncapi optimize command works exactly as before. Alongside the move we
also shipped optimizer v2, a deliberate breaking change for people who use the library directly from npm.
- Monorepo — one git repo containing multiple publishable packages (here: root
@asyncapi/clipluspackages/optimizer). - npm workspaces — the feature that symlinks local packages together, so the CLI's
"@asyncapi/optimizer": "*"resolves topackages/optimizer/on disk instead of downloading from npm. - Turborepo (
turbo) — orders builds/tests across packages (builds the optimizer before the CLI that imports it). - peerDependency — a dependency the consumer must install themselves. In v2,
@asyncapi/parseris a peer of the optimizer (the CLI already provides it). - Changesets — how both packages get versioned, changelogged, and published from this repo.
- If you use the
asyncapi optimizeCLI command: No change. Same command, flags, and behaviour. - If you install
@asyncapi/optimizerfrom npm directly: Yes — v2 is breaking. See below.
-
Typed, coded errors. The library used to throw plain
Error(andconsole.errorthe parser diagnostics). It now throws typed subclasses ofOptimizerError, each with a stable.code(OptimizerErrorCode), and attaches diagnostics toerror.detailsinstead of printing them.import { OptimizerError, OptimizerErrorCode } from '@asyncapi/optimizer'; try { const report = await optimizer.getReport(); } catch (err) { if (err instanceof OptimizerError && err.code === OptimizerErrorCode.DOCUMENT_PARSE_FAILED) { console.error('Could not parse:', err.details); } }
-
getReport()return shape. It now returns an array of groups instead of an object keyed by optimization name:// v1 const report = await optimizer.getReport(); report.removeComponents; // ReportElement[] | undefined // v2 const report = await optimizer.getReport(); // { type, elements }[] report.find((g) => g.type === 'removeComponents')?.elements ?? [];
-
@asyncapi/parseris now a peerDependency. Make sure your project installs it:npm install @asyncapi/optimizer @asyncapi/parser
Unchanged in v2: the optimization algorithm and its output, the Optimizer class + constructor, and
getOptimizedDocument(options).
The CLI stays at the repo root. Workspaces are [".", "packages/*"] so Changesets versions both
@asyncapi/cli (same npx changeset flow as today) and @asyncapi/optimizer.
- A PR includes a
.changeset/*.mdentry. Name@asyncapi/cliand/or@asyncapi/optimizer. - After merge, a bot opens a "Version Packages" PR that applies version bumps + changelogs.
- Merging that PR publishes each bumped package to npm (with provenance).
@asyncapi/optimizer must be registered as a Trusted Publisher on npm for asyncapi/cli before the first
publish from this repo.
npm install # links the workspace
npm run optimizer:build # build just the optimizer
npm run optimizer:test # test just the optimizer
npm test # optimizer + CLI + GitHub Action tests (PR CI)
npm run build # full CLI build (builds optimizer first)- Package spec:
spec.md - Tracking issue: optimizer#306
- Prior art (same pattern):
@asyncapi/openapi-schema-parserintoasyncapi/parser-js