Skip to content

Commit f8001b6

Browse files
SimenBljharb
authored andcommitted
[patch] sync/async: use native realpath if available to unwrap symlinks
1 parent 3830a4e commit f8001b6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/async.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var nodeModulesPaths = require('./node-modules-paths.js');
55
var normalizeOptions = require('./normalize-options.js');
66
var isCore = require('./is-core');
77

8+
var realpath = typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;
9+
810
var defaultIsFile = function isFile(file, cb) {
911
fs.stat(file, function (err, stat) {
1012
if (!err) {
@@ -27,7 +29,7 @@ var defaultIsDir = function isDirectory(dir, cb) {
2729

2830
var maybeUnwrapSymlink = function maybeUnwrapSymlink(x, opts, cb) {
2931
if (!opts || !opts.preserveSymlinks) {
30-
fs.realpath(x, function (realPathErr, realPath) {
32+
realpath(x, function (realPathErr, realPath) {
3133
if (realPathErr && realPathErr.code !== 'ENOENT') cb(realPathErr);
3234
else cb(null, realPathErr ? x : realPath);
3335
});

lib/sync.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var caller = require('./caller.js');
55
var nodeModulesPaths = require('./node-modules-paths.js');
66
var normalizeOptions = require('./normalize-options.js');
77

8+
var realpath = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;
9+
810
var defaultIsFile = function isFile(file) {
911
try {
1012
var stat = fs.statSync(file);
@@ -28,7 +30,7 @@ var defaultIsDir = function isDirectory(dir) {
2830
var maybeUnwrapSymlink = function maybeUnwrapSymlink(x, opts) {
2931
if (!opts || !opts.preserveSymlinks) {
3032
try {
31-
return fs.realpathSync(x);
33+
return realpath(x);
3234
} catch (realPathErr) {
3335
if (realPathErr.code !== 'ENOENT') {
3436
throw realPathErr;

0 commit comments

Comments
 (0)