mirror of
				https://github.com/pnpm/action-setup.git
				synced 2025-10-31 17:32:24 +08:00 
			
		
		
		
	feat: standalone binary (#92)
* feat: add an option to install the self-contained binary version of pnpm * test: add a test about nodejs_bundled * style: remove an empty line * chore: use newer pnpm * chore: update dependencies * feat: rename `nodejs_bundled` to `standalone` as @zkochan suggested * docs: add --------- Co-authored-by: Takashi Sato <takashi@tks.st>
This commit is contained in:
		| @@ -1,4 +1,4 @@ | ||||
| import { getInput, InputOptions } from '@actions/core' | ||||
| import { getBooleanInput, getInput, InputOptions } from '@actions/core' | ||||
| import expandTilde from 'expand-tilde' | ||||
| import { RunInstall, parseRunInstall } from './run-install' | ||||
|  | ||||
| @@ -7,6 +7,7 @@ export interface Inputs { | ||||
|   readonly dest: string | ||||
|   readonly runInstall: RunInstall[] | ||||
|   readonly packageJsonFile: string | ||||
|   readonly standalone: boolean | ||||
| } | ||||
|  | ||||
| const options: InputOptions = { | ||||
| @@ -20,6 +21,7 @@ export const getInputs = (): Inputs => ({ | ||||
|   dest: parseInputPath('dest'), | ||||
|   runInstall: parseRunInstall('run_install'), | ||||
|   packageJsonFile: parseInputPath('package_json_file'), | ||||
|   standalone: getBooleanInput('standalone'), | ||||
| }) | ||||
|  | ||||
| export default getInputs | ||||
|   | ||||
| @@ -6,7 +6,7 @@ import { execPath } from 'process' | ||||
| import { Inputs } from '../inputs' | ||||
|  | ||||
| export async function runSelfInstaller(inputs: Inputs): Promise<number> { | ||||
|   const { version, dest, packageJsonFile } = inputs | ||||
|   const { version, dest, packageJsonFile, standalone } = inputs | ||||
|  | ||||
|   // prepare self install | ||||
|   await remove(dest) | ||||
| @@ -15,7 +15,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> { | ||||
|   await writeFile(pkgJson, JSON.stringify({ private: true })) | ||||
|  | ||||
|   // prepare target pnpm | ||||
|   const target = await readTarget(packageJsonFile, version) | ||||
|   const target = await readTarget({ version, packageJsonFile, standalone }) | ||||
|   const cp = spawn(execPath, [path.join(__dirname, 'pnpm.js'), 'install', target, '--no-lockfile'], { | ||||
|     cwd: dest, | ||||
|     stdio: ['pipe', 'inherit', 'inherit'], | ||||
| @@ -33,8 +33,14 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> { | ||||
|   return exitCode | ||||
| } | ||||
|  | ||||
| async function readTarget(packageJsonFile: string, version?: string | undefined) { | ||||
|   if (version) return `pnpm@${version}` | ||||
| async function readTarget(opts: { | ||||
|   readonly version?: string | undefined | ||||
|   readonly packageJsonFile: string | ||||
|   readonly standalone: boolean | ||||
| }) { | ||||
|   const { version, packageJsonFile, standalone } = opts | ||||
|  | ||||
|   if (version) return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}` | ||||
|  | ||||
|   const { GITHUB_WORKSPACE } = process.env | ||||
|   if (!GITHUB_WORKSPACE) { | ||||
| @@ -55,6 +61,11 @@ Please specify it by one of the following ways: | ||||
|   if (!packageManager.startsWith('pnpm@')) { | ||||
|     throw new Error('Invalid packageManager field in package.json') | ||||
|   } | ||||
|  | ||||
|   if(standalone){ | ||||
|     return packageManager.replace('pnpm@', '@pnpm/exe@') | ||||
|   } | ||||
|  | ||||
|   return packageManager | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user