From b35fafcd33744246bcfcec1f67a4f66f239300e0 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 10 May 2023 11:04:00 -0700 Subject: [PATCH] check if user passes absolute path to prune --- cli/internal/prune/prune.go | 8 ++++++- .../integration/tests/prune/out_dir.t | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 turborepo-tests/integration/tests/prune/out_dir.t diff --git a/cli/internal/prune/prune.go b/cli/internal/prune/prune.go index 65555673d894f..e61032105f298 100644 --- a/cli/internal/prune/prune.go +++ b/cli/internal/prune/prune.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "os" + "path/filepath" "strings" "github.com/vercel/turbo/cli/internal/cmdutil" @@ -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") diff --git a/turborepo-tests/integration/tests/prune/out_dir.t b/turborepo-tests/integration/tests/prune/out_dir.t new file mode 100644 index 0000000000000..78021de54bf45 --- /dev/null +++ b/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" + } + } + }