Skip to content
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

add pnpm workspaces info #3398

Open
1 task
futurist opened this issue Apr 26, 2021 · 9 comments
Open
1 task

add pnpm workspaces info #3398

futurist opened this issue Apr 26, 2021 · 9 comments

Comments

@futurist
Copy link

Describe the user story

Want a command like yarn workspaces info, but no counterpart command for pnpm.

Describe the solution you'd like

Maybe add a command like pnpm workspaces info

And if pass --json, it can output the json results.

@rdsedmundo
Copy link

rdsedmundo commented May 8, 2021

I managed to get some useful information with pnpm ls -r --depth -1 --long --parseable.

/Users/user/acme/packages/first:@acme/first@1.0.0
/Users/user/acme/packages/second:@acme/second@1.0.0
...

The ls command also supports a --json flag, but it unfortunately doesn't display the package path like the former.

I converted it to JSON like this (note that I'm assuming that packages names start with @, like @acme/package):

const workspaces = execSync('pnpm ls -r --depth -1 --long --parseable')
  .toString('utf8')
  .split('\n')
  // the first line is the workspace root
  .slice(1)
  .map((entry) => {
    const [location, nameWithVersion] = entry.split(':');
    const [, name, version] = nameWithVersion.split('@');

    return {
      location,
      version,
      // add forward @ again that was split
      name: `@${name}`,
    };
  })
  .reduce((acc, workspace) => ({ ...acc, [workspace.name]: workspace }), {});

@gluxon
Copy link
Member

gluxon commented Dec 25, 2021

Hey everyone, I got linked here by @zkochan's comment in #4154

  1. I'm wondering if resolving this via the existing pnpm list command makes sense? In theory that allows the --depth, --filter, and --json flags to be reused.
  2. Alternatively we could close the pnpm list feature request I opened in favor of a new pnpm workspaces info command like this issue proposes.

I would personally prefer extending pnpm list to traverse through workspaces (option 1) since a new pnpm workspaces info command would create 2 commands for listing out dependencies, and users might be confused when using the wrong one.

What does everyone else think?

Edit: To be clear, I'm not a pnpm main contributor. Just starting a discussion in hopes of figuring out which GitHub issue to close.

@zkochan
Copy link
Member

zkochan commented Dec 25, 2021

I think it is fine to extend the pnpm list command. pnpm workspaces might be a bad command for pnpm because we don't call the packages in the workspace "workspaces".

@NullVoxPopuli
Copy link
Contributor

I just ran in to a need for this today as I was adding pnpm support to my project hopper script: https://github.com/NullVoxPopuli/dotfiles/blob/master/home/shell/bash/gg.sh

@NullVoxPopuli
Copy link
Contributor

This is the command I ended up using in bash:

pnpm ls -r --depth -1 --long --parseable \
  | cut -f1 -d':' \
  | sed "s~$PWD~~g" \
  | sed '/^[[:space:]]*$/d' \
  | sed 's~^/~~g'

image

@karlomedallo
Copy link

+1 for this. My use case is I wanted to get all the workspace package dependencies of an app so that during CI it would know if it needs to run a job or not when changes has been detected from the dependent package

@gluxon
Copy link
Member

gluxon commented Jan 1, 2023

Hey @karlomedallo, would #5863 help for that use case?

@karlomedallo
Copy link

@gluxon yes, that #5863 will definitely help! I hope that gets merged. Thanks!

@kachkaev
Copy link

kachkaev commented Apr 5, 2023

If pnpm workspaces is added, having yarn workspace command too would be great! #3451 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants