Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ vi.mock('@shopify/cli-kit/node/fs')

describe('hosted_app_home', () => {
describe('transform', () => {
test('should return the transformed object with static_root', () => {
test('should return the transformed object with static_root (local admin subsection to flat remote)', () => {
const object = {
static_root: 'public',
admin: {static_root: 'public'},
}
const appConfigSpec = spec

Expand All @@ -20,7 +20,7 @@ describe('hosted_app_home', () => {
})
})

test('should return empty object when static_root is not provided', () => {
test('should return empty object when admin.static_root is not provided', () => {
const object = {}
const appConfigSpec = spec

Expand All @@ -31,7 +31,7 @@ describe('hosted_app_home', () => {
})

describe('reverseTransform', () => {
test('should return the reversed transformed object with static_root', () => {
test('should return the reversed transformed object (flat remote to local admin subsection)', () => {
const object = {
static_root: 'public',
}
Expand All @@ -40,7 +40,7 @@ describe('hosted_app_home', () => {
const result = appConfigSpec.transformRemoteToLocal!(object)

expect(result).toMatchObject({
static_root: 'public',
admin: {static_root: 'public'},
})
})

Expand All @@ -57,7 +57,7 @@ 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 config = {admin: {static_root: 'public'}}
const directory = '/app/root'
const outputPath = '/output/dist/bundle.js'

Expand All @@ -66,7 +66,7 @@ describe('hosted_app_home', () => {
expect(copyDirectoryContents).toHaveBeenCalledWith('/app/root/public', '/output/dist')
})

test('should not copy assets when static_root is not provided', async () => {
test('should not copy assets when admin.static_root is not provided', async () => {
const config = {}
const directory = '/app/root'
const outputPath = '/output/dist/bundle.js'
Expand All @@ -78,7 +78,7 @@ describe('hosted_app_home', () => {

test('should throw error when copy fails', async () => {
vi.mocked(copyDirectoryContents).mockRejectedValue(new Error('Permission denied'))
const config = {static_root: 'public'}
const config = {admin: {static_root: 'public'}}
const directory = '/app/root'
const outputPath = '/output/dist/bundle.js'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import {dirname, joinPath} from '@shopify/cli-kit/node/path'
import {zod} from '@shopify/cli-kit/node/schema'

const HostedAppHomeSchema = BaseSchemaWithoutHandle.extend({
static_root: zod.string().optional(),
admin: zod
.object({
static_root: zod.string().optional(),
})
.optional(),
})

const HostedAppHomeTransformConfig: TransformationConfig = {
static_root: 'static_root',
static_root: 'admin.static_root',
}

export const HostedAppHomeSpecIdentifier = 'hosted_app_home'
Expand All @@ -20,8 +24,9 @@ const hostedAppHomeSpec = createConfigExtensionSpecification({
schema: HostedAppHomeSchema,
transformConfig: HostedAppHomeTransformConfig,
copyStaticAssets: async (config, directory, outputPath) => {
if (!config.static_root) return
const sourceDir = joinPath(directory, config.static_root)
const staticRoot = config.admin?.static_root
if (!staticRoot) return
const sourceDir = joinPath(directory, staticRoot)
const outputDir = dirname(outputPath)

return copyDirectoryContents(sourceDir, outputDir).catch((error) => {
Expand Down
Loading