-
Notifications
You must be signed in to change notification settings - Fork 28
Update packages to work with Babel 7 #136
Changes from all 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() {} }; |
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 😄