Unverified Commit 9a9ea121 authored by Benjamin Woodruff ‮'s avatar Benjamin Woodruff Committed by GitHub

Turbopack: Remove implicit mismatched root fallthrough for…

Turbopack: Remove implicit mismatched root fallthrough for AfterResolvePluginCondition, accept None as a root (#99556)

`AfterResolvePluginCondition` would ignore the root path if the
`ResolvedVc<FileSystem>`s didn't match, which worked for additional
roots, but is surprising implicit behavior. Make it explicit by
requiring `None` if you don't want to match a specific root.
parent 84eb323f
...@@ -193,9 +193,7 @@ pub async fn get_client_resolve_options_context( ...@@ -193,9 +193,7 @@ pub async fn get_client_resolve_options_context(
// necessarily the root of the filesystem (e.g. in a monorepo). // necessarily the root of the filesystem (e.g. in a monorepo).
server_relative_root: Some(project_path.clone()), server_relative_root: Some(project_path.clone()),
after_resolve_plugins: vec![ResolvedVc::upcast( after_resolve_plugins: vec![ResolvedVc::upcast(
NextSharedRuntimeResolvePlugin::new(project_path.clone()) NextSharedRuntimeResolvePlugin::new().to_resolved().await?,
.to_resolved()
.await?,
)], )],
..Default::default() ..Default::default()
}; };
......
...@@ -114,9 +114,7 @@ pub async fn get_edge_resolve_options_context( ...@@ -114,9 +114,7 @@ pub async fn get_edge_resolve_options_context(
.await?; .await?;
let after_resolve_plugins = vec![ResolvedVc::upcast( let after_resolve_plugins = vec![ResolvedVc::upcast(
NextSharedRuntimeResolvePlugin::new(project_path.clone()) NextSharedRuntimeResolvePlugin::new().to_resolved().await?,
.to_resolved()
.await?,
)]; )];
// https://github.com/vercel/next.js/blob/bf52c254973d99fed9d71507a2e818af80b8ade7/packages/next/src/build/webpack-config.ts#L96-L102 // https://github.com/vercel/next.js/blob/bf52c254973d99fed9d71507a2e818af80b8ade7/packages/next/src/build/webpack-config.ts#L96-L102
......
...@@ -186,7 +186,6 @@ pub async fn get_server_resolve_options_context( ...@@ -186,7 +186,6 @@ pub async fn get_server_resolve_options_context(
external_packages.retain(|item| !transpiled_packages.contains(item)); external_packages.retain(|item| !transpiled_packages.contains(item));
let server_external_packages_plugin = ExternalCjsModulesResolvePlugin::new( let server_external_packages_plugin = ExternalCjsModulesResolvePlugin::new(
project_path.root().owned().await?,
ExternalPredicate::Only(ResolvedVc::cell(external_packages)).cell(), ExternalPredicate::Only(ResolvedVc::cell(external_packages)).cell(),
*next_config.import_externals().await?, *next_config.import_externals().await?,
) )
...@@ -211,7 +210,6 @@ pub async fn get_server_resolve_options_context( ...@@ -211,7 +210,6 @@ pub async fn get_server_resolve_options_context(
server_external_packages_plugin server_external_packages_plugin
} else { } else {
ExternalCjsModulesResolvePlugin::new( ExternalCjsModulesResolvePlugin::new(
project_path.root().owned().await?,
ExternalPredicate::AllExcept(ResolvedVc::cell(transpiled_packages)).cell(), ExternalPredicate::AllExcept(ResolvedVc::cell(transpiled_packages)).cell(),
*next_config.import_externals().await?, *next_config.import_externals().await?,
) )
...@@ -219,11 +217,8 @@ pub async fn get_server_resolve_options_context( ...@@ -219,11 +217,8 @@ pub async fn get_server_resolve_options_context(
.await? .await?
}; };
let next_external_plugin = NextExternalResolvePlugin::new(project_path.clone()) let next_external_plugin = NextExternalResolvePlugin::new().to_resolved().await?;
.to_resolved() let next_node_shared_runtime_plugin = NextNodeSharedRuntimeResolvePlugin::new(ty.clone())
.await?;
let next_node_shared_runtime_plugin =
NextNodeSharedRuntimeResolvePlugin::new(project_path.clone(), ty.clone())
.to_resolved() .to_resolved()
.await?; .await?;
......
...@@ -51,12 +51,11 @@ pub(crate) struct ExternalCjsModulesResolvePlugin { ...@@ -51,12 +51,11 @@ pub(crate) struct ExternalCjsModulesResolvePlugin {
impl ExternalCjsModulesResolvePlugin { impl ExternalCjsModulesResolvePlugin {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn new( pub async fn new(
root: FileSystemPath,
predicate: ResolvedVc<ExternalPredicate>, predicate: ResolvedVc<ExternalPredicate>,
import_externals: bool, import_externals: bool,
) -> Result<Vc<Self>> { ) -> Result<Vc<Self>> {
let condition = AfterResolvePluginCondition::new_with_glob( let condition = AfterResolvePluginCondition::new_with_glob(
root, None,
Glob::new(rcstr!("**/node_modules/**"), GlobOptions::default()), Glob::new(rcstr!("**/node_modules/**"), GlobOptions::default()),
) )
.to_resolved() .to_resolved()
......
...@@ -77,9 +77,9 @@ pub(crate) struct NextExternalResolvePlugin { ...@@ -77,9 +77,9 @@ pub(crate) struct NextExternalResolvePlugin {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl NextExternalResolvePlugin { impl NextExternalResolvePlugin {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn new(project_path: FileSystemPath) -> Result<Vc<Self>> { pub async fn new() -> Result<Vc<Self>> {
let condition = AfterResolvePluginCondition::new_with_glob( let condition = AfterResolvePluginCondition::new_with_glob(
project_path.root().owned().await?, None,
Glob::new( Glob::new(
rcstr!("**/next/dist/**/*.{external,runtime.dev,runtime.prod}.js"), rcstr!("**/next/dist/**/*.{external,runtime.dev,runtime.prod}.js"),
GlobOptions::default(), GlobOptions::default(),
...@@ -134,12 +134,9 @@ pub(crate) struct NextNodeSharedRuntimeResolvePlugin { ...@@ -134,12 +134,9 @@ pub(crate) struct NextNodeSharedRuntimeResolvePlugin {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl NextNodeSharedRuntimeResolvePlugin { impl NextNodeSharedRuntimeResolvePlugin {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn new( pub async fn new(server_context_type: ServerContextType) -> Result<Vc<Self>> {
root: FileSystemPath,
server_context_type: ServerContextType,
) -> Result<Vc<Self>> {
let condition = AfterResolvePluginCondition::new_with_glob( let condition = AfterResolvePluginCondition::new_with_glob(
root.root().owned().await?, None,
Glob::new( Glob::new(
rcstr!("**/next/dist/**/*.shared-runtime.js"), rcstr!("**/next/dist/**/*.shared-runtime.js"),
GlobOptions::default(), GlobOptions::default(),
...@@ -215,9 +212,9 @@ pub(crate) struct NextSharedRuntimeResolvePlugin { ...@@ -215,9 +212,9 @@ pub(crate) struct NextSharedRuntimeResolvePlugin {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl NextSharedRuntimeResolvePlugin { impl NextSharedRuntimeResolvePlugin {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn new(root: FileSystemPath) -> Result<Vc<Self>> { pub async fn new() -> Result<Vc<Self>> {
let condition = AfterResolvePluginCondition::new_with_glob( let condition = AfterResolvePluginCondition::new_with_glob(
root.root().owned().await?, None,
Glob::new( Glob::new(
rcstr!("**/next/dist/esm/**/*.shared-runtime.js"), rcstr!("**/next/dist/esm/**/*.shared-runtime.js"),
GlobOptions::default(), GlobOptions::default(),
......
...@@ -15,8 +15,10 @@ use crate::{ ...@@ -15,8 +15,10 @@ use crate::{
/// recomputing this is very cheap. /// recomputing this is very cheap.
#[turbo_tasks::value(serialization = "skip")] #[turbo_tasks::value(serialization = "skip")]
pub enum AfterResolvePluginCondition { pub enum AfterResolvePluginCondition {
/// Matches the glob against the resolved path relative to `root`. A `root` of `None` matches
/// resolved paths on any filesystem, relative to that filesystem's root.
Glob { Glob {
root: FileSystemPath, root: Option<FileSystemPath>,
glob: ReadRef<Glob>, glob: ReadRef<Glob>,
}, },
// these variants are used by utoo // these variants are used by utoo
...@@ -27,7 +29,10 @@ pub enum AfterResolvePluginCondition { ...@@ -27,7 +29,10 @@ pub enum AfterResolvePluginCondition {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl AfterResolvePluginCondition { impl AfterResolvePluginCondition {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn new_with_glob(root: FileSystemPath, glob: ResolvedVc<Glob>) -> Result<Vc<Self>> { pub async fn new_with_glob(
root: Option<FileSystemPath>,
glob: ResolvedVc<Glob>,
) -> Result<Vc<Self>> {
let glob = glob.await?; let glob = glob.await?;
Ok(AfterResolvePluginCondition::Glob { root, glob }.cell()) Ok(AfterResolvePluginCondition::Glob { root, glob }.cell())
} }
...@@ -38,11 +43,11 @@ impl AfterResolvePluginCondition { ...@@ -38,11 +43,11 @@ impl AfterResolvePluginCondition {
pub fn matches(&self, fs_path: &FileSystemPath) -> bool { pub fn matches(&self, fs_path: &FileSystemPath) -> bool {
match self { match self {
AfterResolvePluginCondition::Glob { root, glob } => { AfterResolvePluginCondition::Glob { root, glob } => {
if root.fs == fs_path.fs { let path = match root {
root.get_path_to(fs_path).is_some_and(|p| glob.matches(p)) Some(root) => root.get_path_to(fs_path),
} else { None => Some(&*fs_path.path),
glob.matches(&fs_path.path) };
} path.is_some_and(|p| glob.matches(p))
} }
AfterResolvePluginCondition::Always => true, AfterResolvePluginCondition::Always => true,
AfterResolvePluginCondition::Never => false, AfterResolvePluginCondition::Never => false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment