SCRIPTS: Script modules are reused when they are imported (#461)

Also corrects some compile race conditions.
This commit is contained in:
Snarling
2023-04-07 00:33:51 -04:00
committed by GitHub
parent f5cddb6984
commit 04d49e3a6d
67 changed files with 428 additions and 561 deletions
+8 -14
View File
@@ -186,19 +186,14 @@ export abstract class BaseServer {
}
}
} else if (isScriptFilename(fn)) {
for (let i = 0; i < this.scripts.length; ++i) {
if (this.scripts[i].filename === fn) {
if (this.isRunning(fn)) {
return {
res: false,
msg: "Cannot delete a script that is currently running!",
};
}
this.scripts.splice(i, 1);
return { res: true };
}
const scriptIndex = this.scripts.findIndex((script) => script.filename === fn);
if (scriptIndex === -1) return { res: false, msg: `script ${fn} not found.` };
if (this.isRunning(fn)) {
return { res: false, msg: "Cannot delete a script that is currently running!" };
}
this.scripts[i].invalidateModule();
this.scripts.splice(i, 1);
return { res: true };
} else if (fn.endsWith(".lit")) {
for (let i = 0; i < this.messages.length; ++i) {
const f = this.messages[i];
@@ -273,8 +268,7 @@ export abstract class BaseServer {
const script = this.scripts[i];
script.code = code;
// Set ramUsage to null in order to force recalculation on next run
script.ramUsage = null;
script.markUpdated();
script.invalidateModule();
ret.overwritten = true;
ret.success = true;
return ret;