Merge pull request #15957 from overleaf/jpa-invalidate-babel-cache

[web] after changing settings invalidate babel cache on webpack startup

GitOrigin-RevId: 3d83c56d119bcbbd91ea71b0a85ad8e0a767b679
This commit is contained in:
Eric Mc Sween 2024-01-04 07:31:13 -05:00 committed by Copybot
parent d2f64811b5
commit 4a8a811cc1
4 changed files with 39 additions and 0 deletions

View file

@ -2,6 +2,10 @@ const fs = require('fs')
const Path = require('path')
const { merge } = require('@overleaf/settings/merge')
// Automatically detect module imports that are included in this version of the application (SaaS, Server-CE, Server Pro).
// E.g. during a Server-CE build, we will not find imports for proprietary modules.
//
// Restart webpack after adding/removing modules.
const MODULES_PATH = Path.join(__dirname, '../modules')
const entryPointsIde = []
const entryPointsMain = []
@ -837,6 +841,9 @@ module.exports = {
overleafModuleImports: {
// modules to import (an empty array for each set of modules)
//
// Restart webpack after making changes.
//
createFileModes: [],
devToolbar: [],
gitBridge: [],
@ -863,6 +870,7 @@ module.exports = {
managedGroupSubscriptionEnrollmentNotification: [],
managedGroupEnrollmentInvite: [],
ssoConfigurationModal: [],
// See comment at the definition of these variables.
entryPointsIde,
entryPointsMain,
},

View file

@ -1,4 +1,7 @@
const { createMacro, MacroError } = require('babel-plugin-macros')
// This copy of the settings will be taken when webpack starts.
// Be sure to restart webpack after making changes to the settings.
const Settings = require('@overleaf/settings')
const macro = createMacro(importOverleafModuleMacro)

View file

@ -0,0 +1,24 @@
const fs = require('fs')
const Path = require('path')
const logger = require('@overleaf/logger')
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) {
logger.warn(
{},
'Detected change in overleafModuleImports, purging babel cache!'
)
fs.rmSync(cachePath, { recursive: true, force: true, maxRetries: 5 })
fs.mkdirSync(cachePath)
fs.writeFileSync(statePath, newState)
}
}

View file

@ -9,6 +9,10 @@ const {
} = require('./webpack-plugins/lezer-grammar-compiler')
const PackageVersions = require('./app/src/infrastructure/PackageVersions')
const invalidateBabelCacheIfNeeded = require('./frontend/macros/invalidate-babel-cache-if-needed')
// Make sure that babel-macros are re-evaluated after changing the modules config
invalidateBabelCacheIfNeeded()
// Generate a hash of entry points, including modules
const entryPoints = {