feat(publish): compile and package workers for npm and isolate workflow imports

This commit is contained in:
yiling
2026-06-05 14:34:22 +08:00
parent dfdf095be7
commit 042188cc74
5 changed files with 219 additions and 72 deletions
@@ -33,9 +33,32 @@ export function temporalWorkflow(options: TemporalWorkflowPluginOptions = {}): B
build.onLoad({ filter: /.*/, namespace: 'temporal-workflow' }, async (args) => {
const workflowsPath = args.path
// The bundleOptions contains raw parameters for Temporal bundleWorkflowCode which uses Webpack.
// We cast options.bundleOptions to any to check for webpackConfigHook.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const originalHook = (options.bundleOptions as any)?.webpackConfigHook
const bundleOptions = {
...options.bundleOptions,
// Webpack config is untyped inside Temporal's webpackConfigHook callback.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
webpackConfigHook: (config: any) => {
config.resolve = config.resolve || {}
config.resolve.alias = {
...config.resolve.alias,
'@shumai/workflow-core':
require.resolve('@shumai/workflow-core/src/workflow-utils.ts'),
}
console.log('Webpack config aliases:', config.resolve.alias)
if (originalHook) {
return originalHook(config)
}
return config
},
}
const bundle = await bundleWorkflowCode({
workflowsPath,
...options.bundleOptions,
...bundleOptions,
})
return {
+2
View File
@@ -110,6 +110,7 @@ export class WorkflowService {
'@temporalio/workflow': path.dirname(
require.resolve('@temporalio/workflow/package.json'),
),
'@shumai/workflow-core': require.resolve('./workflow-utils'),
}
return config
},
@@ -130,6 +131,7 @@ export class WorkflowService {
'@temporalio/workflow': path.dirname(
require.resolve('@temporalio/workflow/package.json'),
),
'@shumai/workflow-core': require.resolve('./workflow-utils'),
}
return config
},