mirror of
https://github.com/pnpm/action-setup.git
synced 2025-03-31 05:00: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 * as yaml from 'yaml'
|
||||||
import { z, ZodError } from 'zod'
|
import { z, ZodError } from 'zod'
|
||||||
|
|
||||||
export interface RunInstall {
|
const RunInstallSchema = z.object({
|
||||||
readonly recursive?: boolean
|
|
||||||
readonly cwd?: string
|
|
||||||
readonly args?: readonly string[]
|
|
||||||
}
|
|
||||||
|
|
||||||
const zRunInstall = z.object({
|
|
||||||
recursive: z.boolean().optional(),
|
recursive: z.boolean().optional(),
|
||||||
cwd: z.string().optional(),
|
cwd: z.string().optional(),
|
||||||
args: z.array(z.string()).optional(),
|
args: z.array(z.string()).optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export type RunInstallInput =
|
const RunInstallInputSchema = z.union([
|
||||||
| null
|
|
||||||
| boolean
|
|
||||||
| RunInstall
|
|
||||||
| RunInstall[]
|
|
||||||
|
|
||||||
const zRunInstallInput = z.union([
|
|
||||||
z.null(),
|
z.null(),
|
||||||
z.boolean(),
|
z.boolean(),
|
||||||
zRunInstall,
|
RunInstallSchema,
|
||||||
z.array(zRunInstall),
|
z.array(RunInstallSchema),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
export type RunInstallInput = z.infer<typeof RunInstallInputSchema>
|
||||||
|
export type RunInstall = z.infer<typeof RunInstallSchema>
|
||||||
|
|
||||||
export function parseRunInstall(inputName: string): RunInstall[] {
|
export function parseRunInstall(inputName: string): RunInstall[] {
|
||||||
const input = getInput(inputName, { required: true })
|
const input = getInput(inputName, { required: true })
|
||||||
const parsedInput: unknown = yaml.parse(input)
|
const parsedInput: unknown = yaml.parse(input)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result: RunInstallInput = zRunInstallInput.parse(parsedInput)
|
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
|
||||||
if (!result) return []
|
if (!result) return []
|
||||||
if (result === true) return [{ recursive: true }]
|
if (result === true) return [{ recursive: true }]
|
||||||
if (Array.isArray(result)) return result
|
if (Array.isArray(result)) return result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user