MCPcopy Create free account
hub / github.com/webpack/webpack-cli / makeCommand

Method makeCommand

packages/webpack-cli/src/webpack-cli.ts:812–956  ·  view source on GitHub ↗
(
    options: CommandOptions<A, O, C>,
  )

Source from the content-addressed store, hash-verified

810 }
811
812 async makeCommand<A = void, O extends CommanderArgs = CommanderArgs, C extends Context = Context>(
813 options: CommandOptions<A, O, C>,
814 ): Promise<Command> {
815 const alreadyLoaded = this.program.commands.find(
816 (command) => command.name() === options.rawName,
817 );
818
819 if (alreadyLoaded) {
820 return alreadyLoaded as Command;
821 }
822
823 const command = this.program.command(options.name, {
824 hidden: options.hidden,
825 isDefault: options.isDefault,
826 }) as Command & { context: C };
827
828 if (options.description) {
829 command.description(options.description);
830 }
831
832 if (options.usage) {
833 command.usage(options.usage);
834 }
835
836 if (Array.isArray(options.alias)) {
837 command.aliases(options.alias);
838 } else {
839 command.alias(options.alias);
840 }
841
842 command.pkg = options.pkg || "webpack-cli";
843
844 const { forHelp } = this.program;
845
846 let allDependenciesInstalled = true;
847
848 if (options.dependencies && options.dependencies.length > 0) {
849 for (const dependency of options.dependencies) {
850 if (
851 // Allow to use `./path/to/webpack.js` outside `node_modules`
852 (dependency === WEBPACK_PACKAGE && WEBPACK_PACKAGE_IS_CUSTOM) ||
853 // Allow to use `./path/to/webpack-dev-server.js` outside `node_modules`
854 (dependency === WEBPACK_DEV_SERVER_PACKAGE && WEBPACK_DEV_SERVER_PACKAGE_IS_CUSTOM)
855 ) {
856 continue;
857 }
858
859 const isPkgExist = await this.isPackageInstalled(dependency);
860
861 if (isPkgExist) {
862 continue;
863 }
864
865 allDependenciesInstalled = false;
866
867 if (forHelp) {
868 command.description(
869 `${

Callers 2

#loadCommandByNameMethod · 0.95
CLI.test.jsFile · 0.80

Calls 6

isPackageInstalledMethod · 0.95
installPackageMethod · 0.95
#neededOptionNamesMethod · 0.95
#isOptionNeededMethod · 0.95
makeOptionMethod · 0.95

Tested by

no test coverage detected