Skip to content

Commit 5f8be1f

Browse files
authored
Turbopack: Use structured styled text in issue descriptions (#58156)
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.
1 parent a551569 commit 5f8be1f

File tree

14 files changed

+199
-93
lines changed

14 files changed

+199
-93
lines changed

Cargo.lock

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ next-transform-strip-page-exports = { path = "packages/next-swc/crates/next-tran
4040
testing = { version = "0.35.7" }
4141

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

4949
# General Deps
5050

packages/next-swc/crates/napi/src/next_api/utils.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use turbopack_binding::{
1313
turbopack::core::{
1414
diagnostics::{Diagnostic, DiagnosticContextExt, PlainDiagnostic},
1515
error::PrettyPrintError,
16-
issue::{IssueDescriptionExt, PlainIssue, PlainIssueSource, PlainSource},
16+
issue::{IssueDescriptionExt, PlainIssue, PlainIssueSource, PlainSource, StyledString},
1717
source_pos::SourcePos,
1818
},
1919
};
@@ -101,7 +101,7 @@ pub struct NapiIssue {
101101
pub category: String,
102102
pub file_path: String,
103103
pub title: String,
104-
pub description: String,
104+
pub description: serde_json::Value,
105105
pub detail: String,
106106
pub source: Option<NapiIssueSource>,
107107
pub documentation_link: String,
@@ -111,7 +111,8 @@ pub struct NapiIssue {
111111
impl From<&PlainIssue> for NapiIssue {
112112
fn from(issue: &PlainIssue) -> Self {
113113
Self {
114-
description: issue.description.clone(),
114+
description: serde_json::to_value(Into::<NapiStyledString>::into(&issue.description))
115+
.unwrap(),
115116
category: issue.category.clone(),
116117
file_path: issue.file_path.clone(),
117118
detail: issue.detail.clone(),
@@ -128,6 +129,38 @@ impl From<&PlainIssue> for NapiIssue {
128129
}
129130
}
130131

132+
#[derive(Serialize)]
133+
#[serde(tag = "type", rename_all = "camelCase")]
134+
pub enum NapiStyledString {
135+
Line { value: Vec<NapiStyledString> },
136+
Stack { value: Vec<NapiStyledString> },
137+
Text { value: String },
138+
Code { value: String },
139+
Strong { value: String },
140+
}
141+
142+
impl From<&StyledString> for NapiStyledString {
143+
fn from(value: &StyledString) -> Self {
144+
match value {
145+
StyledString::Line(parts) => NapiStyledString::Line {
146+
value: parts.iter().map(|p| p.into()).collect(),
147+
},
148+
StyledString::Stack(parts) => NapiStyledString::Stack {
149+
value: parts.iter().map(|p| p.into()).collect(),
150+
},
151+
StyledString::Text(string) => NapiStyledString::Text {
152+
value: string.clone(),
153+
},
154+
StyledString::Code(string) => NapiStyledString::Code {
155+
value: string.clone(),
156+
},
157+
StyledString::Strong(string) => NapiStyledString::Strong {
158+
value: string.clone(),
159+
},
160+
}
161+
}
162+
}
163+
131164
#[napi(object)]
132165
pub struct NapiIssueSource {
133166
pub source: NapiSource,

0 commit comments

Comments
 (0)