Skip to content

Instantly share code, notes, and snippets.

@yocontra
Created January 15, 2015 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yocontra/de3c0ea120437d8207ca to your computer and use it in GitHub Desktop.
Save yocontra/de3c0ea120437d8207ca to your computer and use it in GitHub Desktop.
const os = require('os');
const fs = require('fs');
const path = require('path');
const execFile = require('child_process').execFile;
const tmpfile = path.join(os.tmpdir(), process.versions.v8+'.flags.json');
const exclusions = ['--help'];
module.exports = function (cb) {
fs.exists(tmpfile, function (exists) {
if (exists) {
cb(null, require(tmpfile));
} else {
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;
});
fs.writeFile(tmpfile, JSON.stringify(flags), { encoding:'utf8' },
function (writeErr) {
if (writeErr) {
return cb(writeErr);
}
cb(null, flags);
}
);
});
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment