Skip to content

Commit

Permalink
fix manifest path for index pages/apis
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Aug 25, 2023
1 parent 5f245d4 commit 6037c22
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
12 changes: 6 additions & 6 deletions packages/next-swc/crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use next_core::{
get_server_module_options_context, get_server_resolve_options_context,
get_server_runtime_entries, ServerContextType,
},
util::NextRuntime,
util::{get_asset_prefix_from_pathname, NextRuntime},
};
use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, Completion, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc};
Expand Down Expand Up @@ -706,7 +706,7 @@ impl AppEndpoint {
};
let edge_function_definition = EdgeFunctionDefinition {
files: files_paths_from_root,
name: app_entry.original_name.to_string(),
name: app_entry.pathname.to_string(),
page: app_entry.original_name.clone(),
regions: app_entry
.config
Expand All @@ -718,16 +718,16 @@ impl AppEndpoint {
..Default::default()
};
let middleware_manifest_v2 = MiddlewaresManifestV2 {
sorted_middleware: vec![app_entry.original_name.clone()],
sorted_middleware: vec![app_entry.pathname.clone()],
middleware: Default::default(),
functions: [(app_entry.original_name.clone(), edge_function_definition)]
functions: [(app_entry.pathname.clone(), edge_function_definition)]
.into_iter()
.collect(),
};
let manifest_path_prefix = get_asset_prefix_from_pathname(&app_entry.pathname);
let middleware_manifest_v2 = Vc::upcast(VirtualOutputAsset::new(
node_root.join(format!(
"server/app{original_name}/middleware-manifest.json",
original_name = app_entry.original_name
"server/app{manifest_path_prefix}/middleware-manifest.json",
)),
AssetContent::file(
FileContent::Content(File::from(serde_json::to_string_pretty(
Expand Down
9 changes: 5 additions & 4 deletions packages/next-swc/crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,22 +849,23 @@ impl PageEndpoint {
let original_name = this.original_name.await?;
let edge_function_definition = EdgeFunctionDefinition {
files: files_paths_from_root,
name: original_name.to_string(),
name: pathname.to_string(),
page: original_name.to_string(),
regions: None,
matchers: vec![matchers],
..Default::default()
};
let middleware_manifest_v2 = MiddlewaresManifestV2 {
sorted_middleware: vec![original_name.to_string()],
sorted_middleware: vec![pathname.to_string()],
middleware: Default::default(),
functions: [(original_name.to_string(), edge_function_definition)]
functions: [(pathname.to_string(), edge_function_definition)]
.into_iter()
.collect(),
};
let manifest_path_prefix = get_asset_prefix_from_pathname(&this.pathname.await?);
let middleware_manifest_v2 = Vc::upcast(VirtualOutputAsset::new(
node_root.join(format!(
"server/pages{original_name}/middleware-manifest.json"
"server/pages{manifest_path_prefix}/middleware-manifest.json"
)),
AssetContent::file(
FileContent::Content(File::from(serde_json::to_string_pretty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub async fn wrap_edge_entry(
context: Vc<ModuleAssetContext>,
project_root: Vc<FileSystemPath>,
entry: Vc<Box<dyn Module>>,
original_name: String,
pathname: String,
) -> Result<Vc<Box<dyn Module>>> {
let mut source = RopeBuilder::default();
writedoc!(
Expand All @@ -158,7 +158,7 @@ pub async fn wrap_edge_entry(
default: EdgeRouteModuleWrapper.wrap(module.routeModule),
}}
"#,
StringifyJs(&format_args!("middleware_{}", original_name))
StringifyJs(&format_args!("middleware_{}", pathname))
)?;
let file = File::from(source.build());
// TODO(alexkirsz) Figure out how to name this virtual asset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub async fn create_page_ssr_entry_module(
ssr_module_context,
project_root,
ssr_module,
definition_page.to_string(),
definition_pathname.to_string(),
);
}

Expand All @@ -143,7 +143,7 @@ pub async fn wrap_edge_entry(
context: Vc<Box<dyn AssetContext>>,
project_root: Vc<FileSystemPath>,
entry: Vc<Box<dyn Module>>,
original_name: String,
pathname: String,
) -> Result<Vc<Box<dyn Module>>> {
let mut source = RopeBuilder::default();
writedoc!(
Expand All @@ -154,7 +154,7 @@ pub async fn wrap_edge_entry(
self._ENTRIES ||= {{}}
self._ENTRIES[{}] = module
"#,
StringifyJs(&format_args!("middleware_{}", original_name))
StringifyJs(&format_args!("middleware_{}", pathname))
)?;
let file = File::from(source.build());
// TODO(alexkirsz) Figure out how to name this virtual asset.
Expand Down

0 comments on commit 6037c22

Please sign in to comment.