diff --git a/cmd/ftl/cmd_build.go b/cmd/ftl/cmd_build.go index e50415e198..01f5857fc2 100644 --- a/cmd/ftl/cmd_build.go +++ b/cmd/ftl/cmd_build.go @@ -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 { diff --git a/cmd/ftl/cmd_dev.go b/cmd/ftl/cmd_dev.go index d6bb8f85f8..6de51bb3c0 100644 --- a/cmd/ftl/cmd_dev.go +++ b/cmd/ftl/cmd_dev.go @@ -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 { diff --git a/common/projectconfig/integration_test.go b/common/projectconfig/integration_test.go index de2b47810f..36bd172613 100644 --- a/common/projectconfig/integration_test.go +++ b/common/projectconfig/integration_test.go @@ -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"]) + }), + ) +} diff --git a/common/projectconfig/projectconfig.go b/common/projectconfig/projectconfig.go index d683c15c0b..dfa65c3b19 100644 --- a/common/projectconfig/projectconfig.go +++ b/common/projectconfig/projectconfig.go @@ -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 { diff --git a/common/projectconfig/testdata/go/no-module-dirs-ftl-project.toml b/common/projectconfig/testdata/go/no-module-dirs-ftl-project.toml new file mode 100644 index 0000000000..e5b05afd26 --- /dev/null +++ b/common/projectconfig/testdata/go/no-module-dirs-ftl-project.toml @@ -0,0 +1,2 @@ +[commands] + startup = ["echo 'Executing global pre-build command'"]