Skip to content

Commit

Permalink
fix: default to root when module-dirs is not set (#1675)
Browse files Browse the repository at this point in the history
Fixes #1668

Note that this isn't usable in the `ftl` repo itself because
`go-runtime/scaffolding/{{ .Name | camel | lower }}/ftl.toml` confuses
the walker, so we do need to specify `examples/go` in our own
`ftl-project.toml`. However, the change does WAI in normal repositories
that don't have module templates.
  • Loading branch information
deniseli authored Jun 6, 2024
1 parent 1b38c7b commit 48839a4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/ftl/cmd_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type buildCmd struct {
func (b *buildCmd) Run(ctx context.Context, projConfig projectconfig.Config) error {
client := rpc.ClientFromContext[ftlv1connect.ControllerServiceClient](ctx)
if len(b.Dirs) == 0 && len(b.External) == 0 {
b.Dirs = projConfig.ModuleDirs
b.Dirs = projConfig.ModuleDirsOrDefault()
b.External = projConfig.ExternalDirs
}
if len(b.Dirs) == 0 && len(b.External) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ftl/cmd_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type devCmd struct {

func (d *devCmd) Run(ctx context.Context, projConfig projectconfig.Config) error {
if len(d.Dirs) == 0 && len(d.External) == 0 {
d.Dirs = projConfig.ModuleDirs
d.Dirs = projConfig.ModuleDirsOrDefault()
d.External = projConfig.ExternalDirs
}
if len(d.Dirs) == 0 && len(d.External) == 0 {
Expand Down
11 changes: 11 additions & 0 deletions common/projectconfig/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ func TestCmdsCreateProjectTomlFilesIfNonexistent(t *testing.T) {
err = os.Remove(configPath)
assert.NoError(t, err)
}

func TestDefaultToRootWhenModuleDirsMissing(t *testing.T) {
in.Run(t, "no-module-dirs-ftl-project.toml",
in.CopyModule("echo"),
in.Exec("ftl", "build"), // Needs to be `ftl build`, not `ftl build echo`
in.Deploy("echo"),
in.Call("echo", "echo", in.Obj{"name": "Bob"}, func(t testing.TB, response in.Obj) {
assert.Equal(t, "Hello, Bob!", response["message"])
}),
)
}
9 changes: 9 additions & 0 deletions common/projectconfig/projectconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ type Config struct {
FTLMinVersion string `toml:"ftl-min-version"`
}

// ModuleDirsOrDefault returns the module-dirs field from the ftl-project.toml, unless
// that is not defined, in which case it defaults to the root directory.
func (c Config) ModuleDirsOrDefault() []string {
if len(c.ModuleDirs) > 0 {
return c.ModuleDirs
}
return []string{"."}
}

// ConfigPaths returns the computed list of configuration paths to load.
func ConfigPaths(input []string) []string {
if len(input) > 0 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[commands]
startup = ["echo 'Executing global pre-build command'"]

0 comments on commit 48839a4

Please sign in to comment.