mirror of
https://github.com/pnpm/action-setup.git
synced 2026-03-18 00:06:14 +08:00
fix: ensure pnpm bin link exists after npm ci
npm ci sometimes doesn't create the .bin/pnpm symlink for @pnpm/exe (observed on Linux CI). Manually create the symlink if it's missing after npm ci completes. This fixes the case where standalone=true with no explicit version (relying on packageManager field) — pnpm self-update wouldn't run, leaving .bin empty and pnpm not found on PATH. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
232
dist/index.js
vendored
232
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
|||||||
import { addPath, exportVariable } from '@actions/core'
|
import { addPath, exportVariable } from '@actions/core'
|
||||||
import { spawn } from 'child_process'
|
import { spawn } from 'child_process'
|
||||||
import { rm, writeFile, mkdir } from 'fs/promises'
|
import { rm, writeFile, mkdir, symlink } from 'fs/promises'
|
||||||
import { readFileSync } from 'fs'
|
import { readFileSync, existsSync } from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import util from 'util'
|
import util from 'util'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
@@ -30,22 +30,17 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pnpmHome = path.join(dest, 'node_modules', '.bin')
|
const pnpmHome = path.join(dest, 'node_modules', '.bin')
|
||||||
console.log(`Adding to PATH: ${pnpmHome}`)
|
|
||||||
addPath(pnpmHome)
|
addPath(pnpmHome)
|
||||||
exportVariable('PNPM_HOME', pnpmHome)
|
exportVariable('PNPM_HOME', pnpmHome)
|
||||||
|
|
||||||
// Debug: list .bin contents
|
// Ensure pnpm bin link exists — npm ci sometimes doesn't create it
|
||||||
const { readdirSync, lstatSync } = await import('fs')
|
const pnpmBinLink = path.join(pnpmHome, 'pnpm')
|
||||||
try {
|
if (!existsSync(pnpmBinLink)) {
|
||||||
const bins = readdirSync(pnpmHome)
|
await mkdir(pnpmHome, { recursive: true })
|
||||||
console.log(`.bin contents: ${bins.join(', ')}`)
|
const target = standalone
|
||||||
for (const bin of bins) {
|
? path.join('..', '@pnpm', 'exe', 'pnpm')
|
||||||
const binPath = path.join(pnpmHome, bin)
|
: path.join('..', 'pnpm', 'bin', 'pnpm.cjs')
|
||||||
const stat = lstatSync(binPath)
|
await symlink(target, pnpmBinLink)
|
||||||
console.log(` ${bin}: symlink=${stat.isSymbolicLink()}, mode=${stat.mode.toString(8)}`)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log(`Failed to list .bin: ${e}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bootstrapPnpm = standalone
|
const bootstrapPnpm = standalone
|
||||||
|
|||||||
Reference in New Issue
Block a user