diff --git a/.yarn/versions/4aa0961e.yml b/.yarn/versions/4aa0961e.yml new file mode 100644 index 000000000000..9f833d0003a8 --- /dev/null +++ b/.yarn/versions/4aa0961e.yml @@ -0,0 +1,34 @@ +releases: + "@yarnpkg/core": minor + "@yarnpkg/plugin-workspace-tools": patch + +declined: + - "@yarnpkg/plugin-compat" + - "@yarnpkg/plugin-constraints" + - "@yarnpkg/plugin-dlx" + - "@yarnpkg/plugin-essentials" + - "@yarnpkg/plugin-exec" + - "@yarnpkg/plugin-file" + - "@yarnpkg/plugin-git" + - "@yarnpkg/plugin-github" + - "@yarnpkg/plugin-http" + - "@yarnpkg/plugin-init" + - "@yarnpkg/plugin-interactive-tools" + - "@yarnpkg/plugin-link" + - "@yarnpkg/plugin-nm" + - "@yarnpkg/plugin-npm" + - "@yarnpkg/plugin-npm-cli" + - "@yarnpkg/plugin-pack" + - "@yarnpkg/plugin-patch" + - "@yarnpkg/plugin-pnp" + - "@yarnpkg/plugin-pnpm" + - "@yarnpkg/plugin-stage" + - "@yarnpkg/plugin-typescript" + - "@yarnpkg/plugin-version" + - "@yarnpkg/builder" + - "@yarnpkg/cli" + - "@yarnpkg/doctor" + - "@yarnpkg/extensions" + - "@yarnpkg/nm" + - "@yarnpkg/pnpify" + - "@yarnpkg/sdks" diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/commands/workspaces/__snapshots__/foreach.test.js.snap b/packages/acceptance-tests/pkg-tests-specs/sources/commands/workspaces/__snapshots__/foreach.test.js.snap index 44aec2cad0b8..fc37c9e5fc14 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/commands/workspaces/__snapshots__/foreach.test.js.snap +++ b/packages/acceptance-tests/pkg-tests-specs/sources/commands/workspaces/__snapshots__/foreach.test.js.snap @@ -4,13 +4,13 @@ exports[`Commands workspace foreach --since --recursive runs on workspaces chang { "code": 0, "stderr": "", - "stdout": "➤ YN0000: Test Workspace A -➤ YN0000: Test Workspace B -➤ YN0000: Test Workspace D -➤ YN0000: Test Workspace E -➤ YN0000: Test Workspace F -➤ YN0000: Test Workspace C -➤ YN0000: Done + "stdout": "Test Workspace A +Test Workspace B +Test Workspace D +Test Workspace E +Test Workspace F +Test Workspace C +Done ", } `; @@ -19,7 +19,7 @@ exports[`Commands workspace foreach --since runs on no workspaces if there are n { "code": 0, "stderr": "", - "stdout": "➤ YN0000: Done + "stdout": "Done ", } `; @@ -28,7 +28,7 @@ exports[`Commands workspace foreach --since runs on no workspaces if there have { "code": 0, "stderr": "", - "stdout": "➤ YN0000: Done + "stdout": "Done ", } `; @@ -37,13 +37,13 @@ exports[`Commands workspace foreach --since runs on workspaces changed since bra { "code": 0, "stderr": "", - "stdout": "➤ YN0000: Test Workspace B -➤ YN0000: Test Workspace C -➤ YN0000: Test Workspace D -➤ YN0000: Test Workspace E -➤ YN0000: Test Workspace F -➤ YN0000: Test Workspace G -➤ YN0000: Done + "stdout": "Test Workspace B +Test Workspace C +Test Workspace D +Test Workspace E +Test Workspace F +Test Workspace G +Done ", } `; @@ -52,13 +52,13 @@ exports[`Commands workspace foreach --since runs on workspaces changed since com { "code": 0, "stderr": "", - "stdout": "➤ YN0000: Test Workspace B -➤ YN0000: Test Workspace C -➤ YN0000: Test Workspace D -➤ YN0000: Test Workspace E -➤ YN0000: Test Workspace F -➤ YN0000: Test Workspace G -➤ YN0000: Done + "stdout": "Test Workspace B +Test Workspace C +Test Workspace D +Test Workspace E +Test Workspace F +Test Workspace G +Done ", } `; @@ -67,8 +67,8 @@ exports[`Commands workspace foreach --since runs only on changed workspaces 1`] { "code": 0, "stderr": "", - "stdout": "➤ YN0000: Test Workspace A -➤ YN0000: Done + "stdout": "Test Workspace A +Done ", } `; @@ -77,9 +77,9 @@ exports[`Commands workspace foreach can run on public workspaces only 1`] = ` { "code": 0, "stderr": "", - "stdout": "➤ YN0000: Test Workspace A -➤ YN0000: Test Workspace C -➤ YN0000: Done + "stdout": "Test Workspace A +Test Workspace C +Done ", } `; @@ -88,11 +88,11 @@ exports[`Commands workspace foreach should execute 'node' command 1`] = ` { "code": 0, "orderedStdout": [ - "➤ YN0000: workspace-c", - "➤ YN0000: workspace-d", - "➤ YN0000: workspace-e", - "➤ YN0000: workspace-f", - "➤ YN0000: workspace-g", + "workspace-c", + "workspace-d", + "workspace-e", + "workspace-f", + "workspace-g", ], "stderr": "", } @@ -102,9 +102,9 @@ exports[`Commands workspace foreach should handle global scripts getting downgra { "code": 0, "stderr": "", - "stdout": "➤ YN0000: root workspace -➤ YN0000: Test Workspace G -➤ YN0000: Done + "stdout": "root workspace +Test Workspace G +Done ", } `; @@ -113,10 +113,10 @@ exports[`Commands workspace foreach should include dependencies if using --recur { "code": 0, "stderr": "", - "stdout": "➤ YN0000: Test Workspace A -➤ YN0000: Test Workspace C -➤ YN0000: Test Workspace B -➤ YN0000: Done + "stdout": "Test Workspace A +Test Workspace C +Test Workspace B +Done ", } `; @@ -125,11 +125,11 @@ exports[`Commands workspace foreach should include dependencies of workspaces ma { "code": 0, "stderr": "", - "stdout": "➤ YN0000: Test Workspace A -➤ YN0000: Test Workspace G -➤ YN0000: Test Workspace C -➤ YN0000: Test Workspace B -➤ YN0000: Done + "stdout": "Test Workspace A +Test Workspace G +Test Workspace C +Test Workspace B +Done ", } `; @@ -138,26 +138,26 @@ exports[`Commands workspace foreach should never run the scripts on workspaces t { "code": 0, "stderr": "", - "stdout": "➤ YN0000: [workspace-c]: Process started -➤ YN0000: [workspace-c]: Test Workspace C -➤ YN0000: [workspace-c]: Process exited (exit code 0) - -➤ YN0000: [workspace-d]: Process started -➤ YN0000: [workspace-d]: Test Workspace D -➤ YN0000: [workspace-d]: Process exited (exit code 0) - -➤ YN0000: [workspace-e]: Process started -➤ YN0000: [workspace-e]: Test Workspace E -➤ YN0000: [workspace-e]: Process exited (exit code 0) - -➤ YN0000: [workspace-f]: Process started -➤ YN0000: [workspace-f]: Test Workspace F -➤ YN0000: [workspace-f]: Process exited (exit code 0) - -➤ YN0000: [workspace-g]: Process started -➤ YN0000: [workspace-g]: Test Workspace G -➤ YN0000: [workspace-g]: Process exited (exit code 0) -➤ YN0000: Done + "stdout": "[workspace-c]: Process started +[workspace-c]: Test Workspace C +[workspace-c]: Process exited (exit code 0) + +[workspace-d]: Process started +[workspace-d]: Test Workspace D +[workspace-d]: Process exited (exit code 0) + +[workspace-e]: Process started +[workspace-e]: Test Workspace E +[workspace-e]: Process exited (exit code 0) + +[workspace-f]: Process started +[workspace-f]: Test Workspace F +[workspace-f]: Process exited (exit code 0) + +[workspace-g]: Process started +[workspace-g]: Test Workspace G +[workspace-g]: Process exited (exit code 0) +Done ", } `; @@ -166,14 +166,30 @@ exports[`Commands workspace foreach should not fall into endless loop if foreach { "code": 0, "stderr": "", - "stdout": "➤ YN0000: Test Workspace A -➤ YN0000: Test Workspace B -➤ YN0000: Test Workspace C -➤ YN0000: Test Workspace D -➤ YN0000: Test Workspace E -➤ YN0000: Test Workspace F -➤ YN0000: Test Workspace G -➤ YN0000: Done + "stdout": "Test Workspace A +Test Workspace B +Test Workspace C +Test Workspace D +Test Workspace E +Test Workspace F +Test Workspace G +Done +", +} +`; + +exports[`Commands workspace foreach should not include the prefix or a ➤ character when run with --no-verbose 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "Test Workspace A +Test Workspace B +Test Workspace C +Test Workspace D +Test Workspace E +Test Workspace F +Test Workspace G +Done ", } `; @@ -182,14 +198,14 @@ exports[`Commands workspace foreach should only run the scripts on workspaces th { "code": 0, "stderr": "", - "stdout": "➤ YN0000: [workspace-a]: Process started -➤ YN0000: [workspace-a]: Test Workspace A -➤ YN0000: [workspace-a]: Process exited (exit code 0) - -➤ YN0000: [workspace-b]: Process started -➤ YN0000: [workspace-b]: Test Workspace B -➤ YN0000: [workspace-b]: Process exited (exit code 0) -➤ YN0000: Done + "stdout": "[workspace-a]: Process started +[workspace-a]: Test Workspace A +[workspace-a]: Process exited (exit code 0) + +[workspace-b]: Process started +[workspace-b]: Test Workspace B +[workspace-b]: Process exited (exit code 0) +Done ", } `; @@ -198,34 +214,34 @@ exports[`Commands workspace foreach should prefix the output with run with --ver { "code": 0, "stderr": "", - "stdout": "➤ YN0000: [workspace-a]: Process started -➤ YN0000: [workspace-a]: Test Workspace A -➤ YN0000: [workspace-a]: Process exited (exit code 0) - -➤ YN0000: [workspace-b]: Process started -➤ YN0000: [workspace-b]: Test Workspace B -➤ YN0000: [workspace-b]: Process exited (exit code 0) - -➤ YN0000: [workspace-c]: Process started -➤ YN0000: [workspace-c]: Test Workspace C -➤ YN0000: [workspace-c]: Process exited (exit code 0) - -➤ YN0000: [workspace-d]: Process started -➤ YN0000: [workspace-d]: Test Workspace D -➤ YN0000: [workspace-d]: Process exited (exit code 0) - -➤ YN0000: [workspace-e]: Process started -➤ YN0000: [workspace-e]: Test Workspace E -➤ YN0000: [workspace-e]: Process exited (exit code 0) - -➤ YN0000: [workspace-f]: Process started -➤ YN0000: [workspace-f]: Test Workspace F -➤ YN0000: [workspace-f]: Process exited (exit code 0) - -➤ YN0000: [workspace-g]: Process started -➤ YN0000: [workspace-g]: Test Workspace G -➤ YN0000: [workspace-g]: Process exited (exit code 0) -➤ YN0000: Done + "stdout": "[workspace-a]: Process started +[workspace-a]: Test Workspace A +[workspace-a]: Process exited (exit code 0) + +[workspace-b]: Process started +[workspace-b]: Test Workspace B +[workspace-b]: Process exited (exit code 0) + +[workspace-c]: Process started +[workspace-c]: Test Workspace C +[workspace-c]: Process exited (exit code 0) + +[workspace-d]: Process started +[workspace-d]: Test Workspace D +[workspace-d]: Process exited (exit code 0) + +[workspace-e]: Process started +[workspace-e]: Test Workspace E +[workspace-e]: Process exited (exit code 0) + +[workspace-f]: Process started +[workspace-f]: Test Workspace F +[workspace-f]: Process exited (exit code 0) + +[workspace-g]: Process started +[workspace-g]: Test Workspace G +[workspace-g]: Process exited (exit code 0) +Done ", } `; @@ -234,15 +250,15 @@ exports[`Commands workspace foreach should run execute global scripts even on wo { "code": 0, "stderr": "", - "stdout": "➤ YN0000: One execution -➤ YN0000: One execution -➤ YN0000: One execution -➤ YN0000: One execution -➤ YN0000: One execution -➤ YN0000: One execution -➤ YN0000: One execution -➤ YN0000: One execution -➤ YN0000: Done + "stdout": "One execution +One execution +One execution +One execution +One execution +One execution +One execution +One execution +Done ", } `; @@ -251,12 +267,12 @@ exports[`Commands workspace foreach should run on current and descendant workspa { "code": 0, "stderr": "", - "stdout": "➤ YN0000: Test Workspace C -➤ YN0000: Test Workspace D -➤ YN0000: Test Workspace E -➤ YN0000: Test Workspace F -➤ YN0000: Test Workspace G -➤ YN0000: Done + "stdout": "Test Workspace C +Test Workspace D +Test Workspace E +Test Workspace F +Test Workspace G +Done ", } `; @@ -281,13 +297,13 @@ exports[`Commands workspace foreach should run scripts in parallel but following exports[`Commands workspace foreach should start all the processes at once when --jobs is unlimited 1`] = ` { "code": 0, - "first7Lines": "➤ YN0000: [workspace-a]: Process started -➤ YN0000: [workspace-b]: Process started -➤ YN0000: [workspace-c]: Process started -➤ YN0000: [workspace-d]: Process started -➤ YN0000: [workspace-e]: Process started -➤ YN0000: [workspace-f]: Process started -➤ YN0000: [workspace-g]: Process started", + "first7Lines": "[workspace-a]: Process started +[workspace-b]: Process started +[workspace-c]: Process started +[workspace-d]: Process started +[workspace-e]: Process started +[workspace-f]: Process started +[workspace-g]: Process started", "stderr": "", } `; diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/commands/workspaces/foreach.test.js b/packages/acceptance-tests/pkg-tests-specs/sources/commands/workspaces/foreach.test.js index 45266b7dbd4d..18c0e7488d52 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/commands/workspaces/foreach.test.js +++ b/packages/acceptance-tests/pkg-tests-specs/sources/commands/workspaces/foreach.test.js @@ -211,6 +211,22 @@ describe(`Commands`, () => { ), ); + test( + `should not include the prefix or a ➤ character when run with --no-verbose`, + makeTemporaryEnv( + { + private: true, + workspaces: [`packages/*`], + }, + async ({path, run}) => { + await setupWorkspaces(path); + await run(`install`); + + await expect(run(`workspaces`, `foreach`, `--no-verbose`, `run`, `print`)).resolves.toMatchSnapshot(); + }, + ), + ); + test( `should only run the scripts on workspaces that match the --include list`, makeTemporaryEnv( diff --git a/packages/plugin-workspace-tools/sources/commands/foreach.ts b/packages/plugin-workspace-tools/sources/commands/foreach.ts index f7bd3c204bf9..93fcb31b4ef9 100644 --- a/packages/plugin-workspace-tools/sources/commands/foreach.ts +++ b/packages/plugin-workspace-tools/sources/commands/foreach.ts @@ -221,6 +221,7 @@ export default class WorkspacesForeachCommand extends BaseCommand { const report = await StreamReport.start({ configuration, stdout: this.context.stdout, + includePrefix: false, }, async report => { const runCommand = async (workspace: Workspace, {commandIndex}: {commandIndex: number}) => { if (abortNextCommands) diff --git a/packages/yarnpkg-core/sources/StreamReport.ts b/packages/yarnpkg-core/sources/StreamReport.ts index d416e31d0320..7309742c4bf3 100644 --- a/packages/yarnpkg-core/sources/StreamReport.ts +++ b/packages/yarnpkg-core/sources/StreamReport.ts @@ -18,6 +18,7 @@ export type StreamReportOptions = { includeInfos?: boolean; includeLogs?: boolean; includeWarnings?: boolean; + includePrefix?: boolean; json?: boolean; stdout: Writable; }; @@ -142,6 +143,7 @@ export class StreamReport extends Report { } private configuration: Configuration; + private includePrefix: boolean; private includeFooter: boolean; private includeInfos: boolean; private includeWarnings: boolean; @@ -184,6 +186,7 @@ export class StreamReport extends Report { configuration, stdout, json = false, + includePrefix = true, includeFooter = true, includeLogs = !json, includeInfos = includeLogs, @@ -198,6 +201,7 @@ export class StreamReport extends Report { this.configuration = configuration; this.forgettableBufferSize = forgettableBufferSize; this.forgettableNames = new Set([...forgettableNames, ...BASE_FORGETTABLE_NAMES]); + this.includePrefix = includePrefix; this.includeFooter = includeFooter; this.includeInfos = includeInfos; this.includeWarnings = includeWarnings; @@ -374,8 +378,7 @@ export class StreamReport extends Report { const formattedName = this.formatNameWithHyperlink(name); const prefix = formattedName ? `${formattedName}: ` : ``; - - const message = `${formatUtils.pretty(this.configuration, `➤`, `blueBright`)} ${prefix}${this.formatIndent()}${text}`; + const message = `${this.formatPrefix(prefix, `blueBright`)}${text}`; if (!this.json) { if (this.forgettableNames.has(name)) { @@ -408,7 +411,7 @@ export class StreamReport extends Report { const prefix = formattedName ? `${formattedName}: ` : ``; if (!this.json) { - this.writeLineWithForgettableReset(`${formatUtils.pretty(this.configuration, `➤`, `yellowBright`)} ${prefix}${this.formatIndent()}${text}`); + this.writeLineWithForgettableReset(`${this.formatPrefix(prefix, `yellowBright`)}${text}`); } else { this.reportJson({type: `warning`, name, displayName: this.formatName(name), indent: this.formatIndent(), data: text}); } @@ -423,7 +426,7 @@ export class StreamReport extends Report { const prefix = formattedName ? `${formattedName}: ` : ``; if (!this.json) { - this.writeLineWithForgettableReset(`${formatUtils.pretty(this.configuration, `➤`, `redBright`)} ${prefix}${this.formatIndent()}${text}`, {truncate: false}); + this.writeLineWithForgettableReset(`${this.formatPrefix(prefix, `redBright`)}${text}`, {truncate: false}); } else { this.reportJson({type: `error`, name, displayName: this.formatName(name), indent: this.formatIndent(), data: text}); } @@ -684,6 +687,10 @@ export class StreamReport extends Report { }); } + private formatPrefix(prefix: string, caretColor: string) { + return this.includePrefix ? `${formatUtils.pretty(this.configuration, `➤`, caretColor)} ${prefix}${this.formatIndent()}` : ``; + } + private formatNameWithHyperlink(name: MessageName | null) { return formatNameWithHyperlink(name, { configuration: this.configuration,