diff --git a/pkg/client/client.go b/pkg/client/client.go index f2f0bbd4..e8b8285d 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -632,8 +632,11 @@ func (c *KpmClient) AddDepWithOpts(kclPkg *pkg.KclPkg, opt *opt.AddOptions) (*pk // 3. update the kcl.mod and kcl.mod.lock. if opt.NewPkgName != "" { - d.ChangePkgName(opt.NewPkgName) + tempDeps := kclPkg.ModFile.Dependencies.Deps[d.Name] + tempDeps.Name = opt.NewPkgName + kclPkg.ModFile.Dependencies.Deps[d.Name] = tempDeps } + err = kclPkg.UpdateModAndLockFile() if err != nil { return nil, err diff --git a/pkg/package/modfile.go b/pkg/package/modfile.go index 9f5b1c23..38946a04 100644 --- a/pkg/package/modfile.go +++ b/pkg/package/modfile.go @@ -266,10 +266,6 @@ func (dep *Dependency) GetDownloadPath() string { return "" } -func (dep *Dependency) ChangePkgName(NewPkgName string) { - dep.Name = NewPkgName -} - func GenSource(sourceType string, uri string, tagName string) (Source, error) { source := Source{} if sourceType == GIT {