Skip to content

Commit

Permalink
[kbn-test] upgrade to babel7, add ts support (#32168) (#32226)
Browse files Browse the repository at this point in the history
* [babel] add babel7 compatible node preset

* [kbn-test] upgrade to babel7 preset
  • Loading branch information
Spencer authored Feb 28, 2019
1 parent dcfa8e9 commit 1194d14
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 98 deletions.
39 changes: 39 additions & 0 deletions packages/kbn-babel-preset/common_preset_7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

module.exports = {
presets: [
require.resolve('@babel/preset-react'),
require.resolve('@babel/preset-typescript'),
],
plugins: [
require.resolve('babel7-plugin-add-module-exports'),
// stage 3
require.resolve('@babel/plugin-proposal-async-generator-functions'),
require.resolve('@babel/plugin-proposal-object-rest-spread'),

// the class properties proposal was merged with the private fields proposal
// into the "class fields" proposal. Babel doesn't support this combined
// proposal yet, which includes private field, so this transform is
// TECHNICALLY stage 2, but for all intents and purposes it's stage 3
//
// See https://github.com/babel/proposals/issues/12 for progress
require.resolve('@babel/plugin-proposal-class-properties'),
],
};
50 changes: 50 additions & 0 deletions packages/kbn-babel-preset/node_preset_7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

module.exports = () => ({
presets: [
[
require.resolve('@babel/preset-env'),
{
targets: {
// only applies the necessary transformations based on the
// current node.js processes version. For example: running
// `nvm install 8 && node ./src/cli` will run kibana in node
// version 8 and babel will stop transpiling async/await
// because they are supported in the "current" version of node
node: 'current',
},

// replaces `import "babel-polyfill"` with a list of require statements
// for just the polyfills that the target versions don't already supply
// on their own
useBuiltIns: 'entry',
},
],
require('./common_preset_7'),
],
plugins: [
[
require.resolve('babel-plugin-transform-define'),
{
'global.__BUILT_WITH_BABEL__': 'true'
}
]
]
});
12 changes: 10 additions & 2 deletions packages/kbn-babel-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
"version": "1.0.0",
"license": "Apache-2.0",
"dependencies": {
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-async-generator-functions": "^7.2.0",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"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-define": "^1.3.0",
"babel-plugin-transform-define": "^1.3.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1"
"babel-preset-react": "^6.24.1",
"babel7-plugin-add-module-exports": "npm:babel-plugin-add-module-exports@^1.0.0"
}
}
3 changes: 0 additions & 3 deletions packages/kbn-test/.babelrc

This file was deleted.

23 changes: 23 additions & 0 deletions packages/kbn-test/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

module.exports = {
presets: ['@kbn/babel-preset/node_preset_7'],
ignore: ['**/*.test.js'],
};
6 changes: 3 additions & 3 deletions packages/kbn-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "babel src --out-dir target",
"kbn:bootstrap": "yarn build --quiet",
"build": "babel src --out-dir target --delete-dir-on-start --extensions .ts,.js,.tsx",
"kbn:bootstrap": "yarn build",
"kbn:watch": "yarn build --watch"
},
"devDependencies": {
"@kbn/babel-preset": "1.0.0",
"@kbn/dev-utils": "1.0.0",
"babel-cli": "^6.26.0"
"@babel/cli": "^7.2.3"
},
"dependencies": {
"chalk": "^2.4.1",
Expand Down
Loading

0 comments on commit 1194d14

Please sign in to comment.