Skip to content

Commit

Permalink
feat(place patches in json folder when pruning for docker) (#4318)
Browse files Browse the repository at this point in the history
### Description

Implements #4289

Using the `--docker` flag with prune produces a `full` and `json`
directory where the `json` directory only includes everything required
to install dependencies. If a dependency is patched it makes sense to
include the patch in the `json` directory as both the `package.json` and
the lockfile reference the patch file.

### Testing Instructions

Added an integration test to verify that patches end up in the `json`
output folder.
  • Loading branch information
chris-olszewski authored Mar 29, 2023
1 parent 0d20a5e commit 89a9e7f
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cli/integration_tests/prune/docker.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Setup
$ . ${TESTDIR}/../setup.sh
$ . ${TESTDIR}/setup.sh $(pwd)

$ ${TURBO} prune --scope=web --docker
Generating pruned monorepo for web in .*out (re)
- Added shared
- Added util
- Added web
Make sure patches are part of the json output
$ ls out/json
apps
package.json
packages
patches
pnpm-workspace.yaml

Make sure the pnpm patches section is present
$ cat out/json/package.json | jq '.pnpm.patchedDependencies'
{
"is-number@7.0.0": "patches/is-number@7.0.0.patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"build": "echo 'building'"
},
"dependencies": {
"is-number": "^7.0.0",
"shared": "workspace:*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"packageManager": "pnpm@7.25.1",
"devDependencies": {
"util": "workspace:*"
},
"pnpm": {
"patchedDependencies": {
"is-number@7.0.0": "patches/is-number@7.0.0.patch"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
diff --git a/index.js b/index.js
index 27f19b757f7c1186b92c405a213bf0dd9b6cbe95..24315132970b6299c9c158ef5fb75b2e9c0e633d 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,4 @@
+// patch
/*!
* is-number <https://github.com/jonschlinkert/is-number>
*
15 changes: 15 additions & 0 deletions cli/integration_tests/prune/monorepo_with_root_dep/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions cli/internal/prune/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ func (p *prune) prune(opts *turbostate.PrunePayload) error {
); err != nil {
return errors.Wrap(err, "Failed copying patch file")
}
if opts.Docker {
jsonDir := outDir.Join(turbopath.RelativeSystemPath("json"))
if err := fs.CopyFile(
&fs.LstatCachedFile{Path: p.base.RepoRoot.UntypedJoin(patch.ToString())},
patch.ToSystemPath().RestoreAnchor(jsonDir).ToStringDuringMigration(),
); err != nil {
return errors.Wrap(err, "Failed copying patch file")
}
}
}
} else {
if err := fs.CopyFile(
Expand Down

0 comments on commit 89a9e7f

Please sign in to comment.