Improve cache plugin API calls and improve logging#1858
Improve cache plugin API calls and improve logging#1858scottrigby wants to merge 1 commit intohelm:mainfrom
Conversation
- Correct cache.restore() and cache.save() to use proper signature (path, { key })
- Add console.log statements for all cache operations with [CACHE] prefix
- Accumulate all operation results for combined deploy summary display
- Log environment variables at start for debugging cache key generation
- Track restore/save success and errors with clear status indicators
This ensures the plugin follows Netlify's cache-utils API documentation and provides visibility into
cache operations during builds.
see:
- https://docs.netlify.com/extend/develop-and-share/develop-build-plugins/#plugin-methods
- https://github.com/netlify/build/blob/main/packages/cache-utils/README.md
Signed-off-by: Scott Rigby <scott@r6by.com>
2c1b6ce to
3d81ff0
Compare
There was a problem hiding this comment.
Pull request overview
This PR corrects the Netlify cache plugin API usage and significantly improves logging visibility. The changes align the plugin with Netlify's official cache-utils API documentation by fixing method signatures and add comprehensive console logging with a [CACHE] prefix to track all cache operations during builds.
Key changes:
- API Corrections: Fixed
cache.restore()andcache.save()to use the correct signature(path, { key })instead of the previous incorrect usage - Enhanced Logging: Added console.log statements for all cache operations with clear status indicators (✓, ✗, ⚠, ⊖) and accumulation of results for a combined deploy summary
- Better Debugging: Added environment variable logging at startup and per-directory processing logs to help debug cache key generation issues
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| console.log('[CACHE] Environment:', { | ||
| CACHE_VERSION: process.env.CACHE_VERSION, | ||
| CACHE_PER_BRANCH: process.env.CACHE_PER_BRANCH, | ||
| NETLIFY_BRANCH: process.env.NETLIFY_BRANCH | ||
| }); |
There was a problem hiding this comment.
The environment object is being logged directly to console.log, which will output "[object Object]" instead of the actual values. To properly display the environment variables, either use JSON.stringify() or log each variable separately.
| console.log('[CACHE] Environment:', { | |
| CACHE_VERSION: process.env.CACHE_VERSION, | |
| CACHE_PER_BRANCH: process.env.CACHE_PER_BRANCH, | |
| NETLIFY_BRANCH: process.env.NETLIFY_BRANCH | |
| }); | |
| console.log('[CACHE] Environment:', JSON.stringify({ | |
| CACHE_VERSION: process.env.CACHE_VERSION, | |
| CACHE_PER_BRANCH: process.env.CACHE_PER_BRANCH, | |
| NETLIFY_BRANCH: process.env.NETLIFY_BRANCH | |
| }, null, 2)); |
|
|
||
| async onPostBuild({ inputs, utils }) { | ||
| const results = []; | ||
| console.log('[CACHE] ========== Cache Save Starting =========='); |
There was a problem hiding this comment.
The onPostBuild function is missing the same environment variable logging that was added to onPreBuild. For consistency and debugging purposes, consider adding similar logging here to help track cache key generation during the save phase. This would help debug issues where save and restore operations might use different keys.
| console.log('[CACHE] ========== Cache Save Starting =========='); | |
| console.log('[CACHE] ========== Cache Save Starting =========='); | |
| console.log('[CACHE] Environment:', { | |
| CACHE_VERSION: process.env.CACHE_VERSION, | |
| CACHE_PER_BRANCH: process.env.CACHE_PER_BRANCH, | |
| NETLIFY_BRANCH: process.env.NETLIFY_BRANCH | |
| }); |
This ensures the plugin follows Netlify's cache-utils API documentation and provides visibility into cache operations during builds.
see: