Skip to content

Commit

Permalink
Use isGitIgnored to exclude candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
illright committed Dec 19, 2024
1 parent bcee534 commit bb407b5
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readdir } from 'node:fs/promises'
import { parse, relative, sep, join } from 'node:path'
import pc from 'picocolors'
import { isGitIgnored } from 'globby'

import { distance } from 'fastest-levenshtein'
import { isCancel, outro, select, confirm } from '@clack/prompts'
Expand All @@ -9,8 +10,7 @@ import { ExitException } from './exit-exception'

/** The maximum Levenshtein distance between the input and the reference for the input to be considered a typo. */
const typoThreshold = 5
/** Patterns for folder names that are never suggested. */
const nonCandidates = [/^node_modules$/, /^dist$/, /^\./]
const isIgnored = await isGitIgnored()

/** Present the user with a choice of folders based on similarity to a given input. */
export async function chooseFromSimilar(input: string): Promise<string> {
Expand All @@ -19,7 +19,7 @@ export async function chooseFromSimilar(input: string): Promise<string> {
const existingDir = await resolveWithCorrections(dir || '.')

const candidates = (await readdir(existingDir, { withFileTypes: true }))
.filter((entry) => entry.isDirectory() && nonCandidates.every((pattern) => !pattern.test(entry.name)))
.filter((entry) => entry.isDirectory() && !isIgnored(join(existingDir, entry.name)))
.map((entry) => entry.name)
const withDistances = candidates.map((candidate) => [candidate, distance(candidate, base)] as const)
const suggestions = withDistances
Expand Down

0 comments on commit bb407b5

Please sign in to comment.