diff --git a/crates/oxc_resolver/src/cache.rs b/crates/oxc_resolver/src/cache.rs index fbb36f8e0..d02b495a0 100644 --- a/crates/oxc_resolver/src/cache.rs +++ b/crates/oxc_resolver/src/cache.rs @@ -282,6 +282,11 @@ impl CachedPathImpl { let Ok(package_json_string) = fs.read_to_string(&package_json_path) else { return Ok(None); }; + let package_json_path = if options.symlinks { + self.realpath(fs)?.join("package.json") + } else { + package_json_path + }; PackageJson::parse(package_json_path.clone(), &package_json_string, options) .map(Arc::new) .map(Some) diff --git a/crates/oxc_resolver/src/lib.rs b/crates/oxc_resolver/src/lib.rs index 359952e43..9d1b74f6e 100644 --- a/crates/oxc_resolver/src/lib.rs +++ b/crates/oxc_resolver/src/lib.rs @@ -202,11 +202,16 @@ impl ResolverGeneric { let path = self.load_realpath(&cached_path)?; // enhanced-resolve: restrictions self.check_restrictions(&path)?; + let package_json = cached_path.find_package_json(&self.cache.fs, &self.options)?; + if let Some(package_json) = &package_json { + // path must be inside the package. + debug_assert!(path.starts_with(package_json.directory())); + } Ok(Resolution { path, query: ctx.query.take(), fragment: ctx.fragment.take(), - package_json: cached_path.find_package_json(&self.cache.fs, &self.options)?, + package_json, }) }