Comparing version 2.0.2 to 2.0.3
109
index.js
@@ -0,1 +1,3 @@ | ||
// this entire module is depressing. | ||
const os = require('os'); | ||
@@ -5,33 +7,88 @@ const fs = require('fs'); | ||
const execFile = require('child_process').execFile; | ||
const tmpfile = path.join(os.tmpdir(), process.versions.v8+'.flags.json'); | ||
const env = process.env; | ||
const user = env.LOGNAME || env.USER || env.LNAME || env.USERNAME; | ||
const configfile = '.v8flags.'+process.versions.v8+'.'+user+'.json'; | ||
const exclusions = ['--help']; | ||
module.exports = function (cb) { | ||
try { | ||
var flags = require(tmpfile); | ||
process.nextTick(function(){ | ||
cb(null, flags); | ||
const failureMessage = [ | ||
'Unable to cache a config file for v8flags to a your home directory', | ||
'or a temporary folder. To fix this problem, please correct your', | ||
'environment by setting HOME=/path/to/home or TEMP=/path/to/temp.', | ||
'NOTE: the user running this must be able to access provided path.', | ||
'If all else fails, please open an issue here:', | ||
'http://github.com/tkellen/js-v8flags' | ||
].join('\n'); | ||
function fail (err) { | ||
err.message += '\n\n' + failureMessage; | ||
return err; | ||
} | ||
function openConfig (cb) { | ||
var userHome = require('user-home'); | ||
var configpath = path.join(userHome || os.tmpdir(), configfile); | ||
fs.open(configpath, 'a+', function (err, fd) { | ||
if (err) { | ||
return cb(fail(err)); | ||
} | ||
return cb(null, fd); | ||
}); | ||
} | ||
function writeConfig (fd, cb) { | ||
execFile(process.execPath, ['--v8-options'], function (execErr, result) { | ||
var flags; | ||
if (execErr) { | ||
return cb(execErr); | ||
} | ||
flags = result.match(/\s\s--(\w+)/gm).map(function (match) { | ||
return match.substring(2); | ||
}).filter(function (name) { | ||
return exclusions.indexOf(name) === -1; | ||
}); | ||
} catch (e) { | ||
execFile(process.execPath, ['--v8-options'], function (execErr, result) { | ||
var flags; | ||
if (execErr) { | ||
return cb(execErr); | ||
} | ||
flags = result.match(/\s\s--(\w+)/gm).map(function (match) { | ||
return match.substring(2); | ||
}).filter(function (name) { | ||
return exclusions.indexOf(name) === -1; | ||
var buf = new Buffer(JSON.stringify(flags)); | ||
fs.write(fd, buf, 0, buf.length, null, function (writeErr, bytesWritten, buffer) { | ||
fs.close(fd, function (closeErr) { | ||
var err = writeErr || closeErr; | ||
if (err) { | ||
return cb(fail(err)); | ||
} | ||
return cb(null, JSON.parse(buffer.toString())); | ||
}); | ||
fs.writeFile(tmpfile, JSON.stringify(flags), { encoding:'utf8' }, | ||
function (writeErr) { | ||
if (writeErr) { | ||
return cb(writeErr); | ||
} | ||
cb(null, flags); | ||
} | ||
); | ||
}); | ||
} | ||
}); | ||
} | ||
function readConfig (fd, filesize, cb) { | ||
var buf = new Buffer(filesize); | ||
fs.read(fd, buf, 0, filesize, 0, function (readErr, bytesRead, buffer) { | ||
fs.close(fd, function (closeErr) { | ||
var err = readErr || closeErr; | ||
if (err) { | ||
return cb(fail(err)); | ||
} | ||
return cb(null, JSON.parse(buffer.toString())); | ||
}); | ||
}); | ||
} | ||
module.exports = function (cb) { | ||
openConfig(function (err, fd) { | ||
if (err) { | ||
return cb(fail(err)); | ||
} | ||
fs.fstat(fd, function (statErr, stats) { | ||
var filesize = stats.size; | ||
if (statErr) { | ||
return cb(fail(statErr)); | ||
} | ||
if (filesize === 0) { | ||
return writeConfig(fd, cb); | ||
} | ||
return readConfig(fd, filesize, cb); | ||
}); | ||
}); | ||
}; | ||
module.exports.configfile = configfile; |
{ | ||
"name": "v8flags", | ||
"description": "Get available v8 flags.", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"homepage": "https://github.com/tkellen/node-v8flags", | ||
@@ -37,3 +37,6 @@ "author": { | ||
"mocha": "~1.21.4" | ||
}, | ||
"dependencies": { | ||
"user-home": "^1.1.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# v8flags [![Build Status](https://secure.travis-ci.org/tkellen/node-v8flags.png)](http://travis-ci.org/tkellen/node-v8flags) [![Build status](https://ci.appveyor.com/api/projects/status/5jpe6yawxdllrok4?svg=true)](https://ci.appveyor.com/project/tkellen/node-v8flags) | ||
# v8flags [![Build Status](https://secure.travis-ci.org/tkellen/node-v8flags.png)](http://travis-ci.org/tkellen/js-v8flags) [![Build status](https://ci.appveyor.com/api/projects/status/5jpe6yawxdllrok4?svg=true)](https://ci.appveyor.com/project/tkellen/js-v8flags) | ||
> Get available v8 flags. | ||
@@ -26,2 +26,3 @@ | ||
* 2015-03-31 - v2.0.3 - prefer to store config files in user home over tmp | ||
* 2015-01-18 - v2.0.2 - keep his dark tentacles contained | ||
@@ -28,0 +29,0 @@ * 2015-01-15 - v2.0.1 - store temp file in `os.tmpdir()`, drop support for node 0.8 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
6412
84
41
1
+ Addeduser-home@^1.1.1
+ Addeduser-home@1.1.1(transitive)