-
-
Notifications
You must be signed in to change notification settings - Fork 956
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
Allow runtime detection of the got
version
#2385
Comments
If you would like to accept this feature, and tell me which way you prefer - I'll be happy to submit a PR. However - I might need help in onboarding: I cloned the repo, ran node reproduced on the Windows host as well with node 💡 |
I'm not interested in adding any kind of version export. This should be solved by your bundler instead. It's not a problem specific to this package. It applies to every package with an exports field. I also believe Node.js is working on a method to get the package.json of a specific package. |
I see. Thanks for the response. Well. I'm writing server code in plain JS, I do not have any bundler. So the solution would be to locate the node_modules, find |
mm! sorry for the hassle! Looks like the solution is much simpler than I thought. Sharing: import { readFileSync } from 'node:fs'
const gotPath = import.meta.resolve("got").slice(6) // remove 'file:/' prefix
const pkgPath = gotPath.replace(/\/got\/.*/, '/got/package.json')
const { version } = JSON.parse( readFileSync( pkgPath ) ) Add some error-handling, and there you go 🙂 |
What problem are you trying to solve?
got@10
, migrating togot@14
.user-agent
header strings that included the version ofgot
among other things like the version of the service and the runtime version of node.package-lock.json
, and we want to reflect the version that landed in the distribution.require('got/package').version
, however, since the introduction of thepackage.json:exports
section - I cannot do that anymore 😞Describe the feature
Allow runtime detection of the
got
version.Two ways to do that:
got
should export aversion
field, that should reflect theversion
field in the package.jsone.g.:
or, alternatively
package.json
Checklist
The text was updated successfully, but these errors were encountered: