Skip to content

Latest commit

 

History

History
199 lines (153 loc) · 5.66 KB

File metadata and controls

199 lines (153 loc) · 5.66 KB

Deno Bundle Fix Summary

Issue Description

The GitHub Actions security scan workflow was using the deprecated deno bundle command, which was removed in Deno 2.x. This caused the workflow to fail with errors like:

error: `deno bundle` was removed in Deno 2.

Root Cause

The deno bundle command was deprecated and removed in Deno 2.0+ in favor of more modern bundling solutions like:

  • Third-party bundlers (Vite, esbuild, etc.)
  • deno compile for creating standalone executables
  • Native ES modules and HTTP imports

Solution Implemented

Approach: Direct Source Size Analysis (Recommended)

We replaced the bundle size analysis with a direct source size calculation that:

  1. Sums all relevant TypeScript files in the project
  2. Provides the same size warnings as the original bundle analysis
  3. Works reliably across all Deno versions
  4. Gives more accurate insights into actual source code size

Implementation Details

The new analysis calculates total source size by examining:

  • main.ts - Main application file
  • test_*.ts - All test files matching the pattern
  • src/*.ts - Any source files in src/ directory (if present)
# Calculate total source size
total_size=0

# Add main.ts
main_size=$(stat -f%z main.ts 2>/dev/null || stat -c%s main.ts)
total_size=$((total_size + main_size))

# Add test files
for test_file in test_*.ts; do
  if [ -f "$test_file" ]; then
    test_size=$(stat -f%z "$test_file" 2>/dev/null || stat -c%s "$test_file")
    total_size=$((total_size + test_size))
  fi
done

# Add src files (if directory exists)
if [ -d "src" ]; then
  src_size=$(find src -name "*.ts" -type f -exec stat -f%z {} + 2>/dev/null | awk '{sum+=$1} END {print sum+0}')
  total_size=$((total_size + src_size))
fi

Size Thresholds

The same warning thresholds are maintained:

  • >1MB: Large size warning
  • >512KB: Moderate size warning
  • <512KB: Reasonable size ✅

Additional Enhancement: Compiled Executable Analysis

As a bonus feature, we also added optional compiled executable size analysis using deno compile:

if deno compile --output proxy-executable main.ts 2>/dev/null; then
  executable_size=$(stat -f%z proxy-executable 2>/dev/null || stat -c%s proxy-executable)
  ratio=$((executable_size / total_size))
  echo "Compilation ratio: ${ratio}x"
fi

This provides insights into:

  • How the compiled executable size compares to source
  • Compilation overhead and efficiency
  • Deployment artifact size for standalone distributions

Results

Before (Broken)

❌ error: `deno bundle` was removed in Deno 2.
Bundle size analysis FAILED

After (Working)

✅ Source size analysis:
main.ts: 8820 bytes
test_openai_responses_simple.ts: 8056 bytes
test_openai_responses.ts: 16424 bytes
test_server_startup.ts: 2230 bytes
Total source size: 35530 bytes (34 KB)
✅ Source size is reasonable (<512KB)

📦 Compiled executable: 86838078 bytes
📈 Compilation ratio: 2444x

Benefits of the New Approach

1. Deno 2.x Compatibility

  • Works with all modern Deno versions
  • No dependency on deprecated commands
  • Future-proof implementation

2. More Accurate Analysis

  • Measures actual source code size
  • Includes all relevant project files
  • Better reflects development complexity

3. Enhanced Insights

  • Source vs compiled size comparison
  • File-by-file breakdown
  • Compilation efficiency metrics

4. Cross-Platform Compatibility

  • Works on macOS (stat -f%z) and Linux (stat -c%s)
  • Handles missing files gracefully
  • Robust error handling

5. Maintainable and Extensible

  • Clear, readable shell script logic
  • Easy to add new file patterns
  • Configurable thresholds

Testing

A comprehensive test script (test_source_size.sh) was created to validate the logic:

./test_source_size.sh
✅ SUCCESS: Source size calculation logic works correctly
   - Files found: 4
   - Total source size: 35530 bytes
   - Size category: Reasonable <512KB

Migration Guide

If you have similar deno bundle usage in your projects:

Replace This:

- name: Bundle size analysis
  run: |
    deno bundle main.ts bundle.js
    bundle_size=$(stat -c%s bundle.js)
    echo "Bundle size: $bundle_size bytes"

With This:

- name: Source size analysis
  run: |
    total_size=0
    for file in main.ts test_*.ts; do
      if [ -f "$file" ]; then
        size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file")
        total_size=$((total_size + size))
      fi
    done
    echo "Total source size: $total_size bytes"

Alternative Solutions Considered

Option 1: Third-party Bundlers

  • Vite: Modern bundler with excellent Deno support
  • esbuild: Fast bundler with TypeScript support
  • Pros: Industry standard, feature-rich
  • Cons: Additional dependencies, complexity

Option 2: deno compile Only

  • Approach: Use compiled executable size as metric
  • Pros: Real deployment artifact size
  • Cons: Much larger than source (2000x+), less useful for development

Option 3: Source Size Analysis (Chosen)

  • Approach: Sum actual source file sizes
  • Pros: Simple, accurate, no dependencies
  • Cons: Doesn't reflect final bundle optimizations

Conclusion

The direct source size analysis provides a practical, maintainable solution that:

  • ✅ Fixes the Deno 2.x compatibility issue
  • ✅ Provides meaningful size metrics for development
  • ✅ Maintains the same warning thresholds
  • ✅ Adds valuable compilation insights
  • ✅ Works reliably across platforms

This approach balances simplicity with functionality, giving developers the information they need to monitor code size growth without the complexity of external bundlers.