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
@@ -88,7 +82,6 @@ export const UIExtensionSchema = BaseSchema.extend({
8882 }
8983
9084 return {
91- tools : targeting . tools ,
9285 target : targeting . target ,
9386 module : targeting . module ,
9487 metafields : targeting . metafields ?? config . metafields ?? [ ] ,
@@ -97,6 +90,8 @@ export const UIExtensionSchema = BaseSchema.extend({
9790 capabilities : targeting . capabilities ,
9891 preloads : targeting . preloads ?? { } ,
9992 build_manifest : buildManifest ,
93+ tools : targeting . tools ,
94+ instructions : targeting . instructions ,
10095 }
10196 } )
10297 return { ...config , extension_points : extensionPoints }
@@ -148,27 +143,10 @@ const uiExtensionSpec = createExtensionSpecification({
148143
149144 const assets : { [ key : string ] : Asset } = { }
150145 extensionPoints . forEach ( ( extensionPoint ) => {
151- // Start of Selection
152- Object . entries ( extensionPoint . build_manifest . assets ) . forEach ( ( [ identifier , asset ] ) => {
153- if ( identifier === AssetIdentifier . Main ) {
154- return
155- }
156-
157- // Skip static assets - they are copied after esbuild completes in rebuildContext
158- if ( asset . static && asset . module ) {
159- return
160- }
161-
162- assets [ identifier ] = {
163- identifier : identifier as AssetIdentifier ,
164- outputFileName : asset . filepath ,
165- content : shouldIncludeShopifyExtend
166- ? `import shouldRender from '${ asset . module } ';shopify.extend('${ getShouldRenderTarget (
167- extensionPoint . target ,
168- ) } ', (...args) => shouldRender(...args));`
169- : `import '${ asset . module } '` ,
170- }
171- } )
146+ const shouldRenderAsset = buildShouldRenderAsset ( extensionPoint , shouldIncludeShopifyExtend )
147+ if ( shouldRenderAsset ) {
148+ assets [ AssetIdentifier . ShouldRender ] = shouldRenderAsset
149+ }
172150 } )
173151
174152 const assetsArray = Object . values ( assets )
@@ -181,8 +159,8 @@ const uiExtensionSpec = createExtensionSpecification({
181159 if ( ! isRemoteDomExtension ( config ) ) return
182160
183161 await Promise . all (
184- config . extension_points . map ( ( extensionPoint ) => {
185- if ( ! ( 'build_manifest' in extensionPoint ) ) return Promise . resolve ( )
162+ config . extension_points . flatMap ( ( extensionPoint ) => {
163+ if ( ! ( 'build_manifest' in extensionPoint ) ) return [ ]
186164
187165 return Object . entries ( extensionPoint . build_manifest . assets ) . map ( ( [ _ , asset ] ) => {
188166 if ( asset . static && asset . module ) {
@@ -459,4 +437,23 @@ export function getShouldRenderTarget(target: string) {
459437 return target . replace ( / \. r e n d e r $ / , '.should-render' )
460438}
461439
440+ function buildShouldRenderAsset (
441+ extensionPoint : NewExtensionPointSchemaType & { build_manifest : BuildManifest } ,
442+ shouldIncludeShopifyExtend : boolean ,
443+ ) {
444+ const shouldRenderAsset = extensionPoint . build_manifest . assets [ AssetIdentifier . ShouldRender ]
445+ if ( ! shouldRenderAsset ) {
446+ return
447+ }
448+ return {
449+ identifier : AssetIdentifier . ShouldRender ,
450+ outputFileName : shouldRenderAsset . filepath ,
451+ content : shouldIncludeShopifyExtend
452+ ? `import shouldRender from '${ shouldRenderAsset . module } ';shopify.extend('${ getShouldRenderTarget (
453+ extensionPoint . target ,
454+ ) } ', (...args) => shouldRender(...args));`
455+ : `import '${ shouldRenderAsset . module } '` ,
456+ }
457+ }
458+
462459export default uiExtensionSpec
0 commit comments