screeps-typescript-starter
screeps-typescript-starter copied to clipboard
Bump source-map dependency
Hi!
I am trying to locally upgrade the source-map dependency.
As of now, the following code is initializing it:
public static get consumer(): SourceMapConsumer {
if (this._consumer == null) {
this._consumer = new SourceMapConsumer(require("main.js.map"));
}
return this._consumer;
}
However, the new SourceMapConsumer now returns a promise, which makes the source-map parsing asynchronous.
The problem is that a getter cannot be async.
How can I handle this? I am considering doing a PR after I resolve this.
Thanks in advance for your help!
Referencing mozilla/source-map#331, I don't think it's possible to use versions higher than 0.6.1 which is what we're targeting.
Is there is some new feature of source-map that you really need, or are you just trying to run the latest version because it's newer?
It might be worth making your case for needing a sync version of the latest source-map on the referenced issue.
I am trying to upgrade the source-map dependency for many reasons, mainly because the dependencies of this project have not been updated for 2 to 3 years so I am basically trying to upgrade everything to increase the global stability and get the benefits of performance improvements. Using the async version of source-map can be really great because parsing a source-map requires a lot of computation compared to the other operations that a screeps script does, so doing it asynchronously can help I guess.
Is there is some new feature of source-map that you really need
So I would say that I "need" the performance improvements that have been made since the 0.6.1 version.
The async parsing is not a problem for me, which is different from the issue you referenced: I just need to figure out a clean way to handle it.
@pyrodogg @resir014 Can you help?
Referencing mozilla/source-map#331, I don't think it's possible to use versions higher than 0.6.1 which is what we're targeting.
@pyrodogg What is the problem to asynchronously throw errors?
The problem isn't inherently that it's an async library. Promises do exist and operate within the screeps game loop. The problem really comes from looking at why source-map is async.
// https://github.com/mozilla/source-map/blob/master/lib/read-wasm.js
const fs = require("fs");
const path = require("path");
module.exports = function readWasm() {
return new Promise((resolve, reject) => {
const wasmPath = path.join(__dirname, "mappings.wasm");
fs.readFile(wasmPath, null, (error, data) => {
if (error) {
reject(error);
return;
}
resolve(data.buffer);
});
});
};
It's async because it's reading the wasm module with fs.readFile, which isn't available in screeps.
There are other issues on that project that seems to point at working around it. https://github.com/mozilla/source-map/issues/372 https://github.com/mozilla/source-map/pull/339 https://github.com/mozilla/source-map/pull/369
It looks like node version of source-map needs a method to receive wasm as a synchronous parameter so that it could be loaded with require() and not rely on fs.