UNPKG

872 BJavaScriptView Raw
1const fs = require('fs');
2const path = require('path');
3
4const exec = require('child_process').exec;
5const nodePath = process.execPath;
6const version = process.versions.v8;
7const tmpfile = path.join(__dirname, 'cache', version+'.flags.json');
8
9if (!fs.existsSync(tmpfile)) {
10 exec('"'+nodePath+'" --v8-options', function (execErr, result) {
11 var flags;
12 if (execErr) {
13 throw new Error(execErr);
14 } else {
15 flags = result.match(/\s\s--(\w+)/gm).map(function (match) {
16 return match.substring(2);
17 });
18 fs.writeFile(tmpfile, JSON.stringify(flags), { encoding:'utf8' },
19 function (writeErr) {
20 if (writeErr) {
21 throw new Error(writeErr);
22 } else {
23 console.log('flags for v8 '+version+' cached.');
24 }
25 }
26 );
27 }
28 });
29}
30
31module.exports = require.bind(null, tmpfile);