diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1c163f7..5086b82 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -73,6 +73,41 @@ jobs: - name: 'Test: 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: name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})' diff --git a/dist/index.js b/dist/index.js index fa1f176..6a45aa2 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/src/install-pnpm/bootstrap/exe-lock.json b/src/install-pnpm/bootstrap/exe-lock.json new file mode 100644 index 0000000..c660a11 --- /dev/null +++ b/src/install-pnpm/bootstrap/exe-lock.json @@ -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" + } + } + } +} diff --git a/src/install-pnpm/run.ts b/src/install-pnpm/run.ts index e6c4464..90d24dd 100644 --- a/src/install-pnpm/run.ts +++ b/src/install-pnpm/run.ts @@ -7,20 +7,24 @@ import util from 'util' import { Inputs } from '../inputs' import { parse as parseYaml } from 'yaml' 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 { - const { version, dest, packageJsonFile } = inputs + const { version, dest, packageJsonFile, standalone } = inputs // Install bootstrap pnpm via npm (integrity verified by committed lockfile) await rm(dest, { recursive: true, force: true }) await mkdir(dest, { recursive: true }) - await writeFile(path.join(dest, 'package.json'), BOOTSTRAP_PACKAGE_JSON) - await writeFile(path.join(dest, 'package-lock.json'), JSON.stringify(pnpmLock)) + const lockfile = standalone ? exeLock : 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) { return npmExitCode } @@ -29,14 +33,17 @@ export async function runSelfInstaller(inputs: Inputs): Promise { addPath(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 const targetVersion = readTargetVersion({ version, packageJsonFile }) if (targetVersion) { - // Explicit version specified (via action input or packageManager field) - const exitCode = await runCommand(process.execPath, [bootstrapPnpm, 'self-update', targetVersion], { cwd: dest }) + const cmd = standalone ? bootstrapPnpm : process.execPath + const args = standalone ? ['self-update', targetVersion] : [bootstrapPnpm, 'self-update', targetVersion] + const exitCode = await runCommand(cmd, args, { cwd: dest }) if (exitCode !== 0) { return exitCode }