Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.