From 4c4791b5899afe585738ac0a15ba5c21d36952cc Mon Sep 17 00:00:00 2001 From: Liam Murphy <43807659+Liamolucko@users.noreply.github.com> Date: Wed, 6 Jan 2021 10:42:40 +1100 Subject: fix(std/node): resolve files in symlinked directories (#8840) --- std/node/module.ts | 11 +---------- std/node/module_test.ts | 5 +++++ std/node/tests/cjs/dir | 1 + std/node/tests/cjs/subdir/dir/index.js | 4 ++++ 4 files changed, 11 insertions(+), 10 deletions(-) create mode 120000 std/node/tests/cjs/dir create mode 100644 std/node/tests/cjs/subdir/dir/index.js (limited to 'std/node') diff --git a/std/node/module.ts b/std/node/module.ts index f10fc2ca7..a7052668a 100644 --- a/std/node/module.ts +++ b/std/node/module.ts @@ -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 diff --git a/std/node/module_test.ts b/std/node/module_test.ts index 2faaff575..86fb1d386 100644 --- a/std/node/module_test.ts +++ b/std/node/module_test.ts @@ -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"); +}); diff --git a/std/node/tests/cjs/dir b/std/node/tests/cjs/dir new file mode 120000 index 000000000..abec30059 --- /dev/null +++ b/std/node/tests/cjs/dir @@ -0,0 +1 @@ +./subdir/dir \ No newline at end of file diff --git a/std/node/tests/cjs/subdir/dir/index.js b/std/node/tests/cjs/subdir/dir/index.js new file mode 100644 index 000000000..0b4d11386 --- /dev/null +++ b/std/node/tests/cjs/subdir/dir/index.js @@ -0,0 +1,4 @@ +// deno-lint-ignore-file no-undef +const C = require("../cjs_c"); + +module.exports = { C }; -- cgit v1.2.3