Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jul 18, 2023
1 parent a26bac9 commit b5ecdd0
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 57 deletions.
35 changes: 0 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ swc_core = { version = "0.79.13" }
testing = { version = "0.33.20" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230718.2" }
turbopack-binding = { path = "../turbo_upstream/crates/turbopack-binding" }
# [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-230718.2" }
turbo-tasks = { path = "../turbo_upstream/crates/turbo-tasks" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230718.2" }
turbo-tasks-fs = { path = "../turbo_upstream/crates/turbo-tasks-fs" }

# General Deps

Expand Down
27 changes: 23 additions & 4 deletions packages/next-swc/crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ use next_api::{
};
use turbo_tasks::{TurboTasks, Vc};
use turbopack_binding::{
turbo::tasks_memory::MemoryBackend, turbopack::core::error::PrettyPrintError,
turbo::{tasks::TryJoinIterExt, tasks_memory::MemoryBackend},
turbopack::core::{
diagnostics::{Diagnostic, DiagnosticContextExt},
error::PrettyPrintError,
},
};

use super::{
Expand Down Expand Up @@ -180,12 +184,27 @@ pub fn project_entrypoints_subscribe(
func,
move || async move {
let entrypoints = project.entrypoints();
let captured_diags = entrypoints.peek_diagnostics().await?;

let entrypoints = entrypoints.strongly_consistent().await?;
let captured_diags = captured_diags.strongly_consistent().await?;

let diags = captured_diags
.diagnostics
.iter()
.map(|d| d.into_plain())
.try_join()
.await?
.iter()
.map(|d| NapiDiagnostic::from(&d))
.collect::<Vec<NapiDiagnostic>>();

// TODO peek_issues and diagnostics
Ok(entrypoints)
Ok((entrypoints, diags))
},
move |ctx| {
let entrypoints = ctx.value;
let (entrypoints, diags) = ctx.value;

Ok(vec![NapiEntrypoints {
routes: entrypoints
.routes
Expand All @@ -200,7 +219,7 @@ pub fn project_entrypoints_subscribe(
.map(|m| NapiMiddleware::from_middleware(m, &turbo_tasks))
.transpose()?,
issues: vec![],
diagnostics: vec![],
diagnostics: diags,
}])
},
)
Expand Down
21 changes: 18 additions & 3 deletions packages/next-swc/crates/napi/src/next_api/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{future::Future, ops::Deref, sync::Arc};
use std::{future::Future, ops::Deref, sync::Arc, collections::HashMap};

use anyhow::{anyhow, Context, Result};
use napi::{
Expand All @@ -9,7 +9,8 @@ use napi::{
use serde::Serialize;
use turbo_tasks::{unit, TaskId, TurboTasks};
use turbopack_binding::{
turbo::tasks_memory::MemoryBackend, turbopack::core::error::PrettyPrintError,
turbo::tasks_memory::MemoryBackend,
turbopack::core::{diagnostics::PlainDiagnostic, error::PrettyPrintError},
};

/// A helper type to hold both a Vc operation and the TurboTasks root process.
Expand Down Expand Up @@ -75,7 +76,21 @@ pub fn root_task_dispose(
pub struct NapiIssue {}

#[napi(object)]
pub struct NapiDiagnostic {}
pub struct NapiDiagnostic {
pub category: String,
pub name: String,
pub payload: HashMap<String, String>,
}

impl NapiDiagnostic {
pub fn from(diagnostic: &PlainDiagnostic) -> Self {
Self {
category: diagnostic.category.clone(),
name: diagnostic.name.clone(),
payload: diagnostic.payload.clone(),
}
}
}

pub struct TurbopackResult<T: ToNapiValue> {
pub result: T,
Expand Down
1 change: 1 addition & 0 deletions packages/next-swc/crates/next-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mod next_route_matcher;
pub mod next_server;
pub mod next_server_component;
pub mod next_shared;
mod next_telemetry;
mod page_loader;
mod page_source;
pub mod pages_structure;
Expand Down

0 comments on commit b5ecdd0

Please sign in to comment.