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

feat(config): load local deno.json file as import map #2824

Merged
merged 6 commits into from
Nov 3, 2024

Conversation

jgoux
Copy link
Contributor

@jgoux jgoux commented Nov 1, 2024

What kind of change does this PR introduce?

feature

What is the current behavior?

Currently each edge function shares a global import_map.json by default.
To use one particular import map per function the user has to define it manually in config.toml

What is the new behavior?

We now automatically load deno.json and deno.jsonc under the supabase/functions/<slug> directory.
Each function should be treated as a different project with its own set of dependencies.

Additional context

import_map.json disappeared from Deno's doc since as of v1.19.2: https://deno.land/x/[email protected]/npm_nodejs/import_maps.md?source

Imports should now be declared as part of deno's config file deno.json.

We might want to deprecate import_map.json, especially when we will ship deno v2 support.

@coveralls
Copy link

coveralls commented Nov 1, 2024

Pull Request Test Coverage Report for Build 11647813901

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 7 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.03%) to 59.803%

Files with Coverage Reduction New Missed Lines %
internal/storage/rm/rm.go 2 89.53%
internal/gen/keys/keys.go 5 12.9%
Totals Coverage Status
Change from base Build 11639792814: -0.03%
Covered Lines: 6375
Relevant Lines: 10660

💛 - Coveralls

pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
@jgoux jgoux marked this pull request as draft November 2, 2024 09:56
@jgoux jgoux marked this pull request as ready for review November 2, 2024 10:00
Comment on lines 657 to 666
// Load functions config
pattern := filepath.Join(builder.FunctionsDir, "*", "index.ts")
paths, err := fs.Glob(fsys, pattern)
if err != nil {
return errors.Errorf("failed to glob function slugs: %w", err)
}

if c.Functions == nil {
c.Functions = make(FunctionConfig)
}
Copy link
Contributor

@sweatybridge sweatybridge Nov 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Globbing functions this way is very fragile because users often have shared components that they don't want to deploy as functions, for eg. functions/shared/index.ts. That was one of the reasons we opted to require explicit declaration of functions in config.toml.

Instead, we want to find deno.json relative to entrypoint path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the code from

func GetFunctionSlugs(fsys afero.Fs) (slugs []string, err error) {
pattern := filepath.Join(utils.FunctionsDir, "*", "index.ts")
paths, err := afero.Glob(fsys, pattern)
if err != nil {
return nil, errors.Errorf("failed to glob function slugs: %w", err)
}
for _, path := range paths {
slug := filepath.Base(filepath.Dir(path))
if utils.FuncSlugPattern.MatchString(slug) {
slugs = append(slugs, slug)
}
}
// Add all function slugs declared in config file
for slug := range utils.Config.Functions {
slugs = append(slugs, slug)
}
return slugs, nil
}

Should we also change this part then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to update deploy for the time being. We left it for backwards compatibility with those who use setup-cli GitHub action.

Users only need to declare if they want to deploy to branches using our new integration.

@sweatybridge sweatybridge force-pushed the feat/load-local-deno-config-files branch from 3559079 to 0a4fe8d Compare November 3, 2024 02:37
@sweatybridge sweatybridge force-pushed the feat/load-local-deno-config-files branch from 0a4fe8d to 7b4509d Compare November 3, 2024 02:39
@sweatybridge sweatybridge merged commit 4cf189a into develop Nov 3, 2024
13 checks passed
@sweatybridge sweatybridge deleted the feat/load-local-deno-config-files branch November 3, 2024 02:43
@tazmaniax
Copy link

As per the additional context in the description can a global deno.json now be used instead of an import_map.json with this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants