Skip to content

Commit 31378ea

Browse files
pranaygpclaude
authored 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 <noreply@anthropic.com>
1 parent f8c779e commit 31378ea

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
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
@@ -1,6 +1,7 @@
11
export type { WorkflowManifest } from './apply-swc-transform.js';
22
export { applySwcTransform } from './apply-swc-transform.js';
33
export { BaseBuilder } from './base-builder.js';
4+
export { createBaseBuilderConfig } from './config-helpers.js';
45
export { STEP_QUEUE_TRIGGER, WORKFLOW_QUEUE_TRIGGER } from './constants.js';
56
export { createDiscoverEntriesPlugin } from './discover-entries-esbuild-plugin.js';
67
export { createNodeModuleErrorPlugin } from './node-module-esbuild-plugin.js';

packages/nitro/src/builders.ts

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

6-
const CommonBuildOptions = {
7-
buildTarget: 'next' as const, // unused in base
8-
stepsBundlePath: '', // unused in base
9-
workflowsBundlePath: '', // unused in base
10-
webhookBundlePath: '', // unused in base
11-
};
12-
1310
export class VercelBuilder extends VercelBuildOutputAPIBuilder {
1411
constructor(nitro: Nitro) {
1512
super({
16-
...CommonBuildOptions,
17-
dirs: getWorkflowDirs(nitro),
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,10 +34,11 @@ export class LocalBuilder extends BaseBuilder {
3634
constructor(nitro: Nitro) {
3735
const outDir = join(nitro.options.buildDir, 'workflow');
3836
super({
39-
...CommonBuildOptions,
40-
dirs: getWorkflowDirs(nitro),
41-
workingDir: nitro.options.rootDir,
42-
watch: nitro.options.dev,
37+
...createBaseBuilderConfig({
38+
workingDir: nitro.options.rootDir,
39+
watch: nitro.options.dev,
40+
}),
41+
buildTarget: 'next', // Placeholder, not actually used
4342
});
4443
this.#outDir = outDir;
4544
}

0 commit comments

Comments
 (0)