Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading