Unverified Commit e22f3f80 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

Add a new `fs` method to track a glob. (#78686)

This will ensure that the caller is invalidated whenever any directory or file matching the glob changes.

Happy for feedback on the name!

In addition to creating this fast path for the webpack.rs loader, also optimize the way paths are constructed in `read_dir` to use `new_normalized` instead of `join`.  This allows us to skip some cpu intensive string manipulation that is unneeded when composing paths returned from a `readdir` operation.

Before:

![before.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/AwJ29EfoPcPdLSwCZxAz/6e0ce683-da94-40ad-aeec-99e381d8dc26.png)

We can see the `read_glob` and `dir_dependency` calls which happened sequentially.

After:

![after.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/AwJ29EfoPcPdLSwCZxAz/988ed4ca-78a4-4849-b070-445981f018de.png)

We can see the same time spent in `read file` but we have saved a lot of time in `FileSystemPath::join` (eliminated!) and we eliminated the redundant traversal of `dir_dependency`.
parent 9b44e3e3
...@@ -9549,6 +9549,7 @@ dependencies = [ ...@@ -9549,6 +9549,7 @@ dependencies = [
"triomphe 0.1.12", "triomphe 0.1.12",
"turbo-rcstr", "turbo-rcstr",
"turbo-tasks", "turbo-tasks",
"turbo-tasks-backend",
"turbo-tasks-build", "turbo-tasks-build",
"turbo-tasks-hash", "turbo-tasks-hash",
"turbo-tasks-memory", "turbo-tasks-memory",
......
...@@ -63,6 +63,7 @@ sha2 = "0.10.2" ...@@ -63,6 +63,7 @@ sha2 = "0.10.2"
tempfile = { workspace = true } tempfile = { workspace = true }
turbo-tasks-memory = { workspace = true } turbo-tasks-memory = { workspace = true }
turbo-tasks-testing = { workspace = true } turbo-tasks-testing = { workspace = true }
turbo-tasks-backend = { workspace = true }
[build-dependencies] [build-dependencies]
turbo-tasks-build = { workspace = true } turbo-tasks-build = { workspace = true }
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{Completion, ResolvedVc, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use crate::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent}; use crate::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent};
...@@ -133,11 +133,6 @@ impl FileSystem for AttachedFileSystem { ...@@ -133,11 +133,6 @@ impl FileSystem for AttachedFileSystem {
self.get_inner_fs_path(path).raw_read_dir() self.get_inner_fs_path(path).raw_read_dir()
} }
#[turbo_tasks::function(fs)]
fn track(self: Vc<Self>, path: Vc<FileSystemPath>) -> Vc<Completion> {
self.get_inner_fs_path(path).track()
}
#[turbo_tasks::function(fs)] #[turbo_tasks::function(fs)]
fn write(self: Vc<Self>, path: Vc<FileSystemPath>, content: Vc<FileContent>) -> Vc<()> { fn write(self: Vc<Self>, path: Vc<FileSystemPath>, content: Vc<FileContent>) -> Vc<()> {
self.get_inner_fs_path(path).write(content) self.get_inner_fs_path(path).write(content)
......
...@@ -2,7 +2,7 @@ use anyhow::{bail, Result}; ...@@ -2,7 +2,7 @@ use anyhow::{bail, Result};
use auto_hash_map::AutoMap; use auto_hash_map::AutoMap;
use include_dir::{Dir, DirEntry}; use include_dir::{Dir, DirEntry};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{Completion, ValueToString, Vc}; use turbo_tasks::{ValueToString, Vc};
use crate::{ use crate::{
File, FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent, File, FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent,
...@@ -69,11 +69,6 @@ impl FileSystem for EmbeddedFileSystem { ...@@ -69,11 +69,6 @@ impl FileSystem for EmbeddedFileSystem {
Ok(RawDirectoryContent::new(converted_entries)) Ok(RawDirectoryContent::new(converted_entries))
} }
#[turbo_tasks::function]
fn track(&self, _path: Vc<FileSystemPath>) -> Vc<Completion> {
Completion::immutable()
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn write(&self, _path: Vc<FileSystemPath>, _content: Vc<FileContent>) -> Result<Vc<()>> { fn write(&self, _path: Vc<FileSystemPath>, _content: Vc<FileContent>) -> Result<Vc<()>> {
bail!("Writing is not possible to the embedded filesystem") bail!("Writing is not possible to the embedded filesystem")
......
...@@ -50,21 +50,33 @@ pub struct Glob { ...@@ -50,21 +50,33 @@ pub struct Glob {
impl Glob { impl Glob {
pub fn execute(&self, path: &str) -> bool { pub fn execute(&self, path: &str) -> bool {
// TODO(lukesandberg): deprecate this implicit behavior
let match_partial = path.ends_with('/'); let match_partial = path.ends_with('/');
self.iter_matches(path, true, match_partial) self.iter_matches(path, true, match_partial)
.any(|result| matches!(result, ("", _))) .any(|result| matches!(result, ("", _)))
} }
// Returns true if the glob could match a filename underneath this `path` where the path
// represents a directory.
pub fn match_in_directory(&self, path: &str) -> bool {
debug_assert!(!path.ends_with('/'));
// TODO(lukesandberg): see if we can avoid this allocation by changing the matching
// algorithm
let path = format!("{path}/");
self.iter_matches(&path, true, true)
.any(|result| matches!(result, ("", _)))
}
fn iter_matches<'a>( fn iter_matches<'a>(
&'a self, &'a self,
path: &'a str, path: &'a str,
previous_part_is_path_separator_equivalent: bool, previous_part_is_path_separator_equivalent: bool,
match_partial: bool, match_in_directory: bool,
) -> GlobMatchesIterator<'a> { ) -> GlobMatchesIterator<'a> {
GlobMatchesIterator { GlobMatchesIterator {
current: path, current: path,
glob: self, glob: self,
match_partial, match_in_directory,
is_path_separator_equivalent: previous_part_is_path_separator_equivalent, is_path_separator_equivalent: previous_part_is_path_separator_equivalent,
stack: Vec::new(), stack: Vec::new(),
index: 0, index: 0,
...@@ -89,7 +101,9 @@ impl Glob { ...@@ -89,7 +101,9 @@ impl Glob {
struct GlobMatchesIterator<'a> { struct GlobMatchesIterator<'a> {
current: &'a str, current: &'a str,
glob: &'a Glob, glob: &'a Glob,
match_partial: bool, // In this mode we are checking if the glob might match something in the directory represented
// by this path.
match_in_directory: bool,
is_path_separator_equivalent: bool, is_path_separator_equivalent: bool,
stack: Vec<GlobPartMatchesIterator<'a>>, stack: Vec<GlobPartMatchesIterator<'a>>,
index: usize, index: usize,
...@@ -107,7 +121,7 @@ impl<'a> Iterator for GlobMatchesIterator<'a> { ...@@ -107,7 +121,7 @@ impl<'a> Iterator for GlobMatchesIterator<'a> {
let iter = part.iter_matches( let iter = part.iter_matches(
self.current, self.current,
self.is_path_separator_equivalent, self.is_path_separator_equivalent,
self.match_partial, self.match_in_directory,
); );
self.stack.push(iter); self.stack.push(iter);
self.stack.last_mut().unwrap() self.stack.last_mut().unwrap()
...@@ -118,7 +132,7 @@ impl<'a> Iterator for GlobMatchesIterator<'a> { ...@@ -118,7 +132,7 @@ impl<'a> Iterator for GlobMatchesIterator<'a> {
self.index += 1; self.index += 1;
if self.match_partial && self.current.is_empty() { if self.match_in_directory && self.current.is_empty() {
return Some(("", self.is_path_separator_equivalent)); return Some(("", self.is_path_separator_equivalent));
} }
} else { } else {
...@@ -152,12 +166,12 @@ impl GlobPart { ...@@ -152,12 +166,12 @@ impl GlobPart {
&'a self, &'a self,
path: &'a str, path: &'a str,
previous_part_is_path_separator_equivalent: bool, previous_part_is_path_separator_equivalent: bool,
match_partial: bool, match_in_directory: bool,
) -> GlobPartMatchesIterator<'a> { ) -> GlobPartMatchesIterator<'a> {
GlobPartMatchesIterator { GlobPartMatchesIterator {
path, path,
part: self, part: self,
match_partial, match_in_directory,
previous_part_is_path_separator_equivalent, previous_part_is_path_separator_equivalent,
cursor: GraphemeCursor::new(0, path.len(), true), cursor: GraphemeCursor::new(0, path.len(), true),
index: 0, index: 0,
...@@ -256,7 +270,7 @@ impl GlobPart { ...@@ -256,7 +270,7 @@ impl GlobPart {
struct GlobPartMatchesIterator<'a> { struct GlobPartMatchesIterator<'a> {
path: &'a str, path: &'a str,
part: &'a GlobPart, part: &'a GlobPart,
match_partial: bool, match_in_directory: bool,
previous_part_is_path_separator_equivalent: bool, previous_part_is_path_separator_equivalent: bool,
cursor: GraphemeCursor, cursor: GraphemeCursor,
index: usize, index: usize,
...@@ -375,7 +389,7 @@ impl<'a> Iterator for GlobPartMatchesIterator<'a> { ...@@ -375,7 +389,7 @@ impl<'a> Iterator for GlobPartMatchesIterator<'a> {
self.glob_iterator = Some(Box::new(alternative.iter_matches( self.glob_iterator = Some(Box::new(alternative.iter_matches(
self.path, self.path,
self.previous_part_is_path_separator_equivalent, self.previous_part_is_path_separator_equivalent,
self.match_partial, self.match_in_directory,
))); )));
} else { } else {
return None; return None;
......
...@@ -46,8 +46,8 @@ use invalidator_map::InvalidatorMap; ...@@ -46,8 +46,8 @@ use invalidator_map::InvalidatorMap;
use jsonc_parser::{parse_to_serde_value, ParseOptions}; use jsonc_parser::{parse_to_serde_value, ParseOptions};
use mime::Mime; use mime::Mime;
use rayon::iter::{IntoParallelIterator, ParallelIterator}; use rayon::iter::{IntoParallelIterator, ParallelIterator};
use read_glob::read_glob;
pub use read_glob::ReadGlobResult; pub use read_glob::ReadGlobResult;
use read_glob::{read_glob, track_glob};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use tokio::{ use tokio::{
...@@ -203,7 +203,6 @@ pub trait FileSystem: ValueToString { ...@@ -203,7 +203,6 @@ pub trait FileSystem: ValueToString {
fn read(self: Vc<Self>, fs_path: Vc<FileSystemPath>) -> Vc<FileContent>; fn read(self: Vc<Self>, fs_path: Vc<FileSystemPath>) -> Vc<FileContent>;
fn read_link(self: Vc<Self>, fs_path: Vc<FileSystemPath>) -> Vc<LinkContent>; fn read_link(self: Vc<Self>, fs_path: Vc<FileSystemPath>) -> Vc<LinkContent>;
fn raw_read_dir(self: Vc<Self>, fs_path: Vc<FileSystemPath>) -> Vc<RawDirectoryContent>; fn raw_read_dir(self: Vc<Self>, fs_path: Vc<FileSystemPath>) -> Vc<RawDirectoryContent>;
fn track(self: Vc<Self>, fs_path: Vc<FileSystemPath>) -> Vc<Completion>;
fn write(self: Vc<Self>, fs_path: Vc<FileSystemPath>, content: Vc<FileContent>) -> Vc<()>; fn write(self: Vc<Self>, fs_path: Vc<FileSystemPath>, content: Vc<FileContent>) -> Vc<()>;
fn write_link(self: Vc<Self>, fs_path: Vc<FileSystemPath>, target: Vc<LinkContent>) -> Vc<()>; fn write_link(self: Vc<Self>, fs_path: Vc<FileSystemPath>, target: Vc<LinkContent>) -> Vc<()>;
fn metadata(self: Vc<Self>, fs_path: Vc<FileSystemPath>) -> Vc<FileMeta>; fn metadata(self: Vc<Self>, fs_path: Vc<FileSystemPath>) -> Vc<FileMeta>;
...@@ -686,14 +685,6 @@ impl FileSystem for DiskFileSystem { ...@@ -686,14 +685,6 @@ impl FileSystem for DiskFileSystem {
.cell()) .cell())
} }
#[turbo_tasks::function(fs)]
async fn track(&self, fs_path: Vc<FileSystemPath>) -> Result<Vc<Completion>> {
mark_session_dependent();
let full_path = self.to_sys_path(fs_path).await?;
self.inner.register_read_invalidator(&full_path)?;
Ok(Completion::new())
}
#[turbo_tasks::function(fs)] #[turbo_tasks::function(fs)]
async fn write(&self, fs_path: Vc<FileSystemPath>, content: Vc<FileContent>) -> Result<()> { async fn write(&self, fs_path: Vc<FileSystemPath>, content: Vc<FileContent>) -> Result<()> {
mark_session_dependent(); mark_session_dependent();
...@@ -1328,6 +1319,13 @@ impl FileSystemPath { ...@@ -1328,6 +1319,13 @@ impl FileSystemPath {
read_glob(self, glob, include_dot_files) read_glob(self, glob, include_dot_files)
} }
// Tracks all files and directories matching the glob
// Follows symlinks as though they were part of the original hierarchy.
#[turbo_tasks::function]
pub fn track_glob(self: Vc<Self>, glob: Vc<Glob>, include_dot_files: bool) -> Vc<Completion> {
track_glob(self, glob, include_dot_files)
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn root(self: Vc<Self>) -> Vc<Self> { pub fn root(self: Vc<Self>) -> Vc<Self> {
self.fs().root() self.fs().root()
...@@ -1466,10 +1464,6 @@ impl FileSystemPath { ...@@ -1466,10 +1464,6 @@ impl FileSystemPath {
self.fs().raw_read_dir(self) self.fs().raw_read_dir(self)
} }
pub fn track(self: Vc<Self>) -> Vc<Completion> {
self.fs().track(self)
}
pub fn write(self: Vc<Self>, content: Vc<FileContent>) -> Vc<()> { pub fn write(self: Vc<Self>, content: Vc<FileContent>) -> Vc<()> {
self.fs().write(self, content) self.fs().write(self, content)
} }
...@@ -1503,24 +1497,29 @@ impl FileSystemPath { ...@@ -1503,24 +1497,29 @@ impl FileSystemPath {
/// depend on the order. /// depend on the order.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn read_dir(self: Vc<Self>) -> Result<Vc<DirectoryContent>> { pub async fn read_dir(self: Vc<Self>) -> Result<Vc<DirectoryContent>> {
match &*self.await?.fs.raw_read_dir(self).await? { let this = self.await?;
let fs = this.fs;
match &*fs.raw_read_dir(self).await? {
RawDirectoryContent::NotFound => Ok(DirectoryContent::not_found()), RawDirectoryContent::NotFound => Ok(DirectoryContent::not_found()),
RawDirectoryContent::Entries(entries) => { RawDirectoryContent::Entries(entries) => {
let mut normalized_entries = AutoMap::new(); let mut normalized_entries = AutoMap::new();
let dir_path = &this.path;
for (name, entry) in entries { for (name, entry) in entries {
// Construct the path directly instead of going through `join`.
// We do not need to normalize since the `name` is guaranteed to be a simple
// path segment.
let path = if dir_path.is_empty() {
name.clone()
} else {
RcStr::from(format!("{dir_path}/{name}"))
};
let entry_path = Self::new_normalized(*fs, path).to_resolved().await?;
let entry = match entry { let entry = match entry {
RawDirectoryEntry::File => { RawDirectoryEntry::File => DirectoryEntry::File(entry_path),
DirectoryEntry::File(self.join(name.clone()).to_resolved().await?) RawDirectoryEntry::Directory => DirectoryEntry::Directory(entry_path),
} RawDirectoryEntry::Symlink => DirectoryEntry::Symlink(entry_path),
RawDirectoryEntry::Directory => { RawDirectoryEntry::Other => DirectoryEntry::Other(entry_path),
DirectoryEntry::Directory(self.join(name.clone()).to_resolved().await?)
}
RawDirectoryEntry::Symlink => {
DirectoryEntry::Symlink(self.join(name.clone()).to_resolved().await?)
}
RawDirectoryEntry::Other => {
DirectoryEntry::Other(self.join(name.clone()).to_resolved().await?)
}
RawDirectoryEntry::Error => DirectoryEntry::Error, RawDirectoryEntry::Error => DirectoryEntry::Error,
}; };
normalized_entries.insert(name.clone(), entry); normalized_entries.insert(name.clone(), entry);
...@@ -2305,10 +2304,10 @@ pub enum DirectoryEntry { ...@@ -2305,10 +2304,10 @@ pub enum DirectoryEntry {
Error, Error,
} }
/// Handles the `DirectoryEntry::Symlink` variant by checking the symlink target
/// type and replacing it with `DirectoryEntry::File` or
/// `DirectoryEntry::Directory`.
impl DirectoryEntry { impl DirectoryEntry {
/// Handles the `DirectoryEntry::Symlink` variant by checking the symlink target
/// type and replacing it with `DirectoryEntry::File` or
/// `DirectoryEntry::Directory`.
pub async fn resolve_symlink(self) -> Result<Self> { pub async fn resolve_symlink(self) -> Result<Self> {
if let DirectoryEntry::Symlink(symlink) = self { if let DirectoryEntry::Symlink(symlink) = self {
let real_path = symlink.realpath().to_resolved().await?; let real_path = symlink.realpath().to_resolved().await?;
...@@ -2321,6 +2320,16 @@ impl DirectoryEntry { ...@@ -2321,6 +2320,16 @@ impl DirectoryEntry {
Ok(self) Ok(self)
} }
} }
pub fn path(self) -> Option<ResolvedVc<FileSystemPath>> {
match self {
DirectoryEntry::File(path)
| DirectoryEntry::Directory(path)
| DirectoryEntry::Symlink(path)
| DirectoryEntry::Other(path) => Some(path),
DirectoryEntry::Error => None,
}
}
} }
#[turbo_tasks::value] #[turbo_tasks::value]
...@@ -2384,6 +2393,8 @@ impl From<&RawDirectoryEntry> for FileSystemEntryType { ...@@ -2384,6 +2393,8 @@ impl From<&RawDirectoryEntry> for FileSystemEntryType {
#[turbo_tasks::value] #[turbo_tasks::value]
#[derive(Debug)] #[derive(Debug)]
pub enum RawDirectoryContent { pub enum RawDirectoryContent {
// The entry keys are the directory relative file names
// e.g. for `/bar/foo`, it will be `foo`
Entries(AutoMap<RcStr, RawDirectoryEntry>), Entries(AutoMap<RcStr, RawDirectoryEntry>),
NotFound, NotFound,
} }
...@@ -2435,11 +2446,6 @@ impl FileSystem for NullFileSystem { ...@@ -2435,11 +2446,6 @@ impl FileSystem for NullFileSystem {
RawDirectoryContent::not_found() RawDirectoryContent::not_found()
} }
#[turbo_tasks::function]
fn track(&self, _fs_path: Vc<FileSystemPath>) -> Vc<Completion> {
Completion::immutable()
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn write(&self, _fs_path: Vc<FileSystemPath>, _content: Vc<FileContent>) -> Vc<()> { fn write(&self, _fs_path: Vc<FileSystemPath>, _content: Vc<FileContent>) -> Vc<()> {
Vc::default() Vc::default()
......
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{Completion, ValueDefault, ValueToString, Vc}; use turbo_tasks::{ValueDefault, ValueToString, Vc};
use super::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent}; use super::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent};
use crate::RawDirectoryContent; use crate::RawDirectoryContent;
...@@ -61,11 +61,6 @@ impl FileSystem for VirtualFileSystem { ...@@ -61,11 +61,6 @@ impl FileSystem for VirtualFileSystem {
bail!("Reading is not possible on the virtual file system") bail!("Reading is not possible on the virtual file system")
} }
#[turbo_tasks::function]
fn track(&self, _fs_path: Vc<FileSystemPath>) -> Result<Vc<Completion>> {
bail!("Tracking is not possible on the virtual file system")
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn write(&self, _fs_path: Vc<FileSystemPath>, _content: Vc<FileContent>) -> Result<Vc<()>> { fn write(&self, _fs_path: Vc<FileSystemPath>, _content: Vc<FileContent>) -> Result<Vc<()>> {
bail!("Writing is not possible on the virtual file system") bail!("Writing is not possible on the virtual file system")
......
...@@ -157,7 +157,7 @@ async fn read_path( ...@@ -157,7 +157,7 @@ async fn read_path(
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let path_str = path.await?.path.clone(); let path_str = path.await?.path.clone();
invalidations.0.lock().unwrap().insert(path_str); invalidations.0.lock().unwrap().insert(path_str);
let _ = path.track().await?; let _ = path.read().await?;
Ok(()) Ok(())
} }
......
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{Completion, ValueToString, Vc}; use turbo_tasks::{ValueToString, Vc};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent, FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent,
}; };
...@@ -33,11 +33,6 @@ impl FileSystem for ServerFileSystem { ...@@ -33,11 +33,6 @@ impl FileSystem for ServerFileSystem {
bail!("Reading is not possible from the marker filesystem for the server") bail!("Reading is not possible from the marker filesystem for the server")
} }
#[turbo_tasks::function]
fn track(&self, _fs_path: Vc<FileSystemPath>) -> Result<Vc<Completion>> {
bail!("Tracking is not possible to the marker filesystem for the server")
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn write(&self, _fs_path: Vc<FileSystemPath>, _content: Vc<FileContent>) -> Result<Vc<()>> { fn write(&self, _fs_path: Vc<FileSystemPath>, _content: Vc<FileContent>) -> Result<Vc<()>> {
bail!("Writing is not possible to the marker filesystem for the server") bail!("Writing is not possible to the marker filesystem for the server")
......
...@@ -16,8 +16,7 @@ use turbo_tasks::{ ...@@ -16,8 +16,7 @@ use turbo_tasks::{
use turbo_tasks_bytes::stream::SingleValue; use turbo_tasks_bytes::stream::SingleValue;
use turbo_tasks_env::ProcessEnv; use turbo_tasks_env::ProcessEnv;
use turbo_tasks_fs::{ use turbo_tasks_fs::{
glob::Glob, json::parse_json_with_source_context, rope::Rope, DirectoryEntry, File, glob::Glob, json::parse_json_with_source_context, rope::Rope, File, FileContent, FileSystemPath,
FileContent, FileSystemPath, ReadGlobResult,
}; };
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -510,15 +509,9 @@ impl EvaluateContext for WebpackLoaderContext { ...@@ -510,15 +509,9 @@ impl EvaluateContext for WebpackLoaderContext {
let directory_subscriptions = directories let directory_subscriptions = directories
.iter() .iter()
.map(|(dir, glob)| { .map(|(dir, glob)| {
// TODO: there is some redundancy between `dir_dependency` and what self.cwd
// `read_glob` does, Introduce a new read_glob .join(dir.clone())
// option that will track all files the way .track_glob(Glob::new(glob.clone()), false)
// `dir_dependency` does but in a single traversal.
dir_dependency(
self.cwd
.join(dir.clone())
.read_glob(Glob::new(glob.clone()), false),
)
}) })
.try_join(); .try_join();
let build_paths = build_file_paths let build_paths = build_file_paths
...@@ -778,45 +771,6 @@ impl Issue for BuildDependencyIssue { ...@@ -778,45 +771,6 @@ impl Issue for BuildDependencyIssue {
} }
} }
/// A hack to invalidate when any file in a directory changes. Need to be
/// awaited before files are accessed.
#[turbo_tasks::function]
async fn dir_dependency(glob: Vc<ReadGlobResult>) -> Result<Vc<Completion>> {
let shallow = dir_dependency_shallow(glob);
let glob = glob.await?;
glob.inner
.values()
.map(|&inner| dir_dependency(*inner))
.try_join()
.await?;
shallow.await?;
Ok(Completion::new())
}
#[turbo_tasks::function]
async fn dir_dependency_shallow(glob: Vc<ReadGlobResult>) -> Result<Vc<Completion>> {
let glob = glob.await?;
for item in glob.results.values() {
// Reading all files to add itself as dependency
match *item {
DirectoryEntry::File(file) => {
file.read().await?;
}
DirectoryEntry::Directory(dir) => {
dir_dependency(dir.read_glob(Glob::new("**".into()), false)).await?;
}
DirectoryEntry::Symlink(symlink) => {
symlink.read_link().await?;
}
DirectoryEntry::Other(other) => {
other.get_type().await?;
}
DirectoryEntry::Error => {}
}
}
Ok(Completion::new())
}
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct EvaluateEmittedErrorIssue { pub struct EvaluateEmittedErrorIssue {
pub file_path: ResolvedVc<FileSystemPath>, pub file_path: ResolvedVc<FileSystemPath>,
......
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