Skip to content

Commit

Permalink
fix: check if user passes absolute path to prune (#4891)
Browse files Browse the repository at this point in the history
### Description

As discovered in #4885, we forcibly join `--out-dir` to the repo root
even if it's absolute. This PR adds a check that skips the join if the
user passes an absolute system path.

### Testing Instructions

Added failing integration test
  • Loading branch information
chris-olszewski committed May 11, 2023
1 parent 3e1c136 commit fd3ac51
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cli/internal/prune/prune.go
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/vercel/turbo/cli/internal/cmdutil"
Expand Down Expand Up @@ -69,7 +70,12 @@ func (p *prune) prune(opts *turbostate.PrunePayload, packageManagerName string)
if err != nil {
return errors.Wrap(err, "could not construct graph")
}
outDir := p.base.RepoRoot.UntypedJoin(opts.OutputDir)
var outDir turbopath.AbsoluteSystemPath
if filepath.IsAbs(opts.OutputDir) {
outDir = turbopath.AbsoluteSystemPathFromUpstream(opts.OutputDir)
} else {
outDir = p.base.RepoRoot.UntypedJoin(opts.OutputDir)
}
fullDir := outDir
if opts.Docker {
fullDir = fullDir.UntypedJoin("full")
Expand Down
24 changes: 24 additions & 0 deletions turborepo-tests/integration/tests/prune/out_dir.t
@@ -0,0 +1,24 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup.sh
$ . ${TESTDIR}/../_helpers/setup_monorepo.sh $(pwd) monorepo_with_root_dep

Test that absolute paths can be passed as out-dir
$ TMPFILE=$(mktemp)
$ ${TURBO} prune --scope=web --out-dir=${TMPFILE}
Generating pruned monorepo for web in .* (re)
- Added shared
- Added util
- Added web
$ cat ${TMPFILE}/package.json
{
"devDependencies": {
"util": "workspace:*"
},
"name": "monorepo",
"packageManager": "pnpm@7.25.1",
"pnpm": {
"patchedDependencies": {
"is-number@7.0.0": "patches/is-number@7.0.0.patch"
}
}
}

0 comments on commit fd3ac51

Please sign in to comment.