hpq icon indicating copy to clipboard operation
hpq copied to clipboard

parse doesn't work with Node.js

Open gziolo opened this issue 4 years ago • 4 comments

The current implementation depends on browser APIs like createHTMLDocument, querySelector, querySelectorAll. It's not possible to use this library with Node.js or React Native.

It would be possible to simulate DOM using jsdom as explored in https://github.com/gziolo/hpq/pull/1.

In ReactNative, you miss some Node.js APIs so you can't use the full implementation of jsdom. That's why I tried to use the smallest possible subset of the library.

gziolo avatar Sep 12 '19 11:09 gziolo

Hi!

I think this makes sense. As you alluded in https://github.com/gziolo/hpq/pull/1#issuecomment-530793003, I'm curious about the impact on the browser distributed bundle (i.e. can we ensure the built code only includes the relevant code path).

I was thinking about the impact on testing too, but since we basically rely on JSDOM as the "native" implementation for tests, I don't think there's anything we can / should need to do there.

aduth avatar Sep 18 '19 17:09 aduth

I'll figure out how to do it but it looks like doable with Rollup 👍

I'd be nice to land https://github.com/aduth/hpq/pull/5 first which updates npm dependencies. Well, maybe it will be a good idea to pin jsdom to one version since we are going to use functionality based on the folder structure which isn't enforced by the public API.

gziolo avatar Sep 19 '19 09:09 gziolo

I'd be nice to land #5 first which updates npm dependencies.

Yep, done.

aduth avatar Sep 19 '19 15:09 aduth

Awesome, thanks. I'll rebase and continue my exploration next week 👍

gziolo avatar Sep 19 '19 15:09 gziolo