Skip to content

Commit

Permalink
Change v8flags to use temp file instead of new process
Browse files Browse the repository at this point in the history
Using npm's preinstall hook, this task it's very simple. Before installation of package, the file with flags will be created and fetch.js will use that file instead of spawning new process. It will limit black magic to none :)
  • Loading branch information
Mateusz Wolsza committed Dec 2, 2014
1 parent c226729 commit afbce3f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 3 additions & 4 deletions fetch.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
const fs = require('fs');
const path = require('path');

const exec = require('child_process').exec;
const nodePath = process.execPath;
const version = process.versions.v8;
const tmpfile = path.join(__dirname, version+'.flags.json');
const flagsFile = path.join(__dirname, 'flags.temp');

if (!fs.existsSync(tmpfile)) {
exec('"'+nodePath+'" --v8-options', function (execErr, result) {
fs.readFile( flagsFile, function( execErr, result) {
var flags;
if (execErr) {
throw new Error(execErr);
} else {
flags = result.match(/\s\s--(\w+)/gm).map(function (match) {
flags = result.toString().match(/\s\s--(\w+)/gm).map(function (match) {
return match.substring(2);
});
fs.writeFile(tmpfile, JSON.stringify(flags), { encoding:'utf8' },
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
],
"scripts": {
"preinstall": "node --v8-options >> flags.temp",
"install": "node fetch.js",
"test": "mocha -R spec test.js"
},
Expand Down

0 comments on commit afbce3f

Please sign in to comment.