diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-03-09 20:40:53 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-09 20:40:53 -0500 |
commit | f8543a9fd8d47753a607dfc04c121c49d1ac4294 (patch) | |
tree | d912fc131909df44fba20e368010b5bab858ef6d /cli/util/fs.rs | |
parent | dff056ae41011104586b60d5e47ded502e60db11 (diff) |
fix(publish): regression - publishing with vendor folder (#22830)
In
https://github.com/denoland/deno/pull/22720/files#diff-d62d85de2a7ffb816cd2fdbaa47e588352f521c7c43d058b75649bbb255e0ae1R70
, I copy and pasted from another area of the code and didn't think about
removing how it ignores the vendor folder by default.
Diffstat (limited to 'cli/util/fs.rs')
-rw-r--r-- | cli/util/fs.rs | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/cli/util/fs.rs b/cli/util/fs.rs index e84f05d1e..047bf18dc 100644 --- a/cli/util/fs.rs +++ b/cli/util/fs.rs @@ -261,6 +261,7 @@ pub struct FileCollector<TFilter: Fn(WalkEntry) -> bool> { ignore_git_folder: bool, ignore_node_modules: bool, ignore_vendor_folder: bool, + vendor_folder: Option<PathBuf>, use_gitignore: bool, } @@ -271,6 +272,7 @@ impl<TFilter: Fn(WalkEntry) -> bool> FileCollector<TFilter> { ignore_git_folder: false, ignore_node_modules: false, ignore_vendor_folder: false, + vendor_folder: None, use_gitignore: false, } } @@ -285,6 +287,11 @@ impl<TFilter: Fn(WalkEntry) -> bool> FileCollector<TFilter> { self } + pub fn set_vendor_folder(mut self, vendor_folder: Option<PathBuf>) -> Self { + self.vendor_folder = vendor_folder; + self + } + pub fn ignore_git_folder(mut self) -> Self { self.ignore_git_folder = true; self @@ -389,22 +396,10 @@ impl<TFilter: Fn(WalkEntry) -> bool> FileCollector<TFilter> { iterator.skip_current_dir(); } } else if is_dir { - let should_ignore_dir = path - .file_name() - .map(|dir_name| { - let dir_name = dir_name.to_string_lossy().to_lowercase(); - let is_ignored_file = match dir_name.as_str() { - "node_modules" => self.ignore_node_modules, - "vendor" => self.ignore_vendor_folder, - ".git" => self.ignore_git_folder, - _ => false, - }; - // allow the user to opt out of ignoring by explicitly specifying the dir - file != path && is_ignored_file - }) - .unwrap_or(false) - || !visited_paths.insert(path.clone()); - if should_ignore_dir { + // allow the user to opt out of ignoring by explicitly specifying the dir + let opt_out_ignore = file == path; + let should_ignore_dir = !opt_out_ignore && self.is_ignored_dir(&path); + if should_ignore_dir || !visited_paths.insert(path.clone()) { iterator.skip_current_dir(); } } else if (self.file_filter)(WalkEntry { @@ -419,6 +414,31 @@ impl<TFilter: Fn(WalkEntry) -> bool> FileCollector<TFilter> { } Ok(target_files) } + + fn is_ignored_dir(&self, path: &Path) -> bool { + path + .file_name() + .map(|dir_name| { + let dir_name = dir_name.to_string_lossy().to_lowercase(); + let is_ignored_file = match dir_name.as_str() { + "node_modules" => self.ignore_node_modules, + "vendor" => self.ignore_vendor_folder, + ".git" => self.ignore_git_folder, + _ => false, + }; + is_ignored_file + }) + .unwrap_or(false) + || self.is_vendor_folder(path) + } + + fn is_vendor_folder(&self, path: &Path) -> bool { + self + .vendor_folder + .as_ref() + .map(|vendor_folder| path == *vendor_folder) + .unwrap_or(false) + } } /// Collects module specifiers that satisfy the given predicate as a file path, by recursively walking `include`. |