Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use babel-plugin-transform-async-to-promises #579

Closed
wants to merge 3 commits into from
Closed
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
24 changes: 12 additions & 12 deletions examples/kitchen-sink/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import * as appContext from '@financial-times/dotcom-ui-app-context'
import * as tracking from '@financial-times/n-tracking'
import * as ads from '@financial-times/n-ads'

domLoaded.then(() => {
async function main() {
await domLoaded
const flagsClient = flags.init()
const appContextClient = appContext.init()

layout.init()

tracking.init({ appContext: appContextClient.getAll() })

ads
.init(
{
trackingCallback: console.log // eslint-disable-line no-console
},
flagsClient
)
.then(() => {
// Ads slots are ready and will request ads
})
})
await ads.init(
{
trackingCallback: console.log // eslint-disable-line no-console
},
flagsClient
)
// Ads slots are ready and will request ads
}

main()
1 change: 1 addition & 0 deletions packages/dotcom-page-kit-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@financial-times/dotcom-page-kit-pluggable": "file:../dotcom-page-kit-pluggable",
"ansi-escapes": "^4.0.0",
"babel-loader": "^8.0.5",
"babel-plugin-transform-async-to-promises": "^0.8.14",
"clean-webpack-plugin": "^3.0.0",
"cli-progress": "^3.0.0",
"commander": "^3.0.0",
Expand Down
15 changes: 11 additions & 4 deletions packages/dotcom-page-kit-cli/src/operations/getBabelConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ export function getBabelConfig(cli: CliContext) {

const presetEnvOpts = {
targets: get(cli, 'config.settings.build.targets') || defaultTargets,
// Exclude transforms that make all code slower
// See https://github.com/facebook/create-react-app/pull/5278
exclude: ['transform-typeof-symbol']
// Exclude transforms we don't want
exclude: [
'@babel/plugin-transform-typeof-symbol', // makes all code slower https://github.com/facebook/create-react-app/pull/5278
'@babel/plugin-transform-async-to-generator', // we're using transform-async-to-promises instead
'@babel/plugin-transform-regenerator'
]
}

const pluginAsyncOpts = {
inlineHelpers: true
}

const babelConfig = {
// By default Babel assumes all source code is ESM so force it to check for CJS
sourceType: 'unambiguous',
presets: [[require.resolve('@babel/preset-env'), presetEnvOpts]],
plugins: [],
plugins: [[require.resolve('babel-plugin-transform-async-to-promises'), pluginAsyncOpts]],
babelrc: true,
cacheDirectory: true
}
Expand Down