Skip to content

Commit

Permalink
HUSKY_SKIP_INSTALL skip install earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Aug 17, 2019
1 parent c1367ef commit a90c641
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
19 changes: 0 additions & 19 deletions src/installer/__tests__/index.ts
Expand Up @@ -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<string[]> => del(tempDir, { force: true }))
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions src/installer/bin.ts
Expand Up @@ -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()

Expand All @@ -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}`))
Expand Down
12 changes: 0 additions & 12 deletions src/installer/index.ts
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -192,6 +182,4 @@ export function uninstall(gitDir: string, huskyDir: string): void {
// Remove hooks
const hooks = getHooks(gitDir)
removeHooks(hooks)

console.log('husky > Done')
}

0 comments on commit a90c641

Please sign in to comment.