Type declarations depend on dev dependencies
gsvarovsky opened this issue · comments
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?
This is an unfortunate situation that I'm not really sure how to get out of.
- 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. - 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.
- If I keep them as
devDependencies
they'll always result in this sort of error.
What would you do?
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.
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.
I think it may be possible for quadstore-comunica
to export all of sparqlalgebrajs
and the types from comunica.
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!
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!
Hello again @gsvarovsky !
Could you please try again with quadstore@9.1.0-beta.0
and quadstore-comunica@1.1.0-beta.0
?
Could you please try again
It works!
Fixed in quadstore@9.1.0
and quadstore-comunica@1.1.0
.