(args: readonly string[], parseOptions: ParseOptions)
| 2528 | } |
| 2529 | |
| 2530 | async run(args: readonly string[], parseOptions: ParseOptions) { |
| 2531 | // Default `--color` and `--no-color` options |
| 2532 | |
| 2533 | const self: WebpackCLI = this; |
| 2534 | |
| 2535 | // Register own exit |
| 2536 | this.program.exitOverride((error) => { |
| 2537 | if (error.exitCode === 0) { |
| 2538 | process.exit(0); |
| 2539 | return; |
| 2540 | } |
| 2541 | |
| 2542 | if (error.code === "commander.unknownOption") { |
| 2543 | let name = error.message.match(/'(.+)'/) as string | null; |
| 2544 | |
| 2545 | if (name) { |
| 2546 | name = name[1].slice(2); |
| 2547 | |
| 2548 | if (name.includes("=")) { |
| 2549 | [name] = name.split("="); |
| 2550 | } |
| 2551 | |
| 2552 | const { operands } = this.program.parseOptions(this.program.args); |
| 2553 | const operand = |
| 2554 | typeof operands[0] !== "undefined" ? operands[0] : this.#commands.build.rawName; |
| 2555 | |
| 2556 | if (operand) { |
| 2557 | const command = this.#findCommandByName(operand); |
| 2558 | |
| 2559 | if (!command) { |
| 2560 | this.logger.error(`Can't find and load command '${operand}'`); |
| 2561 | this.logger.error("Run 'webpack --help' to see available commands and options"); |
| 2562 | process.exit(2); |
| 2563 | } |
| 2564 | |
| 2565 | const { allOptionNames } = command as Command & { allOptionNames?: string[] }; |
| 2566 | const candidateNames = |
| 2567 | allOptionNames ?? |
| 2568 | command.options |
| 2569 | .filter((option) => !(option as Option & { internal?: boolean }).internal) |
| 2570 | .map((option) => option.long?.slice(2) as string); |
| 2571 | |
| 2572 | for (const candidate of candidateNames) { |
| 2573 | if (candidate && WebpackCLI.#distance(name, candidate) < 3) { |
| 2574 | this.logger.error(`Did you mean '--${candidate}'?`); |
| 2575 | } |
| 2576 | } |
| 2577 | } |
| 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | this.logger.error("Run 'webpack --help' to see available commands and options"); |
| 2582 | process.exit(2); |
| 2583 | }); |
| 2584 | |
| 2585 | this.program.option("--color", "Enable colors on console."); |
| 2586 | this.program.on("option:color", function color(this: Command) { |
| 2587 | const { color } = this.opts(); |
no test coverage detected