cms icon indicating copy to clipboard operation
cms copied to clipboard

Migrating to Turborepo (incrementally)

Open aryanprince opened this issue 1 year ago • 3 comments

Summary

To migrate the current repo to a monorepo setup using Turborepo. This will allow us to have multiple different applications (like marketing, Discord Bot, so on) in the same repo, while having shared common packages between each other.

Pros

  1. Improved DX for repetitive tasks such as building, linting, and formatting.
  2. Will allow us to keep the main 100x dashboard, (future) Discord Bot, marketing sites, and other apps in the future in one place. Ensuring all apps can share packages across each other (such as various configs and Tailwind for example).
  3. Saving both time and money in CI - by leveraging Turborepo's Remote Cache.
  4. Improved local dev experience since build caches can be reused by all contributors.
  5. ...and not to mention, every other benefit of having a monorepo fundamentally such as allowing shared packages to be updated locally and seeing live changes on the apps importing shared packages.

Cons

  1. Deployments will need to be updated to new directory inside the monorepo (updating deployment directory to apps/web for example)
  2. Will need to update the Docker Compose script to ensure it works with the new Turborepo setup.

The Plan

Make a very minimal migration to Turborepo. By this, I mean we use a 2 step approach to the migration in order to keep minimal diffs and manageable PRs/reviews.

  • [ ] Step 1. Move the main Nextjs application as is to a folder like apps/web first. This is done to produce as little diffs in the PR as possible, ensuring the first PR is very focused and can be reviewed better.
  • [ ] Step 2: Later, refactor common packages like ESLint, TS config, Tailwind, and so on to their respective packages in subsequent PRs later on.

My Experience

I've incrementally migrated from a single Next.js app to a monorepo setup with Turborepo with 3 different Next.js apps here.

aryanprince avatar Mar 16 '24 14:03 aryanprince

@hkirat If this is something on the roadmap, can I be assigned to this as I’ve already initiated work on it? Thanks.

aryanprince avatar Mar 16 '24 14:03 aryanprince

this is great

hkirat avatar Mar 17 '24 08:03 hkirat

Progress

For now, I have managed to successfully migrate the entire codebase to Turborepo (with pnpm workspaces). Everything works well in my fork for the time being (link here). However, there are several blockers that need to be addressed before I submit my PR.

Blockers

There are currently 2 blocking issues/PRs:

  1. There are a large number of conflicting ESLint and Prettier config rules.

PR #244 plans to fix this blocker.

  1. There are missing migration files from the last DB schema change (part of merged PR #170).

PR #242 plans to solve this minor issue.


I will make my PR after these changes have been merged to ensure minimal overlapping changes and cleaner diff during the (huge - around 195 files currently) monorepo migration PR.

aryanprince avatar Mar 18 '24 15:03 aryanprince