chore: bundle CLI with esbuild#2866
Conversation
🦋 Changeset detectedLatest commit: dc2437d The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Performance Benchmark (Lower is Faster)
|
| "types": "lib/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./lib/index.d.ts", |
| WORKDIR /build | ||
| COPY . . | ||
| RUN apk add --no-cache jq git && \ | ||
| npm ci --no-optional --ignore-scripts && \ |
There was a problem hiding this comment.
We don't need to skip deps under optionalDependencies, because we don't have deps at all.
| "release": "node ./scripts/release-publish.mjs", | ||
| "pack:prepare": "./scripts/local-pack.sh", | ||
| "respect:parser:generate": "pegjs --format es --output packages/respect-core/lib/modules/runtime-expressions/abnf-parser.js packages/respect-core/src/modules/runtime-expressions/abnf-parser.pegjs && cp packages/respect-core/lib/modules/runtime-expressions/abnf-parser.js packages/respect-core/src/modules/runtime-expressions/abnf-parser.js", | ||
| "build-docs:copy-assets": "cp packages/cli/src/commands/build-docs/template.hbs packages/cli/lib/commands/build-docs/template.hbs ", |
There was a problem hiding this comment.
We don't need any templates inside lib folder. We only have lib/index.js.
|
📦 A new experimental 🧪 version v0.0.0-snapshot.1781184257 of Redocly CLI has been published for testing. Install with NPM: npm install @redocly/cli@0.0.0-snapshot.1781184257 |
…ic for build-docs
| "@redocly/cli-otel": "0.3.1", | ||
| "@redocly/openapi-core": "2.32.2", | ||
| "@redocly/respect-core": "2.32.2", | ||
| "ajv": "npm:@redocly/ajv@8.18.1", |
There was a problem hiding this comment.
Removed directly unused deps in CLI, because we bundled all deps together.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit dd57cea. Configure here.


What/Why/How?
Switched
@redocly/clito bundle withesbuildand produce one dependency-free file.scripts/build.mjs- esbuild config that bundlessrc/index.ts→lib/index.jsscripts/prepare-publish-dir.mjs- creates a.publishstaging directory with a minimalpackage.json(no dependencies) and only the files that need to be publishedscripts/local-pack.sh-pack:preparenow builds and packs from.publishpackages/clifromtsconfig.build.jsonreferences -tscno longer compiles theCLItemplate.hbsas a string constant inbuild-docs/utils.tsas a fallback -esbuilddoes not copy assets, soresolveTemplateSourcetries to read the file first and falls back to the embedded templatepackage.ts- replacedcreateRequirewith a static JSON import, whichesbuildhandles nativelypin-intersecting-deps.shand all yarn cache workarounds from smoke tests - no transitive deps means no version conflicts to pinReference
Testing
Locally, in CI, in other products.
Screenshots (optional)
Check yourself
Security
Note
Medium Risk
This changes how every consumer installs and runs the CLI (single bundled artifact vs transitive deps), so regressions would affect all commands and platforms; mitigated by updated smoke, snapshot, and Docker publish paths.
Overview
Bundles
@redocly/cliwith esbuild so the published tarball ships onlybin/, bundledlib/, and metadata—no runtimedependencies. Workspace packages (openapi-core,respect-core) and former CLI deps are folded into the bundle at build time; the CLI workspace manifest keeps them asdevDependenciesfor development and bundling.Build & publish pipeline:
packages/cli/scripts/build.mjsproduces ESM output underlib/;prepare-publish-dir.mjsstages.publishwith a strippedpackage.jsonand root README/LICENSE. Rootcompilerunscompile:cli:bundleinstead oftscfor the CLI (CLI removed fromtsconfig.build.json).npm run releaseusesscripts/release-publish.mjsto stage.publishbeforechangeset publish; snapshot release,local-pack.sh, and Dockerpack:preparefollow the same publish-dir flow.Runtime tweaks for bundling:
build-docsis lazy-imported; default Handlebars template is embedded whentemplate.hbsis not on disk; Redoc version comes fromdevDependencies.redocvia static JSON import inpackage.ts. Scorecard plugin evaluation sets__redocly_dirnamefrom the config directory viapathToFileURL.CI/smoke: Yarn/npm smoke jobs drop cache-cleaning,
pin-intersecting-deps, and retry loops; Dockerfile no longer copiestemplate.hbsafter global install.Reviewed by Cursor Bugbot for commit dc2437d. Bugbot is set up for automated code reviews on this repo. Configure here.