Skip to content

Commit 07674c6

Browse files
pranaygpclaude
authored andcommitted
feat: add type safety for builder configurations with discriminated unions
Improves type safety by creating discriminated union types for builder-specific configurations, making it clear which configuration options are required for each builder type. Changes: - Created BaseWorkflowConfig interface with common options - Created StandaloneConfig, VercelBuildOutputConfig, and NextConfig types - Made WorkflowConfig a discriminated union based on buildTarget - Added documentation for each configuration type - Exported new types from @workflow/builders This enables better IntelliSense and type checking when constructing builder configurations, preventing invalid configuration combinations at compile time. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent bf54a7b commit 07674c6

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

.changeset/add-type-safety.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@workflow/builders": patch
3+
---
4+
5+
Add type safety for builder configurations with discriminated unions

packages/builders/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
export { BaseBuilder } from './base-builder.js';
22
export { StandaloneBuilder } from './standalone.js';
33
export { VercelBuildOutputAPIBuilder } from './vercel-build-output-api.js';
4-
export type { WorkflowConfig, BuildTarget } from './types.js';
4+
export type {
5+
WorkflowConfig,
6+
BuildTarget,
7+
StandaloneConfig,
8+
VercelBuildOutputConfig,
9+
NextConfig,
10+
} from './types.js';
511
export { validBuildTargets, isValidBuildTarget } from './types.js';
612
export type { WorkflowManifest } from './apply-swc-transform.js';
713
export { applySwcTransform } from './apply-swc-transform.js';

packages/builders/src/types.ts

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ export const validBuildTargets = [
66
] as const;
77
export type BuildTarget = (typeof validBuildTargets)[number];
88

9-
export interface WorkflowConfig {
9+
/**
10+
* Common configuration options shared across all builder types.
11+
*/
12+
interface BaseWorkflowConfig {
1013
watch?: boolean;
1114
dirs: string[];
1215
workingDir: string;
13-
buildTarget: BuildTarget;
14-
stepsBundlePath: string;
15-
workflowsBundlePath: string;
16-
webhookBundlePath: string;
1716

1817
// Optionally generate a client library for workflow execution. The preferred
1918
// method of using workflow is to use a loader within a framework (like
@@ -25,6 +24,45 @@ export interface WorkflowConfig {
2524
workflowManifestPath?: string;
2625
}
2726

27+
/**
28+
* Configuration for standalone (CLI-based) builds.
29+
*/
30+
export interface StandaloneConfig extends BaseWorkflowConfig {
31+
buildTarget: 'standalone';
32+
stepsBundlePath: string;
33+
workflowsBundlePath: string;
34+
webhookBundlePath: string;
35+
}
36+
37+
/**
38+
* Configuration for Vercel Build Output API builds.
39+
*/
40+
export interface VercelBuildOutputConfig extends BaseWorkflowConfig {
41+
buildTarget: 'vercel-build-output-api';
42+
stepsBundlePath: string;
43+
workflowsBundlePath: string;
44+
webhookBundlePath: string;
45+
}
46+
47+
/**
48+
* Configuration for Next.js builds.
49+
*/
50+
export interface NextConfig extends BaseWorkflowConfig {
51+
buildTarget: 'next';
52+
// Next.js builder computes paths dynamically, so these are not used
53+
stepsBundlePath: string;
54+
workflowsBundlePath: string;
55+
webhookBundlePath: string;
56+
}
57+
58+
/**
59+
* Discriminated union of all builder configuration types.
60+
*/
61+
export type WorkflowConfig =
62+
| StandaloneConfig
63+
| VercelBuildOutputConfig
64+
| NextConfig;
65+
2866
export function isValidBuildTarget(
2967
target: string | undefined
3068
): target is BuildTarget {

0 commit comments

Comments
 (0)