From fa5be4971ad1a3fb8f6214d8f21cc03ca60d6457 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Thu, 8 Aug 2019 09:38:51 -0400 Subject: [PATCH] Bugfix: Babel targets value can be a String (#8268) * Fix modern SSR build when Babel configuration uses a String value for "targets". Fixes #8255. * Add custom babelrc integration tests --- packages/next/build/babel/preset.ts | 6 +++++- .../fixtures/targets-browsers/.babelrc | 14 ++++++++++++++ .../fixtures/targets-browsers/pages/index.js | 1 + .../fixtures/targets-string/.babelrc | 12 ++++++++++++ .../fixtures/targets-string/pages/index.js | 1 + test/integration/babel-custom/test/.babelrc | 9 +++++++++ test/integration/babel-custom/test/index.test.js | 16 ++++++++++++++++ 7 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 test/integration/babel-custom/fixtures/targets-browsers/.babelrc create mode 100644 test/integration/babel-custom/fixtures/targets-browsers/pages/index.js create mode 100644 test/integration/babel-custom/fixtures/targets-string/.babelrc create mode 100644 test/integration/babel-custom/fixtures/targets-string/pages/index.js create mode 100644 test/integration/babel-custom/test/.babelrc create mode 100644 test/integration/babel-custom/test/index.test.js diff --git a/packages/next/build/babel/preset.ts b/packages/next/build/babel/preset.ts index 6d734457f2..a2671db80c 100644 --- a/packages/next/build/babel/preset.ts +++ b/packages/next/build/babel/preset.ts @@ -73,7 +73,11 @@ module.exports = ( // if not explicitly specified: if ( (isServer || isTest) && - (!presetEnvConfig.targets || !('node' in presetEnvConfig.targets)) + (!presetEnvConfig.targets || + !( + typeof presetEnvConfig.targets === 'object' && + 'node' in presetEnvConfig.targets + )) ) { presetEnvConfig.targets = { // Targets the current process' version of Node. This requires apps be diff --git a/test/integration/babel-custom/fixtures/targets-browsers/.babelrc b/test/integration/babel-custom/fixtures/targets-browsers/.babelrc new file mode 100644 index 0000000000..1ee00605c4 --- /dev/null +++ b/test/integration/babel-custom/fixtures/targets-browsers/.babelrc @@ -0,0 +1,14 @@ +{ + "presets": [ + [ + "next/babel", + { + "preset-env": { + "targets": { + "browsers": "chrome>71" + } + } + } + ] + ] +} \ No newline at end of file diff --git a/test/integration/babel-custom/fixtures/targets-browsers/pages/index.js b/test/integration/babel-custom/fixtures/targets-browsers/pages/index.js new file mode 100644 index 0000000000..69192c68a0 --- /dev/null +++ b/test/integration/babel-custom/fixtures/targets-browsers/pages/index.js @@ -0,0 +1 @@ +export default () =>

Hello World

diff --git a/test/integration/babel-custom/fixtures/targets-string/.babelrc b/test/integration/babel-custom/fixtures/targets-string/.babelrc new file mode 100644 index 0000000000..ebec263410 --- /dev/null +++ b/test/integration/babel-custom/fixtures/targets-string/.babelrc @@ -0,0 +1,12 @@ +{ + "presets": [ + [ + "next/babel", + { + "preset-env": { + "targets": "chrome>71" + } + } + ] + ] +} \ No newline at end of file diff --git a/test/integration/babel-custom/fixtures/targets-string/pages/index.js b/test/integration/babel-custom/fixtures/targets-string/pages/index.js new file mode 100644 index 0000000000..69192c68a0 --- /dev/null +++ b/test/integration/babel-custom/fixtures/targets-string/pages/index.js @@ -0,0 +1 @@ +export default () =>

Hello World

diff --git a/test/integration/babel-custom/test/.babelrc b/test/integration/babel-custom/test/.babelrc new file mode 100644 index 0000000000..27c7237aeb --- /dev/null +++ b/test/integration/babel-custom/test/.babelrc @@ -0,0 +1,9 @@ +{ + "presets": [ + ["next/babel", { + "preset-env": { + "modules": "commonjs" + } + }] + ] +} \ No newline at end of file diff --git a/test/integration/babel-custom/test/index.test.js b/test/integration/babel-custom/test/index.test.js new file mode 100644 index 0000000000..11c92f4eca --- /dev/null +++ b/test/integration/babel-custom/test/index.test.js @@ -0,0 +1,16 @@ +/* eslint-env jest */ +/* global jasmine */ +import { join } from 'path' +import { nextBuild } from 'next-test-utils' + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 + +describe('Babel', () => { + it('should allow setting targets.browsers', async () => { + await nextBuild(join(__dirname, '../fixtures/targets-browsers')) + }) + + it('should allow setting targets to a string', async () => { + await nextBuild(join(__dirname, '../fixtures/targets-string')) + }) +}) -- GitLab