From 5c7b12ddfd91c8461e7693ded53c14f3a8316d23 Mon Sep 17 00:00:00 2001 From: Sam McCord Date: Tue, 23 May 2023 09:10:51 -0600 Subject: [PATCH] feat: allow --unstable flag in functions serve --- cmd/functions.go | 4 +++- internal/functions/serve/serve.go | 7 ++++++- internal/functions/serve/serve_test.go | 12 ++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cmd/functions.go b/cmd/functions.go index 1160d33b3..49e992c58 100644 --- a/cmd/functions.go +++ b/cmd/functions.go @@ -75,6 +75,7 @@ var ( } envFilePath string + unstable = new(bool) functionsServeCmd = &cobra.Command{ Use: "serve ", @@ -95,7 +96,7 @@ var ( if len(args) > 0 { slug = args[0] } - return serve.Run(ctx, slug, envFilePath, noVerifyJWT, importMapPath, afero.NewOsFs()) + return serve.Run(ctx, slug, envFilePath, noVerifyJWT, importMapPath, unstable, afero.NewOsFs()) }, } ) @@ -111,6 +112,7 @@ func init() { functionsServeCmd.Flags().StringVar(&envFilePath, "env-file", "", "Path to an env file to be populated to the Function environment.") functionsServeCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.") functionsServeCmd.Flags().Bool("all", true, "Serve all Functions (caution: experimental feature)") + functionsServeCmd.Flags().BoolVar(unstable, "unstable", false, "Enable the use of unstable Deno APIs") cobra.CheckErr(functionsServeCmd.Flags().MarkHidden("all")) functionsDownloadCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.") functionsCmd.AddCommand(functionsDeleteCmd) diff --git a/internal/functions/serve/serve.go b/internal/functions/serve/serve.go index b60021f7e..294fde8ed 100644 --- a/internal/functions/serve/serve.go +++ b/internal/functions/serve/serve.go @@ -34,7 +34,7 @@ var ( mainFuncEmbed string ) -func Run(ctx context.Context, slug string, envFilePath string, noVerifyJWT *bool, importMapPath string, fsys afero.Fs) error { +func Run(ctx context.Context, slug string, envFilePath string, noVerifyJWT *bool, importMapPath string, unstable *bool, fsys afero.Fs) error { if len(slug) == 0 { return runServeAll(ctx, envFilePath, noVerifyJWT, importMapPath, fsys) } @@ -174,6 +174,11 @@ func Run(ctx context.Context, slug string, envFilePath string, noVerifyJWT *bool } else { return fmt.Errorf("failed to check index.ts for function %s: %w", slug, err) } + + if *unstable { + denoRunCmd = append(denoRunCmd, "--unstable") + } + denoRunCmd = append(denoRunCmd, dockerFuncPath) } diff --git a/internal/functions/serve/serve_test.go b/internal/functions/serve/serve_test.go index 95a3a1b4d..887208508 100644 --- a/internal/functions/serve/serve_test.go +++ b/internal/functions/serve/serve_test.go @@ -36,7 +36,7 @@ func TestServeCommand(t *testing.T) { Post("/v" + utils.Docker.ClientVersion() + "/containers"). Reply(http.StatusServiceUnavailable) // Run test - err := Run(context.Background(), "test-func", "", nil, "", fsys) + err := Run(context.Background(), "test-func", "", nil, "", nil, fsys) // Check error assert.ErrorContains(t, err, "request returned Service Unavailable for API route and version") assert.Empty(t, apitest.ListUnmatchedRequests()) @@ -63,7 +63,7 @@ func TestServeCommand(t *testing.T) { require.NoError(t, apitest.MockDockerLogs(utils.Docker, containerId, "success")) // Run test noVerifyJWT := true - err := Run(context.Background(), "", ".env", &noVerifyJWT, "", fsys) + err := Run(context.Background(), "", ".env", &noVerifyJWT, "", nil, fsys) // Check error assert.NoError(t, err) assert.Empty(t, apitest.ListUnmatchedRequests()) @@ -73,7 +73,7 @@ func TestServeCommand(t *testing.T) { // Setup in-memory fs fsys := afero.NewMemMapFs() // Run test - err := Run(context.Background(), "", "", nil, "", fsys) + err := Run(context.Background(), "", "", nil, "", nil, fsys) // Check error assert.ErrorContains(t, err, "open supabase/config.toml: file does not exist") }) @@ -89,7 +89,7 @@ func TestServeCommand(t *testing.T) { Get("/v" + utils.Docker.ClientVersion() + "/containers/supabase_db_test/json"). ReplyError(errors.New("network error")) // Run test - err := Run(context.Background(), "", "", nil, "", fsys) + err := Run(context.Background(), "", "", nil, "", nil, fsys) // Check error assert.ErrorIs(t, err, utils.ErrNotRunning) }) @@ -106,7 +106,7 @@ func TestServeCommand(t *testing.T) { Reply(http.StatusOK). JSON(types.ContainerJSON{}) // Run test - err := Run(context.Background(), "", ".env", nil, "", fsys) + err := Run(context.Background(), "", ".env", nil, "", nil, fsys) // Check error assert.ErrorContains(t, err, "open .env: file does not exist") }) @@ -124,7 +124,7 @@ func TestServeCommand(t *testing.T) { Reply(http.StatusOK). JSON(types.ContainerJSON{}) // Run test - err := Run(context.Background(), "", ".env", nil, "import_map.json", fsys) + err := Run(context.Background(), "", ".env", nil, "import_map.json", nil, fsys) // Check error assert.ErrorContains(t, err, "Failed to read import map") assert.ErrorContains(t, err, "file does not exist")