Selecting a Package Manager
During the CLI prompts, you’ll see:Setting a Default
You can set a default package manager in yourzustand-store-config.json:
"npm"(default)"yarn"
How Dependency Installation Works
After generating your store file, the CLI automatically checks if Zustand is installed in your project.Check for Existing Installation
The CLI runs a check command based on your selected package manager:Install if Missing
If Zustand is not found, the CLI installs it automatically:Skip if Already Installed
If Zustand is already installed, you’ll see:Package Manager Differences
The CLI handles the differences between npm and yarn automatically:| Action | npm Command | yarn Command |
|---|---|---|
| Check installation | npm list zustand | yarn list zustand |
| Install package | npm install zustand | yarn add zustand |
- npm uses
installfor adding packages - yarn uses
addfor adding packages
Dependencies Installed
The CLI only installs the core dependency:- zustand - The Zustand state management library
If you choose to add persistence, the CLI generates code that imports from
zustand/middleware, but this is included in the main zustand package - no additional dependencies are needed.Workspace and Monorepo Support
Both npm and yarn support workspaces and monorepos. The CLI:- Runs commands in the current working directory
- Respects your existing
package.jsonand lock files - Uses your package manager’s standard resolution logic
Error Handling
If dependency installation fails, you’ll see an error message:Best Practices
Consistency
Use the same package manager throughout your project:- Don’t mix npm and yarn in the same project
- Commit only one lock file (
package-lock.jsonfor npm,yarn.lockfor yarn) - Set the package manager in your config file to avoid accidentally using the wrong one
Team Configuration
In a team environment, addzustand-store-config.json to version control:
CI/CD
If you’re using the CLI in CI/CD pipelines, ensure:- The selected package manager is installed in your CI environment
- Lock files are committed to version control
- The appropriate cache is configured (npm cache vs yarn cache)
Package Manager Detection
The CLI does not auto-detect your package manager. It always asks you to choose, or uses the value from your config file. If you want to always use the package manager that matches your project’s lock file:- Check if
yarn.lockexists → set"packageManager": "yarn" - Check if
package-lock.jsonexists → set"packageManager": "npm" - Save this in your
zustand-store-config.json