From 36ecf130add6e150420da0105552dfa4a523b01f Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 8 May 2017 15:29:28 -0700 Subject: [PATCH] [babel] tweak babel options for performance and debugging (#11535) * [babel] tweak babel options for performance and debugging * [babel] remove babel-plugin-transform-export-extensions * [npm] lock new deps to the patch version * [npm] remove unused deps --- package.json | 11 ++-- src/cli/cli.js | 2 +- src/cli/cluster/cluster_manager.js | 2 +- src/cli_plugin/cli.js | 2 +- src/cli_plugin/install/index.js | 2 +- src/cli_plugin/list/__tests__/settings.js | 2 +- src/cli_plugin/remove/__tests__/settings.js | 2 +- .../lib/__tests__/is_upgradeable.js | 2 +- .../elasticsearch/lib/__tests__/routes.js | 2 +- .../server/lib/__tests__/manage_uuid.js | 2 +- src/deprecation/__tests__/create_transform.js | 2 +- src/deprecation/create_transform.js | 2 +- .../deprecations/__tests__/rename.js | 2 +- .../deprecations/__tests__/unused.js | 2 +- src/deprecation/deprecations/index.js | 4 +- src/deprecation/deprecations/rename.js | 2 +- src/deprecation/deprecations/unused.js | 2 +- src/deprecation/index.js | 6 ++- src/optimize/babel/helpers.js | 54 +++++++++++-------- src/optimize/babel/options.build.js | 11 ++-- src/optimize/babel/options.js | 11 ++-- src/optimize/babel/polyfills.js | 2 + src/optimize/babel/register.js | 3 +- src/optimize/base_optimizer.js | 2 +- src/server/http/__tests__/index.js | 2 +- src/ui/ui_bundler_env.js | 2 +- .../__tests__/deep_clone_with_buffers.js | 2 +- src/utils/__tests__/unset.js | 2 +- src/utils/binder_for.js | 3 +- src/utils/deep_clone_with_buffers.js | 2 +- src/utils/from_root.js | 9 ++-- src/utils/index.js | 16 +++--- src/utils/package_json.js | 8 +-- src/utils/unset.js | 4 +- tasks/build/verify_translations.js | 2 +- 35 files changed, 95 insertions(+), 91 deletions(-) create mode 100644 src/optimize/babel/polyfills.js diff --git a/package.json b/package.json index 2718f629fdb80..c7919bb94fa71 100644 --- a/package.json +++ b/package.json @@ -97,14 +97,13 @@ "babel-jest": "19.0.0", "babel-loader": "6.2.10", "babel-plugin-add-module-exports": "0.2.1", + "babel-plugin-transform-async-generator-functions": "6.24.1", + "babel-plugin-transform-class-properties": "6.24.1", + "babel-plugin-transform-object-rest-spread": "6.23.0", "babel-polyfill": "6.20.0", - "babel-preset-env": "1.1.8", - "babel-preset-es2015": "6.22.0", - "babel-preset-es2015-node": "6.1.1", + "babel-preset-env": "1.4.0", "babel-preset-react": "6.22.0", - "babel-preset-stage-1": "6.22.0", "babel-register": "6.18.0", - "babel-runtime": "6.20.0", "bluebird": "2.9.34", "body-parser": "1.12.0", "boom": "2.8.0", @@ -204,6 +203,7 @@ }, "devDependencies": { "@elastic/eslint-config-kibana": "0.5.0", + "@elastic/eslint-plugin-kibana-custom": "1.0.3", "@spalger/babel-presets": "0.3.2", "angular-mocks": "1.4.7", "auto-release-sinon": "1.0.3", @@ -219,7 +219,6 @@ "eslint": "3.11.1", "eslint-plugin-babel": "4.0.0", "eslint-plugin-jest": "19.0.1", - "@elastic/eslint-plugin-kibana-custom": "1.0.3", "eslint-plugin-mocha": "4.7.0", "eslint-plugin-react": "6.10.3", "event-stream": "3.3.2", diff --git a/src/cli/cli.js b/src/cli/cli.js index b53dc922b67b0..fc3422ce02cd7 100644 --- a/src/cli/cli.js +++ b/src/cli/cli.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import pkg from '../utils/package_json'; +import { pkg } from '../utils'; import Command from './command'; import serveCommand from './serve/serve'; diff --git a/src/cli/cluster/cluster_manager.js b/src/cli/cluster/cluster_manager.js index ce373ceb80677..ed3aa90a58126 100644 --- a/src/cli/cluster/cluster_manager.js +++ b/src/cli/cluster/cluster_manager.js @@ -81,7 +81,7 @@ module.exports = class ClusterManager { setupWatching(extraPaths) { const chokidar = require('chokidar'); - const fromRoot = require('../../utils/from_root'); + const { fromRoot } = require('../../utils'); const watchPaths = [ fromRoot('src/core_plugins'), diff --git a/src/cli_plugin/cli.js b/src/cli_plugin/cli.js index 5d3dd2f702267..c972727923585 100644 --- a/src/cli_plugin/cli.js +++ b/src/cli_plugin/cli.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import pkg from '../utils/package_json'; +import { pkg } from '../utils'; import Command from '../cli/command'; import listCommand from './list'; import installCommand from './install'; diff --git a/src/cli_plugin/install/index.js b/src/cli_plugin/install/index.js index d34160ff82c2f..27d8df9d0f782 100644 --- a/src/cli_plugin/install/index.js +++ b/src/cli_plugin/install/index.js @@ -1,7 +1,7 @@ import { fromRoot } from '../../utils'; import install from './install'; import Logger from '../lib/logger'; -import pkg from '../../utils/package_json'; +import { pkg } from '../../utils'; import { getConfig } from '../../server/path'; import { parse, parseMilliseconds } from './settings'; import logWarnings from '../lib/log_warnings'; diff --git a/src/cli_plugin/list/__tests__/settings.js b/src/cli_plugin/list/__tests__/settings.js index 433037c12114b..d2b127e166b21 100644 --- a/src/cli_plugin/list/__tests__/settings.js +++ b/src/cli_plugin/list/__tests__/settings.js @@ -1,5 +1,5 @@ import expect from 'expect.js'; -import fromRoot from '../../../utils/from_root'; +import { fromRoot } from '../../../utils'; import { parse } from '../settings'; describe('kibana cli', function () { diff --git a/src/cli_plugin/remove/__tests__/settings.js b/src/cli_plugin/remove/__tests__/settings.js index 0d031f820829f..012f54af2e003 100644 --- a/src/cli_plugin/remove/__tests__/settings.js +++ b/src/cli_plugin/remove/__tests__/settings.js @@ -1,5 +1,5 @@ import expect from 'expect.js'; -import fromRoot from '../../../utils/from_root'; +import { fromRoot } from '../../../utils'; import { parse } from '../settings'; describe('kibana cli', function () { diff --git a/src/core_plugins/elasticsearch/lib/__tests__/is_upgradeable.js b/src/core_plugins/elasticsearch/lib/__tests__/is_upgradeable.js index 400990a9b8265..36b5329bf3835 100644 --- a/src/core_plugins/elasticsearch/lib/__tests__/is_upgradeable.js +++ b/src/core_plugins/elasticsearch/lib/__tests__/is_upgradeable.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import expect from 'expect.js'; import isUpgradeable from '../is_upgradeable'; -import pkg from '../../../../utils/package_json'; +import { pkg } from '../../../../utils'; let version = pkg.version; describe('plugins/elasticsearch', function () { diff --git a/src/core_plugins/elasticsearch/lib/__tests__/routes.js b/src/core_plugins/elasticsearch/lib/__tests__/routes.js index 5d1f023f533b0..017c621743fc7 100644 --- a/src/core_plugins/elasticsearch/lib/__tests__/routes.js +++ b/src/core_plugins/elasticsearch/lib/__tests__/routes.js @@ -1,7 +1,7 @@ import { format } from 'util'; import * as kbnTestServer from '../../../../../test/utils/kbn_server'; -import fromRoot from '../../../../utils/from_root'; +import { fromRoot } from '../../../../utils'; describe('plugins/elasticsearch', function () { describe('routes', function () { diff --git a/src/core_plugins/kibana/server/lib/__tests__/manage_uuid.js b/src/core_plugins/kibana/server/lib/__tests__/manage_uuid.js index 1b61f1f6b5e7c..1103fa02e4087 100644 --- a/src/core_plugins/kibana/server/lib/__tests__/manage_uuid.js +++ b/src/core_plugins/kibana/server/lib/__tests__/manage_uuid.js @@ -1,7 +1,7 @@ import expect from 'expect.js'; import sinon from 'sinon'; import * as kbnTestServer from '../../../../../../test/utils/kbn_server.js'; -import fromRoot from '../../../../../utils/from_root'; +import { fromRoot } from '../../../../../utils'; import manageUuid from '../manage_uuid'; describe('core_plugins/kibana/server/lib', function () { diff --git a/src/deprecation/__tests__/create_transform.js b/src/deprecation/__tests__/create_transform.js index 387ca3957b1b1..b0c8b9d368571 100644 --- a/src/deprecation/__tests__/create_transform.js +++ b/src/deprecation/__tests__/create_transform.js @@ -1,4 +1,4 @@ -import createTransform from '../create_transform'; +import { createTransform } from '../create_transform'; import expect from 'expect.js'; import sinon from 'sinon'; diff --git a/src/deprecation/create_transform.js b/src/deprecation/create_transform.js index c932796c1edcd..b1ce4777ba02a 100644 --- a/src/deprecation/create_transform.js +++ b/src/deprecation/create_transform.js @@ -1,7 +1,7 @@ import { deepCloneWithBuffers as clone } from '../utils'; import { forEach, noop } from 'lodash'; -export default function (deprecations) { +export function createTransform(deprecations) { return (settings, log = noop) => { const result = clone(settings); diff --git a/src/deprecation/deprecations/__tests__/rename.js b/src/deprecation/deprecations/__tests__/rename.js index 0d86829be14be..cab7ec1281e0c 100644 --- a/src/deprecation/deprecations/__tests__/rename.js +++ b/src/deprecation/deprecations/__tests__/rename.js @@ -1,5 +1,5 @@ import expect from 'expect.js'; -import rename from '../rename'; +import { rename } from '../rename'; import sinon from 'sinon'; describe('deprecation/deprecations', function () { diff --git a/src/deprecation/deprecations/__tests__/unused.js b/src/deprecation/deprecations/__tests__/unused.js index 27b5f1efeab4b..82b8730c91e0b 100644 --- a/src/deprecation/deprecations/__tests__/unused.js +++ b/src/deprecation/deprecations/__tests__/unused.js @@ -1,6 +1,6 @@ import expect from 'expect.js'; import sinon from 'sinon'; -import unused from '../unused'; +import { unused } from '../unused'; describe('deprecation/deprecations', function () { describe('unused', function () { diff --git a/src/deprecation/deprecations/index.js b/src/deprecation/deprecations/index.js index 03e9b892a2372..d3ce01a1234d0 100644 --- a/src/deprecation/deprecations/index.js +++ b/src/deprecation/deprecations/index.js @@ -1,2 +1,2 @@ -export rename from './rename'; -export unused from './unused'; +export { rename } from './rename'; +export { unused } from './unused'; diff --git a/src/deprecation/deprecations/rename.js b/src/deprecation/deprecations/rename.js index 59b73280ee9e1..89745a1cf95c1 100644 --- a/src/deprecation/deprecations/rename.js +++ b/src/deprecation/deprecations/rename.js @@ -1,7 +1,7 @@ import { get, isUndefined, noop, set } from 'lodash'; import { unset } from '../../utils'; -export default function (oldKey, newKey) { +export function rename(oldKey, newKey) { return (settings, log = noop) => { const value = get(settings, oldKey); if (isUndefined(value)) { diff --git a/src/deprecation/deprecations/unused.js b/src/deprecation/deprecations/unused.js index 67cbd21f52f5f..a37a44eab7b39 100644 --- a/src/deprecation/deprecations/unused.js +++ b/src/deprecation/deprecations/unused.js @@ -1,7 +1,7 @@ import { get, isUndefined, noop } from 'lodash'; import { unset } from '../../utils'; -export default function (oldKey) { +export function unused(oldKey) { return (settings, log = noop) => { const value = get(settings, oldKey); if (isUndefined(value)) { diff --git a/src/deprecation/index.js b/src/deprecation/index.js index 5ffc6eefab7d1..4c756cfc830c8 100644 --- a/src/deprecation/index.js +++ b/src/deprecation/index.js @@ -1,2 +1,4 @@ -export createTransform from './create_transform'; -export * as Deprecations from './deprecations'; +import { rename, unused } from './deprecations'; + +export { createTransform } from './create_transform'; +export const Deprecations = { rename, unused }; diff --git a/src/optimize/babel/helpers.js b/src/optimize/babel/helpers.js index a080edecad57e..6dffcc45cc062 100644 --- a/src/optimize/babel/helpers.js +++ b/src/optimize/babel/helpers.js @@ -9,39 +9,47 @@ if (!env.BABEL_CACHE_PATH) { exports.webpackCacheDir = env.WEBPACK_BABEL_CACHE_DIR || fromRoot('optimize/.webpack.babelcache'); -exports.nodePresets = [ - [ - require.resolve('babel-preset-env'), - { +const commonPreset = { + presets: [ + require.resolve('babel-preset-react') + ], + plugins: [ + require.resolve('babel-plugin-add-module-exports'), + // stage 3 + require.resolve('babel-plugin-transform-async-generator-functions'), + require.resolve('babel-plugin-transform-object-rest-spread'), + // stage 2 + require.resolve('babel-plugin-transform-class-properties'), + ], +} + +exports.nodePreset = { + presets: [ + [require.resolve('babel-preset-env'), { targets: { node: 'current' - } - } + }, + useBuiltIns: true, + }], + commonPreset, ], - require.resolve('babel-preset-stage-1'), - require.resolve('babel-preset-react'), -]; - -exports.webpackPresets = [ - [ - require.resolve('babel-preset-env'), - { +}; + +exports.webpackPreset = { + presets: [ + [require.resolve('babel-preset-env'), { targets: { browsers: [ 'last 2 versions', '> 5%', 'Safari 7' // for PhantomJS support ] - } - } + }, + useBuiltIns: true, + }], + commonPreset, ], - require.resolve('babel-preset-stage-1'), - require.resolve('babel-preset-react'), -] - -exports.plugins = [ - require.resolve('babel-plugin-add-module-exports'), -]; +} exports.devIgnore = [ /[\\\/](node_modules|bower_components)[\\\/]/ diff --git a/src/optimize/babel/options.build.js b/src/optimize/babel/options.build.js index f318b7d46334f..e13955768ab1a 100644 --- a/src/optimize/babel/options.build.js +++ b/src/optimize/babel/options.build.js @@ -1,19 +1,16 @@ const { - nodePresets, - webpackPresets, - plugins, + nodePreset, + webpackPreset, buildIgnore } = require('./helpers'); const nodeOptions = { - presets: nodePresets, - plugins, + presets: [nodePreset], ignore: buildIgnore }; exports.webpack = { - presets: webpackPresets, - plugins: plugins + presets: [webpackPreset], }; exports.node = nodeOptions; diff --git a/src/optimize/babel/options.js b/src/optimize/babel/options.js index 6da8838b4e186..81916562ff0c0 100644 --- a/src/optimize/babel/options.js +++ b/src/optimize/babel/options.js @@ -1,23 +1,20 @@ // this file is not transpiled in dev const { - nodePresets, - webpackPresets, + nodePreset, + webpackPreset, webpackCacheDir, - plugins, devIgnore } = require('./helpers'); const nodeOptions = { - presets: nodePresets, - plugins, + presets: [nodePreset], ignore: devIgnore }; exports.webpack = { cacheDirectory: webpackCacheDir, - presets: webpackPresets, - plugins: plugins + presets: [webpackPreset], }; exports.node = nodeOptions; diff --git a/src/optimize/babel/polyfills.js b/src/optimize/babel/polyfills.js new file mode 100644 index 0000000000000..ddb7d87c74bac --- /dev/null +++ b/src/optimize/babel/polyfills.js @@ -0,0 +1,2 @@ +// this is in it's own file so babel-preset-env can convert it to just the polyfills necessary +require('babel-polyfill'); diff --git a/src/optimize/babel/register.js b/src/optimize/babel/register.js index dc852184189e0..2fabf4fe94841 100644 --- a/src/optimize/babel/register.js +++ b/src/optimize/babel/register.js @@ -1,4 +1,3 @@ // this file is not transpiled in dev - -require('babel-polyfill'); require('./options').registerNodeOptions(); +require('./polyfills'); diff --git a/src/optimize/base_optimizer.js b/src/optimize/base_optimizer.js index 9280858d9baef..b54507807b9ea 100644 --- a/src/optimize/base_optimizer.js +++ b/src/optimize/base_optimizer.js @@ -10,7 +10,7 @@ import DefinePlugin from 'webpack/lib/DefinePlugin'; import UglifyJsPlugin from 'webpack/lib/optimize/UglifyJsPlugin'; import { defaults, transform } from 'lodash'; -import fromRoot from '../utils/from_root'; +import { fromRoot } from '../utils'; import babelOptions from './babel/options'; import pkg from '../../package.json'; import { setLoaderQueryParam, makeLoaderString } from './loaders'; diff --git a/src/server/http/__tests__/index.js b/src/server/http/__tests__/index.js index 786478e642d33..2380b4c747543 100644 --- a/src/server/http/__tests__/index.js +++ b/src/server/http/__tests__/index.js @@ -1,6 +1,6 @@ import expect from 'expect.js'; import * as kbnTestServer from '../../../../test/utils/kbn_server'; -import fromRoot from '../../../utils/from_root'; +import { fromRoot } from '../../../utils'; describe('routes', function () { this.slow(10000); diff --git a/src/ui/ui_bundler_env.js b/src/ui/ui_bundler_env.js index 0bd05ea61aeca..12ddc3ef16af2 100644 --- a/src/ui/ui_bundler_env.js +++ b/src/ui/ui_bundler_env.js @@ -1,4 +1,4 @@ -import fromRoot from '../utils/from_root'; +import { fromRoot } from '../utils'; import { includes } from 'lodash'; const arr = v => [].concat(v || []); diff --git a/src/utils/__tests__/deep_clone_with_buffers.js b/src/utils/__tests__/deep_clone_with_buffers.js index 02bb17c5c430c..90b75de1864a9 100644 --- a/src/utils/__tests__/deep_clone_with_buffers.js +++ b/src/utils/__tests__/deep_clone_with_buffers.js @@ -1,4 +1,4 @@ -import deepCloneWithBuffers from '../deep_clone_with_buffers'; +import { deepCloneWithBuffers } from '../deep_clone_with_buffers'; import expect from 'expect.js'; describe('deepCloneWithBuffers()', function () { diff --git a/src/utils/__tests__/unset.js b/src/utils/__tests__/unset.js index 5b26fccdf68c2..4f2fbb1efaa68 100644 --- a/src/utils/__tests__/unset.js +++ b/src/utils/__tests__/unset.js @@ -1,4 +1,4 @@ -import unset from '../unset'; +import { unset } from '../unset'; import expect from 'expect.js'; describe('unset(obj, key)', function () { diff --git a/src/utils/binder_for.js b/src/utils/binder_for.js index cb0a3f42dd57b..49b8452f5b032 100644 --- a/src/utils/binder_for.js +++ b/src/utils/binder_for.js @@ -1,6 +1,6 @@ import { BinderBase } from './binder'; -export default class BinderFor extends BinderBase { +export class BinderFor extends BinderBase { constructor(emitter) { super(); this.emitter = emitter; @@ -10,4 +10,3 @@ export default class BinderFor extends BinderBase { super.on(this.emitter, ...args); } } - diff --git a/src/utils/deep_clone_with_buffers.js b/src/utils/deep_clone_with_buffers.js index b61296b2b81ae..63161e5b1ba3a 100644 --- a/src/utils/deep_clone_with_buffers.js +++ b/src/utils/deep_clone_with_buffers.js @@ -6,6 +6,6 @@ function cloneBuffersCustomizer(val) { } } -export default function (vals) { +export function deepCloneWithBuffers(vals) { return cloneDeep(vals, cloneBuffersCustomizer); } diff --git a/src/utils/from_root.js b/src/utils/from_root.js index c5ecd37546ef5..1bb7ce0376fe5 100644 --- a/src/utils/from_root.js +++ b/src/utils/from_root.js @@ -1,5 +1,6 @@ -import _ from 'lodash'; -import { __dirname as root } from './package_json'; -import { join, normalize } from 'path'; +import { pkg } from './package_json'; +import { resolve } from 'path'; -module.exports = _.flow(_.partial(join, root), normalize); +export function fromRoot(...args) { + return resolve(pkg.__dirname, ...args); +} diff --git a/src/utils/index.js b/src/utils/index.js index 2a6bc33298ed8..6c8f7f8cef65e 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,11 +1,12 @@ export { BinderBase } from './binder'; -export BinderFor from './binder_for'; -export deepCloneWithBuffers from './deep_clone_with_buffers'; -export fromRoot from './from_root'; -export pkg from './package_json'; -export unset from './unset'; - +export { BinderFor } from './binder_for'; +export { deepCloneWithBuffers } from './deep_clone_with_buffers'; +export { fromRoot } from './from_root'; +export { pkg } from './package_json'; +export { unset } from './unset'; export { encodeQueryComponent } from './encode_query_component'; +export { modifyUrl } from './modify_url'; +export { createToolingLog } from './tooling_log'; export { createConcatStream, @@ -17,6 +18,3 @@ export { createReduceStream, createSplitStream, } from './streams'; - -export { modifyUrl } from './modify_url'; -export { createToolingLog } from './tooling_log'; diff --git a/src/utils/package_json.js b/src/utils/package_json.js index 7bc29253fa447..9662f8e3fdd69 100644 --- a/src/utils/package_json.js +++ b/src/utils/package_json.js @@ -1,5 +1,7 @@ import { dirname } from 'path'; -module.exports = require('../../package.json'); -module.exports.__filename = require.resolve('../../package.json'); -module.exports.__dirname = dirname(module.exports.__filename); +export const pkg = { + __filename: require.resolve('../../package.json'), + __dirname: dirname(require.resolve('../../package.json')), + ...require('../../package.json') +}; diff --git a/src/utils/unset.js b/src/utils/unset.js index 60de86dcb720d..11d2f428517b2 100644 --- a/src/utils/unset.js +++ b/src/utils/unset.js @@ -1,7 +1,7 @@ import _ from 'lodash'; import toPath from 'lodash/internal/toPath'; -module.exports = function unset(object, rawPath) { +export function unset(object, rawPath) { if (!object) return; const path = toPath(rawPath); @@ -23,4 +23,4 @@ module.exports = function unset(object, rawPath) { } break; } -}; \ No newline at end of file +} diff --git a/tasks/build/verify_translations.js b/tasks/build/verify_translations.js index 50dabda300210..ff18b34618363 100644 --- a/tasks/build/verify_translations.js +++ b/tasks/build/verify_translations.js @@ -1,7 +1,7 @@ import Promise from 'bluebird'; import _ from 'lodash'; -import fromRoot from '../../src/utils/from_root'; +import { fromRoot } from '../../src/utils'; import KbnServer from '../../src/server/kbn_server'; import * as i18nVerify from '../utils/i18n_verify_keys';