diff --git a/builder/source/cache.ts b/builder/source/cache.ts index 766572a..396e2d1 100644 --- a/builder/source/cache.ts +++ b/builder/source/cache.ts @@ -1,10 +1,18 @@ import * as Zod from 'zod' import * as Fs from 'node:fs' import * as Process from 'node:process' +import * as Path from 'node:path' import { FetchAdShieldDomains } from './references/index.js' -const CachePath = (Process.env.INIT_CWD ? Process.env.INIT_CWD : Process.cwd()) + '/.buildcache' -const CacheDomainsPath = CachePath + '/domains.json' +const ProjectRoot = Path.resolve(Process.cwd()) +const EnvInitCwd = Process.env.INIT_CWD && Path.isAbsolute(Process.env.INIT_CWD) + ? Path.resolve(Process.env.INIT_CWD) + : null +const BaseCacheDir = (EnvInitCwd && (EnvInitCwd === ProjectRoot || EnvInitCwd.startsWith(ProjectRoot + Path.sep))) + ? EnvInitCwd + : ProjectRoot +const CachePath = Path.join(BaseCacheDir, '.buildcache') +const CacheDomainsPath = Path.join(CachePath, 'domains.json') export function CreateCache(Domains: Set) { if (!Fs.existsSync(CachePath)) {