jacoscaz / quadstore

A LevelDB-backed graph database for JS runtimes (Node.js, Deno, browsers, ...) supporting SPARQL queries and the RDF/JS interface.
https://github.com/jacoscaz/quadstore
MIT License
197 stars 14 forks source link

ES Module support #138

Closed ProvocaTeach closed 2 years ago

ProvocaTeach commented 3 years ago

The other day I was looking at Quadstore’s page on Skypack and noticed there were a few missing checks. Namely, the package lacks an ES module entry point and an export map.

Are there any plans to adapt Quadstore to the ES module ecosystem? Browser support is intended to be baked in, and this would help cut out the Webpack/Browserify middleman. Node supports ES modules now, while Deno is becoming ever more popular.

jacoscaz commented 3 years ago

Hello @ProvocaTeach! Yes, quadstore will eventually be adapted to the ES module ecosystem. In fact, these used to be an open issue to track that: https://github.com/beautifulinteractions/node-quadstore/issues/97 .

However, as of the last time I checked, native support for ES module made little sense as our dependencies were still based on the CommonJS module spec, thus forcing the use of one such middleman anyway.

That said, I haven't reviewed the situation recently and something might have changed in the meantime. I also haven't had a chance to play with Deno, yet. What is your use case?

ProvocaTeach commented 3 years ago

Ah, makes sense. I am a lover of the Semantic Web, and I was hoping to build a basic website with a custom CMS on top of Quadstore. It could probably be done with Node, but I am more familiar with the ES module ecosystem (as a relative newcomer to JS).

Deno is nice because there is little package management; you just import a JavaScript file directly from a URI, and it caches the module (much like a browser would). Package management is handled by the ES module system, without the need for NPM or package.json.

I was trying to get Quadstore to work on Deno using Skypack – a CDN that makes the NPM registry available as ES modules. Many Node packages work out-of-the-box from Skypack, but I think the level library relies on some Node-specific code, because I wasn’t able to get it to work.

This is a personal project I’m doing just to learn about RDF and JavaScript. I initially chose Deno because I’m very big on future-proof knowledge… but maybe I just need to learn Node? 🤷‍♂️

jacoscaz commented 3 years ago

Hi @ProvocaTeach !

Understood and that’s an interesting use case. I know very little about Deno and was completely unaware of Skypack.

I would be happy to try and tweak things to make Quadstore available through Skypack, although you’d surely have a much easier life if you were to get started using Node. Quadstore implements one of the RDF/JS specifications, a collective effort to standardize interfaces and data models for better interoperability between JS libraries dealing with RDF. That I know of, little to none of the ecosystem officially supports Deno. I am sure that, given the latter’s increasing adoption rate, we’ll start having dedicated tests for its runtime but it’s not a trivial effort and it will take some time before that happens.

That said, I think I should be able to carve out a few hours at the end of next week to look into this. It’s also a nice excuse to finally have a look at Deno.

jacoscaz commented 3 years ago

If you believe you’ll continue with Deno, feel free to open a dedicated issue as that’s a separate feature of which support for ES modules is a prerequisite.

jacoscaz commented 2 years ago

Recent experience with https://github.com/beautifulinteractions/node-quadstore/issues/141 points to the possibility that bundling could be used as a workaround for the lack of support of ES modules in quadstore's dependencies.

We already ship our own custom distribution of Comunica as a pre-bundled package with zero dependencies. It should be possible to do the same for quadstore, with bundles available both as CommonJS modules and ES modules.

retog commented 2 years ago

As node-quadstore works in the browser I'd assume that rollup can be used to create an es-module that works in the browser and in demo. For demo you might consider publishing the resulting module on demo.land/x /Cc #139

retog commented 2 years ago

Some code using webpack to create a module that exports a quadstore instance: https://github.com/retog/quadstore-module

It bases on this hack https://stackoverflow.com/a/60010871/1455912 by @colxi.

jacoscaz commented 2 years ago

Thank you @retog , I really appreciate this. Bundling clearly works! However, the question now becomes whether to ship a single bundle or multiple ones and what to include. For instance, should an AbstractLevelDOWN backend be included? Probably not as there are multiple to choose from even for browser use (level-js and memdown). On the other side, last time I checked none of the available implementations shipped as ES modules, which would force devs to find workarounds all the same. Furthermore, bundling prevents dependency deduplication, which in turn prevents from shipping quadstore and quadstore-comunica as separate bundles as they share deps ATM.

jacoscaz commented 2 years ago

@ProvocaTeach @retog Very good progress on this. The latest betas quadstore@11.0.0-beta.4 and quadstore-comunica@3.0.0-beta.5 both ship with two different builds, a CJS and an ESM one. The reference repo for bundling and shipping browser-side is now consuming and producing ES modules: https://github.com/belayeng/quadstore-webpack-bundle/tree/4d5204977dca1b3ce23bb89ab9bc4bd851dceb23

jacoscaz commented 2 years ago

Closing - will be a part of the upcoming 11.0.0 release!