diff --git a/src/workspace/discovery.rs b/src/workspace/discovery.rs index b98cbb6..6cbf937 100644 --- a/src/workspace/discovery.rs +++ b/src/workspace/discovery.rs @@ -767,12 +767,15 @@ fn resolve_workspace_for_config_folder( .iter() .partition(|member| is_glob_pattern(member) || member.starts_with('!')); + // Deno workspaces can discover wildcard members that use either `deno.json`, `deno.jsonc` or `package.json`. + // But it only works for Deno workspaces, npm workspaces don't discover `deno.json(c)` files, otherwise + // we'd be incompatible with npm workspaces if we discovered more files. let deno_json_paths = collect_member_config_folders( "Deno", pattern_members, &deno_json.specifier, &deno_json.dir_path(), - &["deno.json", "deno.jsonc"], + &["deno.json", "deno.jsonc", "package.json"], )?; let mut member_dir_urls = @@ -824,6 +827,8 @@ fn resolve_workspace_for_config_folder( .iter() .partition(|member| is_glob_pattern(member) || member.starts_with('!')); + // npm workspaces can discover wildcard members `package.json` files, but not `deno.json(c)` files, otherwise + // we'd be incompatible with npm workspaces if we discovered more files than just `package.json`. let pkg_json_paths = collect_member_config_folders( "npm", pattern_members, diff --git a/src/workspace/mod.rs b/src/workspace/mod.rs index de10ae1..c97e98c 100644 --- a/src/workspace/mod.rs +++ b/src/workspace/mod.rs @@ -3614,6 +3614,33 @@ mod test { assert_eq!(workspace_dir.workspace.deno_jsons().count(), 4); } + #[test] + fn test_deno_workspace_globs_with_package_json() { + let mut fs = TestFileSystem::default(); + fs.insert_json( + root_dir().join("deno.json"), + json!({ + "workspace": ["./packages/*", "./examples/*"] + }), + ); + fs.insert_json(root_dir().join("packages/package-a/deno.json"), json!({})); + fs.insert_json(root_dir().join("packages/package-b/deno.json"), json!({})); + fs.insert_json(root_dir().join("packages/package-c/deno.jsonc"), json!({})); + fs.insert_json( + root_dir().join("examples/examples1/package.json"), + json!({}), + ); + fs.insert_json( + root_dir().join("examples/examples2/package.json"), + json!({}), + ); + let workspace_dir = + workspace_at_start_dir(&fs, &root_dir().join("packages")); + assert_eq!(workspace_dir.workspace.diagnostics(), Vec::new()); + assert_eq!(workspace_dir.workspace.deno_jsons().count(), 4); + assert_eq!(workspace_dir.workspace.package_jsons().count(), 2); + } + #[test] fn test_deno_workspace_negations() { for negation in ["!ignored/package-c", "!ignored/**"] {