pax_global_header00006660000000000000000000000064136650271520014521gustar00rootroot0000000000000052 comment=8e6b0a2e424eba308698f703fe92bdf372e9621c v8flags-3.2.0/000077500000000000000000000000001366502715200130755ustar00rootroot00000000000000v8flags-3.2.0/.editorconfig000066400000000000000000000003261366502715200155530ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true end_of_line = lf [*.md] trim_trailing_whitespace = false v8flags-3.2.0/.eslintrc000066400000000000000000000001031366502715200147130ustar00rootroot00000000000000{ "extends": "gulp", "globals": { "Uint8Array": true } } v8flags-3.2.0/.gitattributes000066400000000000000000000000161366502715200157650ustar00rootroot00000000000000* text eol=lf v8flags-3.2.0/.gitignore000066400000000000000000000011631366502715200150660ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript # Garbage files .DS_Store *.flags.json v8flags-3.2.0/.npmrc000066400000000000000000000000231366502715200142100ustar00rootroot00000000000000package-lock=false v8flags-3.2.0/.travis.yml000066400000000000000000000002131366502715200152020ustar00rootroot00000000000000sudo: false language: node_js node_js: - '12' - '10' - '8' - '6' - '4' - '0.12' - '0.10' after_script: - npm run coveralls v8flags-3.2.0/LICENSE000066400000000000000000000022421366502715200141020ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014-2018 Tyler Kellen , Blaine Bublitz , and Eric Schoffstall 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. v8flags-3.2.0/README.md000066400000000000000000000034531366502715200143610ustar00rootroot00000000000000

