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

Update to Babel 7 #845

Merged
merged 2 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
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
12 changes: 8 additions & 4 deletions packages/jest/src/transformer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
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 wrap the higher-level babel-jest 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, { 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
2 changes: 1 addition & 1 deletion packages/mocha/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = (neutrino, opts = {}) => {

neutrino.config.when(usingBabel, () => {
neutrino.use(loaderMerge('compile', 'babel'), {
plugins: [require.resolve('babel-plugin-transform-es2015-modules-commonjs')]
plugins: [require.resolve('@babel/plugin-transform-modules-commonjs')]
});
});

Expand Down
Loading