I'm trying to recreate lerna
's list
functionality with Yarn 2, I need to get a list of every public package's name in the workspace. yarn workspaces list
can list all the packages on the workplace, but it returns every package, private included.
Also I need the result in a parseable format, e.g. JSON, or just a plain output with some line breaks.
Turn out its quite tricky, but doable:
yarn constraints query "workspace(Cwd), \+ workspace_field(Cwd, 'private', true), workspace_ident(Cwd, Ident)" --json
This will give you an NDJSON stream like this:
{"Cwd":"packages/yarnpkg-sdks","Ident":"@yarnpkg/sdks"}
{"Cwd":"packages/yarnpkg-shell","Ident":"@yarnpkg/shell"}