From 1aac5c392b66e1afb2191cfb49dbe9197f6430d2 Mon Sep 17 00:00:00 2001 From: Sibiraj <20282546+sibiraj-s@users.noreply.github.com> Date: Thu, 27 Sep 2018 12:02:45 +0530 Subject: [PATCH] husky-upgrade: don't create husky config if no hooks exist (#359) --- src/upgrader/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/upgrader/index.ts b/src/upgrader/index.ts index cfc23bd24..7f264620f 100644 --- a/src/upgrader/index.ts +++ b/src/upgrader/index.ts @@ -42,8 +42,7 @@ export default function upgrade(cwd: string) { ) } - // Create empty husky.hooks field - pkg.husky = { hooks: {} } + const hooks: IHookMap = {} // Loop trhough hooks and move them to husky.hooks Object.keys(hookList).forEach(name => { @@ -51,7 +50,7 @@ export default function upgrade(cwd: string) { if (script) { delete pkg.scripts[name] const newName = hookList[name] - pkg.husky.hooks[newName] = script.replace( + hooks[newName] = script.replace( /\bGIT_PARAMS\b/g, 'HUSKY_GIT_PARAMS' ) @@ -59,6 +58,12 @@ export default function upgrade(cwd: string) { } }) + if (Object.keys(hooks).length) { + pkg.husky = { hooks } + } else { + console.log('no hooks found') + } + // Update package.json fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`, 'utf-8') console.log(`husky > done`)