Skip to content

Commit 1a87be7

Browse files
dsherretcrowlKats
authored andcommitted
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 (cherry picked from commit 06b6352)
1 parent c0b1d19 commit 1a87be7

File tree

6 files changed

+75
-8
lines changed

6 files changed

+75
-8
lines changed

ext/node_resolver/resolution.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,15 +1370,37 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
13701370
&self,
13711371
file_path: &Path,
13721372
) -> Result<Option<PackageJsonRc>, ClosestPkgJsonError> {
1373+
// we use this for deno compile using byonm because the script paths
1374+
// won't be in virtual file system, but the package.json paths will be
1375+
fn canonicalize_first_ancestor_exists(
1376+
dir_path: &Path,
1377+
env: &dyn NodeResolverEnv,
1378+
) -> Result<Option<PathBuf>, std::io::Error> {
1379+
for ancestor in dir_path.ancestors() {
1380+
match env.realpath_sync(ancestor) {
1381+
Ok(dir_path) => return Ok(Some(dir_path)),
1382+
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
1383+
// keep searching
1384+
}
1385+
Err(err) => return Err(err),
1386+
}
1387+
}
1388+
Ok(None)
1389+
}
1390+
13731391
let parent_dir = file_path.parent().unwrap();
1374-
let current_dir =
1375-
strip_unc_prefix(self.env.realpath_sync(parent_dir).map_err(
1376-
|source| CanonicalizingPkgJsonDirError {
1377-
dir_path: parent_dir.to_path_buf(),
1378-
source,
1379-
},
1380-
)?);
1381-
for current_dir in current_dir.ancestors() {
1392+
let Some(start_dir) = canonicalize_first_ancestor_exists(
1393+
parent_dir, &self.env,
1394+
)
1395+
.map_err(|source| CanonicalizingPkgJsonDirError {
1396+
dir_path: parent_dir.to_path_buf(),
1397+
source,
1398+
})?
1399+
else {
1400+
return Ok(None);
1401+
};
1402+
let start_dir = strip_unc_prefix(start_dir);
1403+
for current_dir in start_dir.ancestors() {
13821404
let package_json_path = current_dir.join("package.json");
13831405
if let Some(pkg_json) = self.load_package_json(&package_json_path)? {
13841406
return Ok(Some(pkg_json));
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"tempDir": true,
3+
"envs": {
4+
"DENO_FUTURE": "1"
5+
},
6+
"steps": [{
7+
"args": "install",
8+
"output": "[WILDCARD]"
9+
}, {
10+
"if": "unix",
11+
"args": "compile --output main src/main.ts",
12+
"output": "[WILDCARD]"
13+
}, {
14+
"if": "unix",
15+
"commandName": "./main",
16+
"args": [],
17+
"output": "main.out"
18+
}, {
19+
"if": "windows",
20+
"args": "compile --output main.exe src/main.ts",
21+
"output": "[WILDCARD]"
22+
}, {
23+
"if": "windows",
24+
"commandName": "./main.exe",
25+
"args": [],
26+
"output": "main.out"
27+
}]
28+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"unstable": ["byonm"]
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "package",
3+
"version": "1.0.0",
4+
"description": "",
5+
"keywords": [],
6+
"author": "",
7+
"license": "MIT",
8+
"dependencies": {
9+
"@denotest/add": "*"
10+
}
11+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { add } from "@denotest/add";
2+
console.log(add(1, 2));

0 commit comments

Comments
 (0)