feat: add yarn berry and monorepo workspace support for init command #119
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.
Summary
This PR adds support for Yarn Berry (v2+) and monorepo workspaces to the
gluestack-ui init
command, resolving theENOWORKSPACES
error that occurs when running the command in workspace environments.Problem
When running
npx gluestack-ui init
in a monorepo workspace (particularly with Yarn Berry), users encounter:This happens because the CLI attempts to run
npm config --location=project set legacy-peer-deps=true
, which doesn't support workspace environments.Solution
This PR implements workspace-aware package manager commands:
Key Changes:
Added workspace detection (
isInWorkspace()
) - Detects if running in a monorepo by checking forworkspaces
field in parent package.json filesAdded Yarn version detection (
detectYarnVersion()
) - Differentiates between Yarn Classic (v1) and Yarn Berry (v2+)Fixed
ensureLegacyPeerDeps()
:Added workspace-aware installation flags:
-w .
flag for current workspace-w
flag for workspace rootUpdated postinstall commands to use workspace flags when needed
Related Issues
Testing
Successfully tested in a Yarn Berry (v4.9.1) workspace-based monorepo. The init command now completes without errors.
Test output from Yarn Berry workspace
Note the line
Skipping npm config in workspace environment
- the CLI now correctly detects the workspace and avoids the problematic npm config command.Test Plan
npx gluestack-ui init
should work as before-w .
flag-w
flag🤖 Generated with Claude Code