Skip to content

Commit a025223

Browse files
committed
upgrade to zod/v4
1 parent 2dc53b7 commit a025223

File tree

6 files changed

+48
-36
lines changed

6 files changed

+48
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- [2025-05-31] [upgrade to zod/v4](https://github.com/RubricLab/cli/commit/732c6745223fce13a322c1d2c6015e3dfbc1443e)
12
- [2025-04-24] [Handle undefined args](https://github.com/RubricLab/cli/commit/f34a9b004438071586bdd126db88a84ab8f1b9b2)
23
- [2025-04-23] [Support arg typing via command helper](https://github.com/RubricLab/cli/commit/01730221c250dc651a1cc466ff3aef85a4361a1e)
34
- [2025-04-23] [Trigger build](https://github.com/RubricLab/cli/commit/f48dfb50b8388ca5b9a6762aba521093a8226e5b)

lib/help.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z } from 'zod'
1+
import { z } from 'zod/v4'
22
import { format } from './colors'
33
import type { Command } from './types'
44

@@ -52,7 +52,7 @@ function showCommandHelp({
5252
console.log(` ${command.description}`)
5353

5454
if (command.args instanceof z.ZodObject) {
55-
const shape = command.args.shape as z.AnyZodObject
55+
const shape = command.args.shape as z.ZodObject
5656
const entries = Object.entries(shape)
5757

5858
if (entries.length > 0) {
@@ -79,27 +79,38 @@ function showCommandHelp({
7979
}
8080
}
8181

82-
function getSchemaType(schema: z.ZodTypeAny): string {
82+
type SupportedZodType =
83+
| z.ZodBoolean
84+
| z.ZodString
85+
| z.ZodNumber
86+
| z.ZodArray
87+
| z.ZodOptional
88+
| z.ZodDefault
89+
90+
function getSchemaType(schema: SupportedZodType): string {
8391
if (schema instanceof z.ZodBoolean) return 'boolean'
8492
if (schema instanceof z.ZodString) return 'string'
8593
if (schema instanceof z.ZodNumber) return 'number'
8694
if (schema instanceof z.ZodArray) return 'array'
87-
if (schema instanceof z.ZodOptional) return getSchemaType(schema.unwrap())
88-
if (schema instanceof z.ZodDefault) return getSchemaType(schema.removeDefault())
95+
if (schema instanceof z.ZodOptional) return getSchemaType(schema.def.innerType as SupportedZodType)
96+
if (schema instanceof z.ZodDefault) return getSchemaType(schema.def.innerType as SupportedZodType)
8997
return 'value'
9098
}
9199

92-
function getSchemaDescription(schema: z.ZodTypeAny): string | undefined {
93-
if (schema instanceof z.ZodOptional) return getSchemaDescription(schema.unwrap())
94-
if (schema instanceof z.ZodDefault) return getSchemaDescription(schema.removeDefault())
100+
function getSchemaDescription(schema: SupportedZodType): string | undefined {
101+
if (schema instanceof z.ZodOptional)
102+
return getSchemaDescription(schema.def.innerType as SupportedZodType)
103+
if (schema instanceof z.ZodDefault)
104+
return getSchemaDescription(schema.def.innerType as SupportedZodType)
95105
return schema.description
96106
}
97107

98-
function getSchemaDefaultValue(schema: z.ZodTypeAny): unknown {
108+
function getSchemaDefaultValue(schema: SupportedZodType): unknown {
99109
if (schema instanceof z.ZodDefault) {
100-
const defaultValue = schema._def.defaultValue()
110+
const defaultValue = schema.def.defaultValue
101111
return defaultValue
102112
}
103-
if (schema instanceof z.ZodOptional) return getSchemaDefaultValue(schema.unwrap())
113+
if (schema instanceof z.ZodOptional)
114+
return getSchemaDefaultValue(schema.def.innerType as SupportedZodType)
104115
return undefined
105116
}

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { parseCommand } from './parse'
22
import type { CLI, Command } from './types'
33
export { format } from './colors'
4-
import type { z } from 'zod'
4+
import type { z } from 'zod/v4'
55
export type { Command, CLI }
66

77
export function createCLI(config: {

lib/parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z } from 'zod'
1+
import { z } from 'zod/v4'
22
import { format } from './colors'
33
import { showHelp } from './help'
44
import type { Command } from './types'

lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { z } from 'zod'
1+
import type { z } from 'zod/v4'
22

33
export type Command<TArgs extends z.ZodSchema = z.ZodSchema> = {
44
name: string

package.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
2-
"scripts": {
3-
"prepare": "bun x simple-git-hooks",
4-
"bleed": "bun x npm-check-updates -u",
5-
"clean": "rm -rf .next && rm -rf node_modules",
6-
"format": "bun x biome format --write .",
7-
"lint": "bun x biome check .",
8-
"lint:fix": "bun x biome lint . --write --unsafe"
9-
},
10-
"name": "@rubriclab/cli",
11-
"version": "0.0.7",
12-
"main": "lib/index.ts",
13-
"private": false,
14-
"dependencies": {
15-
"@rubriclab/config": "*",
16-
"@rubriclab/package": "*"
17-
},
18-
"simple-git-hooks": {
19-
"post-commit": "bun run rubriclab-postcommit"
20-
},
21-
"publishConfig": {
22-
"access": "public"
23-
}
2+
"scripts": {
3+
"prepare": "bun x simple-git-hooks",
4+
"bleed": "bun x npm-check-updates -u",
5+
"clean": "rm -rf .next && rm -rf node_modules",
6+
"format": "bun x biome format --write .",
7+
"lint": "bun x biome check .",
8+
"lint:fix": "bun x biome lint . --write --unsafe"
9+
},
10+
"name": "@rubriclab/cli",
11+
"version": "0.0.8",
12+
"main": "lib/index.ts",
13+
"private": false,
14+
"dependencies": {
15+
"@rubriclab/config": "*",
16+
"@rubriclab/package": "*"
17+
},
18+
"simple-git-hooks": {
19+
"post-commit": "bun run rubriclab-postcommit"
20+
},
21+
"publishConfig": {
22+
"access": "public"
23+
}
2424
}

0 commit comments

Comments
 (0)