Unverified Commit 19e8e3c3 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

Revert "Revert "[turbopack] Compute Import Traces for Issues"" (#80220)

Reverts vercel/next.js#80215 which was a revert of vercel/next.js#79351

Closes PACK-4105
parent ee94be90
......@@ -9970,6 +9970,7 @@ dependencies = [
"owo-colors 3.5.0",
"rustc-hash 2.1.1",
"serde",
"turbo-rcstr",
"turbo-tasks",
"turbo-tasks-build",
"turbo-tasks-fs",
......
......@@ -48,7 +48,7 @@ use turbopack_core::{
source_map::{OptionStringifiedSourceMap, SourceMap, Token},
version::{PartialUpdate, TotalUpdate, Update, VersionState},
};
use turbopack_ecmascript_hmr_protocol::{ClientUpdateInstruction, ResourceIdentifier};
use turbopack_ecmascript_hmr_protocol::{ClientUpdateInstruction, Issue, ResourceIdentifier};
use turbopack_trace_utils::{
exit::{ExitHandler, ExitReceiver},
filter_layer::FilterLayer,
......@@ -1079,7 +1079,7 @@ pub fn project_hmr_events(
.collect();
let update_issues = issues
.iter()
.map(|issue| (&**issue).into())
.map(|issue| Issue::from(&**issue))
.collect::<Vec<_>>();
let identifier = ResourceIdentifier {
......
......@@ -299,6 +299,7 @@ pub struct NapiIssue {
pub detail: Option<serde_json::Value>,
pub source: Option<NapiIssueSource>,
pub documentation_link: String,
pub import_traces: serde_json::Value,
}
impl From<&PlainIssue> for NapiIssue {
......@@ -318,6 +319,7 @@ impl From<&PlainIssue> for NapiIssue {
severity: issue.severity.as_str().to_string(),
source: issue.source.as_ref().map(|source| source.into()),
title: serde_json::to_value(StyledStringSerialize::from(&issue.title)).unwrap(),
import_traces: serde_json::to_value(&issue.import_traces).unwrap(),
}
}
}
......
......@@ -3,7 +3,7 @@ use std::io::Write;
use anyhow::Result;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{glob::Glob, rope::RopeBuilder};
use turbo_tasks_fs::{FileSystem, VirtualFileSystem, glob::Glob, rope::RopeBuilder};
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{
......@@ -25,6 +25,17 @@ use turbopack_ecmascript::{
utils::StringifyJs,
};
/// Each entry point in the HMR system has an ident with a different nested asset.
/// This produces the 'base' ident for the HMR entry point, which is then modified
#[turbo_tasks::function]
fn hmr_entry_point_base_ident() -> Vc<AssetIdent> {
AssetIdent::from_path(
VirtualFileSystem::new_with_name(rcstr!("hmr-entry"))
.root()
.join(rcstr!("hmr-entry.js")),
)
}
#[turbo_tasks::value(shared)]
pub struct HmrEntryModule {
pub ident: ResolvedVc<AssetIdent>,
......@@ -46,7 +57,7 @@ impl HmrEntryModule {
impl Module for HmrEntryModule {
#[turbo_tasks::function]
fn ident(&self) -> Vc<AssetIdent> {
self.ident.with_modifier(rcstr!("hmr-entry"))
hmr_entry_point_base_ident().with_asset(rcstr!("ENTRY"), *self.ident)
}
#[turbo_tasks::function]
......
......@@ -356,6 +356,7 @@ export interface NapiIssue {
detail?: any
source?: NapiIssueSource
documentationLink: string
importTraces: any
}
export interface NapiIssueSource {
source: NapiSource
......
......@@ -95,6 +95,13 @@ export interface Issue {
}
}
documentationLink: string
importTraces?: PlainTraceItem[][]
}
export interface PlainTraceItem {
fsName: string
path: string
rootPath: string
layer?: string
}
export interface Diagnostics {
......
import type {
Issue,
PlainTraceItem,
StyledString,
TurbopackResult,
} from '../../../build/swc/types'
......@@ -129,9 +130,9 @@ export function processIssues(
}
export function formatIssue(issue: Issue) {
const { filePath, title, description, source } = issue
const { filePath, title, description, source, importTraces } = issue
let { documentationLink } = issue
let formattedTitle = renderStyledStringToErrorAnsi(title).replace(
const formattedTitle = renderStyledStringToErrorAnsi(title).replace(
/\n/g,
'\n '
)
......@@ -144,14 +145,14 @@ export function formatIssue(issue: Issue) {
documentationLink = 'https://nextjs.org/docs/messages/module-not-found'
}
let formattedFilePath = filePath
const formattedFilePath = filePath
.replace('[project]/', './')
.replaceAll('/./', '/')
.replace('\\\\?\\', '')
let message = ''
if (source && source.range) {
if (source?.range) {
const { start } = source.range
message = `${formattedFilePath}:${start.line + 1}:${
start.column + 1
......@@ -209,15 +210,79 @@ export function formatIssue(issue: Issue) {
// message += renderStyledStringToErrorAnsi(detail) + '\n\n'
// }
// TODO: Include a trace from the issue.
if (importTraces?.length) {
// This is the same logic as in turbopack/crates/turbopack-cli-utils/src/issue.rs
if (importTraces.length > 1) {
// We end up with multiple traces when the file with the error is reachable from multiple
// different entry points (e.g. ssr, client)
message += 'Example import traces:\n'
const tracesAndLayers: Array<[string | undefined, PlainTraceItem[]]> =
importTraces.map((trace) => [getLayer(trace), trace])
const everyTraceHasADistinctLayer =
new Set(
tracesAndLayers
.map(([layer, _trace]) => layer)
.filter((layer) => layer != null)
).size === tracesAndLayers.length
for (let i = 0; i < tracesAndLayers.length; i++) {
const [layer, trace] = tracesAndLayers[i]
if (everyTraceHasADistinctLayer) {
message += ` ${layer}:\n`
} else {
message += ` #${i + 1}`
if (layer) {
message += ` [${layer}]`
}
message += ':\n'
}
message += formatIssueTrace(trace, ' ', layer === undefined)
}
} else {
const trace = importTraces[0]
// We only display the layer if there is more than one for the trace
message += `Example import trace:\n${formatIssueTrace(trace, ' ', getLayer(trace) === undefined)}`
}
}
if (documentationLink) {
message += documentationLink + '\n\n'
}
return message
}
/** Returns the layer shared by all the items, or undefined if there isn't a unique one. */
function getLayer(items: PlainTraceItem[]): string | undefined {
let array = Array.from(new Set(items.map((i) => i.layer)))
if (array.length === 1) {
return array[0]
}
return undefined
}
function formatIssueTrace(
items: PlainTraceItem[],
indent: string,
printLayers: boolean
): string {
return (
items
.map((item) => {
let r = indent
if (item.fsName !== 'project') {
r += `[${item.fsName}]/`
} else {
// This is consistent with webpack's output
r += './'
}
r += item.path
if (printLayers && item.layer) {
r += ` [${item.layer}]`
}
return r
})
.join('\n') + '\n\n'
)
}
export function isRelevantWarning(issue: Issue): boolean {
return issue.severity === 'warning' && !isNodeModulesIssue(issue)
}
......
......@@ -464,7 +464,18 @@ describe('ReactRefreshLogBox app', () => {
"label": "Build Error",
"source": "./index.module.css
Parsing css source code failed
Selector is not pure (pure selectors must contain at least one local class or id), (lightningcss, Selector(button, specificity = 0x1))",
Selector is not pure (pure selectors must contain at least one local class or id), (lightningcss, Selector(button, specificity = 0x1))
Example import traces:
#1:
./index.module.css [app-client]
./index.js [app-client]
./app/page.js [app-client]
./app/page.js [app-rsc]
#2:
./index.module.css [app-ssr]
./index.js [app-ssr]
./app/page.js [app-ssr]
./app/page.js [app-rsc]",
"stack": [],
}
`)
......
......@@ -184,7 +184,11 @@ describe('Error overlay - RSC build errors', () => {
4 | return 'client-only-lib'
You're importing a component that imports client-only. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.
Learn more: https://nextjs.org/docs/app/building-your-application/rendering"
Learn more: https://nextjs.org/docs/app/building-your-application/rendering
Example import trace:
./app/server-with-errors/client-only-in-server/client-only-lib.js
./app/server-with-errors/client-only-in-server/page.js"
`)
} else {
expect(await session.getRedboxSource()).toInclude(
......
......@@ -602,7 +602,16 @@ describe('ReactRefreshLogBox', () => {
"label": "Build Error",
"source": "./index.module.css
Parsing css source code failed
Selector is not pure (pure selectors must contain at least one local class or id), (lightningcss, Selector(button, specificity = 0x1))",
Selector is not pure (pure selectors must contain at least one local class or id), (lightningcss, Selector(button, specificity = 0x1))
Example import traces:
client:
./index.module.css
./index.js
./pages/index.js
ssr:
./index.module.css
./index.js
./pages/index.js",
"stack": [],
}
`)
......
......@@ -62,7 +62,16 @@ describe('Error Overlay for server components compiler errors in pages', () => {
3 | export default function Page() {
4 | return <p>hello world</p>
You're importing a component that needs "next/headers". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components"
You're importing a component that needs "next/headers". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
Example import traces:
client:
./components/Comp.js
./pages/index.js
ssr:
./components/Comp.js
./pages/index.js"
`)
} else if (isRspack) {
expect(
......@@ -138,7 +147,16 @@ describe('Error Overlay for server components compiler errors in pages', () => {
3 | export default function Page() {
4 | return 'hello world'
You're importing a component that needs "server-only". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components"
You're importing a component that needs "server-only". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
Example import traces:
client:
./components/Comp.js
./pages/index.js
ssr:
./components/Comp.js
./pages/index.js"
`)
} else if (isRspack) {
expect(
......@@ -216,7 +234,16 @@ describe('Error Overlay for server components compiler errors in pages', () => {
3 | export default function Page() {
4 | return 'hello world'
You're importing a component that needs "after". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components"
You're importing a component that needs "after". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-application/rendering/server-components
Example import traces:
client:
./components/Comp.js
./pages/index.js
ssr:
./components/Comp.js
./pages/index.js"
`)
} else if (isRspack) {
expect(
......
......@@ -23,18 +23,18 @@ describe('app-dir - server-component-next-dynamic-ssr-false', () => {
`"Ecmascript file had an error"`
)
expect(redbox.source).toMatchInlineSnapshot(`
"./app/page.js (3:23)
Ecmascript file had an error
1 | import dynamic from 'next/dynamic'
2 |
> 3 | const DynamicClient = dynamic(() => import('./client'), { ssr: false })
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 |
5 | export default function Page() {
6 | return <DynamicClient />
"./app/page.js (3:23)
Ecmascript file had an error
1 | import dynamic from 'next/dynamic'
2 |
> 3 | const DynamicClient = dynamic(() => import('./client'), { ssr: false })
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 |
5 | export default function Page() {
6 | return <DynamicClient />
\`ssr: false\` is not allowed with \`next/dynamic\` in Server Components. Please move it into a Client Component."
`)
\`ssr: false\` is not allowed with \`next/dynamic\` in Server Components. Please move it into a Client Component."
`)
} else {
expect(redbox.description).toMatchInlineSnapshot(
`" x \`ssr: false\` is not allowed with \`next/dynamic\` in Server Components. Please move it into a Client Component."`
......
......@@ -165,16 +165,16 @@ export function runErrorRecoveryHmrTest(nextConfig: {
if (process.env.IS_TURBOPACK_TEST) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js (7:1)
Parsing ecmascript source code failed
5 | div
6 | )
> 7 | }
| ^
8 |
Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?"
`)
"./pages/hmr/about2.js (7:1)
Parsing ecmascript source code failed
5 | div
6 | )
> 7 | }
| ^
8 |
Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?"
`)
} else if (process.env.NEXT_RSPACK) {
expect(trimEndMultiline(source)).toMatchInlineSnapshot(`
"./pages/hmr/about2.js
......@@ -602,17 +602,26 @@ export function runErrorRecoveryHmrTest(nextConfig: {
if (process.env.IS_TURBOPACK_TEST) {
expect(next.normalizeTestDirContent(redboxSource))
.toMatchInlineSnapshot(`
"./components/parse-error.js (3:1)
Parsing ecmascript source code failed
1 | This
2 | is
> 3 | }}}
| ^
4 | invalid
5 | js
"./components/parse-error.js (3:1)
Parsing ecmascript source code failed
1 | This
2 | is
> 3 | }}}
| ^
4 | invalid
5 | js
Expression expected"
`)
Expression expected
Example import traces:
client:
./components/parse-error.js
./pages/hmr/about9.js
ssr:
./components/parse-error.js
./pages/hmr/about9.js"
`)
} else if (process.env.NEXT_RSPACK) {
expect(trimEndMultiline(next.normalizeTestDirContent(redboxSource)))
.toMatchInlineSnapshot(`
......
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import path from 'node:path'
describe('internal traces', () => {
const { next } = nextTestSetup({
......@@ -8,7 +8,7 @@ describe('internal traces', () => {
it('should not write long internal traces to stdio', async () => {
await next.render$('/traces')
expect(next.cliOutput.length).toBeLessThan(128 * 1024 /* 128kb of ascii */)
expect(next.cliOutput.length).toBeLessThan(256 * 1024 /* 256KiB of ascii */)
expect(next.cliOutput).not.toContain(
'https://nextjs.org/docs/messages/large-page-data'
)
......
......@@ -36,7 +36,12 @@ describe('app dir - css', () => {
47 | }
48 |
Pseudo-elements like '::before' or '::after' can't be followed by selectors like 'Ident("path")' at [project]/app/global.scss.css:0:884"
Pseudo-elements like '::before' or '::after' can't be followed by selectors like 'Ident("path")' at [project]/app/global.scss.css:0:884
Example import trace:
./app/global.scss.css [app-client]
./app/layout.js [app-client]
./app/layout.js [app-rsc]"
`)
})
}
......
......@@ -140,16 +140,16 @@ describe('use-cache-unknown-cache-kind', () => {
if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(`
"./app/page.tsx (1:1)
Ecmascript file had an error
> 1 | 'use cache: custom'
| ^^^^^^^^^^^^^^^^^^^
2 |
3 | export default async function Page() {
4 | return <p>hello world</p>
Unknown cache kind "custom". Please configure a cache handler for this kind in the "experimental.cacheHandlers" object in your Next.js config."
`)
"./app/page.tsx (1:1)
Ecmascript file had an error
> 1 | 'use cache: custom'
| ^^^^^^^^^^^^^^^^^^^
2 |
3 | export default async function Page() {
4 | return <p>hello world</p>
Unknown cache kind "custom". Please configure a cache handler for this kind in the "experimental.cacheHandlers" object in your Next.js config."
`)
} else if (isRspack) {
expect(errorSource).toMatchInlineSnapshot(`
"./app/page.tsx
......
......@@ -34,12 +34,21 @@ function runTests({ isDev }) {
const source = await getRedboxSource(browser)
if (process.env.IS_TURBOPACK_TEST) {
expect(source).toMatchInlineSnapshot(`
"./test/integration/next-image-new/invalid-image-import/public/invalid.svg
Processing image failed
Failed to parse svg source code for image dimensions
"./test/integration/next-image-new/invalid-image-import/public/invalid.svg
Processing image failed
Failed to parse svg source code for image dimensions
Caused by:
- Source code does not contain a <svg> root element"
Caused by:
- Source code does not contain a <svg> root element
Example import traces:
#1:
./test/integration/next-image-new/invalid-image-import/public/invalid.svg
./test/integration/next-image-new/invalid-image-import/pages/index.js [client]
#2:
./test/integration/next-image-new/invalid-image-import/public/invalid.svg
./test/integration/next-image-new/invalid-image-import/pages/index.js [ssr]"
`)
} else {
expect(source).toMatchInlineSnapshot(`
......
......@@ -337,7 +337,7 @@ pub const fn inline_atom(s: &str) -> Option<RcStr> {
/// allocates the RcStr inline when possible otherwise uses a `LazyLock` to manage the allocation.
#[macro_export]
macro_rules! rcstr {
($s:tt) => {{
($s:expr) => {{
const INLINE: core::option::Option<$crate::RcStr> = $crate::inline_atom($s);
// this condition should be able to be compile time evaluated and inlined.
if INLINE.is_some() {
......@@ -445,6 +445,7 @@ mod tests {
assert_eq!(rcstr!("abcdefgh"), RcStr::from("abcdefgh"));
assert_eq!(rcstr!("abcdefghi"), RcStr::from("abcdefghi"));
}
#[test]
fn test_inline_atom() {
// This is a silly test, just asserts that we can evaluate this in a constant context.
......
......@@ -1016,7 +1016,7 @@ pub fn get_relative_path_to(path: &str, other_path: &str) -> String {
}
#[turbo_tasks::value]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Hash)]
pub struct FileSystemPath {
pub fs: ResolvedVc<Box<dyn FileSystem>>,
pub path: RcStr,
......
......@@ -1724,8 +1724,8 @@ pub fn mark_session_dependent() {
});
}
/// Marks the current task as finished. This excludes it from waiting for
/// strongly consistency.
/// Marks the current task as a root in the aggregation graph. This means it starts with the
/// correct aggregation number instead of needing to recompute it after the fact.
pub fn mark_root() {
with_turbo_tasks(|tt| {
tt.set_own_task_aggregation_number(current_task("turbo_tasks::mark_root()"), u32::MAX)
......
......@@ -21,6 +21,7 @@ crossterm = "0.26.0"
owo-colors = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true }
turbo-tasks-fs = { workspace = true }
turbopack-core = { workspace = true }
......
......@@ -12,11 +12,12 @@ use anyhow::{Result, anyhow};
use crossterm::style::{StyledContent, Stylize};
use owo_colors::{OwoColorize as _, Style};
use rustc_hash::{FxHashMap, FxHashSet};
use turbo_tasks::{RawVc, ReadRef, TransientInstance, TransientValue, TryJoinIterExt, Vc};
use turbo_rcstr::RcStr;
use turbo_tasks::{RawVc, ReadRef, TransientInstance, TransientValue, Vc};
use turbo_tasks_fs::{FileLinesContent, source_context::get_source_context};
use turbopack_core::issue::{
CapturedIssues, Issue, IssueReporter, IssueSeverity, PlainIssue, PlainIssueProcessingPathItem,
PlainIssueSource, StyledString,
CapturedIssues, IssueReporter, IssueSeverity, PlainIssue, PlainIssueProcessingPathItem,
PlainIssueSource, PlainTraceItem, StyledString,
};
use crate::source_context::format_source_context_lines;
......@@ -141,7 +142,7 @@ pub fn format_issue(
.replace("[project]", &current_dir.to_string_lossy())
.replace("/./", "/")
.replace("\\\\?\\", "");
let stgae = plain_issue.stage.to_string();
let stage = plain_issue.stage.to_string();
let mut styled_issue = style_issue_source(plain_issue, &context_path);
let description = &plain_issue.description;
......@@ -170,12 +171,100 @@ pub fn format_issue(
writeln!(styled_issue, "{path}").unwrap();
}
}
let traces = &*plain_issue.import_traces;
if !traces.is_empty() {
/// Returns the layer used by all items in the trace if it is unique.
/// Returns None, if there are multiple different layers (or no layers)
fn get_layer(items: &[PlainTraceItem]) -> Option<RcStr> {
let layer = items.first().and_then(|t| t.layer.clone());
for item in items.iter().skip(1) {
if item.layer != layer {
return None;
}
}
layer
}
fn format_trace_items(
out: &mut String,
indent: &'static str,
print_layers: bool,
items: &[PlainTraceItem],
) {
for item in items {
out.push_str(indent);
// We want to format the filepath but with a few caveats
// - if it is part of the `[project]` filesystem, omit the fs name
// - format the label at the end
// - if it is the last item add the special marker `[entrypoint]` to help clarify
// that this is an application entry point
// TODO(lukesandberg): some formatting could be useful. We could use colors,
// bold/faint, links?
if item.fs_name != "project" {
out.push('[');
out.push_str(&item.fs_name);
out.push_str("]/");
} else {
// This is consistent with webpack's output
out.push_str("./");
}
out.push_str(&item.path);
if let Some(ref label) = item.layer
&& print_layers
{
out.push_str(" [");
out.push_str(label);
out.push(']');
}
out.push('\n');
}
}
if traces.len() == 1 {
let trace = &traces[0];
// We don't put the layer in the header for the single case. Either they are all the
// same in which case it should be clear from the filename or they are different and we
// need to print them on the items anyway.
writeln!(styled_issue, "Example import trace:").unwrap();
format_trace_items(&mut styled_issue, " ", get_layer(trace).is_none(), trace);
} else {
// When there are multiple traces we:
// * display the layer in the header if the trace has a consistent layer
// * label the traces with their index, unless the layer is sufficiently unique.
styled_issue.push_str("Example import traces:\n");
let traces_and_layers: Vec<_> = traces.iter().map(|t| (get_layer(t), t)).collect();
let every_trace_has_a_distinct_layer = traces_and_layers
.iter()
.filter_map(|t| t.0.clone())
.collect::<FxHashSet<_>>()
.len()
== traces_and_layers.len();
if every_trace_has_a_distinct_layer {
for (layer, trace) in traces_and_layers {
writeln!(styled_issue, " {}:", layer.unwrap()).unwrap();
format_trace_items(&mut styled_issue, " ", false, trace);
}
} else {
for (index, (layer, trace)) in traces_and_layers.iter().enumerate() {
let print_layers = match layer {
Some(layer) => {
writeln!(styled_issue, " #{} [{layer}]:", index + 1).unwrap();
false
}
None => {
writeln!(styled_issue, " #{}:", index + 1).unwrap();
true
}
};
format_trace_items(&mut styled_issue, " ", print_layers, trace);
}
}
}
}
write!(
issue_text,
"{} - [{}] {}",
severity.style(severity_to_style(severity)),
stgae,
stage,
plain_issue.file_path
)
.unwrap();
......@@ -354,15 +443,14 @@ impl IssueReporter for ConsoleUi {
} = self.options;
let mut grouped_issues: GroupedIssues = FxHashMap::default();
let issues = issues
.iter_with_shortest_path()
.map(|(issue, path)| async move {
let plain_issue = issue.into_plain(path);
let id = plain_issue.internal_hash(false).await?;
Ok((plain_issue.await?, *id))
let plain_issues = issues.get_plain_issues().await?;
let issues = plain_issues
.iter()
.map(|plain_issue| {
let id = plain_issue.internal_hash_ref(false);
(plain_issue, id)
})
.try_join()
.await?;
.collect::<Vec<_>>();
let issue_ids = issues.iter().map(|(_, id)| *id).collect::<FxHashSet<_>>();
let mut new_ids = self
......@@ -390,7 +478,7 @@ impl IssueReporter for ConsoleUi {
let category_map = severity_map.entry(stage.clone()).or_default();
let issues = category_map.entry(context_path.to_string()).or_default();
let mut styled_issue = style_issue_source(&plain_issue, &context_path);
let mut styled_issue = style_issue_source(plain_issue, &context_path);
let description = &plain_issue.description;
if let Some(description) = description {
writeln!(
......
......@@ -35,6 +35,7 @@ pub struct AssetIdent {
impl AssetIdent {
pub fn add_modifier(&mut self, modifier: RcStr) {
debug_assert!(!modifier.is_empty(), "modifiers cannot be empty.");
self.modifiers.push(modifier);
}
......@@ -183,6 +184,7 @@ impl AssetIdent {
#[turbo_tasks::function]
pub fn with_layer(&self, layer: RcStr) -> Vc<Self> {
let mut this = self.clone();
debug_assert!(!layer.is_empty(), "cannot set empty layers names");
this.layer = Some(layer);
Self::new(Value::new(this))
}
......@@ -194,6 +196,13 @@ impl AssetIdent {
Self::new(Value::new(this))
}
#[turbo_tasks::function]
pub fn with_asset(&self, key: RcStr, asset: ResolvedVc<AssetIdent>) -> Vc<Self> {
let mut this = self.clone();
this.add_asset(key, asset);
Self::new(Value::new(this))
}
#[turbo_tasks::function]
pub async fn rename_as(&self, pattern: RcStr) -> Result<Vc<Self>> {
let mut this = self.clone();
......
......@@ -811,7 +811,6 @@ impl Pattern {
.then_some(0)
}
}
fn match_internal<'a>(
&self,
mut value: &'a str,
......
......@@ -185,7 +185,7 @@ where
UpdateStreamItem::Found { update, issues } => {
let issues = issues
.iter()
.map(|p| (&**p).into())
.map(|p| Issue::from(&**p))
.collect::<Vec<Issue<'_>>>();
match &**update {
Update::Partial(partial) => {
......
......@@ -125,13 +125,20 @@ async fn get_update_stream_item_operation(
Ok(content) => content,
Err(e) => {
plain_issues.push(
FatalStreamIssue {
resource,
description: StyledString::Text(format!("{}", PrettyPrintError(&e)).into())
.resolved_cell(),
}
.cell()
.into_plain(OptionIssueProcessingPathItems::none())
PlainIssue::from_issue(
Vc::upcast(
FatalStreamIssue {
resource,
description: StyledString::Text(
format!("{}", PrettyPrintError(&e)).into(),
)
.resolved_cell(),
}
.cell(),
),
None,
OptionIssueProcessingPathItems::none(),
)
.await?,
);
......
......@@ -19,7 +19,7 @@ use turbopack_core::{
// Updates the existing snapshot outputs with the actual outputs of this run.
// e.g. `UPDATE=1 cargo test -p turbopack-tests -- test_my_pattern`
static UPDATE: Lazy<bool> = Lazy::new(|| env::var("UPDATE").unwrap_or_default() == "1");
pub static UPDATE: Lazy<bool> = Lazy::new(|| env::var("UPDATE").unwrap_or_default() == "1");
static ANSI_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\x1b\[\d+m").unwrap());
......
......@@ -13,8 +13,8 @@ use serde::{Deserialize, Serialize};
use tracing_subscriber::{Registry, layer::SubscriberExt, util::SubscriberInitExt};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{
Completion, NonLocalValue, OperationVc, ResolvedVc, TryJoinIterExt, TurboTasks, Value, Vc,
apply_effects, debug::ValueDebugFormat, fxindexmap, trace::TraceRawVcs,
Completion, NonLocalValue, OperationVc, ResolvedVc, TurboTasks, Value, Vc, apply_effects,
debug::ValueDebugFormat, fxindexmap, trace::TraceRawVcs,
};
use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage};
use turbo_tasks_bytes::stream::SingleValue;
......@@ -37,7 +37,7 @@ use turbopack_core::{
context::AssetContext,
environment::{Environment, ExecutionEnvironment, NodeJsEnvironment},
file_source::FileSource,
issue::{Issue, IssueDescriptionExt},
issue::IssueDescriptionExt,
reference_type::{InnerAssets, ReferenceType},
resolve::{
ExternalTraced, ExternalType,
......@@ -49,7 +49,7 @@ use turbopack_ecmascript_runtime::RuntimeType;
use turbopack_node::{debug::should_debug, evaluate::evaluate};
use turbopack_nodejs::NodeJsChunkingContext;
use turbopack_resolve::resolve_options_context::ResolveOptionsContext;
use turbopack_test_utils::jest::JestRunResult;
use turbopack_test_utils::{jest::JestRunResult, snapshot::UPDATE};
use turbopack_trace_utils::{
filter_layer::FilterLayer, raw_trace::RawTraceLayer, trace_writer::TraceWriter,
tracing_presets::TRACING_TURBO_TASKS_TARGETS,
......@@ -193,7 +193,7 @@ async fn run(resource: PathBuf, snapshot_mode: IssueSnapshotMode) -> Result<JsRe
let tt = TurboTasks::new(TurboTasksBackend::new(
BackendOptions {
storage_mode: None,
dependency_tracking: false,
dependency_tracking: *UPDATE,
..Default::default()
},
noop_backing_storage(),
......@@ -505,11 +505,7 @@ async fn snapshot_issues(
let captured_issues = run_result_op.peek_issues_with_path().await?;
let plain_issues = captured_issues
.iter_with_shortest_path()
.map(|(issue_vc, path)| async move { issue_vc.into_plain(path).await })
.try_join()
.await?;
let plain_issues = captured_issues.get_plain_issues().await?;
turbopack_test_utils::snapshot::snapshot_issues(
plain_issues,
......
warning - [analysis] [project]/turbopack/crates/turbopack-tests/tests/execution/turbopack/async-modules/export-all/input/exports.js unexpected export *
export * used with module [project]/turbopack/crates/turbopack-tests/tests/execution/turbopack/async-modules/export-all/input/exports.js [test] (ecmascript) which is a CommonJS module with exports only available at runtime
List all export names manually (`export { a, b, c } from "...") or rewrite the module to ESM, to avoid the additional runtime code.`
\ No newline at end of file
List all export names manually (`export { a, b, c } from "...") or rewrite the module to ESM, to avoid the additional runtime code.`
Example import trace:
./turbopack/crates/turbopack-tests/tests/execution/turbopack/async-modules/export-all/input/exports.js
./turbopack/crates/turbopack-tests/tests/execution/turbopack/async-modules/export-all/input/tla.js
./turbopack/crates/turbopack-tests/tests/execution/turbopack/async-modules/export-all/input/index.js
\ No newline at end of file
......@@ -2,4 +2,8 @@ error - [load] [project]/turbopack/crates/turbopack-tests/tests/execution/turbop
An unexpected error happened while trying to read the source code to parse: failed to convert rope into string
Caused by:
- invalid utf-8 sequence of 1 bytes from index 1
\ No newline at end of file
- invalid utf-8 sequence of 1 bytes from index 1
Example import trace:
./turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/error/input/broken.js
./turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/error/input/index.js
\ No newline at end of file
error - [analysis] [project]/turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/node-default-import/input/node_modules/esm-package/invalid-exports.cjs Specified module format (CommonJs) is not matching the module format of the source code (EcmaScript Modules)
The CommonJs module format was specified in the package.json that is affecting this source file or by using an special extension, but Ecmascript import/export syntax is used in the source code.
The module was automatically converted to an EcmaScript module, but that is in conflict with the specified module format. Either change the "type" field in the package.json or replace EcmaScript import/export syntax with CommonJs syntas in the source file.
In some cases EcmaScript import/export syntax is added by an transform and isn't actually part of the source code. In these cases revisit transformation options to inject the correct syntax.
\ No newline at end of file
In some cases EcmaScript import/export syntax is added by an transform and isn't actually part of the source code. In these cases revisit transformation options to inject the correct syntax.
Example import trace:
./turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/node-default-import/input/node_modules/esm-package/invalid-exports.cjs
./turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/node-default-import/input/node_modules/esm-package/index.js
./turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/node-default-import/input/index.js
\ No newline at end of file
warning - [analysis] [project]/turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/node-default-import/input/node_modules/esm-package/invalid-exports.js Specified module format (EcmaScript Modules) is not matching the module format of the source code (CommonJs)
The EcmaScript module format was specified in the package.json that is affecting this source file or by using an special extension, but it looks like that CommonJs syntax is used in the source code.
Exports made by CommonJs syntax will lead to a runtime error, since the module is in EcmaScript mode. Either change the "type" field in the package.json or replace CommonJs syntax with EcmaScript import/export syntax in the source file.
\ No newline at end of file
Exports made by CommonJs syntax will lead to a runtime error, since the module is in EcmaScript mode. Either change the "type" field in the package.json or replace CommonJs syntax with EcmaScript import/export syntax in the source file.
Example import trace:
./turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/node-default-import/input/node_modules/esm-package/invalid-exports.js
./turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/node-default-import/input/node_modules/esm-package/index.js
./turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/node-default-import/input/index.js
\ No newline at end of file
......@@ -17,4 +17,7 @@ error - [bindings] [project]/turbopack/crates/turbopack-tests/tests/execution/tu
| These are the exports of the module:
| Abd, Eef, a, b, c
|
\ No newline at end of file
|
Example import trace:
./turbopack/crates/turbopack-tests/tests/execution/turbopack/exports/invalid-export/input/invalid-export/index.js
./turbopack/crates/turbopack-tests/tests/execution/turbopack/exports/invalid-export/input/index.js
\ No newline at end of file
warning - [analysis] [project]/turbopack/crates/turbopack-tests/tests/execution/webpack/scope-hoisting/reexport-star-external-cjs/input/a.js unexpected export *
export * used with module [project]/turbopack/crates/turbopack-tests/tests/execution/webpack/scope-hoisting/reexport-star-external-cjs/input/a.js [test] (ecmascript) which is a CommonJS module with exports only available at runtime
List all export names manually (`export { a, b, c } from "...") or rewrite the module to ESM, to avoid the additional runtime code.`
\ No newline at end of file
List all export names manually (`export { a, b, c } from "...") or rewrite the module to ESM, to avoid the additional runtime code.`
Example import trace:
./turbopack/crates/turbopack-tests/tests/execution/webpack/scope-hoisting/reexport-star-external-cjs/input/a.js
./turbopack/crates/turbopack-tests/tests/execution/webpack/scope-hoisting/reexport-star-external-cjs/input/c.js
./turbopack/crates/turbopack-tests/tests/execution/webpack/scope-hoisting/reexport-star-external-cjs/input/index.js
\ No newline at end of file
......@@ -43,7 +43,7 @@ use turbopack_core::{
environment::{BrowserEnvironment, Environment, ExecutionEnvironment, NodeJsEnvironment},
file_source::FileSource,
free_var_references,
issue::{Issue, IssueDescriptionExt},
issue::IssueDescriptionExt,
module::Module,
module_graph::{
ModuleGraph,
......@@ -61,7 +61,7 @@ use turbopack_ecmascript_runtime::RuntimeType;
use turbopack_env::ProcessEnvAsset;
use turbopack_nodejs::NodeJsChunkingContext;
use turbopack_resolve::resolve_options_context::ResolveOptionsContext;
use turbopack_test_utils::snapshot::{diff, expected, matches_expected, snapshot_issues};
use turbopack_test_utils::snapshot::{UPDATE, diff, expected, matches_expected, snapshot_issues};
use crate::util::REPO_ROOT;
......@@ -159,6 +159,9 @@ async fn run(resource: PathBuf) -> Result<()> {
let tt = TurboTasks::new(TurboTasksBackend::new(
BackendOptions {
storage_mode: None,
// Enable dependency tracking when we are running under UPDATE=1 to ensure file writes
// don't crash the test.
dependency_tracking: *UPDATE,
..Default::default()
},
noop_backing_storage(),
......@@ -182,11 +185,7 @@ async fn run_inner_operation(resource: RcStr) -> Result<()> {
let out_vc = out_op.resolve_strongly_consistent().await?;
let captured_issues = out_op.peek_issues_with_path().await?;
let plain_issues = captured_issues
.iter_with_shortest_path()
.map(|(issue_vc, path)| async move { issue_vc.into_plain(path).await })
.try_join()
.await?;
let plain_issues = captured_issues.get_plain_issues().await?;
snapshot_issues(plain_issues, out_vc.join(rcstr!("issues")), &REPO_ROOT)
.await
......
warning - [analysis] [project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/esm-specified.mjs Specified module format (EcmaScript Modules) is not matching the module format of the source code (CommonJs)
The EcmaScript module format was specified in the package.json that is affecting this source file or by using an special extension, but it looks like that CommonJs syntax is used in the source code.
Exports made by CommonJs syntax will lead to a runtime error, since the module is in EcmaScript mode. Either change the "type" field in the package.json or replace CommonJs syntax with EcmaScript import/export syntax in the source file.
\ No newline at end of file
Exports made by CommonJs syntax will lead to a runtime error, since the module is in EcmaScript mode. Either change the "type" field in the package.json or replace CommonJs syntax with EcmaScript import/export syntax in the source file.
Example import trace:
./turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/esm-specified.mjs
./turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/index.js
\ No newline at end of file
warning - [analysis] [project]/turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/commonjs.js unexpected export *
export * used with module [project]/turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/commonjs.js [test] (ecmascript) which is a CommonJS module with exports only available at runtime
List all export names manually (`export { a, b, c } from "...") or rewrite the module to ESM, to avoid the additional runtime code.`
\ No newline at end of file
List all export names manually (`export { a, b, c } from "...") or rewrite the module to ESM, to avoid the additional runtime code.`
Example import trace:
./turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/commonjs.js
./turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/c.js
./turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/b.js
./turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/input/index.js
\ No newline at end of file
warning - [analysis] [project]/turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/exported.cjs unexpected export *
export * used with module [project]/turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/exported.cjs [test] (ecmascript) which is a CommonJS module with exports only available at runtime
List all export names manually (`export { a, b, c } from "...") or rewrite the module to ESM, to avoid the additional runtime code.`
\ No newline at end of file
List all export names manually (`export { a, b, c } from "...") or rewrite the module to ESM, to avoid the additional runtime code.`
Example import trace:
./turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/exported.cjs
./turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/mod.js
./turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/input/index.js
\ No newline at end of file
......@@ -16,4 +16,8 @@ error - [code gen] [project]/turbopack/crates/turbopack-tests/tests/snapshot/imp
3 + "this-is": "invalid" // lint-staged will remove trailing commas, so here's a comment
| ^
4 | }
5 | }
\ No newline at end of file
5 | }
Example import trace:
./turbopack/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json
./turbopack/crates/turbopack-tests/tests/snapshot/imports/json/input/index.js [test]
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment