mirror of
https://github.com/pnpm/action-setup.git
synced 2026-11-03 20:40:57 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cfce9a7a7 | ||
|
|
c5f96a3b3f |
@@ -73,6 +73,9 @@ jobs:
|
|||||||
set -e
|
set -e
|
||||||
which pnpm
|
which pnpm
|
||||||
which pnpx
|
which pnpx
|
||||||
|
case "$PNPM_HOME" in
|
||||||
|
''|*node_modules*) echo "PNPM_HOME must be set outside node_modules"; exit 1 ;;
|
||||||
|
esac
|
||||||
actual="$(pnpm --version)"
|
actual="$(pnpm --version)"
|
||||||
echo "pnpm --version: ${actual}"
|
echo "pnpm --version: ${actual}"
|
||||||
if [ "${actual}" != "${REQUIRED}" ]; then
|
if [ "${actual}" != "${REQUIRED}" ]; then
|
||||||
@@ -422,45 +425,3 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
windows_dest_spaces:
|
|
||||||
name: 'Windows destination with spaces (${{ matrix.version }} / standalone=${{ matrix.standalone }})'
|
|
||||||
runs-on: windows-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- version: '10.33.0'
|
|
||||||
standalone: false
|
|
||||||
- version: '11.25.0'
|
|
||||||
standalone: true
|
|
||||||
- version: '12.3.4'
|
|
||||||
standalone: false
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
||||||
- id: pnpm
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
version: ${{ matrix.version }}
|
|
||||||
standalone: ${{ matrix.standalone }}
|
|
||||||
dest: '${{ runner.temp }}/pnpm setup & tools'
|
|
||||||
- name: Verify PowerShell and bin_dest use the requested version
|
|
||||||
shell: pwsh
|
|
||||||
env:
|
|
||||||
EXPECTED_VERSION: ${{ matrix.version }}
|
|
||||||
BIN_DEST: ${{ steps.pnpm.outputs.bin_dest }}
|
|
||||||
run: |
|
|
||||||
$actual = pnpm --version
|
|
||||||
if ($LASTEXITCODE -ne 0 -or $actual -ne $env:EXPECTED_VERSION) {
|
|
||||||
throw "Expected $env:EXPECTED_VERSION on PATH, got $actual"
|
|
||||||
}
|
|
||||||
$command = Get-Command pnpm
|
|
||||||
$executable = Join-Path $env:BIN_DEST $command.Name
|
|
||||||
$actual = & $executable --version
|
|
||||||
if ($LASTEXITCODE -ne 0 -or $actual -ne $env:EXPECTED_VERSION) {
|
|
||||||
throw "Expected $env:EXPECTED_VERSION via bin_dest, got $actual"
|
|
||||||
}
|
|
||||||
$pnpx = Get-Command pnpx -ErrorAction Stop
|
|
||||||
if ((Split-Path -Parent $pnpx.Source) -ne $env:BIN_DEST) {
|
|
||||||
throw "pnpx resolves to $($pnpx.Source), expected under $env:BIN_DEST"
|
|
||||||
}
|
|
||||||
|
|||||||
Vendored
+136
-136
File diff suppressed because one or more lines are too long
+16
-22
@@ -1,5 +1,4 @@
|
|||||||
import { addPath, exportVariable } from '@actions/core'
|
import { addPath, exportVariable } from '@actions/core'
|
||||||
import { exec } from '@actions/exec'
|
|
||||||
import { spawn } from 'child_process'
|
import { spawn } from 'child_process'
|
||||||
import { rm, writeFile, mkdir, symlink } from 'fs/promises'
|
import { rm, writeFile, mkdir, symlink } from 'fs/promises'
|
||||||
import { readFileSync, existsSync } from 'fs'
|
import { readFileSync, existsSync } from 'fs'
|
||||||
@@ -73,14 +72,12 @@ export async function runSelfInstaller(inputs: Inputs): Promise<SelfInstallerRes
|
|||||||
return { exitCode: npmExitCode, binDest: path.join(dest, 'node_modules', '.bin') }
|
return { exitCode: npmExitCode, binDest: path.join(dest, 'node_modules', '.bin') }
|
||||||
}
|
}
|
||||||
|
|
||||||
const pnpmHome = standalone && process.platform === 'win32'
|
const bootstrapBinDir = standalone && process.platform === 'win32'
|
||||||
? path.join(dest, 'node_modules', '@pnpm', 'exe')
|
? path.join(dest, 'node_modules', '@pnpm', 'exe')
|
||||||
: path.join(dest, 'node_modules', '.bin')
|
: path.join(dest, 'node_modules', '.bin')
|
||||||
// PNPM_HOME/bin is where `pnpm self-update` places the target version
|
const pnpmHome = path.join(dest, 'pnpm-home')
|
||||||
// binary. It must have higher PATH precedence than pnpmHome (which
|
await mkdir(pnpmHome, { recursive: true })
|
||||||
// contains the bootstrap binary) so the self-updated version is found
|
addPath(bootstrapBinDir)
|
||||||
// first. The bootstrap pnpm is invoked via absolute path, not PATH,
|
|
||||||
// so this ordering does not affect the bootstrap step.
|
|
||||||
addPath(pnpmHome)
|
addPath(pnpmHome)
|
||||||
addPath(path.join(pnpmHome, 'bin'))
|
addPath(path.join(pnpmHome, 'bin'))
|
||||||
exportVariable('PNPM_HOME', pnpmHome)
|
exportVariable('PNPM_HOME', pnpmHome)
|
||||||
@@ -107,25 +104,17 @@ export async function runSelfInstaller(inputs: Inputs): Promise<SelfInstallerRes
|
|||||||
const bootstrapVersion = native ? bootstrapNativeVersion : standalone ? bootstrapExeVersion : bootstrapPnpmVersion
|
const bootstrapVersion = native ? bootstrapNativeVersion : standalone ? bootstrapExeVersion : bootstrapPnpmVersion
|
||||||
|
|
||||||
if (targetVersion === bootstrapVersion || (native && satisfies(bootstrapVersion, targetVersion))) {
|
if (targetVersion === bootstrapVersion || (native && satisfies(bootstrapVersion, targetVersion))) {
|
||||||
return { exitCode: 0, binDest: pnpmHome }
|
return { exitCode: 0, binDest: bootstrapBinDir }
|
||||||
}
|
}
|
||||||
|
|
||||||
const cmd = native || standalone ? bootstrapPnpm : process.execPath
|
const cmd = native || standalone ? bootstrapPnpm : process.execPath
|
||||||
const args = native || standalone ? ['self-update', targetVersion] : [bootstrapPnpm, 'self-update', targetVersion]
|
const args = native || standalone ? ['self-update', targetVersion] : [bootstrapPnpm, 'self-update', targetVersion]
|
||||||
const exitCode = await runCommand(cmd, args, { cwd: dest })
|
const exitCode = await runCommand(cmd, args, { cwd: dest })
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
return { exitCode, binDest: pnpmHome }
|
return { exitCode, binDest: bootstrapBinDir }
|
||||||
}
|
}
|
||||||
// self-update writes the target pnpm/pnpx into PNPM_HOME/bin, leaving
|
|
||||||
// the bootstrap symlinks in pnpmHome pointing at the old version. Use
|
|
||||||
// PNPM_HOME/bin so consumers of the bin_dest output (e.g.
|
|
||||||
// `${steps.pnpm.outputs.bin_dest}/pnpm`) invoke the requested version.
|
|
||||||
//
|
|
||||||
// When the requested version resolves to the bootstrap version, self-update
|
|
||||||
// is a no-op and PNPM_HOME/bin is not created — fall back to pnpmHome,
|
|
||||||
// whose symlinks already point at the right version.
|
|
||||||
const updatedBinDir = path.join(pnpmHome, 'bin')
|
const updatedBinDir = path.join(pnpmHome, 'bin')
|
||||||
return { exitCode: 0, binDest: existsSync(updatedBinDir) ? updatedBinDir : pnpmHome }
|
return { exitCode: 0, binDest: existsSync(updatedBinDir) ? updatedBinDir : bootstrapBinDir }
|
||||||
}
|
}
|
||||||
|
|
||||||
function readTargetVersion(opts: {
|
function readTargetVersion(opts: {
|
||||||
@@ -222,10 +211,15 @@ function getSystemNodeVersion(): Promise<{ major: number; minor: number }> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function runCommand(cmd: string, args: string[], opts: { cwd: string; env?: Record<string, string | undefined> }): Promise<number> {
|
function runCommand(cmd: string, args: string[], opts: { cwd: string; env?: Record<string, string | undefined> }): Promise<number> {
|
||||||
return exec(`"${cmd}"`, args, {
|
return new Promise<number>((resolve, reject) => {
|
||||||
cwd: opts.cwd,
|
const cp = spawn(cmd, args, {
|
||||||
env: opts.env && Object.fromEntries(Object.entries(opts.env).filter((entry): entry is [string, string] => entry[1] !== undefined)),
|
cwd: opts.cwd,
|
||||||
ignoreReturnCode: true,
|
env: opts.env,
|
||||||
|
stdio: ['pipe', 'inherit', 'inherit'],
|
||||||
|
shell: process.platform === 'win32',
|
||||||
|
})
|
||||||
|
cp.on('error', reject)
|
||||||
|
cp.on('close', resolve)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user