From 147411e64b22fe74cb258125acab83f9182c9f81 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 3 Jul 2024 20:54:33 -0400 Subject: 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 --- cli/util/collections.rs | 38 ++++++++++++++++++++++++++++++++++++++ cli/util/file_watcher.rs | 3 +++ cli/util/mod.rs | 1 + 3 files changed, 42 insertions(+) create mode 100644 cli/util/collections.rs (limited to 'cli/util') diff --git a/cli/util/collections.rs b/cli/util/collections.rs new file mode 100644 index 000000000..21f73024b --- /dev/null +++ b/cli/util/collections.rs @@ -0,0 +1,38 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +use std::marker::PhantomData; + +pub struct CheckedSet { + _kind: PhantomData, + checked: std::collections::HashSet, +} + +impl Default for CheckedSet { + fn default() -> Self { + Self { + _kind: Default::default(), + checked: Default::default(), + } + } +} + +impl CheckedSet { + pub fn with_capacity(capacity: usize) -> Self { + Self { + _kind: PhantomData, + checked: std::collections::HashSet::with_capacity(capacity), + } + } + + pub fn insert(&mut self, value: &T) -> bool { + self.checked.insert(self.get_hash(value)) + } + + fn get_hash(&self, value: &T) -> u64 { + use std::collections::hash_map::DefaultHasher; + use std::hash::Hasher; + let mut hasher = DefaultHasher::new(); + value.hash(&mut hasher); + hasher.finish() + } +} diff --git a/cli/util/file_watcher.rs b/cli/util/file_watcher.rs index b2628760b..176ca43f0 100644 --- a/cli/util/file_watcher.rs +++ b/cli/util/file_watcher.rs @@ -163,6 +163,9 @@ pub struct WatcherCommunicator { impl WatcherCommunicator { pub fn watch_paths(&self, paths: Vec) -> Result<(), AnyError> { + if paths.is_empty() { + return Ok(()); + } self.paths_to_watch_tx.send(paths).map_err(AnyError::from) } diff --git a/cli/util/mod.rs b/cli/util/mod.rs index 89df7bb98..69cdc77c3 100644 --- a/cli/util/mod.rs +++ b/cli/util/mod.rs @@ -2,6 +2,7 @@ // Note: Only add code in this folder that has no application specific logic pub mod checksum; +pub mod collections; pub mod console; pub mod diff; pub mod display; -- cgit v1.2.3