Skip to content

Commit

Permalink
Use standard directories on Unix and Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Oden committed Jun 11, 2015
1 parent 880a03b commit c318e10
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 16 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@ 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 () {
delete require.cache[require.resolve('user-home')];
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) {}
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit c318e10

Please sign in to comment.