mirror of
https://code.forgejo.org/pnpm/action-setup.git
synced 2025-05-18 12:34:46 +00:00
Use pnpm.js to install pnpm
This commit is contained in:
parent
b7b9d6344b
commit
aefcd1e623
12 changed files with 64 additions and 37 deletions
|
@ -5,8 +5,6 @@ import { RunInstall, parseRunInstall } from './run-install'
|
|||
export interface Inputs {
|
||||
readonly version: string
|
||||
readonly dest: string
|
||||
readonly binDest: string
|
||||
readonly registry: string
|
||||
readonly runInstall: RunInstall[]
|
||||
}
|
||||
|
||||
|
@ -19,8 +17,6 @@ const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
|||
export const getInputs = (): Inputs => ({
|
||||
version: getInput('version', options),
|
||||
dest: parseInputPath('dest'),
|
||||
binDest: parseInputPath('bin_dest'),
|
||||
registry: getInput('registry', options),
|
||||
runInstall: parseRunInstall('run_install'),
|
||||
})
|
||||
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
import { spawn } from 'child_process'
|
||||
import { execPath } from 'process'
|
||||
import { downloadSelfInstaller } from '../self-installer'
|
||||
import { join } from 'path'
|
||||
import { remove, ensureFile, writeFile } from 'fs-extra'
|
||||
import fetch from 'node-fetch'
|
||||
import { Inputs } from '../inputs'
|
||||
|
||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
const cp = spawn(execPath, {
|
||||
env: {
|
||||
PNPM_VERSION: inputs.version,
|
||||
PNPM_DEST: inputs.dest,
|
||||
PNPM_BIN_DEST: inputs.binDest,
|
||||
PNPM_REGISTRY: inputs.registry,
|
||||
},
|
||||
const { version, dest } = inputs
|
||||
const target = version ? `pnpm@${version}` : 'pnpm'
|
||||
const pkgJson = join(dest, 'package.json')
|
||||
|
||||
await remove(dest)
|
||||
await ensureFile(pkgJson)
|
||||
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
||||
|
||||
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
|
||||
stdio: ['pipe', 'inherit', 'inherit'],
|
||||
})
|
||||
|
||||
const response = await downloadSelfInstaller()
|
||||
const response = await fetch('https://pnpm.js.org/pnpm.js')
|
||||
response.body.pipe(cp.stdin)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import { setOutput, addPath } from '@actions/core'
|
||||
import { Inputs } from '../inputs'
|
||||
import { getBinDest } from '../utils'
|
||||
|
||||
export function setOutputs(inputs: Inputs) {
|
||||
addPath(inputs.binDest)
|
||||
const binDest = getBinDest(inputs)
|
||||
addPath(binDest)
|
||||
setOutput('dest', inputs.dest)
|
||||
setOutput('bin_dest', inputs.binDest)
|
||||
setOutput('bin_dest', binDest)
|
||||
}
|
||||
|
||||
export default setOutputs
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
import fetch from 'node-fetch'
|
||||
import url from './url'
|
||||
export const downloadSelfInstaller = () => fetch(url)
|
||||
export default downloadSelfInstaller
|
|
@ -1,2 +0,0 @@
|
|||
export * from './url'
|
||||
export * from './download'
|
|
@ -1,3 +0,0 @@
|
|||
export const ref = '301414cec74a2b6b63c95b42f2ad1790ccb980ed'
|
||||
export const url = `https://raw.githubusercontent.com/pnpm/self-installer/${ref}/install.js`
|
||||
export default url
|
|
@ -2,7 +2,9 @@ import process from 'process'
|
|||
import path from 'path'
|
||||
import { Inputs } from '../inputs'
|
||||
|
||||
export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')
|
||||
|
||||
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
|
||||
...process.env,
|
||||
PATH: inputs.binDest + path.delimiter + process.env.PATH
|
||||
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue