Skip to content

Commit

Permalink
Use babel 6 and move where babel-polyfills are added.
Browse files Browse the repository at this point in the history
Babel 7 is still pending official release and causes some issues.  Babel
7.0.0-rc.2 throws errors where 7.0.0-rc.1 does not.  Rather than figure
out what causes these, I recommend we wait until it is officially
released.  The main benefit of Babel 7 is that the polyfills can be
added conditionally based on actual use.

When adding babel-polyfill to src/index.js, the coverage for index.js is
wrong (the line numbers are incorrect).  Further, babel-polyfill is
fairly heavy, so just add it to the vendor.js (geo.js not geo.lean.js).
It also needs to be added to the test-utils to ensure that we can use
new language features in the tests with PhantomJS.  Reference to
babel-polyfill has been moved to src/polyfills.js, and that file has
been excluded from coverage analysis.

For the coverage reporters, disable the html reporter as it fails with
karma-coverage and babel.  One solution would be to switch to
karma-coverage-istanbul-reporter, but I don't think the html coverage is
strictly necessary as we use codecov.
  • Loading branch information
manthey committed Aug 23, 2018
1 parent b21f208 commit 5c9c1d7
Show file tree
Hide file tree
Showing 9 changed files with 1,440 additions and 2,589 deletions.
5 changes: 3 additions & 2 deletions karma-cov.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ module.exports = function (config) {
karma_config.specReporter = {suppressPassed: true, suppressSkipped: true};
karma_config.coverageReporter = {
reporters: [
{type: 'html', dir: 'dist/coverage/', subdir: subdir_name},
// {type: 'html', dir: 'dist/coverage/', subdir: subdir_name},
{type: 'cobertura', dir: 'dist/cobertura/', file: 'coverage.xml', subdir: subdir_name},
{type: 'json', dir: 'dist/coverage/json/', subdir: subdir_name},
{type: 'lcovonly', dir: 'lcov', subdir: subdir_name},
{type: 'lcovonly', dir: 'dist/coverage/lcov', subdir: subdir_name},
{type: 'text'}
]
};
karma_config.webpack.module.rules.unshift({
test: /\.js$/,
include: path.resolve('src/'),
exclude: path.resolve('src/polyfills.js'),
use: ['istanbul-instrumenter-loader']
});

Expand Down
3,995 changes: 1,419 additions & 2,576 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
"hammerjs": "^2.0.8"
},
"devDependencies": {
"@babel/core": "^7.0.0-rc.1",
"@babel/polyfill": "^7.0.0-rc.1",
"@babel/preset-env": "^7.0.0-rc.1",
"babel-loader": "^8.0.0-beta.4",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.5",
"babel-plugin-istanbul": "^4.1.6",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"body-parser": "^1.15.0",
"bootstrap": "^3.3.6",
"bootswatch": "^3.3.6",
Expand Down
1 change: 1 addition & 0 deletions src/polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('babel-polyfill');
3 changes: 3 additions & 0 deletions src/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* @copyright 2010-2016, Michael Bostock
* @license BSD-3-Clause
*/

require('./polyfills');

var globals = {
d3: require('d3'),
hammerjs: require('hammerjs')
Expand Down
2 changes: 1 addition & 1 deletion tests/test-common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// General utilities that are made available to tests.

var $ = require('jquery');
var geo = require('../src');
var geo = require('./test-utils').geo;

module.exports = {
createOsmMap: function (mapOpts, osmOpts, notiles) {
Expand Down
1 change: 1 addition & 0 deletions tests/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var $ = require('jquery');

require('../src/polyfills');
var geo = require('../src');
var bowser = require('bowser');

Expand Down
9 changes: 5 additions & 4 deletions webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ module.exports = {
loader: 'babel-loader',
options: {
presets: [[
'@babel/preset-env', {
'env', {
targets: {
browsers: ['defaults']
browsers: ['defaults'],
uglify: true
},
forceAllTransforms: true,
useBuiltIns: 'usage'
}
]]
]],
cacheDirectory: true
}
}]
}, {
Expand Down
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var merge = require('webpack-merge');

module.exports = merge(config, {
entry: {
'geo': './index.js',
'geo.min': './index.js'
'geo': ['./polyfills', './index.js'],
'geo.min': ['./polyfills', './index.js']
}
});

0 comments on commit 5c9c1d7

Please sign in to comment.