Skip to content

Commit

Permalink
fix: Revert #18921 and inline absolute babel runtime only for YarnPnp (
Browse files Browse the repository at this point in the history
…#19542)

This reverts #18921 and ensures that the Babel runtime is only inlined as an absolute path when using PnP as before, but then including the correction this resolution as implemented by @merceyz only in the PnP cases, while keeping the diff to a minimum.
  • Loading branch information
guybedford committed Nov 25, 2020
1 parent 899a29c commit 9dd5ff2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions packages/next/build/babel/preset.ts
@@ -1,6 +1,5 @@
import { PluginItem } from 'next/dist/compiled/babel/core'
import { dirname } from 'path'

const env = process.env.NODE_ENV
const isProduction = env === 'production'
const isDevelopment = env === 'development'
Expand Down Expand Up @@ -170,9 +169,9 @@ module.exports = (
helpers: true,
regenerator: true,
useESModules: supportsESM && presetEnvConfig.modules !== 'commonjs',
absoluteRuntime: dirname(
require.resolve('@babel/runtime/package.json')
),
absoluteRuntime: process.versions.pnp
? dirname(require.resolve('@babel/runtime/package.json'))
: undefined,
...options['transform-runtime'],
},
],
Expand Down
4 changes: 2 additions & 2 deletions test/unit/next-babel.unit.test.js
Expand Up @@ -64,8 +64,8 @@ describe('next/babel', () => {
expect(output).toMatch(`__jsx(${react}.Fragment`)
expect(output).toMatch(`__jsx("a",{href:"/"`)

expect(babel(`const a = ()=><a href="/">home</a>`)).toMatch(
`var _react=_interopRequireDefault(require("react"));var __jsx=_react["default"].createElement;var a=function a(){return __jsx("a",{href:"/"},"home");};`
expect(babel(`const a = ()=><a href="/">home</a>`)).toMatchInlineSnapshot(
`"\\"use strict\\";var _interopRequireDefault=require(\\"@babel/runtime/helpers/interopRequireDefault\\");var _react=_interopRequireDefault(require(\\"react\\"));var __jsx=_react[\\"default\\"].createElement;var a=function a(){return __jsx(\\"a\\",{href:\\"/\\"},\\"home\\");};"`
)
})

Expand Down

0 comments on commit 9dd5ff2

Please sign in to comment.