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

Build: Add text suggestions for incorrect task names #30056

Merged
merged 2 commits into from
Dec 15, 2024
Merged
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
14 changes: 14 additions & 0 deletions scripts/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { testRunnerBuild } from './tasks/test-runner-build';
import { testRunnerDev } from './tasks/test-runner-dev';
import { vitestTests } from './tasks/vitest-test';
import { CODE_DIRECTORY, JUNIT_DIRECTORY, SANDBOX_DIRECTORY } from './utils/constants';
import { findMostMatchText } from './utils/diff';
import type { OptionValues } from './utils/options';
import { createOptions, getCommand, getOptionsOrPrompt } from './utils/options';

Expand Down Expand Up @@ -351,6 +352,19 @@ async function run() {
const { junit, startFrom, ...optionValues } = allOptionValues;
const taskKey = optionValues.task;

if (!(taskKey in tasks)) {
const matchText = findMostMatchText(Object.keys(tasks), taskKey);

if (matchText) {
console.log(
`${picocolors.red('Error')}: ${picocolors.cyan(
taskKey
)} is not a valid task name, Did you mean ${picocolors.cyan(matchText)}?`
);
Comment on lines +359 to +363
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using logger.error() for consistency with other error logging in this file

}
process.exit(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Add a newline before process.exit(1) for better error message readability

}

const finalTask = tasks[taskKey];
const { template: templateKey } = optionValues;
const template = TEMPLATES[templateKey];
Expand Down
Loading