Skip to content

Commit

Permalink
fix: no longer crash for single projects with global dependencies (#5002
Browse files Browse the repository at this point in the history
)

### Description

Fixes #4914, this is the pnpm implementation of #4240

Was caused as `pnpm` when calculating ignores touches the file system
and will error if `pnpm-workspace.yaml` isn't present. This also avoids
failing on the rare case of someone using turbo on a single project with
no external dependencies as pnpm won't create a lockfile in this case.

### Testing Instructions

Added integration test for a single project using pnpm with global
dependencies

---------

Co-authored-by: Chris Olszewski <Chris Olszewski>
  • Loading branch information
chris-olszewski authored May 18, 2023
1 parent f886022 commit ef9f6b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cli/internal/packagemanager/pnpm.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package packagemanager

import (
"errors"
"fmt"
stdfs "io/fs"
"strings"

"github.com/vercel/turbo/cli/internal/fs"
Expand Down Expand Up @@ -58,6 +60,10 @@ func getPnpmWorkspaceIgnores(pm PackageManager, rootpath turbopath.AbsoluteSyste
}
pkgGlobs, err := readPnpmWorkspacePackages(rootpath.UntypedJoin("pnpm-workspace.yaml"))
if err != nil {
// If workspace file doesn't exist we shouldn't error as we might be a single package repo
if errors.Is(err, stdfs.ErrNotExist) {
return ignores, nil
}
return nil, err
}
for _, pkgGlob := range pkgGlobs {
Expand Down
4 changes: 3 additions & 1 deletion cli/internal/run/global_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ func getGlobalHashInputs(
if lockFile == nil {
// If we don't have lockfile information available, add the specfile and lockfile to global deps
globalDeps.Add(filepath.Join(rootpath.ToStringDuringMigration(), packageManager.Specfile))
globalDeps.Add(filepath.Join(rootpath.ToStringDuringMigration(), packageManager.Lockfile))
if rootpath.UntypedJoin(packageManager.Lockfile).Exists() {
globalDeps.Add(filepath.Join(rootpath.ToStringDuringMigration(), packageManager.Lockfile))
}
}

// No prefix, global deps already have full paths
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup.sh
$ . ${TESTDIR}/../_helpers/setup_monorepo.sh $(pwd) single_package pnpm@8.0.0

We only care about this running sucessfully and not the json output
$ ${TURBO} run build --dry=json > /dev/null

0 comments on commit ef9f6b8

Please sign in to comment.