No More Hustleporn: What It's Like to Migrate a Codebase


Tweet by Andrew Lunny

https://twitter.com/alunny/

dachshund owner, frontend engineering at @stripe


Over the weekend, my team at @stripe converted the company's largest JS codebase from Flow to @typescript. We modified about 3.5 million lines of code, and then hundreds of developers came in Monday morning ready to write TS.

Why? Flow had served us well since 2016, but TypeScript had clearly won over the frontend community, and the TS team has done a fantastic job with tooling and support. We want new developers at Stripe to write TS from day one.

We were heavily inspired by @calebmer and @umbrant's migration at Airtable medium.com/airtable-eng/t…
We used their codemod as the basis for the migration.

The continual evolution of Airtable’s codebase: Migrating a million lines of code to TypeScript

Our biggest tweak was to run the codemod in two passes: once to generate ts{,x} files, and second time to auto-suppress errors.

Why suppress errors? We want to improve the developer experience for Stripe engineers; the biggest win was to start using TS's superlative tools. Once the big jump to the new tooling was behind us, we could ramp up strictness, performance, coverage as needed.

Because of the size of our codebase, we had to introduce project references into a monolithic and entangled codebase, to keep tsc memory usage somewhat reasonable.

We then took on the painstaking work of writing patch files, update code generators, and fixing new errors, while continuing to rebase and merge against the moving target of the Flow codebase.

And then the unenviable task of updating other dependencies–Jest, ESlint, webpack–to play nicely with the TypeScript code. And a lot of manual testing in QA to be safe.

We knew we would want to lock the Stripe monorepo to merge such a huge change. Since we're a global company, the only feasible time was at the weekend, before our coworkers in Tokyo and Singapore would come online Monday morning.

On Sunday we locked the repo, merged the change and… everything worked? (well okay, some things broke, but we fixed them quickly)

End to end, it took us about a year from initial plans to shipping, including adding TS type definitions to our shared design system.

We're very fortunate to be in an organization that lets us take on gnarly problems and drive them to a solution, even as we had to shift focus a few times along the way.

There are still several codebases to tackle, but this milestone puts the single biggest one behind us, and makes life better for hundred of our coworkers.

My personal role was to go to meetings and ask "But could we do it sooner?" All the credit goes to the amazing team @tylerkrupicka @ken_kenware @partyfists @natanlafon and some other folks too smart to be on Twitter.

If doing boring work over a long period of time to improve the lives of your fellow engineers sounds appealing, we're hiring! stripe.com/jobs/listing/f…

Frontend Platform Engineer, Developer Productivity - Stripe: Job Openings

Folks from under-represented groups are encouraged to apply; if you have any questions about the team or the role, my DMs are open.

We work in North American timezones but Stripe has teams across the globe; I'm happy to redirect anyone who's interested.