Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump source-map dependency #140

Open
BlueskyFR opened this issue Jul 21, 2020 · 6 comments
Open

Bump source-map dependency #140

BlueskyFR opened this issue Jul 21, 2020 · 6 comments

Comments

@BlueskyFR
Copy link

BlueskyFR commented Jul 21, 2020

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!

@pyrodogg
Copy link
Member

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.

@BlueskyFR
Copy link
Author

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.

@BlueskyFR
Copy link
Author

BlueskyFR commented Jul 24, 2020

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.

@BlueskyFR
Copy link
Author

@pyrodogg @resir014 Can you help?

@BlueskyFR
Copy link
Author

BlueskyFR commented Aug 16, 2020

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?

@pyrodogg
Copy link
Member

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.
mozilla/source-map#372
mozilla/source-map#339
mozilla/source-map#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants