Skip to content

Conversation

@SlayTheDragons
Copy link
Contributor

@SlayTheDragons SlayTheDragons commented Oct 29, 2025

Closes #1630

This PR is a duplicate of #1637 because Github closed that when I rebased to clean the slate from esbuild.

@SlayTheDragons SlayTheDragons marked this pull request as draft October 29, 2025 07:37
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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

@SlayTheDragons
Copy link
Contributor Author

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
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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 &quot;foo&quot; instead of &quot;foo.v1&quot;, 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 &quot;supabase/functions/&lt;functionName&gt;&quot; path segment, so existing imports that rely on that directory structure (e.g. &quot;../../shared&quot;) 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.

Copy link
Contributor

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!)

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'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.

@SlayTheDragons SlayTheDragons marked this pull request as ready for review October 30, 2025 00:33
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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 &quot;shared/&quot; to &quot;../shared/&quot;, but for root-level entrypoints (e.g., entrypoint_path = &quot;index.ts&quot;) that resolves one level above the uploaded files, so bare specifiers like &quot;shared/foo.ts&quot; will 404 at runtime. Please compute the correct relative path (e.g., &quot;shared/&quot; when entryDir is &quot;.&quot;) 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.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants