mirror of
https://code.forgejo.org/pnpm/action-setup.git
synced 2025-05-19 21:04:46 +00:00
feat: try support packageManager
This commit is contained in:
parent
ad2b35ae0c
commit
1d51e20937
6 changed files with 94 additions and 45 deletions
|
@ -3,7 +3,7 @@ import expandTilde from 'expand-tilde'
|
|||
import { RunInstall, parseRunInstall } from './run-install'
|
||||
|
||||
export interface Inputs {
|
||||
readonly version: string
|
||||
readonly version?: string
|
||||
readonly dest: string
|
||||
readonly runInstall: RunInstall[]
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ const options: InputOptions = {
|
|||
const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
||||
|
||||
export const getInputs = (): Inputs => ({
|
||||
version: getInput('version', options),
|
||||
version: getInput('version'),
|
||||
dest: parseInputPath('dest'),
|
||||
runInstall: parseRunInstall('run_install'),
|
||||
})
|
||||
|
|
|
@ -2,14 +2,28 @@ import { addPath, exportVariable } from '@actions/core'
|
|||
import { spawn } from 'child_process'
|
||||
import { execPath } from 'process'
|
||||
import path from 'path'
|
||||
import { remove, ensureFile, writeFile } from 'fs-extra'
|
||||
import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
|
||||
import fetch from '@pnpm/fetch'
|
||||
import { Inputs } from '../inputs'
|
||||
|
||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
const { version, dest } = inputs
|
||||
const target = version ? `pnpm@${version}` : 'pnpm'
|
||||
const pkgJson = path.join(dest, 'package.json')
|
||||
let target: string
|
||||
|
||||
if (!version) {
|
||||
const packageManager = JSON.parse(await readFile(pkgJson, 'utf8')).packageManager
|
||||
if (packageManager) {
|
||||
if (!packageManager.startsWith('pnpm@')) {
|
||||
throw new Error('packageManager field is not pnpm')
|
||||
}
|
||||
target = packageManager
|
||||
} else {
|
||||
throw new Error('None of packageManager (in package.json) or version (in action config) is defined')
|
||||
}
|
||||
} else {
|
||||
target = `pnpm@${version}`
|
||||
}
|
||||
|
||||
await remove(dest)
|
||||
await ensureFile(pkgJson)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue