samsam2310 / zbar.wasm

A wasm build of C/C++ ZBar barcode scanning library.
GNU Lesser General Public License v2.1
222 stars 30 forks source link

Deno compatibility #11

Closed jcs224 closed 2 years ago

jcs224 commented 2 years ago

I'd like to see if it would be possible to give guidance on how this library could be used with the Deno runtime. Deno is capable of running .wasm files and is focused on maintaining compatibility with web standards whenever possible.

Here's Deno's manual entry on WebAssembly.

https://deno.land/manual@v1.16.2/webassembly/using_wasm

Would this be feasible?

samsam2310 commented 2 years ago

I'm not familiar with how Deno load packages. I think we can add the support of Deno to provide the loader.

Currently, loading wasm is done by load.ts, and is overridden in the browser environment. This behavior is controlled by package.json, which I think is not supported in Deno.

samsam2310 commented 2 years ago

So what need to be done is making the load.ts work on both node.js and deno.

jcs224 commented 2 years ago

Thanks for looking into this!

I did make an attempt to get it working with Deno. Because Deno is browser-first I tried going the load-browser.ts route first. That was unsuccessful because while Deno has most of the JavaScript APIs of the browsers, it doesn't have DOM-related functionality (like document or, in this case, Image). There is also a node compatibility layer with Deno, that might be the route to take.

https://deno.land/manual@v1.16.2/npm_nodejs

The Deno Discord community is also quite helpful. The core Deno team also answers questions on occasion.

https://discord.gg/deno

jcs224 commented 2 years ago

Also, the files require using the whole path, so you have to include the file extension on every import. For example:

import { CppObject } from './CppObject.ts';
samsam2310 commented 2 years ago

After some surveying, I found that some patch need to be applied to make deno work.