Skip to content

Commit 5de3d55

Browse files
authored
Merge branch 'main' into renovate/github-actions
2 parents 42cdbf3 + 2d2ebf0 commit 5de3d55

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub struct ResolverGeneric<Fs> {
115115
options: ResolveOptions,
116116
cache: Arc<Cache<Fs>>,
117117
#[cfg(feature = "yarn_pnp")]
118-
pnp_manifest: Arc<arc_swap::ArcSwapOption<pnp::Manifest>>,
118+
pnp_manifest: Arc<arc_swap::ArcSwapOption<(PathBuf, pnp::Manifest)>>,
119119
/// Paths that have been searched and confirmed to have no `.pnp.cjs` reachable by filesystem walk.
120120
#[cfg(feature = "yarn_pnp")]
121121
pnp_no_manifest_cache: Arc<DashSet<CachedPath>>,
@@ -957,7 +957,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
957957

958958
#[cfg(feature = "yarn_pnp")]
959959
#[cfg_attr(feature = "enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(path = %cached_path.path().to_string_lossy())))]
960-
fn find_pnp_manifest(&self, cached_path: &CachedPath) -> Option<Arc<pnp::Manifest>> {
960+
fn find_pnp_manifest(&self, cached_path: &CachedPath) -> Option<Arc<(PathBuf, pnp::Manifest)>> {
961961
// 1. Already have a manifest → return it (covers global cache paths too)
962962
if let Some(manifest) = self.pnp_manifest.load_full() {
963963
return Some(manifest);
@@ -986,7 +986,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
986986
tracing::debug!("use manifest path: {:?}", manifest_path);
987987

988988
let manifest = pnp::load_pnp_manifest(&manifest_path).ok()?;
989-
let manifest = Arc::new(manifest);
989+
let manifest = Arc::new((manifest_path, manifest));
990990

991991
let previous = self
992992
.pnp_manifest
@@ -1007,13 +1007,15 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
10071007
specifier: &str,
10081008
ctx: &mut Ctx,
10091009
) -> Result<Option<CachedPath>, ResolveError> {
1010-
let Some(manifest) = self.find_pnp_manifest(cached_path) else {
1010+
let Some(pnp_data) = self.find_pnp_manifest(cached_path) else {
10111011
return Ok(None);
10121012
};
1013+
let (manifest_path, manifest) = pnp_data.as_ref();
1014+
ctx.add_file_dependency(manifest_path);
10131015

10141016
let mut path = cached_path.to_path_buf();
10151017
path.push("");
1016-
let resolution = pnp::resolve_to_unqualified_via_manifest(&manifest, specifier, &path);
1018+
let resolution = pnp::resolve_to_unqualified_via_manifest(manifest, specifier, &path);
10171019

10181020
tracing::debug!("pnp resolve unqualified as: {:?}", resolution);
10191021

src/tests/pnp.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! enhanced_resolve's test <https://github.com/webpack/enhanced-resolve/blob/main/test/pnp.test.js>
44
//! cannot be ported over because it uses mocks on `pnpApi` provided by the runtime.
55
6-
use crate::{path::PathUtil, ResolveError::NotFound, ResolveOptions, Resolver};
6+
use crate::{path::PathUtil, ResolveContext, ResolveError::NotFound, ResolveOptions, Resolver};
77

88
#[tokio::test]
99
async fn pnp1() {
@@ -78,6 +78,28 @@ async fn pnp1() {
7878
);
7979
}
8080

81+
#[tokio::test]
82+
async fn pnp_file_dependencies() {
83+
let fixture = super::fixture_root().join("pnp");
84+
85+
let resolver = Resolver::new(ResolveOptions {
86+
extensions: vec![".js".into()],
87+
condition_names: vec!["import".into()],
88+
..ResolveOptions::default()
89+
});
90+
91+
let mut ctx = ResolveContext::default();
92+
let result = resolver
93+
.resolve_with_context(&fixture, "is-even", &mut ctx)
94+
.await;
95+
assert!(result.is_ok());
96+
assert!(
97+
ctx.file_dependencies.contains(&fixture.join(".pnp.cjs")),
98+
".pnp.cjs should be in file_dependencies, got: {:?}",
99+
ctx.file_dependencies
100+
);
101+
}
102+
81103
// https://github.com/webpack/enhanced-resolve/blob/main/lib/PnpPlugin.js#L118
82104
// `fullySpecified` should be disabled for bare specifiers without subpath,
83105
// so that the `main` field value (e.g. "index" without extension) can be resolved.

0 commit comments

Comments
 (0)