Skip to content

Commit

Permalink
fix(node): resolve files in symlinked directories (denoland/deno#8840)
Browse files Browse the repository at this point in the history
  • Loading branch information
Liamolucko authored and caspervonb committed Jan 31, 2021
1 parent c1ab9ea commit c11eb1a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
11 changes: 1 addition & 10 deletions node/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,16 +764,7 @@ function tryFile(requestPath: string, _isMain: boolean): string | false {
}

function toRealPath(requestPath: string): string {
// Deno does not have realpath implemented yet.
let fullPath = requestPath;
while (true) {
try {
fullPath = Deno.readLinkSync(fullPath);
} catch {
break;
}
}
return path.resolve(requestPath);
return Deno.realPathSync(requestPath);
}

// Given a path, check if the file exists with any of the set extensions
Expand Down
5 changes: 5 additions & 0 deletions node/module_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ Deno.test("requireStack", function () {
assertStringIncludes(e.stack, "/tests/cjs/cjs_throw.js");
}
});

Deno.test("requireFileInSymlinkDir", () => {
const { C } = require("./tests/cjs/dir");
assertEquals(C, "C");
});
1 change: 1 addition & 0 deletions node/tests/cjs/dir
4 changes: 4 additions & 0 deletions node/tests/cjs/subdir/dir/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// deno-lint-ignore-file no-undef
const C = require("../cjs_c");

module.exports = { C };

0 comments on commit c11eb1a

Please sign in to comment.