Skip to content

Commit

Permalink
Merge branch 'canary' into 12-07-test_move_hmr_main_test_to_a_separat…
Browse files Browse the repository at this point in the history
…e_file
  • Loading branch information
devjiwonchoi authored Dec 9, 2024
2 parents 6ec9980 + a0f8570 commit 8096f1d
Show file tree
Hide file tree
Showing 537 changed files with 3,239 additions and 2,611 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
13 changes: 7 additions & 6 deletions crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
87 changes: 57 additions & 30 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::future::IntoFuture;

use anyhow::{bail, Context, Result};
use futures::future::BoxFuture;
use next_core::{
all_assets_from_entries, create_page_loader_entry_module, get_asset_path_from_pathname,
get_edge_resolve_options_context,
Expand Down Expand Up @@ -105,7 +106,11 @@ impl PagesProject {
async fn add_page_to_routes(
routes: &mut FxIndexMap<RcStr, Route>,
page: Vc<PagesStructureItem>,
make_route: impl Fn(Vc<RcStr>, Vc<RcStr>, Vc<PagesStructureItem>) -> Route,
make_route: impl Fn(
Vc<RcStr>,
Vc<RcStr>,
Vc<PagesStructureItem>,
) -> BoxFuture<'static, Result<Route>>,
) -> Result<()> {
let PagesStructureItem {
next_router_path,
Expand All @@ -115,15 +120,19 @@ impl PagesProject {
let pathname: RcStr = format!("/{}", next_router_path.await?.path).into();
let pathname_vc = Vc::cell(pathname.clone());
let original_name = Vc::cell(format!("/{}", original_path.await?.path).into());
let route = make_route(pathname_vc, original_name, page);
let route = make_route(pathname_vc, original_name, page).await?;
routes.insert(pathname, route);
Ok(())
}

async fn add_dir_to_routes(
routes: &mut FxIndexMap<RcStr, Route>,
dir: Vc<PagesDirectoryStructure>,
make_route: impl Fn(Vc<RcStr>, Vc<RcStr>, Vc<PagesStructureItem>) -> Route,
make_route: impl Fn(
Vc<RcStr>,
Vc<RcStr>,
Vc<PagesStructureItem>,
) -> BoxFuture<'static, Result<Route>>,
) -> Result<()> {
let mut queue = vec![dir];
while let Some(dir) = queue.pop() {
Expand All @@ -145,37 +154,55 @@ impl PagesProject {

if let Some(api) = *api {
add_dir_to_routes(&mut routes, *api, |pathname, original_name, page| {
Route::PageApi {
endpoint: Vc::upcast(PageEndpoint::new(
PageEndpointType::Api,
self,
pathname,
original_name,
page,
pages_structure,
)),
}
Box::pin(async move {
Ok(Route::PageApi {
endpoint: ResolvedVc::upcast(
PageEndpoint::new(
PageEndpointType::Api,
self,
pathname,
original_name,
page,
pages_structure,
)
.to_resolved()
.await?,
),
})
})
})
.await?;
}

let make_page_route = |pathname, original_name, page| Route::Page {
html_endpoint: Vc::upcast(PageEndpoint::new(
PageEndpointType::Html,
self,
pathname,
original_name,
page,
pages_structure,
)),
data_endpoint: Vc::upcast(PageEndpoint::new(
PageEndpointType::Data,
self,
pathname,
original_name,
page,
pages_structure,
)),
let make_page_route = |pathname, original_name, page| -> BoxFuture<_> {
Box::pin(async move {
Ok(Route::Page {
html_endpoint: ResolvedVc::upcast(
PageEndpoint::new(
PageEndpointType::Html,
self,
pathname,
original_name,
page,
pages_structure,
)
.to_resolved()
.await?,
),
data_endpoint: ResolvedVc::upcast(
PageEndpoint::new(
PageEndpointType::Data,
self,
pathname,
original_name,
page,
pages_structure,
)
.to_resolved()
.await?,
),
})
})
};

if let Some(pages) = *pages {
Expand Down
4 changes: 2 additions & 2 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ impl Project {
async fn collect_project_feature_telemetry(self: Vc<Self>) -> Result<Vc<()>> {
let emit_event = |feature_name: &str, enabled: bool| {
NextFeatureTelemetry::new(feature_name.into(), enabled)
.cell()
.resolved_cell()
.emit();
};

Expand Down Expand Up @@ -898,7 +898,7 @@ impl Project {
.resolved_cell(),
severity: IssueSeverity::Error.resolved_cell(),
}
.cell()
.resolved_cell()
.emit();
*entry.get_mut() = Route::Conflict;
}
Expand Down
35 changes: 11 additions & 24 deletions crates/next-api/src/route.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use anyhow::Result;
use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr;
use turbo_tasks::{debug::ValueDebugFormat, trace::TraceRawVcs, Completion, FxIndexMap, Vc};
use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, Completion, FxIndexMap, ResolvedVc, Vc,
};
use turbopack_core::module::Modules;

use crate::paths::ServerPath;
Expand Down Expand Up @@ -30,43 +32,28 @@ impl AppPageRoute {
#[derive(Clone, Debug)]
pub enum Route {
Page {
html_endpoint: Vc<Box<dyn Endpoint>>,
data_endpoint: Vc<Box<dyn Endpoint>>,
html_endpoint: ResolvedVc<Box<dyn Endpoint>>,
data_endpoint: ResolvedVc<Box<dyn Endpoint>>,
},
PageApi {
endpoint: Vc<Box<dyn Endpoint>>,
endpoint: ResolvedVc<Box<dyn Endpoint>>,
},
AppPage(Vec<AppPageRoute>),
AppRoute {
original_name: String,
endpoint: Vc<Box<dyn Endpoint>>,
endpoint: ResolvedVc<Box<dyn Endpoint>>,
},
Conflict,
}

impl Route {
pub async fn resolve(&mut self) -> Result<()> {
match self {
Route::Page {
html_endpoint,
data_endpoint,
} => {
*html_endpoint = html_endpoint.resolve().await?;
*data_endpoint = data_endpoint.resolve().await?;
if let Route::AppPage(routes) = self {
for route in routes {
route.resolve().await?;
}
Route::PageApi { endpoint } => {
*endpoint = endpoint.resolve().await?;
}
Route::AppPage(routes) => {
for route in routes {
route.resolve().await?;
}
}
Route::AppRoute { endpoint, .. } => {
*endpoint = endpoint.resolve().await?;
}
Route::Conflict => {}
}

Ok(())
}
}
Expand Down
9 changes: 5 additions & 4 deletions crates/next-build-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use next_core::tracing_presets::{
TRACING_NEXT_OVERVIEW_TARGETS, TRACING_NEXT_TARGETS, TRACING_NEXT_TURBOPACK_TARGETS,
TRACING_NEXT_TURBO_TASKS_TARGETS,
};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, Registry};
use turbo_tasks::TurboTasks;
use turbo_tasks_malloc::TurboMalloc;
use turbo_tasks_memory::MemoryBackend;
use turbopack_trace_utils::{exit::ExitGuard, raw_trace::RawTraceLayer, trace_writer::TraceWriter};
use turbopack_trace_utils::{
exit::ExitGuard, filter_layer::FilterLayer, raw_trace::RawTraceLayer, trace_writer::TraceWriter,
};

#[global_allocator]
static ALLOC: TurboMalloc = TurboMalloc;
Expand Down Expand Up @@ -99,8 +101,7 @@ fn main() {

let subscriber = Registry::default();

let subscriber =
subscriber.with(EnvFilter::builder().parse(trace).unwrap());
let subscriber = subscriber.with(FilterLayer::try_new(&trace).unwrap());
let trace_file = "trace.log";
let trace_writer = std::fs::File::create(trace_file).unwrap();
let (trace_writer, guard) = TraceWriter::new(trace_writer);
Expand Down
Loading

0 comments on commit 8096f1d

Please sign in to comment.