diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-04-24 14:52:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-24 18:52:05 +0000 |
commit | ded6afccf21f0f6804fa5ff8bd7e5be6275092d5 (patch) | |
tree | d4f8131e6dc8e702bf3841be8525adde7afdba75 /cli/tools/registry/mod.rs | |
parent | da70608700274392a8f134735ac3701eecd6cfa7 (diff) |
fix(publish): --dry-publish should error for gitignored excluded files (#23540)
Files that were gitignored only were not included in the diagnostic.
Diffstat (limited to 'cli/tools/registry/mod.rs')
-rw-r--r-- | cli/tools/registry/mod.rs | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index de319281b..b8d31853b 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use std::collections::HashMap; +use std::collections::HashSet; use std::io::IsTerminal; use std::path::Path; use std::process::Stdio; @@ -68,6 +69,7 @@ use unfurl::SpecifierUnfurler; use super::check::TypeChecker; +use self::paths::CollectedPublishPath; use self::tar::PublishableTarball; fn ring_bell() { @@ -105,7 +107,7 @@ async fn prepare_publish( diagnostics_collector: &PublishDiagnosticsCollector, ) -> Result<Rc<PreparedPublishPackage>, AnyError> { let config_path = deno_json.specifier.to_file_path().unwrap(); - let dir_path = config_path.parent().unwrap().to_path_buf(); + let root_dir = config_path.parent().unwrap().to_path_buf(); let Some(version) = deno_json.json.version.clone() else { bail!("{} is missing 'version' field", deno_json.specifier); }; @@ -113,7 +115,7 @@ async fn prepare_publish( let mut suggested_entrypoint = None; for entrypoint in SUGGESTED_ENTRYPOINTS { - if dir_path.join(entrypoint).exists() { + if root_dir.join(entrypoint).exists() { suggested_entrypoint = Some(entrypoint); break; } @@ -143,7 +145,10 @@ async fn prepare_publish( let Some((scope, name_no_scope)) = name_no_at.split_once('/') else { bail!("Invalid package name, use '@<scope_name>/<package_name> format"); }; - let file_patterns = deno_json.to_publish_config()?.map(|c| c.files); + let file_patterns = deno_json + .to_publish_config()? + .map(|c| c.files) + .unwrap_or_else(|| FilePatterns::new_with_base(root_dir.to_path_buf())); let diagnostics_collector = diagnostics_collector.clone(); let tarball = deno_core::unsync::spawn_blocking(move || { @@ -154,20 +159,24 @@ async fn prepare_publish( bare_node_builtins, ); let root_specifier = - ModuleSpecifier::from_directory_path(&dir_path).unwrap(); + ModuleSpecifier::from_directory_path(&root_dir).unwrap(); + let publish_paths = paths::collect_publish_paths( + &root_dir, + &cli_options, + &diagnostics_collector, + file_patterns, + )?; collect_excluded_module_diagnostics( &root_specifier, &graph, - file_patterns.as_ref(), + &publish_paths, &diagnostics_collector, ); tar::create_gzipped_tarball( - &dir_path, - &cli_options, + &publish_paths, LazyGraphSourceParser::new(&source_cache, &graph), &diagnostics_collector, &unfurler, - file_patterns, ) .context("Failed to create a tarball") }) @@ -205,13 +214,14 @@ async fn prepare_publish( fn collect_excluded_module_diagnostics( root: &ModuleSpecifier, graph: &deno_graph::ModuleGraph, - file_patterns: Option<&FilePatterns>, + publish_paths: &[CollectedPublishPath], diagnostics_collector: &PublishDiagnosticsCollector, ) { - let Some(file_patterns) = file_patterns else { - return; - }; - let specifiers = graph + let publish_specifiers = publish_paths + .iter() + .map(|path| &path.specifier) + .collect::<HashSet<_>>(); + let graph_specifiers = graph .modules() .filter_map(|m| match m { deno_graph::Module::Js(_) | deno_graph::Module::Json(_) => { @@ -222,8 +232,8 @@ fn collect_excluded_module_diagnostics( | deno_graph::Module::External(_) => None, }) .filter(|s| s.as_str().starts_with(root.as_str())); - for specifier in specifiers { - if !file_patterns.matches_specifier(specifier) { + for specifier in graph_specifiers { + if !publish_specifiers.contains(specifier) { diagnostics_collector.push(PublishDiagnostic::ExcludedModule { specifier: specifier.clone(), }); |