Skip to content

Commit 5e6343e

Browse files
committed
Make target the full path
1 parent 7516e63 commit 5e6343e

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

crates/next-core/src/next_server/resolve.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -320,21 +320,7 @@ impl AfterResolvePlugin for ExternalCjsModulesResolvePlugin {
320320
}
321321
};
322322

323-
let mut target = result_from_original_location.ident().path().owned().await?;
324-
loop {
325-
let parent = target.parent();
326-
if parent.is_root() {
327-
break;
328-
}
329-
if parent.file_name() == "node_modules" {
330-
break;
331-
}
332-
if parent.file_name().starts_with("@") && parent.parent().file_name() == "node_modules"
333-
{
334-
break;
335-
}
336-
target = parent;
337-
}
323+
let target = result_from_original_location.ident().path().owned().await?;
338324

339325
Ok(ResolveResultOption::some(*ResolveResult::primary(
340326
ResolveResultItem::External {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ pub enum ResolveResultItem {
414414
name: RcStr,
415415
ty: ExternalType,
416416
traced: ExternalTraced,
417+
/// The file path to the resolved file. Passing a value will create a symlink in the output
418+
/// root to be able to access potentially transitive dependencies.
417419
target: Option<FileSystemPath>,
418420
},
419421
Ignore,

turbopack/crates/turbopack/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,27 @@ pub async fn replace_external(
10851085
}
10861086
};
10871087

1088+
// Determine the package folder, `target` is the full path to the resolved file.
1089+
let target = if let Some(mut target) = target {
1090+
loop {
1091+
let parent = target.parent();
1092+
if parent.is_root() {
1093+
break;
1094+
}
1095+
if parent.file_name() == "node_modules" {
1096+
break;
1097+
}
1098+
if parent.file_name().starts_with("@") && parent.parent().file_name() == "node_modules"
1099+
{
1100+
break;
1101+
}
1102+
target = parent;
1103+
}
1104+
Some(target)
1105+
} else {
1106+
None
1107+
};
1108+
10881109
let module = CachedExternalModule::new(name.clone(), target, external_type, analyze_mode)
10891110
.to_resolved()
10901111
.await?;

0 commit comments

Comments
 (0)