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(
// necessarily the root of the filesystem (e.g. in a monorepo).
server_relative_root: Some(project_path.clone()),
after_resolve_plugins: vec![ResolvedVc::upcast(
NextSharedRuntimeResolvePlugin::new(project_path.clone())
.to_resolved()
.await?,
NextSharedRuntimeResolvePlugin::new().to_resolved().await?,
)],
..Default::default()
};
......
......@@ -114,9 +114,7 @@ pub async fn get_edge_resolve_options_context(
.await?;
let after_resolve_plugins = vec![ResolvedVc::upcast(
NextSharedRuntimeResolvePlugin::new(project_path.clone())
.to_resolved()
.await?,
NextSharedRuntimeResolvePlugin::new().to_resolved().await?,
)];
// 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(
external_packages.retain(|item| !transpiled_packages.contains(item));
let server_external_packages_plugin = ExternalCjsModulesResolvePlugin::new(
project_path.root().owned().await?,
ExternalPredicate::Only(ResolvedVc::cell(external_packages)).cell(),
*next_config.import_externals().await?,
)
......@@ -211,7 +210,6 @@ pub async fn get_server_resolve_options_context(
server_external_packages_plugin
} else {
ExternalCjsModulesResolvePlugin::new(
project_path.root().owned().await?,
ExternalPredicate::AllExcept(ResolvedVc::cell(transpiled_packages)).cell(),
*next_config.import_externals().await?,
)
......@@ -219,13 +217,10 @@ pub async fn get_server_resolve_options_context(
.await?
};
let next_external_plugin = NextExternalResolvePlugin::new(project_path.clone())
let next_external_plugin = NextExternalResolvePlugin::new().to_resolved().await?;
let next_node_shared_runtime_plugin = NextNodeSharedRuntimeResolvePlugin::new(ty.clone())
.to_resolved()
.await?;
let next_node_shared_runtime_plugin =
NextNodeSharedRuntimeResolvePlugin::new(project_path.clone(), ty.clone())
.to_resolved()
.await?;
let after_resolve_plugins = match ty {
ServerContextType::Pages { .. } | ServerContextType::PagesApi { .. } => {
......
......@@ -51,12 +51,11 @@ pub(crate) struct ExternalCjsModulesResolvePlugin {
impl ExternalCjsModulesResolvePlugin {
#[turbo_tasks::function]
pub async fn new(
root: FileSystemPath,
predicate: ResolvedVc<ExternalPredicate>,
import_externals: bool,
) -> Result<Vc<Self>> {
let condition = AfterResolvePluginCondition::new_with_glob(
root,
None,
Glob::new(rcstr!("**/node_modules/**"), GlobOptions::default()),
)
.to_resolved()
......
......@@ -77,9 +77,9 @@ pub(crate) struct NextExternalResolvePlugin {
#[turbo_tasks::value_impl]
impl NextExternalResolvePlugin {
#[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(
project_path.root().owned().await?,
None,
Glob::new(
rcstr!("**/next/dist/**/*.{external,runtime.dev,runtime.prod}.js"),
GlobOptions::default(),
......@@ -134,12 +134,9 @@ pub(crate) struct NextNodeSharedRuntimeResolvePlugin {
#[turbo_tasks::value_impl]
impl NextNodeSharedRuntimeResolvePlugin {
#[turbo_tasks::function]
pub async fn new(
root: FileSystemPath,
server_context_type: ServerContextType,
) -> Result<Vc<Self>> {
pub async fn new(server_context_type: ServerContextType) -> Result<Vc<Self>> {
let condition = AfterResolvePluginCondition::new_with_glob(
root.root().owned().await?,
None,
Glob::new(
rcstr!("**/next/dist/**/*.shared-runtime.js"),
GlobOptions::default(),
......@@ -215,9 +212,9 @@ pub(crate) struct NextSharedRuntimeResolvePlugin {
#[turbo_tasks::value_impl]
impl NextSharedRuntimeResolvePlugin {
#[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(
root.root().owned().await?,
None,
Glob::new(
rcstr!("**/next/dist/esm/**/*.shared-runtime.js"),
GlobOptions::default(),
......
......@@ -15,8 +15,10 @@ use crate::{
/// recomputing this is very cheap.
#[turbo_tasks::value(serialization = "skip")]
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 {
root: FileSystemPath,
root: Option<FileSystemPath>,
glob: ReadRef<Glob>,
},
// these variants are used by utoo
......@@ -27,7 +29,10 @@ pub enum AfterResolvePluginCondition {
#[turbo_tasks::value_impl]
impl AfterResolvePluginCondition {
#[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?;
Ok(AfterResolvePluginCondition::Glob { root, glob }.cell())
}
......@@ -38,11 +43,11 @@ impl AfterResolvePluginCondition {
pub fn matches(&self, fs_path: &FileSystemPath) -> bool {
match self {
AfterResolvePluginCondition::Glob { root, glob } => {
if root.fs == fs_path.fs {
root.get_path_to(fs_path).is_some_and(|p| glob.matches(p))
} else {
glob.matches(&fs_path.path)
}
let path = match root {
Some(root) => root.get_path_to(fs_path),
None => Some(&*fs_path.path),
};
path.is_some_and(|p| glob.matches(p))
}
AfterResolvePluginCondition::Always => true,
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