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.7 to 2.0.8

71

index.js

@@ -33,2 +33,5 @@ // this entire module is depressing. i should have spent my time learning

try {
// if the config file is valid, it should be json and therefore
// node should be able to require it directly. if this doesn't
// throw, we're done!
content = require(configpath);

@@ -39,5 +42,9 @@ process.nextTick(function () {

} catch (e) {
// if requiring the config file failed, maybe it doesn't exist, or
// perhaps it has become corrupted. instead of calling back with the
// content of the file, call back with a file descriptor that we can
// write the cached data to
fs.open(configpath, 'w+', function (err, fd) {
if (err) {
return cb(fail(err));
return cb(err);
}

@@ -49,9 +56,12 @@ return cb(null, fd);

function writeConfig (fd, cb) {
// i can't wait for the day this whole module is obsolete because these
// options are available on the process object. this executes node with
// `--v8-options` and parses the result, returning an array of command
// line flags.
function getFlags (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) {
var flags = result.match(/\s\s--(\w+)/gm).map(function (match) {
return match.substring(2);

@@ -61,11 +71,17 @@ }).filter(function (name) {

});
var buf = new Buffer(JSON.stringify(flags));
fs.write(fd, buf, 0, buf.length, 0, 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()));
});
return cb(null, flags);
});
}
// write some json to a file descriptor. if this fails, call back
// with both the error and the data that was meant to be written.
function writeConfig (fd, flags, cb) {
var buf = new Buffer(JSON.stringify(flags));
return fs.write(fd, buf, 0, buf.length, 0 , function (writeErr) {
fs.close(fd, function (closeErr) {
var err = writeErr || closeErr;
if (err) {
return cb(fall(err), flags);
}
return cb(null, flags);
});

@@ -76,10 +92,25 @@ });

module.exports = function (cb) {
openConfig(function (err, result) {
if (err) {
return cb(fail(err));
// attempt to open/read cache file
openConfig(function (openErr, result) {
if (!openErr && typeof result !== 'number') {
return cb(null, result);
}
if (typeof result === 'number') {
return writeConfig(result, cb);
}
return cb(null, result);
// if the result is not an array, we need to go fetch
// the flags by invoking node with `--v8-options`
getFlags(function (flagsErr, flags) {
// if there was an error fetching the flags, bail immediately
if (flagsErr) {
return cb(flagsErr);
}
// if there was a problem opening the config file for writing
// throw an error but include the flags anyway so that users
// can continue to execute (at the expense of having to fetch
// flags on every run until they fix the underyling problem).
if (openErr) {
return cb(fail(openErr), flags);
}
// write the config file to disk so subsequent runs can read
// flags out of a cache file.
return writeConfig(result, flags, cb);
});
});

@@ -86,0 +117,0 @@ };

{
"name": "v8flags",
"description": "Get available v8 flags.",
"version": "2.0.7",
"version": "2.0.8",
"homepage": "https://github.com/tkellen/node-v8flags",

@@ -6,0 +6,0 @@ "author": {

@@ -26,2 +26,3 @@ # v8flags [![Build Status](https://secure.travis-ci.org/tkellen/js-v8flags.png)](http://travis-ci.org/tkellen/js-v8flags) [![Build status](https://ci.appveyor.com/api/projects/status/9psgmwayx9kpol1a?svg=true)](https://ci.appveyor.com/project/tkellen/js-v8flags)

* 2015-06-25 - v2.0.8 - call back with flags even if cache file can't be written
* 2015-06-15 - v2.0.7 - revert to 2.0.5 behavior.

@@ -28,0 +29,0 @@ * 2015-06-15 - v2.0.6 - store cache file in ~/.cache or ~/AppData/Local depending on platform

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