From 816c4a7084f2c905f3416e3d3dd9121763884d18 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Tue, 12 Dec 2023 09:12:22 -0800 Subject: [PATCH] fix: avoid double slash if glob ends with slash (#6772) ### Description Fixes #6748 ### Testing Instructions Added unit test making sure we don't have multiple forward slashes in the `package.json` globs. Also tested that we no longer error if a workspace glob has a trailing slash: ``` [0 olszewski@chriss-mbp] /tmp/trailing-slash $ cat pnpm-workspace.yaml packages: - "apps/*" - "packages/*" - ci/ # before changes in PR [0 olszewski@chriss-mbp] /tmp/trailing-slash $ turbo_dev info Turbo error: discovery failed: bad pattern /private/tmp/trailing-slash/ci//package.json: malformed glob expression: adjacent component bounda ries `/` or `**` # after PR changes [0 olszewski@chriss-mbp] /tmp/trailing-slash $ turbo_dev info You are logged in but not linked 6 packages found in workspace - @repo/eslint-config packages/eslint-config - @repo/typescript-config packages/typescript-config - @repo/ui packages/ui - ci ci - docs apps/docs - web apps/web ``` Closes TURBO-1896 Co-authored-by: Chris Olszewski --- .../src/package_manager/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/turborepo-repository/src/package_manager/mod.rs b/crates/turborepo-repository/src/package_manager/mod.rs index 85f9c7fba785e..46dc2a6bf76b5 100644 --- a/crates/turborepo-repository/src/package_manager/mod.rs +++ b/crates/turborepo-repository/src/package_manager/mod.rs @@ -136,7 +136,11 @@ impl WorkspaceGlobs { .iter() .map(|s| { let mut s: String = s.clone(); - s.push_str("/package.json"); + if s.ends_with('/') { + s.push_str("package.json"); + } else { + s.push_str("/package.json"); + } s }) .collect::>(); @@ -870,4 +874,14 @@ mod tests { assert_eq!(nested.workspaces.as_ref(), vec!["packages/**"]); Ok(()) } + + #[test] + fn test_workspace_globs_trailing_slash() { + let globs = + WorkspaceGlobs::new(vec!["scripts/", "packages/**"], vec!["package/template"]).unwrap(); + assert_eq!( + &globs.package_json_inclusions, + &["scripts/package.json", "packages/**/package.json"] + ); + } }