refactor(registry/utils): replace inline original file creation with createRegistryFile
utility
#8313
+46
β29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR: Improve Registry Path Handling in Monorepo Environments
π οΈ Changes Summary
createRegistryFile
utilityRegistryItemFile
ofregistryItemFileSchema
Reason
if (!stats.isFile()) {
ofrecursivelyResolveFileImports
will reusecreateRegistryFile
.PR roadmap introduces several refactors and new utility functions to improve how the
shadcn registry:build
CLI handles failed aliased import paths, especially in monorepo setups using path aliases (e.g.@/components/...
).π Problem
In monorepos, adding a registry component like:
...and running:
Would fail with:
fs.stat()
is called before the alias is resolved bytsconfig-paths
, causing the CLI to crash ungracefully.π‘ Why This Happens
In a monorepo, files from multiple workspaces may be referenced using aliases (
@
,@ui
, etc.). If these aliases aren't fully resolved to disk paths, the CLI crashes when trying to access them directly viafs.stat
.The current logic fails here:
When
fs.stat()
is called on an invalid or unresolved path, it throws anENOENT
error, causing the CLI to crash ungracefully.π§ Roadmap
part of a multi step effort to enable the registry CLI to handle path aliases gracefully in monorepo environments.
determineFileType()
to its own file (utils/registry/determine-file-type.ts
) π (awaiting merge refactor(registry/utils): movedetermineFileType
todetermine-file-type.ts
Β #8299)createRegistryFile()
util for creating registry file shape β (this PR)getStatsOrNonFile()
to gracefully suppress ENOENT errorsretryAlternativePath()
to retry common alias misresolves!stat.isFile()
and handle returned suppressed files in registry build command'sresolveRegistryItems
Each change is isolated for clean diffs.
π§± Directory Structure (for Context)
my monorepo structure to understand the issue:
tsconfig.json
π Notes
tsconfig-paths
is used, but currentfs.stat()
happens before alias resolution in some cases.π Follow-Ups