Skip to content

Commit 0108275

Browse files
committed
Expose tools and instructions in the Dev Server payload
1 parent 00cd44a commit 0108275

File tree

4 files changed

+256
-141
lines changed

4 files changed

+256
-141
lines changed

packages/app/src/cli/models/extensions/specification.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ export interface Asset {
4848
content: string
4949
}
5050

51+
export interface BuildAsset {
52+
filepath: string
53+
module: string
54+
static?: boolean
55+
}
56+
5157
type BuildConfig =
5258
| {mode: 'ui' | 'theme' | 'function' | 'tax_calculation' | 'none'}
5359
| {mode: 'copy_files'; filePatterns: string[]; ignoredFilePatterns?: string[]}

packages/app/src/cli/models/extensions/specifications/ui_extension.ts

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
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'
1010
import {NewExtensionPointSchemaType, NewExtensionPointsSchema, BaseSchema, MetafieldSchema} from '../schemas.js'
1111
import {loadLocalesConfig} from '../../../utilities/extensions/locales-configuration.js'
1212
import {getExtensionPointTargetSurface} from '../../../services/dev/extension/utilities.js'
@@ -27,16 +27,10 @@ const validatePoints = (config: {extension_points?: unknown[]; targeting?: unkno
2727
export 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(/\.render$/, '.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+
461457
export default uiExtensionSpec

0 commit comments

Comments
 (0)