-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat(shadcn): opt‑in unified radix-ui imports for components #7996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Introduced a new boolean option `unifiedRadixImports` in schema.json and the add command. - Updated addComponents function to handle unified radix imports. - Implemented logic to replace @radix-ui/react-* imports with unified radix-ui imports during component addition.
- Added a new optional boolean flag `unifiedRadixImports` to the init command. - Updated the initialization schema and prompt to include the new option for unified radix-ui imports. - Ensured the unifiedRadixImports setting is correctly parsed and utilized in the configuration.
- Implemented tests to verify migration to unified radix imports when enabled via CLI flag and in components.json. - Ensured that the generated component files and package.json reflect the correct imports and dependencies.
@chocochu is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
@chocochu Could this build upon our radix migrate command? https://github.com/shadcn-ui/ui/blob/main/packages/shadcn/src/migrations/migrate-radix.ts |
yes the feature already uses migrateRadixFile() in this file! |
@shadcn lmk how ur feeling about this |
shadcn@minor
with release note “Add unifiedRadixImports flag to shadcn cli and components.json”.Why
@radix-ui/react-*
to the unifiedradix-ui
package is the preferred path going forward.@radix-ui/react-*
subpackages and emits those imports, forcing you to re-run the Radix migration each time you add components.--unified-radix-imports
orcomponents.json
) so new components are installed and emitted withradix-ui
from the start.What’s included
shadcn init --unified-radix-imports
: persist preference incomponents.json
.shadcn add --unified-radix-imports
: one-off enablement for that add command.components.json
now supports"unifiedRadixImports": boolean
(defaults to false).migrateRadixFile
logic:import { ... } from "radix-ui"
.@radix-ui/react-*
dependencies and addradix-ui
if needed.applyUnifiedRadixImports(tree)
insideadd-components
to DRY out transformation/dependency normalization for both project and workspace add paths."unifiedRadixImports": false
across templates and generated configs.Technical details
packages/shadcn/src/registry/schema.ts
unifiedRadixImports: z.coerce.boolean().default(false).optional()
apps/v4/public/schema.json
: added"unifiedRadixImports": { "type": "boolean" }
apps/www/public/schema.json
: added"unifiedRadixImports": { "type": "boolean" }
packages/shadcn/src/commands/init.ts
--unified-radix-imports
option.promptForConfig
includes an interactive toggle for unified imports.addComponents(...)
during initial install.packages/shadcn/src/commands/add.ts
--unified-radix-imports
option.components.json
and forwards it.packages/shadcn/src/utils/add-components.ts
unifiedRadixImports?: boolean
.applyUnifiedRadixImports(tree)
:migrateRadixFile
to JS/TS(X) files.@radix-ui/react-*
from dependencies/devDependencies.radix-ui
when any@radix-ui/react-*
were removed.Developer docs (API/Interfaces)
components.json
(new key)unifiedRadixImports
(boolean, default: false)radix-ui
imports and dependency set updated accordingly.--unified-radix-imports
init
: persists the setting intocomponents.json
.add
: applies the behavior only for that invocation.Precedence
--unified-radix-imports
(if provided)components.json
"unifiedRadixImports"
false
Testing
packages/tests/src/tests/add.test.ts
radix-ui
andpackage.json
includesradix-ui
but no@radix-ui/react-*
.components.json
tounifiedRadixImports: true
then adding a component yieldsradix-ui
imports.packages/tests/src/tests/init.test.ts
"unifiedRadixImports": false
intocomponents.json
.Docs
apps/www/content/docs/cli.mdx
andapps/v4/content/docs/(root)/cli.mdx
: added the new flag under bothinit
andadd
.unifiedRadixImports
.Backward compatibility
Performance and safety
migrateRadixFile
which explicitly ignoresreact-icons
and preserves import formatting and semicolon style.How to enable
shadcn init --unified-radix-imports
shadcn add alert-dialog --unified-radix-imports
"unifiedRadixImports": true
tocomponents.json
.TODO