Skip to content

chore(husky): change prepare script to postinstall and add setup script#6944

Closed
theo-sim-dev wants to merge 6 commits intoaxios:v1.xfrom
theo-sim-dev:chore/replace-prepare-with-safe-husky-setup
Closed

chore(husky): change prepare script to postinstall and add setup script#6944
theo-sim-dev wants to merge 6 commits intoaxios:v1.xfrom
theo-sim-dev:chore/replace-prepare-with-safe-husky-setup

Conversation

@theo-sim-dev
Copy link
Copy Markdown

@theo-sim-dev theo-sim-dev commented Jun 22, 2025

Fixes #6931

Summary

This PR replaces the use of the prepare script with a safer postinstall-based Husky setup that only runs in contributor environments. This ensures that consumers of Axios can install it from GitHub or tarballs without encountering errors related to Husky, even in environments without a .git directory.

Previously, Axios's prepare script included Husky install logic that assumed the presence of a .git directory. This caused installation failures in environments such as:

  • CI pipelines
  • Monorepos
  • Git-based installs from forks or branches (e.g., npm install github:axios/axios)

To prevent this while preserving automatic Git hook setup for contributors, this change moves the Husky logic into a guarded shell script executed during postinstall, but only when a .git directory is present.

Changes

  • Removed the "prepare" and "prepare:hooks" scripts from package.json
  • Added "postinstall" with a guarded scripts/setup-husky.sh script that:
    • Runs husky install (same as before)
    • Sets up the commit-msg hook using commitlint (same as before)
    • Skips setup entirely if .git/ is not present (new)
  • Updated .npmignore to ensure the script is included in the published tarball. Otherwise, npm install will fail.
  • Replaced usage of npx with direct binary references for environments where npx may not be available

@jasonsaayman
Copy link
Copy Markdown
Member

please check it seems you included a sub module?

@theo-sim-dev
Copy link
Copy Markdown
Author

theo-sim-dev commented Jun 25, 2025

please check it seems you included a sub module?

@jasonsaayman Oops, it was added by accident during testing. Just removed it!

@jasonsaayman
Copy link
Copy Markdown
Member

please check it seems you included a sub module?

@jasonsaayman Oops, it was added by accident during testing. Just removed it!

no worries thanks 🙌

@jasonsaayman jasonsaayman added this to the v1.11.0 milestone Jun 27, 2025
@jasonsaayman jasonsaayman removed this from the v1.11.0 milestone Jul 10, 2025
Copy link
Copy Markdown
Member

@jasonsaayman jasonsaayman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something is off with the tests, please check it out

@theo-sim-dev
Copy link
Copy Markdown
Author

something is off with the tests, please check it out

@jasonsaayman Can you please clarify how I can reproduce the issue? I ran npm test locally and did not get any test failures. I wonder if it came from the changes I made in package-lock.json previously, which is undone now.

@jasonsaayman
Copy link
Copy Markdown
Member

Thanks @theo-sim-dev. I have already merged a fix for this as part of modernisation. Closing.

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

Successfully merging this pull request may close these issues.

remove prepare script using husky and deprecated husky set from npm package

2 participants