From a90c64160af4f811ed929837c9fcfe0bf9a4160e Mon Sep 17 00:00:00 2001 From: typicode Date: Sat, 17 Aug 2019 15:18:48 +0200 Subject: [PATCH] HUSKY_SKIP_INSTALL skip install earlier --- src/installer/__tests__/index.ts | 19 ------------------- src/installer/bin.ts | 14 ++++++++++++++ src/installer/index.ts | 12 ------------ 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/src/installer/__tests__/index.ts b/src/installer/__tests__/index.ts index 106307909..e5866fe53 100644 --- a/src/installer/__tests__/index.ts +++ b/src/installer/__tests__/index.ts @@ -75,7 +75,6 @@ function expectHookToExist(filename: string): void { describe('install', (): void => { beforeEach((): void => { delete process.env.INIT_CWD - delete process.env.HUSKY_SKIP_INSTALL tempDir = tempy.directory() }) afterEach((): Promise => del(tempDir, { force: true })) @@ -303,24 +302,6 @@ describe('install', (): void => { expect(hook).toMatch(huskyIdentifier) }) - it('should not install hooks if HUSKY_SKIP_INSTALL=1', (): void => { - mkdir(defaultGitDir, defaultHuskyDir) - writeFile('package.json', pkg) - - process.env.HUSKY_SKIP_INSTALL = '1' - install() - expect(exists(defaultHookFilename)).toBeFalsy() - }) - - it('should not install hooks if HUSKY_SKIP_INSTALL=true', (): void => { - mkdir(defaultGitDir, defaultHuskyDir) - writeFile('package.json', pkg) - - process.env.HUSKY_SKIP_INSTALL = 'true' - install() - expect(exists(defaultHookFilename)).toBeFalsy() - }) - it('should not install hooks in CI server', (): void => { mkdir(defaultGitHooksDir, defaultHuskyDir) writeFile('package.json', pkg) diff --git a/src/installer/bin.ts b/src/installer/bin.ts index d0da0092d..8e599dac2 100644 --- a/src/installer/bin.ts +++ b/src/installer/bin.ts @@ -21,6 +21,18 @@ try { action === 'install' ? 'Setting up' : 'Uninstalling' ) + // Skip install if HUSKY_SKIP_INSTALL=1 + if ( + action === 'install' && + ['1', 'true'].includes(process.env.HUSKY_SKIP_INSTALL || '') + ) { + console.log( + "HUSKY_SKIP_INSTALL environment variable is set to 'true',", + 'skipping Git hooks installation.' + ) + process.exit(0) + } + // Get top level and git dir const { topLevel, absoluteGitDir } = gitRevParse() @@ -34,6 +46,8 @@ try { } else { uninstall(absoluteGitDir, huskyDir) } + + console.log(`husky > Done`) } catch (error) { console.log(chalk.red(error.message.trim())) console.log(chalk.red(`husky > Failed to ${action}`)) diff --git a/src/installer/index.ts b/src/installer/index.ts index da50da542..19fb78ae6 100644 --- a/src/installer/index.ts +++ b/src/installer/index.ts @@ -141,14 +141,6 @@ export function install( const conf = getConf(userPkgDir) // Checks - if (['1', 'true'].includes(process.env.HUSKY_SKIP_INSTALL || '')) { - console.log( - "HUSKY_SKIP_INSTALL environment variable is set to 'true',", - 'skipping Git hooks installation.' - ) - return - } - if (isCI && conf.skipCI) { console.log('CI detected, skipping Git hooks installation.') return @@ -170,8 +162,6 @@ export function install( const hooks = getHooks(gitDir) const script = getScript(topLevel, huskyDir, requireRunNodePath) createHooks(hooks, script) - - console.log(`husky > Done`) } export function uninstall(gitDir: string, huskyDir: string): void { @@ -192,6 +182,4 @@ export function uninstall(gitDir: string, huskyDir: string): void { // Remove hooks const hooks = getHooks(gitDir) removeHooks(hooks) - - console.log('husky > Done') }