• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / cli / 12510084008

27 Dec 2024 12:51AM UTC coverage: 59.735% (-0.009%) from 59.744%
12510084008

Pull #2984

github

web-flow
Merge f28903dbc into 3f5da996b
Pull Request #2984: fix(edge-functions): add deno.json fallback

36 of 47 new or added lines in 3 files covered. (76.6%)

7 existing lines in 2 files now uncovered.

7667 of 12835 relevant lines covered (59.74%)

203.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.51
/internal/functions/deploy/deploy.go
1
package deploy
2

3
import (
4
        "context"
5
        "fmt"
6
        "os"
7
        "path/filepath"
8
        "strings"
9

10
        "github.com/go-errors/errors"
11
        "github.com/spf13/afero"
12
        "github.com/supabase/cli/internal/utils"
13
        "github.com/supabase/cli/internal/utils/flags"
14
        "github.com/supabase/cli/pkg/cast"
15
        "github.com/supabase/cli/pkg/config"
16
        "github.com/supabase/cli/pkg/function"
17
)
18

19
func Run(ctx context.Context, slugs []string, projectRef string, noVerifyJWT *bool, importMapPath string, fsys afero.Fs) error {
7✔
20
        // Load function config and project id
7✔
21
        if err := utils.LoadConfigFS(fsys); err != nil {
7✔
22
                return err
×
23
        } else if len(slugs) > 0 {
11✔
24
                for _, s := range slugs {
9✔
25
                        if err := utils.ValidateFunctionSlug(s); err != nil {
6✔
26
                                return err
1✔
27
                        }
1✔
28
                }
29
        } else if slugs, err = GetFunctionSlugs(fsys); err != nil {
3✔
30
                return err
×
31
        }
×
32
        // TODO: require all functions to be deployed from config for v2
33
        if len(slugs) == 0 {
7✔
34
                return errors.Errorf("No Functions specified or found in %s", utils.Bold(utils.FunctionsDir))
1✔
35
        }
1✔
36
        functionConfig, err := GetFunctionConfig(slugs, importMapPath, noVerifyJWT, fsys)
5✔
37
        if err != nil {
5✔
38
                return err
×
39
        }
×
40
        api := function.NewEdgeRuntimeAPI(projectRef, *utils.GetSupabase(), NewDockerBundler(fsys))
5✔
41
        if err := api.UpsertFunctions(ctx, functionConfig); err != nil {
5✔
42
                return err
×
43
        }
×
44
        fmt.Printf("Deployed Functions on project %s: %s\n", utils.Aqua(projectRef), strings.Join(slugs, ", "))
5✔
45
        url := fmt.Sprintf("%s/project/%v/functions", utils.GetSupabaseDashboardURL(), projectRef)
5✔
46
        fmt.Println("You can inspect your deployment in the Dashboard: " + url)
5✔
47
        return nil
5✔
48
}
49

50
func GetFunctionSlugs(fsys afero.Fs) (slugs []string, err error) {
3✔
51
        pattern := filepath.Join(utils.FunctionsDir, "*", "index.ts")
3✔
52
        paths, err := afero.Glob(fsys, pattern)
3✔
53
        if err != nil {
3✔
54
                return nil, errors.Errorf("failed to glob function slugs: %w", err)
×
55
        }
×
56
        for _, path := range paths {
7✔
57
                slug := filepath.Base(filepath.Dir(path))
4✔
58
                if utils.FuncSlugPattern.MatchString(slug) {
7✔
59
                        slugs = append(slugs, slug)
3✔
60
                }
3✔
61
        }
62
        // Add all function slugs declared in config file
63
        remote, _ := utils.Config.GetRemoteByProjectRef(flags.ProjectRef)
3✔
64
        for slug := range remote.Functions {
5✔
65
                slugs = append(slugs, slug)
2✔
66
        }
2✔
67
        return slugs, nil
3✔
68
}
69

70
func GetFunctionConfig(slugs []string, importMapPath string, noVerifyJWT *bool, fsys afero.Fs) (config.FunctionConfig, error) {
12✔
71
        // Flag import map is specified relative to current directory instead of workdir
12✔
72
        if len(importMapPath) > 0 && !filepath.IsAbs(importMapPath) {
13✔
73
                importMapPath = filepath.Join(utils.CurrentDirAbs, importMapPath)
1✔
74
        }
1✔
75
        remote, _ := utils.Config.GetRemoteByProjectRef(flags.ProjectRef)
12✔
76
        functionConfig := make(config.FunctionConfig, len(slugs))
12✔
77
        for _, name := range slugs {
28✔
78
                function := remote.Functions[name]
16✔
79
                // Precedence order: flag > config > fallback
16✔
80
                functionDir := filepath.Join(utils.FunctionsDir, name)
16✔
81
                if len(function.Entrypoint) == 0 {
26✔
82
                        function.Entrypoint = filepath.Join(functionDir, "index.ts")
10✔
83
                }
10✔
84
                if len(importMapPath) > 0 {
18✔
85
                        function.ImportMap = importMapPath
2✔
86
                } else if len(function.ImportMap) == 0 {
25✔
87
                        if dedicatedFunctionPath, err := utils.GetImportsFilePath(functionDir, fsys); err == nil {
9✔
NEW
88
                                function.ImportMap = dedicatedFunctionPath
×
89
                        } else if fallbackFunctionPath, err := utils.GetImportsFilePath(utils.FunctionsDir, fsys); err == nil {
12✔
90
                                function.ImportMap = fallbackFunctionPath
3✔
91
                        }
3✔
92
                }
93
                if noVerifyJWT != nil {
20✔
94
                        function.VerifyJWT = cast.Ptr(!*noVerifyJWT)
4✔
95
                }
4✔
96
                functionConfig[name] = function
16✔
97
        }
98
        // Check validity of ImportMap paths
99
        functionsWithFallback := []string{}
12✔
100
        if fallbacksPath, err := utils.GetImportsFilePath(utils.FunctionsDir, fsys); err == nil {
18✔
101
                for name, function := range functionConfig {
12✔
102
                        if function.ImportMap == fallbacksPath {
9✔
103
                                functionsWithFallback = append(functionsWithFallback, name)
3✔
104
                        }
3✔
105
                }
106
                if len(functionsWithFallback) > 0 {
9✔
107
                        msg := fmt.Sprintf(
3✔
108
                                utils.Yellow("WARNING: ")+
3✔
109
                                        "The following functions are using the fallback import map at %s: %s\n"+
3✔
110
                                        "This is not recommended outside of development. Please move import maps into each function folder.\n"+
3✔
111
                                        "See: https://supabase.com/docs/guides/functions/import-maps\n",
3✔
112
                                fallbacksPath,
3✔
113
                                strings.Join(functionsWithFallback, ", "),
3✔
114
                        )
3✔
115
                        fmt.Fprint(os.Stderr, msg)
3✔
116
                }
3✔
117
        }
118

119
        return functionConfig, nil
12✔
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc