Skip to content

Commit 985fd5f

Browse files
authored
Merge pull request #577 from Shopify/add-jsx-transform-support-to-extensions-build
Add jsx-transform support to extensions build
2 parents 46408ab + b02e2ff commit 985fd5f

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
@@ -132,6 +132,7 @@ async function uiExtensionInit({
132132

133133
if (extensionFlavor) {
134134
await changeIndexFileExtension(extensionDirectory, extensionFlavor)
135+
await removeUnwantedTemplateFilesPerFlavor(extensionDirectory, extensionFlavor)
135136
}
136137

137138
task.title = `${getExtensionOutputConfig(extensionType).humanKey} extension generated`
@@ -185,6 +186,14 @@ async function changeIndexFileExtension(extensionDirectory: string, extensionFla
185186
}
186187
}
187188

189+
async function removeUnwantedTemplateFilesPerFlavor(extensionDirectory: string, extensionFlavor: ExtensionFlavor) {
190+
// tsconfig.json file is only needed in extension folder to inform the IDE
191+
// About the `react-jsx` tsconfig option, so IDE don't complain about missing react import
192+
if (extensionFlavor !== 'typescript-react') {
193+
await file.remove(path.join(extensionDirectory, 'tsconfig.json'))
194+
}
195+
}
196+
188197
async function functionExtensionInit(options: FunctionExtensionInitOptions) {
189198
const url = options.cloneUrl || blocks.functions.defaultUrl
190199
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)