Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a warning when using implicit metadata #47928

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 85 additions & 5 deletions packages/next-swc/crates/next-core/src/app_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use turbo_binding::{
compile_time_info::CompileTimeInfoVc,
context::{AssetContext, AssetContextVc},
environment::{EnvironmentIntention, ServerAddrVc},
issue::{Issue, IssueSeverity, IssueSeverityVc, IssueVc},
reference_type::{
EcmaScriptModulesReferenceSubType, EntryReferenceSubType, ReferenceType,
},
Expand All @@ -35,8 +36,10 @@ use turbo_binding::{
},
},
ecmascript::{
magic_identifier, utils::StringifyJs, EcmascriptInputTransformsVc,
EcmascriptModuleAssetType, EcmascriptModuleAssetVc, InnerAssetsVc,
magic_identifier,
utils::{FormatIter, StringifyJs},
EcmascriptInputTransformsVc, EcmascriptModuleAssetType, EcmascriptModuleAssetVc,
InnerAssetsVc,
},
env::ProcessEnvAssetVc,
node::{
Expand All @@ -54,11 +57,12 @@ use turbo_binding::{
},
},
};
use turbo_tasks::{TryJoinIterExt, ValueToString};

use crate::{
app_render::next_layout_entry_transition::NextServerComponentTransition,
app_structure::{
get_entrypoints, Components, Entrypoint, LoaderTree, LoaderTreeVc, OptionAppDirVc,
get_entrypoints, Components, Entrypoint, LoaderTree, LoaderTreeVc, Metadata, OptionAppDirVc,
},
embed_js::{next_js_file, next_js_file_path},
env::env_for_js,
Expand Down Expand Up @@ -473,6 +477,7 @@ async fn create_app_page_source_for_route(
pathname_vc,
AppRenderer {
runtime_entries,
app_dir,
context_ssr,
context,
server_root,
Expand Down Expand Up @@ -532,6 +537,7 @@ async fn create_app_route_source_for_route(
#[turbo_tasks::value]
struct AppRenderer {
runtime_entries: AssetsVc,
app_dir: FileSystemPathVc,
context_ssr: AssetContextVc,
context: AssetContextVc,
project_path: FileSystemPathVc,
Expand All @@ -546,6 +552,7 @@ impl AppRendererVc {
async fn entry(self, is_rsc: bool) -> Result<NodeRenderingEntryVc> {
let AppRenderer {
runtime_entries,
app_dir,
context_ssr,
context,
project_path,
Expand All @@ -566,6 +573,7 @@ impl AppRendererVc {
imports: Vec<String>,
loader_tree_code: String,
context: AssetContextVc,
unsupported_metadata: Vec<FileSystemPathVc>,
}

let mut state = State {
Expand All @@ -574,6 +582,7 @@ impl AppRendererVc {
imports: Vec::new(),
loader_tree_code: String::new(),
context,
unsupported_metadata: Vec::new(),
};

fn write_component(
Expand Down Expand Up @@ -613,6 +622,12 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
Ok(())
}

fn emit_metadata_warning(state: &mut State, files: &[FileSystemPathVc]) {
for file in files {
state.unsupported_metadata.push(*file);
}
}

#[async_recursion]
async fn walk_tree(state: &mut State, loader_tree: LoaderTreeVc) -> Result<()> {
use std::fmt::Write;
Expand Down Expand Up @@ -643,7 +658,14 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
layout,
loading,
template,
metadata: _,
metadata:
Metadata {
icon,
apple,
twitter,
open_graph,
favicon,
},
route: _,
} = &*components.await?;
write_component(state, "page", *page)?;
Expand All @@ -652,7 +674,12 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
write_component(state, "layout", *layout)?;
write_component(state, "loading", *loading)?;
write_component(state, "template", *template)?;
// TODO something for metadata
// TODO something useful for metadata
emit_metadata_warning(state, icon);
emit_metadata_warning(state, apple);
emit_metadata_warning(state, twitter);
emit_metadata_warning(state, open_graph);
emit_metadata_warning(state, favicon);
write!(state.loader_tree_code, "}}]")?;
Ok(())
}
Expand All @@ -663,9 +690,20 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
mut inner_assets,
imports,
loader_tree_code,
unsupported_metadata,
..
} = state;

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

// IPC need to be the first import to allow it to catch errors happening during
// the other imports
let mut result =
Expand Down Expand Up @@ -834,3 +872,45 @@ impl NodeEntry for AppRoute {
self_vc.entry()
}
}

#[turbo_tasks::value]
struct UnsupportedImplicitMetadataIssue {
app_dir: FileSystemPathVc,
files: Vec<FileSystemPathVc>,
}

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

#[turbo_tasks::function]
fn context(&self) -> FileSystemPathVc {
self.app_dir
}

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

#[turbo_tasks::function]
async fn description(&self) -> Result<StringVc> {
let mut files = self
.files
.iter()
.map(|file| file.to_string())
.try_join()
.await?;
files.sort();
Ok(StringVc::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]))
)))
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function RootLayout({ children }: { children: any }) {
return (
<html>
<body>{children}</body>
</html>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test from "./test";

export default function Page() {
return (
<div>
<Test />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use client";

import { useEffect } from "react";

export default function Test() {
useEffect(() => {
import("@turbo/pack-test-harness").then(() => {
it("should run", () => {});
});
return () => {};
}, []);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
appDir: true,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PlainIssue {
severity: Warning,
context: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/implicit-metadata/input/app",
category: "",
title: "Implicit metadata from filesystem is currently not supported in Turbopack",
description: "The following files were found in the app directory, but are not supported by Turbopack. They are ignored:\n\n- [project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/implicit-metadata/input/app/apple-icon.png\n- [project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/implicit-metadata/input/app/icon1234.png\n- [project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/implicit-metadata/input/app/icon234.png",
detail: "",
documentation_link: "",
source: None,
sub_issues: [],
processing_path: Some(
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/implicit-metadata/input/app",
),
description: "Next.js App Page Route /",
},
],
),
}