From 58b121d42a9f58a5a992f0c378b036f37e9715fc Mon Sep 17 00:00:00 2001 From: dave caruso Date: Wed, 9 Aug 2023 12:11:41 -0700 Subject: [PATCH] Support Bun by adjusting how `@babel/plugin-transform-react-jsx` is imported. (#8007) * Support bun/other tooling that respects `__esModule` * Add changeset file --- .changeset/quick-actors-sing.md | 6 ++++++ packages/astro/src/jsx/renderer.ts | 7 +++---- packages/integrations/preact/src/index.ts | 14 ++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 .changeset/quick-actors-sing.md diff --git a/.changeset/quick-actors-sing.md b/.changeset/quick-actors-sing.md new file mode 100644 index 000000000000..02e804799d6a --- /dev/null +++ b/.changeset/quick-actors-sing.md @@ -0,0 +1,6 @@ +--- +'@astrojs/preact': patch +'astro': patch +--- + +Support Bun by adjusting how `@babel/plugin-transform-react-jsx` is imported. diff --git a/packages/astro/src/jsx/renderer.ts b/packages/astro/src/jsx/renderer.ts index 78ac1a0b2e3b..39d7f5adb71b 100644 --- a/packages/astro/src/jsx/renderer.ts +++ b/packages/astro/src/jsx/renderer.ts @@ -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: [ diff --git a/packages/integrations/preact/src/index.ts b/packages/integrations/preact/src/index.ts index 4f4b0ee7924e..98a2dd20564b 100644 --- a/packages/integrations/preact/src/index.ts +++ b/packages/integrations/preact/src/index.ts @@ -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' }),