Skip to content

Commit 1e7976d

Browse files
committed
Fix affecting_sources
1 parent 226f825 commit 1e7976d

File tree

1 file changed

+29
-33
lines changed
  • turbopack/crates/turbopack-core/src/resolve

1 file changed

+29
-33
lines changed

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

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,24 +1140,36 @@ impl ResolveResultOption {
11401140
}
11411141

11421142
async fn exists(
1143-
fs_path: FileSystemPath,
1143+
fs_path: &FileSystemPath,
11441144
refs: &mut Vec<ResolvedVc<Box<dyn Source>>>,
11451145
) -> Result<Option<FileSystemPath>> {
11461146
type_exists(fs_path, FileSystemEntryType::File, refs).await
11471147
}
11481148

11491149
async fn dir_exists(
1150-
fs_path: FileSystemPath,
1150+
fs_path: &FileSystemPath,
11511151
refs: &mut Vec<ResolvedVc<Box<dyn Source>>>,
11521152
) -> Result<Option<FileSystemPath>> {
11531153
type_exists(fs_path, FileSystemEntryType::Directory, refs).await
11541154
}
11551155

11561156
async fn type_exists(
1157-
fs_path: FileSystemPath,
1157+
fs_path: &FileSystemPath,
11581158
ty: FileSystemEntryType,
11591159
refs: &mut Vec<ResolvedVc<Box<dyn Source>>>,
11601160
) -> Result<Option<FileSystemPath>> {
1161+
let path = realpath(fs_path, refs).await?;
1162+
Ok(if *path.get_type().await? == ty {
1163+
Some(path)
1164+
} else {
1165+
None
1166+
})
1167+
}
1168+
1169+
async fn realpath(
1170+
fs_path: &FileSystemPath,
1171+
refs: &mut Vec<ResolvedVc<Box<dyn Source>>>,
1172+
) -> Result<FileSystemPath> {
11611173
let result = fs_path.realpath_with_links().owned().await?;
11621174
refs.extend(
11631175
result
@@ -1171,12 +1183,7 @@ async fn type_exists(
11711183
.try_join()
11721184
.await?,
11731185
);
1174-
let path = result.path;
1175-
Ok(if *path.get_type().await? == ty {
1176-
Some(path)
1177-
} else {
1178-
None
1179-
})
1186+
Ok(result.path)
11801187
}
11811188

11821189
#[turbo_tasks::value(shared)]
@@ -1279,7 +1286,7 @@ pub async fn find_context_file(
12791286
let mut refs = Vec::new();
12801287
for name in &*names.await? {
12811288
let fs_path = lookup_path.join(name)?;
1282-
if let Some(fs_path) = exists(fs_path, &mut refs).await? {
1289+
if let Some(fs_path) = exists(&fs_path, &mut refs).await? {
12831290
return Ok(FindContextFileResult::Found(fs_path, refs).cell());
12841291
}
12851292
}
@@ -1319,7 +1326,7 @@ pub async fn find_context_file_or_package_key(
13191326
) -> Result<Vc<FindContextFileResult>> {
13201327
let mut refs = Vec::new();
13211328
let package_json_path = lookup_path.join("package.json")?;
1322-
if let Some(package_json_path) = exists(package_json_path, &mut refs).await?
1329+
if let Some(package_json_path) = exists(&package_json_path, &mut refs).await?
13231330
&& let Some(json) =
13241331
&*read_package_json(Vc::upcast(FileSource::new(package_json_path.clone()))).await?
13251332
&& json.get(&*package_key).is_some()
@@ -1328,7 +1335,7 @@ pub async fn find_context_file_or_package_key(
13281335
}
13291336
for name in &*names.await? {
13301337
let fs_path = lookup_path.join(name)?;
1331-
if let Some(fs_path) = exists(fs_path, &mut refs).await? {
1338+
if let Some(fs_path) = exists(&fs_path, &mut refs).await? {
13321339
return Ok(FindContextFileResult::Found(fs_path, refs).into());
13331340
}
13341341
}
@@ -1388,25 +1395,21 @@ async fn find_package(
13881395

13891396
for resolve_modules in &options.modules {
13901397
match resolve_modules {
1391-
ResolveModules::Nested(root_vc, names) => {
1398+
ResolveModules::Nested(root, names) => {
13921399
let mut lookup_path = lookup_path.clone();
13931400
let mut lookup_path_value = lookup_path.clone();
1394-
// For clippy -- This explicit deref is necessary
1395-
let root = root_vc.clone();
1396-
while lookup_path_value.is_inside_ref(&root) {
1401+
while lookup_path_value.is_inside_ref(root) {
13971402
for name in names.iter() {
13981403
let fs_path = lookup_path.join(name)?;
1399-
if let Some(fs_path) = dir_exists(fs_path, &mut affecting_sources).await? {
1400-
// TODO this is wrong, it should only match match 1 or 2 levels deep?
1401-
// TODO affecting_sources are not getting added?
1404+
if let Some(fs_path) = dir_exists(&fs_path, &mut affecting_sources).await? {
14021405
let matches =
14031406
read_matches(fs_path.clone(), rcstr!(""), true, package_name_cell)
14041407
.await?;
14051408
for m in &*matches {
14061409
if let PatternMatch::Directory(_, package_dir) = m {
14071410
packages.push(FindPackageItem::PackageDirectory {
14081411
name: get_package_name(&fs_path, package_dir)?,
1409-
dir: package_dir.clone(),
1412+
dir: realpath(package_dir, &mut affecting_sources).await?,
14101413
});
14111414
}
14121415
}
@@ -1424,24 +1427,20 @@ async fn find_package(
14241427
dir,
14251428
excluded_extensions,
14261429
} => {
1427-
// TODO this is wrong, it should only match match 1 or 2 levels deep?
1428-
// TODO affecting_sources are not getting added?
14291430
let matches =
14301431
read_matches(dir.clone(), rcstr!(""), true, package_name_cell).await?;
14311432
for m in &*matches {
14321433
match m {
14331434
PatternMatch::Directory(_, package_dir) => {
1434-
let name = get_package_name(dir, package_dir)?;
14351435
packages.push(FindPackageItem::PackageDirectory {
1436-
name: name.clone(),
1437-
dir: package_dir.clone(),
1436+
name: get_package_name(dir, package_dir)?,
1437+
dir: realpath(package_dir, &mut affecting_sources).await?,
14381438
});
14391439
}
14401440
PatternMatch::File(_, package_file) => {
1441-
let name = get_package_name(dir, package_file)?;
14421441
packages.push(FindPackageItem::PackageFile {
1443-
name: name.clone(),
1444-
file: package_file.clone(),
1442+
name: get_package_name(dir, package_file)?,
1443+
file: realpath(package_file, &mut affecting_sources).await?,
14451444
});
14461445
}
14471446
}
@@ -1459,17 +1458,14 @@ async fn find_package(
14591458
));
14601459
let package_name_with_extensions = Pattern::new(package_name_with_extensions);
14611460

1462-
// TODO this is wrong, it should only match match 1 or 2 levels deep?
1463-
// TODO affecting_sources are not getting added?
14641461
let matches =
14651462
read_matches(dir.clone(), rcstr!(""), true, package_name_with_extensions)
14661463
.await?;
14671464
for m in matches {
14681465
if let PatternMatch::File(_, package_file) = m {
1469-
let name = get_package_name(dir, package_file)?;
14701466
packages.push(FindPackageItem::PackageFile {
1471-
name: name.clone(),
1472-
file: package_file.clone(),
1467+
name: get_package_name(dir, package_file)?,
1468+
file: realpath(package_file, &mut affecting_sources).await?,
14731469
});
14741470
}
14751471
}

0 commit comments

Comments
 (0)