From 8445067ef08495ac206b5f0c1efc4de068c56cfd Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 9 Feb 2025 10:43:35 +0800 Subject: [PATCH] feat(cache): add experimental cache logging --- packages/core/src/plugins/cache.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/core/src/plugins/cache.ts b/packages/core/src/plugins/cache.ts index cc7faca0d9..7cb81e7ad6 100644 --- a/packages/core/src/plugins/cache.ts +++ b/packages/core/src/plugins/cache.ts @@ -1,7 +1,7 @@ import crypto from 'node:crypto'; import fs from 'node:fs'; import { isAbsolute, join } from 'node:path'; -import { findExists, isFileExists } from '../helpers'; +import { color, findExists, isFileExists } from '../helpers'; import { logger } from '../logger'; import type { BuildCacheOptions, @@ -111,6 +111,8 @@ export const pluginCache = (): RsbuildPlugin => ({ name: 'rsbuild:cache', setup(api) { + let cacheEnabled = false; + api.modifyBundlerChain(async (chain, { environment, env }) => { const { config } = environment; const { bundlerType } = api.context; @@ -124,6 +126,8 @@ export const pluginCache = (): RsbuildPlugin => ({ return; } + cacheEnabled = true; + const { context } = api; const cacheConfig = typeof buildCache === 'boolean' ? {} : buildCache; const cacheDirectory = getCacheDirectory(cacheConfig, context); @@ -166,5 +170,14 @@ export const pluginCache = (): RsbuildPlugin => ({ }); } }); + + api.onAfterCreateCompiler(() => { + // Tell user that the cache is enabled and it's experimental + if (cacheEnabled && api.context.bundlerType === 'rspack') { + logger.info( + `Rspack persistent cache enabled ${color.dim('(experimental)')}`, + ); + } + }); }, });