Skip to content

Commit

Permalink
Merge branch 'canary' into kdy1/ts-ptr-export
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Nov 20, 2024
2 parents 1c75d8a + ac0d72d commit aaad2a1
Show file tree
Hide file tree
Showing 89 changed files with 7,522 additions and 6,853 deletions.
121 changes: 52 additions & 69 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_rcstr::RcStr;
use turbo_tasks::{
fxindexset, trace::TraceRawVcs, Completion, FxIndexMap, FxIndexSet, ResolvedVc, TryJoinIterExt,
Value, ValueToString, Vc,
fxindexmap, fxindexset, trace::TraceRawVcs, Completion, FxIndexMap, FxIndexSet, ResolvedVc,
TryJoinIterExt, Value, ValueToString, Vc,
};
use turbo_tasks_env::{CustomProcessEnv, ProcessEnv};
use turbo_tasks_fs::{File, FileContent, FileSystemPath};
Expand Down Expand Up @@ -76,7 +76,7 @@ use crate::{
loadable_manifest::create_react_loadable_manifest,
nft_json::NftJsonAsset,
paths::{
all_paths_in_root, all_server_paths, get_js_paths_from_root, get_paths_from_root,
all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root,
get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings,
},
project::Project,
Expand Down Expand Up @@ -732,12 +732,12 @@ pub fn app_entry_point_to_route(
}

#[turbo_tasks::function]
fn client_shared_chunks() -> Vc<RcStr> {
Vc::cell("client_shared_chunks".into())
fn client_shared_chunks_modifier() -> Vc<RcStr> {
Vc::cell("client-shared-chunks".into())
}

#[turbo_tasks::function]
fn server_utils_module() -> Vc<RcStr> {
fn server_utils_modifier() -> Vc<RcStr> {
Vc::cell("server-utils".into())
}

Expand Down Expand Up @@ -880,7 +880,6 @@ impl AppEndpoint {
let node_root = this.app_project.project().node_root();

let client_relative_path = this.app_project.project().client_relative_path();
let client_relative_path_ref = client_relative_path.await?;

let server_path = node_root.join("server".into());

Expand Down Expand Up @@ -917,21 +916,19 @@ impl AppEndpoint {
) = if process_client_components {
let client_shared_chunk_group = get_app_client_shared_chunk_group(
AssetIdent::from_path(this.app_project.project().project_path())
.with_modifier(client_shared_chunks()),
.with_modifier(client_shared_chunks_modifier()),
this.app_project.client_runtime_entries(),
client_chunking_context,
)
.await?;

let mut client_shared_chunks_paths = vec![];
let mut client_shared_chunks = vec![];
for chunk in client_shared_chunk_group.assets.await?.iter().copied() {
client_assets.insert(chunk);

let chunk_path = chunk.ident().path().await?;
if chunk_path.extension_ref() == Some("js") {
if let Some(chunk_path) = client_relative_path_ref.get_path_to(&chunk_path) {
client_shared_chunks_paths.push(chunk_path.into());
}
client_shared_chunks.push(chunk);
}
}
let client_shared_availability_info = client_shared_chunk_group.availability_info;
Expand Down Expand Up @@ -1023,41 +1020,31 @@ impl AppEndpoint {
client_assets.extend(entry_client_chunks.iter().copied());
server_assets.extend(entry_ssr_chunks.iter().copied());

let entry_client_chunks_paths = entry_client_chunks
.iter()
.map(|chunk| chunk.ident().path())
.try_join()
.await?;
let mut entry_client_chunks_paths = entry_client_chunks_paths
.iter()
.map(|path| {
Ok(client_relative_path_ref
.get_path_to(path)
.context("asset path should be inside client root")?
.into())
})
.collect::<anyhow::Result<Vec<_>>>()?;
entry_client_chunks_paths.extend(client_shared_chunks_paths.iter().cloned());

let manifest_path_prefix = &app_entry.original_name;

if emit_manifests {
let app_build_manifest = AppBuildManifest {
pages: [(app_entry.original_name.clone(), entry_client_chunks_paths)]
.into_iter()
.collect(),
};
let app_build_manifest_output = VirtualOutputAsset::new(
node_root.join(
format!("server/app{manifest_path_prefix}/app-build-manifest.json",).into(),
),
AssetContent::file(
File::from(serde_json::to_string_pretty(&app_build_manifest)?).into(),
pages: fxindexmap!(
app_entry.original_name.clone() => Vc::cell(entry_client_chunks
.iter()
.chain(client_shared_chunks.iter())
.copied()
.collect())
),
)
.to_resolved()
.await?;
server_assets.insert(ResolvedVc::upcast(app_build_manifest_output));
};
let app_build_manifest_output = app_build_manifest
.build_output(
node_root.join(
format!("server/app{manifest_path_prefix}/app-build-manifest.json",)
.into(),
),
client_relative_path,
)
.await?
.to_resolved()
.await?;

server_assets.insert(app_build_manifest_output);
}

// polyfill-nomodule.js is a pre-compiled asset distributed as part of next,
Expand All @@ -1068,16 +1055,12 @@ impl AppEndpoint {
);
let polyfill_output_path =
client_chunking_context.chunk_path(polyfill_source.ident(), ".js".into());
let polyfill_output_asset =
let polyfill_output_asset = ResolvedVc::upcast(
RawOutput::new(polyfill_output_path, Vc::upcast(polyfill_source))
.to_resolved()
.await?;
let polyfill_client_path = client_relative_path_ref
.get_path_to(&*polyfill_output_path.await?)
.context("failed to resolve client-relative path to polyfill")?
.into();
let polyfill_client_paths = vec![polyfill_client_path];
client_assets.insert(ResolvedVc::upcast(polyfill_output_asset));
.await?,
);
client_assets.insert(polyfill_output_asset);

if emit_manifests {
if *this
Expand All @@ -1103,21 +1086,24 @@ impl AppEndpoint {
}

let build_manifest = BuildManifest {
root_main_files: client_shared_chunks_paths,
polyfill_files: polyfill_client_paths,
root_main_files: client_shared_chunks,
polyfill_files: vec![polyfill_output_asset],
..Default::default()
};
let build_manifest_output = VirtualOutputAsset::new(
node_root.join(
format!("server/app{manifest_path_prefix}/build-manifest.json",).into(),
),
AssetContent::file(
File::from(serde_json::to_string_pretty(&build_manifest)?).into(),
),
)
.to_resolved()
.await?;
server_assets.insert(ResolvedVc::upcast(build_manifest_output));
let build_manifest_output = ResolvedVc::upcast(
build_manifest
.build_output(
node_root.join(
format!("server/app{manifest_path_prefix}/build-manifest.json",)
.into(),
),
client_relative_path,
)
.await?
.to_resolved()
.await?,
);
server_assets.insert(build_manifest_output);
}

if runtime == NextRuntime::Edge {
Expand Down Expand Up @@ -1258,8 +1244,7 @@ impl AppEndpoint {
.extend(get_wasm_paths_from_root(&node_root_value, &all_output_assets).await?);

let all_assets =
get_paths_from_root(&node_root_value, &all_output_assets, |_asset| true)
.await?;
get_asset_paths_from_root(&node_root_value, &all_output_assets).await?;

let entry_file = "app-edge-has-no-entrypoint".into();

Expand Down Expand Up @@ -1415,10 +1400,8 @@ impl AppEndpoint {
{
server_assets.insert(ResolvedVc::upcast(
NftJsonAsset::new(
this.app_project.project(),
*rsc_chunk,
this.app_project.project().output_fs(),
this.app_project.project().project_fs(),
this.app_project.project().client_fs(),
client_reference_manifest.iter().map(|m| **m).collect(),
)
.to_resolved()
Expand Down Expand Up @@ -1503,7 +1486,7 @@ impl AppEndpoint {
async {
let utils_module = IncludeModulesModule::new(
AssetIdent::from_path(this.app_project.project().project_path())
.with_modifier(server_utils_module()),
.with_modifier(server_utils_modifier()),
client_references.server_utils.clone(),
);

Expand Down
21 changes: 20 additions & 1 deletion crates/next-api/src/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use turbopack_core::{
use turbopack_ecmascript::chunk::EcmascriptChunkPlaceable;

use crate::{
nft_json::NftJsonAsset,
paths::{
all_server_paths, get_js_paths_from_root, get_wasm_paths_from_root, wasm_paths_to_bindings,
},
Expand Down Expand Up @@ -93,6 +94,15 @@ impl InstrumentationEndpoint {
.cell())
}

#[turbo_tasks::function]
async fn entry_module(self: Vc<Self>) -> Result<Vc<Box<dyn Module>>> {
if self.await?.is_edge {
Ok(*self.core_modules().await?.edge_entry_module)
} else {
Ok(*self.core_modules().await?.userland_module)
}
}

#[turbo_tasks::function]
async fn edge_files(self: Vc<Self>) -> Result<Vc<OutputAssets>> {
let this = self.await?;
Expand Down Expand Up @@ -211,7 +221,16 @@ impl InstrumentationEndpoint {

Ok(Vc::cell(output_assets))
} else {
Ok(Vc::cell(vec![self.node_chunk().to_resolved().await?]))
let chunk = self.node_chunk().to_resolved().await?;
let mut output_assets = vec![chunk];
if this.project.next_mode().await?.is_production() {
output_assets.push(ResolvedVc::upcast(
NftJsonAsset::new(this.project, *chunk, vec![])
.to_resolved()
.await?,
));
}
Ok(Vc::cell(output_assets))
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use turbopack_ecmascript::chunk::EcmascriptChunkPlaceable;

use crate::{
paths::{
all_paths_in_root, all_server_paths, get_js_paths_from_root, get_paths_from_root,
all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root,
get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings,
},
project::Project,
Expand Down Expand Up @@ -141,8 +141,7 @@ impl MiddlewareEndpoint {
let wasm_paths_from_root =
get_wasm_paths_from_root(&node_root_value, &all_output_assets).await?;

let all_assets =
get_paths_from_root(&node_root_value, &all_output_assets, |_asset| true).await?;
let all_assets = get_asset_paths_from_root(&node_root_value, &all_output_assets).await?;

// Awaited later for parallelism
let config = config.await?;
Expand Down
Loading

0 comments on commit aaad2a1

Please sign in to comment.