Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Update to Babel 7
Browse files Browse the repository at this point in the history
Notable changes:
* All official packages have moved under the `@babel/` namespace and in
  some cases further renamed, so package names adjusted accordingly.
* `@babel/preset-env` now includes `@babel/plugin-transform-spread` and
  `@babel/plugin-transform-classes`, which are the Babel 7 renames of
  `babel-plugin-transform-object-rest-spread` and
  `babel-plugin-transform-es2015-classes`.
* `@babel/preset-env`'s `useBuiltIns: true` mode has been renamed to
  `useBuiltIns: 'entry'` - which is equivalent.
* `@babel/preset-react` now has `development` and `useBuiltIns` options,
  which we set appropriately:
  https://github.com/babel/babel/tree/v7.0.0-beta.46/packages/babel-preset-react#options
* `babel-plugin-dynamic-import-node` is no longer required by
  `@neutrinojs/library` for target `node`, since webpack converts the
  dynamic import to a require itself.
* `@neutrinojs/jest` required more substantial changes since:
  - the custom transformer used the now removed `canCompile()` from
    Babel's API.
  - `babel-preset-jest` is not fully compatible with Babel 7
    (jestjs/jest#6126).
* Several packages now have a peer dependency on `@babel/core`, so it's
  been added where necessary.
* `babel-loader` has been updated to v8 for Babel 7 compatibility.
* `@neutrinojs/vue`'s `babel-preset-vue` dependency doesn't appear to
  be used, but has been left as is pending #836.

Closes #316.
  • Loading branch information
edmorley committed May 6, 2018
1 parent 9985fd2 commit 52a0f48
Show file tree
Hide file tree
Showing 36 changed files with 841 additions and 455 deletions.
4 changes: 2 additions & 2 deletions docs/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ index 3356802..d4d82ef 100644
devtool: 'source-map',
entry: {
index: [
- 'babel-polyfill',
'/node/src/index.js'
- '/node/src/index.js'
+ '/node/src/app.js'
]
},
```
Expand Down
10 changes: 5 additions & 5 deletions docs/packages/compile-loader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const { merge } = require('@neutrinojs/compile-loader');
const together = merge(
{
presets: [
['babel-preset-env', {
['@babel/preset-env', {
targets: {
browsers: ['latest 1 Chrome']
}
Expand All @@ -91,7 +91,7 @@ const together = merge(
},
{
presets: [
['babel-preset-env', {
['@babel/preset-env', {
targets: {
browsers: ['latest 1 Firefox']
}
Expand All @@ -105,7 +105,7 @@ console.log(together);
// Logs:
{
presets: [
['babel-preset-env', {
['@babel/preset-env', {
targets: {
browsers: [
'latest 1 Chrome',
Expand Down Expand Up @@ -139,8 +139,8 @@ config.module
.use('babel')
.tap(options => merge({
plugins: [
require.resolve('babel-plugin-transform-decorators-legacy'),
require.resolve('babel-plugin-transform-class-properties')
require.resolve('@babel/plugin-proposal-decorators'),
require.resolve('@babel/plugin-proposal-class-properties')
]
}, options));
```
Expand Down
10 changes: 5 additions & 5 deletions docs/packages/library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ module.exports = {

// Add additional Babel plugins, presets, or env options
babel: {
// Override options for babel-preset-env
// Override options for @babel/preset-env
presets: [
['babel-preset-env', {
// Passing in browser targets to babel-preset-env will replace them
['@babel/preset-env', {
// Passing in browser targets to @babel/preset-env will replace them
// instead of merging them when using the 'web' target
targets: {
browsers: [
Expand All @@ -282,9 +282,9 @@ module.exports = {
libraryTarget: 'commonjs2',
// Add additional Babel plugins, presets, or env options
babel: {
// Override options for babel-preset-env
// Override options for @babel/preset-env
presets: [
['babel-preset-env', {
['@babel/preset-env', {
targets: {
node: '6.0'
}
Expand Down
8 changes: 4 additions & 4 deletions docs/packages/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ module.exports = {
// Enables Hot Module Replacement. Set to false to disable
hot: true,

// Target specific versions via babel-preset-env
// Target specific versions via @babel/preset-env
targets: {
node: '8.3'
},
Expand All @@ -268,9 +268,9 @@ module.exports = {

// Add additional Babel plugins, presets, or env options
babel: {
// Override options for babel-preset-env, showing defaults:
// Override options for @babel/preset-env, showing defaults:
presets: [
['babel-preset-env', {
['@babel/preset-env', {
targets: { node: '8.3' },
modules: false,
useBuiltIns: true,
Expand All @@ -288,7 +288,7 @@ _Example: Override the Node.js Babel compilation target to Node.js v6:_
module.exports = {
use: [
['@neutrinojs/node', {
// Target specific versions via babel-preset-env
// Target specific versions via @babel/preset-env
targets: {
node: '6.0'
}
Expand Down
6 changes: 3 additions & 3 deletions docs/packages/preact/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ module.exports = {
title: 'Epic Preact App'
},

// Target specific browsers with babel-preset-env
// Target specific browsers with @babel/preset-env
targets: {
browsers: [
'last 1 Chrome versions',
Expand All @@ -224,9 +224,9 @@ module.exports = {

// Add additional Babel plugins, presets, or env options
babel: {
// Override options for babel-preset-env:
// Override options for @babel/preset-env:
presets: [
['babel-preset-env', {
['@babel/preset-env', {
modules: false,
useBuiltIns: true,
}]
Expand Down
4 changes: 2 additions & 2 deletions docs/packages/react-components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ other Neutrino middleware, so you can build, test, and publish multiple React co
- Production-optimized bundles with minification, easy chunking, and scope-hoisted modules for faster execution
- Easily extensible to customize your project as needed

**Important! This preset does not include babel-polyfill for size reasons. If you need
polyfills in your library code, consider importing babel-polyfill, core-js, or other alternative.**
**Important! This preset does not include @babel/polyfill for size reasons. If you need
polyfills in your library code, consider importing @babel/polyfill, core-js, or other alternative.**

## Requirements

Expand Down
6 changes: 3 additions & 3 deletions docs/packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ module.exports = {
title: 'Epic React App'
},

// Target specific browsers with babel-preset-env
// Target specific browsers with @babel/preset-env
targets: {
browsers: [
'last 1 Chrome versions',
Expand All @@ -213,9 +213,9 @@ module.exports = {

// Add additional Babel plugins, presets, or env options
babel: {
// Override options for babel-preset-env:
// Override options for @babel/preset-env:
presets: [
['babel-preset-env', {
['@babel/preset-env', {
modules: false,
useBuiltIns: true,
}]
Expand Down
6 changes: 3 additions & 3 deletions docs/packages/vue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ module.exports = {
title: 'Epic Vue App'
},

// Target specific browsers with babel-preset-env
// Target specific browsers with @babel/preset-env
targets: {
browsers: [
'last 1 Chrome versions',
Expand All @@ -229,9 +229,9 @@ module.exports = {

// Add additional Babel plugins, presets, or env options
babel: {
// Override options for babel-preset-env:
// Override options for @babel/preset-env:
presets: [
['babel-preset-env', {
['@babel/preset-env', {
modules: false,
useBuiltIns: true,
}]
Expand Down
8 changes: 4 additions & 4 deletions docs/packages/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ module.exports = {
proxy: 'https://localhost:8000/api/'
},

// Target specific browsers with babel-preset-env
// Target specific browsers with @babel/preset-env
targets: {
browsers: [
'last 1 Chrome versions',
Expand All @@ -241,9 +241,9 @@ module.exports = {

// Add additional Babel plugins, presets, or env options
babel: {
// Override options for babel-preset-env:
// Override options for @babel/preset-env:
presets: [
['babel-preset-env', {
['@babel/preset-env', {
modules: false,
useBuiltIns: true,
}]
Expand Down Expand Up @@ -277,7 +277,7 @@ module.exports = {
source: false
},

// Example: Use a .browserslistrc file with babel-env
// Example: Use a .browserslistrc file with @babel/preset-env
targets: {
browsers: require('browserslist')()
},
Expand Down
2 changes: 1 addition & 1 deletion docs/presets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ types, but anyone can inherit, extend, and modify these presets and tailor them
team, or company preferences. You can even create your own presets from scratch.

If you are familiar with Babel presets, Neutrino presets work similarly. For example,
given the Babel preset `babel-preset-react`, you can compile React code with JSX
given the Babel preset `@babel/preset-react`, you can compile React code with JSX
to vanilla JavaScript calls. Neutrino adopts this same concept by adapting webpack into
a tool that understands configurations-as-packages, i.e. presets. Many more aspects of
development surround building a complete React project, for which webpack is commonly used.
Expand Down
10 changes: 5 additions & 5 deletions packages/compile-loader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const { merge } = require('@neutrinojs/compile-loader');
const together = merge(
{
presets: [
['babel-preset-env', {
['@babel/preset-env', {
targets: {
browsers: ['latest 1 Chrome']
}
Expand All @@ -91,7 +91,7 @@ const together = merge(
},
{
presets: [
['babel-preset-env', {
['@babel/preset-env', {
targets: {
browsers: ['latest 1 Firefox']
}
Expand All @@ -105,7 +105,7 @@ console.log(together);
// Logs:
{
presets: [
['babel-preset-env', {
['@babel/preset-env', {
targets: {
browsers: [
'latest 1 Chrome',
Expand Down Expand Up @@ -139,8 +139,8 @@ config.module
.use('babel')
.tap(options => merge({
plugins: [
require.resolve('babel-plugin-transform-decorators-legacy'),
require.resolve('babel-plugin-transform-class-properties')
require.resolve('@babel/plugin-proposal-decorators'),
require.resolve('@babel/plugin-proposal-class-properties')
]
}, options));
```
Expand Down
4 changes: 2 additions & 2 deletions packages/compile-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"yarn": ">=1.2.1"
},
"dependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"@babel/core": "^7.0.0-beta.46",
"babel-loader": "^8.0.0-beta.2",
"babel-merge": "^1.1.1",
"deepmerge": "^1.5.2",
"webpack": "^4.7.0"
Expand Down
6 changes: 3 additions & 3 deletions packages/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"yarn": ">=1.2.1"
},
"dependencies": {
"@babel/core": "^7.0.0-beta.46",
"@babel/plugin-transform-modules-commonjs": "^7.0.0-beta.46",
"@neutrinojs/loader-merge": "^8.2.0",
"babel-core": "^6.26.3",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-preset-jest": "^22.4.3",
"babel-plugin-jest-hoist": "^22.4.3",
"deepmerge": "^1.5.2",
"eslint": "^4.19.1",
"eslint-plugin-jest": "^21.15.1",
Expand Down
10 changes: 8 additions & 2 deletions packages/jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ module.exports = (neutrino, opts = {}) => {
neutrino.config.when(usingBabel, () => {
neutrino.use(loaderMerge('compile', 'babel'), {
retainLines: true,
presets: [require.resolve('babel-preset-jest')],
plugins: [
require.resolve('babel-plugin-transform-es2015-modules-commonjs')
// Once babel-preset-jest has better Babel 7 support we should switch back to it
// (or even use babel-jest, which will allow simplifying the transformer too):
// https://github.com/facebook/jest/issues/6126
// For now this plugin is taken from here (we don't need object-rest-spread since node >=8.3):
// https://github.com/facebook/jest/blob/v22.4.2/packages/babel-preset-jest/index.js#L11-L12
require.resolve('babel-plugin-jest-hoist'),
// Since the tests will be run by node which doesn't yet support ES2015 modules
require.resolve('@babel/plugin-transform-modules-commonjs')
]
});
});
Expand Down
16 changes: 12 additions & 4 deletions packages/jest/src/transformer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const babel = require('babel-core');
const { transform } = require('@babel/core');

module.exports = {
// This is inspired by:
// https://github.com/facebook/jest/blob/v22.4.2/packages/babel-jest/src/index.js#L105-L147
// And is required due to:
// https://github.com/facebook/jest/issues/1468
// TODO: See if it would be easier to switch to the higher-level babel-jest,
// and wrap that instead.
process(src, filename, config) {
return babel.util.canCompile(filename) ?
babel.transform(src, Object.assign({}, { filename }, config.globals.BABEL_OPTIONS)).code :
src;
// Babel 7 returns null if the file was ignored.
return transform(
src,
Object.assign({}, { filename }, config.globals.BABEL_OPTIONS)
) || src;
}
};
10 changes: 5 additions & 5 deletions packages/library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ module.exports = {

// Add additional Babel plugins, presets, or env options
babel: {
// Override options for babel-preset-env
// Override options for @babel/preset-env
presets: [
['babel-preset-env', {
// Passing in browser targets to babel-preset-env will replace them
['@babel/preset-env', {
// Passing in browser targets to @babel/preset-env will replace them
// instead of merging them when using the 'web' target
targets: {
browsers: [
Expand All @@ -282,9 +282,9 @@ module.exports = {
libraryTarget: 'commonjs2',
// Add additional Babel plugins, presets, or env options
babel: {
// Override options for babel-preset-env
// Override options for @babel/preset-env
presets: [
['babel-preset-env', {
['@babel/preset-env', {
targets: {
node: '6.0'
}
Expand Down
8 changes: 3 additions & 5 deletions packages/library/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ module.exports = (neutrino, opts = {}) => {
Object.assign(options, {
babel: compileLoader.merge({
plugins: [
options.target === 'node' ?
require.resolve('babel-plugin-dynamic-import-node') :
require.resolve('babel-plugin-syntax-dynamic-import')
require.resolve('@babel/plugin-syntax-dynamic-import')
],
presets: [
[require.resolve('babel-preset-env'), {
[require.resolve('@babel/preset-env'), {
debug: neutrino.options.debug,
modules: false,
useBuiltIns: true,
useBuiltIns: 'entry',
targets: options.target === 'node' ?
{ node: '8.3' } :
{ browsers: [] }
Expand Down
5 changes: 3 additions & 2 deletions packages/library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
"yarn": ">=1.2.1"
},
"dependencies": {
"@babel/core": "^7.0.0-beta.46",
"@babel/plugin-syntax-dynamic-import": "^7.0.0-beta.46",
"@babel/preset-env": "^7.0.0-beta.46",
"@neutrinojs/banner": "^8.2.0",
"@neutrinojs/clean": "^8.2.0",
"@neutrinojs/compile-loader": "^8.2.0",
"@neutrinojs/loader-merge": "^8.2.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-preset-env": "^1.6.1",
"deepmerge": "^1.5.2",
"webpack": "^4.7.0",
"webpack-node-externals": "^1.7.2",
Expand Down
5 changes: 3 additions & 2 deletions packages/mocha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
"yarn": ">=1.2.1"
},
"dependencies": {
"@babel/core": "^7.0.0-beta.46",
"@babel/plugin-transform-modules-commonjs": "^7.0.0-beta.46",
"@babel/register": "^7.0.0-beta.46",
"@neutrinojs/loader-merge": "^8.2.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-register": "^6.26.0",
"change-case": "^3.0.2",
"deepmerge": "^1.5.2",
"mocha": "^5.1.1",
Expand Down
Loading

0 comments on commit 52a0f48

Please sign in to comment.