Skip to content

Commit

Permalink
fix: deno workspace wildcards should discover package.json files (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored Nov 4, 2024
1 parent 40b4cb4 commit 1df7709
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/workspace/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions src/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/**"] {
Expand Down

0 comments on commit 1df7709

Please sign in to comment.