Unverified Commit c8cf55f4 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: fix invalid NFT entry with file behind symlink (#83013)

parent c240df08
...@@ -231,6 +231,38 @@ impl Asset for NftJsonAsset { ...@@ -231,6 +231,38 @@ impl Asset for NftJsonAsset {
continue; continue;
} }
#[cfg(debug_assertions)]
{
// Verify that we there are no entries where a file is created inside of a symlink,
// as this can result in invalid ZIP files and deployment failures.
// For example
// node_modules/.pnpm/node_modules/@libsql/client/package.json
// where
// node_modules/.pnpm/node_modules/@libsql/client is a symlink
let mut current_path = referenced_chunk_path.parent();
loop {
use turbo_tasks_fs::FileSystemEntryType;
if current_path.is_root() {
break;
}
if matches!(
&*current_path.get_type().await?,
FileSystemEntryType::Symlink
) {
bail!(
"Encountered file inside of symlink in NFT list: {} is a symlink, but \
{} was created inside of it",
current_path.value_to_string().await?,
referenced_chunk_path.value_to_string().await?
);
}
current_path = current_path.parent();
}
}
let Some(specifier) = get_output_specifier( let Some(specifier) = get_output_specifier(
&referenced_chunk_path, &referenced_chunk_path,
&ident_folder, &ident_folder,
...@@ -241,6 +273,7 @@ impl Asset for NftJsonAsset { ...@@ -241,6 +273,7 @@ impl Asset for NftJsonAsset {
else { else {
continue; continue;
}; };
result.insert(specifier); result.insert(specifier);
} }
......
...@@ -2133,9 +2133,12 @@ async fn resolve_into_folder( ...@@ -2133,9 +2133,12 @@ async fn resolve_into_folder(
package_path: FileSystemPath, package_path: FileSystemPath,
options: Vc<ResolveOptions>, options: Vc<ResolveOptions>,
) -> Result<Vc<ResolveResult>> { ) -> Result<Vc<ResolveResult>> {
let package_json_path = package_path.join("package.json")?;
let options_value = options.await?; let options_value = options.await?;
let mut affecting_sources = vec![];
if let Some(package_json_path) =
exists(&package_path.join("package.json")?, &mut affecting_sources).await?
{
for resolve_into_package in options_value.into_package.iter() { for resolve_into_package in options_value.into_package.iter() {
match resolve_into_package { match resolve_into_package {
ResolveIntoPackage::MainField { field: name } => { ResolveIntoPackage::MainField { field: name } => {
...@@ -2159,7 +2162,8 @@ async fn resolve_into_folder( ...@@ -2159,7 +2162,8 @@ async fn resolve_into_folder(
} else { } else {
options options
}; };
let result = &*resolve_internal_inline(package_path.clone(), request, options) let result =
&*resolve_internal_inline(package_path.clone(), request, options)
.await? .await?
.await?; .await?;
// we are not that strict when a main field fails to resolve // we are not that strict when a main field fails to resolve
...@@ -2170,6 +2174,7 @@ async fn resolve_into_folder( ...@@ -2170,6 +2174,7 @@ async fn resolve_into_folder(
result.affecting_sources.push(ResolvedVc::upcast( result.affecting_sources.push(ResolvedVc::upcast(
FileSource::new(package_json_path).to_resolved().await?, FileSource::new(package_json_path).to_resolved().await?,
)); ));
result.affecting_sources.extend(affecting_sources);
return Ok(ResolveResult::from(result).cell()); return Ok(ResolveResult::from(result).cell());
} }
}; };
...@@ -2177,14 +2182,21 @@ async fn resolve_into_folder( ...@@ -2177,14 +2182,21 @@ async fn resolve_into_folder(
ResolveIntoPackage::ExportsField { .. } => {} ResolveIntoPackage::ExportsField { .. } => {}
} }
} }
}
if options_value.fully_specified { if options_value.fully_specified {
return Ok(*ResolveResult::unresolvable()); return Ok(*ResolveResult::unresolvable_with_affecting_sources(
affecting_sources,
));
} }
// fall back to dir/index.[js,ts,...] // fall back to dir/index.[js,ts,...]
let pattern = match &options_value.default_files[..] { let pattern = match &options_value.default_files[..] {
[] => return Ok(*ResolveResult::unresolvable()), [] => {
return Ok(*ResolveResult::unresolvable_with_affecting_sources(
affecting_sources,
));
}
[file] => Pattern::Constant(format!("./{file}").into()), [file] => Pattern::Constant(format!("./{file}").into()),
files => Pattern::Alternatives( files => Pattern::Alternatives(
files files
...@@ -2199,7 +2211,8 @@ async fn resolve_into_folder( ...@@ -2199,7 +2211,8 @@ async fn resolve_into_folder(
Ok( Ok(
resolve_internal_inline(package_path.clone(), request, options) resolve_internal_inline(package_path.clone(), request, options)
.await? .await?
.with_request(rcstr!(".")), .with_request(rcstr!("."))
.with_affecting_sources(ResolvedVc::deref_vec(affecting_sources)),
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment