From d278e78bddf957771f319214444100b4032fb7aa Mon Sep 17 00:00:00 2001 From: Jacob Gillespie Date: Wed, 14 Jul 2021 13:06:33 +0100 Subject: [PATCH] Add logic to check that cache folder exists --- src/cache-utils.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cache-utils.ts b/src/cache-utils.ts index e8f68951..cfe8c5b0 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -1,5 +1,8 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; type SupportedPackageManagers = { [prop: string]: PackageManagerInfo; @@ -19,7 +22,7 @@ export const supportedPackageManagers: SupportedPackageManagers = { pnpm: { lockFilePatterns: ['pnpm-lock.yaml'], getCacheFolderCommand: 'pnpm get store', - defaultCacheFolder: '~/.pnpm-store' + defaultCacheFolder: path.join(os.homedir(), '.pnpm-store') }, yarn1: { lockFilePatterns: ['yarn.lock'], @@ -95,5 +98,11 @@ export const getCacheDirectoryPath = async ( core.debug(`${packageManager} path is ${stdOut}`); + if (!fs.existsSync(stdOut)) { + throw new Error( + `Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${stdOut}` + ); + } + return stdOut; };