-
Notifications
You must be signed in to change notification settings - Fork 525
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
d2js: Support Relative Imports #2382
Conversation
realised this might not quite fix #2301 - I'm not sure if they were asking for a more dynamic import e.g. you don't have to read the files from disk until d2 compile time I was having a think about approaches for this - I think we can pass callbacks from js to wasm. could potentially define something that implements the fs.FS interface that just calls some js callbacks to read from files, and this could be passed around instead. I don't think you would be able to pass custom callbacks (which would be especially useful in browser environments), due to all messages to webworkers being serialised this issue is likely relevant when people have a lot of/large d2 files, but would have a bigger impact on local bundling |
This just comes down to the API. In the CLI interface, we pass a real file system. In the JS interface, we pass a virtual filesystem of a string -> string map. If users want to load files at runtime, the interface would have to allow other types, like string -> callback map. We wouldn't actually implement reading the files from disk, that's for the user to do in their callback, we just need to accept that type. I can see both being useful. This PR solves imports for one of the use cases, but indeed not the one the issue is referring to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
yep got it - have got a proof of concept working for loading files at runtime using this approach. will raise a PR once it's ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, just a merge conflict from your other PR
that should be resolved now :) |
Adds support for relative imports for d2js
The main change is through adding
InputPath
toCompileRequest
. This allows for a custom path to be set for the entry point within the provided filesystem e.g.:Minor change of throwing any errors in the elk graph generation for easier debugging
I haven't added it to the
customizable.html
example - don't know how complex you want that example to get but I can add another text area and some input boxes for filenames if neededFixes #2301