Comparing version 3.1.1 to 3.1.2
@@ -1,15 +0,15 @@ | ||
const os = require('os'); | ||
const path = require('path'); | ||
const userHome = require('homedir-polyfill')(); | ||
var os = require('os'); | ||
var path = require('path'); | ||
var userHome = require('homedir-polyfill')(); | ||
const env = process.env; | ||
const name = 'js-v8flags'; | ||
var env = process.env; | ||
var name = 'js-v8flags'; | ||
function macos () { | ||
const library = path.join(userHome, 'Library'); | ||
function macos() { | ||
var library = path.join(userHome, 'Library'); | ||
return path.join(library, 'Caches', name); | ||
} | ||
function windows () { | ||
const appData = env.LOCALAPPDATA || path.join(userHome, 'AppData', 'Local'); | ||
function windows() { | ||
var appData = env.LOCALAPPDATA || path.join(userHome, 'AppData', 'Local'); | ||
return path.join(appData, name); | ||
@@ -19,8 +19,8 @@ } | ||
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html | ||
function linux () { | ||
const username = path.basename(userHome); | ||
function linux() { | ||
var username = path.basename(userHome); | ||
return path.join(env.XDG_CACHE_HOME || path.join(userHome, '.cache'), name); | ||
} | ||
module.exports = function (platform) { | ||
module.exports = function(platform) { | ||
if (!userHome) { | ||
@@ -27,0 +27,0 @@ return os.tmpdir(); |
74
index.js
@@ -5,19 +5,19 @@ // this entire module is depressing. i should have spent my time learning | ||
const os = require('os'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const crypto = require('crypto'); | ||
const execFile = require('child_process').execFile; | ||
const configPath = require('./config-path.js')(process.platform); | ||
const version = require("./package.json").version; | ||
const env = process.env; | ||
const user = env.LOGNAME || env.USER || env.LNAME || env.USERNAME || ''; | ||
const exclusions = ['--help']; | ||
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']; | ||
// This number must be incremented whenever the generated cache file changes. | ||
const CACHE_VERSION = 1; | ||
var CACHE_VERSION = 1; | ||
const configfile = '.v8flags-'+CACHE_VERSION+'-'+process.versions.v8+'.'+crypto.createHash('md5').update(user).digest('hex')+'.json'; | ||
var configfile = '.v8flags-' + CACHE_VERSION + '-' + process.versions.v8 + '.' + crypto.createHash('md5').update(user).digest('hex') + '.json'; | ||
const failureMessage = [ | ||
var failureMessage = [ | ||
'Unable to cache a config file for v8flags to your home directory', | ||
@@ -28,6 +28,6 @@ 'or a temporary folder. To fix this problem, please correct your', | ||
'If all else fails, please open an issue here:', | ||
'http://github.com/tkellen/js-v8flags' | ||
'http://github.com/tkellen/js-v8flags', | ||
].join('\n'); | ||
function fail (err) { | ||
function fail(err) { | ||
err.message += '\n\n' + failureMessage; | ||
@@ -37,12 +37,14 @@ 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); | ||
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) { | ||
function tryOpenConfig(configpath, cb) { | ||
try { | ||
@@ -53,3 +55,3 @@ // if the config file is valid, it should be json and therefore | ||
var content = require(configpath); | ||
process.nextTick(function () { | ||
process.nextTick(function() { | ||
cb(null, content); | ||
@@ -62,3 +64,3 @@ }); | ||
// write the cached data to | ||
fs.open(configpath, 'w+', function (err, fd) { | ||
fs.open(configpath, 'w+', function(err, fd) { | ||
if (err) { | ||
@@ -77,3 +79,3 @@ return cb(err); | ||
function normalizeFlagName(flag) { | ||
return "--" + flag.slice(4).replace(/-/g, "_"); | ||
return '--' + flag.slice(4).replace(/-/g, '_'); | ||
} | ||
@@ -85,4 +87,4 @@ | ||
// line flags. | ||
function getFlags (cb) { | ||
execFile(process.execPath, ['--v8-options'], function (execErr, result) { | ||
function getFlags(cb) { | ||
execFile(process.execPath, ['--v8-options'], function(execErr, result) { | ||
if (execErr) { | ||
@@ -93,3 +95,3 @@ return cb(execErr); | ||
.map(normalizeFlagName) | ||
.filter(function (name) { | ||
.filter(function(name) { | ||
return exclusions.indexOf(name) === -1; | ||
@@ -103,3 +105,3 @@ }); | ||
// with both the error and the data that was meant to be written. | ||
function writeConfig (fd, flags, cb) { | ||
function writeConfig(fd, flags, cb) { | ||
var json = JSON.stringify(flags); | ||
@@ -114,7 +116,9 @@ var buf; | ||
// and code rewrite, it never happens as json is always a string here. | ||
if (typeof json === 'number') throw new Error('Unexpected type number'); | ||
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) { | ||
return fs.write(fd, buf, 0, buf.length, 0 , function(writeErr) { | ||
fs.close(fd, function(closeErr) { | ||
var err = writeErr || closeErr; | ||
@@ -129,7 +133,7 @@ if (err) { | ||
module.exports = function (cb) { | ||
module.exports = function(cb) { | ||
// bail early if this is not node | ||
var isElectron = process.versions && process.versions.electron; | ||
if (isElectron) { | ||
return process.nextTick(function () { | ||
return process.nextTick(function() { | ||
cb(null, []); | ||
@@ -140,3 +144,3 @@ }); | ||
// attempt to open/read cache file | ||
openConfig(function (openErr, result) { | ||
openConfig(function(openErr, result) { | ||
if (!openErr && typeof result !== 'number') { | ||
@@ -147,3 +151,3 @@ return cb(null, result); | ||
// the flags by invoking node with `--v8-options` | ||
getFlags(function (flagsErr, flags) { | ||
getFlags(function(flagsErr, flags) { | ||
// if there was an error fetching the flags, bail immediately | ||
@@ -150,0 +154,0 @@ if (flagsErr) { |
{ | ||
"name": "v8flags", | ||
"version": "3.1.2", | ||
"description": "Get available v8 flags.", | ||
"version": "3.1.1", | ||
"homepage": "https://github.com/tkellen/node-v8flags", | ||
"author": { | ||
"name": "Tyler Kellen", | ||
"url": "http://goingslowly.com/" | ||
"author": "Gulp Team <team@gulpjs.com> (http://gulpjs.com/)", | ||
"contributors": [ | ||
"Tyler Kellen <tyler@sleekcode.net>", | ||
"Blaine Bublitz <blaine.bublitz@gmail.com>", | ||
"Nicolò Ribaudo <nicolo.ribaudo@gmail.com>", | ||
"Selwyn <talk@selwyn.cc>", | ||
"Leo Zhang <leo@leozhang.me>" | ||
], | ||
"repository": "gulpjs/v8flags", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">= 0.10" | ||
}, | ||
"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" | ||
} | ||
"main": "index.js", | ||
"files": [ | ||
"index.js", | ||
"config-path.js", | ||
"LICENSE" | ||
], | ||
"scripts": { | ||
"test": "mocha -R spec test.js" | ||
"lint": "eslint .", | ||
"pretest": "npm run lint", | ||
"test": "mocha --async-only", | ||
"cover": "istanbul cover _mocha --report lcovonly", | ||
"coveralls": "npm run cover && istanbul-coveralls" | ||
}, | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
"dependencies": { | ||
"homedir-polyfill": "^1.0.1" | ||
}, | ||
"keywords": [ | ||
"v8 flags", | ||
"harmony flags" | ||
], | ||
"devDependencies": { | ||
"async": "^2.5.0", | ||
"chai": "^4.1.0", | ||
"mocha": "^3.4.2", | ||
"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" | ||
}, | ||
"dependencies": { | ||
"homedir-polyfill": "^1.0.1" | ||
} | ||
"keywords": [ | ||
"v8 flags", | ||
"harmony flags" | ||
] | ||
} |
101
README.md
@@ -1,55 +0,64 @@ | ||
# 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. | ||
<p align="center"> | ||
<a href="http://gulpjs.com"> | ||
<img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png"> | ||
</a> | ||
</p> | ||
[![NPM](https://nodei.co/npm/v8flags.png)](https://nodei.co/npm/v8flags/) | ||
# v8flags | ||
## Example | ||
[![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 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', | ||
// ... | ||
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 | ||
## API | ||
* 2018-06-01 - v3.1.1 - Add version to the cache file name | ||
* 2018-05-13 - v3.1.0 - Add support for node 10 | ||
* 2018-02-26 - v3.0.2 - fix typo in the failure message | ||
* 2017-09-24 - v3.0.1 - fix home directory lookup behavior & fallback | ||
* 2017-07-14 - v3.0.0 - store cached config to operating system specific directories | ||
* 2017-04-18 - v2.1.1 - default to an empty user | ||
* 2017-04-18 - v2.1.0 - hash username to support invalid path characters | ||
* 2017-03-31 - v2.0.12 - don't pollute global namespace | ||
* 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 | ||
### `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 |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
176
65
10328
8
1
1
5