Support Bun by adjusting how @babel/plugin-transform-react-jsx is imported. (#8007)

* Support bun/other tooling that respects `__esModule`

* Add changeset file
This commit is contained in:
dave caruso 2023-08-09 12:11:41 -07:00 committed by GitHub
parent e65b5b5495
commit 58b121d42a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 12 deletions

View file

@ -0,0 +1,6 @@
---
'@astrojs/preact': patch
'astro': patch
---
Support Bun by adjusting how `@babel/plugin-transform-react-jsx` is imported.

View file

@ -3,10 +3,9 @@ const renderer = {
serverEntrypoint: 'astro/jsx/server.js',
jsxImportSource: 'astro',
jsxTransformOptions: async () => {
const {
default: { default: jsx },
// @ts-expect-error
} = await import('@babel/plugin-transform-react-jsx');
// @ts-expect-error types not found
const plugin = await import('@babel/plugin-transform-react-jsx');
const jsx = plugin.default?.default ?? plugin.default;
const { default: astroJSX } = await import('./babel.js');
return {
plugins: [

View file

@ -7,10 +7,9 @@ function getRenderer(development: boolean): AstroRenderer {
serverEntrypoint: '@astrojs/preact/server.js',
jsxImportSource: 'preact',
jsxTransformOptions: async () => {
const {
default: { default: jsx },
// @ts-expect-error types not found
} = await import('@babel/plugin-transform-react-jsx');
// @ts-expect-error types not found
const plugin = await import('@babel/plugin-transform-react-jsx');
const jsx = plugin.default?.default ?? plugin.default;
return {
plugins: [jsx({}, { runtime: 'automatic', importSource: 'preact' })],
};
@ -25,10 +24,9 @@ function getCompatRenderer(development: boolean): AstroRenderer {
serverEntrypoint: '@astrojs/preact/server.js',
jsxImportSource: 'react',
jsxTransformOptions: async () => {
const {
default: { default: jsx },
// @ts-expect-error types not found
} = await import('@babel/plugin-transform-react-jsx');
// @ts-expect-error types not found
const plugin = await import('@babel/plugin-transform-react-jsx');
const jsx = plugin.default?.default ?? plugin.default;
return {
plugins: [
jsx({}, { runtime: 'automatic', importSource: 'preact/compat' }),