-
Notifications
You must be signed in to change notification settings - Fork 243
fix: support main.ts as an entrypoint #3201
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -54,7 +54,7 @@ func Run(ctx context.Context, slugs []string, useDocker bool, noVerifyJWT *bool, | |||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
func GetFunctionSlugs(fsys afero.Fs) (slugs []string, err error) { | ||||||||||||||||||||||||||||||||||
pattern := filepath.Join(utils.FunctionsDir, "*", "index.ts") | ||||||||||||||||||||||||||||||||||
pattern := filepath.Join(utils.FunctionsDir, "*", "*.ts") | ||||||||||||||||||||||||||||||||||
paths, err := afero.Glob(fsys, pattern) | ||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||
return nil, errors.Errorf("failed to glob function slugs: %w", err) | ||||||||||||||||||||||||||||||||||
|
@@ -97,7 +97,15 @@ func GetFunctionConfig(slugs []string, importMapPath string, noVerifyJWT *bool, | |||||||||||||||||||||||||||||||||
// Precedence order: flag > config > fallback | ||||||||||||||||||||||||||||||||||
functionDir := filepath.Join(utils.FunctionsDir, name) | ||||||||||||||||||||||||||||||||||
if len(function.Entrypoint) == 0 { | ||||||||||||||||||||||||||||||||||
function.Entrypoint = filepath.Join(functionDir, "index.ts") | ||||||||||||||||||||||||||||||||||
indexEntrypoint := filepath.Join(functionDir, "index.ts") | ||||||||||||||||||||||||||||||||||
mainEntrypoint := filepath.Join(functionDir, "main.ts") | ||||||||||||||||||||||||||||||||||
if _, err := fsys.Stat(indexEntrypoint); err == nil { | ||||||||||||||||||||||||||||||||||
function.Entrypoint = indexEntrypoint | ||||||||||||||||||||||||||||||||||
} else if _, err := fsys.Stat(mainEntrypoint); err == nil { | ||||||||||||||||||||||||||||||||||
function.Entrypoint = mainEntrypoint | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
return nil, errors.Errorf("Cannot find a valid entrypoint file (index.ts or main.ts) for the '%s' function. Set the custom entrypoint path in config.toml", name) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
Comment on lines
+100
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
ditto One way to reduce duplication is to add a |
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if len(importMapPath) > 0 { | ||||||||||||||||||||||||||||||||||
function.ImportMap = importMapPath | ||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -654,7 +654,13 @@ func (c *baseConfig) resolve(builder pathBuilder, fsys fs.FS) error { | |||||||||||||||||||||||||||||
// Resolve functions config | ||||||||||||||||||||||||||||||
for slug, function := range c.Functions { | ||||||||||||||||||||||||||||||
if len(function.Entrypoint) == 0 { | ||||||||||||||||||||||||||||||
function.Entrypoint = filepath.Join(builder.FunctionsDir, slug, "index.ts") | ||||||||||||||||||||||||||||||
indexEntrypoint := filepath.Join(builder.FunctionsDir, slug, "index.ts") | ||||||||||||||||||||||||||||||
mainEntrypoint := filepath.Join(builder.FunctionsDir, slug, "main.ts") | ||||||||||||||||||||||||||||||
if _, err := fs.Stat(fsys, indexEntrypoint); err == nil { | ||||||||||||||||||||||||||||||
function.Entrypoint = indexEntrypoint | ||||||||||||||||||||||||||||||
} else if _, err := fs.Stat(fsys, mainEntrypoint); err == nil { | ||||||||||||||||||||||||||||||
function.Entrypoint = mainEntrypoint | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+657
to
+663
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We should still pass down default entrypoint path. |
||||||||||||||||||||||||||||||
} else if !filepath.IsAbs(function.Entrypoint) { | ||||||||||||||||||||||||||||||
// Append supabase/ because paths in configs are specified relative to config.toml | ||||||||||||||||||||||||||||||
function.Entrypoint = filepath.Join(builder.SupabaseDirPath, function.Entrypoint) | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A wildcard match here could open a can of worms with existing CI/CD pipelines as shared modules may be unintentionally deployed. I'd rather let users opt-in by declaring in config. For eg. if they declare
[functions.some-slug]
in config.toml, we can automatically check for bothindex.ts
followed bymain.ts
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm..don't we already have a check to exclude shared modules?
cli/internal/functions/deploy/deploy.go
Line 64 in cf4d803
If there's a Glob to explicitly match both
index.ts
andmain.ts
, I'm happy to change that (tried, but I couldn't get it to work).The problem with having
[functions.some-slug]
in config.toml is users have to add it manually. And if they dodeno init --serve supabase/functions/my-func
and then try to access the function it wouldn't work. If we can auto-populate the valid function slugs, it would improve the DX a lot.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing wildcard match does NOT eliminate shared modules like
functions/_shared/index.ts
. It will deploy a function named_shared
.Unfortunately this isn't something we can easily change now without risking breaking user's CI/CD pipeline. Because users may very well have a function named
_something
and expects it to be deployed.IMO, the root of this evil is due to the implicit behaviour of finding entrypoints by glob patterns. It was ok for small scale local development, but not acceptable for CI/CD when you have 100s of functions to manage.
I suspect you've misunderstood my suggestion. I'm saying to parse
main.ts
as fallback entrypoint inpkg/config
, not to completely ignore it. That way, bothdeno init --serve
andfunctions deploy
work.