While there’s ongoing debate about AI replacing programmers, our recent experience suggests a more grounded reality of AI being a powerful assistant for complex engineering tasks. During the recent migration of our Cashgram project’s framework from Sapper to SvelteKit, we used GitHub Copilot in agent mode to speed up what was originally a two-week-long effort. 

However, with AI’s support and our engineers’ expertise, we were able to complete the migration in less than two days.

Why Migrate from Sapper to SvelteKit?

Sapper, the original Svelte application framework, was officially deprecated in favour of SvelteKit. 

Also, SvelteKit offers several advantages:

  1. Better performance through Vite’s dev server
  2. Improved routing system
  3. Enhanced SSR capabilities
  4. Better TypeScript support
  5. Active maintenance and community support

Our Approach

Instead of spending days manually refactoring, we accelerated the process using GitHub Copilot in Agent mode. Here’s how we implemented it:

  1. Clear Documentation Reference: We provided Copilot with the official migration guide from the Svelte documentation
  2. Iterative Prompting: When Copilot’s first solutions weren’t perfect, we refined our prompts with more context
  3. File-by-File Migration: We tackled the migration file by file, starting with configuration files

Key Migration Wins

Purging Unnecessary Files and Folders

One of the initial tasks Copilot helped with was identifying and removing Sapper-specific files and folders that were no longer needed in SvelteKit. This included:

  1. Removing Sapper-specific Server middleware
  2. Eliminating Sapper manifest files
  3. Cleaning up deprecated template structures

This cleanup phase was critical as it prevented confusion between old and new code patterns and reduced the potential for conflicts. Copilot effectively identified these obsolete elements and suggested appropriate removals.

Bundling Migration: From Rollup to Vite

A significant part of the migration involved transitioning from Rollup (used by Sapper) to Vite (used by SvelteKit). This wasn’t simply a matter of renaming files but required fundamental changes to how the project was configured:

  1. Converting `rollup.config.js` to `vite.config.js`
  2. Updating plugin configurations to their Vite equivalents
  3. Reconfiguring asset handling for Vite’s approach

The bundler change had cascading effects throughout the project, particularly with environment variables. Copilot excelled here by suggesting multiple approaches for environment variable handling. It explained the tradeoffs of each approach, helping me make informed decisions based on our specific project needs.

Intelligent File Analysis

One of the most impressive aspects of working with GitHub Copilot was its ability to autonomously analyse files and determine whether they needed changes or could remain as-is. 

The agent would:

  1. Identify files that required no migration changes
  2. Highlight files needing significant restructuring
  3. Prioritise files with dependencies that need to be migrated first

This autonomous categorisation saved significant time that would otherwise have been spent manually reviewing every file in the project. For larger codebases, this kind of intelligent triage becomes increasingly valuable.

Routing Changes

SvelteKit uses a file-based routing system that differs from Sapper’s approach. The Copilot assisted in:

  1. Converting routes from `src/routes` to the proper SvelteKit structure
  2. Updating all route parameters to use the SvelteKit syntax
  3. Addressing load function changes

Challenges and Limitations

GitHub Copilot wasn’t perfect. We encountered several situations where human intervention was necessary:

  1. Custom Configurations: Copilot sometimes misses project-specific configurations
  2. Edge Cases: Some complex routing edge cases required manual fixes
  3. Environment Setup: Getting the .gitignore file properly updated for `.sveltekit` folders and other new artifacts required human experience

Results and Lessons Learned

By the end of the second day, our application was fully migrated and working in the new SvelteKit environment. Some key lessons:

  1. AI Augmentation Works: Most of the repetitive and mechanical migration work was handled by Copilot, while human effort was reserved for the nuanced, high-impact decisions. 
  2. Context is King: The more context we provided to Copilot, the better its solutions became
  3. Human Verification Critical: We still needed to review all changes and occasionally fix edge cases
  4. Migration Documentation Helps: Providing Copilot with official migration guides significantly improved results

This migration is just the beginning. We are excited to explore how AI tools can continue to scale our engineering capabilities at Cashfree. 

Discover more from Cashfree Payments Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading