Skip to content

Commit

Permalink
feat(prune) allow pruning of projects using Yarn PnP (#5019)
Browse files Browse the repository at this point in the history
### Description

We have had Yarn2+ support* for quite awhile now. This PR is one of the
final steps to remove that asterisks and allow Yarn PnP to be used.

A note is that we currently don't copy over the `.pnp.cjs` file or the
`.yarn/cache` which are required for [zero
installs](https://yarnpkg.com/features/zero-installs). We skip this a
naive copy would cause Docker cache misses in the same way a naive copy
of the lockfile would. Future work can include correctly pruning this
file and directory to allow for the `yarn install` on a cache miss to be
even faster.

### Testing Instructions

Manual testing that `yarn install --immutable` works for PnP projects.

Added an integration test that verifies we no longer throw when trying
to prune a PnP project and that we don't copy over files that would bust
the cache.

---------

Co-authored-by: Chris Olszewski <Chris Olszewski>
  • Loading branch information
chris-olszewski committed May 19, 2023
1 parent 29ea4ab commit e4dc7dc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 38 deletions.
7 changes: 0 additions & 7 deletions cli/internal/packagemanager/berry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"fmt"
"strings"

"github.com/pkg/errors"
"github.com/vercel/turbo/cli/internal/fs"
"github.com/vercel/turbo/cli/internal/lockfile"
"github.com/vercel/turbo/cli/internal/turbopath"
"github.com/vercel/turbo/cli/internal/util"
)

var nodejsBerry = PackageManager{
Expand Down Expand Up @@ -41,11 +39,6 @@ var nodejsBerry = PackageManager{
},

canPrune: func(cwd turbopath.AbsoluteSystemPath) (bool, error) {
if isNMLinker, err := util.IsNMLinker(cwd.ToStringDuringMigration()); err != nil {
return false, errors.Wrap(err, "could not determine if yarn is using `nodeLinker: node-modules`")
} else if !isNMLinker {
return false, errors.New("only yarn v2/v3 with `nodeLinker: node-modules` is supported at this time")
}
return true, nil
},

Expand Down
2 changes: 1 addition & 1 deletion cli/internal/packagemanager/packagemanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func Test_CanPrune(t *testing.T) {
assert.NilError(t, err, "GetCwd")
wants := map[string]want{
"nodejs-npm": {true, false},
"nodejs-berry": {false, true},
"nodejs-berry": {true, false},
"nodejs-yarn": {true, false},
"nodejs-pnpm": {true, false},
"nodejs-pnpm6": {true, false},
Expand Down
30 changes: 0 additions & 30 deletions cli/internal/util/backends.go

This file was deleted.

15 changes: 15 additions & 0 deletions turborepo-tests/integration/tests/prune/yarn-pnp.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup.sh
$ . ${TESTDIR}/../_helpers/copy_fixture.sh $(pwd) berry_resolutions
Remove linker override
$ rm .yarnrc.yml
Prune the project
$ ${TURBO} prune --scope=a
Generating pruned monorepo for a in .*out (re)
- Added a

Verify that .pnp.cjs isn't coppied causing unnecessary cache misses
$ ls -A out/
package.json
packages
yarn.lock

0 comments on commit e4dc7dc

Please sign in to comment.