Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion apps/cli-go/pkg/function/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,20 @@ func (b *nativeBundler) Bundle(ctx context.Context, slug, entrypoint, importMap
}

func ShouldUseDenoJsonDiscovery(entrypoint, importMap string) bool {
return isDeno(filepath.Base(importMap)) && filepath.Dir(importMap) == filepath.Dir(entrypoint)
if !isDeno(filepath.Base(importMap)) {
return false
}
if filepath.Dir(importMap) != filepath.Dir(entrypoint) {
return false
}
// Only rely on Deno auto-discovery if the import map file
// actually exists at the expected path. In GitHub branch
// deploy pipelines, the working directory may differ from
// local, causing auto-discovery to silently fail.
if _, err := os.Stat(importMap); err != nil {
return false
}
return true
}

func ShouldUsePackageJsonDiscovery(entrypoint, importMap string, fsys fs.StatFS) bool {
Expand Down
29 changes: 29 additions & 0 deletions apps/cli-go/pkg/function/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,32 @@ func TestBundleFunction(t *testing.T) {
assert.Nil(t, meta.VerifyJwt)
})
}
func TestShouldUseDenoJsonDiscovery(t *testing.T) {
t.Run("returns false when import map file does not exist", func(t *testing.T) {
result := ShouldUseDenoJsonDiscovery(
"/repo/supabase/functions/hello/index.ts",
"/repo/supabase/functions/hello/deno.json",
)
assert.False(t, result)
})

t.Run("returns true when import map file exists alongside entrypoint", func(t *testing.T) {
dir := t.TempDir()
entrypoint := filepath.Join(dir, "index.ts")
importMap := filepath.Join(dir, "deno.json")
require.NoError(t, os.WriteFile(importMap, []byte("{}"), 0644))

result := ShouldUseDenoJsonDiscovery(entrypoint, importMap)
assert.True(t, result)
})

t.Run("returns false when import map is not a deno json file", func(t *testing.T) {
dir := t.TempDir()
entrypoint := filepath.Join(dir, "index.ts")
importMap := filepath.Join(dir, "import_map.json")
require.NoError(t, os.WriteFile(importMap, []byte("{}"), 0644))

result := ShouldUseDenoJsonDiscovery(entrypoint, importMap)
assert.False(t, result)
})
}