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

Prefix workspace commands with workspace name #6932

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa

## Master

- Prefix `yarn workspaces run` output with workspace name

- Improves PnP compatibility with Node 6

[#6871](https://github.com/yarnpkg/yarn/pull/6871) - [**Robert Jackson**](https://github.com/rwjblue)

- Fixes PnP detection with workspaces (`installConfig` is now read at the top-level)

[#6878](https://github.com/yarnpkg/yarn/pull/6878) - [**Maël Nison**](https://twitter.com/arcanis)

- Fixes an interaction between `yarn pack` and bundled dependencies

[#6908](https://github.com/yarnpkg/yarn/pull/6908) - [**Travis Hoover**](https://twitter.com/thoov)
Expand Down
6 changes: 4 additions & 2 deletions __tests__/commands/workspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ test('workspaces run should spawn command for each workspace', (): Promise<void>
const originalArgs = ['run', 'script', 'arg1', '--flag1'];
return runWorkspaces({originalArgs}, ['run', 'script', 'arg1', '--flag1'], 'run-basic', config => {
expect(spawn).toHaveBeenCalledWith(NODE_BIN_PATH, [YARN_BIN_PATH, 'script', 'arg1', '--flag1'], {
stdio: 'inherit',
stdio: 'pipe',
cwd: path.join(fixturesLoc, 'run-basic', 'packages', 'workspace-child-1'),
workspaceName: 'workspace-1',
});
expect(spawn).toHaveBeenCalledWith(NODE_BIN_PATH, [YARN_BIN_PATH, 'script', 'arg1', '--flag1'], {
stdio: 'inherit',
stdio: 'pipe',
cwd: path.join(fixturesLoc, 'run-basic', 'packages', 'workspace-child-2'),
workspaceName: 'workspace-2',
});
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"ssri": "^5.3.0",
"strip-ansi": "^4.0.0",
"strip-bom": "^3.0.0",
"strong-log-transformer": "2.1.0",
"tar-fs": "^1.16.0",
"tar-stream": "^1.6.1",
"uuid": "^3.0.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/pkg-tests/pkg-tests-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"super-resolve": "^1.0.0",
"tar-fs": "^1.16.0",
"tmp": "^0.0.33"
},
"scripts": {
"test-script": "echo pkg-tests-core test-script"
}
}
3 changes: 2 additions & 1 deletion packages/pkg-tests/pkg-tests-fixtures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "pkg-tests-fixtures",
"version": "1.0.0",
"scripts": {
"copy-index": "find packages -type d -mindepth 1 -maxdepth 1 | while read pkg; do cp default-index.js \"$pkg\/index.js\"; done"
"copy-index": "find packages -type d -mindepth 1 -maxdepth 1 | while read pkg; do cp default-index.js \"$pkg\/index.js\"; done",
"test-script": "echo pkg-tests-fixtures test-script"
}
}
3 changes: 3 additions & 0 deletions packages/pkg-tests/pkg-tests-specs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"fs-extra": "^7.0.0",
"pkg-tests-core": "1.0.0",
"semver": "^5.6.0"
},
"scripts": {
"test-script": "echo pkg-tests-specs test-script"
}
}
3 changes: 2 additions & 1 deletion src/cli/commands/workspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ export async function runScript(config: Config, reporter: Reporter, flags: Objec
const {loc} = workspaces[workspaceName];

await child.spawn(NODE_BIN_PATH, [YARN_BIN_PATH, ...rest], {
stdio: 'inherit',
stdio: 'pipe',
cwd: loc,
workspaceName,
});
}
} catch (err) {
Expand Down
21 changes: 19 additions & 2 deletions src/util/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {promisify} from './promise.js';

const child = require('child_process');

const logTransformer = require('strong-log-transformer');
const chalk = require('chalk');
const colors = ['red', 'yellow', 'green', 'cyan', 'blue', 'magenta', 'white', 'gray'];
const workspaceColors = {};

export const queue = new BlockingQueue('child', constants.CHILD_CONCURRENCY);

// TODO: this uid check is kinda whack
Expand Down Expand Up @@ -61,7 +66,7 @@ type ProcessFn = (
export function spawn(
program: string,
args: Array<string>,
opts?: child_process$spawnOpts & {detached?: boolean, process?: ProcessFn} = {},
opts?: child_process$spawnOpts & {detached?: boolean, process?: ProcessFn, workspaceName?: string} = {},
onData?: (chunk: Buffer | string) => void,
): Promise<string> {
const key = opts.cwd || String(++uid);
Expand Down Expand Up @@ -116,7 +121,19 @@ export function spawn(
}

if (proc.stdout) {
proc.stdout.on('data', updateStdout);
// Prefix output with workspace name, if we have it
if (opts.workspaceName) {
// Stay consistent by using the key that is mapped to proc
if (!workspaceColors[key]) {
const randInt = Math.floor(Math.random() * colors.length);
workspaceColors[key] = colors[randInt];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to just go through the colors array in order here?
It seems like by using rand we could potentially pick the same color for neighboring workspaces.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by going through the array it will also make the output deterministic

}
const wsColor = chalk[workspaceColors[key]];
const tag = `${wsColor.bold(opts.workspaceName)}:`;
proc.stdout.pipe(logTransformer({tag})).pipe(process.stdout);
} else {
proc.stdout.on('data', updateStdout);
}
}

processingDone = true;
Expand Down
16 changes: 15 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,11 @@ domexception@^1.0.1:
dependencies:
webidl-conversions "^4.0.2"

duplexer@^0.1.1:
version "0.1.1"
resolved "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"
integrity sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=

duplexify@^3.5.0, duplexify@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/duplexify/-/duplexify-3.6.0.tgz#592903f5d80b38d037220541264d69a198fb3410"
Expand Down Expand Up @@ -7077,6 +7082,15 @@ [email protected], strip-json-comments@~2.0.1:
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo=

[email protected]:
version "2.1.0"
resolved "https://registry.npmjs.org/strong-log-transformer/-/strong-log-transformer-2.1.0.tgz#0f5ed78d325e0421ac6f90f7f10e691d6ae3ae10"
integrity sha512-B3Hgul+z0L9a236FAUC9iZsL+nVHgoCJnqCbN588DjYxvGXaXaaFbfmQ/JhvKjZwsOukuR72XbHv71Qkug0HxA==
dependencies:
duplexer "^0.1.1"
minimist "^1.2.0"
through "^2.3.4"

supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
Expand Down Expand Up @@ -7231,7 +7245,7 @@ [email protected], through2@^2.0.0, through2@^2.0.1, through2@^2.0.3, through2@~2.0.0
readable-stream "^2.1.5"
xtend "~4.0.1"

through@^2.3.6:
through@^2.3.4, through@^2.3.6:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=
Expand Down