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

Type declarations depend on dev dependencies #136

Closed gsvarovsky closed 3 years ago

gsvarovsky commented 3 years ago

When importing quadstore@9 into a dependent project using Typescript:

node_modules/quadstore/dist/lib/quadstore.d.ts:6:25 - error TS2307: Cannot find module 'sparqlalgebrajs' or its corresponding type declarations.

6 import { Algebra } from 'sparqlalgebrajs';
                          ~~~~~~~~~~~~~~~~~

node_modules/quadstore/dist/lib/quadstore.d.ts:8:30 - error TS2307: Cannot find module '@comunica/types' or its corresponding type declarations.

8 import { IQueryEngine } from '@comunica/types';
                               ~~~~~~~~~~~~~~~~~

These modules are dev dependencies.

As types have no runtime cost I think it might be fine to make @comunica/types a core dependency. However for sparqlalgebra a bundler might pull that project into the runtime. Perhaps type-only imports & exports can help here?

jacoscaz commented 3 years ago

This is an unfortunate situation that I'm not really sure how to get out of.

  1. If I add those dependencies as normal dependencies, NPM will install them and unnecessarily inflate the node_modules folder with stuff that is not really needed.
  2. If I add those dependencies as normal dependencies, bundlers might indeed pull them in (and their own dependencies!). However, this does looks like it can be solved by using type-only imports & exports as you mentioned.
  3. If I keep them as devDependencies they'll always result in this sort of error.

What would you do?

gsvarovsky commented 3 years ago

To just complete the picture for my use-case: m-ld-js uses the sparqlalgebrajs factory to construct algebra objects. So I have to pull in this module myself anyway. This means it's bundled twice, as it's already in the quadstore-comunica bundle.

jacoscaz commented 3 years ago

To just complete the picture for my use-case: m-ld-js uses the sparqlalgebrajs factory to construct algebra objects. So I have to pull in this module myself anyway. This means it's bundled twice, as it's already in the quadstore-comunica bundle.

Oh boy. I was not expecting that. Apologies, then - your bundle size must have grown a little bit. The reason I moved sparqlalgebrajs inside the quadstore-comunica bundle is that parsing needs to happen within Comunica for some SPARQL tests to succeed. I will revert to having sparqlalgebrajs outside of that bundle while still keeping Comunica's SPARQL parser actor around.

gsvarovsky commented 3 years ago

I think it may be possible for quadstore-comunica to export all of sparqlalgebrajs and the types from comunica.

jacoscaz commented 3 years ago

I think it may be possible for quadstore-comunica to export all of sparqlalgebrajs and the types from comunica.

This would be possible, yes, but it would not lend itself well to use cases dealing with custom Comunica configurations other than quadstore-comunica. Reverting to shipping sparqlalgebrajs as a dependency of quadstore but keeping the SPARQL parser actor in the quadstore-comunica bundle and forcing the latter to require sparqlalgebrajs via Webpack (as it was pre-9.0) should make everyone happy.

You can expect a fix by the end of the day. Thank you for raising this!

gsvarovsky commented 3 years ago

Thanks! No problem & no huge rush.

The good news is that with a temporary import of these deps, m-ld-js+quadstore@9 is passing all unit & compliance tests!

jacoscaz commented 3 years ago

Hello again @gsvarovsky !

Could you please try again with quadstore@9.1.0-beta.0 and quadstore-comunica@1.1.0-beta.0?

gsvarovsky commented 3 years ago

Could you please try again

It works!

jacoscaz commented 3 years ago

Fixed in quadstore@9.1.0 and quadstore-comunica@1.1.0.