chore: update all dependencies and update tests

This commit is contained in:
2026-01-26 10:41:20 +02:00
parent 267de909e7
commit 29331c1dad
8 changed files with 2328 additions and 2442 deletions

View File

@@ -27,22 +27,22 @@
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/exec": "^7.1.0",
"@semantic-release/git": "^10.0.1",
"@semantic-release/release-notes-generator": "^12.1.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.8",
"conventional-changelog": "^5.1.0",
"conventional-changelog-cli": "^4.1.0",
"gh-pages": "^6.1.1",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"semantic-release": "^23.0.8",
"ts-jest": "^29.1.2",
"@semantic-release/release-notes-generator": "^14.1.0",
"@types/jest": "^30.0.0",
"@types/node": "^25.0.10",
"conventional-changelog": "^7.1.1",
"conventional-changelog-cli": "^5.0.0",
"gh-pages": "^6.3.0",
"jest": "^30.2.0",
"prettier": "^3.8.1",
"semantic-release": "^25.0.2",
"ts-jest": "^29.4.6",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
"typescript": "^5.9.3"
},
"dependencies": {
"zod": "^3.23.6"
"zod": "^4.3.6"
}
}

4712
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -15,7 +15,7 @@ import { DeepRequired, _setOrPush, _deepMerge, getErrorMessage, capitalize } fro
import { MassargExample, ExampleConfig } from './example'
import { format } from './style'
export const CommandConfig = <RunArgs extends ArgsObject = ArgsObject>(args: z.ZodType<RunArgs>) =>
export const CommandConfig = <RunArgs extends ArgsObject = ArgsObject>(_args: z.ZodType<RunArgs>) =>
z.object({
/** Command name */
name: z.string(),
@@ -27,10 +27,7 @@ export const CommandConfig = <RunArgs extends ArgsObject = ArgsObject>(args: z.Z
* Function used when invoking this command. It receives the parsed options and the primary
* instance of Massarg used to invoke this command (the top-level instance)
*/
run: z
.function()
.args(args, z.any())
.returns(z.union([z.promise(z.void()), z.void()])) as z.ZodType<Runner<RunArgs>>,
run: z.function() as unknown as z.ZodType<Runner<RunArgs>>,
/** The prefix to match before option names, e.g. `--` */
optionPrefix: z.string().default(DEFAULT_OPT_FULL_PREFIX).optional(),
/** The prefix to match before option aliases, e.g. `-` */

View File

@@ -19,9 +19,7 @@ export const OptionConfig = <OptionType, Args extends ArgsObject = ArgsObject>(
* Parse the value of the option. You can return any type here, or throw an error if the value
* is invalid.
*/
parse: z.function().args(z.string(), z.any()).returns(type).optional() as z.ZodOptional<
z.ZodType<Parser<Args, OptionType>>
>,
parse: z.function().optional() as unknown as z.ZodOptional<z.ZodType<Parser<Args, OptionType>>>,
/**
* Whether the option is an array.
*

View File

@@ -1,5 +1,4 @@
import z from 'zod'
import { _zodEnumFromObjKeys } from './utils'
export { strConcat, indent } from './utils'
export const ansiStyles = {
@@ -26,12 +25,14 @@ export const ansiColors = {
brightMagenta: '\x1b[95m',
brightCyan: '\x1b[96m',
brightWhite: '\x1b[97m',
}
} as const
export type AnsiColor = keyof typeof ansiColors
export const StringStyle = z.object({
bold: z.boolean().optional(),
underline: z.boolean().optional(),
color: _zodEnumFromObjKeys(ansiColors).optional(),
color: z.enum(Object.keys(ansiColors) as [AnsiColor, ...AnsiColor[]]).optional(),
reset: z.boolean().default(true).optional(),
})
@@ -39,7 +40,7 @@ export type StringStyle = z.infer<typeof StringStyle>
export function format(string: string, style: StringStyle = {}): string {
const { color, bold, underline, reset = true } = style
const colorCode = color ? ansiColors[color] : ''
const colorCode = color ? ansiColors[color as AnsiColor] : ''
const boldCode = bold ? ansiStyles.bold : ''
const underlineCode = underline ? ansiStyles.underline : ''
const resetCode = reset ? ansiStyles.reset : ''

View File

@@ -68,9 +68,9 @@ export function indent(str: Parseable | Parseable[], indent = 2): string {
}
/** @internal */
export function _zodEnumFromObjKeys<K extends string>(obj: Record<K, any>): z.ZodEnum<[K, ...K[]]> {
const [firstKey, ...otherKeys] = Object.keys(obj) as K[]
return z.enum([firstKey, ...otherKeys])
export function _zodEnumFromObjKeys<K extends string>(obj: Record<K, any>) {
const keys = Object.keys(obj) as [K, ...K[]]
return z.enum(keys)
}
/** @internal */

View File

@@ -34,7 +34,7 @@ describe('sub command', () => {
description: 123 as any,
run: jest.fn(),
}),
).toThrow('Expected string, received number')
).toThrow('Invalid input: expected string, received number')
error.mockRestore()
})
})

View File

@@ -22,7 +22,7 @@ describe('option', () => {
aliases: [],
defaultValue: '',
}),
).toThrow('Expected string, received number')
).toThrow('Invalid input: expected string, received number')
error.mockRestore()
})
test('add duplicate', () => {
@@ -128,7 +128,7 @@ describe('flag', () => {
description: 123 as any,
aliases: [],
}),
).toThrow('Expected string, received number')
).toThrow('Invalid input: expected string, received number')
error.mockRestore()
})
describe('negation', () => {