Skip to content

Commit bdc4b84

Browse files
Fix default output build path for functions
1 parent ab3ea53 commit bdc4b84

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,59 @@ describe('draftMessages', async () => {
551551
expect(extensionInstance.uid).toBe('orders/delete::123::https://my-app.com/webhooks')
552552
})
553553
})
554+
555+
describe('outputPath for function extensions', async () => {
556+
test('uses default path when build is undefined', async () => {
557+
// Given
558+
const config = {
559+
name: 'foo',
560+
type: 'function',
561+
api_version: '2023-07',
562+
configuration_ui: true,
563+
// build is intentionally omitted to test undefined case
564+
} as FunctionConfigType
565+
566+
const extensionInstance = await testFunctionExtension({
567+
config,
568+
dir: 'test-function',
569+
})
570+
571+
// Then
572+
expect(extensionInstance.outputPath).toBe(joinPath('test-function', 'dist', 'index.wasm'))
573+
})
574+
575+
test('uses default path when build.path is undefined', async () => {
576+
// Given
577+
const config = functionConfiguration()
578+
config.build = {
579+
wasm_opt: true,
580+
// path is not defined
581+
}
582+
583+
const extensionInstance = await testFunctionExtension({
584+
config,
585+
dir: 'test-function',
586+
})
587+
588+
// Then
589+
expect(extensionInstance.outputPath).toBe(joinPath('test-function', 'dist', 'index.wasm'))
590+
})
591+
592+
test('uses custom path when build.path is defined', async () => {
593+
// Given
594+
const config = functionConfiguration()
595+
config.build = {
596+
wasm_opt: true,
597+
path: 'custom/output.wasm',
598+
}
599+
600+
const extensionInstance = await testFunctionExtension({
601+
config,
602+
dir: 'test-function',
603+
})
604+
605+
// Then
606+
expect(extensionInstance.outputPath).toBe(joinPath('test-function', 'custom/output.wasm'))
607+
})
608+
})
554609
})

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
169169

170170
if (this.isFunctionExtension) {
171171
const config = this.configuration as unknown as FunctionConfigType
172-
this.outputPath = joinPath(this.directory, config.build.path ?? joinPath('dist', 'index.wasm'))
172+
const defaultPath = joinPath('dist', 'index.wasm')
173+
this.outputPath = joinPath(this.directory, config.build?.path ?? defaultPath)
173174
}
174175
}
175176

0 commit comments

Comments
 (0)