diff --git a/package-lock.json b/package-lock.json index ff9965dc..ca91d6be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "turborepo-remote-cache", - "version": "1.6.6", + "version": "1.7.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "turborepo-remote-cache", - "version": "1.6.6", + "version": "1.7.0", "license": "MIT", "dependencies": { "@google-cloud/storage": "^6.4.1", diff --git a/src/env.ts b/src/env.ts index 5ac16a38..3c1d6ac4 100644 --- a/src/env.ts +++ b/src/env.ts @@ -24,7 +24,9 @@ const schema = Type.Object( STORAGE_PROVIDER: Type.Optional( Type.Enum(STORAGE_PROVIDERS, { default: STORAGE_PROVIDERS.LOCAL }), ), + BODY_LIMIT: Type.Number({ default: 104857600 }), STORAGE_PATH: Type.Optional(Type.String()), + STORAGE_PATH_USE_TMP_FOLDER: Type.Optional(Type.Boolean({ default: true })), // AWS_ env vars are used as aws-sdk defaults AWS_ACCESS_KEY_ID: Type.Optional(Type.String()), AWS_SECRET_ACCESS_KEY: Type.Optional(Type.String()), diff --git a/src/plugins/remote-cache/index.ts b/src/plugins/remote-cache/index.ts index fd62dfc0..edb28089 100644 --- a/src/plugins/remote-cache/index.ts +++ b/src/plugins/remote-cache/index.ts @@ -8,17 +8,12 @@ async function turboRemoteCache( instance: FastifyInstance, options: { allowedTokens: string[] - bodyLimit?: number apiVersion?: `v${number}` provider?: STORAGE_PROVIDERS }, ) { - const { - allowedTokens, - bodyLimit = 104857600, - apiVersion = 'v8', - provider = STORAGE_PROVIDERS.LOCAL, - } = options + const bodyLimit = instance.config.BODY_LIMIT ?? 104857600 + const { allowedTokens, apiVersion = 'v8', provider = STORAGE_PROVIDERS.LOCAL } = options if (!(Array.isArray(allowedTokens) && allowedTokens.length)) { throw new Error( `'allowedTokens' options must be a string[], ${typeof allowedTokens} provided instead`, @@ -58,6 +53,7 @@ async function turboRemoteCache( clientEmail: instance.config.GCS_CLIENT_EMAIL, privateKey: instance.config.GCS_PRIVATE_KEY, projectId: instance.config.GCS_PROJECT_ID, + useTmp: instance.config.STORAGE_PATH_USE_TMP_FOLDER ?? true, }), ) diff --git a/src/plugins/remote-cache/storage/index.ts b/src/plugins/remote-cache/storage/index.ts index 92925574..445ffa28 100644 --- a/src/plugins/remote-cache/storage/index.ts +++ b/src/plugins/remote-cache/storage/index.ts @@ -11,6 +11,7 @@ import { const pipeline = promisify(pipelineCallback) const TURBO_CACHE_FOLDER_NAME = 'turborepocache' as const +const TURBO_CACHE_USE_TMP_FOLDER = true as const type LocalOptions = Partial type S3Options = Omit & LocalOptions @@ -37,11 +38,11 @@ function createStorageLocation( provider: Provider, providerOptions: ProviderOptions, ): StorageProvider { - const { path = TURBO_CACHE_FOLDER_NAME } = providerOptions + const { path = TURBO_CACHE_FOLDER_NAME, useTmp = TURBO_CACHE_USE_TMP_FOLDER } = providerOptions switch (provider) { case STORAGE_PROVIDERS.LOCAL: { - return createLocal({ path }) + return createLocal({ path, useTmp }) } case STORAGE_PROVIDERS.S3: case STORAGE_PROVIDERS.s3: { diff --git a/src/plugins/remote-cache/storage/local.ts b/src/plugins/remote-cache/storage/local.ts index d830e4ad..9123bbc2 100644 --- a/src/plugins/remote-cache/storage/local.ts +++ b/src/plugins/remote-cache/storage/local.ts @@ -1,11 +1,13 @@ import { tmpdir } from 'os' -import { join } from 'path' +import { join, normalize } from 'path' import fs from 'fs-blob-store' export type LocalOptions = { path: string + useTmp: boolean } -export function createLocal({ path }: LocalOptions) { - return fs(join(tmpdir(), path)) +export function createLocal({ path, useTmp }: LocalOptions) { + const fullPath = useTmp ? join(tmpdir(), path) : normalize(path) + return fs(fullPath) }