@@ -93,6 +93,19 @@ pub async fn detect_workspaces(package_json_path: &Path) -> WorkspaceConfig {
9393 Err ( _) => return default,
9494 } ;
9595
96+ // Check for pnpm workspaces first — pnpm projects may also have
97+ // "workspaces" in package.json for compatibility, but
98+ // pnpm-workspace.yaml is the definitive signal.
99+ let dir = package_json_path. parent ( ) . unwrap_or ( Path :: new ( "." ) ) ;
100+ let pnpm_workspace = dir. join ( "pnpm-workspace.yaml" ) ;
101+ if let Ok ( yaml_content) = fs:: read_to_string ( & pnpm_workspace) . await {
102+ let patterns = parse_pnpm_workspace_patterns ( & yaml_content) ;
103+ return WorkspaceConfig {
104+ ws_type : WorkspaceType :: Pnpm ,
105+ patterns,
106+ } ;
107+ }
108+
96109 // Check for npm/yarn workspaces
97110 if let Some ( workspaces) = pkg. get ( "workspaces" ) {
98111 let patterns = if let Some ( arr) = workspaces. as_array ( ) {
@@ -118,17 +131,6 @@ pub async fn detect_workspaces(package_json_path: &Path) -> WorkspaceConfig {
118131 } ;
119132 }
120133
121- // Check for pnpm workspaces
122- let dir = package_json_path. parent ( ) . unwrap_or ( Path :: new ( "." ) ) ;
123- let pnpm_workspace = dir. join ( "pnpm-workspace.yaml" ) ;
124- if let Ok ( yaml_content) = fs:: read_to_string ( & pnpm_workspace) . await {
125- let patterns = parse_pnpm_workspace_patterns ( & yaml_content) ;
126- return WorkspaceConfig {
127- ws_type : WorkspaceType :: Pnpm ,
128- patterns,
129- } ;
130- }
131-
132134 default
133135}
134136
@@ -450,6 +452,28 @@ mod tests {
450452 assert_eq ! ( config. patterns, vec![ "packages/*" ] ) ;
451453 }
452454
455+ #[ tokio:: test]
456+ async fn test_detect_workspaces_pnpm_with_workspaces_field ( ) {
457+ // When both pnpm-workspace.yaml AND "workspaces" in package.json
458+ // exist, pnpm should take priority (e.g. depscan repo)
459+ let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
460+ let pkg = dir. path ( ) . join ( "package.json" ) ;
461+ fs:: write (
462+ & pkg,
463+ r#"{"name": "root", "workspaces": ["packages/*"]}"# ,
464+ )
465+ . await
466+ . unwrap ( ) ;
467+ let pnpm = dir. path ( ) . join ( "pnpm-workspace.yaml" ) ;
468+ fs:: write ( & pnpm, "packages:\n - workspaces/*" )
469+ . await
470+ . unwrap ( ) ;
471+ let config = detect_workspaces ( & pkg) . await ;
472+ assert ! ( matches!( config. ws_type, WorkspaceType :: Pnpm ) ) ;
473+ // Should use pnpm-workspace.yaml patterns, not package.json workspaces
474+ assert_eq ! ( config. patterns, vec![ "workspaces/*" ] ) ;
475+ }
476+
453477 #[ tokio:: test]
454478 async fn test_detect_workspaces_none ( ) {
455479 let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
0 commit comments