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
32 changes: 32 additions & 0 deletions turbopack/crates/turbo-tasks-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ impl FileSystem for DiskFileSystem {
return Ok(());
}

#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
match &*self.content {
FileContent::Content(..) => {
let create_directory = compare == FileComparison::Create;
Expand Down Expand Up @@ -1181,6 +1182,37 @@ impl FileSystem for DiskFileSystem {
}
}

#[cfg(all(target_family = "wasm", target_os = "unknown"))]
match &*self.content {
FileContent::Content(..) => {
let create_directory = compare == FileComparison::Create;
if create_directory && let Some(parent) = full_path.parent() {
self.inner.create_directory(parent).await.with_context(|| {
format!(
"failed to create directory {parent:?} for write to \
{full_path:?}",
)
})?;
}
let content = self.content.clone();
let FileContent::Content(file) = &*content else {
unreachable!()
};
wasm_fs_offload::CLIENT
.write(&full_path, file.content().to_bytes())
.instrument(tracing::info_span!("write file", name = ?full_path))
.await
.with_context(|| format!("failed to write to {full_path:?}"))?;
}
FileContent::NotFound => {
wasm_fs_offload::CLIENT
.remove_file(&full_path)
.instrument(tracing::info_span!("remove file", name = ?full_path))
.await
.with_context(|| format!("removing {full_path:?} failed"))?;
}
}
Comment on lines +1185 to +1214
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The WASM-specific file operation block contains redundant logic and an unnecessary double-match pattern. By cloning the content Arc once before the match, you can bind the inner file value directly in the first match arm, avoiding the need for a second let...else with an unreachable!() check. This also ensures the content remains alive across the .await points in a cleaner way.

                #[cfg(all(target_family = "wasm", target_os = "unknown"))]
                {
                    let content = self.content.clone();
                    match &*content {
                        FileContent::Content(file) => {
                            let create_directory = compare == FileComparison::Create;
                            if create_directory && let Some(parent) = full_path.parent() {
                                self.inner.create_directory(parent).await.with_context(|| {
                                    format!(
                                        "failed to create directory {parent:?} for write to \
                                         {full_path:?}",
                                    )
                                })?;
                            }
                            wasm_fs_offload::CLIENT
                                .write(&full_path, file.content().to_bytes())
                                .instrument(tracing::info_span!("write file", name = ?full_path))
                                .await
                                .with_context(|| format!("failed to write to {full_path:?}"))?;
                        }
                        FileContent::NotFound => {
                            wasm_fs_offload::CLIENT
                                .remove_file(&full_path)
                                .instrument(tracing::info_span!("remove file", name = ?full_path))
                                .await
                                .with_context(|| format!("removing {full_path:?} failed"))?;
                        }
                    }
                }


self.inner
.invalidate_from_write(&full_path, old_invalidators);

Expand Down
8 changes: 3 additions & 5 deletions turbopack/crates/turbopack-node/src/evaluate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
borrow::Cow, iter, process::ExitStatus, sync::Arc, thread::available_parallelism,
time::Duration,
};
use std::{borrow::Cow, iter, process::ExitStatus, sync::Arc, time::Duration};

use anyhow::{Result, bail};
use bincode::{Decode, Encode};
Expand Down Expand Up @@ -45,6 +42,7 @@ use crate::process_pool::ChildProcessPool;
use crate::worker_pool::WorkerThreadPool;
use crate::{
AssetsForSourceMapping,
available_parallelism::available_parallelism,
backend::{CreatePoolOptions, NodeBackend},
embed_js::embed_file_path,
emit, emit_package_json,
Expand Down Expand Up @@ -275,7 +273,7 @@ pub async fn get_evaluate_pool(
assets_for_source_mapping,
assets_root: output_root.clone(),
project_dir: chunking_context.root_path().owned().await?,
concurrency: available_parallelism().map_or(1, |v| v.get()),
concurrency: available_parallelism(),
debug,
})
.await?;
Expand Down
1 change: 1 addition & 0 deletions turbopack/crates/turbopack-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use turbopack_core::{
virtual_output::VirtualOutputAsset,
};

mod available_parallelism;
mod backend;
pub mod debug;
pub mod embed_js;
Expand Down
Loading