Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[babel] tweak babel options for performance and debugging #11535

Merged
merged 4 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@
"babel-jest": "19.0.0",
"babel-loader": "6.2.10",
"babel-plugin-add-module-exports": "0.2.1",
"babel-plugin-syntax-dynamic-import": "6.18.0",
"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-plugin-transform-unicode-property-regex": "2.0.1",
Copy link
Contributor

@kimjoar kimjoar May 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is babel-plugin-transform-unicode-property-regex and babel-plugin-syntax-dynamic-import used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally basing the list of plugins off of babel#master, rather than the released versions

"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",
Expand Down Expand Up @@ -204,6 +205,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",
Expand All @@ -219,7 +221,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",
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/cli/cluster/cluster_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/cli.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/install/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/list/__tests__/settings.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion src/cli_plugin/remove/__tests__/settings.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion src/core_plugins/elasticsearch/lib/__tests__/routes.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion src/deprecation/__tests__/create_transform.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import createTransform from '../create_transform';
import { createTransform } from '../create_transform';
import expect from 'expect.js';
import sinon from 'sinon';

Expand Down
2 changes: 1 addition & 1 deletion src/deprecation/create_transform.js
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/deprecation/deprecations/__tests__/rename.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion src/deprecation/deprecations/__tests__/unused.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
4 changes: 2 additions & 2 deletions src/deprecation/deprecations/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export rename from './rename';
export unused from './unused';
export { rename } from './rename';
export { unused } from './unused';
2 changes: 1 addition & 1 deletion src/deprecation/deprecations/rename.js
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/deprecation/deprecations/unused.js
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down
6 changes: 4 additions & 2 deletions src/deprecation/index.js
Original file line number Diff line number Diff line change
@@ -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 };
54 changes: 31 additions & 23 deletions src/optimize/babel/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)[\\\/]/
Expand Down
11 changes: 4 additions & 7 deletions src/optimize/babel/options.build.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
11 changes: 4 additions & 7 deletions src/optimize/babel/options.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/optimize/babel/polyfills.js
Original file line number Diff line number Diff line change
@@ -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');
3 changes: 1 addition & 2 deletions src/optimize/babel/register.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// this file is not transpiled in dev

require('babel-polyfill');
require('./options').registerNodeOptions();
require('./polyfills');
2 changes: 1 addition & 1 deletion src/optimize/base_optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/server/http/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/ui_bundler_env.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fromRoot from '../utils/from_root';
import { fromRoot } from '../utils';
import { includes } from 'lodash';

const arr = v => [].concat(v || []);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/__tests__/deep_clone_with_buffers.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/__tests__/unset.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import unset from '../unset';
import { unset } from '../unset';
import expect from 'expect.js';

describe('unset(obj, key)', function () {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/binder_for.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,4 +10,3 @@ export default class BinderFor extends BinderBase {
super.on(this.emitter, ...args);
}
}

2 changes: 1 addition & 1 deletion src/utils/deep_clone_with_buffers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ function cloneBuffersCustomizer(val) {
}
}

export default function (vals) {
export function deepCloneWithBuffers(vals) {
return cloneDeep(vals, cloneBuffersCustomizer);
}
9 changes: 5 additions & 4 deletions src/utils/from_root.js
Original file line number Diff line number Diff line change
@@ -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);
}
16 changes: 7 additions & 9 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,6 +18,3 @@ export {
createReduceStream,
createSplitStream,
} from './streams';

export { modifyUrl } from './modify_url';
export { createToolingLog } from './tooling_log';
Loading