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

[feat] List workspace names/paths only #4086

Closed
2 tasks done
restfulhead opened this issue Nov 24, 2021 · 7 comments
Closed
2 tasks done

[feat] List workspace names/paths only #4086

restfulhead opened this issue Nov 24, 2021 · 7 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@restfulhead
Copy link

restfulhead commented Nov 24, 2021

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

I'm looking for an NPM command similar to lerna ls that would print out only the paths of all workspaces.

npm ls --production --depth 0 -json does contain the information, but it's difficult to parse ("resolved": "file:../../packages/package1", instead of just path: packages/package1 for example)

Related Stackoverflow post: https://stackoverflow.com/questions/69980663/list-npm-workspaces-similar-to-lerna-ls

Expected Behavior

Maybe npm ls -ws could just print out the paths, e.g.

packages/package1
packages/package2
my-other-package

Steps To Reproduce

See above

Environment

  • npm: 7.24.2
  • Node: v14.17.3
  • OS: MacOS
  • platform: Mac

P.S.: This is not a bug, but a feature request. I could not find another template.

@restfulhead restfulhead added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Nov 24, 2021
@justinfagnani
Copy link

This is especially important to understand what packages and in what order npm will run scripts in. Related to the issue I just filed about running scripts in topological order: #4139

@nlf
Copy link
Contributor

nlf commented Oct 3, 2022

this is now possible with npm query when combined with a tool like jq in the latest npm@8, an example run from this repository:

> npm query .workspace | jq -r '.[].location'
docs
workspaces/arborist
workspaces/libnpmaccess
workspaces/libnpmdiff
workspaces/libnpmexec
workspaces/libnpmfund
workspaces/libnpmhook
workspaces/libnpmorg
workspaces/libnpmpack
workspaces/libnpmpublish
workspaces/libnpmsearch
workspaces/libnpmteam
workspaces/libnpmversion
smoke-tests

@nlf nlf closed this as completed Oct 3, 2022
@dmail
Copy link

dmail commented May 30, 2023

jq will list a subset of packages when NPM output is too large for the terminal.
It gives the false impression NPM is not taking into account some packages.
And it forces to install jq.

@ljharb
Copy link
Collaborator

ljharb commented May 30, 2023

You can use npx json too. I’m confused why jq would truncate anything tho.

@dmail
Copy link

dmail commented May 30, 2023

Actually my bad, jq works fine.
Some packages where not reported but after removing nodes modules + package-lock.json + npm install: they are listed.

Still something odd to me: the order of packages being listed.

My workspaces config:

"workspaces": [
    "./packages/internal/*",
    "./packages/plugins/*",
    "./packages/rest/*"
]

And the output in the terminal is mixing package directories

packages/rest/a
packages/plugins/plugin-a
packages/internal/internal-a
packages/plugins/plugin-b
packages/rest/b

I would expect them to stay grouped by directory (and in the order provided by "workspaces"):

packages/internal/internal-a
packages/plugins/plugin-a
packages/plugins/plugin-b
packages/rest/a
packages/rest/b

@siefkenj
Copy link

You can get pretty close with npm exec -c pwd -ws (on a unix system), and there's no need for jq.

@luwes
Copy link

luwes commented May 3, 2024

not the fastest but this seems to work and it should be supported on all platforms.

npm exec -c 'node -p "process.env.npm_package_name + \":\" + process.env.PWD"' -w packages

npm query seems less ideal because you lose the filtering options of -w and -ws and the order is not maintained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

7 participants