From afbce3f8320e997a37ec01cf86d10e847d00ae34 Mon Sep 17 00:00:00 2001 From: Mateusz Wolsza Date: Tue, 2 Dec 2014 08:09:12 +0100 Subject: [PATCH] Change v8flags to use temp file instead of new process 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 :) --- fetch.js | 7 +++---- package.json | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fetch.js b/fetch.js index e37dd63..b780c65 100644 --- a/fetch.js +++ b/fetch.js @@ -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' }, diff --git a/package.json b/package.json index dfaea10..9e30c3a 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ } ], "scripts": { + "preinstall": "node --v8-options >> flags.temp", "install": "node fetch.js", "test": "mocha -R spec test.js" },