@@ -429,68 +429,48 @@ func (l *loader) absDirFromImportPath1(pos token.Pos, p importPath) (absDir stri
429
429
if isStdlibPackage (string (p )) {
430
430
return "" , "" , fmt .Errorf ("standard library import path %q cannot be imported as a CUE package" , p )
431
431
}
432
+ if l .pkgs == nil {
433
+ return "" , "" , fmt .Errorf ("imports are unavailable because there is no cue.mod/module.cue file" )
434
+ }
432
435
// Extract the package name.
433
436
parts := module .ParseImportPath (string (p ))
434
437
unqualified := parts .Unqualified ().String ()
435
- if l .cfg .Registry != nil {
436
- if l .pkgs == nil {
437
- return "" , "" , fmt .Errorf ("imports are unavailable because there is no cue.mod/module.cue file" )
438
- }
439
- // TODO predicate registry-aware lookup on module.cue-declared CUE version?
440
-
441
- // Note: use the canonical form of the import path because
442
- // that's the form passed to [modpkgload.LoadPackages]
443
- // and hence it's available by that name via Pkg.
444
- pkg := l .pkgs .Pkg (parts .Canonical ().String ())
445
- // TODO(mvdan): using "unqualified" for the errors below doesn't seem right,
446
- // should we not be using either the original path or the canonical path?
447
- // The unqualified import path should only be used for filepath.FromSlash further below.
448
- if pkg == nil {
449
- return "" , "" , fmt .Errorf ("no dependency found for package %q" , unqualified )
438
+ // TODO predicate registry-aware lookup on module.cue-declared CUE version?
439
+
440
+ // Note: use the canonical form of the import path because
441
+ // that's the form passed to [modpkgload.LoadPackages]
442
+ // and hence it's available by that name via Pkg.
443
+ pkg := l .pkgs .Pkg (parts .Canonical ().String ())
444
+ // TODO(mvdan): using "unqualified" for the errors below doesn't seem right,
445
+ // should we not be using either the original path or the canonical path?
446
+ // The unqualified import path should only be used for filepath.FromSlash further below.
447
+ if pkg == nil {
448
+ return "" , "" , fmt .Errorf ("no dependency found for package %q" , unqualified )
449
+ }
450
+ if err := pkg .Error (); err != nil {
451
+ return "" , "" , fmt .Errorf ("cannot find package %q: %v" , unqualified , err )
452
+ }
453
+ if mv := pkg .Mod (); mv .IsLocal () {
454
+ // It's a local package that's present inside one or both of the gen, usr or pkg
455
+ // directories. Even though modpkgload tells us exactly what those directories
456
+ // are, the rest of the cue/load logic expects only a single directory for now,
457
+ // so just use that.
458
+ absDir = filepath .Join (GenPath (l .cfg .ModuleRoot ), parts .Path )
459
+ } else {
460
+ locs := pkg .Locations ()
461
+ if len (locs ) > 1 {
462
+ return "" , "" , fmt .Errorf ("package %q unexpectedly found in multiple locations" , unqualified )
450
463
}
451
- if err := pkg . Error (); err != nil {
452
- return "" , "" , fmt .Errorf ("cannot find package %q: %v " , unqualified , err )
464
+ if len ( locs ) == 0 {
465
+ return "" , "" , fmt .Errorf ("no location found for package %q" , unqualified )
453
466
}
454
- if mv := pkg .Mod (); mv .IsLocal () {
455
- // It's a local package that's present inside one or both of the gen, usr or pkg
456
- // directories. Even though modpkgload tells us exactly what those directories
457
- // are, the rest of the cue/load logic expects only a single directory for now,
458
- // so just use that.
459
- absDir = filepath .Join (GenPath (l .cfg .ModuleRoot ), parts .Path )
460
- } else {
461
- locs := pkg .Locations ()
462
- if len (locs ) > 1 {
463
- return "" , "" , fmt .Errorf ("package %q unexpectedly found in multiple locations" , unqualified )
464
- }
465
- if len (locs ) == 0 {
466
- return "" , "" , fmt .Errorf ("no location found for package %q" , unqualified )
467
- }
468
- var err error
469
- absDir , err = absPathForSourceLoc (locs [0 ])
470
- if err != nil {
471
- return "" , "" , fmt .Errorf ("cannot determine source directory for package %q: %v" , unqualified , err )
472
- }
467
+ var err error
468
+ absDir , err = absPathForSourceLoc (locs [0 ])
469
+ if err != nil {
470
+ return "" , "" , fmt .Errorf ("cannot determine source directory for package %q: %v" , unqualified , err )
473
471
}
474
- return absDir , pkg .Mod ().Path (), nil
475
- }
476
-
477
- // Determine the directory without using the registry.
478
-
479
- sub := filepath .FromSlash (unqualified )
480
- switch hasPrefix := strings .HasPrefix (unqualified , l .cfg .Module ); {
481
- case hasPrefix && len (sub ) == len (l .cfg .Module ):
482
- modPath = l .cfg .Module
483
- absDir = l .cfg .ModuleRoot
484
-
485
- case hasPrefix && unqualified [len (l .cfg .Module )] == '/' :
486
- modPath = l .cfg .Module
487
- absDir = filepath .Join (l .cfg .ModuleRoot , sub [len (l .cfg .Module )+ 1 :])
488
-
489
- default :
490
- modPath = "local"
491
- absDir = filepath .Join (GenPath (l .cfg .ModuleRoot ), sub )
492
472
}
493
- return absDir , modPath , err
473
+ return absDir , pkg . Mod (). Path (), nil
494
474
}
495
475
496
476
func absPathForSourceLoc (loc module.SourceLoc ) (string , error ) {
0 commit comments