How can I get exact resolved version of dependency? #4667
Unanswered
jjangga0214
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
I need to get the exact version(not semver) of the dependency by programmatic way.
For example, if I want to know the version of
foo
, then I can run this code.(
readPkgUp
is a function that walks up recursively to find package.json)However, the above snippet works only with npm, pnpm, and yarn classic.
For yarn berry with PnP, it does not work.
So I tried this approach.
But it seems this also does not work with yarn berry.
I guess
@yarnpkg/lockfile
only works with yarn classic, though there's no documentation.Therefore I parsed the yarn.lock file to json directly.
By this, I could parse the version.
However, I worry that lockfile's schema can be different by yarn version.
Or I can be changed in the future.
I am a library author, and I need a way to get the dependency version in a stable way.
No matter whether a user of my library use yarn classic, yarn 2, yarn 3, etc.
Is there such a way?
Thanks very much in advance.
Beta Was this translation helpful? Give feedback.
All reactions