Skip to content

Commit

Permalink
Breaking: Cache flags & attempt to read it
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Kellen authored and phated committed Dec 17, 2018
1 parent 5bbce9a commit 8f056e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.flags*
36 changes: 30 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
const exec = require('child_process').exec;
const fs = require('fs');
const path = require('path');

// TODO: cache this to a file in the module matching the version number of v8
module.exports = function (callback) {
exec('node --v8-options', function (err, result) {
callback(err, result.match(/\s\s--(\w+)/gm).map(function (match) {
return match.substring(4);
}));
const version = process.versions.v8;
const tmpfile = path.join(__dirname, '.flags-'+version);

module.exports = function (cb) {
fs.exists(tmpfile, function (exists) {
if (exists) {
fs.readFile(tmpfile, function (err, flags) {
if (err) {
cb(err);
}
cb(null, JSON.parse(flags));
});
} else {
exec('node --v8-options', function (err, result) {
var flags = result.match(/\s\s--(\w+)/gm).map(function (match) {
return match.substring(4);
});
fs.writeFile(tmpfile, JSON.stringify(flags), { encoding:'utf8' },
function (writeErr) {
if (writeErr) {
cb(writeErr);
} else {
cb(null, flags);
}
}
);
});
}
});
};

0 comments on commit 8f056e0

Please # to comment.