Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip in-workspace devDependencies when pruning #1100

Open
marvinroger opened this issue Apr 22, 2022 · 11 comments
Open

Strip in-workspace devDependencies when pruning #1100

marvinroger opened this issue Apr 22, 2022 · 11 comments
Labels
area: ergonomics Issues and features impacting the developer experience of using turbo area: prune turbo prune

Comments

@marvinroger
Copy link

Describe the feature you'd like to request

Hi,

First of all, thanks for this awesome project, it's really powerful!

We're currently using the great turbo prune feature, and we noticed a potential optimization.
Imagine a project app having two "in-workspace" dependencies:

  • lib-config as a dependency
  • tooling as a devDependency

Currently, running turbo prune --scope=app will generate a directory out/ with app, lib-config and tooling.
In our case, we run turbo prune in our CI after all packages have been built. Therefore, we don't need the devDependencies in our out/ directory.

Ideally, our pruned out/ directory would contain only app and lib-config, which are the only packages needed at runtime.

Describe the solution you'd like

Having an optional --production flag that would ignore the devDependencies would be great.

Describe alternatives you've considered

I don't think there are any alternatives, except keeping the devDependencies, which is frankly not a big deal. It's just less optimal... But, isn't Turborepo all about optimization? 😉

@Ghirigoro
Copy link

Ghirigoro commented Jul 6, 2022

This not always just a question of optimizing file size. I have a situation with a backend project that is strictly node, but uses some browser-based utilities when testing. In order to build those browser dependencies that get pulled in I also have to manually pull in the resources required to build those dependencies (for example I have separate base tsconfig.json files for node and for browser at the root of the monorepo). It's not the end of the world but you start to quickly lose the point of pruning if you're pulling in half your monorepo and littering your docker images with resources that are only used to workaround this issue.

P.S. - I'm realizing my tone probably comes off as more stern than I mean to. I agree it's not a huge deal but it would make Turborepo even more awesome if it wasn't the case :)

@azertyalex
Copy link

azertyalex commented Jan 20, 2023

@joemckenney care to share your rm-dev-deps.mjs script referenced in issue #1488 ?
I'm having the same problem as you, 1GB docker image

@joemckenney
Copy link

joemckenney commented Jan 20, 2023

@joemckenney care to share your rm-dev-deps.mjs script referenced in issue #1488 ? I'm having the same problem as you, 1GB docker image

@azertyalex Here's a gist https://gist.github.com/joemckenney/fd55f02ab0bf905283423aadeeca80ca

The script uses a package we built called @dopt/wutils - which assumes you use pnpm. It's open source but not published to any registry - you can find it here https://github.com/dopt/odopt/tree/main/packages/%40dopt/wutils and take inspiration from it or copy pieces to recreate the functionality.

Some additional context - this problem was solved by our shift from yarn to pnpm and pnpm's deploy command.

@azertyalex
Copy link

okay, thanks! I stumbled upon pnpm myself in the last hour, that seems the way to go

@gajus
Copy link

gajus commented May 14, 2023

Tagging core team member to make sure this gets seen since it is a pretty major issue @gsoltis

Annoyingly, pnpm v8 introduced a regression where it broke pnpm deploy so there isn't even a fallback option.

Related pnpm issues:

@mehulkar mehulkar added story area: ergonomics Issues and features impacting the developer experience of using turbo area: prune turbo prune labels Oct 20, 2023
@mehulkar
Copy link
Contributor

A --production flag does seem like a good idea.

cc @chris-olszewski, how hard would this be to do? I got a little lost reading the prune code with the transitive_closure stuff, so I wasn't able to get an easy answer

@mehulkar mehulkar added the needs: team input Filter for core team meetings label Oct 20, 2023
@chris-olszewski chris-olszewski removed the needs: team input Filter for core team meetings label Nov 27, 2023
@chris-olszewski
Copy link
Member

This is something we do want to add, but a few things need to happen first:

  • We need to change our package graph to contain what dependency types in the edges. This is a fairly straight forward change, but it will be pretty invasive throughout the codebase.
  • Come to agreement on flag naming
    Once those are done, this feature will just be using the correct package graph in prune.

@anthonyshew anthonyshew removed the story label Feb 22, 2024
@mehulmpt
Copy link

Faced this today where one of our packages required some devDependencies for building it but turbo prune is pulling them inside production build the way our pipeline is built. We have to write a workaround for this but it would be great if it was natively available.

@wrporter
Copy link

Just came across this problem when dockerizing my app today. The only decent workaround I could think of is to extract packages that are devDependencies in my apps to a separate repo, publish those to a registry, and install them that way. Definitely not a great workaround in cases where you don't want to publish those.

wrporter added a commit to wrporter/starter-monorepo that referenced this issue Jul 26, 2024
- This required a lot of changes and some configs/plugins still haven't updated yet, so will have to wait until they do (e.g. eslint-plugin-jsx-a11y).
- Removed airbnb configs in favor of using default recommended rules.
- Updated prettier config to use more of the defaults rather than deviating.
- Fixed an issue with the `update-package-lock` npm script where using `rm` didn't actually delete the files for some reason. Switched to `rimraf` and it works.
- Added more `tsconfig.eslint.json` files to packages/apps so files that shouldn't be part of the bundle don't get transpiled to the build/dist directory.
- Fixed issues with the Docker build where the full node_modules were not being pulled in. I wonder if there was a caching issue that masked the bug because apps should not have been able to run. We can either extract packages and publish them to npm or live with massive Docker images until Turbo fixes the issue. See vercel/turborepo#1100
@WINOFFRG
Copy link

Facing same issue my workspace has some tooling packages in devDeps and they are getting bundled in image. Some packages like prettier typescript are quite heavy like 22MB

image

@abcdefghiraj
Copy link

I spent some time struggling with the same issue. I am using pnpm and I tried pnpm deploy, but that messes with the symlinks. If I add the option to inject, then turbo complains.

Till there is a fix, here is a possible workaround -
I'm compiling the build output to a single file (using vercel/ncc - can also be tsup or something similar) and only copying that output to the final layer of my docker image, and I am at a third of the previous size. Be mindful of the pitfalls of this approach and make sure you test all code paths by bundling and running this locally before going to production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ergonomics Issues and features impacting the developer experience of using turbo area: prune turbo prune
Projects
None yet
Development

No branches or pull requests