Skip to content

Commit 08ba114

Browse files
authored
Merge pull request #6305 from Shopify/08-22-move_buildmode_to_specification
Move buildMode to specification
2 parents e1656cf + 9cc81cf commit 08ba114

File tree

15 files changed

+19
-28
lines changed

15 files changed

+19
-28
lines changed

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ export const CONFIG_EXTENSION_IDS: string[] = [
4545
WebhooksSpecIdentifier,
4646
]
4747

48-
type BuildMode = 'theme' | 'function' | 'ui' | 'flow' | 'tax_calculation' | 'none'
49-
5048
/**
5149
* Class that represents an instance of a local extension
5250
* Before creating this class we've validated that:
@@ -342,7 +340,7 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
342340
}
343341

344342
async build(options: ExtensionBuildOptions): Promise<void> {
345-
const mode = this.buildMode(options.environment)
343+
const mode = this.specification.buildConfig.mode
346344

347345
switch (mode) {
348346
case 'theme':
@@ -379,7 +377,7 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
379377

380378
this.outputPath = this.getOutputPathForDirectory(bundleDirectory, extensionUuid)
381379

382-
const buildMode = this.buildMode(options.environment)
380+
const buildMode = this.specification.buildConfig.mode
383381

384382
if (this.isThemeExtension) {
385383
await bundleThemeExtension(this, options)
@@ -459,25 +457,6 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
459457
await this.specification.contributeToSharedTypeFile?.(this, typeDefinitionsByFile)
460458
}
461459

462-
buildMode(environment: 'production' | 'development'): BuildMode {
463-
if (this.isThemeExtension) {
464-
return 'theme'
465-
} else if (this.isFunctionExtension) {
466-
return 'function'
467-
} else if (this.features.includes('esbuild')) {
468-
return 'ui'
469-
} else if (this.specification.identifier === 'flow_template' && environment === 'production') {
470-
return 'flow'
471-
}
472-
473-
// Workaround for tax_calculations because they remote spec NEEDS a valid js file to be included.
474-
if (this.type === 'tax_calculation') {
475-
return 'tax_calculation'
476-
}
477-
478-
return 'none'
479-
}
480-
481460
private buildHandle() {
482461
switch (this.specification.uidStrategy) {
483462
case 'single':

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export interface Asset {
4646
content: string
4747
}
4848

49+
interface BuildConfig {
50+
mode: 'ui' | 'theme' | 'flow' | 'function' | 'tax_calculation' | 'none'
51+
}
4952
/**
5053
* Extension specification with all the needed properties and methods to load an extension.
5154
*/
@@ -59,6 +62,7 @@ export interface ExtensionSpecification<TConfiguration extends BaseConfigType =
5962
surface: string
6063
registrationLimit: number
6164
experience: ExtensionExperience
65+
buildConfig: BuildConfig
6266
dependency?: string
6367
graphQLType?: string
6468
getBundleExtensionStdinContent?: (config: TConfiguration) => {main: string; assets?: Asset[]}
@@ -186,6 +190,7 @@ export function createExtensionSpecification<TConfiguration extends BaseConfigTy
186190
experience: spec.experience ?? 'extension',
187191
uidStrategy: spec.uidStrategy ?? (spec.experience === 'configuration' ? 'single' : 'uuid'),
188192
getDevSessionUpdateMessages: spec.getDevSessionUpdateMessages,
193+
buildConfig: spec.buildConfig ?? {mode: 'none'},
189194
}
190195
const merged = {...defaults, ...spec}
191196

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +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'},
1718
deployConfig: async (config, _) => {
1819
return {metafields: config.metafields ?? []}
1920
},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +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'},
2425
deployConfig: async (config, directory) => {
2526
return {
2627
extension_points: config.extension_points,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const flowTemplateSpec = createExtensionSpecification({
4949
identifier: 'flow_template',
5050
schema: FlowTemplateExtensionSchema,
5151
appModuleFeatures: (_) => ['ui_preview'],
52+
buildConfig: {mode: 'flow'},
5253
deployConfig: async (config, extensionPath) => {
5354
return {
5455
template_handle: config.handle,

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

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +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'},
1415
deployConfig: async (config, directory) => {
1516
const result = await getDependencyVersion(dependency, directory)
1617
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +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'},
1516
deployConfig: async (_, directory) => {
1617
const result = await getDependencyVersion(dependency, directory)
1718
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const spec = createExtensionSpecification({
2323
identifier: 'tax_calculation',
2424
schema: TaxCalculationsSchema,
2525
appModuleFeatures: (_) => [],
26+
buildConfig: {mode: 'tax_calculation'},
2627
deployConfig: async (config, _) => {
2728
return {
2829
production_api_base_url: config.production_api_base_url,

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

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

0 commit comments

Comments
 (0)