Skip to content

Commit

Permalink
Merge branch 'vercel:canary' into with-google-analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
suu3 authored Dec 9, 2024
2 parents cbe9628 + 657c2cb commit 3280ba1
Show file tree
Hide file tree
Showing 588 changed files with 5,835 additions and 4,647 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ test/development/basic/hmr/components/parse-error.js
packages/next-swc/docs/assets/**/*
test/lib/amp-validator-wasm.js
test/production/pages-dir/production/fixture/amp-validator-wasm.js
test/e2e/app-dir/server-source-maps/fixtures/default/internal-pkg/sourcemapped.js
test/e2e/app-dir/server-source-maps/fixtures/default/external-pkg/sourcemapped.js
test/e2e/async-modules/amp-validator-wasm.js
test/development/next-lint-eslint-formatter-compact/**/*.js

Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ bench/nested-deps/components/**/*
**/.tina/__generated__/**
test/lib/amp-validator-wasm.js
test/production/pages-dir/production/fixture/amp-validator-wasm.js
test/e2e/app-dir/server-source-maps/fixtures/default/internal-pkg/sourcemapped.js
test/e2e/app-dir/server-source-maps/fixtures/default/external-pkg/sourcemapped.js
test/e2e/async-modules/amp-validator-wasm.js

# turbopack crates
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contributing/examples/adding-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
When you add an example to the [examples](https://github.com/vercel/next.js/tree/canary/examples) directory, please follow these guidelines to ensure high-quality examples:

- TypeScript should be leveraged for new examples (no need for separate JavaScript and TypeScript examples, converting old JavaScript examples is preferred)
- Examples should not add custom ESLint configuration (we have specific templates for ESLint)
- Examples should not add custom ESLint configuration (we have [specific templates for ESLint](https://github.com/vercel/next.js/tree/canary/examples/with-eslint))
- If API routes aren't used in an example, they should be omitted
- If an example exists for a certain library and you would like to showcase a specific feature of that library, the existing example should be updated (instead of adding a new example)
- Package manager specific config should not be added (e.g. `resolutions` in `package.json`)
Expand Down
25 changes: 18 additions & 7 deletions crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{path::PathBuf, sync::Arc, thread, time::Duration};

use anyhow::{anyhow, bail, Context, Result};
use napi::{
bindgen_prelude::External,
bindgen_prelude::{within_runtime_if_available, External},
threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode},
JsFunction, Status,
};
Expand All @@ -22,7 +22,7 @@ use once_cell::sync::Lazy;
use rand::Rng;
use tokio::{io::AsyncWriteExt, time::Instant};
use tracing::Instrument;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, Registry};
use turbo_rcstr::RcStr;
use turbo_tasks::{
get_effects, Completion, Effects, ReadRef, ResolvedVc, TransientInstance, UpdateInfo, Vc,
Expand All @@ -41,6 +41,7 @@ use turbopack_core::{
use turbopack_ecmascript_hmr_protocol::{ClientUpdateInstruction, ResourceIdentifier};
use turbopack_trace_utils::{
exit::{ExitHandler, ExitReceiver},
filter_layer::FilterLayer,
raw_trace::RawTraceLayer,
trace_writer::TraceWriter,
};
Expand Down Expand Up @@ -317,7 +318,7 @@ pub async fn project_new(

let subscriber = Registry::default();

let subscriber = subscriber.with(EnvFilter::builder().parse(trace).unwrap());
let subscriber = subscriber.with(FilterLayer::try_new(&trace).unwrap());
let dist_dir = options.dist_dir.clone();

let internal_dir = PathBuf::from(&options.project_path).join(dist_dir);
Expand Down Expand Up @@ -529,14 +530,14 @@ impl NapiRoute {
} => NapiRoute {
pathname,
r#type: "page",
html_endpoint: convert_endpoint(html_endpoint),
data_endpoint: convert_endpoint(data_endpoint),
html_endpoint: convert_endpoint(*html_endpoint),
data_endpoint: convert_endpoint(*data_endpoint),
..Default::default()
},
Route::PageApi { endpoint } => NapiRoute {
pathname,
r#type: "page-api",
endpoint: convert_endpoint(endpoint),
endpoint: convert_endpoint(*endpoint),
..Default::default()
},
Route::AppPage(pages) => NapiRoute {
Expand All @@ -561,7 +562,7 @@ impl NapiRoute {
pathname,
original_name: Some(original_name),
r#type: "app-route",
endpoint: convert_endpoint(endpoint),
endpoint: convert_endpoint(*endpoint),
..Default::default()
},
Route::Conflict => NapiRoute {
Expand Down Expand Up @@ -1204,6 +1205,16 @@ pub async fn project_get_source_map(
Ok(source_map)
}

#[napi]
pub fn project_get_source_map_sync(
#[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
file_path: String,
) -> napi::Result<Option<String>> {
within_runtime_if_available(|| {
tokio::runtime::Handle::current().block_on(project_get_source_map(project, file_path))
})
}

/// Runs exit handlers for the project registered using the [`ExitHandler`] API.
#[napi]
pub async fn project_on_exit(
Expand Down
8 changes: 4 additions & 4 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,24 +711,24 @@ pub fn app_entry_point_to_route(
root_layouts,
} => Route::AppRoute {
original_name: page.to_string(),
endpoint: Vc::upcast(
endpoint: ResolvedVc::upcast(
AppEndpoint {
ty: AppEndpointType::Route { path, root_layouts },
app_project,
page,
}
.cell(),
.resolved_cell(),
),
},
AppEntrypoint::AppMetadata { page, metadata } => Route::AppRoute {
original_name: page.to_string(),
endpoint: Vc::upcast(
endpoint: ResolvedVc::upcast(
AppEndpoint {
ty: AppEndpointType::Metadata { metadata },
app_project,
page,
}
.cell(),
.resolved_cell(),
),
},
}
Expand Down
8 changes: 4 additions & 4 deletions crates/next-api/src/global_module_id_strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ impl GlobalModuleIdStrategyBuilder {
html_endpoint,
data_endpoint,
} => {
preprocessed_module_ids.push(preprocess_module_ids(*html_endpoint));
preprocessed_module_ids.push(preprocess_module_ids(*data_endpoint));
preprocessed_module_ids.push(preprocess_module_ids(**html_endpoint));
preprocessed_module_ids.push(preprocess_module_ids(**data_endpoint));
}
Route::PageApi { endpoint } => {
preprocessed_module_ids.push(preprocess_module_ids(*endpoint));
preprocessed_module_ids.push(preprocess_module_ids(**endpoint));
}
Route::AppPage(page_routes) => {
for page_route in page_routes {
Expand All @@ -65,7 +65,7 @@ impl GlobalModuleIdStrategyBuilder {
original_name: _,
endpoint,
} => {
preprocessed_module_ids.push(preprocess_module_ids(*endpoint));
preprocessed_module_ids.push(preprocess_module_ids(**endpoint));
}
Route::Conflict => {
tracing::info!("WARN: conflict");
Expand Down
138 changes: 138 additions & 0 deletions crates/next-api/src/operation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
use anyhow::Result;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use turbo_tasks::{debug::ValueDebugFormat, trace::TraceRawVcs, OperationVc, RcStr, Vc};

use crate::{
entrypoints::Entrypoints,
route::{Endpoint, Route},
};

/// A derived type of Entrypoints, but with OperationVc<Endpoint> for every endpoint.
///
/// This is needed to call `write_to_disk` which expects an `OperationVc<Endpoint>`.
/// This is important as OperationVcs can be stored in the VersionedContentMap and can be exposed to
/// JS via napi.
#[turbo_tasks::value(shared)]
pub struct EntrypointsOperation {
pub routes: IndexMap<RcStr, RouteOperation>,
pub middleware: Option<MiddlewareOperation>,
pub instrumentation: Option<InstrumentationOperation>,
pub pages_document_endpoint: OperationVc<Box<dyn Endpoint>>,
pub pages_app_endpoint: OperationVc<Box<dyn Endpoint>>,
pub pages_error_endpoint: OperationVc<Box<dyn Endpoint>>,
}

#[turbo_tasks::value_impl]
impl EntrypointsOperation {
#[turbo_tasks::function]
pub async fn new(entrypoints: OperationVc<Entrypoints>) -> Result<Vc<Self>> {
let e = entrypoints.connect().await?;
Ok(Self {
routes: e
.routes
.iter()
.map(|(k, v)| (k.clone(), wrap_route(v, entrypoints)))
.collect(),
middleware: e.middleware.as_ref().map(|m| MiddlewareOperation {
endpoint: wrap(m.endpoint, entrypoints),
}),
instrumentation: e
.instrumentation
.as_ref()
.map(|i| InstrumentationOperation {
node_js: wrap(i.node_js, entrypoints),
edge: wrap(i.edge, entrypoints),
}),
pages_document_endpoint: wrap(e.pages_document_endpoint, entrypoints),
pages_app_endpoint: wrap(e.pages_app_endpoint, entrypoints),
pages_error_endpoint: wrap(e.pages_error_endpoint, entrypoints),
}
.cell())
}
}

fn wrap_route(route: &Route, entrypoints: OperationVc<Entrypoints>) -> RouteOperation {
match route {
Route::Page {
html_endpoint,
data_endpoint,
} => RouteOperation::Page {
html_endpoint: wrap(*html_endpoint, entrypoints),
data_endpoint: wrap(*data_endpoint, entrypoints),
},
Route::PageApi { endpoint } => RouteOperation::PageApi {
endpoint: wrap(*endpoint, entrypoints),
},
Route::AppPage(pages) => RouteOperation::AppPage(
pages
.iter()
.map(|p| AppPageRouteOperation {
original_name: p.original_name.clone(),
html_endpoint: wrap(p.html_endpoint, entrypoints),
rsc_endpoint: wrap(p.rsc_endpoint, entrypoints),
})
.collect(),
),
Route::AppRoute {
original_name,
endpoint,
} => RouteOperation::AppRoute {
original_name: original_name.clone(),
endpoint: wrap(*endpoint, entrypoints),
},
Route::Conflict => RouteOperation::Conflict,
}
}

#[turbo_tasks::function]
fn wrap_endpoint(
endpoint: Vc<Box<dyn Endpoint>>,
op: OperationVc<Entrypoints>,
) -> Vc<Box<dyn Endpoint>> {
let _ = op.connect();
endpoint
}

fn wrap(
endpoint: Vc<Box<dyn Endpoint>>,
op: OperationVc<Entrypoints>,
) -> OperationVc<Box<dyn Endpoint>> {
OperationVc::new(wrap_endpoint(endpoint, op))
}

#[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat)]
pub struct InstrumentationOperation {
pub node_js: OperationVc<Box<dyn Endpoint>>,
pub edge: OperationVc<Box<dyn Endpoint>>,
}

#[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat)]
pub struct MiddlewareOperation {
pub endpoint: OperationVc<Box<dyn Endpoint>>,
}

#[turbo_tasks::value(shared)]
#[derive(Clone, Debug)]
pub enum RouteOperation {
Page {
html_endpoint: OperationVc<Box<dyn Endpoint>>,
data_endpoint: OperationVc<Box<dyn Endpoint>>,
},
PageApi {
endpoint: OperationVc<Box<dyn Endpoint>>,
},
AppPage(Vec<AppPageRouteOperation>),
AppRoute {
original_name: String,
endpoint: OperationVc<Box<dyn Endpoint>>,
},
Conflict,
}

#[derive(TraceRawVcs, Serialize, Deserialize, PartialEq, Eq, ValueDebugFormat, Clone, Debug)]
pub struct AppPageRouteOperation {
pub original_name: String,
pub html_endpoint: OperationVc<Box<dyn Endpoint>>,
pub rsc_endpoint: OperationVc<Box<dyn Endpoint>>,
}
Loading

0 comments on commit 3280ba1

Please sign in to comment.