Skip to content

Commit a65c60d

Browse files
committed
Fix build step for ui extension to build to local directory first before copying over to the bundle
Remove copy_static_assets client step completely. It was doing nothing for specifications that were not ui_extension. ui_extension now has its own steps for including static assets
1 parent 8bfa970 commit a65c60d

15 files changed

Lines changed: 28 additions & 110 deletions

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
testSingleWebhookSubscriptionExtension,
1515
placeholderAppConfiguration,
1616
} from '../app/app.test-data.js'
17-
import {ExtensionBuildOptions, buildUIExtension} from '../../services/build/extension.js'
17+
import {ExtensionBuildOptions} from '../../services/build/extension.js'
1818
import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
1919
import {joinPath} from '@shopify/cli-kit/node/path'
2020
import {describe, expect, test, vi} from 'vitest'
@@ -172,33 +172,6 @@ describe('build', async () => {
172172
})
173173
})
174174

175-
test('calls copyStaticAssets after buildUIExtension when building UI extensions', async () => {
176-
await inTemporaryDirectory(async (tmpDir) => {
177-
// Given
178-
const extensionInstance = await testUIExtension({
179-
type: 'ui_extension',
180-
directory: tmpDir,
181-
})
182-
183-
const copyStaticAssetsSpy = vi.spyOn(extensionInstance, 'copyStaticAssets').mockResolvedValue()
184-
vi.mocked(buildUIExtension).mockResolvedValue()
185-
186-
const options: ExtensionBuildOptions = {
187-
stdout: new Writable({write: vi.fn()}),
188-
stderr: new Writable({write: vi.fn()}),
189-
app: testApp(),
190-
environment: 'production',
191-
}
192-
193-
// When
194-
await extensionInstance.build(options)
195-
196-
// Then
197-
expect(buildUIExtension).toHaveBeenCalledWith(extensionInstance, options)
198-
expect(copyStaticAssetsSpy).toHaveBeenCalledOnce()
199-
})
200-
})
201-
202175
test('does not copy shopify.extension.toml file when bundling theme extensions', async () => {
203176
await inTemporaryDirectory(async (tmpDir) => {
204177
// Given

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -459,16 +459,6 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
459459
return [...new Set(watchedFiles.map((file) => normalizePath(file)))]
460460
}
461461

462-
/**
463-
* Copy static assets from the extension directory to the output path
464-
* Used by both dev and deploy builds
465-
*/
466-
async copyStaticAssets(outputPath?: string) {
467-
if (this.specification.copyStaticAssets) {
468-
return this.specification.copyStaticAssets(this.configuration, this.directory, outputPath ?? this.outputPath)
469-
}
470-
}
471-
472462
/**
473463
* Rescans imports for this extension and updates the cached import paths
474464
* Returns true if the imports changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ const testClientSteps: ClientSteps = [
4040
lifecycle: 'deploy',
4141
steps: [
4242
{
43-
id: 'copy_static',
44-
name: 'Copy static assets',
45-
type: 'copy_static_assets',
43+
id: 'bundle-ui',
44+
name: 'Bundle UI Extension',
45+
type: 'bundle_ui',
4646
},
4747
],
4848
},

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,6 @@ export interface ExtensionSpecification<TConfiguration extends BaseConfigType =
133133
typeDefinitionsByFile: Map<string, Set<string>>,
134134
) => Promise<void>
135135

136-
/**
137-
* Copy static assets from the extension directory to the output path
138-
*/
139-
copyStaticAssets?: (configuration: TConfiguration, directory: string, outputPath: string) => Promise<void>
140-
141136
/**
142137
* Custom watch configuration for dev sessions.
143138
* Return a DevSessionWatchConfig with paths to watch and optionally paths to ignore,

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ const checkoutPostPurchaseSpec = createExtensionSpecification({
2222
clientSteps: [
2323
{
2424
lifecycle: 'deploy',
25-
steps: [
26-
{id: 'bundle-ui', name: 'Bundle UI Extension', type: 'bundle_ui', config: {}},
27-
{id: 'copy-static-assets', name: 'Copy Static Assets', type: 'copy_static_assets', config: {}},
28-
],
25+
steps: [{id: 'bundle-ui', name: 'Bundle UI Extension', type: 'bundle_ui', config: {}}],
2926
},
3027
],
3128
deployConfig: async (config, _) => {

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ const checkoutSpec = createExtensionSpecification({
2828
clientSteps: [
2929
{
3030
lifecycle: 'deploy',
31-
steps: [
32-
{id: 'bundle-ui', name: 'Bundle UI Extension', type: 'bundle_ui', config: {}},
33-
{id: 'copy-static-assets', name: 'Copy Static Assets', type: 'copy_static_assets', config: {}},
34-
],
31+
steps: [{id: 'bundle-ui', name: 'Bundle UI Extension', type: 'bundle_ui', config: {}}],
3532
},
3633
],
3734
deployConfig: async (config, directory) => {

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ const posUISpec = createExtensionSpecification({
2020
clientSteps: [
2121
{
2222
lifecycle: 'deploy',
23-
steps: [
24-
{id: 'bundle-ui', name: 'Bundle UI Extension', type: 'bundle_ui', config: {}},
25-
{id: 'copy-static-assets', name: 'Copy Static Assets', type: 'copy_static_assets', config: {}},
26-
],
23+
steps: [{id: 'bundle-ui', name: 'Bundle UI Extension', type: 'bundle_ui', config: {}}],
2724
},
2825
],
2926
deployConfig: async (config, directory) => {

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ const productSubscriptionSpec = createExtensionSpecification({
2121
clientSteps: [
2222
{
2323
lifecycle: 'deploy',
24-
steps: [
25-
{id: 'bundle-ui', name: 'Bundle UI Extension', type: 'bundle_ui', config: {}},
26-
{id: 'copy-static-assets', name: 'Copy Static Assets', type: 'copy_static_assets', config: {}},
27-
],
24+
steps: [{id: 'bundle-ui', name: 'Bundle UI Extension', type: 'bundle_ui', config: {}}],
2825
},
2926
],
3027
deployConfig: async (_, directory) => {

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {getExtensionPointTargetSurface} from '../../../services/dev/extension/ut
1313
import {ExtensionInstance} from '../extension-instance.js'
1414
import {formatContent} from '../../../utilities/file-formatter.js'
1515
import {err, ok, Result} from '@shopify/cli-kit/node/result'
16-
import {copyFile, fileExists, readFile} from '@shopify/cli-kit/node/fs'
17-
import {joinPath, dirname} from '@shopify/cli-kit/node/path'
16+
import {fileExists, readFile} from '@shopify/cli-kit/node/fs'
17+
import {joinPath} from '@shopify/cli-kit/node/path'
1818
import {outputContent, outputToken, outputWarn} from '@shopify/cli-kit/node/output'
1919
import {zod} from '@shopify/cli-kit/node/schema'
2020

@@ -174,26 +174,6 @@ const uiExtensionSpec = createExtensionSpecification({
174174
...(assetsArray.length ? {assets: assetsArray} : {}),
175175
}
176176
},
177-
copyStaticAssets: async (config, directory, outputPath) => {
178-
if (!isRemoteDomExtension(config)) return
179-
180-
await Promise.all(
181-
config.extension_points.flatMap((extensionPoint) => {
182-
if (!('build_manifest' in extensionPoint)) return []
183-
184-
return Object.entries(extensionPoint.build_manifest.assets).map(([_, asset]) => {
185-
if (asset.static && asset.module) {
186-
const sourceFile = joinPath(directory, asset.module)
187-
const outputFilePath = joinPath(dirname(outputPath), asset.filepath)
188-
return copyFile(sourceFile, outputFilePath).catch((error) => {
189-
throw new Error(`Failed to copy static asset ${asset.module} to ${outputFilePath}: ${error.message}`)
190-
})
191-
}
192-
return Promise.resolve()
193-
})
194-
}),
195-
)
196-
},
197177
hasExtensionPointTarget: (config, requestedTarget) => {
198178
return (
199179
config.extension_points?.find((extensionPoint) => {

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ const webPixelSpec = createExtensionSpecification({
3838
clientSteps: [
3939
{
4040
lifecycle: 'deploy',
41-
steps: [
42-
{id: 'bundle-ui', name: 'Bundle UI Extension', type: 'bundle_ui', config: {}},
43-
{id: 'copy-static-assets', name: 'Copy Static Assets', type: 'copy_static_assets', config: {}},
44-
],
41+
steps: [{id: 'bundle-ui', name: 'Bundle UI Extension', type: 'bundle_ui', config: {}}],
4542
},
4643
],
4744
deployConfig: async (config, _) => {

0 commit comments

Comments
 (0)