Skip to content

Commit b02e2ff

Browse files
committed
add jsx-transform support to extensions build
1 parent 5bee945 commit b02e2ff

File tree

7 files changed

+26
-2
lines changed

7 files changed

+26
-2
lines changed

.changeset/light-buttons-do.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/app': patch
3+
---
4+
5+
add jsx transform support to extensions build

packages/app/src/cli/services/extensions/bundle.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('buildExtension', () => {
6565
expect(options.legalComments).toEqual('none')
6666
expect(options.minify).toBeTruthy()
6767
expect(options.target).toEqual('es6')
68+
expect(options.jsx).toEqual('automatic')
6869
expect(options.resolveExtensions).toEqual(['.tsx', '.ts', '.js', '.json', '.esnext', '.mjs', '.ejs'])
6970
expect(options.define).toEqual({
7071
'process.env.FOO': JSON.stringify('BAR'),

packages/app/src/cli/services/extensions/bundle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ function getESBuildOptions(options: BundleOptions): Parameters<typeof esBuild>[0
8383
sourceRoot: path.dirname(options.sourceFilePath),
8484
bundle: true,
8585
define,
86+
jsx: 'automatic',
8687
loader: {
8788
'.esnext': 'ts',
8889
'.js': 'jsx',

packages/app/src/cli/services/generate/extension.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ async function uiExtensionInit({
127127

128128
if (extensionFlavor) {
129129
await changeIndexFileExtension(extensionDirectory, extensionFlavor)
130+
await removeUnwantedTemplateFilesPerFlavor(extensionDirectory, extensionFlavor)
130131
}
131132

132133
task.title = `${getExtensionOutputConfig(extensionType).humanKey} extension generated`
@@ -180,6 +181,14 @@ async function changeIndexFileExtension(extensionDirectory: string, extensionFla
180181
}
181182
}
182183

184+
async function removeUnwantedTemplateFilesPerFlavor(extensionDirectory: string, extensionFlavor: ExtensionFlavor) {
185+
// tsconfig.json file is only needed in extension folder to inform the IDE
186+
// About the `react-jsx` tsconfig option, so IDE don't complain about missing react import
187+
if (extensionFlavor !== 'typescript-react') {
188+
await file.remove(path.join(extensionDirectory, 'tsconfig.json'))
189+
}
190+
}
191+
183192
async function functionExtensionInit(options: FunctionExtensionInitOptions) {
184193
const url = options.cloneUrl || blocks.functions.defaultUrl
185194
await file.inTemporaryDirectory(async (tmpDir) => {

packages/app/templates/ui-extensions/projects/checkout_ui/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ For creating an extension:
1616

1717
To add specific features to an extension
1818
* [Adding field validation](https://shopify.dev/apps/checkout/validation)
19-
* [Localizing an exstension](https://shopify.dev/apps/checkout/localize-ui-extensions)
19+
* [Localizing an extension](https://shopify.dev/apps/checkout/localize-ui-extensions)
2020

2121
## Getting Started
2222
Initially, your extension will have the following files:

packages/app/templates/ui-extensions/projects/checkout_ui/src/index.liquid

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{%- if flavor == "react" -%}
2-
import React from 'react';
32
import {
43
useExtensionApi,
54
render,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
// This tsconfig.json file is only needed to inform the IDE
3+
// About the `react-jsx` tsconfig option, so IDE don't complain about missing react import
4+
// Changing options here won't affect the build of your extension
5+
"compilerOptions": {
6+
"jsx": "react-jsx"
7+
},
8+
"include": ["./src"]
9+
}

0 commit comments

Comments
 (0)