From e4dc7dc2a60f12de267453ef420b7e00f66ff76f Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Fri, 19 May 2023 09:44:56 -0700 Subject: [PATCH] feat(prune) allow pruning of projects using Yarn PnP (#5019) ### 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 --- cli/internal/packagemanager/berry.go | 7 ----- .../packagemanager/packagemanager_test.go | 2 +- cli/internal/util/backends.go | 30 ------------------- .../integration/tests/prune/yarn-pnp.t | 15 ++++++++++ 4 files changed, 16 insertions(+), 38 deletions(-) delete mode 100644 cli/internal/util/backends.go create mode 100644 turborepo-tests/integration/tests/prune/yarn-pnp.t diff --git a/cli/internal/packagemanager/berry.go b/cli/internal/packagemanager/berry.go index b1964468f2f04..2bcb12c8ea062 100644 --- a/cli/internal/packagemanager/berry.go +++ b/cli/internal/packagemanager/berry.go @@ -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{ @@ -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 }, diff --git a/cli/internal/packagemanager/packagemanager_test.go b/cli/internal/packagemanager/packagemanager_test.go index 012094215b26f..ef79b6d8e12f8 100644 --- a/cli/internal/packagemanager/packagemanager_test.go +++ b/cli/internal/packagemanager/packagemanager_test.go @@ -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}, diff --git a/cli/internal/util/backends.go b/cli/internal/util/backends.go deleted file mode 100644 index 66941ad71839e..0000000000000 --- a/cli/internal/util/backends.go +++ /dev/null @@ -1,30 +0,0 @@ -package util - -import ( - "fmt" - "io/ioutil" - "path/filepath" - - "github.com/vercel/turbo/cli/internal/yaml" -) - -// YarnRC Represents contents of .yarnrc.yml -type YarnRC struct { - NodeLinker string `yaml:"nodeLinker"` -} - -// IsNMLinker Checks that Yarn is set to use the node-modules linker style -func IsNMLinker(cwd string) (bool, error) { - yarnRC := &YarnRC{} - - bytes, err := ioutil.ReadFile(filepath.Join(cwd, ".yarnrc.yml")) - if err != nil { - return false, fmt.Errorf(".yarnrc.yml: %w", err) - } - - if yaml.Unmarshal(bytes, yarnRC) != nil { - return false, fmt.Errorf(".yarnrc.yml: %w", err) - } - - return yarnRC.NodeLinker == "node-modules", nil -} diff --git a/turborepo-tests/integration/tests/prune/yarn-pnp.t b/turborepo-tests/integration/tests/prune/yarn-pnp.t new file mode 100644 index 0000000000000..ef677ae2f5933 --- /dev/null +++ b/turborepo-tests/integration/tests/prune/yarn-pnp.t @@ -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