summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
authorBartek Iwańczuk <biwanczuk@gmail.com>2023-12-12 15:45:45 +0100
committerGitHub <noreply@github.com>2023-12-12 23:45:45 +0900
commitece78cfb8a9f641b67eaa350bb5344c8bec301bd (patch)
tree09e1c2110321f5e7222c0f70e142b8b157da6af2 /cli/tools
parent06c5f99a01698feba4ce67fa911428cf2d8c95d4 (diff)
refactor: nicer warning display (#21547)
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/registry/mod.rs56
-rw-r--r--cli/tools/registry/tar.rs12
2 files changed, 62 insertions, 6 deletions
diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs
index 202d66ee9..fa9fbe33f 100644
--- a/cli/tools/registry/mod.rs
+++ b/cli/tools/registry/mod.rs
@@ -53,6 +53,7 @@ struct PreparedPublishPackage {
version: String,
tarball_hash: String,
tarball: Bytes,
+ diagnostics: Vec<String>,
}
#[derive(serde::Deserialize)]
@@ -100,8 +101,9 @@ async fn prepare_publish(
let unfurler = ImportMapUnfurler::new(import_map);
- let tarball = tar::create_gzipped_tarball(directory_path, unfurler)
- .context("Failed to create a tarball")?;
+ let (tarball, diagnostics) =
+ tar::create_gzipped_tarball(directory_path, unfurler)
+ .context("Failed to create a tarball")?;
let tarball_hash_bytes: Vec<u8> =
sha2::Sha256::digest(&tarball).iter().cloned().collect();
@@ -116,6 +118,7 @@ async fn prepare_publish(
version: version.to_string(),
tarball_hash,
tarball,
+ diagnostics,
})
}
@@ -221,6 +224,47 @@ struct OidcTokenResponse {
value: String,
}
+/// Prints diagnostics like so:
+/// ```
+///
+/// Warning
+/// ├╌ Dynamic import was not analyzable...
+/// ├╌╌ at file:///dev/foo/bar/foo.ts:4:5
+/// |
+/// ├╌ Dynamic import was not analyzable...
+/// ├╌╌ at file:///dev/foo/bar/foo.ts:4:5
+/// |
+/// ├╌ Dynamic import was not analyzable...
+/// └╌╌ at file:///dev/foo/bar/foo.ts:4:5
+///
+/// ```
+fn print_diagnostics(diagnostics: Vec<String>) {
+ if !diagnostics.is_empty() {
+ let len = diagnostics.len();
+ log::warn!("");
+ log::warn!("{}", crate::colors::yellow("Warning"));
+ for (i, diagnostic) in diagnostics.iter().enumerate() {
+ let last_diagnostic = i == len - 1;
+ let lines = diagnostic.split('\n').collect::<Vec<_>>();
+ let lines_len = lines.len();
+ if i != 0 {
+ log::warn!("|");
+ }
+ for (j, line) in lines.iter().enumerate() {
+ let last_line = j == lines_len - 1;
+ if j == 0 {
+ log::warn!("├╌ {}", line);
+ } else if last_line && last_diagnostic {
+ log::warn!("└╌╌ {}", line);
+ } else {
+ log::warn!("├╌╌ {}", line);
+ }
+ }
+ }
+ log::warn!("");
+ }
+}
+
async fn perform_publish(
http_client: &Arc<HttpClient>,
packages: Vec<PreparedPublishPackage>,
@@ -229,6 +273,12 @@ async fn perform_publish(
let client = http_client.client()?;
let registry_url = deno_registry_api_url().to_string();
+ let diagnostics = packages
+ .iter()
+ .flat_map(|p| p.diagnostics.clone())
+ .collect::<Vec<_>>();
+ print_diagnostics(diagnostics);
+
let permissions = packages
.iter()
.map(|package| Permission::VersionPublish {
@@ -267,6 +317,8 @@ async fn perform_publish(
println!(" @{}/{}", packages[0].scope, packages[0].package);
}
+ // ASCII code for the bell character.
+ print!("\x07");
println!("{}", colors::gray("Waiting..."));
let interval = std::time::Duration::from_secs(auth.poll_interval);
diff --git a/cli/tools/registry/tar.rs b/cli/tools/registry/tar.rs
index 61532917a..418a5b0fd 100644
--- a/cli/tools/registry/tar.rs
+++ b/cli/tools/registry/tar.rs
@@ -16,11 +16,12 @@ pub fn create_gzipped_tarball(
// TODO(bartlomieju): this is too specific, factor it out into a callback that
// returns data
unfurler: ImportMapUnfurler,
-) -> Result<Bytes, AnyError> {
+) -> Result<(Bytes, Vec<String>), AnyError> {
let mut tar = TarGzArchive::new();
let dir = dir
.canonicalize()
.map_err(|_| anyhow::anyhow!("Unable to canonicalize path {:?}", dir))?;
+ let mut diagnostics = vec![];
for entry in walkdir::WalkDir::new(&dir).follow_links(false) {
let entry = entry?;
@@ -37,9 +38,11 @@ pub fn create_gzipped_tarball(
})?;
let data = std::fs::read(entry.path())
.with_context(|| format!("Unable to read file {:?}", entry.path()))?;
- let content = unfurler
+ let (content, unfurl_diagnostics) = unfurler
.unfurl(&url, data)
.with_context(|| format!("Unable to unfurl file {:?}", entry.path()))?;
+
+ diagnostics.extend_from_slice(&unfurl_diagnostics);
tar
.add_file(relative_path.to_string(), &content)
.with_context(|| {
@@ -48,12 +51,13 @@ pub fn create_gzipped_tarball(
} else if entry.file_type().is_dir() {
// skip
} else {
- log::warn!("Unsupported file type at path {:?}", entry.path());
+ diagnostics
+ .push(format!("Unsupported file type at path {:?}", entry.path()));
}
}
let v = tar.finish().context("Unable to finish tarball")?;
- Ok(Bytes::from(v))
+ Ok((Bytes::from(v), diagnostics))
}
struct TarGzArchive {