diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-07-26 15:53:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-26 15:53:53 -0400 |
commit | 06b6352292b69359768c99a1fc984fa4bdcd07c9 (patch) | |
tree | 3b363e2ce167109e21bc9a68fe9e0d0e24bf0003 /ext/node_resolver/resolution.rs | |
parent | ed2bf8ce310824d476c704483b59bb02720f7029 (diff) |
fix(unstable/compile): handle byonm import in sub dir (#24755)
Regression in 1.45.0 caused by storing relative paths instead of
absolute paths in the binary.
Closes #24654
Diffstat (limited to 'ext/node_resolver/resolution.rs')
-rw-r--r-- | ext/node_resolver/resolution.rs | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/ext/node_resolver/resolution.rs b/ext/node_resolver/resolution.rs index 25316c385..f4b2e8056 100644 --- a/ext/node_resolver/resolution.rs +++ b/ext/node_resolver/resolution.rs @@ -1370,15 +1370,37 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> { &self, file_path: &Path, ) -> Result<Option<PackageJsonRc>, ClosestPkgJsonError> { + // we use this for deno compile using byonm because the script paths + // won't be in virtual file system, but the package.json paths will be + fn canonicalize_first_ancestor_exists( + dir_path: &Path, + env: &dyn NodeResolverEnv, + ) -> Result<Option<PathBuf>, std::io::Error> { + for ancestor in dir_path.ancestors() { + match env.realpath_sync(ancestor) { + Ok(dir_path) => return Ok(Some(dir_path)), + Err(err) if err.kind() == std::io::ErrorKind::NotFound => { + // keep searching + } + Err(err) => return Err(err), + } + } + Ok(None) + } + let parent_dir = file_path.parent().unwrap(); - let current_dir = - strip_unc_prefix(self.env.realpath_sync(parent_dir).map_err( - |source| CanonicalizingPkgJsonDirError { - dir_path: parent_dir.to_path_buf(), - source, - }, - )?); - for current_dir in current_dir.ancestors() { + let Some(start_dir) = canonicalize_first_ancestor_exists( + parent_dir, &self.env, + ) + .map_err(|source| CanonicalizingPkgJsonDirError { + dir_path: parent_dir.to_path_buf(), + source, + })? + else { + return Ok(None); + }; + let start_dir = strip_unc_prefix(start_dir); + for current_dir in start_dir.ancestors() { let package_json_path = current_dir.join("package.json"); if let Some(pkg_json) = self.load_package_json(&package_json_path)? { return Ok(Some(pkg_json)); |