Skip to content

Commit 2c8e97e

Browse files
Kevin Deiszarcanis
authored andcommitted
Fix suggestions for CLI (#7808)
At some point the `scripts` object changes to be a map instead of an array, at which point the suggestions functionality broke. This commit includes the fix and a test to make sure it doesn't break again.
1 parent 039bafd commit 2c8e97e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "test_suggestion",
3+
"version": "1.0.0",
4+
"license": "UNLICENSED",
5+
"scripts": {
6+
"foobar": "foobar"
7+
}
8+
}

__tests__/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ test.concurrent('should throws missing command for unknown command', async () =>
300300
await expectAnErrorMessage(execCommand('unknown', [], 'run-add', true), 'Command "unknown" not found');
301301
});
302302

303+
test.concurrent('should suggest options for other commands when missing a command', async () => {
304+
await expectAnErrorMessage(execCommand('foobarx', [], 'run-suggestion', true), 'Did you mean "foobar"?');
305+
});
306+
303307
test.concurrent('should not display documentation link for unknown command', async () => {
304308
await expectAnInfoMessageAfterError(execCommand('unknown', [], 'run-add', true), '');
305309
});

src/cli/commands/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
149149
} else {
150150
let suggestion;
151151

152-
for (const commandName in scripts) {
152+
for (const commandName of scripts.keys()) {
153153
const steps = leven(commandName, action);
154154
if (steps < 2) {
155155
suggestion = commandName;

0 commit comments

Comments
 (0)