pax_global_header00006660000000000000000000000064126314344370014521gustar00rootroot0000000000000052 comment=1a54bb8f0804bb449cdeef762d4a9a1df2b64e8e js-v8flags-2.0.11/000077500000000000000000000000001263143443700135665ustar00rootroot00000000000000js-v8flags-2.0.11/.gitignore000066400000000000000000000000321263143443700155510ustar00rootroot00000000000000node_modules *.flags.json js-v8flags-2.0.11/.npmignore000066400000000000000000000000401263143443700155570ustar00rootroot00000000000000*.yml LICENSE README.md test.js js-v8flags-2.0.11/.travis.yml000066400000000000000000000001301263143443700156710ustar00rootroot00000000000000language: node_js node_js: - "0.10" - "0.12" - "iojs" matrix: fast_finish: true js-v8flags-2.0.11/LICENSE000066400000000000000000000020401263143443700145670ustar00rootroot00000000000000Copyright (c) 2014 Tyler Kellen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. js-v8flags-2.0.11/README.md000066400000000000000000000046561263143443700150600ustar00rootroot00000000000000# v8flags [![Build Status](https://secure.travis-ci.org/js-cli/js-v8flags.png)](http://travis-ci.org/js-cli/js-v8flags) [![Build status](https://ci.appveyor.com/api/projects/status/9psgmwayx9kpol1a?svg=true)](https://ci.appveyor.com/project/js-cli/js-v8flags) > Get available v8 flags. [![NPM](https://nodei.co/npm/v8flags.png)](https://nodei.co/npm/v8flags/) ## Example ```js const v8flags = require('v8flags'); v8flags(function (err, results) { console.log(results); // [ '--use_strict', // '--es5_readonly', // '--es52_globals', // '--harmony_typeof', // '--harmony_scoping', // '--harmony_modules', // '--harmony_proxies', // '--harmony_collections', // '--harmony', // ... }); ``` ## Release History * 2015-12-07 - v2.0.11 - cache to temp directory if home is present but unwritable * 2015-07-28 - v2.0.10 - don't throw for electron runtime, just call back with empty array * 2015-06-25 - v2.0.9 - call back with flags even if cache file can't be written * 2015-06-15 - v2.0.7 - revert to 2.0.5 behavior. * 2015-06-15 - v2.0.6 - store cache file in ~/.cache or ~/AppData/Local depending on platform * 2015-04-18 - v2.0.5 - attempt to require config file, if this throws for any reason, fopen w+ and re-create * 2015-04-16 - v2.0.4 - when concurrent processes are run and no config exists, don't append to the cached config. * 2015-03-31 - v2.0.3 - prefer to store config files in user home over tmp * 2015-01-18 - v2.0.2 - keep his dark tentacles contained * 2015-01-15 - v2.0.1 - store temp file in `os.tmpdir()`, drop support for node 0.8 * 2015-01-15 - v2.0.0 - make the stupid thing async * 2014-12-22 - v1.0.8 - exclude `--help` flag * 2014-12-20 - v1.0.7 - pre-cache flags for every version of node from 0.8 to 0.11 * 2014-12-09 - v1.0.6 - revert to 1.0.0 behavior * 2014-11-26 - v1.0.5 - get node executable from `process.execPath` * 2014-11-18 - v1.0.4 - wrap node executable path in quotes * 2014-11-17 - v1.0.3 - get node executable during npm install via `process.env.NODE` * 2014-11-17 - v1.0.2 - get node executable from `process.env._` * 2014-09-03 - v1.0.0 - first major version release * 2014-09-02 - v0.3.0 - keep -- in flag names * 2014-09-02 - v0.2.0 - cache flags * 2014-05-09 - v0.1.0 - initial release js-v8flags-2.0.11/appveyor.yml000066400000000000000000000006331263143443700161600ustar00rootroot00000000000000init: - git config --global core.autocrlf input environment: matrix: - nodejs_version: "0.10" - nodejs_version: "0.12" install: - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) - npm install test_script: - node --version - npm --version # power shell - ps: "npm test # PowerShell" # standard command line - cmd: npm test build: off version: "{build}" js-v8flags-2.0.11/index.js000066400000000000000000000103731263143443700152370ustar00rootroot00000000000000// this entire module is depressing. i should have spent my time learning // how to patch v8 so that these options would just be available on the // process object. const os = require('os'); const fs = require('fs'); const path = require('path'); const execFile = require('child_process').execFile; const env = process.env; const user = env.LOGNAME || env.USER || env.LNAME || env.USERNAME; const configfile = '.v8flags.'+process.versions.v8+'.'+user+'.json'; const exclusions = ['--help']; const failureMessage = [ 'Unable to cache a config file for v8flags to a your home directory', 'or a temporary folder. To fix this problem, please correct your', 'environment by setting HOME=/path/to/home or TEMP=/path/to/temp.', 'NOTE: the user running this must be able to access provided path.', 'If all else fails, please open an issue here:', 'http://github.com/tkellen/js-v8flags' ].join('\n'); function fail (err) { err.message += '\n\n' + failureMessage; return err; } function openConfig (cb) { var userHome = require('user-home'); if (!userHome) { return tryOpenConfig(path.join(os.tmpdir(), configfile), cb); } tryOpenConfig(path.join(userHome, configfile), function (err, fd) { if (err) return tryOpenConfig(path.join(os.tmpdir(), configfile), cb); return cb(null, fd); }); } function tryOpenConfig (configpath, cb) { try { // if the config file is valid, it should be json and therefore // node should be able to require it directly. if this doesn't // throw, we're done! content = require(configpath); process.nextTick(function () { cb(null, content); }); } catch (e) { // if requiring the config file failed, maybe it doesn't exist, or // perhaps it has become corrupted. instead of calling back with the // content of the file, call back with a file descriptor that we can // write the cached data to fs.open(configpath, 'w+', function (err, fd) { if (err) { return cb(err); } return cb(null, fd); }); } } // i can't wait for the day this whole module is obsolete because these // options are available on the process object. this executes node with // `--v8-options` and parses the result, returning an array of command // line flags. function getFlags (cb) { execFile(process.execPath, ['--v8-options'], function (execErr, result) { if (execErr) { return cb(execErr); } var flags = result.match(/\s\s--(\w+)/gm).map(function (match) { return match.substring(2); }).filter(function (name) { return exclusions.indexOf(name) === -1; }); return cb(null, flags); }); } // write some json to a file descriptor. if this fails, call back // with both the error and the data that was meant to be written. function writeConfig (fd, flags, cb) { var buf = new Buffer(JSON.stringify(flags)); return fs.write(fd, buf, 0, buf.length, 0 , function (writeErr) { fs.close(fd, function (closeErr) { var err = writeErr || closeErr; if (err) { return cb(fail(err), flags); } return cb(null, flags); }); }); } module.exports = function (cb) { // bail early if this is not node var isElectron = process.versions && process.versions.electron; if (isElectron) { return process.nextTick(function () { cb(null, []); }); } // attempt to open/read cache file openConfig(function (openErr, result) { if (!openErr && typeof result !== 'number') { return cb(null, result); } // if the result is not an array, we need to go fetch // the flags by invoking node with `--v8-options` getFlags(function (flagsErr, flags) { // if there was an error fetching the flags, bail immediately if (flagsErr) { return cb(flagsErr); } // if there was a problem opening the config file for writing // throw an error but include the flags anyway so that users // can continue to execute (at the expense of having to fetch // flags on every run until they fix the underyling problem). if (openErr) { return cb(fail(openErr), flags); } // write the config file to disk so subsequent runs can read // flags out of a cache file. return writeConfig(result, flags, cb); }); }); }; module.exports.configfile = configfile; js-v8flags-2.0.11/package.json000066400000000000000000000015361263143443700160610ustar00rootroot00000000000000{ "name": "v8flags", "description": "Get available v8 flags.", "version": "2.0.11", "homepage": "https://github.com/tkellen/node-v8flags", "author": { "name": "Tyler Kellen", "url": "http://goingslowly.com/" }, "repository": { "type": "git", "url": "git://github.com/tkellen/node-v8flags.git" }, "bugs": { "url": "https://github.com/tkellen/node-v8flags/issues" }, "licenses": [ { "type": "MIT", "url": "https://github.com/tkellen/node-v8flags/blob/master/LICENSE" } ], "scripts": { "test": "_mocha -R spec test.js" }, "main": "index.js", "engines": { "node": ">= 0.10.0" }, "keywords": [ "v8 flags", "harmony flags" ], "devDependencies": { "async": "^0.9.0", "chai": "~1.9.1", "mocha": "~1.21.4" }, "dependencies": { "user-home": "^1.1.1" } } js-v8flags-2.0.11/test.js000066400000000000000000000062701263143443700151100ustar00rootroot00000000000000const fs = require('fs'); const path = require('path'); const os = require('os'); const async = require('async'); const expect = require('chai').expect; const env = process.env; function eraseHome() { delete env.HOME; delete env.USERPROFILE; delete env.HOMEDRIVE; delete env.HOMEPATH; delete env.LOGNAME; delete env.USER; delete env.LNAME; delete env.USERNAME; } function setTemp(dir) { env.TMPDIR = env.TEMP = env.TMP = dir; } function cleanup () { var v8flags = require('./'); var userHome = require('user-home'); if (userHome === null) userHome = __dirname; var files = [ path.resolve(userHome, v8flags.configfile), path.resolve(os.tmpdir(), v8flags.configfile), ]; files.forEach(function (file) { try { fs.unlinkSync(file); } catch (e) {} }); delete require.cache[require.resolve('user-home')]; delete process.versions.electron; } describe('v8flags', function () { beforeEach(cleanup); afterEach(cleanup); it('should cache and call back with the v8 flags for the running process', function (done) { var v8flags = require('./'); var configfile = path.resolve(require('user-home'), v8flags.configfile); v8flags(function (err, flags) { expect(flags).to.be.a('array'); expect(fs.existsSync(configfile)).to.be.true; fs.unlinkSync(configfile); fs.writeFileSync(configfile, JSON.stringify({cached:true})); v8flags(function (cacheErr, cachedFlags) { expect(cachedFlags).to.deep.equal({cached:true}); done(); }); }); }); it('should not append the file when multiple calls happen concurrently and the config file does not yet exist', function (done) { var v8flags = require('./'); var configfile = path.resolve(require('user-home'), v8flags.configfile); async.parallel([v8flags, v8flags, v8flags], function (err, result) { v8flags(function (err2, res) { done(); }); }); }); it('should fall back to writing to a temp dir if user home can\'t be found', function (done) { eraseHome(); var v8flags = require('./'); var configfile = path.resolve(os.tmpdir(), v8flags.configfile); v8flags(function (err, flags) { expect(fs.existsSync(configfile)).to.be.true; done(); }); }); it('should fall back to writing to a temp dir if user home is unwriteable', function (done) { eraseHome(); env.HOME = path.join(__dirname, 'does-not-exist'); var v8flags = require('./'); var configfile = path.resolve(os.tmpdir(), v8flags.configfile); v8flags(function (err, flags) { expect(fs.existsSync(configfile)).to.be.true; done(); }); }); it('should return flags even if an error is thrown', function (done) { eraseHome(); setTemp('/nope'); var v8flags = require('./'); v8flags(function (err, flags) { expect(err).to.not.be.null; expect(flags).to.not.be.undefined; done(); }); }); it('should back with an empty array if the runtime is electron', function (done) { process.versions.electron = 'set'; var v8flags = require('./'); v8flags(function (err, flags) { expect(flags).to.have.length(0); expect(flags).to.be.an.array; done(); }); }); });