-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support reusable modules for Supabase edge functions (Draft) (Last PR was closed automatically due to commits being removed from rebase) #1665
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
base: main
Are you sure you want to change the base?
Conversation
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.
No issues found across 1 file
…able-modules-ysihbd Bundle Supabase functions with shared utilities
|
Turns out Supabase CLI package is different from the supabase-js package, so unless the users install an extra supabase package they cannot use the native supabase method so I've just changed it to use zips for bundling. |
…able-modules-hmdfcc Bundle Supabase functions with shared utilities
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.
Reviewed changes from recent commits (found 1 issue).
1 issue found across 7 files
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="src/ipc/processors/response_processor.ts">
<violation number="1" location="src/ipc/processors/response_processor.ts:233">
`getSupabaseFunctionName(filePath)` resolves to the immediate parent folder, so a write to `supabase/functions/foo/lib/utils.ts` passes `lib` into `deploySupabaseFunctions`. `collectFunctionFiles` then treats `/foo/lib` as the function root and throws because that nested folder has no `index.ts`, so helper module writes fail. Please derive the top-level function slug (e.g. `foo`) before deploying.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
…upport-for-reusable-modules-u332d2
…able-modules-u332d2 Fix Supabase function slug resolution and packaging
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.
Reviewed changes from recent commits (found 2 issues).
2 issues found across 2 files
Prompt for AI agents (all 2 issues)
Understand the root cause of the following 2 issues and fix them.
<file name="src/supabase_admin/supabase_utils.ts">
<violation number="1" location="src/supabase_admin/supabase_utils.ts:23">
Stripping the extension from the first segment causes directories with dots (e.g. supabase/functions/foo.v1/index.ts) to resolve to "foo" instead of "foo.v1", breaking function name detection for those modules.</violation>
</file>
<file name="src/supabase_admin/supabase_management_client.ts">
<violation number="1" location="src/supabase_admin/supabase_management_client.ts:411">
Flattening the function package removes the "supabase/functions/<functionName>" path segment, so existing imports that rely on that directory structure (e.g. "../../shared") will no longer resolve when the function runs. Please keep the app-relative prefix when building stat entries (and update entrypoint_path accordingly) to preserve module resolution.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
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.
Thanks for the PR - it's taking me a while to review this file and I was wondering if you can explain to me why you took this approach. Does Supabase Edge function require a single file (zip) to upload?
When I first saw https://supabase.com/docs/reference/api/v1-deploy-a-function, I thought it would take multiple files since file is an Array<string> but now I'm wondering if I was wrong and it takes a single file.
I tried reading through what Supabase CLI does https://github.com/supabase/cli/blob/891a5df913832f4a99ee24ca1ac515d068b8f80b/internal/functions/deploy/deploy.go#L4 and it seems like they ultimately shell out to some bundler like what you did with esbuild.
I need to think a bit more about what the right approach is because I think bundling esbuild into Dyad would be too heavy handed, but potentially we could use the esbuild inside the user's app directory node_modules (esp. if they are using Vite, which is the case for most Dyad users using supabase).
What do you think? It'd be good to hear your thoughts on the pros and cons of the different options as this is quite a tricky problem (and harder than I expected!)
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.
I've changed it to just directly send files without using esbuild or zip, I'm sorry for the confusion on those commits you saw previously. Those commits before were a rough draft of the updated functionality which is why I marked the branch as draft, however it is more stable and ready to review now.
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.
Reviewed changes from recent commits (found 1 issue).
1 issue found across 1 file
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="src/supabase_admin/supabase_management_client.ts">
<violation number="1" location="src/supabase_admin/supabase_management_client.ts:353">
The generated import map points "shared/" to "../shared/", but for root-level entrypoints (e.g., entrypoint_path = "index.ts") that resolves one level above the uploaded files, so bare specifiers like "shared/foo.ts" will 404 at runtime. Please compute the correct relative path (e.g., "shared/" when entryDir is ".") before serializing the map.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
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.
2 issues found across 8 files
Prompt for AI agents (all 2 issues)
Understand the root cause of the following 2 issues and fix them.
<file name="src/supabase_admin/supabase_management_client.ts">
<violation number="1" location="src/supabase_admin/supabase_management_client.ts:299">
Rewriting `../shared/...` imports to `./shared/...` makes nested files resolve `shared` modules relative to their own subfolders (e.g., `routes/shared/...`), so shared imports break at runtime. Replace the rewrite output with a bare `shared/` specifier so the import map can remap it correctly.</violation>
<violation number="2" location="src/supabase_admin/supabase_management_client.ts:353">
The import map currently rewrites `shared/` to `../shared/`, but the deployed bundle places `shared` next to `index.ts`, so this mapping points outside the bundle and breaks shared imports. Point `shared/` to `./shared/` instead so the runtime resolves the uploaded files correctly.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
Closes #1630
This PR is a duplicate of #1637 because Github closed that when I rebased to clean the slate from esbuild.