From 2e81b2fe06e8a8afc6a1df27e763bbc5070abbaf Mon Sep 17 00:00:00 2001 From: JPeer264 Date: Fri, 17 Feb 2017 16:27:40 +0100 Subject: [PATCH] Refactor symlinkPaths/Sync --- lib/ensure/symlink-paths.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/ensure/symlink-paths.js b/lib/ensure/symlink-paths.js index eebc12e..08412e0 100644 --- a/lib/ensure/symlink-paths.js +++ b/lib/ensure/symlink-paths.js @@ -1,6 +1,8 @@ -var path = require('path') +'use strict' + +const path = require('path') // path.isAbsolute shim for Node.js 0.10 support -var fs = require('graceful-fs') +const fs = require('graceful-fs') /** * Function that returns two types of paths, one relative to symlink, and one @@ -26,7 +28,7 @@ var fs = require('graceful-fs') function symlinkPaths (srcpath, dstpath, callback) { if (path.isAbsolute(srcpath)) { - return fs.lstat(srcpath, function (err, stat) { + return fs.lstat(srcpath, (err, stat) => { if (err) { err.message = err.message.replace('lstat', 'ensureSymlink') return callback(err) @@ -37,16 +39,16 @@ function symlinkPaths (srcpath, dstpath, callback) { }) }) } else { - var dstdir = path.dirname(dstpath) - var relativeToDst = path.join(dstdir, srcpath) - return fs.exists(relativeToDst, function (exists) { + const dstdir = path.dirname(dstpath) + const relativeToDst = path.join(dstdir, srcpath) + return fs.exists(relativeToDst, exists => { if (exists) { return callback(null, { 'toCwd': relativeToDst, 'toDst': srcpath }) } else { - return fs.lstat(srcpath, function (err, stat) { + return fs.lstat(srcpath, (err, stat) => { if (err) { err.message = err.message.replace('lstat', 'ensureSymlink') return callback(err) @@ -62,7 +64,7 @@ function symlinkPaths (srcpath, dstpath, callback) { } function symlinkPathsSync (srcpath, dstpath) { - var exists + let exists if (path.isAbsolute(srcpath)) { exists = fs.existsSync(srcpath) if (!exists) throw new Error('absolute srcpath does not exist') @@ -71,8 +73,8 @@ function symlinkPathsSync (srcpath, dstpath) { 'toDst': srcpath } } else { - var dstdir = path.dirname(dstpath) - var relativeToDst = path.join(dstdir, srcpath) + const dstdir = path.dirname(dstpath) + const relativeToDst = path.join(dstdir, srcpath) exists = fs.existsSync(relativeToDst) if (exists) { return { @@ -91,6 +93,6 @@ function symlinkPathsSync (srcpath, dstpath) { } module.exports = { - 'symlinkPaths': symlinkPaths, - 'symlinkPathsSync': symlinkPathsSync + symlinkPaths, + symlinkPathsSync }