From 59299546b119fa7ecd0d1a8eb252f1c9facd7449 Mon Sep 17 00:00:00 2001 From: Marcin Panek Date: Tue, 29 Nov 2022 10:56:31 +0100 Subject: [PATCH] Do not attach husky hooks when installing a repository as a dependency (instead of cloning) --- scripts/postinstall.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 1bb6cdb..4ac2d9c 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -7,4 +7,12 @@ /* eslint-env node */ -require( 'husky' ).install(); +const path = require( 'path' ); +const fs = require( 'fs' ); +const ROOT_DIRECTORY = path.join( __dirname, '..' ); + +// When installing a repository as a dependency, the `.git` directory does not exist. +// In such a case, husky should not attach its hooks as npm treats it as a package, not a git repository. +if ( fs.existsSync( path.join( ROOT_DIRECTORY, '.git' ) ) ) { + require( 'husky' ).install(); +}