Skip to content

Commit

Permalink
conflicts resolved.
Browse files Browse the repository at this point in the history
  • Loading branch information
PapatMayuri committed Dec 9, 2024
2 parents 854637b + e9c4a75 commit 3270e01
Show file tree
Hide file tree
Showing 752 changed files with 36,306 additions and 34,050 deletions.
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
26 changes: 19 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 @@ -24,7 +24,9 @@ use tokio::{io::AsyncWriteExt, time::Instant};
use tracing::Instrument;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry};
use turbo_rcstr::RcStr;
use turbo_tasks::{get_effects, Completion, Effects, ReadRef, TransientInstance, UpdateInfo, Vc};
use turbo_tasks::{
get_effects, Completion, Effects, ReadRef, ResolvedVc, TransientInstance, UpdateInfo, Vc,
};
use turbo_tasks_fs::{
util::uri_from_file, DiskFileSystem, FileContent, FileSystem, FileSystemPath,
};
Expand Down Expand Up @@ -527,14 +529,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 @@ -559,7 +561,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 @@ -1023,7 +1025,7 @@ pub struct StackFrame {
pub async fn get_source_map(
container: Vc<ProjectContainer>,
file_path: String,
) -> Result<Option<Vc<SourceMap>>> {
) -> Result<Option<ResolvedVc<SourceMap>>> {
let (file, module) = match Url::parse(&file_path) {
Ok(url) => match url.scheme() {
"file" => {
Expand Down Expand Up @@ -1202,6 +1204,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
9 changes: 8 additions & 1 deletion crates/napi/src/next_api/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,14 @@ pub fn create_turbo_tasks(
Ok(if persistent_caching {
NextTurboTasks::PersistentCaching(TurboTasks::new(
turbo_tasks_backend::TurboTasksBackend::new(
turbo_tasks_backend::BackendOptions::default(),
turbo_tasks_backend::BackendOptions {
storage_mode: Some(if std::env::var("TURBO_ENGINE_READ_ONLY").is_ok() {
turbo_tasks_backend::StorageMode::ReadOnly
} else {
turbo_tasks_backend::StorageMode::ReadWrite
}),
..Default::default()
},
default_backing_storage(&output_path.join("cache/turbopack"))?,
),
))
Expand Down
18 changes: 9 additions & 9 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 Expand Up @@ -1457,10 +1457,10 @@ impl AppEndpoint {
let evaluatable = ResolvedVc::try_sidecast(app_entry.rsc_entry)
.await?
.context("Entry module must be evaluatable")?;
evaluatable_assets.push(*evaluatable);
evaluatable_assets.push(evaluatable);

if let Some(server_action_manifest_loader) = server_action_manifest_loader {
evaluatable_assets.push(server_action_manifest_loader);
evaluatable_assets.push(server_action_manifest_loader.to_resolved().await?);
}

{
Expand All @@ -1483,7 +1483,7 @@ impl AppEndpoint {
this.app_project.rsc_runtime_entries().await?.clone_value();

if let Some(server_action_manifest_loader) = server_action_manifest_loader {
evaluatable_assets.push(server_action_manifest_loader);
evaluatable_assets.push(server_action_manifest_loader.to_resolved().await?);
}

let EntryChunkGroupResult {
Expand Down Expand Up @@ -1511,7 +1511,7 @@ impl AppEndpoint {
.await?;

current_chunks = current_chunks
.concatenate(chunk_group.assets)
.concatenate(*chunk_group.assets)
.resolve()
.await?;
current_availability_info = chunk_group.availability_info;
Expand Down Expand Up @@ -1545,7 +1545,7 @@ impl AppEndpoint {
.await?;

current_chunks = current_chunks
.concatenate(chunk_group.assets)
.concatenate(*chunk_group.assets)
.resolve()
.await?;
current_availability_info = chunk_group.availability_info;
Expand Down
2 changes: 1 addition & 1 deletion crates/next-api/src/dynamic_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub(crate) async fn collect_evaluated_chunk_group(
if let Some(module) = Vc::try_resolve_downcast::<Box<dyn EvaluatableAsset>>(module).await? {
Ok(chunking_context.evaluated_chunk_group_assets(
module.ident(),
Vc::cell(vec![Vc::upcast(module)]),
Vc::cell(vec![ResolvedVc::upcast(module.to_resolved().await?)]),
Value::new(AvailabilityInfo::Root),
))
} else {
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
2 changes: 1 addition & 1 deletion crates/next-api/src/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl InstrumentationEndpoint {
let Some(evaluatable) = ResolvedVc::try_sidecast(module).await? else {
bail!("Entry module must be evaluatable");
};
evaluatable_assets.push(*evaluatable);
evaluatable_assets.push(evaluatable);

let edge_chunking_context = this.project.edge_chunking_context(false);

Expand Down
6 changes: 3 additions & 3 deletions crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use turbo_tasks::{Completion, ResolvedVc, Value, Vc};
use turbo_tasks_fs::{self, File, FileContent, FileSystemPath};
use turbopack_core::{
asset::AssetContent,
chunk::{availability_info::AvailabilityInfo, ChunkingContextExt},
chunk::{availability_info::AvailabilityInfo, ChunkingContextExt, EvaluatableAsset},
context::AssetContext,
module::{Module, Modules},
output::OutputAssets,
Expand Down Expand Up @@ -104,10 +104,10 @@ impl MiddlewareEndpoint {
bail!("Entry module must be evaluatable");
};

let evaluatable = Vc::try_resolve_sidecast(module)
let evaluatable = Vc::try_resolve_sidecast::<Box<dyn EvaluatableAsset>>(module)
.await?
.context("Entry module must be evaluatable")?;
evaluatable_assets.push(evaluatable);
evaluatable_assets.push(evaluatable.to_resolved().await?);

let edge_chunking_context = self.project.edge_chunking_context(false);

Expand Down
89 changes: 58 additions & 31 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 Expand Up @@ -831,7 +858,7 @@ impl PageEndpoint {
let is_edge = matches!(runtime, NextRuntime::Edge);
if is_edge {
let mut evaluatable_assets = edge_runtime_entries.await?.clone_value();
let evaluatable = *ResolvedVc::try_sidecast(ssr_module)
let evaluatable = ResolvedVc::try_sidecast(ssr_module)
.await?
.context("could not process page loader entry module")?;
evaluatable_assets.push(evaluatable);
Expand Down
Loading

0 comments on commit 3270e01

Please sign in to comment.