diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 74d867f6c..60d2e37fb 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -1453,6 +1453,11 @@ function NetscriptFunctions(workerScript) { if (scriptname == destServer.scripts[i].filename) { workerScript.log("scp", `WARNING: File '${scriptname}' overwritten on '${destServer.hostname}'`); const oldScript = destServer.scripts[i]; + // If it's the exact same file don't actually perform the + // copy to avoid recompiling uselessly. Players tend to scp + // liberally. + if(oldScript.code === sourceScript.code) + return true; oldScript.code = sourceScript.code; oldScript.ramUsage = sourceScript.ramUsage; oldScript.markUpdated(); diff --git a/src/NetscriptJSEvaluator.js b/src/NetscriptJSEvaluator.js index ba8d5f5c3..64352abc0 100644 --- a/src/NetscriptJSEvaluator.js +++ b/src/NetscriptJSEvaluator.js @@ -20,6 +20,7 @@ export async function executeJSScript(scripts = [], workerScript) { let urls = null; let script = workerScript.getScript(); if (shouldCompile(script, scripts)) { + console.log("recompiling"); // The URL at the top is the one we want to import. It will // recursively import all the other modules in the urlStack. // @@ -27,6 +28,7 @@ export async function executeJSScript(scripts = [], workerScript) { // but not really behaves like import. Particularly, it cannot // load fully dynamic content. So we hide the import from webpack // by placing it inside an eval call. + script.markUpdated(); urls = _getScriptUrls(script, scripts, []); script.url = urls[urls.length - 1].url; script.module = new Promise(resolve => resolve(eval('import(urls[urls.length - 1].url)'))); @@ -58,14 +60,15 @@ export async function executeJSScript(scripts = [], workerScript) { */ function shouldCompile(script, scripts) { if (script.module === "") return true; + console.log(script.dependencies); return script.dependencies.some(dep => { - const depScript = scripts.find(s => s.filename == dep.url); + const depScript = scripts.find(s => s.filename == dep.filename); // If the script is not present on the server, we should recompile, if only to get any necessary // compilation errors. if (!depScript) return true; - const depIsMoreRecent = depScript.moduleSequenceNumber > script.moduleSequenceNumber + const depIsMoreRecent = depScript.moduleSequenceNumber > script.moduleSequenceNumber; return depIsMoreRecent; }); }