Skip to content

Commit

Permalink
feat: locked dependencies filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Icaruk committed Feb 21, 2024
1 parent eb2e372 commit 6b74979
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions pkg/updater/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func readDependencies(
isDev bool,
bar *progressbar.ProgressBar,
filter string,
) {
) (lockedDependencyCount int) {

var wg sync.WaitGroup
semaphoreChan := make(chan struct{}, concurrencyLimit)
Expand Down Expand Up @@ -265,6 +265,12 @@ func readDependencies(
continue
}

if versionPrefix == "" {
fmt.Printf(" is locked to version %s, skipping...", cleanCurrentVersion)
lockedDependencyCount++
continue
}

wg.Add(1)

go func(dependency string, currentVersion string) {
Expand Down Expand Up @@ -343,7 +349,7 @@ func readDependencies(
// Wait for all goroutines to complete
wg.Wait()
close(doneChan)

return lockedDependencyCount
}

func Init(cfg npm.CmdFlags) {
Expand All @@ -367,11 +373,14 @@ func Init(cfg npm.CmdFlags) {
bar := initProgressBar(totalDependencyCount)

// Process dependencies
readDependencies(dependencies, versionComparison, false, bar, cfg.Filter)
var lockedDependencyCount int
var lockedDevDependencyCount int

lockedDependencyCount = readDependencies(dependencies, versionComparison, false, bar, cfg.Filter)

// Process devDependencies
if !cfg.NoDev {
readDependencies(devDependencies, versionComparison, true, bar, cfg.Filter)
lockedDevDependencyCount = readDependencies(devDependencies, versionComparison, true, bar, cfg.Filter)
}

// Count total dependencies and filtered dependencies
Expand Down Expand Up @@ -401,6 +410,12 @@ func Init(cfg npm.CmdFlags) {
fmt.Println("Filtered", aurora.Blue(filteredDependencyCount), "dependencies from a total of", aurora.Blue(totalDependencyCount))
} else {
fmt.Println("Total dependencies: ", aurora.Cyan(filteredDependencyCount))

totalLockedDependencyCount := lockedDependencyCount + lockedDevDependencyCount
if totalLockedDependencyCount > 0 {
s := fmt.Sprintf("Locked dependencies: %d", totalLockedDependencyCount)
fmt.Println(aurora.Faint(s))
}
}

printSummary(totalCount, majorCount, minorCount, patchCount)
Expand All @@ -422,28 +437,6 @@ func Init(cfg npm.CmdFlags) {

for {

if value.VersionPrefix == "" {
isDevDependencyText := ""
if value.IsDev {
isDevDependencyText = aurora.Sprintf(
aurora.Magenta(" (devDependency)"),
)
}

message := aurora.Sprintf(
aurora.Yellow("Upgrade ignored because package \"%s\"%s is locked to version %s"),
key,
isDevDependencyText,
value.Current,
)

fmt.Println(message)

updateProgressCount++
break

}

response := cli.PromptUpdateDependency(
key,
value.Current,
Expand Down

0 comments on commit 6b74979

Please sign in to comment.