From c6d357a5e3c6aa6bcf1c5f52eedd2e663a5caaca Mon Sep 17 00:00:00 2001 From: OJ Kwon <1210596+kwonoj@users.noreply.github.com> Date: Wed, 12 Jul 2023 09:51:44 -0700 Subject: [PATCH] feat(turbopack_core): define trait for diagnostics --- crates/turbopack-core/src/diagnostics/mod.rs | 34 ++++++++++++++++++++ crates/turbopack-core/src/lib.rs | 1 + 2 files changed, 35 insertions(+) create mode 100644 crates/turbopack-core/src/diagnostics/mod.rs diff --git a/crates/turbopack-core/src/diagnostics/mod.rs b/crates/turbopack-core/src/diagnostics/mod.rs new file mode 100644 index 00000000000000..604e9eca33e2a0 --- /dev/null +++ b/crates/turbopack-core/src/diagnostics/mod.rs @@ -0,0 +1,34 @@ +use anyhow::Result; +use turbo_tasks::{emit, primitives::StringVc}; + +/// An arbitrary metadata payload can be used to analyze, diagnose +/// Turbopack's behavior. +#[turbo_tasks::value_trait] +pub trait Diagnostics { + // [TODO]: These are subject to change; not finalized yet. + fn category(&self) -> StringVc; + fn key(&self) -> StringVc; + fn value(&self) -> StringVc; +} + +impl DiagnosticsVc { + pub fn emit(self) { + emit(self); + } + + pub async fn peek_diagnostics_with_path( + source: T, + ) -> Result { + Ok(CapturedDiagnosticsVc::cell(CapturedDiagnostics { + diagnostics: source.peek_collectibles().strongly_consistent().await?, + })) + } +} + +/// A list of diagnostics captured with +/// [`DiagnosticsVc::peek_diagnostics_with_path`] and +#[derive(Debug)] +#[turbo_tasks::value] +pub struct CapturedDiagnostics { + pub diagnostics: auto_hash_map::AutoSet, +} diff --git a/crates/turbopack-core/src/lib.rs b/crates/turbopack-core/src/lib.rs index 3c27f998859b89..168a0262ddc905 100644 --- a/crates/turbopack-core/src/lib.rs +++ b/crates/turbopack-core/src/lib.rs @@ -11,6 +11,7 @@ pub mod chunk; pub mod code_builder; pub mod compile_time_info; pub mod context; +pub mod diagnostics; pub mod environment; pub mod error; pub mod file_source;