# v8flags [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] Get available v8 and Node.js flags. ## Usage ```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', // ... }); ``` ## API ### `v8flags(cb)` Finds the available flags and calls the passed callback with any errors and an array of flag results. ### `v8flags.configfile` The name of the cache file for flags. ### `v8flags.configPath` The filepath location of the `configfile` above. ## License MIT [downloads-image]: http://img.shields.io/npm/dm/v8flags.svg [npm-url]: https://www.npmjs.com/package/v8flags [npm-image]: http://img.shields.io/npm/v/v8flags.svg [travis-url]: https://travis-ci.org/gulpjs/v8flags [travis-image]: http://img.shields.io/travis/gulpjs/v8flags.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/v8flags [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/v8flags.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/v8flags [coveralls-image]: http://img.shields.io/coveralls/gulpjs/v8flags/master.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg v8flags-3.2.0/appveyor.yml000066400000000000000000000010661366502715200154700ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml # http://www.appveyor.com/docs/lang/nodejs-iojs environment: matrix: # node.js - nodejs_version: "0.10" - nodejs_version: "0.12" - nodejs_version: "4" - nodejs_version: "6" - nodejs_version: "8" - nodejs_version: "10" install: - ps: Install-Product node $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 # build version format version: "{build}" v8flags-3.2.0/config-path.js000066400000000000000000000015121366502715200156310ustar00rootroot00000000000000var os = require('os'); var path = require('path'); var userHome = require('homedir-polyfill')(); var env = process.env; var name = 'js-v8flags'; function macos() { var library = path.join(userHome, 'Library'); return path.join(library, 'Caches', name); } function windows() { var appData = env.LOCALAPPDATA || path.join(userHome, 'AppData', 'Local'); return path.join(appData, name); } // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html function linux() { var username = path.basename(userHome); return path.join(env.XDG_CACHE_HOME || path.join(userHome, '.cache'), name); } module.exports = function(platform) { if (!userHome) { return os.tmpdir(); } if (platform === 'darwin') { return macos(); } if (platform === 'win32') { return windows(); } return linux(); }; v8flags-3.2.0/index.js000066400000000000000000000134051366502715200145450ustar00rootroot00000000000000// 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. var os = require('os'); var fs = require('fs'); var path = require('path'); var crypto = require('crypto'); var execFile = require('child_process').execFile; var configPath = require('./config-path.js')(process.platform); var version = require('./package.json').version; var env = process.env; var user = env.LOGNAME || env.USER || env.LNAME || env.USERNAME || ''; var exclusions = ['--help', '--completion_bash']; // This number must be incremented whenever the generated cache file changes. var CACHE_VERSION = 2; var configfile = '.v8flags-' + CACHE_VERSION + '-' + process.versions.v8 + '.' + crypto.createHash('md5').update(user).digest('hex') + '.json'; var failureMessage = [ 'Unable to cache a config file for v8flags to 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) { fs.mkdir(configPath, function() { tryOpenConfig(path.join(configPath, 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! var 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); }); } } // Node <= 9 outputs _ in flags with multiple words, while node 10 // uses -. Both ways are accepted anyway, so always use `_` for better // compatibility. // We must not replace the first two --. function normalizeFlagName(flag) { return '--' + flag.slice(4).replace(/-/g, '_'); } // 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) { var errored = false; var pending = 0; var flags = []; runNode('--help'); runNode('--v8-options'); function runNode(option) { pending++; execFile(process.execPath, [option], function(execErr, result) { if (execErr || errored) { if (!errored) { errored = true; cb(execErr); } return; } var index = result.indexOf('\nOptions:'); if (index >= 0) { var regexp = /^\s\s--[\w-]+/gm; regexp.lastIndex = index; var matchedFlags = result.match(regexp); if (matchedFlags) { flags = flags.concat(matchedFlags .map(normalizeFlagName) .filter(function(name) { return exclusions.indexOf(name) === -1; }) ); } } if (--pending === 0) { 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 json = JSON.stringify(flags); var buf; if (Buffer.from && Buffer.from !== Uint8Array.from) { // Node.js 4.5.0 or newer buf = Buffer.from(json); } else { // Old Node.js versions // The typeof safeguard below is mostly against accidental copy-pasting // and code rewrite, it never happens as json is always a string here. if (typeof json === 'number') { throw new Error('Unexpected type number'); } buf = new Buffer(json); } 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; module.exports.configPath = configPath; v8flags-3.2.0/package.json000066400000000000000000000022211366502715200153600ustar00rootroot00000000000000{ "name": "v8flags", "version": "3.2.0", "description": "Get available v8 and Node.js flags.", "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ "Tyler Kellen ", "Blaine Bublitz ", "Nicolò Ribaudo ", "Selwyn ", "Leo Zhang " ], "repository": "gulpjs/v8flags", "license": "MIT", "engines": { "node": ">= 0.10" }, "main": "index.js", "files": [ "index.js", "config-path.js", "LICENSE" ], "scripts": { "lint": "eslint .", "pretest": "npm run lint", "test": "mocha --async-only", "cover": "istanbul cover _mocha --report lcovonly", "coveralls": "npm run cover && istanbul-coveralls" }, "dependencies": { "homedir-polyfill": "^1.0.1" }, "devDependencies": { "async": "^2.5.0", "eslint": "^2.13.0", "eslint-config-gulp": "^3.0.1", "expect": "^1.20.2", "istanbul": "^0.4.3", "istanbul-coveralls": "^1.0.3", "mocha": "^3.5.3", "proxyquire": "^1.8.0" }, "keywords": [ "v8 flags", "harmony flags" ] } v8flags-3.2.0/test/000077500000000000000000000000001366502715200140545ustar00rootroot00000000000000v8flags-3.2.0/test/.eslintrc000066400000000000000000000000351366502715200156760ustar00rootroot00000000000000{ "extends": "gulp/test" } v8flags-3.2.0/test/fake-bin000077500000000000000000000000001366502715200154440ustar00rootroot00000000000000v8flags-3.2.0/test/index.js000066400000000000000000000153251366502715200155270ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var os = require('os'); var async = require('async'); var expect = require('expect'); var proxyquire = require('proxyquire'); var 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; delete env.XDG_CACHE_HOME; delete env.LOCALAPPDATA; } var tmpdir = env.TMPDIR; var temp = env.TEMP; var tmp = env.TMP; function setTemp(dir) { env.TMPDIR = env.TEMP = env.TMP = dir; } function resetTemp() { env.TMPDIR = tmpdir; env.TEMP = temp; env.TMP = tmp; } function cleanup() { var v8flags = require('../'); var files = [ path.resolve(v8flags.configPath, v8flags.configfile), path.resolve(os.tmpdir(), v8flags.configfile), ]; files.forEach(function(file) { try { fs.unlinkSync(file); } catch (e) { // Ignore error } }); delete require.cache[require.resolve('../')]; delete require.cache[require.resolve('../config-path')]; delete require.cache[require.resolve('homedir-polyfill')]; 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(v8flags.configPath, v8flags.configfile); v8flags(function(err, flags) { expect(flags).toBeAn('array'); expect(fs.existsSync(configfile)).toEqual(true); fs.unlinkSync(configfile); fs.writeFileSync(configfile, JSON.stringify({ cached: true })); v8flags(function(cacheErr, cachedFlags) { expect(cachedFlags).toEqual({ 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(v8flags.configPath, 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 is unwriteable', function(done) { eraseHome(); env.HOME = env.LOCALAPPDATA = 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)).toEqual(true); done(); }); }); it('should return flags even if an error is thrown', function(done) { eraseHome(); setTemp('/nope'); env.HOME = env.LOCALAPPDATA = null; var v8flags = require('../'); v8flags(function(err, flags) { resetTemp(); expect(err).toNotBe(null); expect(flags).toNotBe(undefined); done(); }); }); it('will not throw on non-matching return from node --v8-options', function(done) { if (os.platform() === 'win32') { this.skip(); } eraseHome(); var v8flags = require('../'); // Save original execPath var execPath = process.execPath; // Set execPath to our fake-bin process.execPath = __dirname + '/fake-bin'; v8flags(function(err, flags) { expect(err).toNotExist(); expect(flags).toEqual([]); // Restore original execPath process.execPath = execPath; 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.length).toEqual(0); expect(flags).toBeAn('array'); done(); }); }); it('should handle usernames which are invalid file paths', function(done) { eraseHome(); env.USER = 'invalid/user\\name'; var v8flags = require('../'); v8flags(function(err, flags) { expect(err).toBe(null); done(); }); }); it('should handle option names with multiple words', function(done) { if (parseInt(process.versions.node) < 4) { this.skip(); } eraseHome(); var v8flags = require('../'); v8flags(function(err, flags) { expect(flags).toInclude('--expose_gc_as'); done(); }); }); it('should handle undefined usernames', function(done) { eraseHome(); var v8flags = require('../'); v8flags(function(err, flags) { expect(err).toBe(null); done(); }); }); it('should detect non-v8 flags', function(done) { eraseHome(); var v8flags = require('../'); v8flags(function(err, flags) { expect(flags).toInclude('--no_deprecation'); done(); }); }); it('does not detect colliding flags from node', function(done) { eraseHome(); var v8flags = require('../'); v8flags(function(err, flags) { expect(flags).toNotInclude('--exec'); expect(flags).toNotInclude('--print'); expect(flags).toNotInclude('--interactive'); expect(flags).toNotInclude('--require'); expect(flags).toNotInclude('--version'); done(); }); }); }); describe('config-path', function() { var moduleName = 'js-v8flags'; before(function() { env.HOME = env.USERPROFILE = 'somehome'; }); after(cleanup); it('should return default linux path in other environments', function(done) { var configPath = require('../config-path.js')('other'); expect(configPath).toEqual( path.join(env.HOME, '.cache', moduleName) ); done(); }); it('should return default macos path in darwin environment', function(done) { var configPath = require('../config-path.js')('darwin'); expect(configPath).toEqual( path.join(env.HOME, 'Library', 'Caches', moduleName) ); done(); }); it('should return default windows path in win32 environment', function(done) { var configPath = require('../config-path.js')('win32'); expect(configPath).toEqual( path.join(env.HOME, 'AppData', 'Local', moduleName) ); done(); }); it('should return fallback path when homedir is falsy', function(done) { var configPath = proxyquire('../config-path.js', { 'homedir-polyfill': function() { return null; }, })('win32'); expect(configPath).toEqual(os.tmpdir()); done(); }); }); describe('platform specific tests', function() { before(cleanup); it('should return fallback path when no home is found under windows', function(done) { if (os.platform() !== 'win32' || !process.version.match(/0\.10|0\.12/)) { this.skip(); } eraseHome(); var configPath = require('../config-path.js')('win32'); expect(configPath).toEqual(os.tmpdir()); done(); }); });