chore: simplify code for modules internally using remote.require in sandbox (#16104)

This commit is contained in:
Milan Burda 2018-12-17 20:47:41 +01:00 committed by Alexey Kuzmin
parent c64b4a3926
commit 7a6fe00f49
7 changed files with 8 additions and 49 deletions

View file

@ -91,13 +91,16 @@ Object.defineProperty(preloadProcess, 'noDeprecation', {
process.on('exit', () => preloadProcess.emit('exit'))
const { remoteRequire } = require('@electron/internal/renderer/remote')
// This is the `require` function that will be visible to the preload script
function preloadRequire (module) {
if (loadedModules.has(module)) {
return loadedModules.get(module)
}
if (remoteModules.has(module)) {
return require(module)
electron.deprecate.warn(`require('${module}')`, `remote.require('${module}')`)
return remoteRequire(module)
}
throw new Error('module not found')
}