Skip to content

Commit

Permalink
clean up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Sep 5, 2023
1 parent 98d7ca7 commit be50a09
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 150 deletions.
2 changes: 0 additions & 2 deletions packages/next-swc/crates/napi/src/app_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ async fn prepare_components_for_js(
metadata.open_graph.iter(),
)
.await?;
// TODO
// add_meta(&mut meta.favicon, project_path, metadata.favicon.iter()).await?;
add_meta(&mut meta.sitemap, project_path, metadata.sitemap).await?;
Ok(result)
}
Expand Down
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ impl AppEndpoint {
self.app_project.rsc_module_context(),
self.app_project.edge_rsc_module_context(),
loader_tree,
self.app_project.app_dir(),
self.page.clone(),
self.app_project.project().project_path(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ pub async fn get_app_entries(
// TODO add edge support
rsc_context,
*loader_tree,
app_dir,
page.clone(),
project_root,
),
Expand Down
19 changes: 1 addition & 18 deletions packages/next-swc/crates/next-core/src/app_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use turbopack_binding::{
context::AssetContext,
environment::ServerAddr,
file_source::FileSource,
issue::IssueExt,
reference_type::{
EcmaScriptModulesReferenceSubType, EntryReferenceSubType, ReferenceType,
},
Expand Down Expand Up @@ -61,10 +60,7 @@ use crate::{
fallback::get_fallback_page,
loader_tree::{LoaderTreeModule, ServerComponentTransition},
mode::NextMode,
next_app::{
metadata::{route::get_app_metadata_route_source, UnsupportedDynamicMetadataIssue},
AppPage, AppPath, PathSegment,
},
next_app::{metadata::route::get_app_metadata_route_source, AppPage, AppPath, PathSegment},
next_client::{
context::{
get_client_assets_path, get_client_module_options_context,
Expand Down Expand Up @@ -755,7 +751,6 @@ async fn create_app_page_source_for_route(
Vc::upcast(
AppRenderer {
runtime_entries,
app_dir,
context_ssr,
context,
server_root,
Expand Down Expand Up @@ -800,7 +795,6 @@ async fn create_app_not_found_page_source(
Vc::upcast(
AppRenderer {
runtime_entries,
app_dir,
context_ssr,
context,
server_root,
Expand Down Expand Up @@ -918,7 +912,6 @@ async fn create_app_route_source_for_metadata(
#[turbo_tasks::value]
struct AppRenderer {
runtime_entries: Vc<Sources>,
app_dir: Vc<FileSystemPath>,
context_ssr: Vc<ModuleAssetContext>,
context: Vc<ModuleAssetContext>,
project_path: Vc<FileSystemPath>,
Expand All @@ -933,7 +926,6 @@ impl AppRenderer {
async fn entry(self: Vc<Self>, with_ssr: bool) -> Result<Vc<NodeRenderingEntry>> {
let AppRenderer {
runtime_entries,
app_dir,
context_ssr,
context,
project_path,
Expand Down Expand Up @@ -964,15 +956,6 @@ impl AppRenderer {
)
.await?;

if !loader_tree_module.unsupported_metadata.is_empty() {
UnsupportedDynamicMetadataIssue {
app_dir,
files: loader_tree_module.unsupported_metadata,
}
.cell()
.emit();
}

let mut result = RopeBuilder::from(indoc! {"
\"TURBOPACK { chunking-type: isolatedParallel; transition: next-edge-server-component }\";
import GlobalErrorMod from \"next/dist/client/components/error-boundary\"
Expand Down
4 changes: 0 additions & 4 deletions packages/next-swc/crates/next-core/src/loader_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub struct LoaderTreeBuilder {
imports: Vec<String>,
loader_tree_code: String,
context: Vc<ModuleAssetContext>,
unsupported_metadata: Vec<Vc<FileSystemPath>>,
mode: NextMode,
server_component_transition: ServerComponentTransition,
pages: Vec<Vc<FileSystemPath>>,
Expand Down Expand Up @@ -82,7 +81,6 @@ impl LoaderTreeBuilder {
imports: Vec::new(),
loader_tree_code: String::new(),
context,
unsupported_metadata: Vec::new(),
server_component_transition,
mode,
pages: Vec::new(),
Expand Down Expand Up @@ -413,7 +411,6 @@ impl LoaderTreeBuilder {
imports: self.imports,
loader_tree_code: self.loader_tree_code,
inner_assets: self.inner_assets,
unsupported_metadata: self.unsupported_metadata,
pages: self.pages,
})
}
Expand All @@ -423,7 +420,6 @@ pub struct LoaderTreeModule {
pub imports: Vec<String>,
pub loader_tree_code: String,
pub inner_assets: IndexMap<String, Vc<Box<dyn Module>>>,
pub unsupported_metadata: Vec<Vc<FileSystemPath>>,
pub pages: Vec<Vc<FileSystemPath>>,
}

Expand Down
17 changes: 3 additions & 14 deletions packages/next-swc/crates/next-core/src/next_app/app_page_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use turbopack_binding::{
turbo::tasks_fs::{rope::RopeBuilder, File, FileSystemPath},
turbopack::{
core::{
asset::AssetContent, context::AssetContext, issue::IssueExt,
reference_type::ReferenceType, virtual_source::VirtualSource,
asset::AssetContent, context::AssetContext, reference_type::ReferenceType,
virtual_source::VirtualSource,
},
ecmascript::{chunk::EcmascriptChunkPlaceable, utils::StringifyJs},
turbopack::ModuleAssetContext,
Expand All @@ -19,7 +19,7 @@ use crate::{
app_structure::LoaderTree,
loader_tree::{LoaderTreeModule, ServerComponentTransition},
mode::NextMode,
next_app::{AppPage, AppPath, UnsupportedDynamicMetadataIssue},
next_app::{AppPage, AppPath},
next_server_component::NextServerComponentTransition,
parse_segment_config_from_loader_tree,
util::{load_next_js_template, virtual_next_js_template_path, NextRuntime},
Expand All @@ -31,7 +31,6 @@ pub async fn get_app_page_entry(
nodejs_context: Vc<ModuleAssetContext>,
edge_context: Vc<ModuleAssetContext>,
loader_tree: Vc<LoaderTree>,
app_dir: Vc<FileSystemPath>,
page: AppPage,
project_root: Vc<FileSystemPath>,
) -> Result<Vc<AppEntry>> {
Expand All @@ -57,19 +56,9 @@ pub async fn get_app_page_entry(
inner_assets,
imports,
loader_tree_code,
unsupported_metadata,
pages,
} = loader_tree;

if !unsupported_metadata.is_empty() {
UnsupportedDynamicMetadataIssue {
app_dir,
files: unsupported_metadata,
}
.cell()
.emit();
}

let mut result = RopeBuilder::default();

for import in imports {
Expand Down
110 changes: 1 addition & 109 deletions packages/next-swc/crates/next-core/src/next_app/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ use std::{collections::HashMap, ops::Deref};

use anyhow::Result;
use once_cell::sync::Lazy;
use turbo_tasks::{TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbopack_binding::turbopack::{
core::issue::{Issue, IssueSeverity},
ecmascript::utils::FormatIter,
};

use crate::next_app::{AppPage, PageSegment};

pub mod route;
pub mod image;
pub mod route;

pub static STATIC_LOCAL_METADATA: Lazy<HashMap<&'static str, &'static [&'static str]>> =
Lazy::new(|| {
Expand Down Expand Up @@ -258,12 +252,6 @@ fn get_metadata_route_suffix(page: &str) -> Option<String> {
}
}

// page: `/(dashboard)/user/[id]/page`
// pathname: `/user/[id]`
//
// page: `/account/route`
// pathname: `/account`

/// Map metadata page key to the corresponding route
///
/// static file page key: /app/robots.txt -> /robots.txt -> /robots.txt/route
Expand Down Expand Up @@ -361,99 +349,3 @@ mod test {
);
}
}

// pub fn normalize_metadata_route(page: &str) -> String {
// if !is_metadata_route(page) {
// return page.to_string();
// }
//
// let mut route = page.to_string();
// let mut suffix: Option<String> = None;
// if route == "/robots" {
// route += ".txt"
// } else if route == "/manifest" {
// route += ".webmanifest"
// } else if route.ends_with("/sitemap") {
// route += ".xml"
// } else {
// // Remove the file extension, e.g. /route-path/robots.txt ->
// /route-path let pathname_prefix =
// split_directory(page).0.unwrap_or_default(); suffix =
// get_metadata_route_suffix(pathname_prefix); }
//
// // Support both /<metadata-route.ext> and custom routes
// // /<metadata-route>/route.ts. If it's a metadata file route, we need to
// // append /[id]/route to the page.
// if !route.ends_with("/route") {
// let is_static_metadata_file = is_static_metadata_route_file(page);
// let (dir, filename) = split_directory(&route);
// let (base_name, ext) = split_extensions(filename);
//
// let is_static_route =
// page.starts_with("/robots") || page.starts_with("/manifest") ||
// is_static_metadata_file;
//
// // the next version has a `/route` suffix added here, do we need it?
// route = format!(
// "{}/{}{}{}{}",
// dir.unwrap_or_default(),
// base_name,
// suffix
// .map(|suffix| format!("-{suffix}"))
// .unwrap_or_default(),
// ext.map(|ext| format!(".{ext}")).unwrap_or_default(),
// (!is_static_route)
// .then_some("/[[...__metadata_id__]]")
// .unwrap_or_default(),
// );
// }
//
// route
// }

#[turbo_tasks::value(shared)]
pub struct UnsupportedDynamicMetadataIssue {
pub app_dir: Vc<FileSystemPath>,
pub files: Vec<Vc<FileSystemPath>>,
}

#[turbo_tasks::value_impl]
impl Issue for UnsupportedDynamicMetadataIssue {
#[turbo_tasks::function]
fn severity(&self) -> Vc<IssueSeverity> {
IssueSeverity::Warning.into()
}

#[turbo_tasks::function]
fn category(&self) -> Vc<String> {
Vc::cell("unsupported".to_string())
}

#[turbo_tasks::function]
fn file_path(&self) -> Vc<FileSystemPath> {
self.app_dir
}

#[turbo_tasks::function]
fn title(&self) -> Vc<String> {
Vc::cell(
"Dynamic metadata from filesystem is currently not supported in Turbopack".to_string(),
)
}

#[turbo_tasks::function]
async fn description(&self) -> Result<Vc<String>> {
let mut files = self
.files
.iter()
.map(|file| file.to_string())
.try_join()
.await?;
files.sort();
Ok(Vc::cell(format!(
"The following files were found in the app directory, but are not supported by \
Turbopack. They are ignored:\n{}",
FormatIter(|| files.iter().flat_map(|file| vec!["\n- ", file]))
)))
}
}
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-core/src/next_app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub use app_client_shared_chunks::get_app_client_shared_chunks;
pub use app_entry::AppEntry;
pub use app_page_entry::get_app_page_entry;
pub use app_route_entry::get_app_route_entry;
pub use metadata::UnsupportedDynamicMetadataIssue;
use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, TaskInput};

Expand Down

0 comments on commit be50a09

Please sign in to comment.