-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
Feature: Synchronous API #1026
Comments
For anyone who needs this, I've published a very hacky sync version of Terser. It monkey-patches Terser in horrible ways to achieve this, and will probably break in future, so would be much better to implement in Terser itself, but seems to work for now... |
Hey there! I empathise with this pain point quite a bit. I hate it when I need to call something async and I have to rework an entire thing to achieve it, even if it's just a few files. I've had to deal with this async issue myself in Terser's functional tests. However, there was a point in making Terser async, even beyond source maps. You could say it was "prematurely async'd". I've been planning to augment it with rust at some point or another. This isn't visible because this project moves really slowly, as I don't often find myself with time to look at issues or improve the project. |
It sort of ties into SWC. Eventually I'd like for people to be able to drop this project, and use something way faster and more correct. |
Bug report or Feature request?
Feature request.
Description
For some use cases, it'd be useful to run Terser synchronously.
My particular case is a Javascript serializer Livepack. It has a synchronous API, and I'd like to pass the output through Terser, without having to move the whole library to an async API.
As far as I can see, the only element of Terser which currently requires async is the use of source-map. Therefore, it would not be too difficult to add a
minifySync()
method which uses source-map 0.5.7, whileminify()
continues to use the latest source-map, and leave the rest of Terser unchanged.Simplest implementation would probably be to use gensync, but if you'd prefer not to add a dependency, it wouldn't be too hard to write some custom branching logic instead.
The solution suggested in #385 (comment) - for user to wrap Terser in deasync - no longer looks workable. deasync appears to be unmaintained and has major bugs on versions of Node >= 12. Personally, I would also prefer not to include a native dependency in my library if I can avoid it.
I would be very happy to implement
minifySync()
and submit a PR, if you'd be willing to receive it.The text was updated successfully, but these errors were encountered: