Unverified Commit 9dd5ff2b authored by Guy Bedford's avatar Guy Bedford Committed by GitHub

fix: Revert #18921 and inline absolute babel runtime only for YarnPnp (#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.
parent 899a29ca
import { PluginItem } from 'next/dist/compiled/babel/core' import { PluginItem } from 'next/dist/compiled/babel/core'
import { dirname } from 'path' import { dirname } from 'path'
const env = process.env.NODE_ENV const env = process.env.NODE_ENV
const isProduction = env === 'production' const isProduction = env === 'production'
const isDevelopment = env === 'development' const isDevelopment = env === 'development'
...@@ -170,9 +169,9 @@ module.exports = ( ...@@ -170,9 +169,9 @@ module.exports = (
helpers: true, helpers: true,
regenerator: true, regenerator: true,
useESModules: supportsESM && presetEnvConfig.modules !== 'commonjs', useESModules: supportsESM && presetEnvConfig.modules !== 'commonjs',
absoluteRuntime: dirname( absoluteRuntime: process.versions.pnp
require.resolve('@babel/runtime/package.json') ? dirname(require.resolve('@babel/runtime/package.json'))
), : undefined,
...options['transform-runtime'], ...options['transform-runtime'],
}, },
], ],
......
...@@ -64,8 +64,8 @@ describe('next/babel', () => { ...@@ -64,8 +64,8 @@ describe('next/babel', () => {
expect(output).toMatch(`__jsx(${react}.Fragment`) expect(output).toMatch(`__jsx(${react}.Fragment`)
expect(output).toMatch(`__jsx("a",{href:"/"`) expect(output).toMatch(`__jsx("a",{href:"/"`)
expect(babel(`const a = ()=><a href="/">home</a>`)).toMatch( expect(babel(`const a = ()=><a href="/">home</a>`)).toMatchInlineSnapshot(
`var _react=_interopRequireDefault(require("react"));var __jsx=_react["default"].createElement;var a=function a(){return __jsx("a",{href:"/"},"home");};` `"\\"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\\");};"`
) )
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment