mirror of
				https://github.com/pnpm/action-setup.git
				synced 2025-10-31 17:32:24 +08:00 
			
		
		
		
	Use glob
This commit is contained in:
		| @@ -1,4 +1,6 @@ | ||||
| import { getInput, InputOptions } from '@actions/core' | ||||
| import { inspect } from 'util' | ||||
| import { getInput, error, InputOptions } from '@actions/core' | ||||
| import * as glob from '@actions/glob' | ||||
|  | ||||
| export interface Inputs { | ||||
|   readonly version: string | ||||
| @@ -11,10 +13,21 @@ const options: InputOptions = { | ||||
|   required: true, | ||||
| } | ||||
|  | ||||
| export const getInputs = (): Inputs => ({ | ||||
| async function parsePath(pattern: string, inputName: string) { | ||||
|   const builder = await glob.create(pattern) | ||||
|   const paths = await builder.glob() | ||||
|   if (paths.length !== 1) { | ||||
|     error(`Input ${inputName} is expected to match 1 path, but it matches ${paths.length}: ${inspect(paths)}`) | ||||
|   } | ||||
|   return paths[0] | ||||
| } | ||||
|  | ||||
| const parseInputPath = (name: string) => parsePath(getInput(name, options), name) | ||||
|  | ||||
| export const getInputs = async (): Promise<Inputs> => ({ | ||||
|   version: getInput('version', options), | ||||
|   dest: getInput('dest', options), | ||||
|   binDest: getInput('bin_dest', options), | ||||
|   dest: await parseInputPath('dest'), | ||||
|   binDest: await parseInputPath('bin_dest'), | ||||
|   registry: getInput('registry', options), | ||||
| }) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user