Adds an optional settings to use Yarn to run Husky #511
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.
This fix has multiple purposes that improve the compatibility with Yarn at little cost:
First, it ensures that the Husky command will run with the same pipeline as the one used by Husky's users when they run their scripts. It previously wasn't the case, because Husky was using
run-node
to "detect" the version of Node to use whereas Yarn users were usingyarn run [...]
(which enforces the Node version to be the same one as the one used to run Yarn itself).Second, starting from Yarn 2 we're looking to keep packages inside their tarballs as much as possible. In the context of
run-node
this causes problems, becauserun-node
is a shellscript and can only be executed when unpacked. Usingyarn husky-run
avoids the issue altogether.Third, when working with PnP environments, if we call the Node script manually, then we need to inject the PnP hook so that Husky knows how to load its dependencies (since they aren't in the
node_modules
folder anymore). Usingyarn run
makes this process transparent: it will inject the hook when running under PnP, and won't do it otherwise, and the Husky script won't have to know anything about it.Four, I'd like to make it possible to track which scripts and binary are used in an application (through Yarn's new plugin system). Directly calling the Husky script wouldn't allow that, but going through
yarn run
would.I guess later we can see whether it would make sense to enable
HUSKY_USE_YARN
by default in some circumstances, but for now I think it's fine if we keep it behind a variable that must be set through a repository-local rcfile (cf #510).