This commit is contained in:
Sebastian McKenzie 2015-07-13 16:34:43 +01:00
parent 1948946a4d
commit 2d5d1ceb5c
41 changed files with 45 additions and 299 deletions

View File

@ -26,129 +26,8 @@ contributing, please read the
## Developing
> Note: Babel moves fast. Only the latest release is guaranteed to build correctly.
> Older releases are not officially supported. If you attempt to build them, do that at your own risk.
#### Setup
```sh
$ git clone https://github.com/babel/babel
$ cd babel
$ make bootstrap
```
Then you can either run:
```sh
$ make build-core
```
to build Babel **once** or:
```sh
$ make watch-core
```
to have Babel build itself then incrementally build files on change.
#### Running tests
You can run tests via:
```sh
$ make test
```
This is mostly overkill and you can limit the tests to a select few by directly
running them with `mocha`:
```sh
$ mocha test/core/transformation.js
```
Use mocha's `--grep` option to run a subset of tests by name:
```sh
$ mocha test/core/transformation.js --grep es7
```
If you don't have `mocha` installed globally, you can still use it from Babel's
dependencies in `node_modules`, but make sure `node_modules/.bin` is added to
your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path) environment variable.
#### Workflow
* Fork the repository
* Clone your fork and change directory to it (`git clone git@github.com:yourUserName/babel.git && cd babel`)
* Install the project dependencies (`make bootstrap`)
* Link your forked clone (`npm link`)
* Develop your changes ensuring you're fetching updates from upstream often
* Ensure the test are passing (`make test`)
* Create new pull request explaining your proposed change or reference an issue in your commit message
#### Dependencies
+ [ast-types](http://ghub.io/ast-types) This is required to monkeypatch regenerators AST definitions. Could be improved in the future.
+ [chalk](http://ghub.io/chalk) This is used for terminal color highlighting for syntax errors.
+ [convert-source-map](http://ghub.io/convert-source-map) Turns a source map object into a comment etc.
+ [core-js](http://ghub.io/core-js) Used for the polyfill.
+ [debug](http://ghub.io/debug) Used to output debugging information when NODE_DEBUG is set to babel.
+ [detect-indent](http://ghub.io/detect-indent) This is used in the code generator so it can infer indentation.
+ [estraverse](http://ghub.io/estraverse) The only method on this is attachComments. I'd like to implement our own comment attachment algorithm eventually though.
+ [esutils](http://ghub.io/esutils) Various ES related utilities. Check whether something is a keyword etc.
+ [fs-readdir-recursive](http://ghub.io/fs-readdir-recursive) Recursively search a directory for.
+ [globals](http://ghub.io/globals) A list of JavaScript global variables. This is used by the scope tracking to check for colliding variables.
+ [is-integer](http://ghub.io/is-integer) Checks if something is an integer.
+ [js-tokens](http://ghub.io/js-tokens) This is used to get tokens for syntax error highlighting.
+ [line-numbers](http://ghub.io/line-numbers) Used to produce the code frames in syntax errors.
+ [lodash](http://ghub.io/lodash) Used for various utilities.
+ [minimatch](http://ghub.io/minimatch) This is used to match glob-style ignore/only filters.
+ [output-file-sync](http://ghub.io/output-file-sync) Synchronously writes a file and create its ancestor directories if needed.
+ [path-is-absolute](http://ghub.io/path-is-absolute) Checks if a path is absolute. C:\foo and \foo are considered absolute.
+ [regenerator](http://ghub.io/regenerator) This is used to transform generators/async functions.
+ [regexpu](http://ghub.io/regexpu) Used to transform unicode regex patterns.
+ [repeating](http://ghub.io/repeating) Repeats a string.
+ [shebang-regex](http://ghub.io/shebang-regex) Literally just a regex that matches shebangs.
+ [slash](http://ghub.io/slash) Normalises path separators.
+ [source-map](http://ghub.io/source-map) Generates sourcemaps.
+ [source-map-support](http://ghub.io/source-map-support) Adds source map support to babel-node/babel/register.
+ [strip-json-comments](http://ghub.io/strip-json-comments) Remove comments from a JSON string. This is used for .babelrc files.
+ [to-fast-properties](http://ghub.io/to-fast-properties) A V8 trick to put an object into fast properties mode.
+ [trim-right](http://ghub.io/trim-right) Trims the rightside whitespace.
+ [path-exists](https://www.npmjs.com/package/path-exists) Checks if a path exists. (replaces the deprecated `fs.exists` methods)
+ [home-or-tmp](https://github.com/sindresorhus/home-or-tmp) Gets the user home directory with fallback to the system temporary directory. This is used to resolve the babel-node/babel/register cache.
+ [resolve](https://www.npmjs.com/package/resolve) Implements the [`require.resolve()` algorithm](http://nodejs.org/docs/v0.12.0/api/all.html#all_require_resolve) such that we can `require.resolve()` on behalf of a file asynchronously and synchronously.
#### Code Standards
* **General**
@ -177,4 +56,5 @@ your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-ad
* No pollution of global variables and prototypes
#### Internals
Please see [`/doc`](/doc) for internals documentation relevant to developing babel.

View File

@ -1,69 +1,51 @@
MAKEFLAGS = -j1
ISTANBUL_CMD = node_modules/istanbul/lib/cli.js cover
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
MOCHA_CMD = node_modules/mocha/bin/_mocha
BABEL_CMD = node_modules/babel/bin/babel
export NODE_ENV = test
.PHONY: clean test test-cov test-clean test-travis test-browser publish build bootstrap publish-core publish-runtime build-website build-core watch-core build-core-test clean-core prepublish
build-core: clean-core
./scripts/build-core.sh
build: clean
./scripts/build.sh
watch-core: clean-core
./scripts/build-core.sh --watch
build-dist: build
cd packages/babel; \
scripts/build-dist.sh
cd packages/babel-runtime; \
node scripts/build-dist.js
clean-core:
rm -rf packages/*/lib
watch: clean
scripts/build.sh --watch
lint:
eslint packages/*/src
build: build-core
cd packages/babel; \
scripts/build.sh
clean:
rm -rf coverage packages/babel/templates.json test/tmp dist lib
clean: test-clean
rm -rf coverage
rm -rf packages/*/dist dist
rm -rf packages/*/lib packages/babel/templates.json
test-clean:
rm -rf test/tmp
rm -rf packages/*/test/tmp
test:
test: lint
./scripts/test.sh
make test-clean
test-browser:
./scripts/test-browser.sh
test-cov:
rm -rf coverage
test-cov: clean
BABEL_ENV=test; \
make build-core
make build
node $(ISTANBUL_CMD) $(MOCHA_CMD) -- test/core
test-travis: bootstrap lint build test
publish: lint
publish: build-dist
git pull --rebase
make test
read -p "Version: " version; \
npm version $$version --message "v%s"
git push --follow-tags
publish-runtime:
cd packages; \
node build-runtime.js; \
cd babel-runtime; \
npm publish
travis-deploy:
@./scripts/travis/publish-cli.sh
make publish-runtime
@./scripts/travis/build-website.sh
@./scripts/travis/comment-issues.sh
node scripts/publish
./scripts/build-website.sh
bootstrap:
./scripts/bootstrap.sh

View File

@ -7,7 +7,6 @@
"chai": "^2.2.0",
"es5-shim": "^4.1.7",
"eslint": "^0.21.2",
"esvalid": "^1.1.0",
"fs-readdir-recursive": "^0.1.2",
"istanbul": "^0.3.5",
"matcha": "^0.6.0",
@ -15,6 +14,7 @@
"output-file-sync": "^1.1.1",
"path-exists": "^1.0.0",
"rimraf": "^2.4.1",
"semver": "^5.0.0",
"uglify-js": "^2.4.16"
}
}

View File

@ -7,6 +7,7 @@
"repository": "babel/babel",
"preferGlobal": true,
"dependencies": {
"babel": "*",
"chokidar": "^1.0.0",
"commander": "^2.6.0",
"convert-source-map": "^1.1.0",

View File

@ -1,2 +0,0 @@
--reporter dot
--ui tdd

View File

@ -1,2 +0,0 @@
var bar = () => console.log("bar");
bar();

View File

@ -1,5 +0,0 @@
import "./bar2";
import "./not_node_modules";
var foo = () => console.log("foo");
foo();

View File

@ -1,10 +0,0 @@
/*
The purpose of this file is to test that the node_modules check in the require
hook doesn't mistakenly exclude something like "not_node_modules". To pass, this
file merely needs to be transpiled. The transpiled code won't, and doesn't need
to, execute without error. It won't execute because React will be undefined.
*/
try {
<Some jsx="element" />;
}
catch (e) {}

View File

@ -0,0 +1,2 @@
scripts
node_modules

View File

@ -1,5 +1,3 @@
"use strict";
var outputFile = require("output-file-sync");
var transform = require("../lib/babel/transformation");
var each = require("lodash/collection/each");
@ -10,7 +8,7 @@ var t = require("../lib/babel/types");
var _ = require("lodash");
function relative(filename) {
return __dirname + "/babel-runtime/" + filename;
return __dirname + "/../" + filename;
}
function readFile(filename, shouldDefaultify) {
@ -27,16 +25,6 @@ function defaultify(name) {
return 'module.exports = { "default": ' + name + ', __esModule: true };';
}
function updatePackage() {
var pkgLoc = relative("package.json");
var pkg = require(pkgLoc);
var mainPkg = require("../package.json");
pkg.version = mainPkg.version;
writeRootFile("package.json", JSON.stringify(pkg, null, 2));
}
function writeRootFile(filename, content) {
filename = relative(filename);
console.log(filename);
@ -92,5 +80,3 @@ each(paths, function (path) {
writeFile("core-js/" + path + ".js", defaultify('require("core-js/library/fn/' + path + '")'));
});
updatePackage();

View File

@ -3,14 +3,10 @@
.*
/lib/transformation/templates
/test
/benchmark
/Makefile
/dist
/tests.json
/CHANGELOG.md
/.package.json
/coverage
/vendor
/packages
/src
_babel.github.io

View File

@ -41,6 +41,7 @@
"babel-plugin-runtime": "^1.0.7",
"babel-plugin-undeclared-variables-check": "^1.0.2",
"babel-plugin-undefined-to-void": "^1.1.6",
"babylon": "*",
"bluebird": "^2.9.33",
"chalk": "^1.0.0",
"convert-source-map": "^1.1.0",

View File

@ -1,5 +1,4 @@
var pathExists = require("path-exists");
var esvalid = require("esvalid");
var util = require("../lib/util");
var path = require("path");
var fs = require("fs");
@ -20,17 +19,6 @@ var readFile = exports.readFile = function (filename) {
}
};
exports.esvalid = function (ast, code, loc) {
var errors = esvalid.errors(ast);
if (errors.length) {
var msg = [];
_.each(errors, function (err) {
msg.push(err.message + " - " + util.inspect(err.node));
});
throw new Error(loc + ": " + msg.join(". ") + "\n" + code);
}
};
exports.assertVendor = function (name) {
if (!pathExists.sync(__dirname + "/../../../vendor/" + name)) {
console.error("No vendor/" + name + " - run `make bootstrap`");

View File

@ -44,6 +44,7 @@ chai.assert.throw = function (fn, msg) {
return chai.assert._throw(fn, msg);
};
var run = function (task, done) {
var actual = task.actual;
var expect = task.expect;
@ -60,14 +61,6 @@ var run = function (task, done) {
var execCode = exec.code;
var result;
var noCheckAst = opts.noCheckAst;
delete opts.noCheckAst;
var checkAst = function (result, opts) {
if (noCheckAst) return;
helper.esvalid(result.ast.program, result.code, opts.loc);
};
if (execCode) {
result = transform(execCode, getOpts(exec));
execCode = result.code;
@ -90,8 +83,6 @@ var run = function (task, done) {
err.message += codeFrame(execCode);
throw err;
}
checkAst(result, exec);
}
var actualCode = actual.code;
@ -106,8 +97,6 @@ var run = function (task, done) {
//require("fs").writeFileSync(expect.loc, actualCode);
throw err;
}
checkAst(result, actual);
}
if (task.sourceMap) {

View File

@ -1,3 +0,0 @@
{
"noCheckAst": true
}

View File

@ -1,5 +1,4 @@
{
"externalHelpers": true,
"noCheckAst": true,
"optional": ["asyncToGenerator"]
}

View File

@ -1,4 +1,3 @@
{
"optional": ["bluebirdCoroutines"],
"noCheckAst": true
"optional": ["bluebirdCoroutines"]
}

View File

@ -1,4 +1,3 @@
{
"blacklist": ["es6.modules"],
"noCheckAst": true
"blacklist": ["es6.modules"]
}

View File

@ -1,3 +0,0 @@
{
"noCheckAst": true
}

View File

@ -1,5 +1,4 @@
{
"noCheckAst": true,
"externalHelpers": true,
"optional": "es7.exportExtensions"
}

View File

@ -1,4 +1,3 @@
{
"whitelist": ["flow", "es7.asyncFunctions", "es7.classProperties"],
"noCheckAst": true
"whitelist": ["flow", "es7.asyncFunctions", "es7.classProperties"]
}

View File

@ -1,7 +1,6 @@
{
"experimental": true,
"externalHelpers": true,
"noCheckAst": true,
"blacklist": ["regenerator"],
"optional": ["minification.deadCodeElimination"]
}

View File

@ -1,4 +1,3 @@
{
"blacklist": ["es6.modules"],
"noCheckAst": true
"blacklist": ["es6.modules"]
}

View File

@ -1,5 +1,4 @@
{
"noCheckAst": true,
"optional": ["optimisation.react.constantElements"],
"blacklist": ["react", "react.displayName"]
}

View File

@ -1,5 +1,4 @@
{
"externalHelpers": true,
"noCheckAst": true,
"optional": ["optimisation.react.inlineElements"]
}

View File

@ -1,4 +1,3 @@
{
"noCheckAst": true,
"blacklist": ["es6.modules"]
}

View File

@ -1,2 +0,0 @@
--reporter dot
--ui tdd

View File

@ -1,2 +0,0 @@
var bar = () => console.log("bar");
bar();

View File

@ -1,5 +0,0 @@
import "./bar2";
import "./not_node_modules";
var foo = () => console.log("foo");
foo();

View File

@ -1,10 +0,0 @@
/*
The purpose of this file is to test that the node_modules check in the require
hook doesn't mistakenly exclude something like "not_node_modules". To pass, this
file merely needs to be transpiled. The transpiled code won't, and doesn't need
to, execute without error. It won't execute because React will be undefined.
*/
try {
<Some jsx="element" />;
}
catch (e) {}

View File

@ -30,6 +30,7 @@ export class Token {
const pp = Parser.prototype;
// Are we running under Rhino?
/* global Packages */
const isRhino = typeof Packages === "object" && Object.prototype.toString.call(Packages) === "[object JavaPackage]";
// Move to the next token

View File

@ -1,2 +0,0 @@
--reporter dot
--ui tdd

View File

@ -1,11 +0,0 @@
var outputFile = require("output-file-sync");
var pkgLoc = __dirname + "/babel-cli/package.json";
var pkg = require(pkgLoc);
var mainPkg = require("../package.json");
pkg.version = mainPkg.version;
pkg.dependencies["babel-core"] = "^" + mainPkg.version;
outputFile(pkgLoc, JSON.stringify(pkg, null, 2));

View File

@ -12,5 +12,5 @@ if [ ! -d ./_babel ]; then
fi
make build
git commit -am "${TRAVIS_TAG}"
git push "https://${GH_TOKEN}@github.com/babel/babel.github.io"
git commit -am "v`babel -V`"
git push

3
scripts/publish.js Normal file
View File

@ -0,0 +1,3 @@
var fs = require("fs");
var packageNames = fs.readDirSync(__filename + "/../packages");

View File

@ -1,15 +1,16 @@
#!/bin/sh
set -e
TEST_DIRS=""
for f in packages/*; do
if [ -n "$TEST_ONLY" ] && [ `basename $f` != "$TEST_ONLY" ]; then
continue
fi
if [ -d "$f/test" ]; then
echo $f
cd $f
node ../../node_modules/mocha/bin/_mocha
cd ../../
TEST_DIRS="$f/test $TEST_DIRS"
fi
done
node node_modules/mocha/bin/_mocha $TEST_DIRS --reporter dot --ui tdd

View File

@ -1,2 +0,0 @@
#!/bin/bash
set -e

View File

@ -1,17 +0,0 @@
#!/bin/bash
set -e
LAST_TAG=$(git describe $(git rev-list --tags --max-count=1))
TAG_DIFF=$(git diff $LAST_TAG -- packages/babel-cli/)
if [ -n "$TAG_DIFF" ]; then
echo "Changes detected to babel-cli since last tag, publishing new version."
cd ../packages
node build-cli.js
cd babel-cli
npm publish
else
echo "No changes detected to babel-cli since last tag"
fi

2
test/warning.js Normal file
View File

@ -0,0 +1,2 @@
console.error("Don't run `mocha` directly. Use `make test`. See CONTRIBUTING.md for usage instructions.");
process.exit(0);