oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.84k stars 2.56k forks source link

Separate lockfiles for monorepo packages #5450

Open cbilotta opened 9 months ago

cbilotta commented 9 months ago

What is the problem this feature would solve?

Hello,

I am currently using a monorepo setup containing local packages as git submodules. This has two advantages:

One of the issues with this setup is that the lockfile should not be shared (should not be in the root of the monorepo) in order to keep caching working as it should, but also so developers don't trigger changes to the root lockfile simply because they don't have access to one of the sub-module.

As far as I understand, currently Bun can not split the lockfiles into the folders of the respective workspace members when using the "workspaces" monorepo configuration.

What is the feature you are proposing to solve the problem?

It would be great to have a feature such as shared-workspace-lockfile from pnpm.

What alternatives have you considered?

Not using the "workspaces" package.json configuration field and linking packages myself, but it's not that straightforward to do and I imagine I would have to launch dependencies install scripts in all submodules which is not great.

1hko commented 2 months ago

Aside from using git submodules, this is the exact problem I am encountering. I'm having a heck of a time trying to get cached builds using a monorepo with standard "workspaces" configuration.

The bun docker guide does not account for monorepo. The bun install --frozen-lockfile fails first because the workspace directories are not present. To fix this, you have to copy your source packages (dependencies) to the install directory. This creates a new problem though, changes to a source package will now invalidate the build cache, requiring a cold install on each build.

Maybe bun install could have more granular control like -w/-W to install workspace dependencies as a separate step? 🤷‍♀️

1hko commented 2 months ago

Related: https://github.com/oven-sh/bun/issues/6353

Maybe bun fetch is a better solution