paulfitz / daff

align and compare tables
https://paulfitz.github.io/daff
MIT License
790 stars 68 forks source link

Error in daff.js for when running in Deno JavaScript runtime instead of NodeJS #160

Open shah opened 4 years ago

shah commented 4 years ago

@paulfitz this is a great library and seems to work in NodeJS. I'm trying to use bin/daff.js in Deno TypeScript and JavaScript runtime but am getting the following error:

> deno run -A bin/daff.js
error: Uncaught TypeError: Cannot read property 'Coopy' of undefined
    for (f in coopy.Coopy) { 
                    ^
    at file:///home/snshah/workspaces/github.com/paulfitz/daff/bin/daff.js:10607:21

This is probably a problem in the Haxe JS generator but other Haxe generated JS files seem to run in Deno's JavaScript runtime. Any thoughts?

Thanks!

paulfitz commented 4 years ago

I tried running deno run -A bin/daff.js and fixing up problems ad-hoc, just to assess how much was broken. There were a bunch of trivial problems - code for picking what global object (exports/windows/...) to put the library in was failing - hacking it to use self worked, I'd be interested to know how libraries should behave in deno. Then there were some syntax issues (missing "var" declarations) - easy. But then there were complaints about require is not defined (e.g. require('fs')) and I don't know what to replace that with. As a library, daff doesn't need requires, but as a console tool it does. I'd welcome any advice.

shah commented 4 years ago

Excellent sleuthing @paulfitz thanks for checking into this. Deno has its own fs module and cannot use the Node fs module so that might be tricky to fix (since, I suppose, Haxe is generating the require fs?). For the 'require' replacement, that's easy -- Deno supports EcmaScript imports.