Skip to content

Commit

Permalink
refactor: extract module sorting comparator as lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
vvagaytsev committed Aug 18, 2023
1 parent 2579645 commit e00ba0b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/src/util/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export function detectModuleOverlap({
// Don't consider overlap between disabled modules, or where one of the modules is disabled
const enabledModules = moduleConfigs.filter((m) => !m.disabled)

const moduleNameComparator = (a, b) => (a.name > b.name ? 1 : -1)

const findModulePathOverlaps: ModuleOverlapFinder = (config: ModuleConfig) => {
if (!!config.include || !!config.exclude) {
return []
Expand All @@ -103,7 +105,7 @@ export function detectModuleOverlap({
pathIsInside(compare.path, config.path) &&
!(config.path === projectRoot && pathIsInside(compare.path, gardenDirPath))
)
.sort((a, b) => (a.name > b.name ? 1 : -1))
.sort(moduleNameComparator)
}

const findGenerateFilesOverlaps: ModuleOverlapFinder = (config: ModuleConfig) => {
Expand All @@ -126,7 +128,7 @@ export function detectModuleOverlap({
const overlappingTargetPaths = intersection(targetPaths, compareTargetPaths)
return overlappingTargetPaths.length > 0
}
return enabledModules.filter(targetPathsOverlap).sort((a, b) => (a.name > b.name ? 1 : -1))
return enabledModules.filter(targetPathsOverlap).sort(moduleNameComparator)
}

const moduleOverlapFinders: ModuleOverlapFinder[] = [findModulePathOverlaps, findGenerateFilesOverlaps]
Expand Down

0 comments on commit e00ba0b

Please sign in to comment.