Skip to content

Commit

Permalink
Support Bun by adjusting how @babel/plugin-transform-react-jsx is i…
Browse files Browse the repository at this point in the history
…mported. (#8007)

* Support bun/other tooling that respects `__esModule`

* Add changeset file
  • Loading branch information
paperdave authored Aug 9, 2023
1 parent e65b5b5 commit 58b121d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/quick-actors-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/preact': patch
'astro': patch
---

Support Bun by adjusting how `@babel/plugin-transform-react-jsx` is imported.
7 changes: 3 additions & 4 deletions packages/astro/src/jsx/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
14 changes: 6 additions & 8 deletions packages/integrations/preact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })],
};
Expand All @@ -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' }),
Expand Down

0 comments on commit 58b121d

Please sign in to comment.