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
2 changes: 1 addition & 1 deletion apps/cli-go/internal/functions/deploy/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (b *dockerBundler) Bundle(ctx context.Context, slug, entrypoint, importMap
hostOutputPath := filepath.Join(hostOutputDir, "output.eszip")
// Create exec command
cmd := []string{"bundle", "--entrypoint", utils.ToDockerPath(entrypoint), "--output", utils.ToDockerPath(hostOutputPath)}
if len(importMap) > 0 && !function.ShouldUseDenoJsonDiscovery(entrypoint, importMap) {
if len(importMap) > 0 {
cmd = append(cmd, "--import-map", utils.ToDockerPath(importMap))
}
for _, sf := range staticFiles {
Expand Down
6 changes: 1 addition & 5 deletions apps/cli-go/pkg/function/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (b *nativeBundler) Bundle(ctx context.Context, slug, entrypoint, importMap
outputPath := filepath.Join(b.tempDir, slug+".eszip")
// TODO: make edge runtime write to stdout
args := []string{"bundle", "--entrypoint", entrypoint, "--output", outputPath}
if len(importMap) > 0 && !ShouldUseDenoJsonDiscovery(entrypoint, importMap) {
if len(importMap) > 0 {
args = append(args, "--import-map", importMap)
}
for _, staticFile := range staticFiles {
Expand Down Expand Up @@ -90,10 +90,6 @@ func (b *nativeBundler) Bundle(ctx context.Context, slug, entrypoint, importMap
return meta, Compress(eszipBytes, output)
}

func ShouldUseDenoJsonDiscovery(entrypoint, importMap string) bool {
return isDeno(filepath.Base(importMap)) && filepath.Dir(importMap) == filepath.Dir(entrypoint)
}

func ShouldUsePackageJsonDiscovery(entrypoint, importMap string, fsys fs.StatFS) bool {
if len(importMap) > 0 {
return false
Expand Down
33 changes: 33 additions & 0 deletions apps/cli-go/pkg/function/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
fs "testing/fstest"

Expand All @@ -17,6 +18,12 @@ import (
func TestMain(m *testing.M) {
// Setup mock edge runtime binary
if len(os.Args) > 1 && os.Args[1] == "bundle" {
if path := os.Getenv("TEST_BUNDLE_ARGS_FILE"); len(path) > 0 {
if err := os.WriteFile(path, []byte(strings.Join(os.Args[1:], "\n")), 0600); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
if msg := os.Getenv("TEST_BUNDLE_ERROR"); len(msg) > 0 {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
Expand Down Expand Up @@ -63,6 +70,32 @@ func TestBundleFunction(t *testing.T) {
assert.Nil(t, meta.VerifyJwt)
})

t.Run("passes deno config as import map", func(t *testing.T) {
argsFile := filepath.Join(t.TempDir(), "args")
t.Setenv("TEST_BUNDLE_ARGS_FILE", argsFile)
var body bytes.Buffer
fsys := fs.MapFS{
"hello.eszip": &fs.MapFile{},
}
bundler := nativeBundler{fsys: fsys}

_, err := bundler.Bundle(
context.Background(),
"hello",
"hello/index.ts",
"hello/deno.json",
nil,
&body,
)

require.NoError(t, err)
data, err := os.ReadFile(argsFile)
require.NoError(t, err)
args := strings.Split(string(data), "\n")
assert.Contains(t, args, "--import-map")
assert.Contains(t, args, "hello/deno.json")
})

t.Run("ignores empty value", func(t *testing.T) {
var body bytes.Buffer
// Setup in-memory fs
Expand Down