(commandName: string)
| 2474 | } |
| 2475 | |
| 2476 | async #loadCommandByName(commandName: string): Promise<Command | undefined> { |
| 2477 | if (this.#isCommand(commandName, this.#commands.build)) { |
| 2478 | return await this.makeCommand(this.#commands.build); |
| 2479 | } else if (this.#isCommand(commandName, this.#commands.serve)) { |
| 2480 | return await this.makeCommand(this.#commands.serve); |
| 2481 | } else if (this.#isCommand(commandName, this.#commands.watch)) { |
| 2482 | return await this.makeCommand(this.#commands.watch); |
| 2483 | } else if (this.#isCommand(commandName, this.#commands.help)) { |
| 2484 | // Stub for the `help` command |
| 2485 | return await this.makeCommand(this.#commands.help); |
| 2486 | } else if (this.#isCommand(commandName, this.#commands.version)) { |
| 2487 | return await this.makeCommand(this.#commands.version); |
| 2488 | } else if (this.#isCommand(commandName, this.#commands.info)) { |
| 2489 | return await this.makeCommand(this.#commands.info); |
| 2490 | } else if (this.#isCommand(commandName, this.#commands.configtest)) { |
| 2491 | return await this.makeCommand(this.#commands.configtest); |
| 2492 | } |
| 2493 | |
| 2494 | const pkg: string = commandName; |
| 2495 | |
| 2496 | type Instantiable< |
| 2497 | InstanceType = unknown, |
| 2498 | ConstructorParameters extends unknown[] = unknown[], |
| 2499 | > = new (...args: ConstructorParameters) => InstanceType & { apply(cli: WebpackCLI): Command }; |
| 2500 | |
| 2501 | let LoadedCommand: Instantiable<() => void>; |
| 2502 | |
| 2503 | try { |
| 2504 | LoadedCommand = (await import(pkg)).default; |
| 2505 | } catch (error) { |
| 2506 | if ((error as NodeJS.ErrnoException).code !== "ERR_MODULE_NOT_FOUND") { |
| 2507 | this.logger.error(`Unable to load '${pkg}' command`); |
| 2508 | this.logger.error(error); |
| 2509 | process.exit(2); |
| 2510 | } |
| 2511 | |
| 2512 | return; |
| 2513 | } |
| 2514 | |
| 2515 | let command; |
| 2516 | let externalCommand: Command; |
| 2517 | |
| 2518 | try { |
| 2519 | command = new LoadedCommand(); |
| 2520 | externalCommand = await command.apply(this); |
| 2521 | } catch (error) { |
| 2522 | this.logger.error(`Unable to load '${pkg}' command`); |
| 2523 | this.logger.error(error); |
| 2524 | process.exit(2); |
| 2525 | } |
| 2526 | |
| 2527 | return externalCommand; |
| 2528 | } |
| 2529 | |
| 2530 | async run(args: readonly string[], parseOptions: ParseOptions) { |
| 2531 | // Default `--color` and `--no-color` options |
no test coverage detected