这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/node-file-trace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl Args {
}

async fn create_fs(name: &str, root: &str, watch: bool) -> Result<Vc<Box<dyn FileSystem>>> {
let fs = DiskFileSystem::new(name.to_string(), root.to_string());
let fs = DiskFileSystem::new(name.to_string(), root.to_string(), vec![]);
if watch {
fs.await?.start_watching()?;
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/turbo-tasks-fetch/tests/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ async fn errors_on_404() {
}

fn get_issue_context() -> Vc<FileSystemPath> {
DiskFileSystem::new("root".to_owned(), "/".to_owned()).root()
DiskFileSystem::new("root".to_owned(), "/".to_owned(), vec![]).root()
}
2 changes: 1 addition & 1 deletion crates/turbo-tasks-fs/examples/hash_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn main() -> Result<()> {
let task = tt.spawn_root_task(|| {
Box::pin(async {
let root = current_dir().unwrap().to_str().unwrap().to_string();
let disk_fs = DiskFileSystem::new("project".to_string(), root);
let disk_fs = DiskFileSystem::new("project".to_string(), root, vec![]);
disk_fs.await?.start_watching()?;

// Smart Pointer cast
Expand Down
2 changes: 1 addition & 1 deletion crates/turbo-tasks-fs/examples/hash_glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> Result<()> {
let task = tt.spawn_root_task(|| {
Box::pin(async {
let root = current_dir().unwrap().to_str().unwrap().to_string();
let disk_fs = DiskFileSystem::new("project".to_string(), root);
let disk_fs = DiskFileSystem::new("project".to_string(), root, vec![]);
disk_fs.await?.start_watching()?;

// Smart Pointer cast
Expand Down
2 changes: 1 addition & 1 deletion crates/turbo-tasks-fs/src/embed/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub async fn directory_from_relative_path(
name: String,
path: String,
) -> Result<Vc<Box<dyn FileSystem>>> {
let disk_fs = DiskFileSystem::new(name, path);
let disk_fs = DiskFileSystem::new(name, path, vec![]);
disk_fs.await?.start_watching()?;

Ok(Vc::upcast(disk_fs))
Expand Down
1 change: 1 addition & 0 deletions crates/turbo-tasks-fs/src/embed/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub async fn content_from_relative_path(
let disk_fs = DiskFileSystem::new(
root_path.to_string_lossy().to_string(),
root_path.to_string_lossy().to_string(),
vec![],
);
disk_fs.await?.start_watching()?;

Expand Down
33 changes: 32 additions & 1 deletion crates/turbo-tasks-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ pub struct DiskFileSystem {
#[turbo_tasks(debug_ignore, trace_ignore)]
#[serde(skip)]
watcher: Arc<DiskWatcher>,
/// Array of paths that should not notify invalidations.
/// `notify` currently doesn't support unwatching subpaths from the root,
/// so underlying we still watches filesystem event but only skips to
/// invalidate.
ignored_subpaths: Vec<PathBuf>,
}

impl DiskFileSystem {
Expand Down Expand Up @@ -357,6 +362,8 @@ impl DiskFileSystem {
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
let disk_watcher = self.watcher.clone();

let ignored_paths = self.ignored_subpaths.clone();

spawn_thread(move || {
let mut batched_invalidate_path = HashSet::new();
let mut batched_invalidate_path_dir = HashSet::new();
Expand All @@ -373,6 +380,16 @@ impl DiskFileSystem {
match event {
Ok(Ok(events)) => {
events.iter().for_each(|DebouncedEvent { event: notify_debouncer_full::notify::Event {kind, paths, ..}, .. }| {
let paths: Vec<PathBuf> = paths.iter().filter(|p| {
!ignored_paths.iter().any(|ignored| {
p.starts_with(ignored)
})
}).cloned().collect();

if paths.is_empty() {
return;
}

// [NOTE] there is attrs in the `Event` struct, which contains few more metadata like process_id who triggered the event,
// or the source we may able to utilize later.
match kind {
Expand Down Expand Up @@ -628,8 +645,21 @@ pub fn path_to_key(path: impl AsRef<Path>) -> String {

#[turbo_tasks::value_impl]
impl DiskFileSystem {
/// Create a new instance of `DiskFileSystem`.
/// # Arguments
///
/// * `name` - Name of the filesystem.
/// * `root` - Path to the given filesystem's root.
/// * `ignored_subpaths` - A list of subpaths that should not trigger
/// invalidation. This should be a full path, since it is possible that
/// root & project dir is different and requires to ignore specific
/// subpaths from each.
#[turbo_tasks::function]
pub async fn new(name: String, root: String) -> Result<Vc<Self>> {
pub async fn new(
name: String,
root: String,
ignored_subpaths: Vec<String>,
) -> Result<Vc<Self>> {
mark_stateful();
// create the directory for the filesystem on disk, if it doesn't exist
fs::create_dir_all(&root).await?;
Expand All @@ -642,6 +672,7 @@ impl DiskFileSystem {
invalidator_map: Arc::new(InvalidatorMap::new()),
dir_invalidator_map: Arc::new(InvalidatorMap::new()),
watcher: Default::default(),
ignored_subpaths: ignored_subpaths.iter().map(PathBuf::from).collect(),
};

Ok(Self::cell(instance))
Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-cli/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ pub fn normalize_entries(entries: &Option<Vec<String>>) -> Vec<String> {

#[turbo_tasks::function]
pub async fn project_fs(project_dir: String) -> Result<Vc<Box<dyn FileSystem>>> {
let disk_fs = DiskFileSystem::new("project".to_string(), project_dir.to_string());
let disk_fs = DiskFileSystem::new("project".to_string(), project_dir.to_string(), vec![]);
disk_fs.await?.start_watching()?;
Ok(Vc::upcast(disk_fs))
}

#[turbo_tasks::function]
pub async fn output_fs(project_dir: String) -> Result<Vc<Box<dyn FileSystem>>> {
let disk_fs = DiskFileSystem::new("output".to_string(), project_dir.to_string());
let disk_fs = DiskFileSystem::new("output".to_string(), project_dir.to_string(), vec![]);
disk_fs.await?.start_watching()?;
Ok(Vc::upcast(disk_fs))
}
4 changes: 2 additions & 2 deletions crates/turbopack-tests/tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ async fn prepare_test(resource: String) -> Result<Vc<PreparedTest>> {
resource_path.to_str().unwrap()
);

let root_fs = DiskFileSystem::new("workspace".to_string(), REPO_ROOT.clone());
let project_fs = DiskFileSystem::new("project".to_string(), REPO_ROOT.clone());
let root_fs = DiskFileSystem::new("workspace".to_string(), REPO_ROOT.clone(), vec![]);
let project_fs = DiskFileSystem::new("project".to_string(), REPO_ROOT.clone(), vec![]);
let project_root = project_fs.root();

let relative_path = resource_path.strip_prefix(&*REPO_ROOT).context(format!(
Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-tests/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ async fn run_test(resource: String) -> Result<Vc<FileSystemPath>> {
Err(_) => SnapshotOptions::default(),
Ok(options_str) => parse_json_with_source_context(&options_str).unwrap(),
};
let root_fs = DiskFileSystem::new("workspace".to_string(), REPO_ROOT.clone());
let project_fs = DiskFileSystem::new("project".to_string(), REPO_ROOT.clone());
let root_fs = DiskFileSystem::new("workspace".to_string(), REPO_ROOT.clone(), vec![]);
let project_fs = DiskFileSystem::new("project".to_string(), REPO_ROOT.clone(), vec![]);
let project_root = project_fs.root();

let relative_path = test_path.strip_prefix(&*REPO_ROOT)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack/benches/node_file_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn bench_emit(b: &mut Bencher, bench_input: &BenchInput) {
let input = bench_input.input.clone();
async move {
let task = tt.spawn_once_task(async move {
let input_fs = DiskFileSystem::new("tests".to_string(), tests_root.clone());
let input_fs = DiskFileSystem::new("tests".to_string(), tests_root.clone(), vec![]);
let input = input_fs.root().join(input.clone());

let input_dir = input.parent().parent();
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack/examples/turbopack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn main() -> Result<()> {
let task = tt.spawn_root_task(|| {
Box::pin(async {
let root = current_dir().unwrap().to_str().unwrap().to_string();
let disk_fs = DiskFileSystem::new(PROJECT_FILESYSTEM_NAME.to_string(), root);
let disk_fs = DiskFileSystem::new(PROJECT_FILESYSTEM_NAME.to_string(), root, vec![]);
disk_fs.await?.start_watching()?;

// Smart Pointer cast
Expand Down
4 changes: 3 additions & 1 deletion crates/turbopack/tests/node-file-trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,16 @@ fn node_file_trace<B: Backend + 'static>(
let workspace_fs: Vc<Box<dyn FileSystem>> = Vc::upcast(DiskFileSystem::new(
"workspace".to_string(),
package_root.clone(),
vec![],
));
let input_dir = workspace_fs.root();
let input = input_dir.join(format!("tests/{input_string}"));

#[cfg(not(feature = "bench_against_node_nft"))]
let original_output = exec_node(package_root, input);

let output_fs = DiskFileSystem::new("output".to_string(), directory.clone());
let output_fs =
DiskFileSystem::new("output".to_string(), directory.clone(), vec![]);
let output_dir = output_fs.root();

let source = FileSource::new(input);
Expand Down