@@ -166,6 +166,17 @@ func discoveredToListed(components component.Components, opts *Options) (ListedC
166166 listedComponents := make (ListedComponents , 0 , len (components ))
167167 errs := []error {}
168168
169+ // Ensure working directory is absolute for reliable path relativity calculations
170+ absWorkingDir := opts .WorkingDir
171+ if ! filepath .IsAbs (absWorkingDir ) {
172+ var err error
173+
174+ absWorkingDir , err = filepath .Abs (absWorkingDir )
175+ if err != nil {
176+ return nil , errors .New (err )
177+ }
178+ }
179+
169180 for _ , c := range components {
170181 if c .External () && ! opts .External {
171182 continue
@@ -188,7 +199,19 @@ func discoveredToListed(components component.Components, opts *Options) (ListedC
188199 }
189200 }
190201
191- relPath , err := filepath .Rel (opts .WorkingDir , c .Path ())
202+ // Ensure component path is absolute for reliable relativity calculation
203+ componentPath := c .Path ()
204+ if ! filepath .IsAbs (componentPath ) {
205+ var err error
206+
207+ componentPath , err = filepath .Abs (componentPath )
208+ if err != nil {
209+ errs = append (errs , errors .New (err ))
210+ continue
211+ }
212+ }
213+
214+ relPath , err := filepath .Rel (absWorkingDir , componentPath )
192215 if err != nil {
193216 errs = append (errs , errors .New (err ))
194217
@@ -210,7 +233,19 @@ func discoveredToListed(components component.Components, opts *Options) (ListedC
210233 listedCfg .Dependencies = make ([]* ListedComponent , len (c .Dependencies ()))
211234
212235 for i , dep := range c .Dependencies () {
213- relDepPath , err := filepath .Rel (opts .WorkingDir , dep .Path ())
236+ // Ensure dependency path is absolute for reliable relativity calculation
237+ depPath := dep .Path ()
238+ if ! filepath .IsAbs (depPath ) {
239+ var err error
240+
241+ depPath , err = filepath .Abs (depPath )
242+ if err != nil {
243+ errs = append (errs , errors .New (err ))
244+ continue
245+ }
246+ }
247+
248+ relDepPath , err := filepath .Rel (absWorkingDir , depPath )
214249 if err != nil {
215250 errs = append (errs , errors .New (err ))
216251
0 commit comments