Files
Verso/services/web/frontend/macros/invalidate-babel-cache-if-needed.js
T
KristinaandCopybot d8df893593 [web] rm unnecessary webpack configuration (#33587)
GitOrigin-RevId: d9f305e59af2585db096a83c4cbd41ba5f785184
2026-05-14 08:05:39 +00:00

30 lines
1011 B
JavaScript

const fs = require('fs')
const Path = require('path')
const Settings = require('@overleaf/settings')
module.exports = function invalidateBabelCacheIfNeeded() {
const cacheDir = Path.join(__dirname, '../../node_modules/.cache')
const cachePath = Path.join(cacheDir, 'babel-loader')
const statePath = Path.join(cacheDir, 'last-overleafModuleImports.json')
let lastState = ''
try {
lastState = fs.readFileSync(statePath, { encoding: 'utf-8' })
} catch (e) {}
const newState = JSON.stringify(Settings.overleafModuleImports)
if (lastState !== newState) {
// eslint-disable-next-line no-console
console.warn(
'Detected change in overleafModuleImports, purging babel cache!'
)
// Gracefully handle cache mount in Server Pro build, only purge nested folder and keep .cache/ folder.
fs.mkdirSync(cacheDir, { recursive: true })
fs.rmSync(cachePath, {
recursive: true,
force: true,
maxRetries: 5,
})
fs.writeFileSync(statePath, newState)
}
}