-
-
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
Unable to get TypeScript to compile, on grounds that it can't find type declarations for the worker #25
Comments
That's a very fast fix! Could I get you to re-publish to NPM please? (Would you like my auto-publish action?) |
Thank you, unfortunately I have a failing test on CI due to conflicting types in the |
Wow, that's gross. It seems like this is a web API whose type has actually genuinely changed. I think maybe trying to fix this with the version of TypeScript will leave you trapped, because TypeScript isn't wrong here, and you're just setting yourself up with a version of TypeScript that's already out of date. I wonder if you could change the type to be If not, I guess one awful thing you could do is compile two versions of the .d.ts, one for older and one for newer |
The frustrating thing is I'm not even using |
Can you just delete it from the If I knew how to build the library, I'd be trying to help, instead of just writing silly comments |
or, actually, can you generate once with the newer api that has the extra parameter, then manually edit the .d.ts and mark that parameter optional, maybe? |
I've fixed it with a0213df. v3.7.0 is out :) |
I think this signature isn't what you intended: declare let exports: (moduleOverrides?: EMCCModuleOverrides) => Promise<EMCCModuleOverrides> | Worker; I think you just want that to be Running your instructions now results in
I think the problem is that the You can fix this by just switching to the object destructuring syntax Alternately, you might try just manually narrowing that export to remove EMCCModuleOverrides? I don't actually know if that's legal or not |
import Viz from '@aduh95/viz.js';
import getWorker from "@aduh95/viz.js/worker";
function is_worker(w): w is Worker {
if ('postMessage' in w) { return true; }
return false;
}
let worker, viz;
async function setup() {
worker = await getWorker();
if (worker === undefined) { throw 'Worker undefined!'; }
if (!(is_worker(worker))) { throw 'Failed import!'; }
viz = new Viz({ worker });
(window as any).viz = viz;
}
setup();
|
OK, reopening since the issue is not fixed.
It can actually be one or the other depending if you are writing code for Node.js or not. On Node.js, you can use it to create the Lines 31 to 36 in a638079
On a web browser (or Deno), you have to create the web worker yourself – it's necessary as there's no reliable way to know where to look for the WASM file. In that context, the return type is Lines 109 to 131 in a638079
Then, since you mentioned Rollup, you can use import Viz from "@aduh95/viz.js";
import VizWorker from "worker-loader!./worker.js";
let viz
async function dot2svg(dot, options) {
viz ??= new Viz({ worker: new VizWorker });
return viz.renderString(dot, options);
} Unfortunately it looks like there's no easy way to tell TypeScript to generate two
Since this code uses |
Okay but worker throws as undefined, so whatever it is you're returning isn't being returned It's throwing here: if (worker === undefined) { throw 'Worker undefined!'; } |
I'm happy to experiment but at this time I still don't know how to build |
I'm returning whatever you're passing to the function. If you pass no parameters, you get |
Supporting both is a tough one, there are three ways to do that:
Option 2 is the easiest to setup, both for you and for your consumers, but it's arguably the worst one for the end-users. Choice is yours :) |
what do you mean by more bytes through the wire? would that end up with my embedding graphviz twice? it's several meg |
i don't really care about performance if by which you mean speed. it's extremely unlikely in my circumstances that you'll see even a hundred nodes in a given graph. this is for rendering state machines, and it's an auxiliary tool. exposing two files is not realistic in my circumstances if the size hit is like 5-10% that's fine, but if it's a doubling i don't think i can do that |
The brotlified size when using the WASM file is 313kiB, it goes to 400kiB when using ASM_JS (it's 128% the size of the WASM version).
No unless you do something wrong ;) |
okay, an 80k increase is tolerable
sir i will have you know that this is my specialty |
That's closer to 90k than 80k, but as long it works for you all is good. Closing now, as I think the original issue is solved. |
So, I tried to include the sync version. const vizRenderStringSync = require("@aduh95/viz.js/sync");
console.log(vizRenderStringSync("digraph{1 -> 2 }")); This gives me the fascinating and new
It's here: {{a=__dirname+"/"}o=()=>{if(!u){t=require("fs");u=require("path")}};n=function A(e,i){var r=Qi(e);if(r) It looks like it's trying to stub out some node stdlib modules. Assuming you're building using rollup, this may be useful |
hum the sync version is much more Node.js oriented, you'd have to jump a few hoops to make it work on the browser (in case you don't know After closer inspection, most of the Node.js specific code can be removed, the only thing you really need is a |
yeah, that's why i recommended that polyfill. it supports all node's stuff and patches or shims out all the relevant libs
okay, great. the above polyfill can do that, but if you removed everything but that, i'd think the feross buffer polyfill would probably be the better choice i'm a little surprised emscripten doesn't provide one |
@aduh95 - So I wasn't clear after reading this ticket on whether removing stuff from the repo so that it can be portable is a goal here Is this something you expect to do? Can I help? That's sort of a total blocker for me, and I would like to know if I should continue with this fork |
So there's a good chunk of Node.js specific code that can be removed from the To clarify, making the sync version compatible with browsers is not a goal (i.e. I don't intend to ship a |
Yeah, It's FredKSchott/rollup-plugin-polyfill-node. It's not actually part of rollup but it quasi-is. It's first-tier community, I guess.
I wish you would reconsider this. It seems like it would be very helpful for portability.
This is kind of the bottom line for me, is "can I get this working in both node and the browser" It's okay for me if I have to do some juggling to make it work, but I'm not willing to include two versions of the script, because NPM ranks people by binary size I had this working in both locations on mdaines' version for like four years. It's really frustrating not knowing what changed between old rollup and new rollup, that my old juggle doesn't work anymore. I was really hoping this fork was going to save me. |
So it's cool if I need to polyfill, but I don't know what to strip out of the node stuff, and that would involve basically me forking your product It wasn't clear from the way that was written if you were going to continue here. I still can't get Typescript to compile, despite that this issue is closed, is the thing. |
Right now, I'm trying to convert from
mdaines viz
to yours, because an unrelated thing forced my hand in upgrading rollup, and following that, my ability to import viz and my actual project at the same time, since one is es6 and the other homebrew UMD, kind of collapsed. I fought mdaines viz into working something like five years ago and it's been pretty copasetic since, but that truce failed with my recent rollup upgrade and I'm flailing for answers. I'm hoping that your alternative packaging in modern notations smooths things out.At the time of the fault, I'm trying to compile under
tsc
directly. It seems like your project is typescript, and as such that ought to work.take a quick look in the file, and
(Note: the relevant rollup module,
@rollup/plugin-node-resolve
, does in fact support #exports)Er. But I'm not even at bundling yet. I just copy pasted your readme instructions. The failing relevant line is the second line here:
My toolchain is the simple approach: take some ts, run
tsc
against it to write js to disk, in a build directory; afterwards, runrollup
against the js. So rollup hasn't even gotten started yet.So I looked in
dist
, and there's no obvious.d.ts
for this moduleLooked it up through package.json#exports, and it's a
.mjs
. This suggests that in order to use it I'm going to have to turnallowJs
on andcheckJs
off. Fortunately, I already had those on and off respectively, because of the peg parser.But still,
typescript
insists it can't see the types for the declarations. What that suggests to me is that maybe typescript can't find the #exports, and that's ... kind of a problem. I want it to be that I'm misunderstanding.I think maybe this might be fixable with a .d.ts though?
I don't really know what's going on here. I've never seen
package.json#exports
before, and it's worrying to rely on fundamentally new things like that, because oftentimes tools along the way are blind to itRepro
You can see the relevant code here, on line 3
You can see the outcome here in the github action context, or if you prefer, here in source context
The text was updated successfully, but these errors were encountered: