diff --git a/pkg/client/client.go b/pkg/client/client.go index 16efbd07..57994f9d 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -946,26 +946,6 @@ func (c *KpmClient) Download(dep *pkg.Dependency, homePath, localPath string) (* return dep, nil } -func (c *KpmClient) ValidateDependency(dep *pkg.Dependency) error { - if ok, err := features.Enabled(features.SupportModCheck); err == nil && ok { - tmpKclPkg := pkg.KclPkg{ - HomePath: dep.LocalFullPath, - Dependencies: pkg.Dependencies{Deps: func() *orderedmap.OrderedMap[string, pkg.Dependency] { - m := orderedmap.NewOrderedMap[string, pkg.Dependency]() - m.Set(dep.Name, *dep) - return m - }()}, - NoSumCheck: c.GetNoSumCheck(), - } - - if err := c.ModChecker.Check(tmpKclPkg); err != nil { - return reporter.NewErrorEvent(reporter.InvalidKclPkg, err, fmt.Sprintf("%s package does not match the original kcl package", dep.FullName)) - } - } - - return nil -} - // DownloadFromGit will download the dependency from the git repository. func (c *KpmClient) DownloadFromGit(dep *downloader.Git, localPath string) (string, error) { var msg string diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 40409a19..6d082329 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -2287,6 +2287,7 @@ func TestValidateDependency(t *testing.T) { }, } err = kpmcli.ValidateDependency(&dep1) + fmt.Printf("err: %v\n", err) assert.Equal(t, err, nil) dep2 := pkg.Dependency{ diff --git a/pkg/client/deperated.go b/pkg/client/deperated.go index 20b4ba26..0265ee9e 100644 --- a/pkg/client/deperated.go +++ b/pkg/client/deperated.go @@ -6,8 +6,10 @@ import ( "os" "path/filepath" + "github.com/elliotchance/orderedmap/v2" "kcl-lang.io/kcl-go/pkg/kcl" "kcl-lang.io/kpm/pkg/downloader" + "kcl-lang.io/kpm/pkg/features" "kcl-lang.io/kpm/pkg/git" "kcl-lang.io/kpm/pkg/oci" "kcl-lang.io/kpm/pkg/opt" @@ -16,6 +18,33 @@ import ( "kcl-lang.io/kpm/pkg/utils" ) +// Deprecated: ValidateDependency is deprecated, use `Check` replaced. +func (c *KpmClient) ValidateDependency(dep *pkg.Dependency) error { + if ok, err := features.Enabled(features.SupportModCheck); err == nil && ok { + tmpKclPkg := pkg.KclPkg{ + ModFile: pkg.ModFile{ + Pkg: pkg.Package{ + Name: dep.Name, + Version: dep.Version, + }, + }, + HomePath: dep.LocalFullPath, + Dependencies: pkg.Dependencies{Deps: func() *orderedmap.OrderedMap[string, pkg.Dependency] { + m := orderedmap.NewOrderedMap[string, pkg.Dependency]() + m.Set(dep.Name, *dep) + return m + }()}, + NoSumCheck: c.GetNoSumCheck(), + } + + if err := c.ModChecker.Check(tmpKclPkg); err != nil { + return reporter.NewErrorEvent(reporter.InvalidKclPkg, err, fmt.Sprintf("%s package does not match the original kcl package", dep.FullName)) + } + } + + return nil +} + // CompileWithOpts will compile the kcl program with the compile options. // Deprecated: Use `Run` instead. func (c *KpmClient) CompileWithOpts(opts *opt.CompileOptions) (*kcl.KCLResultList, error) {