fix(workflow): add @temporalio/workflow alias to bun-temporal-plugin

This commit is contained in:
yiling
2026-06-06 09:55:18 +08:00
parent a9dcca8cac
commit 852564cc56
2 changed files with 54 additions and 1 deletions
@@ -0,0 +1,50 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { temporalWorkflow } from './bun-temporal-plugin'
import * as worker from '@temporalio/worker'
vi.mock('@temporalio/worker', () => ({
bundleWorkflowCode: vi.fn().mockResolvedValue({ code: 'mock-code', sourceMap: '' })
}))
describe('temporalWorkflow plugin', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('should register onLoad and configure webpackConfigHook with @temporalio/workflow alias', async () => {
const plugin = temporalWorkflow()
let onLoadCallback: Function | null = null
const mockBuild = {
onResolve: vi.fn(),
onLoad: vi.fn((opts, callback) => {
onLoadCallback = callback
})
}
// Run setup
// @ts-ignore
plugin.setup(mockBuild)
expect(onLoadCallback).toBeDefined()
// Trigger onLoad callback
await onLoadCallback!({ path: 'dummy-path' })
// Verify bundleWorkflowCode was called
expect(worker.bundleWorkflowCode).toHaveBeenCalled()
// Inspect the webpackConfigHook that was passed to bundleWorkflowCode
const callArgs = vi.mocked(worker.bundleWorkflowCode).mock.calls[0][0]
expect(callArgs.webpackConfigHook).toBeDefined()
// Invoke the hook with a dummy config
const config = { resolve: { alias: {} } }
const updatedConfig = callArgs.webpackConfigHook(config)
// Check that aliases are set
expect(updatedConfig.resolve.alias['@shumai/workflow-core']).toBeDefined()
expect(updatedConfig.resolve.alias['@temporalio/workflow']).toBeDefined()
})
})
@@ -1,6 +1,6 @@
import { bundleWorkflowCode } from '@temporalio/worker'
import type { BunPlugin } from 'bun'
import { resolve } from 'node:path'
import { resolve, dirname } from 'node:path'
export interface TemporalWorkflowPluginOptions {
/** Query param identifier. Default: 'workflow' */
@@ -47,6 +47,9 @@ export function temporalWorkflow(options: TemporalWorkflowPluginOptions = {}): B
...config.resolve.alias,
'@shumai/workflow-core':
require.resolve('@shumai/workflow-core/src/workflow-utils.ts'),
'@temporalio/workflow': dirname(
require.resolve('@temporalio/workflow/package.json'),
),
}
console.log('Webpack config aliases:', config.resolve.alias)
if (originalHook) {