6.0.0
I'm extremely stupid and didn't commit as I go. To anyone reading this I'm extremely sorry. A lot of these changes are very broad and I plan on releasing Babel 6.0.0 today live on stage at Ember Camp London so I'm afraid I couldn't wait. If you're ever in London I'll buy you a beer (or assorted beverage!) to make up for it, also I'll kiss your feet and give you a back massage, maybe.
This commit is contained in:
@@ -15,10 +15,11 @@ let program = new commander.Command("babel-node");
|
||||
|
||||
program.option("-e, --eval [script]", "Evaluate script");
|
||||
program.option("-p, --print [code]", "Evaluate script and print result");
|
||||
program.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
|
||||
program.option("-o, --only [globs]", "");
|
||||
program.option("-i, --ignore [globs]", "");
|
||||
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]");
|
||||
program.option("-w, --plugins [string]", "TODO", util.list);
|
||||
program.option("-b, --presets [string]", "TODO", util.list);
|
||||
program.option("-w, --plugins [string]", "", util.list);
|
||||
program.option("-b, --presets [string]", "", util.list);
|
||||
|
||||
let pkg = require("../package.json");
|
||||
program.version(pkg.version);
|
||||
@@ -28,24 +29,24 @@ program.parse(process.argv);
|
||||
//
|
||||
|
||||
register({
|
||||
extensions: program.extensions,
|
||||
optional: program.optional,
|
||||
ignore: program.ignore,
|
||||
plugins: program.plugins,
|
||||
presets: program.presets,
|
||||
extensions: program.extensions,
|
||||
ignore: program.ignore,
|
||||
only: program.only,
|
||||
plugins: program.plugins,
|
||||
presets: program.presets,
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
let replPlugin = new babel.Plugin("repl", {
|
||||
let replPlugin = () => ({
|
||||
visitor: {
|
||||
ModuleDeclaration() {
|
||||
throw this.errorWithNode("Modules aren't supported in the REPL");
|
||||
ModuleDeclaration(path) {
|
||||
throw path.buildCodeFrameError("Modules aren't supported in the REPL");
|
||||
},
|
||||
|
||||
VariableDeclaration(node) {
|
||||
if (node.kind !== "var") {
|
||||
throw this.errorWithNode("Only `var` variables are supported in the REPL");
|
||||
VariableDeclaration(path) {
|
||||
if (path.node.kind !== "var") {
|
||||
throw path.buildCodeFrameError("Only `var` variables are supported in the REPL");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,11 +60,8 @@ let _eval = function (code, filename) {
|
||||
|
||||
code = babel.transform(code, {
|
||||
filename: filename,
|
||||
blacklist: program.blacklist,
|
||||
whitelist: program.whitelist,
|
||||
optional: program.optional,
|
||||
stage: program.stage,
|
||||
plugins: [replPlugin]
|
||||
presets: program.presets,
|
||||
plugins: (program.plugins || []).concat([replPlugin])
|
||||
}).code;
|
||||
|
||||
return vm.runInThisContext(code, {
|
||||
|
||||
@@ -18,7 +18,7 @@ if (argSeparator > -1) {
|
||||
babelArgs = babelArgs.slice(0, argSeparator);
|
||||
}
|
||||
|
||||
getV8Flags(function (v8Flags) {
|
||||
getV8Flags(function (err, v8Flags) {
|
||||
babelArgs.forEach(function(arg){
|
||||
let flag = arg.split("=")[0];
|
||||
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
import pathExists from "path-exists";
|
||||
import readline from "readline";
|
||||
import child from "child_process";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
function spawn(cmd, args, callback) {
|
||||
console.log(">", cmd, args);
|
||||
|
||||
let spawn = child.spawn(cmd, args, { stdio: "inherit" });
|
||||
|
||||
spawn.on("exit", function (code) {
|
||||
if (code === 0) {
|
||||
callback();
|
||||
} else {
|
||||
console.log("Killing...");
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function spawnMultiple(cmds) {
|
||||
function next() {
|
||||
let cmd = cmds.shift();
|
||||
if (cmd) {
|
||||
spawn(cmd.command, cmd.args, next);
|
||||
} else {
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
function template(name, data = {}) {
|
||||
let source = fs.readFileSync(path.join(__dirname, "templates", name), "utf8");
|
||||
source = source.replace(/[A-Z_]+/g, function (key) {
|
||||
return data[key] === undefined ? key : data[key];
|
||||
});
|
||||
return source;
|
||||
}
|
||||
|
||||
function write(filename, content) {
|
||||
console.log(filename);
|
||||
fs.writeFileSync(filename, content);
|
||||
}
|
||||
|
||||
function execMaybe(cmd) {
|
||||
try {
|
||||
return child.execSync(cmd).toString();
|
||||
} catch (err) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
let rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
let BABEL_PLUGIN_PREFIX = "babel-plugin-";
|
||||
|
||||
let cmds = {
|
||||
init: function () {
|
||||
let name = path.basename(process.cwd());
|
||||
|
||||
if (name.indexOf(BABEL_PLUGIN_PREFIX) === 0) {
|
||||
name = name.slice(BABEL_PLUGIN_PREFIX.length);
|
||||
}
|
||||
|
||||
rl.question("Description (optional): ", function (description) {
|
||||
let remote = execMaybe("git config --get remote.origin.url").trim().match(/git@github.com:(.*?).git/);
|
||||
if (remote) {
|
||||
build(description, remote[1]);
|
||||
} else {
|
||||
rl.question("GitHub Repository (eg. sebmck/babel-plugin-foobar) (optional): ", function (repo) {
|
||||
build(description, repo);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function build(description, repo) {
|
||||
rl.close();
|
||||
|
||||
let templateData = {
|
||||
DESCRIPTION: description,
|
||||
FULL_NAME: BABEL_PLUGIN_PREFIX + name,
|
||||
NAME: name
|
||||
};
|
||||
|
||||
write("package.json", JSON.stringify({
|
||||
name: templateData.FULL_NAME,
|
||||
version: "1.0.0",
|
||||
description: templateData.DESCRIPTION,
|
||||
repository: repo || undefined,
|
||||
license: "MIT",
|
||||
main: "lib/index.js",
|
||||
|
||||
devDependencies: {
|
||||
babel: "^5.6.0"
|
||||
},
|
||||
|
||||
scripts: {
|
||||
build: "babel-plugin build",
|
||||
push: "babel-plugin publish",
|
||||
test: "babel-plugin test"
|
||||
},
|
||||
|
||||
keywords: ["babel-plugin"]
|
||||
}, null, " ") + "\n");
|
||||
|
||||
write(".npmignore", "node_modules\n*.log\nsrc\n");
|
||||
|
||||
write(".gitignore", "node_modules\n*.log\nlib\n");
|
||||
|
||||
write("README.md", template("README.md", templateData));
|
||||
|
||||
write("LICENSE", template("LICENSE", {
|
||||
AUTHOR_EMAIL: execMaybe("git config --get user.email").trim(),
|
||||
AUTHOR_NAME: execMaybe("git config --get user.name").trim(),
|
||||
YEAR: new Date().getFullYear()
|
||||
}));
|
||||
|
||||
if (!pathExists.sync("src")) {
|
||||
fs.mkdirSync("src");
|
||||
write("src/index.js", template("index.js", templateData));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
build: function () {
|
||||
spawn("babel", ["src", "--out-dir", "lib", "--copy-files"], process.exit);
|
||||
},
|
||||
|
||||
publish: function () {
|
||||
let pkg = require(process.cwd() + "/package.json");
|
||||
console.log("Current version:", pkg.version);
|
||||
|
||||
rl.question("New version (enter nothing for patch): ", function (newVersion) {
|
||||
rl.close();
|
||||
|
||||
newVersion = newVersion || "patch";
|
||||
|
||||
spawnMultiple([
|
||||
{ command: "git", args: ["pull"] },
|
||||
{ command: "git", args: ["push"] },
|
||||
{ command: "babel-plugin", args: ["build"] },
|
||||
{ command: "npm", args: ["version", newVersion] },
|
||||
{ command: "npm", args: ["publish"] },
|
||||
{ command: "git", args: ["push", "--follow-tags"] }
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
let cmd = cmds[process.argv[2]];
|
||||
if (cmd) {
|
||||
cmd();
|
||||
} else {
|
||||
console.error("Unknown command:", cmd);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
Copyright (c) YEAR AUTHOR_NAME <AUTHOR_EMAIL>
|
||||
|
||||
MIT License
|
||||
|
||||
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.
|
||||
@@ -1,35 +0,0 @@
|
||||
# FULL_NAME
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ npm install FULL_NAME
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["NAME"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
$ babel --plugins NAME script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("babel-core").transform("code", {
|
||||
plugins: ["NAME"]
|
||||
});
|
||||
```
|
||||
@@ -1,8 +0,0 @@
|
||||
/* eslint no-unused-vars:0 */
|
||||
export default function ({ Plugin, types: t }) {
|
||||
return new Plugin("NAME", {
|
||||
visitor: {
|
||||
// your visitor methods go here
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -20,6 +20,7 @@ module.exports = function (commander, filenames) {
|
||||
});
|
||||
if (!commander.copyFiles && data.ignored) return;
|
||||
|
||||
// we've requested explicit sourcemaps to be written to disk
|
||||
if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||
let mapLoc = dest + ".map";
|
||||
data.code = util.addSourceMappingUrl(data.code, mapLoc);
|
||||
@@ -27,6 +28,7 @@ module.exports = function (commander, filenames) {
|
||||
}
|
||||
|
||||
outputFileSync(dest, data.code);
|
||||
util.chmod(src, dest);
|
||||
|
||||
util.log(src + " -> " + dest);
|
||||
}
|
||||
@@ -37,7 +39,9 @@ module.exports = function (commander, filenames) {
|
||||
if (util.canCompile(filename, commander.extensions)) {
|
||||
write(src, filename);
|
||||
} else if (commander.copyFiles) {
|
||||
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
|
||||
let dest = path.join(commander.outDir, filename);
|
||||
outputFileSync(dest, fs.readFileSync(src));
|
||||
util.chmod(src, dest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ module.exports = function (commander, filenames, opts) {
|
||||
}
|
||||
});
|
||||
|
||||
// add the inline sourcemap comment if we've either explicitly asked for inline source
|
||||
// maps, or we've requested them without any output file
|
||||
if (commander.sourceMaps === "inline" || (!commander.outFile && commander.sourceMaps)) {
|
||||
code += "\n" + convertSourceMap.fromObject(map).toComment();
|
||||
}
|
||||
@@ -68,6 +70,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
let result = buildResult();
|
||||
|
||||
if (commander.outFile) {
|
||||
// we've requested for a sorucemap to be written to disk
|
||||
if (commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||
let mapLoc = commander.outFile + ".map";
|
||||
result.code = util.addSourceMappingUrl(result.code, mapLoc);
|
||||
|
||||
@@ -7,29 +7,33 @@ let path = require("path");
|
||||
let fs = require("fs");
|
||||
let _ = require("lodash");
|
||||
|
||||
exports.readdirFilter = function (filename) {
|
||||
export function chmod(src, dest) {
|
||||
fs.chmodSync(dest, fs.statSync(src).mode);
|
||||
}
|
||||
|
||||
export function readdirFilter(filename) {
|
||||
return readdir(filename).filter(function (filename) {
|
||||
return util.canCompile(filename);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.readdir = readdir;
|
||||
export { readdir };
|
||||
|
||||
exports.canCompile = util.canCompile;
|
||||
export let canCompile = util.canCompile;
|
||||
|
||||
exports.shouldIgnore = function (loc) {
|
||||
export function shouldIgnore(loc) {
|
||||
return util.shouldIgnore(loc, index.opts.ignore, index.opts.only);
|
||||
};
|
||||
}
|
||||
|
||||
exports.addSourceMappingUrl = function (code, loc) {
|
||||
export function addSourceMappingUrl(code, loc) {
|
||||
return code + "\n//# sourceMappingURL=" + path.basename(loc);
|
||||
};
|
||||
}
|
||||
|
||||
exports.log = function (msg) {
|
||||
export function log(msg) {
|
||||
if (!commander.quiet) console.log(msg);
|
||||
};
|
||||
}
|
||||
|
||||
exports.transform = function (filename, code, opts) {
|
||||
export function transform(filename, code, opts) {
|
||||
opts = _.defaults(opts || {}, index.opts);
|
||||
opts.filename = filename;
|
||||
opts.ignore = null;
|
||||
@@ -39,12 +43,12 @@ exports.transform = function (filename, code, opts) {
|
||||
result.filename = filename;
|
||||
result.actual = code;
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
exports.compile = function (filename, opts) {
|
||||
export function compile(filename, opts) {
|
||||
try {
|
||||
let code = fs.readFileSync(filename, "utf8");
|
||||
return exports.transform(filename, code, opts);
|
||||
return transform(filename, code, opts);
|
||||
} catch (err) {
|
||||
if (commander.watch) {
|
||||
console.error(toErrorStack(err));
|
||||
@@ -53,7 +57,7 @@ exports.compile = function (filename, opts) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function toErrorStack(err) {
|
||||
if (err._babel && err instanceof SyntaxError) {
|
||||
|
||||
Reference in New Issue
Block a user