Skip to content

Commit

Permalink
report error when using "use server" on module level (#47967)
Browse files Browse the repository at this point in the history
### What?

Add a error message when using "use server".

* vercel/turborepo#4477 <!-- Tobias Koppers - add
ServerDirective transform which reports unsupported -->


### Why?

Turbopack doesn't support "use server" yet.

### Other turbopack updates

* vercel/turborepo#4464 <!-- Justin Ridgewell -
Better dotenv error messages -->
* vercel/turborepo#4485 <!-- Justin Ridgewell - Add
ServerAddr::hostname method -->
  • Loading branch information
sokra authored Apr 6, 2023
1 parent e35710f commit 042e19d
Show file tree
Hide file tree
Showing 28 changed files with 145 additions and 37 deletions.
60 changes: 30 additions & 30 deletions packages/next-swc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/next-swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ swc_emotion = { version = "0.29.10" }
testing = { version = "0.31.31" }

# Turbo crates
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230405.4" }
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230406.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230405.4" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230406.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230405.4" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230406.2" }

# General Deps

Expand Down
4 changes: 4 additions & 0 deletions packages/next-swc/crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use turbo_binding::{
free_var_references,
},
dev::DevChunkingContextVc,
ecmascript::EcmascriptInputTransform,
env::ProcessEnvAssetVc,
node::execution_context::ExecutionContextVc,
turbopack::{
Expand Down Expand Up @@ -175,6 +176,9 @@ pub async fn get_client_module_options_context(
};

let module_options_context = ModuleOptionsContext {
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ServerDirective(
StringVc::cell("TODO".to_string()),
)],
preset_env_versions: Some(env),
execution_context: Some(execution_context),
..Default::default()
Expand Down
12 changes: 9 additions & 3 deletions packages/next-swc/crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ pub async fn get_server_module_options_context(
}
ServerContextType::AppSSR { .. } => {
let module_options_context = ModuleOptionsContext {
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ServerDirective(
StringVc::cell("TODO".to_string()),
)],
execution_context: Some(execution_context),
..Default::default()
};
Expand All @@ -279,9 +282,12 @@ pub async fn get_server_module_options_context(
}
ServerContextType::AppRSC { .. } => {
let module_options_context = ModuleOptionsContext {
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ClientDirective(
StringVc::cell("server-to-client".to_string()),
)],
custom_ecmascript_transforms: vec![
EcmascriptInputTransform::ClientDirective(StringVc::cell(
"server-to-client".to_string(),
)),
EcmascriptInputTransform::ServerDirective(StringVc::cell("TODO".to_string())),
],
execution_context: Some(execution_context),
..Default::default()
};
Expand Down
3 changes: 2 additions & 1 deletion packages/next-swc/crates/next-dev-tests/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ fn run_async_test<'a, T>(future: impl Future<Output = T> + Send + 'a) -> T {
}
}

#[testing::fixture("tests/integration/*/*/*")]
#[testing::fixture("tests/integration/*/*/*/input")]
fn test(resource: PathBuf) {
let resource = resource.parent().unwrap().to_path_buf();
if resource.ends_with("__skipped__") || resource.ends_with("__flakey__") {
// "Skip" directories named `__skipped__`, which include test directories to
// skip. These tests are not considered truly skipped by `cargo test`, but they
Expand Down
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 /",
},
],
),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'

export default async function Action() {
return 42
}
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,15 @@
import Test from './test'

export default async function Page() {
let action
try {
await import('./action')
} catch (e) {
action = e.toString()
}
return (
<div>
<Test action={action} />
</div>
)
}
Loading

0 comments on commit 042e19d

Please sign in to comment.