mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-27 01:53:48 +01:00
Fix script needlessly being recompiled (#932)
* Fix nsjs recompiling needlesly.
This commit is contained in:
parent
5613d371c9
commit
3cbf225c98
@ -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();
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user