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

Fix duplication of available bin commands (#1991) #2019

Merged
merged 5 commits into from
Nov 25, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions __tests__/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ test('lists all available commands with no arguments', (): Promise<void> => {
return runRun({}, [], 'no-args', (config, reporter): ?Promise<void> => {
const rprtr = new reporters.BufferReporter({stdout: null, stdin: null});
const scripts = ['build', 'prestart', 'start'];
// Notice `cat-names` is below twice as there is a bug with output duplication
const bins = ['cat-names', 'cat-names'];
const bins = ['cat-names'];

// Emulate run output
rprtr.error(rprtr.lang('commandNotSpecified'));
Expand Down
12 changes: 8 additions & 4 deletions src/cli/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ export async function run(
const scripts = map();
const binCommands = [];
let pkgCommands = [];
let visitedBinFolders = [];
Copy link
Member

Choose a reason for hiding this comment

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

use const instead of let.

And, please run yarn lint before submitting a PR 😄

for (const registry of Object.keys(registries)) {
const binFolder = path.join(config.cwd, config.registries[registry].folder, '.bin');
if (await fs.exists(binFolder)) {
for (const name of await fs.readdir(binFolder)) {
binCommands.push(name);
scripts[name] = `"${path.join(binFolder, name)}"`;
if (!visitedBinFolders.includes(binFolder)) {
if (await fs.exists(binFolder)) {
for (const name of await fs.readdir(binFolder)) {
binCommands.push(name);
scripts[name] = `"${path.join(binFolder, name)}"`;
}
}
visitedBinFolders.push(binFolder);
}
}
if (pkg.scripts) {
Expand Down