Skip to content

Commit

Permalink
Prefix workspace commands with workspace name
Browse files Browse the repository at this point in the history
  • Loading branch information
peterlebrun committed Jan 16, 2019
1 parent fb03788 commit 4dae788
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
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
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
19 changes: 18 additions & 1 deletion 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 @@ -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) {
if (!workspaceColors[opts.workspaceName]) {
const randInt = Math.floor(Math.random() * colors.length);
// Make sure that we are consistent
workspaceColors[opts.workspaceName] = colors[randInt];
}
let wsColor = chalk[workspaceColors[opts.workspaceName]];
let tag = `${wsColor.bold(opts.workspaceName)}:`;
proc.stdout.pipe(logTransformer({tag})).pipe(process.stdout);
} else {
proc.stdout.on('data', updateStdout);
}
}

processingDone = true;
Expand Down

0 comments on commit 4dae788

Please sign in to comment.