Skip to content

Commit 81c03fa

Browse files
committed
feat(turbopack): support resolve windows absolute path with project_root
1 parent 7aa0490 commit 81c03fa

File tree

3 files changed

+74
-14
lines changed
  • turbopack/crates

3 files changed

+74
-14
lines changed

turbopack/crates/turbo-tasks-fs/src/watcher.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,13 @@ impl DiskWatcher {
367367
}
368368
path.components().any(|component| {
369369
if let Component::Normal(name) = component
370-
&& let Some(name_str) = name.to_str() {
371-
return self
372-
.ignored_paths
373-
.iter()
374-
.any(|ignored| ignored.as_str() == name_str);
375-
}
370+
&& let Some(name_str) = name.to_str()
371+
{
372+
return self
373+
.ignored_paths
374+
.iter()
375+
.any(|ignored| ignored.as_str() == name_str);
376+
}
376377
false
377378
})
378379
}

turbopack/crates/turbopack-core/src/resolve/mod.rs

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use turbo_tasks::{
2020
FxIndexMap, FxIndexSet, NonLocalValue, ReadRef, ResolvedVc, TaskInput, TryFlatJoinIterExt,
2121
TryJoinIterExt, ValueToString, Vc, trace::TraceRawVcs,
2222
};
23-
use turbo_tasks_fs::{FileSystemEntryType, FileSystemPath};
23+
use turbo_tasks_fs::{DiskFileSystem, FileSystemEntryType, FileSystemPath};
2424
use turbo_unix_path::normalize_request;
2525

2626
use crate::{
@@ -2020,18 +2020,77 @@ async fn resolve_internal_inline(
20202020
.await?
20212021
}
20222022
Request::Windows {
2023-
path: _,
2024-
query: _,
2025-
fragment: _,
2023+
path,
2024+
query,
2025+
fragment,
20262026
} => {
2027+
if let Some(path_str) = path.as_constant_string() {
2028+
let sys_path = std::path::Path::new(path_str.as_str());
2029+
2030+
if let Some(disk_fs_vc) =
2031+
ResolvedVc::try_downcast_type::<DiskFileSystem>(lookup_path.fs)
2032+
{
2033+
let disk_fs = disk_fs_vc.await?;
2034+
let root_path = lookup_path.root().owned().await?;
2035+
2036+
// Try to convert the Windows path to a FileSystemPath
2037+
if let Some(fs_path) = disk_fs.try_from_sys_path(disk_fs_vc, sys_path, None)
2038+
{
2039+
// Successfully converted - resolve as a raw path
2040+
let mut results = Vec::new();
2041+
let unix_path = &fs_path.path;
2042+
let pattern = Pattern::Constant(unix_path.clone());
2043+
let matches = read_matches(
2044+
root_path.clone(),
2045+
rcstr!(""),
2046+
false,
2047+
Pattern::new(pattern).resolve().await?,
2048+
)
2049+
.await?;
2050+
2051+
for m in matches.iter() {
2052+
match m {
2053+
PatternMatch::File(matched_pattern, path) => {
2054+
results.push(
2055+
resolved(
2056+
RequestKey::new(matched_pattern.clone()),
2057+
path.clone(),
2058+
lookup_path.clone(),
2059+
request,
2060+
options_value,
2061+
options,
2062+
query.clone(),
2063+
fragment.clone(),
2064+
)
2065+
.await?,
2066+
);
2067+
}
2068+
PatternMatch::Directory(matched_pattern, path) => {
2069+
results.push(
2070+
resolve_into_folder(path.clone(), options)
2071+
.with_request(matched_pattern.clone()),
2072+
);
2073+
}
2074+
}
2075+
}
2076+
2077+
return Ok(merge_results(results));
2078+
}
2079+
}
2080+
}
2081+
20272082
if !has_alias {
20282083
ResolvingIssue {
20292084
severity: error_severity(options).await?,
2030-
request_type: "windows import: not implemented yet".to_string(),
2085+
request_type: "windows import".to_string(),
20312086
request: request.to_resolved().await?,
20322087
file_path: lookup_path.clone(),
20332088
resolve_options: options.to_resolved().await?,
2034-
error_message: Some("windows imports are not implemented yet".to_string()),
2089+
error_message: Some(
2090+
"Windows absolute path imports can only be resolved if the path is \
2091+
within the project root. Please use a relative path instead."
2092+
.to_string(),
2093+
),
20352094
source: None,
20362095
}
20372096
.resolved_cell()

turbopack/crates/turbopack-node/src/worker_pool/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl WorkerThreadPool {
9999

100100
if let Some(worker_id) = idle.pop() {
101101
return Ok((worker_id, AcquiredPermits::Idle { concurrency_permit }));
102-
}
102+
}
103103
}
104104

105105
let (tx, rx) = oneshot::channel();
@@ -109,7 +109,7 @@ impl WorkerThreadPool {
109109
let mut idle = self.state.idle_workers.lock();
110110
if let Some(worker_id) = idle.pop() {
111111
return Ok((worker_id, AcquiredPermits::Idle { concurrency_permit }));
112-
}
112+
}
113113
waiters.push(tx);
114114
}
115115

0 commit comments

Comments
 (0)