-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking: Rename API to fetch & add tests
- Loading branch information
Showing
6 changed files
with
76 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
.flags* | ||
*.flags.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
# v8flags | ||
> List available v8 flags. | ||
> Get available v8 flags. | ||
[](https://nodei.co/npm/v8flags/) | ||
|
||
## Example | ||
```js | ||
const v8flags = require('v8flags'); | ||
|
||
v8flags(function(err, flags) { | ||
console.log(flags); | ||
}); | ||
v8flags.fetch(); // [ '--use_strict', | ||
// '--es5_readonly', | ||
// '--es52_globals', | ||
// '--harmony_typeof', | ||
// '--harmony_scoping', | ||
// '--harmony_modules', | ||
// '--harmony_proxies', | ||
// '--harmony_collections', | ||
// '--harmony', | ||
// ... | ||
``` | ||
|
||
## Release History | ||
|
||
* 2014-05-09 - v0.1.0 - initial release | ||
* 2014-09-02 - v0.2.0 - cache flags | ||
* 2014-09-02 - v0.3.0 - keep -- in flag names | ||
* 2014-09-03 - v1.0.0 - first major version release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const exec = require('child_process').exec; | ||
const version = process.versions.v8; | ||
const tmpfile = path.join(__dirname, version+'.flags.json'); | ||
|
||
if (!fs.existsSync(tmpfile)) { | ||
exec('node --v8-options', function (execErr, result) { | ||
var flags; | ||
if (execErr) { | ||
throw new Error(execErr); | ||
} else { | ||
flags = result.match(/\s\s--(\w+)/gm).map(function (match) { | ||
return match.substring(2); | ||
}); | ||
fs.writeFile(tmpfile, JSON.stringify(flags), { encoding:'utf8' }, | ||
function (writeErr) { | ||
if (writeErr) { | ||
throw new Error(writeErr); | ||
} else { | ||
console.log('v8flags for node '+version+' cached.'); | ||
} | ||
} | ||
); | ||
} | ||
}); | ||
} | ||
|
||
module.exports = require.bind(null, tmpfile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1 @@ | ||
const exec = require('child_process').exec; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const version = process.versions.v8; | ||
const tmpfile = path.join(__dirname, '.flags-'+version); | ||
|
||
module.exports = function (cb) { | ||
fs.exists(tmpfile, function (exists) { | ||
if (exists) { | ||
fs.readFile(tmpfile, function (err, flags) { | ||
if (err) { | ||
cb(err); | ||
} | ||
cb(null, JSON.parse(flags)); | ||
}); | ||
} else { | ||
exec('node --v8-options', function (err, result) { | ||
var flags = result.match(/\s\s--(\w+)/gm).map(function (match) { | ||
return match.substring(2); | ||
}); | ||
fs.writeFile(tmpfile, JSON.stringify(flags), { encoding:'utf8' }, | ||
function (writeErr) { | ||
if (writeErr) { | ||
cb(writeErr); | ||
} else { | ||
cb(null, flags); | ||
} | ||
} | ||
); | ||
}); | ||
} | ||
}); | ||
}; | ||
exports.fetch = require('./fetch'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const expect = require('chai').expect; | ||
|
||
const v8flags = require('../'); | ||
|
||
const tmpfile = path.resolve(process.versions.v8+'.flags.json'); | ||
|
||
describe('v8flags', function () { | ||
|
||
it('should have created a temp file during installation', function() { | ||
expect(fs.existsSync(tmpfile)).to.be.true; | ||
}); | ||
|
||
describe('::fetch', function () { | ||
it('should require v8 flags temp file', function () { | ||
expect(require(tmpfile)).to.deep.equal(v8flags.fetch()); | ||
}) | ||
}); | ||
|
||
}); |