pub(super) fn parse_lockfile_dir_remapped(
lockfile_dir: &std::path::Path,
importer_key: &str,
manifest: &aube_manifest::PackageJson,
) -> Result<aube_lockfile::LockfileGraph, aube_lockfile::Error> {
let mut graph = aube_lockfile::parse_lockfile(lockfile_dir, manifest)?;
if importer_key != "."
&& let Some(deps) = graph.importers.remove(importer_key)
{
graph.importers.insert(".".to_string(), deps);
}
Ok(graph)
}
pub(super) fn parse_lockfile_dir_remapped_with_kind(
lockfile_dir: &std::path::Path,
importer_key: &str,
manifest: &aube_manifest::PackageJson,
) -> Result<(aube_lockfile::LockfileGraph, aube_lockfile::LockfileKind), aube_lockfile::Error> {
let (mut graph, kind) = aube_lockfile::parse_lockfile_with_kind(lockfile_dir, manifest)?;
if importer_key != "."
&& let Some(deps) = graph.importers.remove(importer_key)
{
graph.importers.insert(".".to_string(), deps);
}
Ok((graph, kind))
}
pub(super) fn guard_against_foreign_importers(
lockfile_dir: &std::path::Path,
importer_key: &str,
graph: &aube_lockfile::LockfileGraph,
) -> Result<(), aube_lockfile::Error> {
let foreign: Vec<&str> = graph
.importers
.keys()
.map(String::as_str)
.filter(|k| *k != importer_key)
.collect();
if foreign.is_empty() {
return Ok(());
}
Err(aube_lockfile::Error::Parse(
lockfile_dir.to_path_buf(),
format!(
"lockfile already records importers from other projects ({}); \
aube does not yet support multi-project shared lockfiles outside a workspace. \
Use a `pnpm-workspace.yaml` workspace, or point each project at its own `--lockfile-dir`.",
foreign.join(", ")
),
))
}
pub(super) fn write_lockfile_dir_remapped(
lockfile_dir: &std::path::Path,
importer_key: &str,
graph: &aube_lockfile::LockfileGraph,
manifest: &aube_manifest::PackageJson,
kind: aube_lockfile::LockfileKind,
) -> Result<std::path::PathBuf, aube_lockfile::Error> {
if importer_key == "." {
return aube_lockfile::write_lockfile_as(lockfile_dir, graph, manifest, kind);
}
let mut remapped = graph.clone();
let deps = remapped.importers.remove(".").ok_or_else(|| {
aube_lockfile::Error::Parse(
lockfile_dir.to_path_buf(),
format!(
"in-memory lockfile graph missing `.` importer; cannot write under key `{importer_key}`"
),
)
})?;
remapped.importers.insert(importer_key.to_string(), deps);
aube_lockfile::write_lockfile_as(lockfile_dir, &remapped, manifest, kind)
}