Skip to content

Commit 87c62d3

Browse files
pranaygpclaude
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 <noreply@anthropic.com>
1 parent 1e73424 commit 87c62d3

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
@@ -5,14 +5,13 @@ export const validBuildTargets = [
55
] as const;
66
export type BuildTarget = (typeof validBuildTargets)[number];
77

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

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

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

0 commit comments

Comments
 (0)