-
Notifications
You must be signed in to change notification settings - Fork 28
Update packages to work with Babel 7 #136
Changes from 3 commits
a646d88
b3ca12b
5c12ea8
22f6cf9
426a9dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = function( api ) { | ||
api.cache( true ); | ||
|
||
return { | ||
presets: [ '@wordpress/babel-preset-default' ], | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
const env = process.env.BABEL_ENV || process.env.NODE_ENV; | ||
const isTestEnv = env === 'test'; | ||
module.exports = function( api ) { | ||
const isTestEnv = api.env() === 'test'; | ||
|
||
module.exports = { | ||
presets: [ | ||
! isTestEnv && [ require( 'babel-preset-env' ), { | ||
modules: false, | ||
targets: { | ||
browsers: [ 'extends @wordpress/browserslist-config' ], | ||
}, | ||
} ], | ||
isTestEnv && [ require( 'babel-preset-env' ) ], | ||
].filter( Boolean ), | ||
plugins: [ | ||
require( 'babel-plugin-transform-object-rest-spread' ), | ||
[ require( 'babel-plugin-transform-react-jsx' ), { | ||
pragma: 'wp.element.createElement', | ||
} ], | ||
require( 'babel-plugin-transform-async-generator-functions' ), | ||
! isTestEnv && require( 'babel-plugin-transform-runtime' ), | ||
].filter( Boolean ), | ||
return { | ||
presets: [ | ||
! isTestEnv && [ '@babel/preset-env', { | ||
modules: false, | ||
targets: { | ||
browsers: [ 'extends @wordpress/browserslist-config' ], | ||
}, | ||
useBuiltIns: 'usage', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we can make this work, this would be a big improvement ❤️ |
||
} ], | ||
isTestEnv && [ '@babel/preset-env', { | ||
useBuiltIns: 'usage', | ||
} ], | ||
].filter( Boolean ), | ||
plugins: [ | ||
'@babel/plugin-proposal-object-rest-spread', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if the Babel core has been updated for it yet, but Rest/Spread was ratified as part of ES2018, so it might be possible to remove this. https://github.com/tc39/proposals/blob/master/finished-proposals.md |
||
[ '@babel/plugin-transform-react-jsx', { | ||
pragma: 'wp.element.createElement', | ||
} ], | ||
'@babel/plugin-proposal-async-generator-functions', | ||
! isTestEnv && '@babel/plugin-transform-runtime', | ||
].filter( Boolean ), | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,14 @@ | |
"node": ">=8" | ||
}, | ||
"dependencies": { | ||
"@babel/plugin-proposal-async-generator-functions": "^7.0.0-beta.49", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.49", | ||
"@babel/plugin-transform-react-jsx": "^7.0.0-beta.49", | ||
"@babel/plugin-transform-runtime": "^7.0.0-beta.49", | ||
"@babel/preset-env": "^7.0.0-beta.49", | ||
"@babel/runtime": "^7.0.0-beta.49", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we shouldn't add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we can't just remove the runtime since we're using the polyfills of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, |
||
"@wordpress/browserslist-config": "^2.1.4", | ||
"babel-plugin-transform-async-generator-functions": "^6.24.1", | ||
"babel-plugin-transform-object-rest-spread": "^6.23.0", | ||
"babel-plugin-transform-react-jsx": "^6.24.1", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-env": "^1.6.1" | ||
"babel-core": "7.0.0-bridge.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,35 +13,6 @@ global.window.matchMedia = () => ( { | |
removeListener: () => {}, | ||
} ); | ||
|
||
global.window._wpDateSettings = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
formats: { | ||
date: 'j F Y', | ||
datetime: 'j F Y G \h i \m\i\n', | ||
time: 'G \h i \m\i\n', | ||
}, | ||
l10n: { | ||
locale: 'en', | ||
meridiem: { | ||
am: 'am', | ||
AM: 'AM', | ||
pm: 'pm', | ||
PM: 'PM', | ||
}, | ||
months: [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ], | ||
monthsShort: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ], | ||
weekdays: [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ], | ||
weekdaysShort: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ], | ||
relative: { | ||
future: '%s from now', | ||
past: '%s ago', | ||
}, | ||
}, | ||
timezone: { | ||
offset: '-5', | ||
string: 'America/New_York', | ||
}, | ||
}; | ||
|
||
// Setup fake localStorage | ||
const storage = {}; | ||
global.window.localStorage = { | ||
|
@@ -51,6 +22,3 @@ global.window.localStorage = { | |
|
||
// UserSettings global | ||
global.window.userSettings = { uid: 1 }; | ||
|
||
// Mock jQuery | ||
global.window.jQuery = { holdReady() {} }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
const fs = require( 'fs' ); | ||
const path = require( 'path' ); | ||
const glob = require( 'glob' ); | ||
const babel = require( 'babel-core' ); | ||
const babel = require( '@babel/core' ); | ||
const chalk = require( 'chalk' ); | ||
const mkdirp = require( 'mkdirp' ); | ||
|
||
|
@@ -30,20 +30,23 @@ const ERROR = chalk.reset.inverse.bold.red( ' ERROR ' ); | |
/** | ||
* Babel Configuration | ||
*/ | ||
const babelDefaultConfig = require( '../packages/babel-preset-default' ); | ||
babelDefaultConfig.babelrc = false; | ||
const { options: babelDefaultConfig } = babel.loadPartialConfig( { | ||
presets: [ '@wordpress/babel-preset-default' ], | ||
} ); | ||
const presetEnvConfig = babelDefaultConfig.presets[ 0 ][ 1 ]; | ||
const babelConfigs = { | ||
main: Object.assign( | ||
{}, | ||
babelDefaultConfig, | ||
{ presets: [ | ||
[ 'env', Object.assign( | ||
{}, | ||
presetEnvConfig, | ||
{ modules: 'commonjs' }, | ||
) ], | ||
] } | ||
{ | ||
presets: [ | ||
[ '@babel/preset-env', Object.assign( | ||
{}, | ||
presetEnvConfig, | ||
{ modules: 'commonjs' }, | ||
) ], | ||
] | ||
} | ||
), | ||
module: babelDefaultConfig, | ||
}; | ||
|
@@ -114,10 +117,10 @@ function buildFileFor( file, silent, environment ) { | |
if ( ! silent ) { | ||
process.stdout.write( | ||
chalk.green( ' \u2022 ' ) + | ||
path.relative( PACKAGES_DIR, file ) + | ||
chalk.green( ' \u21D2 ' ) + | ||
path.relative( PACKAGES_DIR, destPath ) + | ||
'\n' | ||
path.relative( PACKAGES_DIR, file ) + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooops :) |
||
chalk.green( ' \u21D2 ' ) + | ||
path.relative( PACKAGES_DIR, destPath ) + | ||
'\n' | ||
); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing this, is it useless?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jest can read Babel from its config, and the script which generates the distribution folders for packages uses the same preset internally. So it isn't necessary anymore - it uses defaults :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add
babel.config.js
instead to make everything work 😄