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

supabase / cli / 15585019893

11 Jun 2025 12:35PM UTC coverage: 55.511% (+0.4%) from 55.076%
15585019893

Pull #3675

github

web-flow
Merge aa640d28f into b3bee3dd5
Pull Request #3675: feat: hot reload eszip bundle when function source changes

368 of 536 new or added lines in 8 files covered. (68.66%)

9 existing lines in 2 files now uncovered.

6280 of 11313 relevant lines covered (55.51%)

7.14 hits per line

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

52.22
/internal/functions/serve/serve.go
1
package serve
2

3
import (
4
        "context"
5
        "fmt"
6
        "log"
7

8
        "github.com/docker/docker/api/types/container"
9
        "github.com/spf13/afero"
10
        "github.com/supabase/cli/internal/utils"
11
        "github.com/supabase/cli/internal/utils/flags"
12
)
13

14
type InspectMode string
15

16
const (
17
        InspectModeRun  InspectMode = "run"
18
        InspectModeBrk  InspectMode = "brk"
19
        InspectModeWait InspectMode = "wait"
20
)
21

22
func (mode InspectMode) toFlag() string {
×
23
        switch mode {
×
24
        case InspectModeBrk:
×
25
                return "inspect-brk"
×
26
        case InspectModeWait:
×
27
                return "inspect-wait"
×
28
        case InspectModeRun:
×
29
                fallthrough
×
30
        default:
×
31
                return "inspect"
×
32
        }
33
}
34

35
type RuntimeOption struct {
36
        InspectMode *InspectMode
37
        InspectMain bool
38
}
39

40
const (
41
        dockerRuntimeInspectorPort = 8083
42
)
43

44
func (i *RuntimeOption) toArgs() []string {
7✔
45
        flags := []string{}
7✔
46
        if i.InspectMode != nil {
7✔
47
                flags = append(flags, fmt.Sprintf("--%s=0.0.0.0:%d", i.InspectMode.toFlag(), dockerRuntimeInspectorPort))
×
48
                if i.InspectMain {
×
49
                        flags = append(flags, "--inspect-main")
×
50
                }
×
51
        }
52
        return flags
7✔
53
}
54

UNCOV
55
func Run(ctx context.Context, envFilePath string, noVerifyJWT *bool, importMapPath string, runtimeOption RuntimeOption, fsys afero.Fs) error {
×
NEW
56
        return RunWithWatcher(ctx, envFilePath, noVerifyJWT, importMapPath, runtimeOption, fsys, &RealFileWatcherSetup{})
×
NEW
57
}
×
58

59
func RunWithWatcher(ctx context.Context, envFilePath string, noVerifyJWT *bool, importMapPath string, runtimeOption RuntimeOption, fsys afero.Fs, watcherSetup FileWatcherSetup) error {
5✔
60
        // 1. Sanity checks.
5✔
61
        if err := flags.LoadConfig(fsys); err != nil {
6✔
62
                return err
1✔
63
        }
1✔
64
        if err := utils.AssertSupabaseDbIsRunning(); err != nil {
5✔
65
                return err
1✔
66
        }
1✔
67

68
        watcher, watchedPath, err := watcherSetup.SetupFileWatcher(fsys)
3✔
69
        if err != nil {
3✔
UNCOV
70
                return err
×
UNCOV
71
        }
×
72
        if watcher != nil {
3✔
NEW
73
                defer watcher.Close()
×
UNCOV
74
        }
×
75

76
        // Create a channel to signal when a restart is needed
77
        restartChan := make(chan struct{})
3✔
78

3✔
79
        // Create a map to track watched directories
3✔
80
        watchedDirs := make(map[string]bool)
3✔
81

3✔
82
        // Start the file watcher in a goroutine
3✔
83
        go runFileWatcher(ctx, watcher, watchedPath, restartChan, watchedDirs, fsys)
3✔
84

3✔
85
        errChan := make(chan error, 1)
3✔
86

3✔
87
        for {
6✔
88
                select {
3✔
NEW
89
                case <-ctx.Done():
×
NEW
90
                        fmt.Println("Stopping functions server...")
×
NEW
91
                        // 2. Remove existing container if any.
×
NEW
92
                        _ = utils.Docker.ContainerRemove(context.Background(), utils.EdgeRuntimeId, container.RemoveOptions{
×
NEW
93
                                RemoveVolumes: true,
×
NEW
94
                                Force:         true,
×
NEW
95
                        })
×
NEW
96
                        return ctx.Err()
×
97
                default:
3✔
98
                        // Use network alias because Deno cannot resolve `_` in hostname
3✔
99
                        dbUrl := fmt.Sprintf("postgresql://postgres:postgres@%s:5432/postgres", utils.DbAliases[0])
3✔
100

3✔
101
                        serviceCancel, logsDone, err := manageFunctionServices(ctx, envFilePath, noVerifyJWT, importMapPath, dbUrl, runtimeOption, fsys, errChan)
3✔
102
                        if err != nil {
5✔
103
                                return err
2✔
104
                        }
2✔
105

106
                        select {
1✔
NEW
107
                        case <-restartChan:
×
NEW
108
                                log.Println("Reloading Edge Functions due to file changes...")
×
NEW
109
                                if serviceCancel != nil {
×
NEW
110
                                        serviceCancel()
×
NEW
111
                                }
×
NEW
112
                                <-logsDone
×
NEW
113
                                continue
×
NEW
114
                        case err := <-errChan:
×
NEW
115
                                if serviceCancel != nil {
×
NEW
116
                                        serviceCancel()
×
NEW
117
                                }
×
NEW
118
                                <-logsDone
×
NEW
119
                                _ = utils.Docker.ContainerRemove(context.Background(), utils.EdgeRuntimeId, container.RemoveOptions{Force: true})
×
NEW
120
                                return err
×
121
                        case <-ctx.Done():
1✔
122
                                fmt.Println("Stopping functions server (received done signal during active service)...")
1✔
123
                                if serviceCancel != nil {
2✔
124
                                        serviceCancel()
1✔
125
                                }
1✔
126
                                <-logsDone
1✔
127
                                _ = utils.Docker.ContainerRemove(context.Background(), utils.EdgeRuntimeId, container.RemoveOptions{
1✔
128
                                        RemoveVolumes: true,
1✔
129
                                        Force:         true,
1✔
130
                                })
1✔
131
                                return ctx.Err()
1✔
132
                        }
133
                }
134
        }
135
}
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

© 2025 Coveralls, Inc