Skip to content

Commit a0fa893

Browse files
committed
feat: add single module folder with kcl mod file with entries config
Signed-off-by: peefy <xpf6677@163.com>
1 parent bf93d5f commit a0fa893

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pkg/options/run.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/acarl005/stripansi"
1313
"github.com/pkg/errors"
14+
"kcl-lang.io/cli/pkg/fs"
1415
"kcl-lang.io/kcl-go/pkg/kcl"
1516
"kcl-lang.io/kpm/pkg/api"
1617
"kcl-lang.io/kpm/pkg/client"
@@ -88,7 +89,7 @@ func (o *RunOptions) Run() error {
8889
}
8990
if entry.IsEmpty() {
9091
// kcl compiles the current package under '$pwd'.
91-
if _, found := api.GetKclPackage(pwd); found == nil {
92+
if _, e := api.GetKclPackage(pwd); e == nil {
9293
opts.SetPkgPath(pwd)
9394
result, err = cli.CompileWithOpts(opts)
9495
} else {
@@ -112,8 +113,18 @@ func (o *RunOptions) Run() error {
112113
}
113114
transformedEntries = append(transformedEntries, entry)
114115
}
115-
opts.SetEntries(transformedEntries)
116-
opts.SetPkgPath(entry.PackageSource())
116+
// Maybe a single KCL module folder, use the kcl.mod entry profile to run.
117+
if pkg, e := api.GetKclPackage(transformedEntries[0]); e == nil && fs.IsDir(transformedEntries[0]) {
118+
entries := pkg.GetPkgProfile().Entries
119+
if len(entries) > 0 {
120+
opts.SetEntries(entries)
121+
}
122+
opts.SetPkgPath(transformedEntries[0])
123+
} else {
124+
// Multiple entries with the kcl.mod file and deps.
125+
opts.SetEntries(transformedEntries)
126+
opts.SetPkgPath(entry.PackageSource())
127+
}
117128
result, err = cli.CompileWithOpts(opts)
118129
} else if entry.IsTar() {
119130
// kcl compiles the package from the kcl package tar.

0 commit comments

Comments
 (0)