From 115ddfd4c3a746cf0f709420d90429a2211d44a4 Mon Sep 17 00:00:00 2001 From: Tanusree Samanta Date: Mon, 22 Jun 2026 23:18:58 +0530 Subject: [PATCH] fix: apply import map during GitHub branch Edge Function bundling Fixes #47000 ShouldUseDenoJsonDiscovery skipped passing --import-map when the import map sat next to the entrypoint, assuming Deno would auto- discover it. This works locally but fails in GitHub branch deploy pipelines where the working directory differs, breaking @backend/ style path aliases. Now we verify the file actually exists before relying on auto-discovery. --- apps/cli-go/pkg/function/bundle.go | 15 ++++++++++++- apps/cli-go/pkg/function/bundle_test.go | 29 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/apps/cli-go/pkg/function/bundle.go b/apps/cli-go/pkg/function/bundle.go index 599006aef8..54750c9a50 100644 --- a/apps/cli-go/pkg/function/bundle.go +++ b/apps/cli-go/pkg/function/bundle.go @@ -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 { diff --git a/apps/cli-go/pkg/function/bundle_test.go b/apps/cli-go/pkg/function/bundle_test.go index 1f16b87f47..78b7707c1b 100644 --- a/apps/cli-go/pkg/function/bundle_test.go +++ b/apps/cli-go/pkg/function/bundle_test.go @@ -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) + }) +} \ No newline at end of file