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

supabase / cli / 12790096626

15 Jan 2025 02:10PM UTC coverage: 58.385% (-0.05%) from 58.439%
12790096626

push

github

web-flow
feat: support adding static files to Edge Functions (#3045)

6 of 15 new or added lines in 5 files covered. (40.0%)

3 existing lines in 1 file now uncovered.

7590 of 13000 relevant lines covered (58.38%)

203.18 hits per line

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

56.1
/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
)
15

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

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

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

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

58
const compressedEszipMagicID = "EZBR"
59

60
func Compress(r io.Reader, w io.Writer) error {
1✔
61
        if _, err := fmt.Fprint(w, compressedEszipMagicID); err != nil {
1✔
62
                return errors.Errorf("failed to append magic id: %w", err)
×
63
        }
×
64
        brw := brotli.NewWriter(w)
1✔
65
        defer brw.Close()
1✔
66
        if _, err := io.Copy(brw, r); err != nil {
1✔
67
                return errors.Errorf("failed to compress eszip: %w", err)
×
68
        }
×
69
        return nil
1✔
70
}
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