Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 64 additions & 4 deletions crates/aube/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,14 +1124,33 @@ impl InstallLayoutState {
// "Already up to date" and never relinked the member.
let mut direct_entries = BTreeMap::new();
for (importer, deps) in &layout.graph.importers {
let modules_base = if importer == "." {
project_dir.join(layout.modules_dir_name)
let importer_dir = if importer == "." {
project_dir.to_path_buf()
} else {
project_dir.join(importer).join(layout.modules_dir_name)
aube_util::path::normalize_lexical(&project_dir.join(importer))
};
let entries = deps
.iter()
.map(|dep| relative_path_or_original(&modules_base.join(&dep.name), project_dir))
.map(|dep| {
let importer_entry = importer_dir.join(layout.modules_dir_name).join(&dep.name);
// A workspace-wide hoist may satisfy this direct edge from
// an ancestor node_modules. Record the first placement Node
// can actually see instead of a local slot the linker
// intentionally left absent.
let entry = layout
.placements
.filter(|_| matches!(layout.node_linker, aube_linker::NodeLinker::Hoisted))
.and_then(|placements| {
let package_dirs = placements.all_package_dirs(&dep.dep_path);
importer_dir.ancestors().find_map(|ancestor| {
let candidate =
ancestor.join(layout.modules_dir_name).join(&dep.name);
package_dirs.contains(&candidate).then_some(candidate)
})
})
.unwrap_or(importer_entry);
relative_path_or_original(&entry, project_dir)
})
.collect();
direct_entries.insert(importer.clone(), entries);
}
Expand Down Expand Up @@ -1739,6 +1758,47 @@ mod tests {
);
}

#[test]
fn from_graph_records_visible_hoisted_entries_for_workspace_importers() {
let project_dir = temp_project_dir("layout-hoisted-importer");
let aube_dir = project_dir.join("node_modules/.aube");
let dep = aube_lockfile::DirectDep {
name: "is-number".to_string(),
dep_path: "is-number@7.0.0".to_string(),
dep_type: aube_lockfile::DepType::Production,
specifier: None,
};
let graph = aube_lockfile::LockfileGraph {
importers: BTreeMap::from([
(".".to_string(), Vec::new()),
("packages/app".to_string(), vec![dep]),
]),
..Default::default()
};
let placements = aube_linker::HoistedPlacements::from_package_dirs(BTreeMap::from([(
"is-number@7.0.0".to_string(),
vec![project_dir.join("node_modules/is-number")],
)]));

let layout = InstallLayoutState::from_graph(
&project_dir,
&WriteStateLayout {
graph: &graph,
node_linker: aube_linker::NodeLinker::Hoisted,
hoisting_limits: aube_linker::HoistingLimits::None,
modules_dir_name: "node_modules",
aube_dir: &aube_dir,
virtual_store_dir_max_length: 120,
placements: Some(&placements),
},
);

assert_eq!(
layout.direct_entries.get("packages/app"),
Some(&vec!["node_modules/is-number".to_string()])
);
}

#[test]
fn collect_package_json_hashes_from_manifests_uses_file_paths_for_workspaces() {
let project_dir = temp_project_dir("manifest-hash-keys");
Expand Down
29 changes: 29 additions & 0 deletions test/hoisted.bats
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,35 @@ test "$(realpath "$app")" = "$(realpath "$lib")"
assert_success
}

@test "hoisted workspace root placements stay warm before scripts" {
mkdir -p packages/app
cat >package.json <<'JSON'
{"name":"root","private":true,"scripts":{"ok":"printf 'ok\\n'"}}
JSON
cat >pnpm-workspace.yaml <<'YAML'
packages:
- packages/*
nodeLinker: hoisted
YAML
cat >packages/app/package.json <<'JSON'
{"name":"app","private":true,"dependencies":{"is-number":"7.0.0"}}
JSON

run aube install
assert_success
assert_dir_exists node_modules/is-number
assert_not_exists packages/app/node_modules/is-number

run aube run ok
assert_success
assert_output "ok"
refute_output --partial "Auto-installing"
run aube run ok
assert_success
assert_output "ok"
refute_output --partial "Auto-installing"
}

@test "hoistingLimits=workspaces keeps dependencies under each workspace" {
mkdir -p packages/app packages/lib
cat >package.json <<'JSON'
Expand Down
Loading