From cd6156a92c7641fa3b3e7b0cfb2c258e5789bf6c Mon Sep 17 00:00:00 2001 From: Duncan Bayne Date: Tue, 12 Jun 2018 08:33:40 +1000 Subject: [PATCH 1/3] Clean up existing OS handling a little * Avoid fall-through in switch statement. * Improve error message in the case of incompatibility. * Rename linux() function to posix(). * Sort cases alphabetically for improved readability. --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index d5e10a1..7715f7a 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ var os = require('os') var path = require('path') var homedir = require('os-homedir') -function linux (id) { +function posix (id) { var cacheHome = process.env.XDG_CACHE_HOME || path.join(homedir(), '.cache') return path.join(cacheHome, id) } @@ -18,11 +18,11 @@ function win32 (id) { var implementation = (function () { switch (os.platform()) { - case 'android': - case 'linux': return linux + case 'android': return posix case 'darwin': return darwin + case 'linux': return posix case 'win32': return win32 - default: throw new Error('Your OS is currently not supported by node-cachedir.') + default: throw new Error('Your OS "' + os.platform() + '" is currently not supported by node-cachedir.') } }()) From 79d53496d5e5616be64579ba0f52064811cc126e Mon Sep 17 00:00:00 2001 From: Duncan Bayne Date: Tue, 12 Jun 2018 08:35:45 +1000 Subject: [PATCH 2/3] Add FreeBSD support --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 7715f7a..d1daee7 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ var implementation = (function () { switch (os.platform()) { case 'android': return posix case 'darwin': return darwin + case 'freebsd': return posix case 'linux': return posix case 'win32': return win32 default: throw new Error('Your OS "' + os.platform() + '" is currently not supported by node-cachedir.') From 5672ad2ae02f3254d302d49a712d8184695c65f0 Mon Sep 17 00:00:00 2001 From: Duncan Bayne Date: Tue, 12 Jun 2018 08:50:59 +1000 Subject: [PATCH 3/3] Update test to include FreeBSD --- test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test.js b/test.js index 2215bec..2c7feee 100644 --- a/test.js +++ b/test.js @@ -5,8 +5,9 @@ var homedir = require('os-homedir') var proxyquire = require('proxyquire') var platforms = [ - ['linux', homedir() + '/.cache/linusu'], ['darwin', homedir() + '/Library/Caches/linusu'], + ['freebsd', homedir() + '/.cache/linusu'], + ['linux', homedir() + '/.cache/linusu'], ['win32', homedir() + '/AppData/Local/linusu/Cache'] ]