Fix cache issue & crashing issue (#953)

Fixes #866
This commit is contained in:
Strencher 2021-07-26 00:09:18 +02:00 committed by GitHub
parent 87efffb7e8
commit 62f2f5d830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -96,12 +96,17 @@ export default class AddonManager {
// If this file already exists, give a warning and move on.
if (fs.existsSync(newFilename)) {
Logger.warn("AddonManager", `Duplicate files found: ${filename} and ${newFilename}`);
Logger.warn(this.name, `Duplicate files found: ${filename} and ${newFilename}`);
return;
}
// Rename the file and let it go on
fs.renameSync(absolutePath, path.resolve(this.addonFolder, newFilename));
try {
fs.renameSync(absolutePath, path.resolve(this.addonFolder, newFilename));
}
catch (error) {
Logger.err(this.name, `Could not rename file: ${filename} ${newFilename}`, error);
}
}
await new Promise(r => setTimeout(r, 100));
@ -200,9 +205,11 @@ export default class AddonManager {
loadAddon(filename, shouldToast = false) {
if (typeof(filename) === "undefined") return;
try {
delete __non_webpack_require__.cache[__non_webpack_require__.resolve(path.resolve(this.addonFolder, filename))];
__non_webpack_require__(path.resolve(this.addonFolder, filename));
}
catch (error) {
Logger.err(this.name, `Could not load ${path.basename(filename)}:`, error);
return new AddonError(filename, filename, Strings.Addons.compileError, {message: error.message, stack: error.stack}, this.prefix);
}