summaryrefslogtreecommitdiff
path: root/cli/npm/managed/resolvers
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-07-03 20:54:33 -0400
committerGitHub <noreply@github.com>2024-07-04 00:54:33 +0000
commit147411e64b22fe74cb258125acab83f9182c9f81 (patch)
treea1f63dcbf0404c20534986b10f02b649df5a3ad5 /cli/npm/managed/resolvers
parentdd6d19e12051fac2ea5639f621501f4710a1b8e1 (diff)
feat: npm workspace and better Deno workspace support (#24334)
Adds much better support for the unstable Deno workspaces as well as support for npm workspaces. npm workspaces is still lacking in that we only install packages into the root node_modules folder. We'll make it smarter over time in order for it to figure out when to add node_modules folders within packages. This includes a breaking change in config file resolution where we stop searching for config files on the first found package.json unless it's in a workspace. For the previous behaviour, the root deno.json needs to be updated to be a workspace by adding `"workspace": ["./path-to-pkg-json-folder-goes-here"]`. See details in https://github.com/denoland/deno_config/pull/66 Closes #24340 Closes #24159 Closes #24161 Closes #22020 Closes #18546 Closes #16106 Closes #24160
Diffstat (limited to 'cli/npm/managed/resolvers')
-rw-r--r--cli/npm/managed/resolvers/local.rs22
-rw-r--r--cli/npm/managed/resolvers/mod.rs4
2 files changed, 25 insertions, 1 deletions
diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs
index d338720b6..e8fffa0cd 100644
--- a/cli/npm/managed/resolvers/local.rs
+++ b/cli/npm/managed/resolvers/local.rs
@@ -15,6 +15,7 @@ use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;
+use crate::args::PackageJsonInstallDepsProvider;
use crate::cache::CACHE_PERM;
use crate::npm::cache_dir::mixed_case_package_name_decode;
use crate::util::fs::atomic_write_file_with_retries;
@@ -57,6 +58,7 @@ use super::common::RegistryReadPermissionChecker;
pub struct LocalNpmPackageResolver {
cache: Arc<NpmCache>,
fs: Arc<dyn deno_fs::FileSystem>,
+ pkg_json_deps_provider: Arc<PackageJsonInstallDepsProvider>,
progress_bar: ProgressBar,
resolution: Arc<NpmResolution>,
tarball_cache: Arc<TarballCache>,
@@ -67,9 +69,11 @@ pub struct LocalNpmPackageResolver {
}
impl LocalNpmPackageResolver {
+ #[allow(clippy::too_many_arguments)]
pub fn new(
cache: Arc<NpmCache>,
fs: Arc<dyn deno_fs::FileSystem>,
+ pkg_json_deps_provider: Arc<PackageJsonInstallDepsProvider>,
progress_bar: ProgressBar,
resolution: Arc<NpmResolution>,
tarball_cache: Arc<TarballCache>,
@@ -79,6 +83,7 @@ impl LocalNpmPackageResolver {
Self {
cache,
fs: fs.clone(),
+ pkg_json_deps_provider,
progress_bar,
resolution,
tarball_cache,
@@ -221,6 +226,7 @@ impl NpmPackageFsResolver for LocalNpmPackageResolver {
sync_resolution_with_fs(
&self.resolution.snapshot(),
&self.cache,
+ &self.pkg_json_deps_provider,
&self.progress_bar,
&self.tarball_cache,
&self.root_node_modules_path,
@@ -244,12 +250,13 @@ impl NpmPackageFsResolver for LocalNpmPackageResolver {
async fn sync_resolution_with_fs(
snapshot: &NpmResolutionSnapshot,
cache: &Arc<NpmCache>,
+ pkg_json_deps_provider: &PackageJsonInstallDepsProvider,
progress_bar: &ProgressBar,
tarball_cache: &Arc<TarballCache>,
root_node_modules_dir_path: &Path,
system_info: &NpmSystemInfo,
) -> Result<(), AnyError> {
- if snapshot.is_empty() {
+ if snapshot.is_empty() && pkg_json_deps_provider.workspace_pkgs().is_empty() {
return Ok(()); // don't create the directory
}
@@ -475,6 +482,19 @@ async fn sync_resolution_with_fs(
bin_entries.finish(snapshot, &bin_node_modules_dir_path)?;
}
+ // 7. Create symlinks for the workspace packages
+ {
+ // todo(#24419): this is not exactly correct because it should
+ // install correctly for a workspace (potentially in sub directories),
+ // but this is good enough for a first pass
+ for workspace in pkg_json_deps_provider.workspace_pkgs() {
+ symlink_package_dir(
+ &workspace.pkg_dir,
+ &root_node_modules_dir_path.join(&workspace.alias),
+ )?;
+ }
+ }
+
setup_cache.save();
drop(single_process_lock);
drop(pb_clear_guard);
diff --git a/cli/npm/managed/resolvers/mod.rs b/cli/npm/managed/resolvers/mod.rs
index 2d812a2be..a7f545916 100644
--- a/cli/npm/managed/resolvers/mod.rs
+++ b/cli/npm/managed/resolvers/mod.rs
@@ -10,6 +10,7 @@ use std::sync::Arc;
use deno_npm::NpmSystemInfo;
use deno_runtime::deno_fs::FileSystem;
+use crate::args::PackageJsonInstallDepsProvider;
use crate::util::progress_bar::ProgressBar;
pub use self::common::NpmPackageFsResolver;
@@ -21,9 +22,11 @@ use super::cache::NpmCache;
use super::cache::TarballCache;
use super::resolution::NpmResolution;
+#[allow(clippy::too_many_arguments)]
pub fn create_npm_fs_resolver(
fs: Arc<dyn FileSystem>,
npm_cache: Arc<NpmCache>,
+ pkg_json_deps_provider: &Arc<PackageJsonInstallDepsProvider>,
progress_bar: &ProgressBar,
resolution: Arc<NpmResolution>,
tarball_cache: Arc<TarballCache>,
@@ -34,6 +37,7 @@ pub fn create_npm_fs_resolver(
Some(node_modules_folder) => Arc::new(LocalNpmPackageResolver::new(
npm_cache,
fs,
+ pkg_json_deps_provider.clone(),
progress_bar.clone(),
resolution,
tarball_cache,