Skip to content

Commit 144f115

Browse files
committed
Prefix workspace commands with workspace name
1 parent fb03788 commit 144f115

File tree

8 files changed

+49
-7
lines changed

8 files changed

+49
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa
44

55
## Master
66

7+
- Prefix `yarn workspaces run` output with workspace name
8+
79
- Improves PnP compatibility with Node 6
810

911
[#6871](https://github.com/yarnpkg/yarn/pull/6871) - [**Robert Jackson**](https://github.com/rwjblue)
10-
12+
1113
- Fixes PnP detection with workspaces (`installConfig` is now read at the top-level)
1214

1315
[#6878](https://github.com/yarnpkg/yarn/pull/6878) - [**Maël Nison**](https://twitter.com/arcanis)
14-
16+
1517
- Fixes an interaction between `yarn pack` and bundled dependencies
1618

1719
[#6908](https://github.com/yarnpkg/yarn/pull/6908) - [**Travis Hoover**](https://twitter.com/thoov)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"ssri": "^5.3.0",
4747
"strip-ansi": "^4.0.0",
4848
"strip-bom": "^3.0.0",
49+
"strong-log-transformer": "2.1.0",
4950
"tar-fs": "^1.16.0",
5051
"tar-stream": "^1.6.1",
5152
"uuid": "^3.0.1",

packages/pkg-tests/pkg-tests-core/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"super-resolve": "^1.0.0",
1111
"tar-fs": "^1.16.0",
1212
"tmp": "^0.0.33"
13+
},
14+
"scripts": {
15+
"test-script": "echo pkg-tests-core test-script"
1316
}
1417
}

packages/pkg-tests/pkg-tests-fixtures/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "pkg-tests-fixtures",
33
"version": "1.0.0",
44
"scripts": {
5-
"copy-index": "find packages -type d -mindepth 1 -maxdepth 1 | while read pkg; do cp default-index.js \"$pkg\/index.js\"; done"
5+
"copy-index": "find packages -type d -mindepth 1 -maxdepth 1 | while read pkg; do cp default-index.js \"$pkg\/index.js\"; done",
6+
"test-script": "echo pkg-tests-fixtures test-script"
67
}
78
}

packages/pkg-tests/pkg-tests-specs/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
"fs-extra": "^7.0.0",
77
"pkg-tests-core": "1.0.0",
88
"semver": "^5.6.0"
9+
},
10+
"scripts": {
11+
"test-script": "echo pkg-tests-specs test-script"
912
}
1013
}

src/cli/commands/workspaces.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ export async function runScript(config: Config, reporter: Reporter, flags: Objec
8181
const {loc} = workspaces[workspaceName];
8282

8383
await child.spawn(NODE_BIN_PATH, [YARN_BIN_PATH, ...rest], {
84-
stdio: 'inherit',
84+
stdio: 'pipe',
8585
cwd: loc,
86+
workspaceName,
8687
});
8788
}
8889
} catch (err) {

src/util/child.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import {promisify} from './promise.js';
88

99
const child = require('child_process');
1010

11+
const logTransformer = require('strong-log-transformer');
12+
const chalk = require('chalk');
13+
const colors = ['red', 'yellow', 'green', 'cyan', 'blue', 'magenta', 'white', 'gray'];
14+
const workspaceColors = {};
15+
1116
export const queue = new BlockingQueue('child', constants.CHILD_CONCURRENCY);
1217

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

118123
if (proc.stdout) {
119-
proc.stdout.on('data', updateStdout);
124+
// Prefix output with workspace name, if we have it
125+
if (opts.workspaceName) {
126+
// Stay consistent by using the key that is mapped to proc
127+
if (!workspaceColors[key]) {
128+
const randInt = Math.floor(Math.random() * colors.length);
129+
workspaceColors[key] = colors[randInt];
130+
}
131+
const wsColor = chalk[workspaceColors[opts.workspaceName]];
132+
const tag = `${wsColor.bold(opts.workspaceName)}:`;
133+
proc.stdout.pipe(logTransformer({tag})).pipe(process.stdout);
134+
} else {
135+
proc.stdout.on('data', updateStdout);
136+
}
120137
}
121138

122139
processingDone = true;

yarn.lock

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,11 @@ domexception@^1.0.1:
23872387
dependencies:
23882388
webidl-conversions "^4.0.2"
23892389

2390+
duplexer@^0.1.1:
2391+
version "0.1.1"
2392+
resolved "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"
2393+
integrity sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=
2394+
23902395
duplexify@^3.5.0, duplexify@^3.6.0:
23912396
version "3.6.0"
23922397
resolved "https://registry.yarnpkg.com/duplexify/-/duplexify-3.6.0.tgz#592903f5d80b38d037220541264d69a198fb3410"
@@ -7077,6 +7082,15 @@ [email protected], strip-json-comments@~2.0.1:
70777082
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
70787083
integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo=
70797084

7085+
7086+
version "2.1.0"
7087+
resolved "https://registry.npmjs.org/strong-log-transformer/-/strong-log-transformer-2.1.0.tgz#0f5ed78d325e0421ac6f90f7f10e691d6ae3ae10"
7088+
integrity sha512-B3Hgul+z0L9a236FAUC9iZsL+nVHgoCJnqCbN588DjYxvGXaXaaFbfmQ/JhvKjZwsOukuR72XbHv71Qkug0HxA==
7089+
dependencies:
7090+
duplexer "^0.1.1"
7091+
minimist "^1.2.0"
7092+
through "^2.3.4"
7093+
70807094
supports-color@^2.0.0:
70817095
version "2.0.0"
70827096
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
@@ -7231,7 +7245,7 @@ [email protected], through2@^2.0.0, through2@^2.0.1, through2@^2.0.3, through2@~2.0.0
72317245
readable-stream "^2.1.5"
72327246
xtend "~4.0.1"
72337247

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

0 commit comments

Comments
 (0)