feat: support standalone mode with @pnpm/exe bootstrap

- When standalone=true, bootstrap with @pnpm/exe via npm ci
- When standalone=false, bootstrap with pnpm via npm ci
- Both use pnpm self-update to reach the target version
- Remove --ignore-scripts from npm ci so @pnpm/exe install scripts run
- Add standalone test back to CI

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Zoltan Kochan
2026-03-16 02:29:31 +01:00
parent a722bd2d87
commit 0ffe724fa5
4 changed files with 319 additions and 130 deletions

View File

@@ -73,6 +73,41 @@ jobs:
- name: 'Test: version' - name: 'Test: version'
run: pnpm --version run: pnpm --version
test_standalone:
name: Test with standalone
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Run the action
uses: ./
with:
version: 9.15.0
standalone: true
- name: 'Test: which'
run: which pnpm
- name: 'Test: version'
run: pnpm --version
- name: 'Test: install in a fresh project'
run: |
mkdir /tmp/test-standalone
cd /tmp/test-standalone
pnpm init
pnpm add is-odd
shell: bash
test_run_install: test_run_install:
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})' name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'

244
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,147 @@
{
"name": "bootstrap-exe",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"@pnpm/exe": "10.32.1"
}
},
"node_modules/@pnpm/exe": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/exe/-/exe-10.32.1.tgz",
"integrity": "sha512-baEtwHeZwmZAdBuuDDL6tbdGg5KpxhPxr3QFfYTGXvY6ws+Z1bN0mQ7ZjcaXBSC1HuLpVXnZ6NsBiaZ2DMv4vg==",
"hasInstallScript": true,
"license": "MIT",
"bin": {
"pnpm": "pnpm"
},
"funding": {
"url": "https://opencollective.com/pnpm"
},
"optionalDependencies": {
"@pnpm/linux-arm64": "10.32.1",
"@pnpm/linux-x64": "10.32.1",
"@pnpm/macos-arm64": "10.32.1",
"@pnpm/macos-x64": "10.32.1",
"@pnpm/win-arm64": "10.32.1",
"@pnpm/win-x64": "10.32.1"
}
},
"node_modules/@pnpm/linux-arm64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/linux-arm64/-/linux-arm64-10.32.1.tgz",
"integrity": "sha512-6uB0B+XvunQwHGzIMk2JCkl4Ur6BtM4XbJSwB/mgpWmXDoX/KTJmgx2lodcTjgJSGSySCHfIVuTR9sj/F2D4EA==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"bin": {
"pnpm": "pnpm"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/linux-x64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/linux-x64/-/linux-x64-10.32.1.tgz",
"integrity": "sha512-AM2tv23Fg7h+nV+adqA/SkZKUysSIEetHfBwYFl8ArgdgkqbGoQy0rAOdKYQBb920CqfexXfI8OA8kPCzRxYng==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"bin": {
"pnpm": "pnpm"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/macos-arm64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/macos-arm64/-/macos-arm64-10.32.1.tgz",
"integrity": "sha512-Zr4JkhRbtGVsYgbuGZO0dq/6FPOn072Pdo0ubmqWtc14cUATKgAJD7efG03yqr3MLgtwFHgdtUzZ1WsaYAtUTA==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"bin": {
"pnpm": "pnpm"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/macos-x64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/macos-x64/-/macos-x64-10.32.1.tgz",
"integrity": "sha512-Yk6q3oFDu//OniXJxfTSHo+aew1LX81FcbzJAtEkcCeTQ0SLbQT6J3QiOMNikp8n8IjNhsy+bn2bdkUxaw+akA==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"bin": {
"pnpm": "pnpm"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/win-arm64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/win-arm64/-/win-arm64-10.32.1.tgz",
"integrity": "sha512-P8rsP5IUetpYjr2iwggoswL2qUukYrJoToXWuMyo8immn58CsYxaXsHVQ1Oq1R3XMfmGGWTXLsiJuQ7H991MRg==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"bin": {
"pnpm": "pnpm.exe"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/win-x64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/win-x64/-/win-x64-10.32.1.tgz",
"integrity": "sha512-i24GwbtBO8ojrhp8WWimX7NgZs0UKH1171oRt6qcRL+a+FxE0Eggv2y0KP7ZI7F3+LZMarwr3tnYsZryfciUOg==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"bin": {
"pnpm": "pnpm.exe"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
}
}
}

