@@ -2,7 +2,7 @@ import {createOrUpdateManifestFile} from './include-assets/generate-manifest.js'
22import { buildUIExtension } from '../extension.js'
33import { BuildManifest } from '../../../models/extensions/specifications/ui_extension.js'
44import { copyFile } from '@shopify/cli-kit/node/fs'
5- import { dirname } from '@shopify/cli-kit/node/path'
5+ import { dirname , joinPath } from '@shopify/cli-kit/node/path'
66import type { BundleUIStep , BuildContext } from '../client-steps.js'
77
88interface ExtensionPointWithBuildManifest {
@@ -20,9 +20,13 @@ interface ExtensionPointWithBuildManifest {
2020 */
2121export async function executeBundleUIStep ( step : BundleUIStep , context : BuildContext ) : Promise < void > {
2222 const config = context . extension . configuration
23+ context . options . buildDirectory = step . config ?. bundleFolder ?? undefined
2324 const localOutputPath = await buildUIExtension ( context . extension , context . options )
25+ const bundleOutputDir = step . config ?. bundleFolder
26+ ? joinPath ( dirname ( context . extension . outputPath ) , step . config . bundleFolder )
27+ : dirname ( context . extension . outputPath )
2428 // Copy the locally built files into the bundle
25- await copyFile ( dirname ( localOutputPath ) , dirname ( context . extension . outputPath ) )
29+ await copyFile ( dirname ( localOutputPath ) , bundleOutputDir )
2630
2731 if ( ! step . config ?. generatesAssetsManifest ) return
2832
@@ -32,7 +36,7 @@ export async function executeBundleUIStep(step: BundleUIStep, context: BuildCont
3236 ( ep ) : ep is ExtensionPointWithBuildManifest => typeof ep === 'object' && ep . build_manifest ,
3337 )
3438
35- const entries = extractBuiltAssetEntries ( pointsWithManifest )
39+ const entries = extractBuiltAssetEntries ( pointsWithManifest , step . config ?. bundleFolder )
3640 if ( Object . keys ( entries ) . length > 0 ) {
3741 await createOrUpdateManifestFile ( context , entries )
3842 }
@@ -42,15 +46,18 @@ export async function executeBundleUIStep(step: BundleUIStep, context: BuildCont
4246 * Extracts built asset filepaths from `build_manifest` on each extension point,
4347 * grouped by target. Returns a map of target → `{assetName: filepath}`.
4448 */
45- function extractBuiltAssetEntries ( extensionPoints : { target : string ; build_manifest : BuildManifest } [ ] ) : {
49+ function extractBuiltAssetEntries (
50+ extensionPoints : { target : string ; build_manifest : BuildManifest } [ ] ,
51+ bundleFolder ?: string ,
52+ ) : {
4653 [ target : string ] : { [ assetName : string ] : string }
4754} {
4855 const entries : { [ target : string ] : { [ assetName : string ] : string } } = { }
4956 for ( const { target, build_manifest : buildManifest } of extensionPoints ) {
5057 if ( ! buildManifest ?. assets ) continue
5158 const assets : { [ name : string ] : string } = { }
5259 for ( const [ name , asset ] of Object . entries ( buildManifest . assets ) ) {
53- if ( asset ?. filepath ) assets [ name ] = asset . filepath
60+ if ( asset ?. filepath ) assets [ name ] = bundleFolder ? joinPath ( bundleFolder , asset . filepath ) : asset . filepath
5461 }
5562 if ( Object . keys ( assets ) . length > 0 ) entries [ target ] = assets
5663 }
0 commit comments