refactor: improve progress bar logic and update display (#14)

* fix: Revise progress tracking mechanism

* chore: remove unused getDependencies func

* chore: removed unused property & add fetcher check

* Update pkg/wrapper/npm_base.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com>

* refactor: make SetProgressTracker common for all fetchers

---------

Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Sahil Bansal
2025-05-06 16:35:59 +05:30
committed by GitHub
co-authored by Copilot
parent df754ccc82
commit 6a28fb16a1
3 changed files with 31 additions and 15 deletions
+12
View File
@@ -5,9 +5,11 @@ import (
"encoding/json"
"fmt"
"sync"
"sync/atomic"
"time"
"github.com/safedep/dry/log"
"github.com/safedep/pmg/internal/ui"
"github.com/safedep/pmg/pkg/common/utils"
"github.com/safedep/pmg/pkg/models"
)
@@ -17,6 +19,14 @@ type NpmFetcher struct {
*BaseFetcher
}
func (nf *NpmFetcher) incrementProgress() {
if nf.progressTracker != nil {
atomic.AddInt32(&nf.fetchedDeps, 1)
// Update progress message to show number of packages fetched
ui.SetPinnedMessageOnProgressWriter(fmt.Sprintf("Fetched %d packages", atomic.LoadInt32(&nf.fetchedDeps)))
}
}
// NewNpmFetcher creates a new NPM registry fetcher
func NewNpmFetcher(timeout time.Duration) *NpmFetcher {
client := NewHttpRegistryClient(
@@ -92,6 +102,8 @@ func (nf *NpmFetcher) fetchDependenciesConcurrent(ctx context.Context, pkg model
return nil, fmt.Errorf("failed to fetch package info for %s: %w", pkg.Name, err)
}
nf.incrementProgress()
dependencies := packageInfo.Dependencies
node := &models.DependencyNode{
Name: pkg.Name,