Skip to content

Commit 4dae788

Browse files
committed
Prefix workspace commands with workspace name
1 parent fb03788 commit 4dae788

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
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)

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: 18 additions & 1 deletion
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
@@ -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+
if (!workspaceColors[opts.workspaceName]) {
127+
const randInt = Math.floor(Math.random() * colors.length);
128+
// Make sure that we are consistent
129+
workspaceColors[opts.workspaceName] = colors[randInt];
130+
}
131+
let wsColor = chalk[workspaceColors[opts.workspaceName]];
132+
let 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;

0 commit comments

Comments
 (0)