Skip to content

Commit a90c641

Browse files
committed
HUSKY_SKIP_INSTALL skip install earlier
1 parent c1367ef commit a90c641

3 files changed

Lines changed: 14 additions & 31 deletions

File tree

src/installer/__tests__/index.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ function expectHookToExist(filename: string): void {
7575
describe('install', (): void => {
7676
beforeEach((): void => {
7777
delete process.env.INIT_CWD
78-
delete process.env.HUSKY_SKIP_INSTALL
7978
tempDir = tempy.directory()
8079
})
8180
afterEach((): Promise<string[]> => del(tempDir, { force: true }))
@@ -303,24 +302,6 @@ describe('install', (): void => {
303302
expect(hook).toMatch(huskyIdentifier)
304303
})
305304

306-
it('should not install hooks if HUSKY_SKIP_INSTALL=1', (): void => {
307-
mkdir(defaultGitDir, defaultHuskyDir)
308-
writeFile('package.json', pkg)
309-
310-
process.env.HUSKY_SKIP_INSTALL = '1'
311-
install()
312-
expect(exists(defaultHookFilename)).toBeFalsy()
313-
})
314-
315-
it('should not install hooks if HUSKY_SKIP_INSTALL=true', (): void => {
316-
mkdir(defaultGitDir, defaultHuskyDir)
317-
writeFile('package.json', pkg)
318-
319-
process.env.HUSKY_SKIP_INSTALL = 'true'
320-
install()
321-
expect(exists(defaultHookFilename)).toBeFalsy()
322-
})
323-
324305
it('should not install hooks in CI server', (): void => {
325306
mkdir(defaultGitHooksDir, defaultHuskyDir)
326307
writeFile('package.json', pkg)

src/installer/bin.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ try {
2121
action === 'install' ? 'Setting up' : 'Uninstalling'
2222
)
2323

24+
// Skip install if HUSKY_SKIP_INSTALL=1
25+
if (
26+
action === 'install' &&
27+
['1', 'true'].includes(process.env.HUSKY_SKIP_INSTALL || '')
28+
) {
29+
console.log(
30+
"HUSKY_SKIP_INSTALL environment variable is set to 'true',",
31+
'skipping Git hooks installation.'
32+
)
33+
process.exit(0)
34+
}
35+
2436
// Get top level and git dir
2537
const { topLevel, absoluteGitDir } = gitRevParse()
2638

@@ -34,6 +46,8 @@ try {
3446
} else {
3547
uninstall(absoluteGitDir, huskyDir)
3648
}
49+
50+
console.log(`husky > Done`)
3751
} catch (error) {
3852
console.log(chalk.red(error.message.trim()))
3953
console.log(chalk.red(`husky > Failed to ${action}`))

src/installer/index.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,6 @@ export function install(
141141
const conf = getConf(userPkgDir)
142142

143143
// Checks
144-
if (['1', 'true'].includes(process.env.HUSKY_SKIP_INSTALL || '')) {
145-
console.log(
146-
"HUSKY_SKIP_INSTALL environment variable is set to 'true',",
147-
'skipping Git hooks installation.'
148-
)
149-
return
150-
}
151-
152144
if (isCI && conf.skipCI) {
153145
console.log('CI detected, skipping Git hooks installation.')
154146
return
@@ -170,8 +162,6 @@ export function install(
170162
const hooks = getHooks(gitDir)
171163
const script = getScript(topLevel, huskyDir, requireRunNodePath)
172164
createHooks(hooks, script)
173-
174-
console.log(`husky > Done`)
175165
}
176166

177167
export function uninstall(gitDir: string, huskyDir: string): void {
@@ -192,6 +182,4 @@ export function uninstall(gitDir: string, huskyDir: string): void {
192182
// Remove hooks
193183
const hooks = getHooks(gitDir)
194184
removeHooks(hooks)
195-
196-
console.log('husky > Done')
197185
}

0 commit comments

Comments
 (0)