• Will Chen's avatar
    Support shared modules for supabase edge functions (#1964) · 91cf1e97
    Will Chen 提交于
    Credit: thanks @SlayTheDragons whose PR
    https://github.com/dyad-sh/dyad/pull/1665 paved the way for this
    implementation.
    
    <!-- CURSOR_SUMMARY -->
    > [!NOTE]
    > Adds _shared module support for Supabase edge functions with
    import-map packaging and automatic redeploys; updates deployment to
    include full function directories plus shared files, and adds path
    utilities and tests.
    > 
    > - **Supabase Edge Functions**
    > - **Shared Modules Support**: Detect `_shared` changes and redeploy
    all functions; regular function changes deploy only that function.
    > - **Deployment Overhaul**: `deploySupabaseFunctions` now uploads full
    function directories plus `_shared` files via multipart form-data, sets
    `entrypoint_path`, and writes `import_map.json` (`_shared/` →
    `../_shared/`).
    > - **Function Discovery & Packaging**: Add file collection helpers
    (`listFilesWithStats`, `loadZipEntries`) and path utilities
    (`toPosixPath`, `findFunctionDirectory`, `stripSupabaseFunctionsPrefix`)
    with signature-based caching for `_shared`.
    > - **APIs & Utils**: Introduce `isSharedServerModule`, refine
    `isServerFunction` (excludes `_shared`), add
    `extractFunctionNameFromPath`, and `buildSignature`.
    > - **IPC Changes**
    > - Update file edit/rename/delete flows to track shared module edits
    and trigger full redeploys; otherwise deploy per-function using
    extracted name and `appPath`.
    > - **Prompts**
    >   - Document `_shared` usage and import pattern in Supabase prompt.
    > - **Tests**
    > - Add tests for function/shared detection, name extraction, path
    handling, and signature building.
    > 
    > <sup>Written by [Cursor
    Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
    f35599ec0e708e2ef6b7e78ae7901b29953a6dff. This will update automatically
    on new commits. Configure
    [here](https://cursor.com/dashboard?tab=bugbot).</sup>
    <!-- /CURSOR_SUMMARY -->
    
    
    
    
    
    
    
    
    
    <!-- This is an auto-generated description by cubic. -->
    ---
    ## Summary by cubic
    Adds support for shared modules for Supabase edge functions. Shared code
    in supabase/functions/_shared is now bundled via an import map and
    triggers redeploys across all functions when changed.
    
    - **New Features**
    - Detects shared modules in supabase/functions/_shared and redeploys all
    functions when they change.
    - Deploys full function directories plus shared files, and writes an
    import_map.json that resolves "_shared/" imports.
    - Auto-deploys only the affected function on file changes; switches to
    redeploy-all when a shared module is touched.
    
    - **Refactors**
    - deploySupabaseFunction now uploads multiple files (function + shared)
    using multipart form-data and sets entrypoint/import map.
    - Added file collection, path utilities, and shared-file caching via
    content signatures to reduce redundant reads.
    - Updated deployAllSupabaseFunctions to skip non-function dirs (e.g.,
    _shared) and use functionPath.
    - Added tests for function/shared detection, path handling, and
    signature building.
    
    <sup>Written for commit 302d84625d9e61477db9ada052a027b29ff18cef.
    Summary will update automatically on new commits.</sup>
    
    <!-- End of auto-generated description by cubic. -->
    91cf1e97
supabase_utils.ts 4.1 KB