-
-
Notifications
You must be signed in to change notification settings - Fork 8
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 request] Synchronous API #1
Comments
Hi!
I plan to maintain it and have started using it for my own projects. I haven't released a stable version yet because my fork is using some experimental Node.js features (ESM, worker_threads), I am waiting for them to land on LTS line.
Currently, the whole API is async indeed. I am not opposed to provide a sync version alongside though, I haven't came up with an elegant solution so far. Maybe something like that? import { renderStringSync } from '@aduh95/viz.js/sync'
renderStringSync("digraph{1 -> 2 }"); // <svg ...>
I don't see why not, but I don't have a sufficient knowledge of deasync. |
@christianvoigt do you want to have a look to the linked PR to check if my implementation fits your use-case? |
That's really great news! Thanks for the PR, I will test it and get back to you here. |
Ok, I tried to build the project after installing emscripten, but I get some errors when running grep: build-full/graphviz-2.45.20200410.2133/graphviz_version.h: No such file or directory There is only a I removed the line from the make file and tried it without it. That produced an error in the next line: /bin/sh: 1: ./configure: not found In both cases some files in the I am trying to do this under Windows, but using WSL2, so I have used apt-get to install all dependencies listed in the Readme except "qt", because I ran into some trouble installing it under Linux. Might that cause these problems? |
Thanks for your feedback, I am facing similar issues trying to setup GitHub Actions. I am going to try to update Emscripten version and switch to a stable release of Graphviz to see if the setup gets easier. Regarding the Dockerfile, since I'm not using it for development, I didn't take time to maintain and update it; I'm probably just gonna delete it for the time being. |
@christianvoigt You can use the GitHub Action script to help you set up your environment, otherwise you can use the build artefact of the attached PR to test locally. |
Thank you for your help! I can build the project now and have tested it for christianvoigt/argdown. The main issue currently is the use of subpath exports in the package.json file. Even though I have installed node v13.13.0 locally, Typescript is still not supporting this (see this issue). I simply changed the package.json to test the renderSync file. Apart from the subpath issue it works perfectly. Even if the subpath feature lands in LTS I think I can not use it in Argdown in the next half year or so. Argdown provides a VSCode plugin to its users. VSCode is based on Electron and Electron has just updated to Node v12.13.0 in version 8. VSCode is not even using Electron 8 yet, so it will take some time until Node v13 (or 14) arrives in VScode. A workaround would be to create a second package.json for older node versions as this might be a problem for other users as well. Otherwise, the only option I see right now is to fork your project and change the package.json to suit my needs (or even copy the source file directly into my project). What do you think? I think in the long run it will be great that this fork uses modern node features, but for now it makes it harder to switch. |
I have included a Lines 112 to 113 in 886efaa
But I forgot to add it to the |
I just realized that I could import const vizRenderStringSync = require("../../node_modules/@aduh95/viz.js/dist/renderSync.cjs"); So maybe the package.json does not have to change. This will not work using "import" (in typescript), though. How does the "sync" file in the root folder change that? At the moment I think I can not import it because it is missing a file extension (Typescript is not finding the module). If I change that to ".js" Typescript complains about a missing type declaration, so maybe it would work? I don't really get why including this file makes a difference from simply including "dist/renderSync.cjs" in the By the way, a test in the CI action failed after your change. |
ah, sorry for the confusion. I think I get it now. So you can simply use the extension-less "sync" file as a fallback for the package export, that's great! I did not know that. Once I realized this, I simply added declare module "@aduh95/viz.js/sync"; to my "types/index.d.ts" and now I can simply use: import vizRenderStringSync from "@aduh95/viz.js/sync"; This is great! Thank you for your effort! |
I just repeated my test using nvm in node v12.8.1 and node v10.20.1 and it works in both versions. |
@christianvoigt Thanks for your input, I have added a
Yep that's an issue on GH Actions actually, and the fix has already been merged so I won't bother fixing it on my side ;) |
I just checked and it now works without
I just realized you already released the beta version to npm.js. It would be great if you could release the sync-api as well so that I can release a new Argdown version based on your fork. From my point of view it would make sense to release viz.js officially even if worker-threads have not landed in lts, as the sync-api and the browser version do not depend on node worker threads and you have added fallbacks for the subpath exports. Maybe it would be helpful to mention the minimal required node version for the async usage in the Readme. |
I found another small Typescript issue: In line 1 in import type { RenderOptions } from "./types"; |
I'm planning on releasing a new beta version as soon as the PR is ready to be merged. I don't expect to make any other breaking changes to the sync API, so feel free to treat it as a Release Candidate.
Yep I should a tests for that kind of behaviour, thanks for the report. |
Hi, I just discovered your fork. Your Changelog sounds very promising. What are your plans for this fork? Are you planning to offer a constantly maintained alternative to the original version or is this intended as an experiment or a project for personal use only?
The demise of viz.js was really a shame for a lot of projects as the only other real alternative for hierarchical layouts (dagre) was also more or less abandoned and is still lacking a lot of important features. You would definitely do a lot of people a great service if you were willing to bring viz.js to life once more.
I was the author of the last unanswered issue in this project: mdaines#165
If I understand the Changelog correctly, in your version it will be even more difficult to use viz.js synchronously. I think that would be a mistake as there are contexts where asynchronous calls simply are not possible and performance is not so important. I have no experience with worker threads in node.js, but do you think it would at least be possible to use https://www.npmjs.com/package/deasync with them?
Anyhow, thanks for your work, I hope this was not too intrusive, I am just really enthusiastic about the prospect of someone maintaining a new viz.js after all this time.
The text was updated successfully, but these errors were encountered: