diff --git a/packages/app/src/cli/models/extensions/specification.ts b/packages/app/src/cli/models/extensions/specification.ts index ab5ad22008..26a5b4b9bc 100644 --- a/packages/app/src/cli/models/extensions/specification.ts +++ b/packages/app/src/cli/models/extensions/specification.ts @@ -55,9 +55,10 @@ export interface BuildAsset { static?: boolean } -type BuildConfig = - | {mode: 'none'} - | {mode: 'ui' | 'theme' | 'function' | 'tax_calculation' | 'copy_files'; steps: ReadonlyArray} +interface BuildConfig { + mode: 'ui' | 'theme' | 'function' | 'tax_calculation' | 'copy_files' | 'none' + steps: ReadonlyArray +} /** * Extension specification with all the needed properties and methods to load an extension. */ @@ -204,7 +205,7 @@ export function createExtensionSpecification, appModuleFeatures: spec.appModuleFeatures, - buildConfig: spec.buildConfig ?? {mode: 'none'}, + buildConfig: spec.buildConfig ?? {mode: 'none', steps: []}, deployConfig: async (config, directory) => { let parsedConfig = configWithoutFirstClassFields(config) if (spec.appModuleFeatures().includes('localization')) { diff --git a/packages/app/src/cli/models/extensions/specifications/app_config_hosted_app_home.test.ts b/packages/app/src/cli/models/extensions/specifications/app_config_hosted_app_home.test.ts index 9824718961..0f9ac44283 100644 --- a/packages/app/src/cli/models/extensions/specifications/app_config_hosted_app_home.test.ts +++ b/packages/app/src/cli/models/extensions/specifications/app_config_hosted_app_home.test.ts @@ -1,9 +1,6 @@ import spec from './app_config_hosted_app_home.js' import {placeholderAppConfiguration} from '../../app/app.test-data.js' -import {copyDirectoryContents} from '@shopify/cli-kit/node/fs' -import {describe, expect, test, vi} from 'vitest' - -vi.mock('@shopify/cli-kit/node/fs') +import {describe, expect, test} from 'vitest' describe('hosted_app_home', () => { describe('transform', () => { @@ -54,43 +51,42 @@ describe('hosted_app_home', () => { }) }) - describe('copyStaticAssets', () => { - test('should copy static assets from source to output directory', async () => { - vi.mocked(copyDirectoryContents).mockResolvedValue(undefined) - const config = {static_root: 'public'} - const directory = '/app/root' - const outputPath = '/output/dist/bundle.js' - - await spec.copyStaticAssets!(config, directory, outputPath) - - expect(copyDirectoryContents).toHaveBeenCalledWith('/app/root/public', '/output/dist') + describe('buildConfig', () => { + test('should use copy_files mode', () => { + expect(spec.buildConfig.mode).toBe('copy_files') }) - test('should not copy assets when static_root is not provided', async () => { - const config = {} - const directory = '/app/root' - const outputPath = '/output/dist/bundle.js' - - await spec.copyStaticAssets!(config, directory, outputPath) + test('should have copy-static-assets step with tomlKey entry', () => { + if (spec.buildConfig.mode === 'none') { + throw new Error('Expected build_steps mode') + } - expect(copyDirectoryContents).not.toHaveBeenCalled() + expect(spec.buildConfig.steps).toHaveLength(1) + expect(spec.buildConfig.steps[0]).toMatchObject({ + id: 'copy-static-assets', + displayName: 'Copy Static Assets', + type: 'copy_files', + config: { + strategy: 'files', + definition: {files: [{tomlKey: 'static_root'}]}, + }, + }) }) - test('should throw error when copy fails', async () => { - vi.mocked(copyDirectoryContents).mockRejectedValue(new Error('Permission denied')) - const config = {static_root: 'public'} - const directory = '/app/root' - const outputPath = '/output/dist/bundle.js' + test('config should be serializable to JSON', () => { + if (spec.buildConfig.mode === 'none') { + throw new Error('Expected build_steps mode') + } - await expect(spec.copyStaticAssets!(config, directory, outputPath)).rejects.toThrow( - 'Failed to copy static assets from /app/root/public to /output/dist: Permission denied', - ) - }) - }) + const serialized = JSON.stringify(spec.buildConfig) + expect(serialized).toBeDefined() - describe('buildConfig', () => { - test('should have hosted_app_home build mode', () => { - expect(spec.buildConfig).toEqual({mode: 'none'}) + const deserialized = JSON.parse(serialized) + expect(deserialized.steps).toHaveLength(1) + expect(deserialized.steps[0].config).toEqual({ + strategy: 'files', + definition: {files: [{tomlKey: 'static_root'}]}, + }) }) }) diff --git a/packages/app/src/cli/models/extensions/specifications/app_config_hosted_app_home.ts b/packages/app/src/cli/models/extensions/specifications/app_config_hosted_app_home.ts index b11578d83e..873d18d64b 100644 --- a/packages/app/src/cli/models/extensions/specifications/app_config_hosted_app_home.ts +++ b/packages/app/src/cli/models/extensions/specifications/app_config_hosted_app_home.ts @@ -1,7 +1,5 @@ import {BaseSchemaWithoutHandle} from '../schemas.js' import {TransformationConfig, createConfigExtensionSpecification} from '../specification.js' -import {copyDirectoryContents} from '@shopify/cli-kit/node/fs' -import {dirname, joinPath} from '@shopify/cli-kit/node/path' import {zod} from '@shopify/cli-kit/node/schema' const HostedAppHomeSchema = BaseSchemaWithoutHandle.extend({ @@ -16,18 +14,24 @@ export const HostedAppHomeSpecIdentifier = 'hosted_app_home' const hostedAppHomeSpec = createConfigExtensionSpecification({ identifier: HostedAppHomeSpecIdentifier, - buildConfig: {mode: 'none'} as const, + buildConfig: { + mode: 'copy_files', + steps: [ + { + id: 'copy-static-assets', + displayName: 'Copy Static Assets', + type: 'copy_files', + config: { + strategy: 'files', + definition: { + files: [{tomlKey: 'static_root'}], + }, + }, + }, + ], + }, schema: HostedAppHomeSchema, transformConfig: HostedAppHomeTransformConfig, - copyStaticAssets: async (config, directory, outputPath) => { - if (!config.static_root) return - const sourceDir = joinPath(directory, config.static_root) - const outputDir = dirname(outputPath) - - return copyDirectoryContents(sourceDir, outputDir).catch((error) => { - throw new Error(`Failed to copy static assets from ${sourceDir} to ${outputDir}: ${error.message}`) - }) - }, }) export default hostedAppHomeSpec