vercel / turborepo

Build system optimized for JavaScript and TypeScript, written in Rust
https://turbo.build/repo/docs
MIT License
26.45k stars 1.84k forks source link

[turborepo] prune doesn't support per workspace lockfiles #3541

Open Suniron opened 1 year ago

Suniron commented 1 year ago

What version of Turborepo are you using?

1.7.0

What package manager are you using / does the bug impact?

pnpm

What operating system are you using?

Linux

Describe the Bug

On Linux as WSL2 Windows 10 distro.

I have only one .npmrc file at root which contains this code:

public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*prettier*
public-hoist-pattern[]=*prisma*
shamefully-hoist=true
strict-peer-dependencies=false
auto-install-peers=true
enable-pre-post-scripts=true
shared-workspace-lockfile=false

shamefully-hoist and shared-workspace-lockfile are needed in my configuration but with theese two options.

If i try to prune with this command pnpm turbo prune --scope @myapp/web --verbosity 10, i got this error:

2023-01-31T11:34:53.281+0100 [DEBUG] turborepo_lib::shim: Running local turbo binary in /home/user/development/nodejs/my-project/node_modules/.bin/turbo

Turbo error: could not construct graph: 10 errors occurred:
        * no workspace '' found in lockfile
        * no workspace 'apps/store' found in lockfile
        * no workspace 'packages/config/tailwind-config' found in lockfile
        * no workspace 'packages/config/jest-presets' found in lockfile
        * no workspace 'apps/api' found in lockfile
        * no workspace 'packages/ui' found in lockfile
        * no workspace 'apps/web' found in lockfile
        * no workspace 'packages/config/eslint-config-custom' found in lockfile
        * no workspace '' found in lockfile

Is there a way to prune the project (for Docker) with a .npmrc file like mine ? 🙏

Expected Behavior

Project should be "pruned" in a out folder at root.

To Reproduce

Add a .npmrc file with options like mine and try to prune with any app as scope.

Reproduction Repo

No response

Kuirak commented 1 year ago

I recently had the same issue and the problematic setting is: shared-workspace-lockfile=false because it allows multiple pnpm-lock.yaml and turbo can't handle it yet

Suniron commented 1 year ago

I recently had the same issue and the problematic setting is: shared-workspace-lockfile=false because it allows multiple pnpm-lock.yaml and turbo can't handle it yet

Yes, i see your issue.. 😪

Did you find a solution to build a Docker image ?

chris-olszewski commented 1 year ago

This is something that won't be prioritized, but I'd be willing to help a community PR along to achieve this. Since pnpm is already splitting up the lockfile for us we just need to:

Kuirak commented 1 year ago

I just did some code exploration and I think it is more than that:

Since this is a feature I only know from "classic" lerna (without package manager powered workspaces) and pnpm I don't think this should be included directly in the prune.go file

So option A) would be to extend the PackageManager with a flag that indicates if it is a shared-workspace-lockfile and than implement the detection within each packageManager or option B) would be to just copy lock files if there is one beside a package.json.

I tend to option B) because it would also enable support for "classic" lerna repos.

What do you think @chris-olszewski ?

chris-olszewski commented 1 year ago

I tend to option B)

There still needs to be a way to know when it's okay for our lockfile analysis to fail during prune. I think it's fine to extend the PackageManager with a method to check if we should expect multiple lockfiles and only implement it for pnpm. From some quick looking around it looks like pnpm is the only package manager that supports multiple lockfiles when using workspaces.

support for "classic" lerna repos

Support for classic lerna repos is more of an ask and should probably be implemented independent of this one. I see you opened #3648 and I'll follow up with the team there.