Skip to content

Commit

Permalink
Moving the realpath resolution to a function that uses it
Browse files Browse the repository at this point in the history
  • Loading branch information
lgandecki committed Apr 16, 2020
1 parent 45d83c0 commit c0a4927
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ var nodeModulesPaths = require('./node-modules-paths.js');
var normalizeOptions = require('./normalize-options.js');
var isCore = require('./is-core');

var realpath = typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;

var defaultIsFile = function isFile(file, cb) {
fs.stat(file, function (err, stat) {
if (!err) {
Expand All @@ -29,6 +27,8 @@ var defaultIsDir = function isDirectory(dir, cb) {

var maybeUnwrapSymlink = function maybeUnwrapSymlink(x, opts, cb) {
if (!opts || !opts.preserveSymlinks) {
var realpath = typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;

realpath(x, function (realPathErr, realPath) {
if (realPathErr && realPathErr.code !== 'ENOENT') cb(realPathErr);
else cb(null, realPathErr ? x : realPath);
Expand Down
4 changes: 2 additions & 2 deletions lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ var caller = require('./caller.js');
var nodeModulesPaths = require('./node-modules-paths.js');
var normalizeOptions = require('./normalize-options.js');

var realpath = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;

var defaultIsFile = function isFile(file) {
try {
var stat = fs.statSync(file);
Expand All @@ -29,6 +27,8 @@ var defaultIsDir = function isDirectory(dir) {

var maybeUnwrapSymlink = function maybeUnwrapSymlink(x, opts) {
if (!opts || !opts.preserveSymlinks) {
var realpath = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;

try {
return realpath(x);
} catch (realPathErr) {
Expand Down

0 comments on commit c0a4927

Please sign in to comment.