mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
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:
parent
d2f64811b5
commit
4a8a811cc1
4 changed files with 39 additions and 0 deletions
|
@ -2,6 +2,10 @@ const fs = require('fs')
|
||||||
const Path = require('path')
|
const Path = require('path')
|
||||||
const { merge } = require('@overleaf/settings/merge')
|
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 MODULES_PATH = Path.join(__dirname, '../modules')
|
||||||
const entryPointsIde = []
|
const entryPointsIde = []
|
||||||
const entryPointsMain = []
|
const entryPointsMain = []
|
||||||
|
@ -837,6 +841,9 @@ module.exports = {
|
||||||
|
|
||||||
overleafModuleImports: {
|
overleafModuleImports: {
|
||||||
// modules to import (an empty array for each set of modules)
|
// modules to import (an empty array for each set of modules)
|
||||||
|
//
|
||||||
|
// Restart webpack after making changes.
|
||||||
|
//
|
||||||
createFileModes: [],
|
createFileModes: [],
|
||||||
devToolbar: [],
|
devToolbar: [],
|
||||||
gitBridge: [],
|
gitBridge: [],
|
||||||
|
@ -863,6 +870,7 @@ module.exports = {
|
||||||
managedGroupSubscriptionEnrollmentNotification: [],
|
managedGroupSubscriptionEnrollmentNotification: [],
|
||||||
managedGroupEnrollmentInvite: [],
|
managedGroupEnrollmentInvite: [],
|
||||||
ssoConfigurationModal: [],
|
ssoConfigurationModal: [],
|
||||||
|
// See comment at the definition of these variables.
|
||||||
entryPointsIde,
|
entryPointsIde,
|
||||||
entryPointsMain,
|
entryPointsMain,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
const { createMacro, MacroError } = require('babel-plugin-macros')
|
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 Settings = require('@overleaf/settings')
|
||||||
|
|
||||||
const macro = createMacro(importOverleafModuleMacro)
|
const macro = createMacro(importOverleafModuleMacro)
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,10 @@ const {
|
||||||
} = require('./webpack-plugins/lezer-grammar-compiler')
|
} = require('./webpack-plugins/lezer-grammar-compiler')
|
||||||
|
|
||||||
const PackageVersions = require('./app/src/infrastructure/PackageVersions')
|
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
|
// Generate a hash of entry points, including modules
|
||||||
const entryPoints = {
|
const entryPoints = {
|
||||||
|
|
Loading…
Reference in a new issue