jk back to new function

This commit is contained in:
Zack Rauen 2022-06-29 18:47:36 -04:00
parent b7af7380b9
commit fd5afa06cf
1 changed files with 4 additions and 2 deletions

View File

@ -116,9 +116,11 @@ export default new class PluginManager extends AddonManager {
finalizeRequire(module, fileContent, meta) {
try {
// Test if the code is valid gracefully
vm.compileFunction(fileContent, ["require", "module", "exports", "__filename", "__dirname"]);
fileContent += normalizeExports(meta.exports || meta.name);
const compiled = `(${vm.compileFunction(fileContent, ["require", "module", "exports", "__filename", "__dirname"]).toString()})\n//# sourceURL=betterdiscord://plugins/${path.basename(module.filename)}`;
const wrappedPlugin = (0, eval)(compiled); // eslint-disable-line no-eval
fileContent += `\n//# sourceURL=betterdiscord://plugins/${path.basename(module.filename)}`;
const wrappedPlugin = new Function(["require", "module", "exports", "__filename", "__dirname"], fileContent); // eslint-disable-line no-new-func
wrappedPlugin(window.require, module, module.exports, module.filename, this.addonFolder);
meta.exports = module.exports;
module.exports = meta;