Skip to content

fix(cli): mirror workspace routing in add --diff/--dry-run#11003

Open
Kaeldehta wants to merge 3 commits into
shadcn-ui:mainfrom
Kaeldehta:fix/dry-run-workspace-aliases
Open

fix(cli): mirror workspace routing in add --diff/--dry-run#11003
Kaeldehta wants to merge 3 commits into
shadcn-ui:mainfrom
Kaeldehta:fix/dry-run-workspace-aliases

Conversation

@Kaeldehta

Copy link
Copy Markdown

Summary

Fixes #11002.

In a monorepo where an app references a UI package by its published name (@workspace/ui/*) but the UI package itself uses package.json #imports (#lib/utils), shadcn add <component> --diff/--dry-run run from an app previewed the wrong import aliases for files routed into the UI package.

  • The real add path (addComponentsaddWorkspaceComponents) routes registry:ui/registry:hook/registry:lib files into the UI package and transforms them with that package's own config → import { cn } from "#lib/utils".
  • The dry-run path had no workspace routing — it transformed every file with the single app config → import { cn } from "@workspace/ui/lib/utils".

So the preview and the actual write disagreed, making --diff misleading. Workspace routing was added to the real path in #10519; the dry-run path was never updated to mirror it.

Changes

  • New packages/shadcn/src/utils/workspace-files.tsgroupFilesByWorkspaceTarget(), extracted from addWorkspaceComponents so the file-grouping / per-package config routing is a single source of truth shared by both paths (this drift is what caused the bug).
  • add-components.tsaddWorkspaceComponents now uses the shared helper. Pure extraction, behavior-preserving.
  • dry-run.tsdryRunComponents now detects the workspace (same condition as the real path) and processes files per target package, transforming each with its own config and reporting workspace-root-relative paths. CSS/env route to the UI package. Non-workspace behavior is unchanged.

Tests

  • Added a registry:ui monorepo dry-run test asserting the preview emits #lib/utils and writes to packages/ui/src/components/badge.tsx.
  • Updated the existing app-local monorepo test: the previewed path is now reported relative to the workspace root, matching what the real add reports.
  • Full package suite passes: pnpm --filter=shadcn test → 1524 passed.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

@Kaeldehta is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@Kaeldehta
Kaeldehta force-pushed the fix/dry-run-workspace-aliases branch from 3d3c027 to e02cd4f Compare June 24, 2026 08:20
…#11002)

In a monorepo, `add --diff`/`--dry-run` previewed the app's import aliases
for files that the real `add` routes into a separate UI package, so the
preview disagreed with what was actually written (e.g. `@workspace/ui/lib/utils`
vs `#lib/utils`).

Extract the workspace file-grouping/config-routing logic out of
`addWorkspaceComponents` into a shared `groupFilesByWorkspaceTarget` helper, and
use it from the dry-run path so each file is transformed with the config of the
package it's written to. This keeps the preview and the real write in sync and
prevents the two paths from drifting again.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Kaeldehta
Kaeldehta force-pushed the fix/dry-run-workspace-aliases branch from e02cd4f to 2e2ab93 Compare June 24, 2026 08:26
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.

[bug]: add --diff/--dry-run previews wrong import aliases for cross-workspace files in a monorepo

1 participant