Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Incorrect 'node_modules' path for the dependencies. #93

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nine-steaks-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-bin": patch
---

fix: Incorrect 'node_modules' path for the dependencies.
47 changes: 47 additions & 0 deletions pkg/node-modules/nodeModuleCollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
return nil
}

nodeModuleDir = fixNodeModuleDir(nodeModuleDir, dependency.Dependencies)

// process direct children first
queue := make([]*Dependency, maxQueueSize)
queueIndex := 0
Expand Down Expand Up @@ -255,6 +257,51 @@
}
}

func fixNodeModuleDir(nodeModuleDir string, dependencies map[string]string) string {
result := nodeModuleDir
pathList := strings.Split(nodeModuleDir, string(os.PathSeparator))

check := false
missedDeps := make([]string, 0)
for i := 0; i < len(pathList); i++ {
if check {
break
}

path := nodeModuleDir
for j := 0; j < i; j++ {
path = filepath.Join(path, "..")
}

// check if all dependencies are present
for k := range dependencies {
fileInfo, err := os.Stat(filepath.Join(path, k))
if err != nil || !fileInfo.IsDir() {
if !slices.Contains(missedDeps, k) {

Check failure on line 280 in pkg/node-modules/nodeModuleCollector.go

View workflow job for this annotation

GitHub Actions / build

undefined: slices
missedDeps = append(missedDeps, k)
}
check = false
} else {
// remove from failed deps if dependency is present
for i, v := range missedDeps {
if v == k {
missedDeps = append(missedDeps[:i], missedDeps[i+1:]...)
break
}
}
check = true
result = path
}
}
}

if (len(result) != len(nodeModuleDir)) && len(missedDeps) != 0 && log.IsDebugEnabled() {
log.Debug("fixed node_module dir", zap.String("old", nodeModuleDir), zap.String("new", result), zap.Strings("missedDeps", missedDeps))
}

return result
}

func getParentDir(file string) string {
if len(file) == 0 {
return file
Expand Down
Loading