Skip to content
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

husky init overwrites existing prepare script without warning #1573

Open
IllegalCreed opened this issue Mar 11, 2025 · 0 comments
Open

husky init overwrites existing prepare script without warning #1573

IllegalCreed opened this issue Mar 11, 2025 · 0 comments

Comments

@IllegalCreed
Copy link

Description

When running pnpm dlx husky init (or npx husky init) in a project with an existing prepare script in package.json, Husky overwrites it without any warning or prompt. This behavior can lead to the unintended loss of existing setup logic, which is particularly problematic in projects with multiple tools relying on the prepare script.

Steps to Reproduce

Create a package.json with an existing prepare script:

{
  "scripts": {
    "prepare": "cypress install"
  }
}

Install Husky:

pnpm add -D husky

Run the init command:

pnpm dlx husky init

Check package.json after execution.

Expected Behavior

If a prepare script already exists, Husky should either:
Skip modifying package.json and log a message (e.g., "Existing prepare script detected, please manually add husky if needed").
Prompt the user to confirm whether to overwrite or merge the script.

Actual Behavior

The existing prepare script ("cypress install") is silently overwritten with "husky".
After running pnpm dlx husky init, package.json becomes:

{
  "scripts": {
    "prepare": "husky"
  }
}

This removes the original cypress install command, breaking the project's setup workflow.

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

No branches or pull requests

1 participant