Skip to content

husky init overwrites existing prepare script without warning #1573

Description

@IllegalCreed

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions