Symlinks in Monorepos

Ikechi Michael
1 min readFeb 29, 2024

What if you could:

  • Sync commonly referenced files across projects in a monorepo?

So that:

  • You only edit common config files once, and all projects using it get updated.

For example:

  • tsconfig.json
  • .npmrc
  • .nvmrc
  • index.html

Oh, how?

Use Symlinks.

Wait, what? Won’t that cause version-control issues? And don’t Symlinks differ across operating systems?

Ignore them in version-control, so they get re-created on every machine.

How would they get re-created?

Git Hooks, running on post-checkout.

And how would we know which symlinks to create?

Use a config file e.g. symlinks.yml in the root of your repo with format:

/path/to/source:
- /path/to/symlink/1
- /path/to/symlink/2
- /path/to/symlink/n
/foo:
- /bar/foo
- /baz/foo

Are those absolute paths? Symlink paths are usually relative.

All the paths in the config are relative to the root of the repo, because we need a common starting point to avoid confusion.

Okay, what next?

Write the script.

What script?

THE Script!

npx @mykeels/symlinks

--

--

Ikechi Michael

I’ve learned I don’t know anything. I've also learned that people will pay for what I know. Maybe that's why they never pay.