Skip to content

chore(cli): bundle with bun target node and publish from staged dir#2637

Open
RomanHotsiy wants to merge 12 commits intomainfrom
codex/bun-node-publish-dir
Open

chore(cli): bundle with bun target node and publish from staged dir#2637
RomanHotsiy wants to merge 12 commits intomainfrom
codex/bun-node-publish-dir

Conversation

@RomanHotsiy
Copy link
Copy Markdown
Member

@RomanHotsiy RomanHotsiy commented Mar 4, 2026

What/Why/How?

  • Switch CLI build output to Bun bundling for Node (bun build --target node) instead of the previous TypeScript-only compile flow.
  • Fix bundled-runtime resolution issues by replacing runtime createRequire('../../package.json') patterns with static JSON imports in CLI runtime paths.
  • Add a built-in build-docs template fallback so bundled artifacts do not depend on template.hbs being present as a filesystem asset.
  • Replace publish-time package.json mutation/restore with a staged publish directory (packages/cli/.publish) and publishConfig.directory so changeset publish publishes from the staged manifest/artifacts.
  • Keep the staged directory minimal: bin/cli.js, bundled lib/index.js, README.md, LICENSE, and a stripped package.json (no deps/devDeps/scripts).
  • Update local pack/smoke/perf/release snapshot flows to use the staged directory.
  • Update CI jobs that execute e2e/pack/publish flows to ensure Bun is installed.

Reference

  • N/A

Testing

  • npm --workspace packages/cli run compile
  • node packages/cli/lib/index.js --help
  • npm run typecheck
  • npm run pack:prepare
  • npm run release (no unpublished packages in this run; verified publish-dir prepare/cleanup path)

Screenshots (optional)

  • N/A

Check yourself

  • Code changed? - Tested with Redoc/Realm/Reunite (internal)
  • All new/updated code is covered by tests
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

Note

Medium Risk
Changes the CLI build and release/publish pipeline (bundling + staged publish directory), which could impact install/runtime behavior and npm publish correctness, but does not alter security-sensitive logic.

Overview
CLI distribution is reworked to ship as a Bun-bundled Node target: packages/cli now builds lib/index.js via bun build (with an npx bun fallback), and CI/e2e workflows install Bun and run a bundle step before tests.

Publishing/packing now happens from a staged directory: a new prepare-publish-dir script generates packages/cli/.publish with only the bin entrypoint, bundled output, README/LICENSE, and a minimal package.json; release, snapshot publish, and local pack scripts are updated to publish/pack that directory and then clean it up.

Bundling compatibility fixes: runtime package.json access is switched to a static JSON import (exposing redocVersion), and build-docs embeds a default Handlebars template fallback when template.hbs isn’t available as a file. Docker build no longer manually copies the template, and smoke fixtures are updated accordingly.

Reviewed by Cursor Bugbot for commit 4077b74. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 4, 2026

🦋 Changeset detected

Latest commit: 4077b74

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@redocly/cli Patch
@redocly/openapi-core Patch
@redocly/respect-core Patch

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

@RomanHotsiy RomanHotsiy added the snapshot Create experimental release PR label Mar 4, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 79.91% (🎯 79%) 6689 / 8370
🔵 Statements 79.34% (🎯 79%) 6920 / 8721
🔵 Functions 83.13% (🎯 82%) 1356 / 1631
🔵 Branches 71.61% (🎯 71%) 4545 / 6346
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/commands/build-docs/index.ts 93.33% 50% 100% 93.33% 53
packages/cli/src/commands/build-docs/utils.ts 59.45% 33.33% 85.71% 61.11% 51-72, 127, 134, 149
packages/cli/src/utils/package.ts 100% 100% 100% 100%
Generated in workflow #9325 for commit 4077b74 by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

CLI Version Mean Time ± Std Dev (s) Relative Performance (Lower is Faster)
cli-latest 3.492s ± 0.034s ▓▓ 1.04x
cli-next 3.374s ± 0.018s ▓ 1.00x (Fastest)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

📦 A new experimental 🧪 version v0.0.0-snapshot.1772635755 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1772635755
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1772635755
# or
npm install @redocly/respect-core@0.0.0-snapshot.1772635755

⚠️ Note: This is a development build and may contain unstable features.

@RomanHotsiy RomanHotsiy removed the snapshot Create experimental release PR label Mar 4, 2026
@RomanHotsiy RomanHotsiy marked this pull request as ready for review March 12, 2026 03:43
@RomanHotsiy RomanHotsiy requested review from a team as code owners March 12, 2026 03:43
Copy link
Copy Markdown
Collaborator

@tatomyr tatomyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a brief look. Will give it another pass later.

import { performance } from 'node:perf_hooks';
import { default as redoc } from 'redoc';

import packageJson from '../../../package.json' with { type: 'json' };
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably makes more sense to import it from utils/package.js.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solved

}

function cleanUpStyledComponentWarnings(str: string): string {
return str.replace(/^styled-components: it looks like an unknown prop .*?(?:\r?\n|$)/gm, '');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the message anywhere. Why do wee need this?

const result = spawnSync(command, args, {
cwd: rootDir,
stdio: 'inherit',
shell: process.platform === 'win32',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to publish from Win?

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1b232c3. Configure here.

Copy link
Copy Markdown
Collaborator

@tatomyr tatomyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a minor comment. Please also check this comment: #2637 (comment).
Otherwise LGTM.

Co-authored-by: Roman Hotsiy <gotsijroman@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants