mirror of
https://github.com/pnpm/action-setup.git
synced 2025-03-28 02:30:11 +08:00
fix: use zod.infer for exported RunInstall types
This commit is contained in:
parent
2be3e926cc
commit
e801474ba4
@ -2,37 +2,28 @@ import { getInput, error } from '@actions/core'
|
||||
import * as yaml from 'yaml'
|
||||
import { z, ZodError } from 'zod'
|
||||
|
||||
export interface RunInstall {
|
||||
readonly recursive?: boolean
|
||||
readonly cwd?: string
|
||||
readonly args?: readonly string[]
|
||||
}
|
||||
|
||||
const zRunInstall = z.object({
|
||||
const RunInstallSchema = z.object({
|
||||
recursive: z.boolean().optional(),
|
||||
cwd: z.string().optional(),
|
||||
args: z.array(z.string()).optional(),
|
||||
})
|
||||
|
||||
export type RunInstallInput =
|
||||
| null
|
||||
| boolean
|
||||
| RunInstall
|
||||
| RunInstall[]
|
||||
|
||||
const zRunInstallInput = z.union([
|
||||
const RunInstallInputSchema = z.union([
|
||||
z.null(),
|
||||
z.boolean(),
|
||||
zRunInstall,
|
||||
z.array(zRunInstall),
|
||||
RunInstallSchema,
|
||||
z.array(RunInstallSchema),
|
||||
])
|
||||
|
||||
export type RunInstallInput = z.infer<typeof RunInstallInputSchema>
|
||||
export type RunInstall = z.infer<typeof RunInstallSchema>
|
||||
|
||||
export function parseRunInstall(inputName: string): RunInstall[] {
|
||||
const input = getInput(inputName, { required: true })
|
||||
const parsedInput: unknown = yaml.parse(input)
|
||||
|
||||
try {
|
||||
const result: RunInstallInput = zRunInstallInput.parse(parsedInput)
|
||||
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
|
||||
if (!result) return []
|
||||
if (result === true) return [{ recursive: true }]
|
||||
if (Array.isArray(result)) return result
|
||||
|
Loading…
x
Reference in New Issue
Block a user