action-setup/src/pnpm-store-prune/index.ts

32 lines
701 B
TypeScript
Raw Normal View History

2020-05-09 21:50:47 +07:00
import { warning, startGroup, endGroup } from '@actions/core'
2022-02-23 10:07:15 +07:00
import { spawnSync } from 'child_process'
2020-05-09 21:15:50 +07:00
import { Inputs } from '../inputs'
2020-05-09 21:41:25 +07:00
import { patchPnpmEnv } from '../utils'
2020-05-09 21:15:50 +07:00
export function pruneStore(inputs: Inputs) {
if (inputs.runInstall.length === 0) {
console.log('Pruning is unnecessary.')
return
}
2020-05-09 21:50:47 +07:00
startGroup('Running pnpm store prune...')
2020-05-09 21:15:50 +07:00
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
stdio: 'inherit',
2020-05-09 21:41:25 +07:00
shell: true,
2022-02-23 10:07:15 +07:00
env: patchPnpmEnv(inputs),
2020-05-09 21:15:50 +07:00
})
2020-05-09 21:50:47 +07:00
endGroup()
2020-05-09 21:15:50 +07:00
if (error) {
2020-05-09 21:43:19 +07:00
warning(error)
2020-05-09 21:15:50 +07:00
return
}
if (status) {
2020-05-09 21:43:19 +07:00
warning(`command pnpm store prune exits with code ${status}`)
2020-05-09 21:15:50 +07:00
return
}
}
export default pruneStore