mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
26ee64fe62
* Replace `logger` with `console` in frontend macro logger import is causing problems cleaning node_modules/.cache after webpack builds. Since macros are used at build time we can use console statements. GitOrigin-RevId: 22bbbb34391334ec8f8ec256a3a8a72e5fe91588
23 lines
806 B
JavaScript
23 lines
806 B
JavaScript
const fs = require('fs')
|
|
const Path = require('path')
|
|
const Settings = require('@overleaf/settings')
|
|
|
|
module.exports = function invalidateBabelCacheIfNeeded() {
|
|
const cachePath = Path.join(__dirname, '../../node_modules/.cache')
|
|
const statePath = Path.join(cachePath, '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!'
|
|
)
|
|
fs.rmSync(cachePath, { recursive: true, force: true, maxRetries: 5 })
|
|
fs.mkdirSync(cachePath)
|
|
fs.writeFileSync(statePath, newState)
|
|
}
|
|
}
|