mirror of
				https://github.com/pnpm/action-setup.git
				synced 2025-11-04 13:29:08 +08:00 
			
		
		
		
	Use glob
This commit is contained in:
		
							
								
								
									
										2
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										13
									
								
								src/index.ts
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/index.ts
									
									
									
									
									
								
							@@ -3,12 +3,15 @@ import getInputs from './inputs'
 | 
				
			|||||||
import setOutputs from './outputs'
 | 
					import setOutputs from './outputs'
 | 
				
			||||||
import install from './install'
 | 
					import install from './install'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const inputs = getInputs()
 | 
					async function main() {
 | 
				
			||||||
 | 
					  const inputs = await getInputs()
 | 
				
			||||||
 | 
					  await install(inputs).then(() => {
 | 
				
			||||||
 | 
					    console.log('Installation Completed!')
 | 
				
			||||||
 | 
					    setOutputs(inputs)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
install(inputs).then(() => {
 | 
					main().catch(error => {
 | 
				
			||||||
  console.log('Installation Completed!')
 | 
					 | 
				
			||||||
  setOutputs(inputs)
 | 
					 | 
				
			||||||
}).catch(error => {
 | 
					 | 
				
			||||||
  console.error(error)
 | 
					  console.error(error)
 | 
				
			||||||
  setFailed(error)
 | 
					  setFailed(error)
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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 {
 | 
					export interface Inputs {
 | 
				
			||||||
  readonly version: string
 | 
					  readonly version: string
 | 
				
			||||||
@@ -11,10 +13,21 @@ const options: InputOptions = {
 | 
				
			|||||||
  required: true,
 | 
					  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),
 | 
					  version: getInput('version', options),
 | 
				
			||||||
  dest: getInput('dest', options),
 | 
					  dest: await parseInputPath('dest'),
 | 
				
			||||||
  binDest: getInput('bin_dest', options),
 | 
					  binDest: await parseInputPath('bin_dest'),
 | 
				
			||||||
  registry: getInput('registry', options),
 | 
					  registry: getInput('registry', options),
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user