Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: defaults to json when initialising import map #3038

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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
17 changes: 14 additions & 3 deletions internal/functions/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,22 @@ func GetFunctionConfig(slugs []string, importMapPath string, noVerifyJWT *bool,
functionConfig[name] = function
}
if len(functionsUsingDeprecatedImportMap) > 0 {
fmt.Fprintln(os.Stderr, utils.Yellow("WARNING:"), "Functions using deprecated import_map.json (please migrate to deno.jsonc):", utils.Aqua(strings.Join(functionsUsingDeprecatedImportMap, ", ")))
fmt.Fprintln(os.Stderr,
utils.Yellow("WARNING:"),
"Functions using deprecated import_map.json (please migrate to deno.json):",
utils.Aqua(strings.Join(functionsUsingDeprecatedImportMap, ", ")),
)
}
if len(functionsUsingDeprecatedGlobalFallback) > 0 {
fmt.Fprintln(os.Stderr, utils.Yellow("WARNING:"), "Functions using fallback import map:", utils.Aqua(strings.Join(functionsUsingDeprecatedGlobalFallback, ", ")))
fmt.Fprintln(os.Stderr, "Please use recommended per function dependency declaration ", utils.Aqua("https://supabase.com/docs/guides/functions/import-maps"))
fmt.Fprintln(os.Stderr,
utils.Yellow("WARNING:"),
"Functions using fallback import map:",
utils.Aqua(strings.Join(functionsUsingDeprecatedGlobalFallback, ", ")),
)
fmt.Fprintln(os.Stderr,
"Please use recommended per function dependency declaration ",
utils.Aqua("https://supabase.com/docs/guides/functions/import-maps"),
)
}
return functionConfig, nil
}
6 changes: 3 additions & 3 deletions internal/functions/new/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
var (
//go:embed templates/index.ts
indexEmbed string
//go:embed templates/deno.jsonc
//go:embed templates/deno.json
denoEmbed string
//go:embed templates/.npmrc
npmrcEmbed string
Expand Down Expand Up @@ -57,8 +57,8 @@ func Run(ctx context.Context, slug string, fsys afero.Fs) error {
return errors.Errorf("failed to create function entrypoint: %w", err)
}

if err := afero.WriteFile(fsys, filepath.Join(funcDir, "deno.jsonc"), []byte(denoEmbed), 0644); err != nil {
return errors.Errorf("failed to create deno.jsonc config: %w", err)
if err := afero.WriteFile(fsys, filepath.Join(funcDir, "deno.json"), []byte(denoEmbed), 0644); err != nil {
return errors.Errorf("failed to create deno.json config: %w", err)
}

if err := afero.WriteFile(fsys, filepath.Join(funcDir, ".npmrc"), []byte(npmrcEmbed), 0644); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/functions/new/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func TestNewCommand(t *testing.T) {
"curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/test-func'",
)

// Verify deno.jsonc exists
denoPath := filepath.Join(utils.FunctionsDir, "test-func", "deno.jsonc")
// Verify deno.json exists
denoPath := filepath.Join(utils.FunctionsDir, "test-func", "deno.json")
_, err = afero.ReadFile(fsys, denoPath)
assert.NoError(t, err, "deno.jsonc should be created")
assert.NoError(t, err, "deno.json should be created")

// Verify .npmrc exists
npmrcPath := filepath.Join(utils.FunctionsDir, "test-func", ".npmrc")
Expand Down
3 changes: 3 additions & 0 deletions internal/functions/new/templates/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"imports": {}
}
6 changes: 0 additions & 6 deletions internal/functions/new/templates/deno.jsonc

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func TestLoadFunctionImportMap(t *testing.T) {
}
// Run test
assert.NoError(t, config.Load("", fsys))
// Check that deno.json was set as import map
// Check that deno.jsonc was set as import map
assert.Equal(t, "supabase/functions/hello/deno.jsonc", config.Functions["hello"].ImportMap)
})

Expand Down
Loading