From cf36a2bb3d638a3502cb7567afc3808ac43c1390 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 14 Jul 2024 10:42:51 +0200 Subject: [PATCH] Turbopack build: Exclude .d.ts files as routes (#67744) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Matches the check we do for webpack here: https://github.com/vercel/next.js/blob/8c4bd571c1996eb1e42d64c9328d41a71690a028/packages/next/src/build/entries.ts#L251 `.d.ts` files are not routable but because the page extensions includes `.ts` it ends up matching at the end, which is correct, but we don't want to include `.d.` 👍 --- packages/next-swc/crates/next-core/src/app_structure.rs | 4 ++++ packages/next-swc/crates/next-core/src/pages_structure.rs | 4 ++++ test/turbopack-build-tests-manifest.json | 5 ++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/next-swc/crates/next-core/src/app_structure.rs b/packages/next-swc/crates/next-core/src/app_structure.rs index 59836f3d79cae0..39ab9ceb24a41c 100644 --- a/packages/next-swc/crates/next-core/src/app_structure.rs +++ b/packages/next-swc/crates/next-core/src/app_structure.rs @@ -323,6 +323,10 @@ async fn get_directory_tree_internal( match *entry { DirectoryEntry::File(file) => { let file = file.resolve().await?; + // Do not process .d.ts files as routes + if basename.ends_with(".d.ts") { + continue; + } if let Some((stem, ext)) = basename.split_once('.') { if page_extensions_value.iter().any(|e| e == ext) { match stem { diff --git a/packages/next-swc/crates/next-core/src/pages_structure.rs b/packages/next-swc/crates/next-core/src/pages_structure.rs index 95769a0fae6f1f..29e64c2ae4f14b 100644 --- a/packages/next-swc/crates/next-core/src/pages_structure.rs +++ b/packages/next-swc/crates/next-core/src/pages_structure.rs @@ -199,6 +199,10 @@ async fn get_pages_structure_for_root_directory( for (name, entry) in entries.iter() { match entry { DirectoryEntry::File(file_project_path) => { + // Do not process .d.ts files as routes + if name.ends_with(".d.ts") { + continue; + } let Some(basename) = page_basename(name, page_extensions_raw) else { continue; }; diff --git a/test/turbopack-build-tests-manifest.json b/test/turbopack-build-tests-manifest.json index 6bde5ae92a2a26..3892eac192b69f 100644 --- a/test/turbopack-build-tests-manifest.json +++ b/test/turbopack-build-tests-manifest.json @@ -5467,9 +5467,7 @@ "404 Page Support development mode 2 does not show error with getStaticProps in pages/404 dev", "404 Page Support development mode 2 falls back to _error correctly without pages/404", "404 Page Support development mode 2 shows error with getInitialProps in pages/404 dev", - "404 Page Support development mode 2 shows error with getServerSideProps in pages/404 dev" - ], - "failed": [ + "404 Page Support development mode 2 shows error with getServerSideProps in pages/404 dev", "404 Page Support production mode does not show error with getStaticProps in pages/404 build", "404 Page Support production mode should add /404 to pages-manifest correctly", "404 Page Support production mode should not cache for custom 404 page with gssp and revalidate disabled", @@ -5484,6 +5482,7 @@ "404 Page Support production mode shows error with getInitialProps in pages/404 build", "404 Page Support production mode shows error with getServerSideProps in pages/404 build" ], + "failed": [], "pending": [ "404 Page Support development mode should not error when visited directly", "404 Page Support development mode should render _error for a 500 error still",