Skip to content

Commit 1f4b28f

Browse files
authored
feat(essentials): Add --no-private flag to list command (#4830)
1 parent 1155af0 commit 1f4b28f

File tree

3 files changed

+65
-0
lines changed
  • .yarn/versions
  • packages
    • acceptance-tests/pkg-tests-specs/sources/commands/workspaces
    • plugin-essentials/sources/commands/workspaces

3 files changed

+65
-0
lines changed

.yarn/versions/5fb9cb98.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
releases:
2+
"@yarnpkg/cli": minor
3+
"@yarnpkg/plugin-essentials": minor
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-init"
10+
- "@yarnpkg/plugin-interactive-tools"
11+
- "@yarnpkg/plugin-nm"
12+
- "@yarnpkg/plugin-npm-cli"
13+
- "@yarnpkg/plugin-pack"
14+
- "@yarnpkg/plugin-patch"
15+
- "@yarnpkg/plugin-pnp"
16+
- "@yarnpkg/plugin-pnpm"
17+
- "@yarnpkg/plugin-stage"
18+
- "@yarnpkg/plugin-typescript"
19+
- "@yarnpkg/plugin-version"
20+
- "@yarnpkg/plugin-workspace-tools"
21+
- "@yarnpkg/builder"
22+
- "@yarnpkg/core"
23+
- "@yarnpkg/doctor"

packages/acceptance-tests/pkg-tests-specs/sources/commands/workspaces/list.test.js

+33
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,39 @@ describe(`Commands`, () => {
159159
}),
160160
);
161161

162+
test(
163+
`--no-private excludes private workspaces`,
164+
makeTemporaryEnv({
165+
private: true,
166+
workspaces: [`packages/*`],
167+
}, async ({run, path}) => {
168+
await writeJson(`${path}/packages/workspace-a/package.json`, {
169+
name: `workspace-a`,
170+
private: true,
171+
version: `1.0.0`,
172+
});
173+
174+
await writeJson(`${path}/packages/workspace-b/package.json`, {
175+
name: `workspace-b`,
176+
version: `1.0.0`,
177+
});
178+
179+
await expect(
180+
parseJsonStream(
181+
(await run(`workspaces`, `list`, `-v`, `--no-private`, `--json`)).stdout,
182+
`location`,
183+
),
184+
).toEqual({
185+
[`packages/workspace-b`]: {
186+
location: `packages/workspace-b`,
187+
name: `workspace-b`,
188+
workspaceDependencies: [],
189+
mismatchedWorkspaceDependencies: [],
190+
},
191+
});
192+
}),
193+
);
194+
162195
test(
163196
`--since returns only changed workspaces`,
164197
makeWorkspacesListSinceEnv(async ({path, run}) => {

packages/plugin-essentials/sources/commands/workspaces/list.ts

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default class WorkspacesListCommand extends BaseCommand {
1919
2020
- If \`-R,--recursive\` is set, Yarn will find workspaces to run the command on by recursively evaluating \`dependencies\` and \`devDependencies\` fields, instead of looking at the \`workspaces\` fields.
2121
22+
- If \`--no-private\` is set, Yarn will not list any workspaces that have the \`private\` field set to \`true\`.
23+
2224
- If both the \`-v,--verbose\` and \`--json\` options are set, Yarn will also return the cross-dependencies between each workspaces (useful when you wish to automatically generate Buck / Bazel rules).
2325
`,
2426
});
@@ -32,6 +34,10 @@ export default class WorkspacesListCommand extends BaseCommand {
3234
description: `Find packages via dependencies/devDependencies instead of using the workspaces field`,
3335
});
3436

37+
noPrivate = Option.Boolean(`--no-private`, {
38+
description: `Exclude workspaces that have the private field set to true`,
39+
});
40+
3541
verbose = Option.Boolean(`-v,--verbose`, false, {
3642
description: `Also return the cross-dependencies between workspaces`,
3743
});
@@ -62,6 +68,9 @@ export default class WorkspacesListCommand extends BaseCommand {
6268
for (const workspace of workspaces) {
6369
const {manifest} = workspace;
6470

71+
if (manifest.private && this.noPrivate)
72+
continue;
73+
6574
let extra;
6675
if (this.verbose) {
6776
const workspaceDependencies = new Set<Workspace>();

0 commit comments

Comments
 (0)