yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.42k stars 1.11k forks source link

[Feature] yarn list #720

Closed IanVS closed 4 years ago

IanVS commented 4 years ago

One of the most useful commands I'm used to running in yarn 1 is yarn list <pkgname>. I see that there's no such thing in yarn 2. Is there a replacement? I couldn't find anything about it in the migration guide.

Edit: it seems like network-timeout has been removed as well. Is there a new way to set that? I don't see it in any of the config docs.

arcanis commented 4 years ago

Does yarn why <name> fits the bill?

arcanis commented 4 years ago

As for networkTimeout we don't have this setting at the moment, but I'd be happy to review a PR that would add that! It's probably just a matter of defining the extra setting in Configuration.ts, adding support for it into httpUtils.ts, and writing some doc in yarnrc.js.

jdanil commented 4 years ago

I'm after yarn list as well. It was useful to see what dependencies were installed, which isn't something that yarn why can be used for.

Particularly interested in a command equivalent to npm ls --depth=0 to list the direct dependencies of a package (yarn v1 supports yarn list --depth <number> but doesn't work as expected https://github.com/yarnpkg/yarn/issues/3569).

pnpm also supports this quite well, with an additional recursive command to include dependencies of workspaces (https://pnpm.js.org/en/cli/list).

Wondering if this is something you see being added to berry? And if so, whether it would be in the core or added as a plugin?

charliematters commented 4 years ago

Confusingly, there is the httpTimeout property in the docs

When you actually set it though you get: Usage Error: Unrecognized or legacy configuration settings found: httpTimeout.

I've noticed a few inconsistencies with the docs in general though (npmScopes.my-company.npmAuthToken appears, but yarn rejects it) which is quite frustrating

bgotink commented 4 years ago

@charliematters The httpTimeout configuration has been added a couple of weeks ago in https://github.com/yarnpkg/berry/pull/1291. This new code hasn't been released yet, so if you want to set a timeout you'll have to update to the master branch using yarn set version from sources.

arcanis commented 4 years ago

Yep, same for npmAuthToken in npmScopes (although I think it's been released in an rc).

Generally speaking the documentation website is generated based on master, not whatever the latest release is. I don't know whether it would be better or worse to use the latest tag for the CLI doc, since the rest of the doc would still be "too fresh" ... and we don't want to cherry-pick the typos etc from master either, so we can't deploy the latest tag for the whole website.

Annoying 🤔

kydesnic commented 4 years ago

yarn list or some replacement would be very welcome. yarn why doesn't suit, because it tells what depends on the specified package, it says nothing about what I have.

By the way the fresh documentation on the main site is really very annoying. Because as a yarn/webpack/js newbie I expect the documentation to describe the latest stable, working version. The banner about having the v1 docs says nothing to a newcomer. It doesn't say "don't use v2, it is raw yet", it just says "we support the old v1". I follow the current v2 docs, install berry, and get the unusable environment. Finally --version says that the main "Getting Started" docs path has led me to an... RC... (2.0.0-rc.36). That is really annoying.

Also as an off-topic, I wonder whether I should post a new issue/question about launching the packages: I have tried to install webpack with berry, but I cannot launch it -- yarn hasn't created node_modules folder (I even cannot deduce from the "Getting Started" docs, whether it is ok, or not), npm doesn't see any packages, npx doesn't see webpack, how on earth can I start it?? Also error messages are not very descriptive (try yarn exec webpack, and enjoy Internal Error: spawn webpack ENOENT, for example).

Please forgive me for swerving from the thread's topic so much. But that was my front-end programming beginning! I cannot say Yarn 2 has made it very nice. I just could not stop writing, I'm sorry...

arcanis commented 4 years ago

@kydesnic Generally, if you have N feedbacks and only a single one matches the thread, better open a new one.

The banner about having the v1 docs says nothing to a newcomer. It doesn't say "don't use v2, it is raw yet", it just says "we support the old v1".

I think it's in large part because we don't intend to say "don't use v2", but rather "the old v1 is here if you're using it already". So from what you say, the wording is spot on 🙂

I have tried to install webpack with berry, but I cannot launch it -- yarn hasn't created node_modules folder

Did Yarn generate an error? If not, you can assume that's expected (it is).

npm doesn't see any packages, npx doesn't see webpack, how on earth can I start it??

Both npm and npx are npm projects, not Yarn ones. Yarn and npm have different architectures, so there's no reason to think that you could use one on what the other installed.

As for "how to start it", did you try to ... literally just start it? Using yarn webpack ...? (Note that for Webpack the CLI is in a separate package, so you'll actually need to also run yarn add webpack-cli, and use yarn webpack-cli ... afterwards - but that's not something unique to Yarn).

Please forgive me for swerving from the thread's topic so much. But that was my front-end programming beginning!

We all start somewhere 🙂 Still, if you know that this isn't the topic discussed here, perhaps a new thread would have been better indeed (or, better yet, just pop on our Discord to ask quick questions like this).

kydesnic commented 4 years ago

@arcanis , thank you very much for your patient explanations! I will try to find some more appropriate place for such questions next time.

As for "how to start it", did you try to ... literally just start it? Using yarn webpack ...?

I thought yarn run runs only package.json scripts, not package commands (as npm run does). As for "literally" -- no, I didn't expect the script can be launched directly, my experience says to look for some command or keyword.

Thus some mention about running packages in the "Getting Started" manual would be much appreciated, it wasn't obvious for me.

Yarn and npm have different architectures, so there's no reason to think that you could use one on what the other installed.

This is not obvious also. After trying berry I had turned to Yarn 1, and it does create node_modules, and npx does work with it. Therefore I repeat, that this difference of Yarn 2 is not obvious to a complete beginner, who starts with Yarn 2 directly.

Having a short notice in "Getting Started" with the link to the PnP section would be great also.

May be most of yarn newcomers have good experience with js/npm or other js package systems, but that's not my case, I'm new to both yarn and npm. :slightly_smiling_face:

Thank you again! I hope the "Getting Started" manual will become more friendly for beginners. It is usual, that a thing, obvious to a developer, is not so obvious to a user.

agschrei commented 4 years ago

Is there an update on the current progress of porting yarn list to berry?

I assume that an implementation of this would have to interface with the pnpapi? You already provide a very basic example of how to iterate over the dependency tree using calls to the interface.

Towards that end, my question is: How stable is the API already? I.e. does it make sense to build a tool that extracts dependency information using the current state of the API?

cmonacaps commented 4 years ago

I agree along this thread, I think although they're separate issues, clearly, on the other hand they may comprise steps along a path of user adoption, that is so much happier when it's a well developed, smooth path, than when we have the expectation that we already know the way, or that it's all so intuitive that it's not worth writing out.

For my experience thus far I ran into

  1. how can I run webpack without node_modules/ ?

I looked at the docs and the yarn help for a while on this one.

Finally I entered a stack overflow post and when fortunately someone answered I was on my way!

But why did I have to do that. The answer I was looking for was yarn run webpack. How did I miss it?

$ yarn help
 ...
  yarn run [--inspect] [--inspect-brk] <scriptName> ...
    run a script defined in the package.json
 ...

Well... and especially for those of us with a background using npm, this reinforces an expectation about what it might mean.

Anyway I didn't dwell on this too long because I had moved from the group without knowledge facing the docs to the group with knowledge who doesn't need any docs!

  1. Armed with that knowledge I forgot, did I also add webpack-cli yet? Do I have the packages I need to move forward? I tried it, without the docs, maybe it would work, no reason for it to,
$ yarn list
Usage Error: Couldn't find a script named "list".

$ yarn run [--inspect] [--inspect-brk] <scriptName> ...

Well, ok so 1) that was not the right command and 2) why is it telling me about yarn run? It can't reasonably be the command to list packages. Let me know if I'm mistaken on that point please!

I read the yarn help several more times reading over it all. I was motivated by my instinct that this common-sense command must exist. Nothing appeared to fit. I tried Google. There it was a bit tricky since anything I typed led me to the classic.yarn docs on the yarn list command.

Carefully narrowing down my search led me here. I see above that yarn why might work.

That should be easy to remember:

Yarn, Why?

$ yarn why  
Unknown Syntax Error: Not enough positional arguments.

$ yarn why [-R,--recursive] [--peers] <package>
jdanil commented 4 years ago

Hi @arcanis. Saw your comment on #1902. I had a play around with it on master. I'm wondering if there is any way to use yarn info to get a similar output to npm list --depth=0? Would the best way be to run yarn workspaces list and then run yarn info <workspace> --all on each workspace?

arcanis commented 4 years ago

I'm wondering if there is any way to use yarn info to get a similar output to npm list --depth=0?

I think the --name-only flag would match the same use case as the list --depth=0 command.

Would the best way be to run yarn workspaces list and then run yarn info <workspace> --all on each workspace?

yarn workspaces foreach info --name-only

I think the only problem with that is that yarn info has currently what I deem to be a bug where it by default prints transitive dependencies as well as the direct dependencies. We should fix that to make it in line with what happens with yarn why (which only considers direct dependencies unless -R,--recursive is set).

jdanil commented 4 years ago

Great. That sounds good. I thought that yarn info printing transitive dependencies by default was expected. But direct dependencies would be more useful.

arcanis commented 4 years ago

Is it something you'd be interested to contribute? We're planing a patch release shortly, this could be part of it

jdanil commented 4 years ago

Is it something you'd be interested to contribute? We're planing a patch release shortly, this could be part of it

Potentially! I'll finish off audit before starting anything else though.

arcanis commented 4 years ago

I went ahead and fixed that for the 2.3.1, now published 🙂

So if you're looking for yarn list, try: yarn info --name-only

mesqueeb commented 3 years ago

how to do something like npm list vue to see all dependencies in an entire workspace that use "vue" alongside which version of "vue" they are using.

merceyz commented 3 years ago

Use the yarn why command - https://yarnpkg.com/cli/why

yarn why vue
sdankel commented 1 year ago

Is there a way to do something like yarn list --prod with yarn info? That is, list only the production dependencies, excluding devDependencies. I looked through the output yarn info to see if there was a pattern I could filter on, but didn't find anything. Edit: I see there's a newer issue for this: https://github.com/yarnpkg/berry/issues/5117

broofa commented 7 months ago

Came here looking for a command that will list all dependencies installed across all workspaces. Didn't find anything. Using this command for the time being:

grep "^\"" yarn.lock | sed -e "s/^\"//" -e "s/\"://"