Skip to content

Commit 554656f

Browse files
authored
fix: mock fsevents module to avoid cgo (#4505)
* chore: add e2e tests for linking * feat: mock fsevents module to avoid cgo
1 parent 483f379 commit 554656f

File tree

7 files changed

+179
-4
lines changed

7 files changed

+179
-4
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ jobs:
7979
env:
8080
SUPABASE_INTERNAL_IMAGE_REGISTRY: ghcr.io
8181

82+
link:
83+
name: Link
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v6
87+
- uses: actions/setup-go@v6
88+
with:
89+
go-version-file: go.mod
90+
cache: true
91+
- run: go build main.go
92+
- run: ./main link
93+
env:
94+
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
95+
SUPABASE_PROJECT_ID: ${{ secrets.SUPABASE_PROJECT_ID }}
96+
8297
codegen:
8398
name: Codegen
8499
runs-on: ubuntu-latest

fsevents/fsevents.go

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//go:build darwin
2+
3+
// Package fsevents provides file system notifications on macOS.
4+
package fsevents
5+
6+
import (
7+
"syscall"
8+
"time"
9+
)
10+
11+
// Event represents a single file system notification.
12+
type Event struct {
13+
// Path holds the path to the item that's changed, relative
14+
// to its device's root.
15+
// Use DeviceForPath to determine the absolute path that's
16+
// being referred to.
17+
Path string
18+
19+
// Flags holds details what has happened.
20+
Flags EventFlags
21+
22+
// ID holds the event ID.
23+
//
24+
// Each event ID comes from the most recent event being reported
25+
// in the corresponding directory named in the EventStream.Paths field
26+
// Event IDs all come from a single global source.
27+
// They are guaranteed to always be increasing, usually in leaps
28+
// and bounds, even across system reboots and moving drives from
29+
// one machine to another. If you were to
30+
// stop processing events from this stream after this event
31+
// and resume processing them later from a newly-created
32+
// EventStream, this is the value you would pass for the
33+
// EventStream.EventID along with Resume=true.
34+
ID uint64
35+
}
36+
37+
// DeviceForPath returns the device ID for the specified volume.
38+
func DeviceForPath(path string) (int32, error) {
39+
stat := syscall.Stat_t{}
40+
if err := syscall.Lstat(path, &stat); err != nil {
41+
return 0, err
42+
}
43+
return stat.Dev, nil
44+
}
45+
46+
// EventStream is the primary interface to FSEvents
47+
// You can provide your own event channel if you wish (or one will be
48+
// created on Start).
49+
//
50+
// es := &EventStream{Paths: []string{"/tmp"}, Flags: 0}
51+
// es.Start()
52+
// es.Stop()
53+
// ...
54+
type EventStream struct {
55+
// Events holds the channel on which events will be sent.
56+
// It's initialized by EventStream.Start if nil.
57+
Events chan []Event
58+
59+
// Paths holds the set of paths to watch, each
60+
// specifying the root of a filesystem hierarchy to be
61+
// watched for modifications.
62+
Paths []string
63+
64+
// Flags specifies what events to receive on the stream.
65+
Flags CreateFlags
66+
67+
// Resume specifies that watching should resume from the event
68+
// specified by EventID.
69+
Resume bool
70+
71+
// EventID holds the most recent event ID.
72+
//
73+
// NOTE: this is updated asynchronously by the
74+
// watcher and should not be accessed while
75+
// the stream has been started.
76+
EventID uint64
77+
78+
// Latency holds the number of seconds the service should wait after hearing
79+
// about an event from the kernel before passing it along to the
80+
// client via its callback. Specifying a larger value may result
81+
// in more effective temporal coalescing, resulting in fewer
82+
// callbacks and greater overall efficiency.
83+
Latency time.Duration
84+
85+
// When Device is non-zero, the watcher will watch events on the
86+
// device with this ID, and the paths in the Paths field are
87+
// interpreted relative to the device's root.
88+
//
89+
// The device ID is the same as the st_dev field from a stat
90+
// structure of a file on that device or the f_fsid[0] field of
91+
// a statfs structure.
92+
Device int32
93+
}
94+
95+
// Start listening to an event stream. This creates es.Events if it's not already
96+
// a valid channel.
97+
func (es *EventStream) Start() error {
98+
return nil
99+
}
100+
101+
// Flush flushes events that have occurred but haven't been delivered.
102+
// If sync is true, it will block until all the events have been delivered,
103+
// otherwise it will return immediately.
104+
func (es *EventStream) Flush(sync bool) {
105+
}
106+
107+
// Stop stops listening to the event stream.
108+
func (es *EventStream) Stop() {
109+
}
110+
111+
// Restart restarts the event listener. This
112+
// can be used to change the current watch flags.
113+
func (es *EventStream) Restart() error {
114+
es.Stop()
115+
es.Resume = true
116+
return es.Start()
117+
}

fsevents/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
go 1.24.10
2+
3+
module github.com/fsnotify/fsevents

fsevents/wrap.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//go:build darwin
2+
3+
package fsevents
4+
5+
// CreateFlags specifies what events will be seen in an event stream.
6+
type CreateFlags uint32
7+
8+
const (
9+
// IgnoreSelf doesn't send events triggered by the current process (macOS 10.6+).
10+
//
11+
// Don't send events that were triggered by the current process.
12+
// This is useful for reducing the volume of events that are
13+
// sent. It is only useful if your process might modify the file
14+
// system hierarchy beneath the path(s) being monitored. Note:
15+
// this has no effect on historical events, i.e., those
16+
// delivered before the HistoryDone sentinel event.
17+
IgnoreSelf = CreateFlags(0)
18+
19+
// FileEvents sends events about individual files, generating significantly
20+
// more events (macOS 10.7+) than directory level notifications.
21+
FileEvents = CreateFlags(1)
22+
)
23+
24+
// EventFlags passed to the FSEventStreamCallback function.
25+
// These correspond directly to the flags as described here:
26+
// https://developer.apple.com/documentation/coreservices/1455361-fseventstreameventflags
27+
type EventFlags uint32
28+
29+
const (
30+
// ItemCreated indicates that a file or directory has been created.
31+
ItemCreated = EventFlags(0)
32+
33+
// ItemIsDir indicates that the item is a directory.
34+
ItemIsDir = EventFlags(1)
35+
)
36+
37+
// LatestEventID returns the most recently generated event ID, system-wide.
38+
func LatestEventID() uint64 {
39+
return 0
40+
}

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/supabase/cli
22

3-
go 1.24.9
3+
go 1.24.10
44

55
require (
66
github.com/BurntSushi/toml v1.5.0
@@ -455,6 +455,8 @@ require (
455455

456456
replace github.com/supabase/cli/pkg v1.0.0 => ./pkg
457457

458+
replace github.com/fsnotify/fsevents v0.2.0 => ./fsevents
459+
458460
tool (
459461
github.com/golangci/golangci-lint/v2/cmd/golangci-lint
460462
github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@ github.com/firefart/nonamedreturns v1.0.6 h1:vmiBcKV/3EqKY3ZiPxCINmpS431OcE1S47A
327327
github.com/firefart/nonamedreturns v1.0.6/go.mod h1:R8NisJnSIpvPWheCq0mNRXJok6D8h7fagJTF8EMEwCo=
328328
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
329329
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
330-
github.com/fsnotify/fsevents v0.2.0 h1:BRlvlqjvNTfogHfeBOFvSC9N0Ddy+wzQCQukyoD7o/c=
331-
github.com/fsnotify/fsevents v0.2.0/go.mod h1:B3eEk39i4hz8y1zaWS/wPrAP4O6wkIl7HQwKBr1qH/w=
332330
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
333331
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
334332
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=

pkg/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/supabase/cli/pkg
22

3-
go 1.24.4
3+
go 1.24.10
44

55
require (
66
github.com/BurntSushi/toml v1.5.0

0 commit comments

Comments
 (0)