summaryrefslogtreecommitdiff
path: root/cli/tools/registry/tar.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-04-24 14:52:05 -0400
committerGitHub <noreply@github.com>2024-04-24 18:52:05 +0000
commitded6afccf21f0f6804fa5ff8bd7e5be6275092d5 (patch)
treed4f8131e6dc8e702bf3841be8525adde7afdba75 /cli/tools/registry/tar.rs
parentda70608700274392a8f134735ac3701eecd6cfa7 (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/tar.rs')
-rw-r--r--cli/tools/registry/tar.rs111
1 files changed, 8 insertions, 103 deletions
diff --git a/cli/tools/registry/tar.rs b/cli/tools/registry/tar.rs
index fdc2f2fcd..8124a0c9e 100644
--- a/cli/tools/registry/tar.rs
+++ b/cli/tools/registry/tar.rs
@@ -2,25 +2,20 @@
use bytes::Bytes;
use deno_ast::MediaType;
-use deno_ast::ModuleSpecifier;
-use deno_config::glob::FilePatterns;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::url::Url;
use sha2::Digest;
-use std::collections::HashSet;
use std::fmt::Write as FmtWrite;
use std::io::Write;
use std::path::Path;
use tar::Header;
-use crate::args::CliOptions;
use crate::cache::LazyGraphSourceParser;
-use crate::tools::registry::paths::PackagePath;
-use crate::util::fs::FileCollector;
use super::diagnostics::PublishDiagnostic;
use super::diagnostics::PublishDiagnosticsCollector;
+use super::paths::CollectedPublishPath;
use super::unfurl::SpecifierUnfurler;
#[derive(Debug, Clone, PartialEq)]
@@ -39,117 +34,27 @@ pub struct PublishableTarball {
}
pub fn create_gzipped_tarball(
- dir: &Path,
- cli_options: &CliOptions,
+ publish_paths: &[CollectedPublishPath],
source_parser: LazyGraphSourceParser,
diagnostics_collector: &PublishDiagnosticsCollector,
unfurler: &SpecifierUnfurler,
- file_patterns: Option<FilePatterns>,
) -> Result<PublishableTarball, AnyError> {
- let file_patterns = file_patterns
- .unwrap_or_else(|| FilePatterns::new_with_base(dir.to_path_buf()));
let mut tar = TarGzArchive::new();
let mut files = vec![];
- let iter_paths = FileCollector::new(|e| {
- if !e.file_type.is_file() {
- if let Ok(specifier) = ModuleSpecifier::from_file_path(e.path) {
- diagnostics_collector.push(PublishDiagnostic::UnsupportedFileType {
- specifier,
- kind: if e.file_type.is_symlink() {
- "symlink".to_owned()
- } else {
- format!("{:?}", e.file_type)
- },
- });
- }
- return false;
- }
- e.path
- .file_name()
- .map(|s| s != ".DS_Store" && s != ".gitignore")
- .unwrap_or(true)
- })
- .ignore_git_folder()
- .ignore_node_modules()
- .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned))
- .use_gitignore()
- .collect_file_patterns(file_patterns)?;
-
- let mut paths = HashSet::with_capacity(iter_paths.len());
-
- for path in iter_paths {
- let Ok(specifier) = Url::from_file_path(&path) else {
- diagnostics_collector
- .to_owned()
- .push(PublishDiagnostic::InvalidPath {
- path: path.to_path_buf(),
- message: "unable to convert path to url".to_string(),
- });
- continue;
- };
-
- let Ok(relative_path) = path.strip_prefix(dir) else {
- diagnostics_collector
- .to_owned()
- .push(PublishDiagnostic::InvalidPath {
- path: path.to_path_buf(),
- message: "path is not in publish directory".to_string(),
- });
- continue;
- };
-
- let path_str =
- relative_path
- .components()
- .fold("".to_string(), |mut path, component| {
- path.push('/');
- match component {
- std::path::Component::Normal(normal) => {
- path.push_str(&normal.to_string_lossy())
- }
- std::path::Component::CurDir => path.push('.'),
- std::path::Component::ParentDir => path.push_str(".."),
- _ => unreachable!(),
- }
- path
- });
-
- match PackagePath::new(path_str.clone()) {
- Ok(package_path) => {
- if !paths.insert(package_path) {
- diagnostics_collector.to_owned().push(
- PublishDiagnostic::DuplicatePath {
- path: path.to_path_buf(),
- },
- );
- }
- }
- Err(err) => {
- diagnostics_collector
- .to_owned()
- .push(PublishDiagnostic::InvalidPath {
- path: path.to_path_buf(),
- message: err.to_string(),
- });
- }
- }
+ for path in publish_paths {
+ let path_str = &path.relative_path;
+ let specifier = &path.specifier;
+ let path = &path.path;
let content = resolve_content_maybe_unfurling(
- &path,
- &specifier,
+ path,
+ specifier,
unfurler,
source_parser,
diagnostics_collector,
)?;
- let media_type = MediaType::from_specifier(&specifier);
- if matches!(media_type, MediaType::Jsx | MediaType::Tsx) {
- diagnostics_collector.push(PublishDiagnostic::UnsupportedJsxTsx {
- specifier: specifier.clone(),
- });
- }
-
files.push(PublishableTarballFile {
path_str: path_str.clone(),
specifier: specifier.clone(),