Skip to content

Commit

Permalink
Turbopack: Use structured styled text in issue descriptions (#58156)
Browse files Browse the repository at this point in the history
Requires vercel/turborepo#6388

This uses the structure implemented in vercel/turborepo#6388 to support formatted text when reporting. Right now only the `Line` and basic `String` cases are handled.
  • Loading branch information
wbinnssmith authored Nov 15, 2023
1 parent a551569 commit 5f8be1f
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 93 deletions.
66 changes: 33 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ next-transform-strip-page-exports = { path = "packages/next-swc/crates/next-tran
testing = { version = "0.35.7" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231113.3" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231114.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231113.3" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231114.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231113.3" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231114.2" }

# General Deps

Expand Down
39 changes: 36 additions & 3 deletions packages/next-swc/crates/napi/src/next_api/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use turbopack_binding::{
turbopack::core::{
diagnostics::{Diagnostic, DiagnosticContextExt, PlainDiagnostic},
error::PrettyPrintError,
issue::{IssueDescriptionExt, PlainIssue, PlainIssueSource, PlainSource},
issue::{IssueDescriptionExt, PlainIssue, PlainIssueSource, PlainSource, StyledString},
source_pos::SourcePos,
},
};
Expand Down Expand Up @@ -101,7 +101,7 @@ pub struct NapiIssue {
pub category: String,
pub file_path: String,
pub title: String,
pub description: String,
pub description: serde_json::Value,
pub detail: String,
pub source: Option<NapiIssueSource>,
pub documentation_link: String,
Expand All @@ -111,7 +111,8 @@ pub struct NapiIssue {
impl From<&PlainIssue> for NapiIssue {
fn from(issue: &PlainIssue) -> Self {
Self {
description: issue.description.clone(),
description: serde_json::to_value(Into::<NapiStyledString>::into(&issue.description))
.unwrap(),
category: issue.category.clone(),
file_path: issue.file_path.clone(),
detail: issue.detail.clone(),
Expand All @@ -128,6 +129,38 @@ impl From<&PlainIssue> for NapiIssue {
}
}

#[derive(Serialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum NapiStyledString {
Line { value: Vec<NapiStyledString> },
Stack { value: Vec<NapiStyledString> },
Text { value: String },
Code { value: String },
Strong { value: String },
}

impl From<&StyledString> for NapiStyledString {
fn from(value: &StyledString) -> Self {
match value {
StyledString::Line(parts) => NapiStyledString::Line {
value: parts.iter().map(|p| p.into()).collect(),
},
StyledString::Stack(parts) => NapiStyledString::Stack {
value: parts.iter().map(|p| p.into()).collect(),
},
StyledString::Text(string) => NapiStyledString::Text {
value: string.clone(),
},
StyledString::Code(string) => NapiStyledString::Code {
value: string.clone(),
},
StyledString::Strong(string) => NapiStyledString::Strong {
value: string.clone(),
},
}
}
}

#[napi(object)]
pub struct NapiIssueSource {
pub source: NapiSource,
Expand Down
Loading

0 comments on commit 5f8be1f

Please sign in to comment.