From 0edecbde422b6d2c7e99f9a9f888a1e6fcf44bf7 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Fri, 27 Sep 2024 17:05:49 -0700 Subject: [PATCH] refactor(turbo-tasks-fs): Use ResolvedVc instead of Vc in structs --- crates/next-api/src/pages.rs | 10 +- crates/next-core/src/app_structure.rs | 4 +- crates/next-core/src/page_loader.rs | 7 +- crates/next-core/src/pages_structure.rs | 50 ++++----- turbopack/crates/node-file-trace/src/lib.rs | 4 +- .../turbo-tasks-fs/examples/hash_directory.rs | 8 +- .../turbo-tasks-fs/examples/hash_glob.rs | 4 +- turbopack/crates/turbo-tasks-fs/src/attach.rs | 24 ++-- .../crates/turbo-tasks-fs/src/embed/fs.rs | 44 ++++---- turbopack/crates/turbo-tasks-fs/src/lib.rs | 106 ++++++++++-------- .../crates/turbo-tasks-fs/src/read_glob.rs | 16 +-- .../turbopack-core/src/chunk/optimize.rs | 2 +- .../crates/turbopack-core/src/resolve/mod.rs | 14 +-- .../turbopack-core/src/resolve/pattern.rs | 19 ++-- .../src/source/static_assets.rs | 8 +- .../src/references/node.rs | 4 +- .../src/references/require_context.rs | 4 +- .../src/references/typescript.rs | 2 +- .../turbopack-node/src/transforms/webpack.rs | 2 +- .../src/node_native_binding.rs | 8 +- .../turbopack-resolve/src/typescript.rs | 4 +- .../turbopack-test-utils/src/snapshot.rs | 2 +- 22 files changed, 181 insertions(+), 165 deletions(-) diff --git a/crates/next-api/src/pages.rs b/crates/next-api/src/pages.rs index 144a622427ff3f..812bd901c1cf21 100644 --- a/crates/next-api/src/pages.rs +++ b/crates/next-api/src/pages.rs @@ -1180,8 +1180,14 @@ impl PageEndpoint { } #[turbo_tasks::function] - fn client_relative_path(&self) -> Vc { - Vc::cell(Some(self.pages_project.project().client_relative_path())) + async fn client_relative_path(&self) -> Result> { + Ok(Vc::cell(Some( + self.pages_project + .project() + .client_relative_path() + .to_resolved() + .await?, + ))) } } diff --git a/crates/next-core/src/app_structure.rs b/crates/next-core/src/app_structure.rs index c36b7a6f6ab547..46a3479824f619 100644 --- a/crates/next-core/src/app_structure.rs +++ b/crates/next-core/src/app_structure.rs @@ -1330,9 +1330,9 @@ pub async fn get_global_metadata( }; if dynamic { - *entry = Some(MetadataItem::Dynamic { path: file }); + *entry = Some(MetadataItem::Dynamic { path: *file }); } else { - *entry = Some(MetadataItem::Static { path: file }); + *entry = Some(MetadataItem::Static { path: *file }); } // TODO(WEB-952) handle symlinks in app dir } diff --git a/crates/next-core/src/page_loader.rs b/crates/next-core/src/page_loader.rs index f3e04516d6ff4f..5a5955fc59abd7 100644 --- a/crates/next-core/src/page_loader.rs +++ b/crates/next-core/src/page_loader.rs @@ -111,7 +111,7 @@ impl PageLoaderAsset { .map(|chunk| { Vc::upcast(ProxiedAsset::new( *chunk, - FileSystemPath::rebase(chunk.ident().path(), *rebase_path, root_path), + FileSystemPath::rebase(chunk.ident().path(), **rebase_path, root_path), )) }) .collect(); @@ -131,7 +131,10 @@ fn page_loader_chunk_reference_description() -> Vc { impl OutputAsset for PageLoaderAsset { #[turbo_tasks::function] async fn ident(&self) -> Result> { - let root = self.rebase_prefix_path.await?.unwrap_or(self.server_root); + let root = self + .rebase_prefix_path + .await? + .map_or(self.server_root, |path| *path); Ok(AssetIdent::from_path( root.join( format!( diff --git a/crates/next-core/src/pages_structure.rs b/crates/next-core/src/pages_structure.rs index d90fc5a97ec4c7..87deebe96a959c 100644 --- a/crates/next-core/src/pages_structure.rs +++ b/crates/next-core/src/pages_structure.rs @@ -117,33 +117,29 @@ pub async fn find_pages_structure( let pages_root = project_root .join("pages".into()) .realpath() - .resolve() + .to_resolved() .await?; - let pages_root = Vc::::cell( - if *pages_root.get_type().await? == FileSystemEntryType::Directory { - Some(pages_root) + let pages_root = if *pages_root.get_type().await? == FileSystemEntryType::Directory { + Some(pages_root) + } else { + let src_pages_root = project_root + .join("src/pages".into()) + .realpath() + .to_resolved() + .await?; + if *src_pages_root.get_type().await? == FileSystemEntryType::Directory { + Some(src_pages_root) } else { - let src_pages_root = project_root - .join("src/pages".into()) - .realpath() - .resolve() - .await?; - if *src_pages_root.get_type().await? == FileSystemEntryType::Directory { - Some(src_pages_root) - } else { - // If neither pages nor src/pages exists, we still want to generate - // the pages structure, but with no pages and default values for - // _app, _document and _error. - None - } - }, - ) - .resolve() - .await?; + // If neither pages nor src/pages exists, we still want to generate + // the pages structure, but with no pages and default values for + // _app, _document and _error. + None + } + }; Ok(get_pages_structure_for_root_directory( project_root, - pages_root, + Vc::cell(pages_root), next_router_root, page_extensions, )) @@ -202,7 +198,7 @@ async fn get_pages_structure_for_root_directory( DirectoryEntry::Directory(dir_project_path) => match name.as_str() { "api" => { api_directory = Some(get_pages_structure_for_directory( - dir_project_path, + *dir_project_path, next_router_path.join(name.clone()), 1, page_extensions, @@ -212,7 +208,7 @@ async fn get_pages_structure_for_root_directory( children.push(( name, get_pages_structure_for_directory( - dir_project_path, + *dir_project_path, next_router_path.join(name.clone()), 1, page_extensions, @@ -231,7 +227,7 @@ async fn get_pages_structure_for_root_directory( Some( PagesDirectoryStructure { - project_path: *project_path, + project_path: **project_path, next_router_path, items: items.into_iter().map(|(_, v)| v).collect(), children: children.into_iter().map(|(_, v)| v).collect(), @@ -243,7 +239,7 @@ async fn get_pages_structure_for_root_directory( }; let pages_path = if let Some(project_path) = *project_path { - project_path + *project_path } else { project_root.join("pages".into()) }; @@ -338,7 +334,7 @@ async fn get_pages_structure_for_directory( children.push(( name, get_pages_structure_for_directory( - *dir_project_path, + **dir_project_path, next_router_path.join(name.clone()), position + 1, page_extensions, diff --git a/turbopack/crates/node-file-trace/src/lib.rs b/turbopack/crates/node-file-trace/src/lib.rs index 71b2f4e5052679..5b6b09befbe364 100644 --- a/turbopack/crates/node-file-trace/src/lib.rs +++ b/turbopack/crates/node-file-trace/src/lib.rs @@ -205,7 +205,7 @@ async fn add_glob_results( let result = result.await?; for entry in result.results.values() { if let DirectoryEntry::File(path) = entry { - let source = Vc::upcast(FileSource::new(*path)); + let source = Vc::upcast(FileSource::new(**path)); let module = asset_context .process( source, @@ -224,7 +224,7 @@ async fn add_glob_results( Box::pin(add_glob_results(asset_context, result, list)) } // Boxing for async recursion - recurse(asset_context, *result, list).await?; + recurse(asset_context, **result, list).await?; } Ok(()) } diff --git a/turbopack/crates/turbo-tasks-fs/examples/hash_directory.rs b/turbopack/crates/turbo-tasks-fs/examples/hash_directory.rs index 6a74f417816682..5efbdb7263a667 100644 --- a/turbopack/crates/turbo-tasks-fs/examples/hash_directory.rs +++ b/turbopack/crates/turbo-tasks-fs/examples/hash_directory.rs @@ -76,12 +76,12 @@ async fn hash_directory(directory: Vc) -> Result> { for entry in entries.values() { match entry { DirectoryEntry::File(path) => { - let name = filename(*path).await?; - hashes.insert(name, hash_file(*path).await?.clone_value()); + let name = filename(**path).await?; + hashes.insert(name, hash_file(**path).await?.clone_value()); } DirectoryEntry::Directory(path) => { - let name = filename(*path).await?; - hashes.insert(name, hash_directory(*path).await?.clone_value()); + let name = filename(**path).await?; + hashes.insert(name, hash_directory(**path).await?.clone_value()); } _ => {} } diff --git a/turbopack/crates/turbo-tasks-fs/examples/hash_glob.rs b/turbopack/crates/turbo-tasks-fs/examples/hash_glob.rs index e3c8aa8a693cad..507b56e6210da5 100644 --- a/turbopack/crates/turbo-tasks-fs/examples/hash_glob.rs +++ b/turbopack/crates/turbo-tasks-fs/examples/hash_glob.rs @@ -72,11 +72,11 @@ async fn hash_glob_result(result: Vc) -> Result> { let mut hashes = BTreeMap::new(); for (name, entry) in result.results.iter() { if let DirectoryEntry::File(path) = entry { - hashes.insert(name, hash_file(*path).await?.clone_value()); + hashes.insert(name, hash_file(**path).await?.clone_value()); } } for (name, result) in result.inner.iter() { - let hash = hash_glob_result(*result).await?; + let hash = hash_glob_result(**result).await?; if !hash.is_empty() { hashes.insert(name, hash.clone_value()); } diff --git a/turbopack/crates/turbo-tasks-fs/src/attach.rs b/turbopack/crates/turbo-tasks-fs/src/attach.rs index 7705aad035361a..23c8302c38813f 100644 --- a/turbopack/crates/turbo-tasks-fs/src/attach.rs +++ b/turbopack/crates/turbo-tasks-fs/src/attach.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Result}; use auto_hash_map::AutoMap; -use turbo_tasks::{Completion, RcStr, ValueToString, Vc}; +use turbo_tasks::{Completion, RcStr, ResolvedVc, ValueToString, Vc}; use crate::{ DirectoryContent, DirectoryEntry, FileContent, FileMeta, FileSystem, FileSystemPath, @@ -13,11 +13,11 @@ use crate::{ /// Caveat: The `child_path` itself is not visible as a directory entry. #[turbo_tasks::value] pub struct AttachedFileSystem { - root_fs: Vc>, + root_fs: ResolvedVc>, // we turn this into a string because creating a FileSystemPath requires the filesystem which // we are creating (circular reference) child_path: RcStr, - child_fs: Vc>, + child_fs: ResolvedVc>, } #[turbo_tasks::value_impl] @@ -27,7 +27,7 @@ impl AttachedFileSystem { #[turbo_tasks::function] pub async fn new( child_path: Vc, - child_fs: Vc>, + child_fs: ResolvedVc>, ) -> Result> { let child_path = child_path.await?; @@ -45,11 +45,11 @@ impl AttachedFileSystem { /// [FileSystem] or this [AttachedFileSystem]. #[turbo_tasks::function] pub async fn convert_path( - self: Vc, + self: ResolvedVc, contained_path_vc: Vc, ) -> Result> { let contained_path = contained_path_vc.await?; - let self_fs: Vc> = Vc::upcast(self); + let self_fs: ResolvedVc> = ResolvedVc::upcast(self); let this = self.await?; match contained_path.fs { @@ -89,12 +89,12 @@ impl AttachedFileSystem { /// on the [AttachedFileSystem] #[turbo_tasks::function] pub async fn get_inner_fs_path( - self: Vc, + self: ResolvedVc, path: Vc, ) -> Result> { let this = self.await?; let path = path.await?; - let self_fs: Vc> = Vc::upcast(self); + let self_fs: ResolvedVc> = ResolvedVc::upcast(self); if path.fs != self_fs { let self_fs_str = self_fs.to_string().await?; @@ -144,10 +144,10 @@ impl FileSystem for AttachedFileSystem { use DirectoryEntry::*; let entry = match *entry { - File(path) => File(self.convert_path(path)), - Directory(path) => Directory(self.convert_path(path)), - Symlink(path) => Symlink(self.convert_path(path)), - Other(path) => Other(self.convert_path(path)), + File(path) => File(self.convert_path(*path).to_resolved().await?), + Directory(path) => Directory(self.convert_path(*path).to_resolved().await?), + Symlink(path) => Symlink(self.convert_path(*path).to_resolved().await?), + Other(path) => Other(self.convert_path(*path).to_resolved().await?), Error => Error, }; diff --git a/turbopack/crates/turbo-tasks-fs/src/embed/fs.rs b/turbopack/crates/turbo-tasks-fs/src/embed/fs.rs index 72a43ece95d652..159042797b6eb9 100644 --- a/turbopack/crates/turbo-tasks-fs/src/embed/fs.rs +++ b/turbopack/crates/turbo-tasks-fs/src/embed/fs.rs @@ -1,4 +1,5 @@ use anyhow::{bail, Result}; +use auto_hash_map::AutoMap; use include_dir::{Dir, DirEntry}; use turbo_tasks::{Completion, RcStr, ValueToString, Vc}; @@ -46,29 +47,26 @@ impl FileSystem for EmbeddedFileSystem { (_, None) => return Ok(DirectoryContent::NotFound.cell()), }; - let entries = dir - .entries() - .iter() - .map(|e| { - let entry_name: RcStr = e - .path() - .file_name() - .unwrap_or_default() - .to_string_lossy() - .into(); - let entry_path = path.join(entry_name.clone()); - - ( - entry_name, - match e { - DirEntry::Dir(_) => DirectoryEntry::Directory(entry_path), - DirEntry::File(_) => DirectoryEntry::File(entry_path), - }, - ) - }) - .collect(); - - Ok(DirectoryContent::new(entries)) + let mut converted_entries = AutoMap::new(); + for e in dir.entries() { + let entry_name: RcStr = e + .path() + .file_name() + .unwrap_or_default() + .to_string_lossy() + .into(); + let entry_path = path.join(entry_name.clone()).to_resolved().await?; + + converted_entries.insert( + entry_name, + match e { + DirEntry::Dir(_) => DirectoryEntry::Directory(entry_path), + DirEntry::File(_) => DirectoryEntry::File(entry_path), + }, + ); + } + + Ok(DirectoryContent::new(converted_entries)) } #[turbo_tasks::function] diff --git a/turbopack/crates/turbo-tasks-fs/src/lib.rs b/turbopack/crates/turbo-tasks-fs/src/lib.rs index 611611fc297a93..404f43e62c7929 100644 --- a/turbopack/crates/turbo-tasks-fs/src/lib.rs +++ b/turbopack/crates/turbo-tasks-fs/src/lib.rs @@ -59,7 +59,7 @@ use tokio::{ }; use tracing::Instrument; use turbo_tasks::{ - mark_stateful, trace::TraceRawVcs, Completion, Invalidator, RcStr, ReadRef, + mark_stateful, trace::TraceRawVcs, Completion, Invalidator, RcStr, ReadRef, ResolvedVc, SerializationInvalidator, ValueToString, Vc, }; use turbo_tasks_hash::{ @@ -530,29 +530,29 @@ impl FileSystem for DiskFileSystem { match &*self.read_dir_internal(fs_path).await? { InternalDirectoryContent::NotFound => Ok(DirectoryContent::not_found()), InternalDirectoryContent::Entries(entries) => { - let fs = fs_path.await?.fs; - let entries = entries - .iter() - .map(|(name, entry)| { - let entry = match entry { - InternalDirectoryEntry::File(path) => DirectoryEntry::File( - FileSystemPath::new_normalized(fs, path.clone()), - ), - InternalDirectoryEntry::Directory(path) => DirectoryEntry::Directory( - FileSystemPath::new_normalized(fs, path.clone()), - ), - InternalDirectoryEntry::Symlink(path) => DirectoryEntry::Symlink( - FileSystemPath::new_normalized(fs, path.clone()), - ), - InternalDirectoryEntry::Other(path) => DirectoryEntry::Other( - FileSystemPath::new_normalized(fs, path.clone()), - ), - InternalDirectoryEntry::Error => DirectoryEntry::Error, - }; - (name.clone(), entry) - }) - .collect(); - Ok(DirectoryContent::new(entries)) + let fs = *fs_path.await?.fs; + let normalize = + |path: &RcStr| FileSystemPath::new_normalized(fs, path.clone()).to_resolved(); + let mut normalized_entries = AutoMap::new(); + for (name, entry) in entries { + let entry = match entry { + InternalDirectoryEntry::File(path) => { + DirectoryEntry::File(normalize(path).await?) + } + InternalDirectoryEntry::Directory(path) => { + DirectoryEntry::Directory(normalize(path).await?) + } + InternalDirectoryEntry::Symlink(path) => { + DirectoryEntry::Symlink(normalize(path).await?) + } + InternalDirectoryEntry::Other(path) => { + DirectoryEntry::Other(normalize(path).await?) + } + InternalDirectoryEntry::Error => DirectoryEntry::Error, + }; + normalized_entries.insert(name.clone(), entry); + } + Ok(DirectoryContent::new(normalized_entries)) } } } @@ -881,7 +881,7 @@ impl ValueToString for DiskFileSystem { #[turbo_tasks::value] #[derive(Debug, Clone)] pub struct FileSystemPath { - pub fs: Vc>, + pub fs: ResolvedVc>, pub path: RcStr, } @@ -1085,7 +1085,7 @@ impl FileSystemPath { } #[turbo_tasks::value(transparent)] -pub struct FileSystemPathOption(Option>); +pub struct FileSystemPathOption(Option>); #[turbo_tasks::value_impl] impl FileSystemPathOption { @@ -1101,7 +1101,7 @@ impl FileSystemPath { /// /-separated path is expected to be already normalized (this is asserted /// in dev mode). #[turbo_tasks::function] - fn new_normalized(fs: Vc>, path: RcStr) -> Vc { + fn new_normalized(fs: ResolvedVc>, path: RcStr) -> Vc { // On Windows, the path must be converted to a unix path before creating. But on // Unix, backslashes are a valid char in file names, and the path can be // provided by the user, so we allow it. @@ -1125,7 +1125,7 @@ impl FileSystemPath { pub async fn join(self: Vc, path: RcStr) -> Result> { let this = self.await?; if let Some(path) = join_path(&this.path, &path) { - Ok(Self::new_normalized(this.fs, path.into())) + Ok(Self::new_normalized(*this.fs, path.into())) } else { bail!( "Vc(\"{}\").join(\"{}\") leaves the filesystem root", @@ -1147,7 +1147,7 @@ impl FileSystemPath { ) } Ok(Self::new_normalized( - this.fs, + *this.fs, format!("{}{}", this.path, path).into(), )) } @@ -1166,12 +1166,12 @@ impl FileSystemPath { } if let (path, Some(ext)) = this.split_extension() { return Ok(Self::new_normalized( - this.fs, + *this.fs, format!("{}{}.{}", path, appending, ext).into(), )); } Ok(Self::new_normalized( - this.fs, + *this.fs, format!("{}{}", this.path, appending).into(), )) } @@ -1182,7 +1182,9 @@ impl FileSystemPath { pub async fn try_join(&self, path: RcStr) -> Result> { if let Some(path) = join_path(&self.path, &path) { Ok(Vc::cell(Some( - Self::new_normalized(self.fs, path.into()).resolve().await?, + Self::new_normalized(*self.fs, path.into()) + .to_resolved() + .await?, ))) } else { Ok(FileSystemPathOption::none()) @@ -1196,7 +1198,9 @@ impl FileSystemPath { if let Some(path) = join_path(&self.path, &path) { if path.starts_with(&*self.path) { return Ok(Vc::cell(Some( - Self::new_normalized(self.fs, path.into()).resolve().await?, + Self::new_normalized(*self.fs, path.into()) + .to_resolved() + .await?, ))); } } @@ -1219,7 +1223,7 @@ impl FileSystemPath { #[turbo_tasks::function] pub fn fs(&self) -> Vc> { - self.fs + *self.fs } #[turbo_tasks::function] @@ -1243,7 +1247,7 @@ impl FileSystemPath { pub async fn with_extension(&self, extension: RcStr) -> Vc { let (path_without_extension, _) = self.split_extension(); Self::new_normalized( - self.fs, + *self.fs, // Like `Path::with_extension` and `PathBuf::set_extension`, if the extension is empty, // we remove the extension altogether. match extension.is_empty() { @@ -1392,7 +1396,7 @@ impl FileSystemPath { Some(index) => path[..index].to_string(), None => "".to_string(), }; - Ok(FileSystemPath::new_normalized(this.fs, p.into())) + Ok(FileSystemPath::new_normalized(*this.fs, p.into())) } #[turbo_tasks::function] @@ -1427,7 +1431,7 @@ impl FileSystemPath { } #[turbo_tasks::function] - pub async fn realpath_with_links(self: Vc) -> Result> { + pub async fn realpath_with_links(self: ResolvedVc) -> Result> { let this = self.await?; if this.is_root() { return Ok(RealPathResult { @@ -1436,14 +1440,18 @@ impl FileSystemPath { } .cell()); } - let parent = self.parent().resolve().await?; + let parent = self.parent().to_resolved().await?; let parent_result = parent.realpath_with_links().await?; let basename = this .path .rsplit_once('/') .map_or(this.path.as_str(), |(_, name)| name); let real_self = if parent_result.path != parent { - parent_result.path.join(basename.into()).resolve().await? + parent_result + .path + .join(basename.into()) + .to_resolved() + .await? } else { self }; @@ -1452,12 +1460,12 @@ impl FileSystemPath { if let LinkContent::Link { target, link_type } = &*real_self.read_link().await? { result.symlinks.push(real_self); result.path = if link_type.contains(LinkType::ABSOLUTE) { - real_self.root().resolve().await? + real_self.root().to_resolved().await? } else { result.path } .join(target.clone()) - .resolve() + .to_resolved() .await?; return Ok(result.cell()); } @@ -1480,15 +1488,15 @@ impl ValueToString for FileSystemPath { #[derive(Clone, Debug)] #[turbo_tasks::value(shared)] pub struct RealPathResult { - pub path: Vc, - pub symlinks: Vec>, + pub path: ResolvedVc, + pub symlinks: Vec>, } #[turbo_tasks::value_impl] impl RealPathResult { #[turbo_tasks::function] pub fn path(&self) -> Vc { - self.path + *self.path } } @@ -2080,10 +2088,10 @@ pub enum InternalDirectoryEntry { #[derive(Hash, Clone, Copy, Debug, PartialEq, Eq, TraceRawVcs, Serialize, Deserialize)] pub enum DirectoryEntry { - File(Vc), - Directory(Vc), - Symlink(Vc), - Other(Vc), + File(ResolvedVc), + Directory(ResolvedVc), + Symlink(ResolvedVc), + Other(ResolvedVc), Error, } @@ -2093,7 +2101,7 @@ pub enum DirectoryEntry { impl DirectoryEntry { pub async fn resolve_symlink(self) -> Result { if let DirectoryEntry::Symlink(symlink) = self { - let real_path = symlink.realpath().resolve().await?; + let real_path = symlink.realpath().to_resolved().await?; match *real_path.get_type().await? { FileSystemEntryType::Directory => Ok(DirectoryEntry::Directory(real_path)), FileSystemEntryType::File => Ok(DirectoryEntry::File(real_path)), diff --git a/turbopack/crates/turbo-tasks-fs/src/read_glob.rs b/turbopack/crates/turbo-tasks-fs/src/read_glob.rs index 69d1dbc2afd694..d5a88996ce2c26 100644 --- a/turbopack/crates/turbo-tasks-fs/src/read_glob.rs +++ b/turbopack/crates/turbo-tasks-fs/src/read_glob.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use anyhow::Result; -use turbo_tasks::{RcStr, Vc}; +use turbo_tasks::{RcStr, ResolvedVc, Vc}; use crate::{glob::Glob, DirectoryContent, DirectoryEntry, FileSystemPath}; @@ -9,7 +9,7 @@ use crate::{glob::Glob, DirectoryContent, DirectoryEntry, FileSystemPath}; #[derive(Default, Debug)] pub struct ReadGlobResult { pub results: HashMap, - pub inner: HashMap>, + pub inner: HashMap>, } /// Reads matches of a glob pattern. @@ -22,7 +22,7 @@ pub async fn read_glob( glob: Vc, include_dot_files: bool, ) -> Result> { - read_glob_internal("", directory, glob, include_dot_files).await + Ok(*read_glob_internal("", directory, glob, include_dot_files).await?) } #[turbo_tasks::function(fs)] @@ -32,7 +32,7 @@ async fn read_glob_inner( glob: Vc, include_dot_files: bool, ) -> Result> { - read_glob_internal(&prefix, directory, glob, include_dot_files).await + Ok(*read_glob_internal(&prefix, directory, glob, include_dot_files).await?) } async fn read_glob_internal( @@ -40,7 +40,7 @@ async fn read_glob_internal( directory: Vc, glob: Vc, include_dot_files: bool, -) -> Result> { +) -> Result> { let dir = directory.read_dir().await?; let mut result = ReadGlobResult::default(); let glob_value = glob.await?; @@ -63,7 +63,9 @@ async fn read_glob_internal( if glob_value.execute(&full_path_prefix) { result.inner.insert( full_path, - read_glob_inner(full_path_prefix, path, glob, include_dot_files), + read_glob_inner(full_path_prefix, *path, glob, include_dot_files) + .to_resolved() + .await?, ); } } @@ -78,5 +80,5 @@ async fn read_glob_internal( } DirectoryContent::NotFound => {} } - Ok(ReadGlobResult::cell(result)) + Ok(ReadGlobResult::resolved_cell(result)) } diff --git a/turbopack/crates/turbopack-core/src/chunk/optimize.rs b/turbopack/crates/turbopack-core/src/chunk/optimize.rs index d216b25174bb0d..bea7a542ce426e 100644 --- a/turbopack/crates/turbopack-core/src/chunk/optimize.rs +++ b/turbopack/crates/turbopack-core/src/chunk/optimize.rs @@ -45,7 +45,7 @@ where Ok(( if let Some(common_parent) = &*common_parent { - Some(FileSystemPathKey::new(*common_parent).await?) + Some(FileSystemPathKey::new(**common_parent).await?) } else { None }, diff --git a/turbopack/crates/turbopack-core/src/resolve/mod.rs b/turbopack/crates/turbopack-core/src/resolve/mod.rs index fa9ad1e0cb1476..fc1c7d8d5f12ba 100644 --- a/turbopack/crates/turbopack-core/src/resolve/mod.rs +++ b/turbopack/crates/turbopack-core/src/resolve/mod.rs @@ -1010,7 +1010,7 @@ async fn type_exists( ) -> Result>> { let result = fs_path.resolve().await?.realpath_with_links().await?; for path in result.symlinks.iter() { - refs.push(Vc::upcast(FileSource::new(*path))); + refs.push(Vc::upcast(FileSource::new(**path))); } let path = result.path.resolve().await?; Ok(if *path.get_type().await? == ty { @@ -1026,7 +1026,7 @@ async fn any_exists( ) -> Result)>> { let result = fs_path.resolve().await?.realpath_with_links().await?; for path in result.symlinks.iter() { - refs.push(Vc::upcast(FileSource::new(*path))); + refs.push(Vc::upcast(FileSource::new(**path))); } let path = result.path.resolve().await?; let ty = *path.get_type().await?; @@ -1334,10 +1334,10 @@ pub async fn resolve_raw( let RealPathResult { path, symlinks } = &*path.realpath_with_links().await?; Ok(ResolveResult::source_with_affecting_sources( RequestKey::new(request.into()), - Vc::upcast(FileSource::new(*path)), + Vc::upcast(FileSource::new(**path)), symlinks .iter() - .copied() + .map(|symlink| **symlink) .map(FileSource::new) .map(Vc::upcast) .collect(), @@ -2583,7 +2583,7 @@ async fn resolved( if let Some(resolved_map) = options_value.resolved_map { let result = resolved_map - .lookup(*path, original_context, original_request) + .lookup(**path, original_context, original_request) .await?; let resolved_result = resolve_import_map_result( @@ -2603,10 +2603,10 @@ async fn resolved( Ok(ResolveResult::source_with_affecting_sources( request_key, - Vc::upcast(FileSource::new_with_query(*path, query)), + Vc::upcast(FileSource::new_with_query(**path, query)), symlinks .iter() - .copied() + .map(|symlink| **symlink) .map(FileSource::new) .map(Vc::upcast) .collect(), diff --git a/turbopack/crates/turbopack-core/src/resolve/pattern.rs b/turbopack/crates/turbopack-core/src/resolve/pattern.rs index b0802bc504a8cd..df2b4623dd448e 100644 --- a/turbopack/crates/turbopack-core/src/resolve/pattern.rs +++ b/turbopack/crates/turbopack-core/src/resolve/pattern.rs @@ -1512,7 +1512,7 @@ pub async fn read_matches( if let Some(pos) = pat.match_position(&prefix) { results.push(( pos, - PatternMatch::File(prefix.clone().into(), *path), + PatternMatch::File(prefix.clone().into(), **path), )); } prefix.truncate(len) @@ -1527,7 +1527,7 @@ pub async fn read_matches( if let Some(pos) = pat.match_position(&prefix) { results.push(( pos, - PatternMatch::Directory(prefix.clone().into(), *path), + PatternMatch::Directory(prefix.clone().into(), **path), )); } prefix.push('/'); @@ -1535,13 +1535,13 @@ pub async fn read_matches( if let Some(pos) = pat.match_position(&prefix) { results.push(( pos, - PatternMatch::Directory(prefix.clone().into(), *path), + PatternMatch::Directory(prefix.clone().into(), **path), )); } if let Some(pos) = pat.could_match_position(&prefix) { nested.push(( pos, - read_matches(*path, prefix.clone().into(), true, pattern), + read_matches(**path, prefix.clone().into(), true, pattern), )); } prefix.truncate(len) @@ -1562,13 +1562,16 @@ pub async fn read_matches( pos, PatternMatch::Directory( prefix.clone().into(), - *fs_path, + **fs_path, ), )); } else { results.push(( pos, - PatternMatch::File(prefix.clone().into(), *fs_path), + PatternMatch::File( + prefix.clone().into(), + **fs_path, + ), )); } } @@ -1583,7 +1586,7 @@ pub async fn read_matches( pos, PatternMatch::Directory( prefix.clone().into(), - *fs_path, + **fs_path, ), )); } @@ -1598,7 +1601,7 @@ pub async fn read_matches( pos, PatternMatch::Directory( prefix.clone().into(), - *fs_path, + **fs_path, ), )); } diff --git a/turbopack/crates/turbopack-dev-server/src/source/static_assets.rs b/turbopack/crates/turbopack-dev-server/src/source/static_assets.rs index dc8ef38e3984fd..8e113c1e3d198b 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/static_assets.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/static_assets.rs @@ -56,11 +56,11 @@ async fn get_routes_from_directory(dir: Vc) -> Result Some( - get_routes_from_directory(*path) + get_routes_from_directory(**path) .with_prepended_base(vec![BaseSegment::Static(name.clone())]), ), _ => None, @@ -121,12 +121,12 @@ impl Introspectable for StaticAssetsContentSource { .map(|(name, entry)| { let child = match entry { DirectoryEntry::File(path) | DirectoryEntry::Symlink(path) => { - IntrospectableSource::new(Vc::upcast(FileSource::new(*path))) + IntrospectableSource::new(Vc::upcast(FileSource::new(**path))) } DirectoryEntry::Directory(path) => { Vc::upcast(StaticAssetsContentSource::with_prefix( Vc::cell(format!("{}{name}/", &*prefix).into()), - *path, + **path, )) } DirectoryEntry::Other(_) => todo!("what's DirectoryContent::Other?"), diff --git a/turbopack/crates/turbopack-ecmascript/src/references/node.rs b/turbopack/crates/turbopack-ecmascript/src/references/node.rs index 49c78c2b28ef40..820b121a306104 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/node.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/node.rs @@ -122,11 +122,11 @@ async fn resolve_reference_from_dir( PatternMatch::File(matched_path, file) => { let realpath = file.realpath_with_links().await?; for &symlink in &realpath.symlinks { - affecting_sources.push(Vc::upcast(FileSource::new(symlink))); + affecting_sources.push(Vc::upcast(FileSource::new(*symlink))); } results.push(( RequestKey::new(matched_path.clone()), - Vc::upcast(RawModule::new(Vc::upcast(FileSource::new(realpath.path)))), + Vc::upcast(RawModule::new(Vc::upcast(FileSource::new(*realpath.path)))), )); } PatternMatch::Directory(..) => {} diff --git a/turbopack/crates/turbopack-ecmascript/src/references/require_context.rs b/turbopack/crates/turbopack-ecmascript/src/references/require_context.rs index 24f1beb39a3589..6a096b422800cd 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/require_context.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/require_context.rs @@ -84,7 +84,7 @@ impl DirList { DirectoryEntry::File(path) => { if let Some(relative_path) = root_val.get_relative_path_to(&*path.await?) { if regex.is_match(&relative_path) { - list.insert(relative_path, DirListEntry::File(*path)); + list.insert(relative_path, DirListEntry::File(**path)); } } } @@ -93,7 +93,7 @@ impl DirList { list.insert( relative_path, DirListEntry::Dir(DirList::read_internal( - root, *path, recursive, filter, + root, **path, recursive, filter, )), ); } diff --git a/turbopack/crates/turbopack-ecmascript/src/references/typescript.rs b/turbopack/crates/turbopack-ecmascript/src/references/typescript.rs index b6347fc845a8e3..b2442a03a10056 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/typescript.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/typescript.rs @@ -80,7 +80,7 @@ impl ModuleReference for TsReferencePathAssetReference { .origin .asset_context() .process( - Vc::upcast(FileSource::new(*path)), + Vc::upcast(FileSource::new(**path)), Value::new(ReferenceType::TypeScript( TypeScriptReferenceSubType::Undefined, )), diff --git a/turbopack/crates/turbopack-node/src/transforms/webpack.rs b/turbopack/crates/turbopack-node/src/transforms/webpack.rs index 5460599d78927d..ebd1fce574d80e 100644 --- a/turbopack/crates/turbopack-node/src/transforms/webpack.rs +++ b/turbopack/crates/turbopack-node/src/transforms/webpack.rs @@ -704,7 +704,7 @@ async fn dir_dependency(glob: Vc) -> Result> { let glob = glob.await?; glob.inner .values() - .map(|&inner| dir_dependency(inner)) + .map(|&inner| dir_dependency(*inner)) .try_join() .await?; shallow.await?; diff --git a/turbopack/crates/turbopack-resolve/src/node_native_binding.rs b/turbopack/crates/turbopack-resolve/src/node_native_binding.rs index 8216a9da9743da..827eda87a6e981 100644 --- a/turbopack/crates/turbopack-resolve/src/node_native_binding.rs +++ b/turbopack/crates/turbopack-resolve/src/node_native_binding.rs @@ -150,7 +150,7 @@ pub async fn resolve_node_pre_gyp_files( { sources.insert( format!("{native_binding_path}/{key}").into(), - Vc::upcast(FileSource::new(dylib)), + Vc::upcast(FileSource::new(*dylib)), ); } } @@ -179,17 +179,17 @@ pub async fn resolve_node_pre_gyp_files( DirectoryEntry::File(dylib) => { sources.insert( format!("deps/lib/{key}").into(), - Vc::upcast(FileSource::new(dylib)), + Vc::upcast(FileSource::new(*dylib)), ); } DirectoryEntry::Symlink(dylib) => { let realpath_with_links = dylib.realpath_with_links().await?; for &symlink in realpath_with_links.symlinks.iter() { - affecting_paths.push(symlink); + affecting_paths.push(*symlink); } sources.insert( format!("deps/lib/{key}").into(), - Vc::upcast(FileSource::new(realpath_with_links.path)), + Vc::upcast(FileSource::new(*realpath_with_links.path)), ); } _ => {} diff --git a/turbopack/crates/turbopack-resolve/src/typescript.rs b/turbopack/crates/turbopack-resolve/src/typescript.rs index ee5f27517bc590..a46faf46619337 100644 --- a/turbopack/crates/turbopack-resolve/src/typescript.rs +++ b/turbopack/crates/turbopack-resolve/src/typescript.rs @@ -269,7 +269,7 @@ pub async fn tsconfig_resolve_options( let mut context_dir = source.ident().path().parent(); if let Some(base_url) = json["compilerOptions"]["baseUrl"].as_str() { if let Some(new_context) = *context_dir.try_join(base_url.into()).await? { - context_dir = new_context; + context_dir = *new_context; } }; for (key, value) in paths.iter() { @@ -336,7 +336,7 @@ pub async fn tsconfig_resolve_options( .unwrap_or_default(); Ok(TsConfigResolveOptions { - base_url, + base_url: base_url.as_deref().copied(), import_map, is_module_resolution_nodenext, } diff --git a/turbopack/crates/turbopack-test-utils/src/snapshot.rs b/turbopack/crates/turbopack-test-utils/src/snapshot.rs index c8d34ef86b2f06..2c73d5bd7e53f6 100644 --- a/turbopack/crates/turbopack-test-utils/src/snapshot.rs +++ b/turbopack/crates/turbopack-test-utils/src/snapshot.rs @@ -91,7 +91,7 @@ pub async fn expected(dir: Vc) -> Result { - expected.insert(*file); + expected.insert(**file); } _ => bail!( "expected file at {}, found {:?}",