Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions crates/next-core/src/next_client/transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ pub async fn get_next_client_transforms_rules(

let modularize_imports_config = next_config.modularize_imports();
let enable_mdx_rs = next_config.mdx_rs().await?.is_some();
let page_extensions: Vec<String> = next_config
.page_extensions()
.await?
.iter()
.map(|s| s.to_string())
.collect();

if !foreign_code {
rules.push(get_next_lint_transform_rule(enable_mdx_rs).await?);
Expand Down Expand Up @@ -83,7 +77,7 @@ pub async fn get_next_client_transforms_rules(
ExportFilter::StripDataExports,
enable_mdx_rs,
vec![],
&page_extensions,
&next_config.page_extensions().await?,
)
.await?,
);
Expand Down
12 changes: 3 additions & 9 deletions crates/next-core/src/next_server/transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ pub async fn get_next_server_transforms_rules(
let mut rules = vec![];

let modularize_imports_config = next_config.modularize_imports();
let mdx_rs = next_config.mdx_rs().await?.is_some();
let page_extensions: Vec<String> = next_config
.page_extensions()
.await?
.iter()
.map(|s| s.to_string())
.collect();
let mdx_rs: bool = next_config.mdx_rs().await?.is_some();

if !foreign_code {
rules.push(get_next_lint_transform_rule(mdx_rs).await?);
Expand Down Expand Up @@ -92,7 +86,7 @@ pub async fn get_next_server_transforms_rules(
vec![RuleCondition::ReferenceType(ReferenceTypeCondition::Entry(
Some(EntryReferenceSubType::PageData),
))],
&page_extensions,
&next_config.page_extensions().await?,
)
.await?,
);
Expand Down Expand Up @@ -157,7 +151,7 @@ pub async fn get_next_server_transforms_rules(
};

if is_app_dir {
rules.push(get_next_debug_instant_stack_rule(mdx_rs, page_extensions.clone()).await?);
rules.push(get_next_debug_instant_stack_rule(mdx_rs, next_config.page_extensions()).await?);
}

if is_app_dir &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::debug_instant_stack::debug_instant_stack;
use next_custom_transforms::transforms::debug_instant_stack::DebugInstantStack;
use swc_core::ecma::ast::Program;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Vc};
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{
Expand All @@ -12,9 +13,9 @@ use super::module_rule_match_js_no_url;

pub async fn get_next_debug_instant_stack_rule(
enable_mdx_rs: bool,
page_extensions: Vec<String>,
page_extensions: Vc<Vec<RcStr>>,
) -> Result<ModuleRule> {
let transform = EcmascriptInputTransform::Plugin(
let transform: EcmascriptInputTransform = EcmascriptInputTransform::Plugin(
next_debug_instant_stack_transform_plugin(page_extensions)
.to_resolved()
.await?,
Expand All @@ -32,24 +33,27 @@ pub async fn get_next_debug_instant_stack_rule(
}

#[turbo_tasks::function]
fn next_debug_instant_stack_transform_plugin(page_extensions: Vec<String>) -> Vc<TransformPlugin> {
Vc::cell(Box::new(NextDebugInstantStack { page_extensions })
as Box<dyn CustomTransformer + Send + Sync>)
async fn next_debug_instant_stack_transform_plugin(
page_extensions: ResolvedVc<Vec<RcStr>>,
) -> Result<Vc<TransformPlugin>> {
Ok(Vc::cell(Box::new(NextDebugInstantStack {
debug_instant_stack: DebugInstantStack::new(&*page_extensions.await?),
}) as Box<dyn CustomTransformer + Send + Sync>))
}

#[derive(Debug)]
struct NextDebugInstantStack {
page_extensions: Vec<String>,
debug_instant_stack: DebugInstantStack,
}

#[async_trait]
impl CustomTransformer for NextDebugInstantStack {
#[tracing::instrument(level = tracing::Level::TRACE, name = "debug_instant_stack", skip_all)]
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> {
program.mutate(debug_instant_stack(
ctx.file_path_str.to_string(),
self.page_extensions.clone(),
));
program.mutate(
self.debug_instant_stack
.get_pass(ctx.file_path_str.to_string()),
);
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use next_custom_transforms::transforms::strip_page_exports::{
ExportFilter, next_transform_strip_page_exports,
};
use swc_core::ecma::ast::Program;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, TaskInput, Vc, trace::TraceRawVcs};
use turbo_tasks_fs::FileSystemPath;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect, RuleCondition};
Expand Down Expand Up @@ -45,7 +46,7 @@ pub async fn get_next_pages_transforms_rule(
export_filter: ExportFilter,
enable_mdx_rs: bool,
extra_conditions: Vec<RuleCondition>,
page_extensions: &[String],
page_extensions: &[RcStr],
) -> Result<ModuleRule> {
// Apply the Next SSG transform to all pages.
let strip_transform = EcmascriptInputTransform::Plugin(
Expand Down
6 changes: 3 additions & 3 deletions crates/next-custom-transforms/src/chain_transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ where
crate::transforms::debug_fn_name::debug_fn_name(),
opts.debug_function_name,
),
crate::transforms::debug_instant_stack::debug_instant_stack(
file_path_for_instant_stack,
crate::transforms::debug_instant_stack::DebugInstantStack::new(
match &opts.server_components {
Some(react_server_components::Config::WithOptions(options)) => {
options.page_extensions.clone()
}
_ => vec![],
},
),
)
.get_pass(file_path_for_instant_stack),
visit_mut_pass(crate::transforms::pure::pure_magic(comments.clone())),
Optional::new(
linter(lint_codemod_comments(comments)),
Expand Down
61 changes: 38 additions & 23 deletions crates/next-custom-transforms/src/transforms/debug_instant_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,48 @@ use swc_core::{
quote,
};

fn build_page_extensions_regex(page_extensions: &[String]) -> String {
if page_extensions.is_empty() {
"(ts|js)x?".to_string()
} else {
let escaped: Vec<String> = page_extensions
.iter()
.map(|ext| regex::escape(ext))
.collect();
format!("({})", escaped.join("|"))
}
#[derive(Debug)]
pub struct DebugInstantStack {
page_or_layout: Regex,
}

pub fn debug_instant_stack(filepath: String, page_extensions: Vec<String>) -> impl Pass {
visit_mut_pass(DebugInstantStack {
filepath,
instant_export_span: None,
page_extensions,
})
impl DebugInstantStack {
pub fn new<I, S>(page_extensions: I) -> Self
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
let mut result = String::from(r"[\\/](page|layout|default)\.");
let mut iter = page_extensions.into_iter();
if let Some(first) = iter.next() {
result.push('(');
result.push_str(&regex::escape(first.as_ref()));
for ext in iter {
result.push('|');
result.push_str(&regex::escape(ext.as_ref()));
}
result.push(')');
} else {
result.push_str("(ts|js)x?");
}
result.push('$');
Self {
page_or_layout: Regex::new(&result).unwrap(),
}
}
pub fn get_pass(&self, filepath: String) -> impl Pass + use<> {
visit_mut_pass(DebugInstantStackPass {
filepath,
instant_export_span: None,
page_or_layout: self.page_or_layout.clone(),
})
}
}

struct DebugInstantStack {
struct DebugInstantStackPass {
filepath: String,
instant_export_span: Option<Span>,
page_extensions: Vec<String>,
page_or_layout: Regex,
}

/// Given an export specifier, returns `Some((exported_name, local_name))` if
Expand Down Expand Up @@ -80,12 +98,9 @@ fn find_var_init_span(items: &[ModuleItem], local_name: &str) -> Option<Span> {
None
}

impl VisitMut for DebugInstantStack {
impl VisitMut for DebugInstantStackPass {
fn visit_mut_module_items(&mut self, items: &mut Vec<ModuleItem>) {
let ext_pattern = build_page_extensions_regex(&self.page_extensions);
let page_or_layout_re =
Regex::new(&format!(r"[\\/](page|layout|default)\.{ext_pattern}$")).unwrap();
if !page_or_layout_re.is_match(&self.filepath) {
if !self.page_or_layout.is_match(&self.filepath) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions crates/next-custom-transforms/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bytes_str::BytesStr;
use next_custom_transforms::transforms::{
cjs_optimizer::cjs_optimizer,
debug_fn_name::debug_fn_name,
debug_instant_stack::debug_instant_stack,
debug_instant_stack::DebugInstantStack,
dynamic::{NextDynamicMode, next_dynamic},
fonts::{Config as FontLoaderConfig, next_font_loaders},
named_import_transform::named_import_transform,
Expand Down Expand Up @@ -878,7 +878,7 @@ fn test_debug_instant_stack(input: PathBuf) {

test_fixture(
syntax(),
&|_| debug_instant_stack("app/page.js".to_string(), vec![]),
&|_| DebugInstantStack::new::<Vec<&str>, &str>(vec![]).get_pass("app/page.js".to_string()),
&input,
&output,
FixtureTestConfig {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "16.3.0-canary.3"
"version": "16.3.0-canary.4"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"description": "ESLint configuration used by Next.js.",
"license": "MIT",
"repository": {
Expand All @@ -12,7 +12,7 @@
"dist"
],
"dependencies": {
"@next/eslint-plugin-next": "16.3.0-canary.3",
"@next/eslint-plugin-next": "16.3.0-canary.4",
"eslint-import-resolver-node": "^0.3.6",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.32.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-internal/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@next/eslint-plugin-internal",
"private": true,
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"description": "ESLint plugin for working on Next.js.",
"exports": {
".": "./src/eslint-plugin-internal.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"description": "ESLint plugin for Next.js.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@next/font",
"private": true,
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-playwright/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/playwright",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-playwright"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-routing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/routing",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-rspack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-rspack",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-rspack"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "16.3.0-canary.3",
"version": "16.3.0-canary.4",
"private": true,
"files": [
"native/"
Expand Down
Loading
Loading