Skip to content

Commit

Permalink
Refactor handling of import paths in ProcessImportSection
Browse files Browse the repository at this point in the history
  • Loading branch information
milldr committed Dec 27, 2024
1 parent 362e979 commit 8d76059
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/exec/stack_processor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1744,10 +1744,10 @@ func FindComponentDependenciesLegacy(
}

// ProcessImportSection processes the `import` section in stack manifests
// The `import` section` can be of the following types:
// 1. list of `StackImport` structs
// 2. list of strings
// 3. List of strings and `StackImport` structs in the same file
// The `import` section can contain:
// 1. Project-relative paths (e.g. "mixins/region/us-east-2")
// 2. Paths relative to the current file (starting with "./" or "../")
// 3. StackImport structs containing either of the above path types
func ProcessImportSection(stackMap map[string]any, filePath string) ([]schema.StackImport, error) {
stackImports, ok := stackMap[cfg.ImportSectionName]

Expand All @@ -1773,7 +1773,7 @@ func ProcessImportSection(stackMap map[string]any, filePath string) ([]schema.St
var importObj schema.StackImport
err := mapstructure.Decode(imp, &importObj)
if err == nil {
// Handle relative paths in StackImport.Path
// Handle paths relative to current file (starting with ./ or ../)
if strings.HasPrefix(importObj.Path, "./") || strings.HasPrefix(importObj.Path, "../") {
// Get the directory of the current file
baseDir := filepath.Dir(filePath)
Expand All @@ -1795,7 +1795,7 @@ func ProcessImportSection(stackMap map[string]any, filePath string) ([]schema.St
return nil, fmt.Errorf("invalid empty import in the file '%s'", filePath)
}

// Handle relative paths in string imports
// Handle paths relative to current file (starting with ./ or ../)
if strings.HasPrefix(s, "./") || strings.HasPrefix(s, "../") {
baseDir := filepath.Dir(filePath)
s = filepath.Join(baseDir, s)
Expand Down

0 comments on commit 8d76059

Please sign in to comment.