@@ -59,40 +59,41 @@ func FindPackageByModSpec(root string, modSpec *ModSpec) (string, error) {
59
59
if err != nil {
60
60
return err
61
61
}
62
- if info .IsDir () {
63
- kclModPath := filepath .Join (path , constants .KCL_MOD )
64
- if _ , err := os .Stat (kclModPath ); err == nil {
65
- // If the package name and version are specified,
66
- // we can directly check if the kcl.mod file matches the package.
67
- if matchesPackageSpec (kclModPath , modSpec ) {
68
- result = path
69
- return filepath .SkipAll
70
- } else if modSpec .Version == "" {
71
- // If the package name specified, but version are not specified,
72
- if utils .MatchesPackageName (kclModPath , modSpec .Name ) {
73
- // load the version from the kcl.mod file
74
- tmpSpec , err := loadModSpecFromKclMod (kclModPath )
75
- if err != nil {
76
- return err
77
- }
78
- // Remember the local path with the highest version
79
- tmpVer , err := version .NewSemver (tmpSpec .Version )
62
+ if ! info .IsDir () {
63
+ return nil
64
+ }
65
+ kclModPath := filepath .Join (path , constants .KCL_MOD )
66
+ if _ , err := os .Stat (kclModPath ); err == nil {
67
+ // If the package name and version are specified,
68
+ // we can directly check if the kcl.mod file matches the package.
69
+ if matchesPackageSpec (kclModPath , modSpec ) {
70
+ result = path
71
+ return filepath .SkipAll
72
+ } else if modSpec .Version == "" {
73
+ // If the package name specified, but version are not specified,
74
+ if utils .MatchesPackageName (kclModPath , modSpec .Name ) {
75
+ // load the version from the kcl.mod file
76
+ tmpSpec , err := loadModSpecFromKclMod (kclModPath )
77
+ if err != nil {
78
+ return err
79
+ }
80
+ // Remember the local path with the highest version
81
+ tmpVer , err := version .NewSemver (tmpSpec .Version )
82
+ if err != nil {
83
+ return err
84
+ }
85
+ if modVersion != "" {
86
+ modVer , err := version .NewSemver (modVersion )
80
87
if err != nil {
81
88
return err
82
89
}
83
- if modVersion != "" {
84
- modVer , err := version .NewSemver (modVersion )
85
- if err != nil {
86
- return err
87
- }
88
- if tmpVer .GreaterThan (modVer ) {
89
- modVersion = tmpSpec .Version
90
- result = path
91
- }
92
- } else {
90
+ if tmpVer .GreaterThan (modVer ) {
93
91
modVersion = tmpSpec .Version
94
92
result = path
95
93
}
94
+ } else {
95
+ modVersion = tmpSpec .Version
96
+ result = path
96
97
}
97
98
}
98
99
}
0 commit comments