Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the searchResult function to correctly return its type. #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ import { cosmiconfigSync } from 'cosmiconfig'
import fs from 'fs'
import { set } from 'husky'

function searchResult(): {
interface SearchResult {
hooks: { [key: string]: string }
filepath: string | undefined
} {
}

function searchResult(): SearchResult {
const explorer = cosmiconfigSync('husky')

const result = explorer.search()
if (result === null) {
throw new Error('no husky 4 config found')
throw new Error('No Husky v4 config found')
}

interface Config {
hooks?: { [key: string]: string }
}
const config = result?.config as Config
const config = result.config as Config

return {
hooks: config?.hooks || {},
filepath: result?.filepath,
filepath: result.filepath,
}
}

Expand All @@ -30,17 +32,16 @@ function showManualUpdateMessage(hooks: { [key: string]: string }) {

// Simple heuristic to check if hook needs to be manually updated
const packageManagers = ['npm', 'npx', 'yarn', 'pnpm', 'pnpx']
const otherCriterias = ['HUSKY_GIT_PARAMS', '&&', '||']
if (hooks) {
Object.entries(hooks).forEach(([name, script]) => {
if (
!packageManagers.some((s) => script.startsWith(s)) ||
otherCriterias.some((s) => script.includes(s))
) {
names.push(name)
}
})
}
const otherCriteria = ['HUSKY_GIT_PARAMS', '&&', '||']

Object.entries(hooks).forEach(([name, script]) => {
if (
!packageManagers.some((pm) => script.startsWith(pm)) ||
otherCriteria.some((crit) => script.includes(crit))
) {
names.push(name)
}
})

// Show manual update message
if (names.length > 0) {
Expand Down