66 createToolsTypeDefinition ,
77 ToolsFileSchema ,
88} from './type-generation.js'
9- import { Asset , AssetIdentifier , ExtensionFeature , createExtensionSpecification } from '../specification.js'
9+ import { Asset , AssetIdentifier , BuildAsset , ExtensionFeature , createExtensionSpecification } from '../specification.js'
1010import { NewExtensionPointSchemaType , NewExtensionPointsSchema , BaseSchema , MetafieldSchema } from '../schemas.js'
1111import { loadLocalesConfig } from '../../../utilities/extensions/locales-configuration.js'
1212import { getExtensionPointTargetSurface } from '../../../services/dev/extension/utilities.js'
@@ -27,16 +27,10 @@ const validatePoints = (config: {extension_points?: unknown[]; targeting?: unkno
2727export interface BuildManifest {
2828 assets : {
2929 // Main asset is always required
30- [ AssetIdentifier . Main ] : {
31- filepath : string
32- module ?: string
33- }
34- } & {
35- [ key in AssetIdentifier ] ?: {
36- filepath : string
37- module ?: string
38- static ?: boolean
39- }
30+ [ AssetIdentifier . Main ] : BuildAsset
31+ [ AssetIdentifier . ShouldRender ] ?: BuildAsset
32+ [ AssetIdentifier . Tools ] ?: BuildAsset
33+ [ AssetIdentifier . Instructions ] ?: BuildAsset
4034 }
4135}
4236
@@ -147,27 +141,10 @@ const uiExtensionSpec = createExtensionSpecification({
147141
148142 const assets : { [ key : string ] : Asset } = { }
149143 extensionPoints . forEach ( ( extensionPoint ) => {
150- // Start of Selection
151- Object . entries ( extensionPoint . build_manifest . assets ) . forEach ( ( [ identifier , asset ] ) => {
152- if ( identifier === AssetIdentifier . Main ) {
153- return
154- }
155-
156- // Skip static assets - they are copied after esbuild completes in rebuildContext
157- if ( asset . static && asset . module ) {
158- return
159- }
160-
161- assets [ identifier ] = {
162- identifier : identifier as AssetIdentifier ,
163- outputFileName : asset . filepath ,
164- content : shouldIncludeShopifyExtend
165- ? `import shouldRender from '${ asset . module } ';shopify.extend('${ getShouldRenderTarget (
166- extensionPoint . target ,
167- ) } ', (...args) => shouldRender(...args));`
168- : `import '${ asset . module } '` ,
169- }
170- } )
144+ const shouldRenderAsset = buildShouldRenderAsset ( extensionPoint , shouldIncludeShopifyExtend )
145+ if ( shouldRenderAsset ) {
146+ assets [ AssetIdentifier . ShouldRender ] = shouldRenderAsset
147+ }
171148 } )
172149
173150 const assetsArray = Object . values ( assets )
@@ -458,4 +435,23 @@ export function getShouldRenderTarget(target: string) {
458435 return target . replace ( / \. r e n d e r $ / , '.should-render' )
459436}
460437
438+ function buildShouldRenderAsset (
439+ extensionPoint : NewExtensionPointSchemaType & { build_manifest : BuildManifest } ,
440+ shouldIncludeShopifyExtend : boolean ,
441+ ) {
442+ const shouldRenderAsset = extensionPoint . build_manifest . assets [ AssetIdentifier . ShouldRender ]
443+ if ( ! shouldRenderAsset ) {
444+ return
445+ }
446+ return {
447+ identifier : AssetIdentifier . ShouldRender ,
448+ outputFileName : shouldRenderAsset . filepath ,
449+ content : shouldIncludeShopifyExtend
450+ ? `import shouldRender from '${ shouldRenderAsset . module } ';shopify.extend('${ getShouldRenderTarget (
451+ extensionPoint . target ,
452+ ) } ', (...args) => shouldRender(...args));`
453+ : `import '${ shouldRenderAsset . module } '` ,
454+ }
455+ }
456+
461457export default uiExtensionSpec
0 commit comments