-
Notifications
You must be signed in to change notification settings - Fork 772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client: make prom client optional #3469
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, very cool! 🤩
For now I would rather like to not make the depedency optional (yet) for comfortability reasons but keep in the normal set of dependencies, can we do that?
This is rather a conceptual thing within the code base so that we are prepared later on to easily remove (If/when we split packages out), and the code changes do count for this here.
Side question out of interest: I found/find this super interesting, that it is possible to type with promClient
but only have the dependency in the optionalDependencies
set, since this is at least touching one of the core conceptual problems I always have with this that the type would be nice to have but the dependency should be out.
Is this - to your knowlege - the minimal setup to achieve this? 🤔 Or is there any way to get the dependency out completely but keep the typing??
Or are there other ways to approach this? There is no way (in package.json
) to "only reference the types" of a dependency, or something like that, right? Or would it be a way to "auto-generate" types for these cases from the original library (to get this done quickly) and include these??
Still one of the biggest structurally unsolved problems for me. 🤓
I don't remember exactly how it all worked (and don't have the energy to do the git archaeology this early in the morning) but this is basically what we did with our DB back when we had the specific |
We certainly can leave that as a dependency, and eventually decide to make it optional. It does make the conditionality checks irrelevant (since it will always be present), but at least that part of the work will be done. Wouldn't it make sense for this to be done "all at once" though rather than in 2 steps? Concerning the optionalDependencies and their related types, I've researched this a bit today and it seems like the proper approach would be:
Otherwise we would have (from what I'm reading) to do some conditional magic for the types as well in case they have not been installed. |
Hmm, but how would this work for TypeScript users of the library with types as a dev dependency? 🤔 Wouldn’t this break their code? |
Not sure I understand what you mean. Aren't types always just used as dev dependency since they're only needed during development and not in the production runtime environment? |
No, at least as far as my understanding goes (correct me if I have some thought error along the way), types are shipped as these So here is e.g. a similar example from If we would now directly remove the dependency (or make it optional) we will break people's TypeScript code from the default installation, right? That's why I have e.g. replaced this with a minimal interface here: But that's also where I am hanging a bit. So this is simple to be done for dependencies with a very low/small surface API but otherwise things get hairy quickly. Or is the way to go here to include the definitely-typed type package (so here e.g.: for |
I think the example you mention is a different scenario, where we were actually instantiating the class here:
For something like prometheus, I think the API surface is more substantial, so creating a minimal interface might not be feasible. I'll look into it again. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
This PR addresses a task that was mentioned in #3460, namely making the prometheus dependency optional.