Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
123de49d9c | ||
|
|
7cd574d7bc | ||
|
|
45c8c29cdf | ||
|
|
5b08924c02 |
20
README.md
20
README.md
@@ -172,8 +172,9 @@ to5.transformFile("filename.js", options, function (err, result) {
|
||||
|
||||
#### Require hook
|
||||
|
||||
All subsequent files required by node will be transformed by 6to5. The polyfill
|
||||
specified in [Polyfill](#polyfill) is also required.
|
||||
All subsequent files required by node with the extensions `.es6` and `.js` will
|
||||
be transformed by 6to5. The polyfill specified in [Polyfill](#polyfill) is also
|
||||
required.
|
||||
|
||||
```javascript
|
||||
require("6to5/register");
|
||||
@@ -183,7 +184,20 @@ require("6to5/register");
|
||||
override this by passing an ignore regex via:
|
||||
|
||||
```javascript
|
||||
require("6to5/register")(/regex/)
|
||||
require("6to5/register")(/regex/);
|
||||
```
|
||||
|
||||
You can also customise the file extensions that the require hook will use via:
|
||||
|
||||
```javascript
|
||||
require("6to5/register")({
|
||||
// optional ignore regex
|
||||
ignoreRegex: /regex/,
|
||||
|
||||
// this will remove the currently hooked extensions of .es6 and .js so you'll
|
||||
// have to add them back if you want them to be used again
|
||||
extensions: [".js", ".es6"]
|
||||
});
|
||||
```
|
||||
|
||||
### Browser
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
var commander = require("commander");
|
||||
var Module = require("module");
|
||||
var path = require("path");
|
||||
var util = require("../lib/6to5/util");
|
||||
var path = require("path");
|
||||
var repl = require("repl");
|
||||
@@ -12,13 +11,29 @@ var _ = require("lodash");
|
||||
|
||||
commander.option("-e, --eval [script]", "evaluate script");
|
||||
commander.option("-p, --print", "evaluate script and print result");
|
||||
commander.option("-i, --ignore [regex]", "ignore all files that match this regex when using the require hook");
|
||||
commander.option("-x, --extensions [extensions]", "list of extensions to hook into [.es6,.js]", util.list);
|
||||
|
||||
var pkg = require("../package.json");
|
||||
commander.version(pkg.version);
|
||||
commander.usage("[options] [ -e script | script.js ] [arguments]");
|
||||
commander.parse(process.argv);
|
||||
|
||||
to5.register();
|
||||
//
|
||||
|
||||
var registerOpts = {};
|
||||
|
||||
if (commander.ignore) {
|
||||
registerOpts.ignoreRegex = new RegExp(commander.ignore);
|
||||
}
|
||||
|
||||
if (commander.extensions && commander.extensions.length) {
|
||||
registerOpts.extensions = commander.extensions
|
||||
}
|
||||
|
||||
to5.register(registerOpts);
|
||||
|
||||
//
|
||||
|
||||
var _eval = function (code, filename) {
|
||||
code = to5.transform(code, { filename: filename }).code;
|
||||
|
||||
@@ -5,6 +5,8 @@ var sourceMap = require("source-map");
|
||||
var transform = require("../../lib/6to5/transform");
|
||||
var chokidar = require("chokidar");
|
||||
var mkdirp = require("mkdirp");
|
||||
var util2 = require("../../lib/6to5/util");
|
||||
var util = require("./util");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
@@ -14,12 +16,8 @@ commander.option("-s, --source-maps", "Save source map alongside the compiled co
|
||||
commander.option("-f, --filename [filename]", "Filename to use when reading from stdin - this will be used in source-maps, errors etc [stdin]", "stdin");
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
|
||||
var list = function (val) {
|
||||
return val ? val.split(",") : [];
|
||||
};
|
||||
|
||||
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", list);
|
||||
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", list);
|
||||
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util2.list);
|
||||
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util2.list);
|
||||
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
|
||||
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@ var _ = require("lodash");
|
||||
|
||||
exports.util = require("./util");
|
||||
|
||||
exports.register = function () {
|
||||
return require("./register");
|
||||
exports.register = function (opts) {
|
||||
var register = require("./register");
|
||||
if (opts != null) register(opts);
|
||||
return register;
|
||||
};
|
||||
|
||||
exports.polyfill = function () {
|
||||
|
||||
@@ -2,6 +2,7 @@ require("./polyfill");
|
||||
|
||||
var sourceMapSupport = require("source-map-support");
|
||||
var to5 = require("./index");
|
||||
var _ = require("lodash");
|
||||
|
||||
sourceMapSupport.install({
|
||||
retrieveSourceMap: function (source) {
|
||||
@@ -17,12 +18,14 @@ sourceMapSupport.install({
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
var ignoreRegex = /node_modules/;
|
||||
var exts = [];
|
||||
var maps = {};
|
||||
var old = require.extensions[".js"];
|
||||
|
||||
require.extensions[".js"] =
|
||||
require.extensions[".es6"] = function (m, filename) {
|
||||
var loader = function (m, filename) {
|
||||
if (ignoreRegex && ignoreRegex.test(filename)) {
|
||||
return old.apply(this, arguments);
|
||||
}
|
||||
@@ -36,6 +39,27 @@ require.extensions[".es6"] = function (m, filename) {
|
||||
m._compile(result.code, filename);
|
||||
};
|
||||
|
||||
module.exports = function (_ignoreRegex) {
|
||||
ignoreRegex = _ignoreRegex;
|
||||
var hookExtensions = function (_exts) {
|
||||
_.each(exts, function (ext) {
|
||||
delete require.extensions[ext];
|
||||
});
|
||||
|
||||
exts = _exts;
|
||||
|
||||
_.each(exts, function (ext) {
|
||||
require.extensions[ext] = loader;
|
||||
});
|
||||
};
|
||||
|
||||
hookExtensions([".es6", ".js"]);
|
||||
|
||||
module.exports = function (opts) {
|
||||
opts = opts || {};
|
||||
if (_.isRegExp(opts)) opts = { ignoreRegex: opts };
|
||||
|
||||
if (opts.ignoreRegex != null) {
|
||||
ignoreRegex = opts.ignoreRegex;
|
||||
}
|
||||
|
||||
if (opts.extensions) hookExtensions(opts.extensions);
|
||||
};
|
||||
|
||||
@@ -20,6 +20,10 @@ exports.ensureBlock = function (node) {
|
||||
node.body = b.blockStatement(block);
|
||||
};
|
||||
|
||||
exports.list = function (val) {
|
||||
return val ? val.split(",") : [];
|
||||
};
|
||||
|
||||
exports.getUid = function (parent, file) {
|
||||
var node;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "1.9.5",
|
||||
"version": "1.9.6",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/sebmck/6to5",
|
||||
"repository": {
|
||||
@@ -51,13 +51,13 @@
|
||||
"es6-transpiler": "0.7.17",
|
||||
"istanbul": "0.3.2",
|
||||
"matcha": "0.5.0",
|
||||
"mocha": "1.21.4",
|
||||
"traceur": "0.0.66",
|
||||
"mocha": "1.21.5",
|
||||
"traceur": "0.0.67",
|
||||
"esnext": "0.11.1",
|
||||
"es6now": "0.8.11",
|
||||
"jstransform": "6.3.2",
|
||||
"uglify-js": "2.4.15",
|
||||
"browserify": "6.0.3",
|
||||
"browserify": "6.1.0",
|
||||
"proclaim": "2.0.0",
|
||||
"rimraf": "2.2.8",
|
||||
"jshint": "2.5.6"
|
||||
|
||||
Reference in New Issue
Block a user