Skip to content

Commit

Permalink
Filter out yarn.lock files when displaying diffs (#18)
Browse files Browse the repository at this point in the history
We have a few spurious historic diffs in yarn.lock
due to the changes in the way lockfile seeding
works in create-app. These diffs are never
relevant for upgraders - they're not expected to
update their yarn.lock file in response to seed
changes. With that in mind, it makes sense to
always filter out any changes in yarn.lock in the
diff.

Co-authored-by: Vincenzo Scamporlino <[email protected]>
  • Loading branch information
mtlewis and vinzscam authored Oct 21, 2024
1 parent dfa92ad commit 35505c4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/hooks/fetch-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { useSettings } from '../SettingsProvider'

const delay = ms => new Promise(res => setTimeout(res, ms))

const movePackageJsonToTop = parsedDiff =>
parsedDiff.sort(({ newPath }) => (newPath.includes('package.json') ? -1 : 1))
const excludeYarnLock = ({ oldPath, newPath, ...rest }) =>
!(oldPath.includes('yarn.lock') || newPath.includes('yarn.lock'))

const packageJsonFirst = ({ newPath }) =>
newPath.includes('package.json') ? -1 : 1

export const useFetchDiff = ({
shouldShowDiff,
Expand Down Expand Up @@ -42,7 +45,11 @@ export const useFetchDiff = ({

const diff = await response.text()

setDiff(movePackageJsonToTop(parseDiff(diff)))
setDiff(
parseDiff(diff)
.filter(excludeYarnLock)
.sort(packageJsonFirst)
)

setIsLoading(false)
setIsDone(true)
Expand Down

0 comments on commit 35505c4

Please sign in to comment.