From b0e9ff7ce07a52887b161f52095f51ca2b7733a6 Mon Sep 17 00:00:00 2001 From: bren Date: Mon, 9 Sep 2019 16:42:05 +0100 Subject: [PATCH 1/3] use async/await for kitchen sink example so we can test the compilation --- examples/kitchen-sink/client/main.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/kitchen-sink/client/main.js b/examples/kitchen-sink/client/main.js index 87f310f12..801cc08dc 100644 --- a/examples/kitchen-sink/client/main.js +++ b/examples/kitchen-sink/client/main.js @@ -5,7 +5,8 @@ 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() @@ -13,14 +14,13 @@ domLoaded.then(() => { 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() From 32416e80f89bd960d368de4b6207be7585c3e166 Mon Sep 17 00:00:00 2001 From: bren Date: Mon, 9 Sep 2019 16:43:01 +0100 Subject: [PATCH 2/3] use babel-plugin-transform-async-to-promises --- packages/dotcom-page-kit-cli/package.json | 1 + .../src/operations/getBabelConfig.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/dotcom-page-kit-cli/package.json b/packages/dotcom-page-kit-cli/package.json index 76388ce14..fa2b5c7a5 100644 --- a/packages/dotcom-page-kit-cli/package.json +++ b/packages/dotcom-page-kit-cli/package.json @@ -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", diff --git a/packages/dotcom-page-kit-cli/src/operations/getBabelConfig.ts b/packages/dotcom-page-kit-cli/src/operations/getBabelConfig.ts index 823742884..1064c45e2 100644 --- a/packages/dotcom-page-kit-cli/src/operations/getBabelConfig.ts +++ b/packages/dotcom-page-kit-cli/src/operations/getBabelConfig.ts @@ -13,16 +13,19 @@ 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 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')], babelrc: true, cacheDirectory: true } From 4416212074e79e0e26ed042af00c7a6d299b73f3 Mon Sep 17 00:00:00 2001 From: bren brightwell Date: Mon, 14 Oct 2019 11:41:36 +0100 Subject: [PATCH 3/3] use inlineHelpers --- .../dotcom-page-kit-cli/src/operations/getBabelConfig.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/dotcom-page-kit-cli/src/operations/getBabelConfig.ts b/packages/dotcom-page-kit-cli/src/operations/getBabelConfig.ts index 1064c45e2..7953afcc4 100644 --- a/packages/dotcom-page-kit-cli/src/operations/getBabelConfig.ts +++ b/packages/dotcom-page-kit-cli/src/operations/getBabelConfig.ts @@ -20,12 +20,16 @@ export function getBabelConfig(cli: CliContext) { '@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: [require.resolve('babel-plugin-transform-async-to-promises')], + plugins: [[require.resolve('babel-plugin-transform-async-to-promises'), pluginAsyncOpts]], babelrc: true, cacheDirectory: true }