Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check if user passes absolute path to prune #4891

Merged
merged 2 commits into from May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
}
}
}