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

supabase / cli / 13910325011

17 Mar 2025 09:34PM UTC coverage: 51.053%. First build
13910325011

Pull #3314

github

web-flow
Merge 191509d66 into bc0db16f3
Pull Request #3314: fix: return deploy metadata from bundle

35 of 96 new or added lines in 3 files covered. (36.46%)

6955 of 13623 relevant lines covered (51.05%)

186.45 hits per line

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

72.0
/pkg/function/bundle.go
1
package function
2

3
import (
4
        "context"
5
        "fmt"
6
        "io"
7
        "io/fs"
8
        "os"
9
        "os/exec"
10
        "path/filepath"
11

12
        "github.com/andybalholm/brotli"
13
        "github.com/go-errors/errors"
14
        "github.com/supabase/cli/pkg/api"
15
)
16

17
type nativeBundler struct {
18
        tempDir string
19
        fsys    fs.FS
20
}
21

22
func NewNativeBundler(tempDir string, fsys fs.FS) EszipBundler {
×
23
        return &nativeBundler{
×
24
                tempDir: tempDir,
×
25
                fsys:    fsys,
×
26
        }
×
27
}
×
28

29
// Use a package private variable to allow testing without gosec complaining about G204
30
var edgeRuntimeBin = "edge-runtime"
31

32
func (b *nativeBundler) Bundle(ctx context.Context, slug, entrypoint, importMap string, staticFiles []string, output io.Writer) (api.FunctionDeployMetadata, error) {
2✔
33
        meta := api.FunctionDeployMetadata{
2✔
34
                Name:           &slug,
2✔
35
                EntrypointPath: entrypoint,
2✔
36
        }
2✔
37
        if len(importMap) > 0 {
3✔
38
                meta.ImportMapPath = &importMap
1✔
39
        }
1✔
40
        if len(staticFiles) > 0 {
3✔
41
                meta.StaticPatterns = &staticFiles
1✔
42
        }
1✔
43
        outputPath := filepath.Join(b.tempDir, slug+".eszip")
2✔
44
        // TODO: make edge runtime write to stdout
2✔
45
        args := []string{"bundle", "--entrypoint", entrypoint, "--output", outputPath}
2✔
46
        if len(importMap) > 0 {
3✔
47
                args = append(args, "--import-map", importMap)
1✔
48
        }
1✔
49
        for _, staticFile := range staticFiles {
3✔
50
                args = append(args, "--static", staticFile)
1✔
51
        }
1✔
52
        cmd := exec.CommandContext(ctx, edgeRuntimeBin, args...)
2✔
53
        cmd.Stderr = os.Stderr
2✔
54
        cmd.Stdout = os.Stdout
2✔
55
        if err := cmd.Run(); err != nil {
2✔
NEW
56
                return meta, errors.Errorf("failed to bundle function: %w", err)
×
57
        }
×
58
        defer os.Remove(outputPath)
2✔
59
        // Compress the output
2✔
60
        eszipBytes, err := b.fsys.Open(outputPath)
2✔
61
        if err != nil {
2✔
NEW
62
                return meta, errors.Errorf("failed to open eszip: %w", err)
×
63
        }
×
64
        defer eszipBytes.Close()
2✔
65
        return meta, Compress(eszipBytes, output)
2✔
66
}
67

68
const compressedEszipMagicID = "EZBR"
69

70
func Compress(r io.Reader, w io.Writer) error {
2✔
71
        if _, err := fmt.Fprint(w, compressedEszipMagicID); err != nil {
2✔
72
                return errors.Errorf("failed to append magic id: %w", err)
×
73
        }
×
74
        brw := brotli.NewWriter(w)
2✔
75
        defer brw.Close()
2✔
76
        if _, err := io.Copy(brw, r); err != nil {
2✔
77
                return errors.Errorf("failed to compress eszip: %w", err)
×
78
        }
×
79
        return nil
2✔
80
}
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