-
Notifications
You must be signed in to change notification settings - Fork 12
Adds support for generating package maps #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f3364ae
6eadee7
6e80271
13aa7ed
5693f89
578c179
f5b2a4b
889778e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ use zpm_sync::{SyncItem, SyncTemplate, SyncTree}; | |
| use zpm_utils::{FromFileString, IoResultExt, Path, ToHumanString}; | ||
|
|
||
| use crate::{ | ||
| build::{self, BuildRequest, BuildRequests}, content_flags, error::Error, fetchers::PackageData, install::Install, linker::{self, LinkResult, helpers::PackageMeta, nm::hoist::{Hoister, WorkTree}}, project::Project | ||
| build::{self, BuildRequest, BuildRequests}, content_flags, error::Error, fetchers::PackageData, install::Install, linker::{self, LinkResult, helpers::PackageMeta, nm::hoist::{Hoister, WorkTree}, package_map::{NodeModulesPackageMapBuilder, persist_package_map, persist_package_map_at}}, project::Project | ||
| }; | ||
|
|
||
| pub mod hoist; | ||
|
|
@@ -86,6 +86,7 @@ fn register_workspace_symlinks_at( | |
| project: &Project, | ||
| install: &Install, | ||
| workspace_nm_tree: &mut SyncTree, | ||
| mut package_map_builder: Option<&mut NodeModulesPackageMapBuilder>, | ||
| host_node: &hoist::WorkNode, | ||
| host_abs_path: &Path, | ||
| candidate_workspaces: impl IntoIterator<Item = (Ident, Path)>, | ||
|
|
@@ -147,9 +148,20 @@ fn register_workspace_symlinks_at( | |
| = workspace_dir | ||
| .relative_to(&host_abs_path.with_join(&symlink_path).dirname().unwrap_or_default()); | ||
|
|
||
| let symlink_location | ||
| = host_abs_path.with_join(&symlink_path); | ||
|
|
||
| workspace_nm_tree.register_entry(symlink_path, SyncItem::Symlink { | ||
| target_path, | ||
| })?; | ||
|
|
||
| if let Some(package_map_builder) = package_map_builder.as_deref_mut() { | ||
| package_map_builder.register_package( | ||
| symlink_location, | ||
| workspace_dir, | ||
| &target_locator, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
|
|
@@ -187,11 +199,15 @@ fn generate_workspace_node_modules( | |
| install: &Install, | ||
| work_tree: &WorkTree, | ||
| workspace_node_idx: usize, | ||
| package_map_builder: Option<&mut NodeModulesPackageMapBuilder>, | ||
| packages_by_location: &mut BTreeMap<Path, zpm_primitives::Locator>, | ||
| canonical_build_locations: &mut BTreeMap<Locator, Path>, | ||
| force_rebuild_locators: &mut BTreeSet<Locator>, | ||
| cas_extractions: &mut Vec<(Path, Locator)>, | ||
| ) -> Result<(), Error> { | ||
| let mut package_map_builder | ||
| = package_map_builder; | ||
|
|
||
| let hardlinks_mode = matches!( | ||
| project.config.settings.nm_mode.value, | ||
| zpm_config::NmMode::HardlinksLocal | zpm_config::NmMode::HardlinksGlobal, | ||
|
|
@@ -213,6 +229,14 @@ fn generate_workspace_node_modules( | |
| = project.project_cwd | ||
| .with_join(&workspace.rel_path); | ||
|
|
||
| if let Some(package_map_builder) = package_map_builder.as_deref_mut() { | ||
| package_map_builder.register_package( | ||
| workspace_dir.clone(), | ||
| workspace_dir.clone(), | ||
| &workspace_node.locator, | ||
| ); | ||
| } | ||
|
|
||
| let workspace_abs_path | ||
| = workspace_dir | ||
| .with_join_str("node_modules"); | ||
|
|
@@ -255,6 +279,7 @@ fn generate_workspace_node_modules( | |
| project, | ||
| install, | ||
| &mut workspace_nm_tree, | ||
| package_map_builder.as_deref_mut(), | ||
| &work_tree.nodes[workspace_node_idx], | ||
| &workspace_abs_path, | ||
| candidate_workspaces, | ||
|
|
@@ -315,6 +340,14 @@ fn generate_workspace_node_modules( | |
| let child_abs_path | ||
| = workspace_abs_path.with_join(&child_rel_path); | ||
|
|
||
| if let Some(package_map_builder) = package_map_builder.as_deref_mut() { | ||
| package_map_builder.register_package( | ||
| child_abs_path.clone(), | ||
| package_directory.clone(), | ||
| &child_node.locator, | ||
| ); | ||
| } | ||
|
|
||
| let target_path | ||
| = package_directory.relative_to(&child_abs_path.dirname().unwrap()); | ||
|
|
||
|
|
@@ -328,6 +361,14 @@ fn generate_workspace_node_modules( | |
| }, | ||
|
|
||
| Some(PackageData::Zip {archive_path, package_directory, ..}) => { | ||
| if let Some(package_map_builder) = package_map_builder.as_deref_mut() { | ||
| package_map_builder.register_package( | ||
| abs_path.clone(), | ||
| abs_path.clone(), | ||
| &child_node.locator, | ||
| ); | ||
| } | ||
|
|
||
| // SyncTree re-extracts user-deleted destinations | ||
| // automatically; we just need to flag for rebuild | ||
| // so the build cache doesn't short-circuit. | ||
|
|
@@ -373,6 +414,14 @@ fn generate_workspace_node_modules( | |
| let target_path | ||
| = Path::from_file_string(¶ms.path)?; | ||
|
|
||
| if let Some(package_map_builder) = package_map_builder.as_deref_mut() { | ||
| package_map_builder.register_package( | ||
| abs_path.clone(), | ||
| target_path.clone(), | ||
| &child_node.locator, | ||
| ); | ||
| } | ||
|
|
||
| workspace_nm_tree.register_entry(child_rel_path, SyncItem::Symlink { | ||
| target_path, | ||
| })?; | ||
|
|
@@ -492,10 +541,16 @@ pub async fn link_island_nm( | |
| = BTreeSet::new(); | ||
| let mut cas_extractions | ||
| = Vec::new(); | ||
| let mut package_maps | ||
| = Vec::new(); | ||
|
|
||
| for workspace_ident in &island.workspace_idents { | ||
| let workspace = project.workspace_by_ident(workspace_ident)?; | ||
| let workspace_locator = workspace.locator(); | ||
| let package_map_base_path | ||
| = workspace.path.with_join_str("node_modules"); | ||
| let mut package_map_builder | ||
| = NodeModulesPackageMapBuilder::new_at(project, install, package_map_base_path.clone()); | ||
|
|
||
| let mut work_tree = WorkTree::new_for_island_workspace( | ||
| project, | ||
|
|
@@ -513,15 +568,25 @@ pub async fn link_island_nm( | |
| install, | ||
| &work_tree, | ||
| 0, | ||
| Some(&mut package_map_builder), | ||
| &mut packages_by_location, | ||
| &mut canonical_build_locations, | ||
| &mut force_rebuild_locators, | ||
| &mut cas_extractions, | ||
| )?; | ||
|
|
||
| package_maps.push(( | ||
| project.package_map_path(Some(workspace)), | ||
| package_map_builder.build()?, | ||
| )); | ||
| } | ||
|
|
||
| run_cas_extractions(project, install, &cas_extractions)?; | ||
|
|
||
| for (package_map_path, package_map) in package_maps { | ||
| persist_package_map_at(&package_map_path, &package_map)?; | ||
| } | ||
|
|
||
| let dependencies_meta | ||
| = linker::helpers::TopLevelConfiguration::from_project(project); | ||
|
|
||
|
|
@@ -772,6 +837,9 @@ pub async fn link_project_nm(project: &Project, install: &Install) -> Result<Lin | |
|
|
||
| check_external_portal_conflicts(project, install, &work_tree)?; | ||
|
|
||
| let mut package_map_builder | ||
| = NodeModulesPackageMapBuilder::new(project, install); | ||
|
|
||
| let mut project_queue | ||
| = vec![0usize]; | ||
|
|
||
|
|
@@ -781,6 +849,7 @@ pub async fn link_project_nm(project: &Project, install: &Install) -> Result<Lin | |
| install, | ||
| &work_tree, | ||
| workspace_node_idx, | ||
| Some(&mut package_map_builder), | ||
| &mut packages_by_location, | ||
| &mut canonical_build_locations, | ||
| &mut force_rebuild_locators, | ||
|
|
@@ -792,6 +861,8 @@ pub async fn link_project_nm(project: &Project, install: &Install) -> Result<Lin | |
|
|
||
| run_cas_extractions(project, install, &cas_extractions)?; | ||
|
|
||
| persist_package_map(project, &package_map_builder.build()?)?; | ||
|
cursor[bot] marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stale map after build failureMedium Severity The node-modules linker updates Reviewed by Cursor Bugbot for commit 6eadee7. Configure here. |
||
|
|
||
| let dependencies_meta | ||
| = linker::helpers::TopLevelConfiguration::from_project(project); | ||
|
|
||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.