Skip to content

Commit b1d4c32

Browse files
authored
Don't throw error during uninstall if file doesn't exist (#708)
1 parent 4e1d440 commit b1d4c32

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/installer/__tests__/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,14 @@ describe('install', (): void => {
236236
expectHookToExist('.git/hooks/pre-commit')
237237
})
238238

239+
it('should not throw error during uninstall if some files do not exist', (): void => {
240+
writeFile('package.json', pkg)
241+
242+
install()
243+
fs.unlinkSync(path.join(tempDir, '.git/hooks/pre-commit'))
244+
fs.unlinkSync(path.join(tempDir, '.git/hooks/husky.sh'))
245+
246+
expect(uninstall).not.toThrow()
247+
})
239248
hooksManagers.forEach(testMigration)
240249
})

src/installer/localScript.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ export function createLocalScript(
2626
}
2727

2828
export function removeLocalScript(gitHooksDir: string): void {
29-
fs.unlinkSync(path.join(gitHooksDir, 'husky.local.sh'))
29+
const filename = path.join(gitHooksDir, 'husky.local.sh')
30+
if (fs.existsSync(filename)) {
31+
fs.unlinkSync(filename)
32+
}
3033
}

src/installer/mainScript.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ export function createMainScript(gitHooksDir: string): void {
1818
}
1919

2020
export function removeMainScript(gitHooksDir: string): void {
21-
fs.unlinkSync(path.join(gitHooksDir, 'husky.sh'))
21+
const filename = path.join(gitHooksDir, 'husky.sh')
22+
if (fs.existsSync(filename)) {
23+
fs.unlinkSync(filename)
24+
}
2225
}

0 commit comments

Comments
 (0)