mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(resolver): make sure package.json path is inside the resolved path (#1481)
This commit is contained in:
parent
79c2bac6b1
commit
4dbe17c33a
2 changed files with 11 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -202,11 +202,16 @@ impl<Fs: FileSystem + Default> ResolverGeneric<Fs> {
|
|||
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,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue