From c318e10127d3a9ca819d7dd444f4228c65aa71b1 Mon Sep 17 00:00:00 2001 From: Oden Date: Wed, 10 Jun 2015 14:16:52 -0700 Subject: [PATCH] Use standard directories on Unix and Windows --- index.js | 9 ++++++++- test.js | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 21f0a1b..268824f 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,14 @@ function fail (err) { function openConfig (cb) { var userHome = require('user-home'); - var configpath = path.join(userHome || os.tmpdir(), configfile); + var datapath = userHome || os.tmpdir(); + if (process.platform === 'win32' && userHome) { + datapath = path.join(datapath, 'AppData', 'Local'); + } + else if (userHome) { + datapath = path.join(datapath, '.cache'); + } + var configpath = path.join(datapath, configfile); var content; try { content = require(configpath); diff --git a/test.js b/test.js index b9d5c19..eb1b016 100644 --- a/test.js +++ b/test.js @@ -7,6 +7,19 @@ const expect = require('chai').expect; const env = process.env; +function getConfigPath() { + var v8flags = require('./'); + var userHome = require('user-home'); + var datapath = userHome || os.tmpdir(); + if (process.platform === 'win32' && userHome) { + datapath = path.join(datapath, 'AppData', 'Local'); + } + else if (userHome) { + datapath = path.join(datapath, '.cache'); + } + return path.join(datapath, v8flags.configfile); +} + describe('v8flags', function () { afterEach(function () { @@ -14,7 +27,7 @@ describe('v8flags', function () { var v8flags = require('./'); try { [ - path.resolve(require('user-home'), v8flags.configfile), + path.resolve(getConfigPath()), path.resolve(os.tmpdir(), v8flags.configfile) ].map(fs.unlinkSync); } catch (e) {} @@ -23,7 +36,7 @@ describe('v8flags', function () { it('should cache and call back with the v8 flags for the running process', function (done) { var v8flags = require('./'); - var configfile = path.resolve(require('user-home'), v8flags.configfile); + var configfile = path.resolve(getConfigPath()); v8flags(function (err, flags) { expect(flags).to.be.a('array'); expect(fs.existsSync(configfile)).to.be.true; @@ -38,7 +51,7 @@ describe('v8flags', function () { it('should create config correctly when multiple concurrent calls happen and it does not exist yet', function (done) { var v8flags = require('./'); - var configfile = path.resolve(require('user-home'), v8flags.configfile); + var configfile = path.resolve(getConfigPath()); async.parallel([v8flags, v8flags], function (err, results) { v8flags(function (err, final) { expect(results[0]).to.deep.equal(final);