Socket
Socket
Sign inDemoInstall

v8flags

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

v8flags - npm Package Compare versions

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc