Skip to content

Commit 0e3af76

Browse files
committed
Make build config a series of build steps
1 parent 9bbde93 commit 0e3af76

14 files changed

+39
-40
lines changed

packages/app/src/cli/models/extensions/extension-instance.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {WebhookSubscriptionSpecIdentifier} from './specifications/app_config_web
1515
import {
1616
ExtensionBuildOptions,
1717
buildFunctionExtension,
18+
buildTaxCalculationExtension,
1819
buildThemeExtension,
1920
buildUIExtension,
2021
bundleFunctionExtension,
@@ -29,7 +30,7 @@ import {constantize, slugify} from '@shopify/cli-kit/common/string'
2930
import {hashString, nonRandomUUID} from '@shopify/cli-kit/node/crypto'
3031
import {partnersFqdn} from '@shopify/cli-kit/node/context/fqdn'
3132
import {joinPath, basename} from '@shopify/cli-kit/node/path'
32-
import {fileExists, touchFile, moveFile, writeFile, glob, copyFile} from '@shopify/cli-kit/node/fs'
33+
import {fileExists, moveFile, glob, copyFile} from '@shopify/cli-kit/node/fs'
3334
import {getPathValue} from '@shopify/cli-kit/common/object'
3435
import {outputDebug} from '@shopify/cli-kit/node/output'
3536

@@ -339,28 +340,21 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
339340
}
340341

