Skip to content

Commit

Permalink
add jsx-transform support to extensions build
Browse files Browse the repository at this point in the history
  • Loading branch information
faouzioudouh committed Oct 5, 2022
1 parent 5bee945 commit b02e2ff
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-buttons-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

add jsx transform support to extensions build
1 change: 1 addition & 0 deletions packages/app/src/cli/services/extensions/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('buildExtension', () => {
expect(options.legalComments).toEqual('none')
expect(options.minify).toBeTruthy()
expect(options.target).toEqual('es6')
expect(options.jsx).toEqual('automatic')
expect(options.resolveExtensions).toEqual(['.tsx', '.ts', '.js', '.json', '.esnext', '.mjs', '.ejs'])
expect(options.define).toEqual({
'process.env.FOO': JSON.stringify('BAR'),
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/cli/services/extensions/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function getESBuildOptions(options: BundleOptions): Parameters<typeof esBuild>[0
sourceRoot: path.dirname(options.sourceFilePath),
bundle: true,
define,
jsx: 'automatic',
loader: {
'.esnext': 'ts',
'.js': 'jsx',
Expand Down
9 changes: 9 additions & 0 deletions packages/app/src/cli/services/generate/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ async function uiExtensionInit({

if (extensionFlavor) {
await changeIndexFileExtension(extensionDirectory, extensionFlavor)
await removeUnwantedTemplateFilesPerFlavor(extensionDirectory, extensionFlavor)
}

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

async function removeUnwantedTemplateFilesPerFlavor(extensionDirectory: string, extensionFlavor: ExtensionFlavor) {
// tsconfig.json file is only needed in extension folder to inform the IDE
// About the `react-jsx` tsconfig option, so IDE don't complain about missing react import
if (extensionFlavor !== 'typescript-react') {
await file.remove(path.join(extensionDirectory, 'tsconfig.json'))
}
}

async function functionExtensionInit(options: FunctionExtensionInitOptions) {
const url = options.cloneUrl || blocks.functions.defaultUrl
await file.inTemporaryDirectory(async (tmpDir) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For creating an extension:

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

## Getting Started
Initially, your extension will have the following files:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{%- if flavor == "react" -%}
import React from 'react';
import {
useExtensionApi,
render,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// This tsconfig.json file is only needed to inform the IDE
// About the `react-jsx` tsconfig option, so IDE don't complain about missing react import
// Changing options here won't affect the build of your extension
"compilerOptions": {
"jsx": "react-jsx"
},
"include": ["./src"]
}

0 comments on commit b02e2ff

Please sign in to comment.