diff --git a/.gitignore b/.gitignore index 8f5b2905f2..da344e99ac 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ # Ignore object files. *.o -build/*.js +build/ tags bin/rippled Debug/*.* diff --git a/.npmignore b/.npmignore index 928256a82b..7378066b39 100644 --- a/.npmignore +++ b/.npmignore @@ -1,2 +1,4 @@ lib-cov coverage.html +src +dist/bower diff --git a/.travis.yml b/.travis.yml index 5b666aaa3d..9fac3c25b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: node_js node_js: - - "0.10" + - "0.12" before_script: - npm install -g eslint - - curl 'https://raw.githubusercontent.com/ripple/javascript-style-guide/master/eslintrc' > ./eslintrc + - curl 'https://raw.githubusercontent.com/ripple/javascript-style-guide/es6/eslintrc' > ./eslintrc - eslint --reset -c ./eslintrc $(git --no-pager diff --name-only -M100% --diff-filter=AM --relative $(git merge-base FETCH_HEAD origin/HEAD) FETCH_HEAD | grep "\.js$") script: MOCHA_REPORTER=tap npm test --coverage after_success: diff --git a/Gulpfile.js b/Gulpfile.js index 0a6944224b..bb3b5a7ed3 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -1,4 +1,7 @@ +/* eslint-disable no-var, no-param-reassign */ +/* these eslint rules are disabled because gulp does not support babel yet */ 'use strict'; +var _ = require('lodash'); var gulp = require('gulp'); var gutil = require('gulp-util'); var watch = require('gulp-watch'); @@ -15,20 +18,33 @@ var argv = require('yargs').argv; var pkg = require('./package.json'); -function logPluginError(error) { - gutil.log(error.toString()); -} - -gulp.task('build', function(callback) { - webpack({ +function webpackConfig(extension, overrides) { + overrides = overrides || {}; + var defaults = { cache: true, entry: './src/index.js', output: { library: 'ripple', path: './build/', - filename: ['ripple-', '.js'].join(pkg.version) + filename: ['ripple-', extension].join(pkg.version) + }, + module: { + loaders: [{ + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel-loader?optional=runtime' + }] } - }, callback); + }; + return _.assign({}, defaults, overrides); +} + +function logPluginError(error) { + gutil.log(error.toString()); +} + +gulp.task('build', function(callback) { + webpack(webpackConfig('.js'), callback); }); gulp.task('build-min', ['build'], function() { @@ -39,17 +55,8 @@ gulp.task('build-min', ['build'], function() { }); gulp.task('build-debug', function(callback) { - webpack({ - cache: true, - entry: './src/index.js', - output: { - library: 'ripple', - path: './build/', - filename: ['ripple-', '-debug.js'].join(pkg.version) - }, - debug: true, - devtool: 'eval' - }, callback); + var configOverrides = {debug: true, devtool: 'eval'}; + webpack(webpackConfig('-debug.js', configOverrides), callback); }); /** @@ -64,51 +71,44 @@ function buildUseError(cons) { } gulp.task('build-core', function(callback) { - webpack({ - entry: [ - './src/remote.js' - ], - externals: [ - { - './transaction': buildUseError('Transaction'), - './orderbook': buildUseError('OrderBook'), - './account': buildUseError('Account'), - './serializedobject': buildUseError('SerializedObject') - } - ], - output: { - library: 'ripple', - path: './build/', - filename: ['ripple-', '-core.js'].join(pkg.version) - }, + var configOverrides = { + cache: false, + entry: './src/remote.js', + externals: [{ + './transaction': buildUseError('Transaction'), + './orderbook': buildUseError('OrderBook'), + './account': buildUseError('Account'), + './serializedobject': buildUseError('SerializedObject') + }], plugins: [ new webpack.optimize.UglifyJsPlugin() ] - }, callback); + }; + webpack(webpackConfig('-core.js', configOverrides), callback); }); gulp.task('bower-build', ['build'], function() { return gulp.src(['./build/ripple-', '.js'].join(pkg.version)) .pipe(rename('ripple.js')) - .pipe(gulp.dest('./dist/')); + .pipe(gulp.dest('./dist/bower')); }); gulp.task('bower-build-min', ['build-min'], function() { return gulp.src(['./build/ripple-', '-min.js'].join(pkg.version)) .pipe(rename('ripple-min.js')) - .pipe(gulp.dest('./dist/')); + .pipe(gulp.dest('./dist/bower')); }); gulp.task('bower-build-debug', ['build-debug'], function() { return gulp.src(['./build/ripple-', '-debug.js'].join(pkg.version)) .pipe(rename('ripple-debug.js')) - .pipe(gulp.dest('./dist/')); + .pipe(gulp.dest('./dist/bower')); }); gulp.task('bower-version', function() { - gulp.src('./dist/bower.json') + gulp.src('./dist/bower/bower.json') .pipe(bump({version: pkg.version})) - .pipe(gulp.dest('./dist/')); + .pipe(gulp.dest('./dist/bower')); }); gulp.task('bower', ['bower-build', 'bower-build-min', 'bower-build-debug', diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index ae98582d71..4278d4f703 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -2,12 +2,22 @@ "name": "ripple-lib", "version": "0.12.5-rc2", "npm-shrinkwrap-version": "5.4.0", - "node-version": "v0.10.38", + "node-version": "v0.12.3", "dependencies": { "async": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/async/-/async-0.9.0.tgz" }, + "babel-runtime": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-5.3.3.tgz", + "dependencies": { + "core-js": { + "version": "0.9.9", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-0.9.9.tgz" + } + } + }, "bignumber.js": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-2.0.7.tgz" @@ -17,8 +27,8 @@ "resolved": "https://registry.npmjs.org/extend/-/extend-1.2.1.tgz" }, "lodash": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.7.0.tgz" + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.8.0.tgz" }, "lru-cache": { "version": "2.5.2", diff --git a/package.json b/package.json index 8c18cb4b3a..26ca0c6441 100644 --- a/package.json +++ b/package.json @@ -3,19 +3,19 @@ "version": "0.12.5-rc2", "description": "A JavaScript API for interacting with Ripple in Node.js and the browser", "files": [ - "src/js/*", + "dist/npm/*", "bin/*", "build/*", "test/*", - "Makefile", "Gulpfile.js" ], - "main": "src/", + "main": "dist/npm/", "directories": { "test": "test" }, "dependencies": { "async": "~0.9.0", + "babel-runtime": "^5.3.2", "bignumber.js": "^2.0.3", "extend": "~1.2.1", "lodash": "^3.1.0", @@ -26,6 +26,9 @@ }, "devDependencies": { "assert-diff": "^1.0.1", + "babel": "^5.3.3", + "babel-core": "^5.3.2", + "babel-loader": "^5.0.0", "coveralls": "~2.10.0", "eslint": "^0.18.0", "gulp": "~3.8.10", @@ -48,10 +51,12 @@ }, "scripts": { "build": "gulp", + "compile": "babel --optional runtime -d dist/npm/ src/", + "prepublish": "npm run compile", "postinstall": "cd node_modules/sjcl; ./configure --with-all --compress=none; make", "test": "istanbul test _mocha", "coveralls": "cat ./coverage/lcov.info | coveralls", - "lint": "if ! [ -f eslintrc ]; then curl -o eslintrc 'https://raw.githubusercontent.com/ripple/javascript-style-guide/master/eslintrc'; fi; eslint --reset -c eslintrc src/*.js", + "lint": "if ! [ -f eslintrc ]; then curl -o eslintrc 'https://raw.githubusercontent.com/ripple/javascript-style-guide/es6/eslintrc'; fi; eslint --reset -c eslintrc src/*.js", "perf": "./scripts/perf_test.sh" }, "repository": { diff --git a/scripts/perf_test.sh b/scripts/perf_test.sh index 786b68f825..5495d44519 100755 --- a/scripts/perf_test.sh +++ b/scripts/perf_test.sh @@ -8,4 +8,4 @@ then mkdir -p "$DIR/cache" curl -L "$URL" > "$DEST" fi -time node "$DIR/verify_ledger_json.js" "$DEST" +npm run compile && time node "$DIR/verify_ledger_json.js" "$DEST" diff --git a/scripts/publish b/scripts/publish index 4c5761003e..bac4406469 100644 --- a/scripts/publish +++ b/scripts/publish @@ -17,15 +17,15 @@ echo "publish to npm" npm publish exit_on_error -rm -rf dist +rm -rf dist/bower echo "" echo "publish to bower" -git clone git@github.com:ripple/bower-ripple.git dist +git clone git@github.com:ripple/bower-ripple.git dist/bower gulp bower exit_on_error -cd dist +cd dist/bower version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?') echo "version: $version" git add ripple.js ripple-debug.js ripple-min.js bower.json @@ -40,4 +40,4 @@ exit_on_error git push origin master git push --tags origin master -cd .. \ No newline at end of file +cd .. diff --git a/scripts/publish_rc b/scripts/publish_rc index fd90a92041..dc9f6e41e0 100644 --- a/scripts/publish_rc +++ b/scripts/publish_rc @@ -17,15 +17,15 @@ echo "publish rc to npm" npm publish --tag beta exit_on_error -rm -rf dist +rm -rf dist/bower echo "" echo "publish to bower" -git clone git@github.com:ripple/bower-ripple.git dist +git clone git@github.com:ripple/bower-ripple.git dist/bower gulp bower exit_on_error -cd dist +cd dist/bower version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?') echo "version: $version" git add ripple.js ripple-debug.js ripple-min.js bower.json @@ -40,4 +40,4 @@ exit_on_error git push origin master git push --tags origin master -cd .. \ No newline at end of file +cd .. diff --git a/scripts/publish_to_bower b/scripts/publish_to_bower index 93ce1d6ea4..280eb6638e 100644 --- a/scripts/publish_to_bower +++ b/scripts/publish_to_bower @@ -1,7 +1,7 @@ -rm -rf dist -git clone git@github.com:ripple/bower-ripple.git dist +rm -rf dist/bower +git clone git@github.com:ripple/bower-ripple.git dist/bower gulp bower -cd dist +cd dist/bower version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?') echo "version: $version" git add ripple.js ripple-debug.js ripple-min.js bower.json @@ -9,4 +9,4 @@ git commit -m "[TASK] add v$version" git tag "v$version" git push origin master git push --tags origin master -cd .. \ No newline at end of file +cd .. diff --git a/scripts/verify_ledger_json.js b/scripts/verify_ledger_json.js index ae74aa5661..8f2a5f43f7 100755 --- a/scripts/verify_ledger_json.js +++ b/scripts/verify_ledger_json.js @@ -1,8 +1,8 @@ 'use strict'; var fs = require('fs'); -var Amount = require('../src/js/ripple').Amount; -var Ledger = require('../src/js/ripple/ledger').Ledger; +var Amount = require('../dist/npm').Amount; +var Ledger = require('../dist/npm/ledger').Ledger; function parse_options(from, flags) { var argv = from.slice(), diff --git a/src/request.js b/src/request.js index 305eb86175..c2329234e3 100644 --- a/src/request.js +++ b/src/request.js @@ -542,7 +542,7 @@ Request.prototype.addStream = function(stream, values) { break; } } else if (arguments.length > 1) { - for (arg in arguments) { + for (var arg in arguments) { this.addStream(arguments[arg]); } return; diff --git a/test/amount-test.js b/test/amount-test.js index 7863e727cc..e649908543 100644 --- a/test/amount-test.js +++ b/test/amount-test.js @@ -1150,7 +1150,7 @@ describe('Amount', function() { var demAmount = Amount.from_json('10/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); assert.strictEqual(demAmount.to_text_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); demAmount = demAmount.applyInterest(459990264); - assert.strictEqual(demAmount.to_text_full(), '9.294949401870435/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); + assert.strictEqual(demAmount.to_text_full(), '9.294949401870436/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); }); it('from_json apply interest XAU', function() { @@ -1168,7 +1168,7 @@ describe('Amount', function() { var demAmount = Amount.from_json('10/0158415500000000C1F76FF6ECB0BAC600000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); assert.strictEqual(demAmount.to_human_full(), '10/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); demAmount = demAmount.applyInterest(459990264); - assert.strictEqual(demAmount.to_human_full(), '9.294949401870435/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); + assert.strictEqual(demAmount.to_human_full(), '9.294949401870436/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); }); it('from_json apply interest XAU human', function() { diff --git a/test/currency-test.js b/test/currency-test.js index 8f1e051187..f41ba20764 100644 --- a/test/currency-test.js +++ b/test/currency-test.js @@ -272,7 +272,9 @@ describe('Currency', function() { assert.equal(0.995, precision(cur.get_interest_at(new Date(timeUtil.fromRipple(443845330 + 31536000))), 14)); // After one demurrage period, 1/e should have occurred - assert.equal(1/Math.E, cur.get_interest_at(443845330 + 6291418827.05)); + var epsilon = 1e-14; + assert(Math.abs( + 1/Math.E - cur.get_interest_at(443845330 + 6291418827.05)) < epsilon); // One year before start, it should be (roughly) 0.5% higher. assert.equal(1.005, precision(cur.get_interest_at(443845330 - 31536000), 4)); diff --git a/test/ledger-test.js b/test/ledger-test.js index 1742fb6f28..d9796b98fe 100644 --- a/test/ledger-test.js +++ b/test/ledger-test.js @@ -7,7 +7,7 @@ var Ledger = require('ripple-lib').Ledger; * @param ledger_index {Number} * Expects a corresponding ledger dump in $repo/test/fixtures/ folder */ -create_ledger_test = function (ledger_index) { +var create_ledger_test = function (ledger_index) { describe(String(ledger_index), function() { var path = __dirname + '/fixtures/ledger-full-'+ledger_index+'.json'; diff --git a/test/mocha.opts b/test/mocha.opts index ccd434ecf5..63a552fe44 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1 +1 @@ ---reporter spec --timeout 10000 --slow 500 +--reporter spec --timeout 10000 --slow 500 --compilers js:babel/register diff --git a/test/request-test.js b/test/request-test.js index aefd1cc043..1f6e339aea 100644 --- a/test/request-test.js +++ b/test/request-test.js @@ -510,7 +510,7 @@ describe('Request', function() { it('Timeout', function(done) { var server = makeServer('wss://localhost:5006'); - var successEmited = false; + var successEmitted = false; server._request = function(req) { assert(req instanceof Request); @@ -542,7 +542,7 @@ describe('Request', function() { it('Timeout - satisfied', function(done) { var server = makeServer('wss://localhost:5006'); - var successEmited = false; + var successEmitted = false; server._request = function(req) { assert(req instanceof Request);