mirror of
https://github.com/pnpm/action-setup.git
synced 2026-05-01 09:52:51 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 26f6d4f2c5 |
Vendored
+33
-33
File diff suppressed because one or more lines are too long
+13
-2
@@ -29,7 +29,17 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
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'], { cwd: dest })
|
||||
// Prepend the action's node directory to PATH so npm's
|
||||
// `#!/usr/bin/env node` shebang resolves on runners (e.g. GHE
|
||||
// self-hosted) where node isn't already on PATH. npm itself is
|
||||
// resolved via PATH — on the GitHub Actions runner it is not
|
||||
// co-located with `process.execPath`.
|
||||
const nodeDir = path.dirname(process.execPath)
|
||||
// On Windows, the PATH key casing varies; search case-insensitively.
|
||||
const pathKey = Object.keys(process.env).find(k => k.toUpperCase() === 'PATH') ?? 'PATH'
|
||||
const currentPath = process.env[pathKey]
|
||||
const npmEnv = { ...process.env, [pathKey]: currentPath ? nodeDir + path.delimiter + currentPath : nodeDir }
|
||||
const npmExitCode = await runCommand('npm', ['ci'], { cwd: dest, env: npmEnv })
|
||||
if (npmExitCode !== 0) {
|
||||
return npmExitCode
|
||||
}
|
||||
@@ -155,10 +165,11 @@ function getSystemNodeVersion(): Promise<{ major: number; minor: number }> {
|
||||
})
|
||||
}
|
||||
|
||||
function runCommand(cmd: string, args: string[], opts: { cwd: string }): Promise<number> {
|
||||
function runCommand(cmd: string, args: string[], opts: { cwd: string; env?: Record<string, string | undefined> }): Promise<number> {
|
||||
return new Promise<number>((resolve, reject) => {
|
||||
const cp = spawn(cmd, args, {
|
||||
cwd: opts.cwd,
|
||||
env: opts.env,
|
||||
stdio: ['pipe', 'inherit', 'inherit'],
|
||||
shell: process.platform === 'win32',
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user