UNPKG

756 BJavaScriptView Raw
1const { platform, env } = require('process')
2const { resolve } = require('path')
3
4const globalCacheDir = require('global-cache-dir')
5
6const isNetlifyCI = require('./utils/is-netlify-ci')
7
8// Retrieve the cache directory location
9const getCacheDir = function(cacheDir) {
10 if (cacheDir !== undefined) {
11 return resolve(cacheDir)
12 }
13
14 if (!isNetlifyCI()) {
15 return resolve(LOCAL_CACHE_DIR)
16 }
17
18 // Do not use in tests since /opt might not be writable by current user
19 if (platform === 'linux' && !env.NETLIFY_BUILD_TEST) {
20 return CI_CACHE_DIR
21 }
22
23 return globalCacheDir(PROJECT_NAME)
24}
25
26const LOCAL_CACHE_DIR = '.netlify/cache/'
27const CI_CACHE_DIR = '/opt/build/cache/'
28const PROJECT_NAME = 'netlify-build'
29
30module.exports = { getCacheDir }