mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
The `wasm` and `next-custom-transforms` crates were still on Rust edition 2018 while the rest of the crates in this repo use edition 2024. This caused a pre-commit hook conflict:
- `cargo fmt` passes the crate's own edition (2018) to `rustfmt`, which uses **case-insensitive** import sorting
- The lint-staged pre-commit hook runs `rustfmt --edition 2024 --`, which uses **ASCII order** import sorting (uppercase before lowercase)
These two sort orders disagree on items like `{custom_before_pass, TransformOptions}` vs `{TransformOptions, custom_before_pass}`, causing an infinite flip-flop: every commit would reorder imports, and the next `cargo fmt` would reorder them back.
## Changes
- Bump `crates/wasm` and `crates/next-custom-transforms` from edition 2018 to 2024
- Add `+ use<C>` precise capturing to `server_actions()` return type to satisfy edition 2024's stricter `impl Trait` lifetime capture rules
- Add `style_edition = "2024"` to `.rustfmt.toml` as a safety net so `cargo fmt` uses 2024-style formatting regardless of individual crate editions
- Reformat all affected files with `cargo fmt`
- Apply new clippy rules
277 lines
9.0 KiB
Rust
277 lines
9.0 KiB
Rust
use std::{iter::FromIterator, path::PathBuf};
|
|
|
|
use next_custom_transforms::transforms::{
|
|
disallow_re_export_all_in_page::disallow_re_export_all_in_page,
|
|
dynamic::{NextDynamicMode, next_dynamic},
|
|
fonts::{Config as FontLoaderConfig, next_font_loaders},
|
|
next_ssg::next_ssg,
|
|
react_server_components::server_components,
|
|
server_actions::{self, ServerActionsMode, server_actions},
|
|
strip_page_exports::{ExportFilter, next_transform_strip_page_exports},
|
|
};
|
|
use rustc_hash::FxHashSet;
|
|
use swc_core::{
|
|
atoms::atom,
|
|
common::{FileName, Mark},
|
|
ecma::{
|
|
parser::{EsSyntax, Syntax},
|
|
transforms::{
|
|
base::resolver,
|
|
testing::{FixtureTestConfig, test_fixture},
|
|
},
|
|
},
|
|
};
|
|
use testing::fixture;
|
|
use turbo_rcstr::rcstr;
|
|
|
|
fn syntax() -> Syntax {
|
|
Syntax::Es(EsSyntax {
|
|
jsx: true,
|
|
..Default::default()
|
|
})
|
|
}
|
|
|
|
#[fixture("tests/errors/re-export-all-in-page/**/input.js")]
|
|
fn re_export_all_in_page(input: PathBuf) {
|
|
let output = input.parent().unwrap().join("output.js");
|
|
test_fixture(
|
|
syntax(),
|
|
&|_tr| disallow_re_export_all_in_page(true),
|
|
&input,
|
|
&output,
|
|
FixtureTestConfig {
|
|
allow_error: true,
|
|
module: Some(true),
|
|
..Default::default()
|
|
},
|
|
);
|
|
}
|
|
|
|
#[fixture("tests/errors/next-dynamic/**/input.js")]
|
|
fn next_dynamic_errors(input: PathBuf) {
|
|
let output = input.parent().unwrap().join("output.js");
|
|
test_fixture(
|
|
syntax(),
|
|
&|_tr| {
|
|
next_dynamic(
|
|
true,
|
|
false,
|
|
false,
|
|
false,
|
|
NextDynamicMode::Webpack,
|
|
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
|
|
Some("/some-project/src".into()),
|
|
)
|
|
},
|
|
&input,
|
|
&output,
|
|
FixtureTestConfig {
|
|
allow_error: true,
|
|
module: Some(true),
|
|
..Default::default()
|
|
},
|
|
);
|
|
}
|
|
|
|
#[fixture("tests/errors/next-ssg/**/input.js")]
|
|
fn next_ssg_errors(input: PathBuf) {
|
|
let output = input.parent().unwrap().join("output.js");
|
|
test_fixture(
|
|
syntax(),
|
|
&|_tr| next_ssg(Default::default()),
|
|
&input,
|
|
&output,
|
|
FixtureTestConfig {
|
|
allow_error: true,
|
|
module: Some(true),
|
|
..Default::default()
|
|
},
|
|
);
|
|
}
|
|
|
|
#[fixture("tests/errors/react-server-components/**/input.js")]
|
|
#[fixture("tests/errors/react-server-components/**/page.js")]
|
|
#[fixture("tests/errors/react-server-components/**/route.js")]
|
|
fn react_server_components_errors(input: PathBuf) {
|
|
use next_custom_transforms::transforms::react_server_components::{Config, Options};
|
|
let is_react_server_layer = input.iter().any(|s| s.to_str() == Some("server-graph"));
|
|
let cache_components_enabled = input.iter().any(|s| s.to_str() == Some("cache-components"));
|
|
let use_cache_enabled = input.iter().any(|s| s.to_str() == Some("use-cache"));
|
|
let taint_enabled = input.iter().any(|s| s.to_str() == Some("taint-enabled"));
|
|
|
|
let app_dir = input
|
|
.iter()
|
|
.position(|s| s.to_str() == Some("app-dir"))
|
|
.map(|pos| input.iter().take(pos + 1).collect());
|
|
|
|
let output = input.parent().unwrap().join("output.js");
|
|
test_fixture(
|
|
syntax(),
|
|
&|tr| {
|
|
server_components(
|
|
FileName::Real(input.clone()).into(),
|
|
Config::WithOptions(Options {
|
|
is_react_server_layer,
|
|
cache_components_enabled,
|
|
use_cache_enabled,
|
|
taint_enabled,
|
|
}),
|
|
tr.comments.as_ref().clone(),
|
|
app_dir.clone(),
|
|
)
|
|
},
|
|
&input,
|
|
&output,
|
|
FixtureTestConfig {
|
|
allow_error: true,
|
|
module: Some(true),
|
|
..Default::default()
|
|
},
|
|
);
|
|
}
|
|
|
|
#[fixture("tests/errors/next-font-loaders/**/input.js")]
|
|
fn next_font_loaders_errors(input: PathBuf) {
|
|
let output = input.parent().unwrap().join("output.js");
|
|
test_fixture(
|
|
syntax(),
|
|
&|_tr| {
|
|
next_font_loaders(FontLoaderConfig {
|
|
relative_file_path_from_root: atom!("pages/test.tsx"),
|
|
font_loaders: vec![
|
|
atom!("@next/font/google").into(),
|
|
atom!("cool-fonts").into(),
|
|
],
|
|
})
|
|
},
|
|
&input,
|
|
&output,
|
|
FixtureTestConfig {
|
|
allow_error: true,
|
|
module: Some(true),
|
|
..Default::default()
|
|
},
|
|
);
|
|
}
|
|
|
|
#[fixture("tests/errors/server-actions/**/input.js")]
|
|
fn react_server_actions_errors(input: PathBuf) {
|
|
use next_custom_transforms::transforms::react_server_components::{Config, Options};
|
|
let is_react_server_layer = input.iter().any(|s| s.to_str() == Some("server-graph"));
|
|
let output = input.parent().unwrap().join("output.js");
|
|
test_fixture(
|
|
syntax(),
|
|
&|tr| {
|
|
let unresolved_mark = Mark::new();
|
|
(
|
|
// The transforms are intentionally declared in the same order as in
|
|
// crates/next-custom-transforms/src/chain_transforms.rs
|
|
resolver(unresolved_mark, Mark::new(), false),
|
|
server_components(
|
|
FileName::Real(PathBuf::from("/app/item.js")).into(),
|
|
Config::WithOptions(Options {
|
|
is_react_server_layer,
|
|
cache_components_enabled: true,
|
|
use_cache_enabled: true,
|
|
taint_enabled: true,
|
|
}),
|
|
tr.comments.as_ref().clone(),
|
|
None,
|
|
),
|
|
server_actions(
|
|
&FileName::Real("/app/item.js".into()),
|
|
None,
|
|
server_actions::Config {
|
|
is_react_server_layer,
|
|
is_development: true,
|
|
use_cache_enabled: true,
|
|
hash_salt: "".into(),
|
|
cache_kinds: FxHashSet::default(),
|
|
},
|
|
tr.comments.as_ref().clone(),
|
|
unresolved_mark,
|
|
tr.cm.clone(),
|
|
Default::default(),
|
|
ServerActionsMode::Webpack,
|
|
),
|
|
)
|
|
},
|
|
&input,
|
|
&output,
|
|
FixtureTestConfig {
|
|
allow_error: true,
|
|
module: Some(true),
|
|
..Default::default()
|
|
},
|
|
);
|
|
}
|
|
|
|
#[fixture("tests/errors/strip-page-exports/**/input.js")]
|
|
fn next_transform_strip_page_exports_errors(input: PathBuf) {
|
|
let output = input.parent().unwrap().join("output.js");
|
|
test_fixture(
|
|
syntax(),
|
|
&|_tr| {
|
|
next_transform_strip_page_exports(ExportFilter::StripDataExports, Default::default())
|
|
},
|
|
&input,
|
|
&output,
|
|
FixtureTestConfig {
|
|
allow_error: true,
|
|
module: Some(true),
|
|
..Default::default()
|
|
},
|
|
);
|
|
}
|
|
|
|
#[fixture("tests/errors/use-cache-not-allowed/**/input.js")]
|
|
fn use_cache_not_allowed(input: PathBuf) {
|
|
use next_custom_transforms::transforms::react_server_components::{Config, Options};
|
|
let output = input.parent().unwrap().join("output.js");
|
|
test_fixture(
|
|
syntax(),
|
|
&|tr| {
|
|
let unresolved_mark = Mark::new();
|
|
(
|
|
// The transforms are intentionally declared in the same order as in
|
|
// crates/next-custom-transforms/src/chain_transforms.rs
|
|
resolver(unresolved_mark, Mark::new(), false),
|
|
server_components(
|
|
FileName::Real(PathBuf::from("/app/item.js")).into(),
|
|
Config::WithOptions(Options {
|
|
is_react_server_layer: true,
|
|
cache_components_enabled: false,
|
|
use_cache_enabled: false,
|
|
taint_enabled: true,
|
|
}),
|
|
tr.comments.as_ref().clone(),
|
|
None,
|
|
),
|
|
server_actions(
|
|
&FileName::Real("/app/item.js".into()),
|
|
None,
|
|
server_actions::Config {
|
|
is_react_server_layer: true,
|
|
is_development: true,
|
|
use_cache_enabled: false,
|
|
hash_salt: "".into(),
|
|
cache_kinds: FxHashSet::from_iter([rcstr!("x")]),
|
|
},
|
|
tr.comments.as_ref().clone(),
|
|
unresolved_mark,
|
|
tr.cm.clone(),
|
|
Default::default(),
|
|
ServerActionsMode::Webpack,
|
|
),
|
|
)
|
|
},
|
|
&input,
|
|
&output,
|
|
FixtureTestConfig {
|
|
allow_error: true,
|
|
module: Some(true),
|
|
..Default::default()
|
|
},
|
|
);
|
|
}
|