From 4c73872b76faca92ae42b28bc44b1e07926f7996 Mon Sep 17 00:00:00 2001 From: Sibiraj Date: Wed, 26 Sep 2018 20:02:05 +0530 Subject: [PATCH] perf(husky-upgrade): don't create husky config if no hooks exist --- 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 6be6b952e..ebb070598 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,11 +50,17 @@ export default function upgrade(cwd: string) { if (script) { delete pkg.scripts[name] const newName = hookList[name] - pkg.husky.hooks[newName] = script + hooks[newName] = script console.log(`moved scripts.${name} to husky.hooks.${newName}`) } }) + 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), 'utf-8') console.log(`husky > done`)