View File

@@ -7,20 +7,24 @@ import util from 'util'
import { Inputs } from '../inputs' import { Inputs } from '../inputs'
import { parse as parseYaml } from 'yaml' import { parse as parseYaml } from 'yaml'
import pnpmLock from './bootstrap/pnpm-lock.json' import pnpmLock from './bootstrap/pnpm-lock.json'
import exeLock from './bootstrap/exe-lock.json'
const BOOTSTRAP_PACKAGE_JSON = JSON.stringify({ private: true, dependencies: { pnpm: pnpmLock.packages['node_modules/pnpm'].version } }) const BOOTSTRAP_PNPM_PACKAGE_JSON = JSON.stringify({ private: true, dependencies: { pnpm: pnpmLock.packages['node_modules/pnpm'].version } })
const BOOTSTRAP_EXE_PACKAGE_JSON = JSON.stringify({ private: true, dependencies: { '@pnpm/exe': exeLock.packages['node_modules/@pnpm/exe'].version } })
export async function runSelfInstaller(inputs: Inputs): Promise<number> { export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const { version, dest, packageJsonFile } = inputs const { version, dest, packageJsonFile, standalone } = inputs
// Install bootstrap pnpm via npm (integrity verified by committed lockfile) // Install bootstrap pnpm via npm (integrity verified by committed lockfile)
await rm(dest, { recursive: true, force: true }) await rm(dest, { recursive: true, force: true })
await mkdir(dest, { recursive: true }) await mkdir(dest, { recursive: true })
await writeFile(path.join(dest, 'package.json'), BOOTSTRAP_PACKAGE_JSON) const lockfile = standalone ? exeLock : pnpmLock
await writeFile(path.join(dest, 'package-lock.json'), JSON.stringify(pnpmLock)) const packageJson = standalone ? BOOTSTRAP_EXE_PACKAGE_JSON : BOOTSTRAP_PNPM_PACKAGE_JSON
await writeFile(path.join(dest, 'package.json'), packageJson)
await writeFile(path.join(dest, 'package-lock.json'), JSON.stringify(lockfile))
const npmExitCode = await runCommand('npm', ['ci', '--ignore-scripts'], { cwd: dest }) const npmExitCode = await runCommand('npm', ['ci'], { cwd: dest })
if (npmExitCode !== 0) { if (npmExitCode !== 0) {
return npmExitCode return npmExitCode
} }
@@ -29,14 +33,17 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
addPath(pnpmHome) addPath(pnpmHome)
exportVariable('PNPM_HOME', pnpmHome) exportVariable('PNPM_HOME', pnpmHome)
const bootstrapPnpm = path.join(dest, 'node_modules', 'pnpm', 'bin', 'pnpm.cjs') const bootstrapPnpm = standalone
? path.join(dest, 'node_modules', '@pnpm', 'exe', 'pnpm')
: path.join(dest, 'node_modules', 'pnpm', 'bin', 'pnpm.cjs')
// Determine the target version // Determine the target version
const targetVersion = readTargetVersion({ version, packageJsonFile }) const targetVersion = readTargetVersion({ version, packageJsonFile })
if (targetVersion) { if (targetVersion) {
// Explicit version specified (via action input or packageManager field) const cmd = standalone ? bootstrapPnpm : process.execPath
const exitCode = await runCommand(process.execPath, [bootstrapPnpm, 'self-update', targetVersion], { cwd: dest }) const args = standalone ? ['self-update', targetVersion] : [bootstrapPnpm, 'self-update', targetVersion]
const exitCode = await runCommand(cmd, args, { cwd: dest })
if (exitCode !== 0) { if (exitCode !== 0) {
return exitCode return exitCode
} }