Source:
ocean/docs/adr/021-edge-function-dependency-management.md| ✏️ Edit on GitHub
ADR-021: Edge Function Dependency Management
Date: 2024-08-20
Status
Accepted
Context
Our Edge Functions failed due to inconsistent dependency management:
- Different functions using different Sentry import patterns (legacy vs npm)
- Missing dependencies in deno.json files
- No centralized dependency version management
- Functions using deprecated or incompatible APIs
This caused runtime errors that were difficult to debug because functions would fail to start without clear error messages.
Decision
We will standardize Edge Function dependency management:
- Use NPM imports exclusively for third-party dependencies
- Centralize dependency versions where possible
- Explicit dependency declaration in deno.json for each function
- Regular dependency audits to catch deprecated APIs
Standards
-
Import Pattern:
// ✅ Good - NPM import with version
import * as Sentry from 'npm:@sentry/deno@7.119.2'
// ❌ Bad - Legacy Deno import
import * as Sentry from 'https://deno.land/x/sentry/index.mjs' -
Deno.json Structure:
{
"imports": {
"@supabase/supabase-js": "npm:@supabase/supabase-js@2.54.0",
"@sentry/deno": "npm:@sentry/deno@7.119.2",
"stripe": "npm:stripe@18.4.0"
}
} -
Shared Dependencies:
- Create
_shared/deps.tsfor common versions - Import from shared file in individual functions
- Create
-
Version Pinning:
- Always pin to specific versions, not ranges
- Document reason for version choices
- Update all functions together
Consequences
Positive
- Consistent behavior across all Edge Functions
- Easier to debug dependency issues
- Prevents version mismatch bugs
- Clearer dependency tree
Negative
- More verbose import declarations
- Need to update multiple files for version changes
- Potential for larger bundle sizes if not careful
Migration Path
- Audit all Edge Functions for import patterns
- Create deno.json for functions missing it
- Update all imports to use npm pattern
- Test each function after updates
- Document any API changes needed