Skip to content

Commit 5a9ae13

Browse files
Fix other places
1 parent bdc4b84 commit 5a9ae13

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

packages/app/src/cli/models/extensions/extension-instance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
281281
// Functions specific properties
282282
get buildCommand() {
283283
const config = this.configuration as unknown as FunctionConfigType
284-
return config.build.command
284+
return config.build?.command
285285
}
286286

287287
// Paths to be watched in a dev session

packages/app/src/cli/services/build/extension.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,83 @@ describe('buildFunctionExtension', () => {
215215
).rejects.toThrow(AbortError)
216216
expect(releaseLock).not.toHaveBeenCalled()
217217
})
218+
219+
test('handles function with undefined build config', async () => {
220+
// Given
221+
const configWithoutBuild = {
222+
name: 'MyFunction',
223+
type: 'product_discounts',
224+
description: '',
225+
configuration_ui: true,
226+
api_version: '2022-07',
227+
metafields: [],
228+
} as unknown as FunctionConfigType
229+
230+
extension = await testFunctionExtension({config: configWithoutBuild, entryPath: 'src/index.js'})
231+
vi.mocked(fileExistsSync).mockResolvedValue(true)
232+
233+
// When
234+
await expect(
235+
buildFunctionExtension(extension, {
236+
stdout,
237+
stderr,
238+
signal,
239+
app,
240+
environment: 'production',
241+
}),
242+
).resolves.toBeUndefined()
243+
244+
// Then
245+
expect(buildJSFunction).toHaveBeenCalledWith(extension, {
246+
stdout,
247+
stderr,
248+
signal,
249+
app,
250+
environment: 'production',
251+
})
252+
expect(releaseLock).toHaveBeenCalled()
253+
// wasm_opt should not be called when build config is undefined
254+
expect(runWasmOpt).not.toHaveBeenCalled()
255+
})
256+
257+
test('handles function with build config but undefined path', async () => {
258+
// Given
259+
const configWithoutPath = {
260+
name: 'MyFunction',
261+
type: 'product_discounts',
262+
description: '',
263+
build: {
264+
command: 'make build',
265+
wasm_opt: true,
266+
// path is undefined
267+
},
268+
configuration_ui: true,
269+
api_version: '2022-07',
270+
metafields: [],
271+
} as unknown as FunctionConfigType
272+
273+
extension = await testFunctionExtension({config: configWithoutPath})
274+
vi.mocked(fileExistsSync).mockResolvedValue(true)
275+
276+
// When
277+
await expect(
278+
buildFunctionExtension(extension, {
279+
stdout,
280+
stderr,
281+
signal,
282+
app,
283+
environment: 'production',
284+
}),
285+
).resolves.toBeUndefined()
286+
287+
// Then
288+
expect(exec).toHaveBeenCalledWith('make', ['build'], {
289+
stdout,
290+
stderr,
291+
cwd: extension.directory,
292+
signal,
293+
})
294+
expect(releaseLock).toHaveBeenCalled()
295+
expect(runWasmOpt).toHaveBeenCalled()
296+
})
218297
})

packages/app/src/cli/services/build/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export async function buildFunctionExtension(
151151
try {
152152
const bundlePath = extension.outputPath
153153
const relativeBuildPath =
154-
(extension as ExtensionInstance<FunctionConfigType>).configuration.build.path ?? joinPath('dist', 'index.wasm')
154+
(extension as ExtensionInstance<FunctionConfigType>).configuration.build?.path ?? joinPath('dist', 'index.wasm')
155155

156156
extension.outputPath = joinPath(extension.directory, relativeBuildPath)
157157

@@ -161,7 +161,7 @@ export async function buildFunctionExtension(
161161
await buildOtherFunction(extension, options)
162162
}
163163

164-
const wasmOpt = (extension as ExtensionInstance<FunctionConfigType>).configuration.build.wasm_opt
164+
const wasmOpt = (extension as ExtensionInstance<FunctionConfigType>).configuration.build?.wasm_opt
165165
if (fileExistsSync(extension.outputPath) && wasmOpt) {
166166
await runWasmOpt(extension.outputPath)
167167
}

0 commit comments

Comments
 (0)