mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-05 07:09:02 +02:00
db70d2db25
GitOrigin-RevId: 5d97ad59748560fd48b21e6e83e118d10362dac4
30 lines
1011 B
JavaScript
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)
|
|
}
|
|
}
|