341342
async build(options: ExtensionBuildOptions): Promise<void> {
342-
const mode = this.specification.buildConfig.mode
343-
344-
switch (mode) {
345-
case 'theme':
346-
return buildThemeExtension(this, options)
347-
case 'function':
348-
return buildFunctionExtension(this, options)
349-
case 'ui':
350-
return buildUIExtension(this, options)
351-
case 'tax_calculation':
352-
await touchFile(this.outputPath)
353-
await writeFile(this.outputPath, '(()=>{})();')
354-
break
355-
case 'copy_files':
356-
return copyFilesForExtension(
357-
this,
358-
options,
359-
this.specification.buildConfig.filePatterns,
360-
this.specification.buildConfig.ignoredFilePatterns,
361-
)
362-
case 'none':
363-
break
343+
const steps = this.specification.buildSteps
344+
345+
for (const step of steps) {
346+
switch (step.mode) {
347+
case 'theme':
348+
return buildThemeExtension(this, options)
349+
case 'function':
350+
return buildFunctionExtension(this, options)
351+
case 'ui':
352+
return buildUIExtension(this, options)
353+
case 'tax_calculation':
354+
return buildTaxCalculationExtension(this)
355+
case 'copy_files':
356+
return copyFilesForExtension(this, options, step.filePatterns, step.ignoredFilePatterns)
357+
}
364358
}
365359
}
366360

@@ -381,16 +375,16 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
381375

382376
this.outputPath = this.getOutputPathForDirectory(bundleDirectory, extensionUuid)
383377

384-
const buildMode = this.specification.buildConfig.mode
378+
const hasBuildSteps = this.specification.buildSteps.length > 0
385379

386380
if (this.isThemeExtension) {
387381
await bundleThemeExtension(this, options)
388-
} else if (buildMode !== 'none') {
382+
} else if (hasBuildSteps) {
389383
outputDebug(`Will copy pre-built file from ${defaultOutputPath} to ${this.outputPath}`)
390384
if (await fileExists(defaultOutputPath)) {
391385
await copyFile(defaultOutputPath, this.outputPath)
392386

393-
if (buildMode === 'function') {
387+
if (this.isFunctionExtension) {
394388
await bundleFunctionExtension(this.outputPath, this.outputPath)
395389
}
396390
}

packages/app/src/cli/models/extensions/specification.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface Asset {
4747
}
4848

4949
type BuildConfig =
50-
| {mode: 'ui' | 'theme' | 'function' | 'tax_calculation' | 'none'}
50+
| {mode: 'ui' | 'theme' | 'function' | 'tax_calculation'}
5151
| {mode: 'copy_files'; filePatterns: string[]; ignoredFilePatterns?: string[]}
5252
/**
5353
* Extension specification with all the needed properties and methods to load an extension.
@@ -62,7 +62,7 @@ export interface ExtensionSpecification<TConfiguration extends BaseConfigType =
6262
surface: string
6363
registrationLimit: number
6464
experience: ExtensionExperience
65-
buildConfig: BuildConfig
65+
buildSteps: BuildConfig[]
6666
dependency?: string
6767
graphQLType?: string
6868
getBundleExtensionStdinContent?: (config: TConfiguration) => {main: string; assets?: Asset[]}
@@ -190,7 +190,7 @@ export function createExtensionSpecification<TConfiguration extends BaseConfigTy
190190
experience: spec.experience ?? 'extension',
191191
uidStrategy: spec.uidStrategy ?? (spec.experience === 'configuration' ? 'single' : 'uuid'),
192192
getDevSessionUpdateMessages: spec.getDevSessionUpdateMessages,
193-
buildConfig: spec.buildConfig ?? {mode: 'none'},
193+
buildSteps: spec.buildSteps ?? [],
194194
}
195195
const merged = {...defaults, ...spec}
196196

packages/app/src/cli/models/extensions/specifications/checkout_post_purchase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const checkoutPostPurchaseSpec = createExtensionSpecification({
1414
partnersWebIdentifier: 'post_purchase',
1515
schema: CheckoutPostPurchaseSchema,
1616
appModuleFeatures: (_) => ['ui_preview', 'cart_url', 'esbuild', 'single_js_entry_path'],
17-
buildConfig: {mode: 'ui'},
17+
buildSteps: [{mode: 'ui'}],
1818
deployConfig: async (config, _) => {
1919
return {metafields: config.metafields ?? []}
2020
},

packages/app/src/cli/models/extensions/specifications/checkout_ui_extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const checkoutSpec = createExtensionSpecification({
2121
dependency,
2222
schema: CheckoutSchema,
2323
appModuleFeatures: (_) => ['ui_preview', 'cart_url', 'esbuild', 'single_js_entry_path', 'generates_source_maps'],
24-
buildConfig: {mode: 'ui'},
24+
buildSteps: [{mode: 'ui'}],
2525
deployConfig: async (config, directory) => {
2626
return {
2727
extension_points: config.extension_points,

packages/app/src/cli/models/extensions/specifications/flow_template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const flowTemplateSpec = createExtensionSpecification({
4949
identifier: 'flow_template',
5050
schema: FlowTemplateExtensionSchema,
5151
appModuleFeatures: (_) => ['ui_preview'],
52-
buildConfig: {mode: 'copy_files', filePatterns: ['*.flow', '*.json', '*.toml']},
52+
buildSteps: [{mode: 'copy_files', filePatterns: ['*.flow', '*.json', '*.toml']}],
5353
deployConfig: async (config, extensionPath) => {
5454
return {
5555
template_handle: config.handle,

packages/app/src/cli/models/extensions/specifications/function.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const functionSpec = createExtensionSpecification({
8181
],
8282
schema: FunctionExtensionSchema,
8383
appModuleFeatures: (_) => ['function'],
84-
buildConfig: {mode: 'function'},
84+
buildSteps: [{mode: 'function'}],
8585
deployConfig: async (config, directory, apiKey) => {
8686
let inputQuery: string | undefined
8787
const moduleId = randomUUID()

packages/app/src/cli/models/extensions/specifications/pos_ui_extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const posUISpec = createExtensionSpecification({
1111
dependency,
1212
schema: BaseSchema.extend({name: zod.string()}),
1313
appModuleFeatures: (_) => ['ui_preview', 'esbuild', 'single_js_entry_path'],
14-
buildConfig: {mode: 'ui'},
14+
buildSteps: [{mode: 'ui'}],
1515
deployConfig: async (config, directory) => {
1616
const result = await getDependencyVersion(dependency, directory)
1717
if (result === 'not_found') throw new BugError(`Dependency ${dependency} not found`)

packages/app/src/cli/models/extensions/specifications/product_subscription.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const productSubscriptionSpec = createExtensionSpecification({
1212
graphQLType: 'subscription_management',
1313
schema: BaseSchema,
1414
appModuleFeatures: (_) => ['ui_preview', 'esbuild', 'single_js_entry_path'],
15-
buildConfig: {mode: 'ui'},
15+
buildSteps: [{mode: 'ui'}],
1616
deployConfig: async (_, directory) => {
1717
const result = await getDependencyVersion(dependency, directory)
1818
if (result === 'not_found') throw new BugError(`Dependency ${dependency} not found`)

packages/app/src/cli/models/extensions/specifications/tax_calculation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const spec = createExtensionSpecification({
2323
identifier: 'tax_calculation',
2424
schema: TaxCalculationsSchema,
2525
appModuleFeatures: (_) => [],
26-
buildConfig: {mode: 'tax_calculation'},
26+
buildSteps: [{mode: 'tax_calculation'}],
2727
deployConfig: async (config, _) => {
2828
return {
2929
production_api_base_url: config.production_api_base_url,

packages/app/src/cli/models/extensions/specifications/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const themeSpec = createExtensionSpecification({
1212
schema: BaseSchema,
1313
partnersWebIdentifier: 'theme_app_extension',
1414
graphQLType: 'theme_app_extension',
15-
buildConfig: {mode: 'theme'},
15+
buildSteps: [{mode: 'theme'}],
1616
appModuleFeatures: (_) => {
1717
return ['theme']
1818
},

0 commit comments

Comments
 (0)