Skip to content

Commit

Permalink
[TMP] Merge styled
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Nov 15, 2023
1 parent 08af337 commit 69d5a49
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 50 deletions.
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
7 changes: 4 additions & 3 deletions packages/next-swc/crates/next-core/src/app_segment_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use turbopack_binding::turbopack::{
core::{
file_source::FileSource,
ident::AssetIdent,
issue::{Issue, IssueExt, IssueSeverity, IssueSource, OptionIssueSource},
issue::{Issue, IssueExt, IssueSeverity, IssueSource, OptionIssueSource, StyledString},
source::Source,
},
ecmascript::{
Expand Down Expand Up @@ -178,12 +178,13 @@ impl Issue for NextSegmentConfigParsingIssue {
}

#[turbo_tasks::function]
fn description(&self) -> Vc<String> {
Vc::cell(
fn description(&self) -> Vc<StyledString> {
StyledString::Text(
"The exported configuration object in a source file need to have a very specific \
format from which some properties can be statically parsed at compiled-time."
.to_string(),
)
.cell()
}

#[turbo_tasks::function]
Expand Down
16 changes: 9 additions & 7 deletions packages/next-swc/crates/next-core/src/app_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use turbo_tasks::{
};
use turbopack_binding::{
turbo::tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath},
turbopack::core::issue::{Issue, IssueExt, IssueSeverity},
turbopack::core::issue::{Issue, IssueExt, IssueSeverity, StyledString},
};

use crate::{
Expand Down Expand Up @@ -468,11 +468,12 @@ fn conflict_issue(

DirectoryTreeIssue {
app_dir,
message: Vc::cell(format!(
message: StyledString::Text(format!(
"Conflicting {} at {}: {a} at {value_a} and {b} at {value_b}",
item_names,
e.key(),
)),
))
.cell(),
severity: IssueSeverity::Error.cell(),
}
.cell()
Expand Down Expand Up @@ -781,11 +782,12 @@ async fn directory_tree_to_loader_tree(
// TODO: improve error message to have the full paths
DirectoryTreeIssue {
app_dir,
message: Vc::cell(format!(
message: StyledString::Text(format!(
"You cannot have two parallel pages that resolve to the same path. Route \
{} has multiple matches in {}",
for_app_path, app_page
)),
))
.cell(),
severity: IssueSeverity::Error.cell(),
}
.cell()
Expand Down Expand Up @@ -1127,7 +1129,7 @@ pub async fn get_global_metadata(
struct DirectoryTreeIssue {
pub severity: Vc<IssueSeverity>,
pub app_dir: Vc<FileSystemPath>,
pub message: Vc<String>,
pub message: Vc<StyledString>,
}

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -1155,7 +1157,7 @@ impl Issue for DirectoryTreeIssue {
}

#[turbo_tasks::function]
fn description(&self) -> Vc<String> {
fn description(&self) -> Vc<StyledString> {
self.message
}
}
11 changes: 6 additions & 5 deletions packages/next-swc/crates/next-core/src/babel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use turbopack_binding::{
turbo::tasks_fs::{FileSystemEntryType, FileSystemPath},
turbopack::{
core::{
issue::{Issue, IssueExt, IssueSeverity},
issue::{Issue, IssueExt, IssueSeverity, StyledString},
resolve::{parse::Request, pattern::Pattern, resolve},
},
node::transforms::webpack::WebpackLoaderItem,
Expand Down Expand Up @@ -77,10 +77,11 @@ pub async fn maybe_add_babel_loader(
"Unable to resolve babel-loader, but a babel config is present"
.to_owned(),
),
description: Vc::cell(
description: StyledString::Text(
"Make sure babel-loader is installed via your package manager."
.to_owned(),
),
)
.cell(),
severity: IssueSeverity::Fatal.cell(),
}
.cell()
Expand Down Expand Up @@ -143,7 +144,7 @@ pub async fn is_babel_loader_available(project_path: Vc<FileSystemPath>) -> Resu
struct BabelIssue {
path: Vc<FileSystemPath>,
title: Vc<String>,
description: Vc<String>,
description: Vc<StyledString>,
severity: Vc<IssueSeverity>,
}

Expand All @@ -170,7 +171,7 @@ impl Issue for BabelIssue {
}

#[turbo_tasks::function]
fn description(&self) -> Vc<String> {
fn description(&self) -> Vc<StyledString> {
self.description
}
}
6 changes: 3 additions & 3 deletions packages/next-swc/crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use turbopack_binding::{
context::AssetContext,
file_source::FileSource,
ident::AssetIdent,
issue::{Issue, IssueDescriptionExt, IssueExt, IssueSeverity},
issue::{Issue, IssueDescriptionExt, IssueExt, IssueSeverity, StyledString},
reference_type::{EntryReferenceSubType, InnerAssets, ReferenceType},
resolve::{
find_context_file,
Expand Down Expand Up @@ -967,7 +967,7 @@ impl Issue for OutdatedConfigIssue {
}

#[turbo_tasks::function]
fn description(&self) -> Vc<String> {
Vc::cell(self.description.to_string())
fn description(&self) -> Vc<StyledString> {
StyledString::Text(self.description.to_string()).cell()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, Vc};
use turbopack_binding::{
turbo::tasks_fs::FileSystemPath,
turbopack::core::issue::{IssueExt, IssueSeverity},
turbopack::core::issue::{IssueExt, IssueSeverity, StyledString},
};

use super::options::NextFontGoogleOptions;
Expand Down Expand Up @@ -86,7 +86,10 @@ pub(super) async fn get_font_fallback(
"Failed to find font override values for font `{}`",
&options.font_family,
)),
description: Vc::cell("Skipping generating a fallback font.".to_owned()),
description: StyledString::Text(
"Skipping generating a fallback font.".to_owned(),
)
.cell(),
severity: IssueSeverity::Warning.cell(),
}
.cell()
Expand Down
6 changes: 3 additions & 3 deletions packages/next-swc/crates/next-core/src/next_font/issue.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use turbo_tasks::Vc;
use turbopack_binding::{
turbo::tasks_fs::FileSystemPath,
turbopack::core::issue::{Issue, IssueSeverity},
turbopack::core::issue::{Issue, IssueSeverity, StyledString},
};

#[turbo_tasks::value(shared)]
pub(crate) struct NextFontIssue {
pub(crate) path: Vc<FileSystemPath>,
pub(crate) title: Vc<String>,
pub(crate) description: Vc<String>,
pub(crate) description: Vc<StyledString>,
pub(crate) severity: Vc<IssueSeverity>,
}

Expand All @@ -35,7 +35,7 @@ impl Issue for NextFontIssue {
}

#[turbo_tasks::function]
fn description(&self) -> Vc<String> {
fn description(&self) -> Vc<StyledString> {
self.description
}
}
7 changes: 4 additions & 3 deletions packages/next-swc/crates/next-core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use turbopack_binding::{
asset::AssetContent,
environment::{ServerAddr, ServerInfo},
ident::AssetIdent,
issue::{Issue, IssueExt, IssueSeverity},
issue::{Issue, IssueExt, IssueSeverity, StyledString},
module::Module,
source::Source,
virtual_source::VirtualSource,
Expand Down Expand Up @@ -191,12 +191,13 @@ impl Issue for NextSourceConfigParsingIssue {
}

#[turbo_tasks::function]
fn description(&self) -> Vc<String> {
Vc::cell(
fn description(&self) -> Vc<StyledString> {
StyledString::Text(
"The exported configuration object in a source file need to have a very specific \
format from which some properties can be statically parsed at compiled-time."
.to_string(),
)
.cell()
}

#[turbo_tasks::function]
Expand Down
24 changes: 23 additions & 1 deletion packages/next/src/build/swc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,34 @@ export interface TurboEngineOptions {
memoryLimit?: number
}

export type StyledString =
| {
type: 'text'
value: string
}
| {
type: 'code'
value: string
}
| {
type: 'strong'
value: string
}
| {
type: 'stack'
value: StyledString[]
}
| {
type: 'line'
value: StyledString[]
}

export interface Issue {
severity: string
category: string
filePath: string
title: string
description: string
description: StyledString
detail: string
source?: {
source: {
Expand Down
Loading

0 comments on commit 69d5a49

Please sign in to comment.