From 154268a144dfac40a24f09c6ffc8a2fb48aa50be Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 22 Nov 2023 04:39:24 -0800 Subject: [PATCH] Turbopack: Use styled issue titles and details (#58743) This uses styled issue titles and details introduced in vercel/turbo#6535, which also moves "Module not found" messaging to the title field for those issues. Closes PACK-2013 --------- Co-authored-by: Tobias Koppers Co-authored-by: Leah Co-authored-by: Zack Tanner --- Cargo.lock | 66 +++++++++---------- Cargo.toml | 6 +- .../crates/napi/src/next_api/utils.rs | 61 +++++++++-------- .../next-core/src/app_segment_config.rs | 33 ++++++---- .../crates/next-core/src/app_structure.rs | 15 +++-- .../next-swc/crates/next-core/src/babel.rs | 15 +++-- .../crates/next-core/src/next_config.rs | 23 ++++--- .../src/next_font/google/font_fallback.rs | 5 +- .../crates/next-core/src/next_font/issue.rs | 10 +-- .../next-swc/crates/next-core/src/util.rs | 45 +++++++------ packages/next/package.json | 2 +- packages/next/src/build/swc/index.ts | 6 +- .../lib/router-utils/setup-dev-bundler.ts | 29 ++++---- pnpm-lock.yaml | 10 +-- test/development/basic/next-rs-api.test.ts | 21 +++++- 15 files changed, 197 insertions(+), 150 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d585caac1f7c1..da772eab006c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -322,7 +322,7 @@ dependencies = [ [[package]] name = "auto-hash-map" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "serde", "smallvec", @@ -3549,7 +3549,7 @@ dependencies = [ [[package]] name = "node-file-trace" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "serde", @@ -7695,7 +7695,7 @@ dependencies = [ [[package]] name = "turbo-tasks" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "async-trait", @@ -7727,7 +7727,7 @@ dependencies = [ [[package]] name = "turbo-tasks-build" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "cargo-lock", @@ -7739,7 +7739,7 @@ dependencies = [ [[package]] name = "turbo-tasks-bytes" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "bytes", @@ -7754,7 +7754,7 @@ dependencies = [ [[package]] name = "turbo-tasks-env" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "dotenvs", @@ -7768,7 +7768,7 @@ dependencies = [ [[package]] name = "turbo-tasks-fetch" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7785,7 +7785,7 @@ dependencies = [ [[package]] name = "turbo-tasks-fs" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "auto-hash-map", @@ -7815,7 +7815,7 @@ dependencies = [ [[package]] name = "turbo-tasks-hash" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "base16", "hex", @@ -7827,7 +7827,7 @@ dependencies = [ [[package]] name = "turbo-tasks-macros" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "convert_case 0.6.0", @@ -7841,7 +7841,7 @@ dependencies = [ [[package]] name = "turbo-tasks-macros-shared" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "proc-macro2", "quote", @@ -7851,7 +7851,7 @@ dependencies = [ [[package]] name = "turbo-tasks-malloc" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "mimalloc", ] @@ -7859,7 +7859,7 @@ dependencies = [ [[package]] name = "turbo-tasks-memory" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "auto-hash-map", @@ -7884,7 +7884,7 @@ dependencies = [ [[package]] name = "turbopack" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "async-recursion", @@ -7915,7 +7915,7 @@ dependencies = [ [[package]] name = "turbopack-binding" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "auto-hash-map", "mdxjs", @@ -7955,7 +7955,7 @@ dependencies = [ [[package]] name = "turbopack-build" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7978,7 +7978,7 @@ dependencies = [ [[package]] name = "turbopack-cli-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "clap 4.4.2", @@ -8002,7 +8002,7 @@ dependencies = [ [[package]] name = "turbopack-core" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "async-recursion", @@ -8032,7 +8032,7 @@ dependencies = [ [[package]] name = "turbopack-css" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "async-trait", @@ -8058,7 +8058,7 @@ dependencies = [ [[package]] name = "turbopack-dev" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -8082,7 +8082,7 @@ dependencies = [ [[package]] name = "turbopack-dev-server" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "async-compression", @@ -8119,7 +8119,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "async-trait", @@ -8153,7 +8153,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-hmr-protocol" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "serde", "serde_json", @@ -8164,7 +8164,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-plugins" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "async-trait", @@ -8187,7 +8187,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-runtime" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "indoc", @@ -8204,7 +8204,7 @@ dependencies = [ [[package]] name = "turbopack-env" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -8220,7 +8220,7 @@ dependencies = [ [[package]] name = "turbopack-image" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "base64 0.21.4", @@ -8240,7 +8240,7 @@ dependencies = [ [[package]] name = "turbopack-json" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "serde", @@ -8255,7 +8255,7 @@ dependencies = [ [[package]] name = "turbopack-mdx" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "mdxjs", @@ -8270,7 +8270,7 @@ dependencies = [ [[package]] name = "turbopack-node" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "async-stream", @@ -8305,7 +8305,7 @@ dependencies = [ [[package]] name = "turbopack-static" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "serde", @@ -8321,7 +8321,7 @@ dependencies = [ [[package]] name = "turbopack-swc-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "swc_core", "turbo-tasks", @@ -8332,7 +8332,7 @@ dependencies = [ [[package]] name = "turbopack-wasm" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231121.2#46a3854518d697f98747cc70f9a6395547549a2c" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-231122.2#b26f1172ee529e00a86cd7b3b59e01c0aac99fba" dependencies = [ "anyhow", "indexmap 1.9.3", diff --git a/Cargo.toml b/Cargo.toml index 3e760d38c0d11..cf33d5921fd23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,11 +43,11 @@ next-transform-strip-page-exports = { path = "packages/next-swc/crates/next-tran testing = { version = "0.35.10" } # Turbo crates -turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231121.2" } +turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231122.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-231121.2" } +turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231122.2" } # [TODO]: need to refactor embed_directory! macro usage in next-core -turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231121.2" } +turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231122.2" } # General Deps diff --git a/packages/next-swc/crates/napi/src/next_api/utils.rs b/packages/next-swc/crates/napi/src/next_api/utils.rs index 3c09a28a4b97f..13ab019977fb7 100644 --- a/packages/next-swc/crates/napi/src/next_api/utils.rs +++ b/packages/next-swc/crates/napi/src/next_api/utils.rs @@ -100,9 +100,9 @@ pub struct NapiIssue { pub severity: String, pub category: String, pub file_path: String, - pub title: String, - pub description: serde_json::Value, - pub detail: String, + pub title: serde_json::Value, + pub description: Option, + pub detail: Option, pub source: Option, pub documentation_link: String, pub sub_issues: Vec, @@ -111,15 +111,20 @@ pub struct NapiIssue { impl From<&PlainIssue> for NapiIssue { fn from(issue: &PlainIssue) -> Self { Self { - description: serde_json::to_value(Into::::into(&issue.description)) - .unwrap(), + description: issue + .description + .as_ref() + .map(|styled| serde_json::to_value(StyledStringSerialize::from(styled)).unwrap()), category: issue.category.clone(), file_path: issue.file_path.clone(), - detail: issue.detail.clone(), + detail: issue + .detail + .as_ref() + .map(|styled| serde_json::to_value(StyledStringSerialize::from(styled)).unwrap()), documentation_link: issue.documentation_link.clone(), severity: issue.severity.as_str().to_string(), source: issue.source.as_deref().map(|source| source.into()), - title: issue.title.clone(), + title: serde_json::to_value(StyledStringSerialize::from(&issue.title)).unwrap(), sub_issues: issue .sub_issues .iter() @@ -131,32 +136,36 @@ impl From<&PlainIssue> for NapiIssue { #[derive(Serialize)] #[serde(tag = "type", rename_all = "camelCase")] -pub enum NapiStyledString { - Line { value: Vec }, - Stack { value: Vec }, - Text { value: String }, - Code { value: String }, - Strong { value: String }, +pub enum StyledStringSerialize<'a> { + Line { + value: Vec>, + }, + Stack { + value: Vec>, + }, + Text { + value: &'a str, + }, + Code { + value: &'a str, + }, + Strong { + value: &'a str, + }, } -impl From<&StyledString> for NapiStyledString { - fn from(value: &StyledString) -> Self { +impl<'a> From<&'a StyledString> for StyledStringSerialize<'a> { + fn from(value: &'a StyledString) -> Self { match value { - StyledString::Line(parts) => NapiStyledString::Line { + StyledString::Line(parts) => StyledStringSerialize::Line { value: parts.iter().map(|p| p.into()).collect(), }, - StyledString::Stack(parts) => NapiStyledString::Stack { + StyledString::Stack(parts) => StyledStringSerialize::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(), - }, + StyledString::Text(string) => StyledStringSerialize::Text { value: string }, + StyledString::Code(string) => StyledStringSerialize::Code { value: string }, + StyledString::Strong(string) => StyledStringSerialize::Strong { value: string }, } } } diff --git a/packages/next-swc/crates/next-core/src/app_segment_config.rs b/packages/next-swc/crates/next-core/src/app_segment_config.rs index 6804322075400..335f724eba630 100644 --- a/packages/next-swc/crates/next-core/src/app_segment_config.rs +++ b/packages/next-swc/crates/next-core/src/app_segment_config.rs @@ -13,7 +13,10 @@ use turbopack_binding::turbopack::{ core::{ file_source::FileSource, ident::AssetIdent, - issue::{Issue, IssueExt, IssueSeverity, IssueSource, OptionIssueSource, StyledString}, + issue::{ + Issue, IssueExt, IssueSeverity, IssueSource, OptionIssueSource, OptionStyledString, + StyledString, + }, source::Source, }, ecmascript::{ @@ -151,7 +154,7 @@ impl NextSegmentConfig { #[turbo_tasks::value(shared)] pub struct NextSegmentConfigParsingIssue { ident: Vc, - detail: Vc, + detail: Vc, source: Vc, } @@ -163,8 +166,8 @@ impl Issue for NextSegmentConfigParsingIssue { } #[turbo_tasks::function] - fn title(&self) -> Vc { - Vc::cell("Unable to parse config export in source file".to_string()) + fn title(&self) -> Vc { + StyledString::Text("Unable to parse config export in source file".to_string()).cell() } #[turbo_tasks::function] @@ -178,18 +181,20 @@ impl Issue for NextSegmentConfigParsingIssue { } #[turbo_tasks::function] - fn description(&self) -> Vc { - 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() + fn description(&self) -> Vc { + Vc::cell(Some( + 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] - fn detail(&self) -> Vc { - self.detail + fn detail(&self) -> Vc { + Vc::cell(Some(self.detail)) } #[turbo_tasks::function] @@ -285,7 +290,7 @@ fn parse_config_value( let (explainer, hints) = value.explain(2, 0); NextSegmentConfigParsingIssue { ident: source.ident(), - detail: Vc::cell(format!("{detail} Got {explainer}.{hints}")), + detail: StyledString::Text(format!("{detail} Got {explainer}.{hints}")).cell(), source: issue_source(source, span), } .cell() diff --git a/packages/next-swc/crates/next-core/src/app_structure.rs b/packages/next-swc/crates/next-core/src/app_structure.rs index 14dca4fe8dc59..3ff195b687a9a 100644 --- a/packages/next-swc/crates/next-core/src/app_structure.rs +++ b/packages/next-swc/crates/next-core/src/app_structure.rs @@ -13,7 +13,7 @@ use turbo_tasks::{ }; use turbopack_binding::{ turbo::tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath}, - turbopack::core::issue::{Issue, IssueExt, IssueSeverity, StyledString}, + turbopack::core::issue::{Issue, IssueExt, IssueSeverity, OptionStyledString, StyledString}, }; use crate::{ @@ -1140,10 +1140,11 @@ impl Issue for DirectoryTreeIssue { } #[turbo_tasks::function] - async fn title(&self) -> Result> { - Ok(Vc::cell( - "An issue occurred while preparing your Next.js app".to_string(), - )) + async fn title(&self) -> Result> { + Ok( + StyledString::Text("An issue occurred while preparing your Next.js app".to_string()) + .cell(), + ) } #[turbo_tasks::function] @@ -1157,7 +1158,7 @@ impl Issue for DirectoryTreeIssue { } #[turbo_tasks::function] - fn description(&self) -> Vc { - self.message + fn description(&self) -> Vc { + Vc::cell(Some(self.message)) } } diff --git a/packages/next-swc/crates/next-core/src/babel.rs b/packages/next-swc/crates/next-core/src/babel.rs index c2cf946391e00..849bde5cd2593 100644 --- a/packages/next-swc/crates/next-core/src/babel.rs +++ b/packages/next-swc/crates/next-core/src/babel.rs @@ -4,7 +4,7 @@ use turbopack_binding::{ turbo::tasks_fs::{FileSystemEntryType, FileSystemPath}, turbopack::{ core::{ - issue::{Issue, IssueExt, IssueSeverity, StyledString}, + issue::{Issue, IssueExt, IssueSeverity, OptionStyledString, StyledString}, reference_type::{CommonJsReferenceSubType, ReferenceType}, resolve::{parse::Request, pattern::Pattern, resolve}, }, @@ -74,10 +74,11 @@ pub async fn maybe_add_babel_loader( { BabelIssue { path: project_root, - title: Vc::cell( + title: StyledString::Text( "Unable to resolve babel-loader, but a babel config is present" .to_owned(), - ), + ) + .cell(), description: StyledString::Text( "Make sure babel-loader is installed via your package manager." .to_owned(), @@ -145,7 +146,7 @@ pub async fn is_babel_loader_available(project_path: Vc) -> Resu #[turbo_tasks::value] struct BabelIssue { path: Vc, - title: Vc, + title: Vc, description: Vc, severity: Vc, } @@ -168,12 +169,12 @@ impl Issue for BabelIssue { } #[turbo_tasks::function] - fn title(&self) -> Vc { + fn title(&self) -> Vc { self.title } #[turbo_tasks::function] - fn description(&self) -> Vc { - self.description + fn description(&self) -> Vc { + Vc::cell(Some(self.description)) } } diff --git a/packages/next-swc/crates/next-core/src/next_config.rs b/packages/next-swc/crates/next-core/src/next_config.rs index c156ce10660de..9c012d17bb6ef 100644 --- a/packages/next-swc/crates/next-core/src/next_config.rs +++ b/packages/next-swc/crates/next-core/src/next_config.rs @@ -12,7 +12,10 @@ use turbopack_binding::{ context::AssetContext, file_source::FileSource, ident::AssetIdent, - issue::{Issue, IssueDescriptionExt, IssueExt, IssueSeverity, StyledString}, + issue::{ + Issue, IssueDescriptionExt, IssueExt, IssueSeverity, OptionStyledString, + StyledString, + }, reference_type::{EntryReferenceSubType, InnerAssets, ReferenceType}, resolve::{ find_context_file, @@ -983,15 +986,19 @@ impl Issue for OutdatedConfigIssue { } #[turbo_tasks::function] - fn title(&self) -> Vc { - Vc::cell(format!( - "\"{}\" has been replaced by \"{}\"", - self.old_name, self.new_name - )) + fn title(&self) -> Vc { + StyledString::Line(vec![ + StyledString::Code(self.old_name.clone()), + StyledString::Text(" has been replaced by ".to_string()), + StyledString::Code(self.new_name.clone()), + ]) + .cell() } #[turbo_tasks::function] - fn description(&self) -> Vc { - StyledString::Text(self.description.to_string()).cell() + fn description(&self) -> Vc { + Vc::cell(Some( + StyledString::Text(self.description.to_string()).cell(), + )) } } diff --git a/packages/next-swc/crates/next-core/src/next_font/google/font_fallback.rs b/packages/next-swc/crates/next-core/src/next_font/google/font_fallback.rs index 171c353b724fa..b45790cce78ab 100644 --- a/packages/next-swc/crates/next-core/src/next_font/google/font_fallback.rs +++ b/packages/next-swc/crates/next-core/src/next_font/google/font_fallback.rs @@ -82,10 +82,11 @@ pub(super) async fn get_font_fallback( Err(_) => { NextFontIssue { path: context, - title: Vc::cell(format!( + title: StyledString::Text(format!( "Failed to find font override values for font `{}`", &options.font_family, - )), + )) + .cell(), description: StyledString::Text( "Skipping generating a fallback font.".to_owned(), ) diff --git a/packages/next-swc/crates/next-core/src/next_font/issue.rs b/packages/next-swc/crates/next-core/src/next_font/issue.rs index 44c021b4c2632..7f0fd762ef208 100644 --- a/packages/next-swc/crates/next-core/src/next_font/issue.rs +++ b/packages/next-swc/crates/next-core/src/next_font/issue.rs @@ -1,13 +1,13 @@ use turbo_tasks::Vc; use turbopack_binding::{ turbo::tasks_fs::FileSystemPath, - turbopack::core::issue::{Issue, IssueSeverity, StyledString}, + turbopack::core::issue::{Issue, IssueSeverity, OptionStyledString, StyledString}, }; #[turbo_tasks::value(shared)] pub(crate) struct NextFontIssue { pub(crate) path: Vc, - pub(crate) title: Vc, + pub(crate) title: Vc, pub(crate) description: Vc, pub(crate) severity: Vc, } @@ -30,12 +30,12 @@ impl Issue for NextFontIssue { } #[turbo_tasks::function] - fn title(&self) -> Vc { + fn title(&self) -> Vc { self.title } #[turbo_tasks::function] - fn description(&self) -> Vc { - self.description + fn description(&self) -> Vc { + Vc::cell(Some(self.description)) } } diff --git a/packages/next-swc/crates/next-core/src/util.rs b/packages/next-swc/crates/next-core/src/util.rs index 381f78a1ce718..d20658aaf80f8 100644 --- a/packages/next-swc/crates/next-core/src/util.rs +++ b/packages/next-swc/crates/next-core/src/util.rs @@ -12,7 +12,7 @@ use turbopack_binding::{ asset::AssetContent, environment::{ServerAddr, ServerInfo}, ident::AssetIdent, - issue::{Issue, IssueExt, IssueSeverity, StyledString}, + issue::{Issue, IssueExt, IssueSeverity, OptionStyledString, StyledString}, module::Module, source::Source, virtual_source::VirtualSource, @@ -165,7 +165,7 @@ impl ValueDefault for NextSourceConfig { #[turbo_tasks::value(shared)] pub struct NextSourceConfigParsingIssue { ident: Vc, - detail: Vc, + detail: Vc, } #[turbo_tasks::value_impl] @@ -176,8 +176,8 @@ impl Issue for NextSourceConfigParsingIssue { } #[turbo_tasks::function] - fn title(&self) -> Vc { - Vc::cell("Unable to parse config export in source file".to_string()) + fn title(&self) -> Vc { + StyledString::Text("Unable to parse config export in source file".to_string()).cell() } #[turbo_tasks::function] @@ -191,18 +191,20 @@ impl Issue for NextSourceConfigParsingIssue { } #[turbo_tasks::function] - fn description(&self) -> Vc { - 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() + fn description(&self) -> Vc { + Vc::cell(Some( + 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] - fn detail(&self) -> Vc { - self.detail + fn detail(&self) -> Vc { + Vc::cell(Some(self.detail)) } } @@ -238,11 +240,12 @@ pub async fn parse_config_from_source(module: Vc>) -> Result>) -> Result>) -> Result>, value: &JsValue) -> N let (explainer, hints) = value.explain(2, 0); NextSourceConfigParsingIssue { ident: module.ident(), - detail: Vc::cell(format!("{detail} Got {explainer}.{hints}")), + detail: StyledString::Text(format!("{detail} Got {explainer}.{hints}")).cell(), } .cell() .emit() diff --git a/packages/next/package.json b/packages/next/package.json index c1876e2481066..518b85a4c064d 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -193,7 +193,7 @@ "@types/ws": "8.2.0", "@vercel/ncc": "0.34.0", "@vercel/nft": "0.22.6", - "@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231121.2", + "@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231122.2", "acorn": "8.5.0", "amphtml-validator": "1.0.35", "anser": "1.4.9", diff --git a/packages/next/src/build/swc/index.ts b/packages/next/src/build/swc/index.ts index ec11391b36490..225a0e9a4107c 100644 --- a/packages/next/src/build/swc/index.ts +++ b/packages/next/src/build/swc/index.ts @@ -499,9 +499,9 @@ export interface Issue { severity: string category: string filePath: string - title: string - description: StyledString - detail: string + title: StyledString + description?: StyledString + detail?: StyledString source?: { source: { ident: string diff --git a/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts b/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts index 1155a2c6eede3..d2a5176230518 100644 --- a/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts +++ b/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts @@ -291,7 +291,10 @@ async function startWatcher(opts: SetupOpts) { function formatIssue(issue: Issue) { const { filePath, title, description, source, detail } = issue - let formattedTitle = title.replace(/\n/g, '\n ') + let formattedTitle = renderStyledStringToErrorAnsi(title).replace( + /\n/g, + '\n ' + ) let formattedFilePath = filePath .replace('[project]/', '') @@ -341,7 +344,10 @@ async function startWatcher(opts: SetupOpts) { } if (detail) { - message += `\n${detail.replace(/\n/g, '\n ')}` + message += `\n${renderStyledStringToErrorAnsi(detail).replace( + /\n/g, + '\n ' + )}` } return message @@ -502,7 +508,9 @@ async function startWatcher(opts: SetupOpts) { errors.set(key, { message, - details: issue.detail, + details: issue.detail + ? renderStyledStringToErrorAnsi(issue.detail) + : undefined, }) } } @@ -2518,19 +2526,10 @@ function renderStyledStringToErrorAnsi(string: StyledString): string { return bold(red(string.value)) case 'code': return green(string.value) - case 'line': { - let line = '' - for (const styled of string.value) { - line += renderStyledStringToErrorAnsi(styled) - } - return line + '\n' - } + case 'line': + return string.value.map(renderStyledStringToErrorAnsi).join('') case 'stack': - let stack = '' - for (const styled of string.value) { - stack += renderStyledStringToErrorAnsi(styled) + '\n' - } - return stack + '\n' + return string.value.map(renderStyledStringToErrorAnsi).join('\n') default: throw new Error('Unknown StyledString type', string) } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 93bac11312c32..6433a3c6a1e64 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1065,8 +1065,8 @@ importers: specifier: 0.22.6 version: 0.22.6 '@vercel/turbopack-ecmascript-runtime': - specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231121.2 - version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231121.2(react-refresh@0.12.0)(webpack@5.86.0)' + specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231122.2 + version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231122.2(react-refresh@0.12.0)(webpack@5.86.0)' acorn: specifier: 8.5.0 version: 8.5.0 @@ -24646,9 +24646,9 @@ packages: /zwitch@2.0.4: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} - '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231121.2(react-refresh@0.12.0)(webpack@5.86.0)': - resolution: {registry: https://registry.npmjs.org/, tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231121.2} - id: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231121.2' + '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231122.2(react-refresh@0.12.0)(webpack@5.86.0)': + resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231122.2} + id: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-231122.2' name: '@vercel/turbopack-ecmascript-runtime' version: 0.0.0 dependencies: diff --git a/test/development/basic/next-rs-api.test.ts b/test/development/basic/next-rs-api.test.ts index b5648106c6afb..c24ab30b122ce 100644 --- a/test/development/basic/next-rs-api.test.ts +++ b/test/development/basic/next-rs-api.test.ts @@ -8,6 +8,7 @@ import { Issue, loadBindings, Project, + StyledString, TurbopackResult, UpdateInfo, } from 'next/src/build/swc' @@ -23,11 +24,29 @@ function normalizePath(path: string) { ) } +function styledStringToMarkdown(styled: StyledString): string { + switch (styled.type) { + case 'text': + return styled.value + case 'strong': + return '**' + styled.value + '**' + case 'code': + return '`' + styled.value + '`' + case 'line': + return styled.value.map(styledStringToMarkdown).join('') + case 'stack': + return styled.value.map(styledStringToMarkdown).join('\n') + default: + throw new Error('Unknown StyledString type', styled) + } +} + function normalizeIssues(issues: Issue[]) { return issues .map((issue) => ({ ...issue, - detail: issue.detail && normalizePath(issue.detail), + detail: + issue.detail && normalizePath(styledStringToMarkdown(issue.detail)), filePath: issue.filePath && normalizePath(issue.filePath), source: issue.source && { ...issue.source,