Skip to content

Commit 311c7c5

Browse files
pranaygpclaude
andcommitted
refactor: consolidate builder configuration patterns
Extracts common builder configuration pattern into a reusable helper function, improving consistency across framework integrations. Changes: - Created createBaseBuilderConfig() helper in @workflow/builders - Updated @workflow/nitro builders to use the new helper - Removed CommonBuildOptions constant from nitro package - Added clear documentation for when bundle paths are not used This makes it easier for framework integrations to create properly configured builder instances without manually specifying unused bundle path properties. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 9edd6a2 commit 311c7c5

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

.changeset/consolidate-config.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@workflow/builders": patch
3+
"@workflow/nitro": patch
4+
---
5+
6+
Consolidate builder configuration patterns
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { WorkflowConfig } from './types.js';
2+
3+
/**
4+
* Creates a partial configuration for builders that don't use bundle paths directly.
5+
* Used by framework integrations like Nitro where the builder computes paths internally.
6+
*/
7+
export function createBaseBuilderConfig(options: {
8+
workingDir: string;
9+
dirs?: string[];
10+
watch?: boolean;
11+
externalPackages?: string[];
12+
}): Omit<WorkflowConfig, 'buildTarget'> {
13+
return {
14+
dirs: options.dirs ?? ['workflows'],
15+
workingDir: options.workingDir,
16+
watch: options.watch,
17+
stepsBundlePath: '', // Not used by base builder methods
18+
workflowsBundlePath: '', // Not used by base builder methods
19+
webhookBundlePath: '', // Not used by base builder methods
20+
externalPackages: options.externalPackages,
21+
};
22+
}

packages/builders/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export { createDiscoverEntriesPlugin } from './discover-entries-esbuild-plugin.j
1515
export { createNodeModuleErrorPlugin } from './node-module-esbuild-plugin.js';
1616
export { createSwcPlugin } from './swc-esbuild-plugin.js';
1717
export { STEP_QUEUE_TRIGGER, WORKFLOW_QUEUE_TRIGGER } from './constants.js';
18+
export { createBaseBuilderConfig } from './config-helpers.js';

packages/nitro/src/builders.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import { mkdir, readFile, writeFile } from 'node:fs/promises';
22
import { join } from 'node:path';
3-
import { BaseBuilder, VercelBuildOutputAPIBuilder } from '@workflow/builders';
3+
import {
4+
BaseBuilder,
5+
VercelBuildOutputAPIBuilder,
6+
createBaseBuilderConfig,
7+
} from '@workflow/builders';
48
import type { Nitro } from 'nitro/types';
59

6-
const CommonBuildOptions = {
7-
dirs: ['workflows'],
8-
buildTarget: 'next' as const, // unused in base
9-
stepsBundlePath: '', // unused in base
10-
workflowsBundlePath: '', // unused in base
11-
webhookBundlePath: '', // unused in base
12-
};
13-
1410
export class VercelBuilder extends VercelBuildOutputAPIBuilder {
1511
constructor(nitro: Nitro) {
1612
super({
17-
...CommonBuildOptions,
18-
workingDir: nitro.options.rootDir,
13+
...createBaseBuilderConfig({
14+
workingDir: nitro.options.rootDir,
15+
}),
16+
buildTarget: 'vercel-build-output-api',
1917
});
2018
}
2119
override async build(): Promise<void> {
@@ -36,9 +34,11 @@ export class LocalBuilder extends BaseBuilder {
3634
constructor(nitro: Nitro) {
3735
const outDir = join(nitro.options.buildDir, 'workflow');
3836
super({
39-
...CommonBuildOptions,
40-
workingDir: nitro.options.rootDir,
41-
watch: nitro.options.dev,
37+
...createBaseBuilderConfig({
38+
workingDir: nitro.options.rootDir,
39+
watch: nitro.options.dev,
40+
}),
41+
buildTarget: 'next', // Placeholder, not actually used
4242
});
4343
this.#outDir = outDir;
4444
}

0 commit comments

Comments
 (0)